-
Notifications
You must be signed in to change notification settings - Fork 2
/
comparators.ts
executable file
·130 lines (114 loc) · 3.81 KB
/
comparators.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
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
import { Function } from './functions';
import { Item, valuesToValue } from './item';
export abstract class Comparator implements Item {
// false positive
// eslint-disable-next-line @typescript-eslint/ban-types
constructor(protected selector: Function | string, protected comparatorKeyWord: string, protected value?: string | number) {}
toString(): string {
if (typeof this.value === 'undefined' || this.value === null) {
return `${this.selector} ${this.comparatorKeyWord}`;
}
if (typeof this.value === 'number') {
return `${this.selector} ${this.comparatorKeyWord} ${this.value}`;
} else {
return `${this.selector} ${this.comparatorKeyWord} '${this.value}'`;
}
}
}
export class Like extends Comparator {
// false positive
// eslint-disable-next-line @typescript-eslint/ban-types
constructor(selector: Function | string, value: string, caseInsensitive = false) {
super(selector, caseInsensitive ? '~~' : '~', value);
}
}
export class Equal extends Comparator {
// false positive
// eslint-disable-next-line @typescript-eslint/ban-types
constructor(selector: Function | string, value: string | number) {
super(selector, ':', value);
}
}
export class NotEqual extends Comparator {
// false positive
// eslint-disable-next-line @typescript-eslint/ban-types
constructor(selector: Function | string, value: string | number) {
super(selector, '!', value);
}
}
export class Gt extends Comparator {
// false positive
// eslint-disable-next-line @typescript-eslint/ban-types
constructor(selector: Function | string, value: string | number) {
super(selector, '>', value);
}
}
export class Ge extends Comparator {
// false positive
// eslint-disable-next-line @typescript-eslint/ban-types
constructor(selector: Function | string, value: string | number) {
super(selector, '>:', value);
}
}
export class Lt extends Comparator {
// false positive
// eslint-disable-next-line @typescript-eslint/ban-types
constructor(selector: Function | string, value: string | number) {
super(selector, '<', value);
}
}
export class Le extends Comparator {
// false positive
// eslint-disable-next-line @typescript-eslint/ban-types
constructor(selector: Function | string, value: string | number) {
super(selector, '<:', value);
}
}
export class IsNull extends Comparator {
// false positive
// eslint-disable-next-line @typescript-eslint/ban-types
constructor(selector: Function | string) {
super(selector, 'is null');
}
}
export class IsNotNull extends Comparator {
// false positive
// eslint-disable-next-line @typescript-eslint/ban-types
constructor(selector: Function | string) {
super(selector, 'is not null');
}
}
export class IsEmpty extends Comparator {
// false positive
// eslint-disable-next-line @typescript-eslint/ban-types
constructor(selector: Function | string) {
super(selector, 'is empty');
}
}
export class IsNotEmpty extends Comparator {
// false positive
// eslint-disable-next-line @typescript-eslint/ban-types
constructor(selector: Function | string) {
super(selector, 'is not empty');
}
}
export class In extends Comparator {
// false positive
// eslint-disable-next-line @typescript-eslint/ban-types
constructor(selector: Function | string, values: (string | number)[]) {
super(selector, 'in', `[${valuesToValue(values)}]`);
}
public toString(): string {
return `${this.selector} ${this.comparatorKeyWord} ${this.value}`;
}
}
export class NotIn extends Comparator {
// false positive
// eslint-disable-next-line @typescript-eslint/ban-types
constructor(selector: Function | string, values: (string | number)[]) {
super(selector, 'not in', `[${valuesToValue(values)}]`);
}
public toString(): string {
return `${this.selector} ${this.comparatorKeyWord} ${this.value}`;
}
}