-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathLesserThanOrEqual.ts
More file actions
53 lines (51 loc) · 1.55 KB
/
LesserThanOrEqual.ts
File metadata and controls
53 lines (51 loc) · 1.55 KB
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
import { Expression } from "./Expression"
import { Token } from "./lexer"
import { Rule } from "./Rule"
import { Type } from "./Type"
import { Value } from "./Value"
export class LesserThanOrEqual extends Rule {
readonly precedence = 85
readonly class = "LesserThanOrEqual"
readonly symbol = "<="
constructor(readonly value: bigint | boolean | number | string | Expression) {
super()
}
is(value: any): boolean
is(value: any, object?: any): boolean {
return (
(isNaN(+value) ? value : +value) <=
((this.value instanceof Value && typeof this.value.value == "string" && this.value.value.includes("-")) ||
typeof this.value != "object"
? this.value
: this.value.evaluate(object))
)
}
toString(): string {
return this.value.toString()
}
}
export function lesserThanOrEqual(criteria: bigint | boolean | number | string): LesserThanOrEqual
export function lesserThanOrEqual(criteria: bigint | boolean | number | string, value?: any): boolean
export function lesserThanOrEqual(
criteria: bigint | boolean | number | string,
value?: any
): LesserThanOrEqual | boolean {
const result = new LesserThanOrEqual(criteria)
return value ? result.is(value) : result
}
function complete(
tokens: Token[],
type: Type.String | Type.Number,
baseObject: Type.Object
): Type.Completion[] | Type.Completion {
return Type.Completor.operators(
tokens,
(tokens?: Token[]) => (tokens && baseObject ? baseObject?.complete(tokens, undefined, type) : []),
{
value: "<=",
suggestion: { value: "<=" },
}
)
}
Type.Number.add(complete)
Type.String.add(complete)