Newer
Older
import { DefinedBoolean, DefinedString } from "./definedvalue";

Grand Francois
committed
export class NumericalString extends DefinedString {
private get isNumericalFlag(): DefinedBoolean {

Grand Francois
committed
this._isNumericalFlag = new DefinedBoolean();
}

Grand Francois
committed
}
get isNumerical(): boolean {
this.updateNumericalFlag();
return this.isNumericalFlag.value;
}
/**
* nécessaire car si on surcharge un des accesseurs, il faut surcharger les 2 (merci Microsoft)
*/
get value() {
return this.getValue();
}
set value(v: string) {
this.isNumericalFlag.undefine();
this.setValue(v);
// this.updateNumericalFlag();
}
get numericalValue(): number {
if (!this.isNumerical) {
throw new Error("invalid NumericalString '" + this.uncheckedValue + "' value");
}

Grand Francois
committed
return +this.value;
}
get uncheckedValueString(): string {

Grand Francois
committed
return this.uncheckedValue;

Grand Francois
committed
return "";
}

Grand Francois
committed

Grand Francois
committed
return super.toString() + (this.isNumerical ? " [numerical]" : " [NOT numerical]");
}
private updateNumericalFlag() {
if (!this.isNumericalFlag.isDefined) {
this.isNumericalFlag.value = false;
if (this.isDefined) {
if (typeof this.value === "string") {
this.isNumericalFlag.value = String(this.value).trim() !== "" && !isNaN(+this.value);
}
}
}
}