-
Notifications
You must be signed in to change notification settings - Fork 0
/
HasNumberProperty.ts
60 lines (53 loc) · 1.42 KB
/
HasNumberProperty.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
51
52
53
54
55
56
57
58
59
60
import {
Scalar,
ScalarLike,
ScalarOf
} from '@main';
/**
* Determines if scalar or value has a number property.
*/
export class HasNumberProperty<T> implements Scalar<boolean> {
/**
* Scalar.
*/
private readonly scalar: Scalar<T>;
/**
* Name of the property to check.
*/
private readonly name: Scalar<string>;
/**
* Number to be checked.
*/
private readonly compared: Scalar<number>;
/**
* Ctor.
* @param value Value.
* @param name Name of the property to check.
* @param compared Compared value.
*/
constructor(value: ScalarLike<T>, name: ScalarLike<string>, compared: ScalarLike<number>) {
this.scalar = new ScalarOf(value);
this.name = new ScalarOf(name);
this.compared = new ScalarOf(compared);
}
/**
* Type determinant.
*/
public isScalar(): true {
return true;
}
/**
* Get the value.
*/
public value(): boolean {
const name: string = this.name.value();
// tslint:disable-next-line:no-any
const converted: any = <any>this.scalar.value();
return converted !== null
&& typeof converted === 'object'
// tslint:disable-next-line:no-unsafe-any
&& typeof converted[name] === 'number'
// tslint:disable-next-line:no-unsafe-any
&& converted[name] === this.compared.value();
}
}