Newer
Older

Grand Francois
committed
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
import { DefinedValue, DefinedBoolean, DefinedString } from "./definedvalue";
export class NumericalString extends DefinedString {
private _isNumericalFlag: DefinedBoolean;
constructor(s: any = undefined) {
super(s);
}
private get isNumericalFlag(): DefinedBoolean {
if (this._isNumericalFlag == undefined)
this._isNumericalFlag = new DefinedBoolean();
return this._isNumericalFlag;
}
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)
}
}
}
}
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 "invalid NumericString '" + this.uncheckedValue + "' value";
return +this.value;
}
get uncheckValueString(): string {
if (this.isDefined)
return this.uncheckedValue;
return "";
}
toString(): string {
return super.toString() + (this.isNumerical ? " [numerical]" : " [NOT numerical]");
}
}