-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathval.ts
50 lines (44 loc) · 1.35 KB
/
val.ts
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
import {Config} from "./Config";
import {Describe} from "./Describe";
export function val(name: string, _: any): Val {
return new Val(name, _);
}
export class Val {
name: string;
value: any;
constructor(name: string, value: any) {
this.name = name;
this.value = value;
}
/**
* These 3 steps will be applied to format a value in Examples and Tables:
*
* 1) If a [Config.transformDescribe] was provided, it will be used to format the value.
*
* 2) Next, if the value is null, return 'NULL'.
*
* 3) Next, if the value implements the [BddDescribe] interface, or if it has a
* [describe] method, it will be used to format the value.
*
* 4) Last, we'll call the value's [toString] method.
*/
toString(config: Config = Config._default): string {
let _value = this.value;
// 1)
if (config.transformDescribe) {
_value = config.transformDescribe(this.value) || _value;
}
// 2)
if (_value === null) return 'NULL';
//
// 3)
else if ((<Describe>_value).describe) {
let description = (<Describe>_value).describe();
return (description === null) ? 'NULL' : description.toString();
}
//
// 4)
else
return _value.toString();
}
}