@ls-stack/utils 3.43.0 → 3.44.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/partialEqual.cjs +70 -34
- package/dist/partialEqual.d.cts +51 -31
- package/dist/partialEqual.d.ts +51 -31
- package/dist/partialEqual.js +70 -34
- package/package.json +1 -1
package/dist/partialEqual.cjs
CHANGED
|
@@ -91,52 +91,69 @@ function deepEqual(foo, bar, maxDepth = 20) {
|
|
|
91
91
|
|
|
92
92
|
// src/partialEqual.ts
|
|
93
93
|
var has2 = Object.prototype.hasOwnProperty;
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
};
|
|
94
|
+
function createComparison(type) {
|
|
95
|
+
return {
|
|
96
|
+
"~sc": type
|
|
97
|
+
};
|
|
98
|
+
}
|
|
100
99
|
var match = {
|
|
100
|
+
hasType: {
|
|
101
|
+
string: createComparison(["hasType", "string"]),
|
|
102
|
+
number: createComparison(["hasType", "number"]),
|
|
103
|
+
boolean: createComparison(["hasType", "boolean"]),
|
|
104
|
+
object: createComparison(["hasType", "object"]),
|
|
105
|
+
array: createComparison(["hasType", "array"]),
|
|
106
|
+
function: createComparison(["hasType", "function"])
|
|
107
|
+
},
|
|
108
|
+
isInstanceOf: (constructor) => createComparison(["isInstanceOf", constructor]),
|
|
101
109
|
str: {
|
|
102
|
-
contains: (substring) =>
|
|
103
|
-
startsWith: (substring) =>
|
|
104
|
-
endsWith: (substring) =>
|
|
105
|
-
matchesRegex: (regex) =>
|
|
110
|
+
contains: (substring) => createComparison(["strContains", substring]),
|
|
111
|
+
startsWith: (substring) => createComparison(["strStartsWith", substring]),
|
|
112
|
+
endsWith: (substring) => createComparison(["strEndsWith", substring]),
|
|
113
|
+
matchesRegex: (regex) => createComparison(["strMatchesRegex", regex])
|
|
106
114
|
},
|
|
107
115
|
num: {
|
|
108
|
-
isGreaterThan: (value) =>
|
|
109
|
-
isGreaterThanOrEqual: (value) =>
|
|
110
|
-
isLessThan: (value) =>
|
|
111
|
-
isLessThanOrEqual: (value) =>
|
|
112
|
-
isInRange: (value) =>
|
|
116
|
+
isGreaterThan: (value) => createComparison(["numIsGreaterThan", value]),
|
|
117
|
+
isGreaterThanOrEqual: (value) => createComparison(["numIsGreaterThanOrEqual", value]),
|
|
118
|
+
isLessThan: (value) => createComparison(["numIsLessThan", value]),
|
|
119
|
+
isLessThanOrEqual: (value) => createComparison(["numIsLessThanOrEqual", value]),
|
|
120
|
+
isInRange: (value) => createComparison(["numIsInRange", value])
|
|
113
121
|
},
|
|
114
122
|
jsonString: {
|
|
115
|
-
hasPartial: (value) =>
|
|
123
|
+
hasPartial: (value) => createComparison(["jsonStringHasPartial", value])
|
|
116
124
|
},
|
|
117
|
-
equal: (value) =>
|
|
118
|
-
partialEqual: (value) =>
|
|
119
|
-
custom: (isEqual) =>
|
|
125
|
+
equal: (value) => createComparison(["deepEqual", value]),
|
|
126
|
+
partialEqual: (value) => createComparison(["partialEqual", value]),
|
|
127
|
+
custom: (isEqual) => createComparison(["custom", isEqual]),
|
|
120
128
|
not: {
|
|
129
|
+
hasType: {
|
|
130
|
+
string: createComparison(["not", ["hasType", "string"]]),
|
|
131
|
+
number: createComparison(["not", ["hasType", "number"]]),
|
|
132
|
+
boolean: createComparison(["not", ["hasType", "boolean"]]),
|
|
133
|
+
object: createComparison(["not", ["hasType", "object"]]),
|
|
134
|
+
array: createComparison(["not", ["hasType", "array"]]),
|
|
135
|
+
function: createComparison(["not", ["hasType", "function"]])
|
|
136
|
+
},
|
|
137
|
+
isInstanceOf: (constructor) => createComparison(["not", ["isInstanceOf", constructor]]),
|
|
121
138
|
str: {
|
|
122
|
-
contains: (substring) =>
|
|
123
|
-
startsWith: (substring) =>
|
|
124
|
-
endsWith: (substring) =>
|
|
125
|
-
matchesRegex: (regex) =>
|
|
139
|
+
contains: (substring) => createComparison(["not", ["strContains", substring]]),
|
|
140
|
+
startsWith: (substring) => createComparison(["not", ["strStartsWith", substring]]),
|
|
141
|
+
endsWith: (substring) => createComparison(["not", ["strEndsWith", substring]]),
|
|
142
|
+
matchesRegex: (regex) => createComparison(["not", ["strMatchesRegex", regex]])
|
|
126
143
|
},
|
|
127
144
|
num: {
|
|
128
|
-
isGreaterThan: (value) =>
|
|
129
|
-
isGreaterThanOrEqual: (value) =>
|
|
130
|
-
isLessThan: (value) =>
|
|
131
|
-
isLessThanOrEqual: (value) =>
|
|
132
|
-
isInRange: (value) =>
|
|
145
|
+
isGreaterThan: (value) => createComparison(["not", ["numIsGreaterThan", value]]),
|
|
146
|
+
isGreaterThanOrEqual: (value) => createComparison(["not", ["numIsGreaterThanOrEqual", value]]),
|
|
147
|
+
isLessThan: (value) => createComparison(["not", ["numIsLessThan", value]]),
|
|
148
|
+
isLessThanOrEqual: (value) => createComparison(["not", ["numIsLessThanOrEqual", value]]),
|
|
149
|
+
isInRange: (value) => createComparison(["not", ["numIsInRange", value]])
|
|
133
150
|
},
|
|
134
151
|
jsonString: {
|
|
135
|
-
hasPartial: (value) =>
|
|
152
|
+
hasPartial: (value) => createComparison(["not", ["jsonStringHasPartial", value]])
|
|
136
153
|
},
|
|
137
|
-
equal: (value) =>
|
|
138
|
-
partialEqual: (value) =>
|
|
139
|
-
custom: (value) =>
|
|
154
|
+
equal: (value) => createComparison(["not", ["deepEqual", value]]),
|
|
155
|
+
partialEqual: (value) => createComparison(["not", ["partialEqual", value]]),
|
|
156
|
+
custom: (value) => createComparison(["not", ["custom", value]])
|
|
140
157
|
}
|
|
141
158
|
};
|
|
142
159
|
function find2(iter, tar) {
|
|
@@ -147,6 +164,25 @@ function find2(iter, tar) {
|
|
|
147
164
|
function executeComparison(target, comparison) {
|
|
148
165
|
const [type, value] = comparison;
|
|
149
166
|
switch (type) {
|
|
167
|
+
case "hasType":
|
|
168
|
+
switch (value) {
|
|
169
|
+
case "string":
|
|
170
|
+
return typeof target === "string";
|
|
171
|
+
case "number":
|
|
172
|
+
return typeof target === "number";
|
|
173
|
+
case "boolean":
|
|
174
|
+
return typeof target === "boolean";
|
|
175
|
+
case "function":
|
|
176
|
+
return typeof target === "function";
|
|
177
|
+
case "array":
|
|
178
|
+
return Array.isArray(target);
|
|
179
|
+
case "object":
|
|
180
|
+
return typeof target === "object" && target !== null && !Array.isArray(target);
|
|
181
|
+
default:
|
|
182
|
+
return false;
|
|
183
|
+
}
|
|
184
|
+
case "isInstanceOf":
|
|
185
|
+
return target instanceof value;
|
|
150
186
|
case "strStartsWith":
|
|
151
187
|
return typeof target === "string" && target.startsWith(value);
|
|
152
188
|
case "strEndsWith":
|
|
@@ -187,8 +223,8 @@ function executeComparison(target, comparison) {
|
|
|
187
223
|
}
|
|
188
224
|
function partialEqual(target, sub) {
|
|
189
225
|
if (sub === target) return true;
|
|
190
|
-
if (sub
|
|
191
|
-
return executeComparison(target, sub
|
|
226
|
+
if (sub && typeof sub === "object" && "~sc" in sub) {
|
|
227
|
+
return executeComparison(target, sub["~sc"]);
|
|
192
228
|
}
|
|
193
229
|
if (sub && target && sub.constructor === target.constructor) {
|
|
194
230
|
const ctor = sub.constructor;
|
package/dist/partialEqual.d.cts
CHANGED
|
@@ -1,48 +1,68 @@
|
|
|
1
|
-
type ComparisonsType = [type: 'strStartsWith', value: string] | [type: 'strEndsWith', value: string] | [
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
1
|
+
type ComparisonsType = [type: 'strStartsWith', value: string] | [type: 'strEndsWith', value: string] | [
|
|
2
|
+
type: 'hasType',
|
|
3
|
+
value: 'string' | 'number' | 'boolean' | 'object' | 'array' | 'function'
|
|
4
|
+
] | [type: 'strContains', value: string] | [type: 'strMatchesRegex', value: RegExp] | [type: 'deepEqual', value: any] | [type: 'numIsGreaterThan', value: number] | [type: 'numIsGreaterThanOrEqual', value: number] | [type: 'numIsLessThan', value: number] | [type: 'numIsLessThanOrEqual', value: number] | [type: 'numIsInRange', value: [number, number]] | [type: 'jsonStringHasPartial', value: any] | [type: 'partialEqual', value: any] | [type: 'custom', value: (target: unknown) => boolean] | [type: 'isInstanceOf', value: new (...args: any[]) => any] | [type: 'not', value: ComparisonsType];
|
|
5
|
+
type Comparison = {
|
|
6
|
+
'~sc': ComparisonsType;
|
|
7
|
+
};
|
|
6
8
|
declare const match: {
|
|
9
|
+
hasType: {
|
|
10
|
+
string: Comparison;
|
|
11
|
+
number: Comparison;
|
|
12
|
+
boolean: Comparison;
|
|
13
|
+
object: Comparison;
|
|
14
|
+
array: Comparison;
|
|
15
|
+
function: Comparison;
|
|
16
|
+
};
|
|
17
|
+
isInstanceOf: (constructor: new (...args: any[]) => any) => Comparison;
|
|
7
18
|
str: {
|
|
8
|
-
contains: (substring: string) =>
|
|
9
|
-
startsWith: (substring: string) =>
|
|
10
|
-
endsWith: (substring: string) =>
|
|
11
|
-
matchesRegex: (regex: RegExp) =>
|
|
19
|
+
contains: (substring: string) => Comparison;
|
|
20
|
+
startsWith: (substring: string) => Comparison;
|
|
21
|
+
endsWith: (substring: string) => Comparison;
|
|
22
|
+
matchesRegex: (regex: RegExp) => Comparison;
|
|
12
23
|
};
|
|
13
24
|
num: {
|
|
14
|
-
isGreaterThan: (value: number) =>
|
|
15
|
-
isGreaterThanOrEqual: (value: number) =>
|
|
16
|
-
isLessThan: (value: number) =>
|
|
17
|
-
isLessThanOrEqual: (value: number) =>
|
|
18
|
-
isInRange: (value: [number, number]) =>
|
|
25
|
+
isGreaterThan: (value: number) => Comparison;
|
|
26
|
+
isGreaterThanOrEqual: (value: number) => Comparison;
|
|
27
|
+
isLessThan: (value: number) => Comparison;
|
|
28
|
+
isLessThanOrEqual: (value: number) => Comparison;
|
|
29
|
+
isInRange: (value: [number, number]) => Comparison;
|
|
19
30
|
};
|
|
20
31
|
jsonString: {
|
|
21
|
-
hasPartial: (value: any) =>
|
|
32
|
+
hasPartial: (value: any) => Comparison;
|
|
22
33
|
};
|
|
23
|
-
equal: (value: any) =>
|
|
24
|
-
partialEqual: (value: any) =>
|
|
25
|
-
custom: (isEqual: (value: unknown) => boolean) =>
|
|
34
|
+
equal: (value: any) => Comparison;
|
|
35
|
+
partialEqual: (value: any) => Comparison;
|
|
36
|
+
custom: (isEqual: (value: unknown) => boolean) => Comparison;
|
|
26
37
|
not: {
|
|
38
|
+
hasType: {
|
|
39
|
+
string: Comparison;
|
|
40
|
+
number: Comparison;
|
|
41
|
+
boolean: Comparison;
|
|
42
|
+
object: Comparison;
|
|
43
|
+
array: Comparison;
|
|
44
|
+
function: Comparison;
|
|
45
|
+
};
|
|
46
|
+
isInstanceOf: (constructor: new (...args: any[]) => any) => Comparison;
|
|
27
47
|
str: {
|
|
28
|
-
contains: (substring: string) =>
|
|
29
|
-
startsWith: (substring: string) =>
|
|
30
|
-
endsWith: (substring: string) =>
|
|
31
|
-
matchesRegex: (regex: RegExp) =>
|
|
48
|
+
contains: (substring: string) => Comparison;
|
|
49
|
+
startsWith: (substring: string) => Comparison;
|
|
50
|
+
endsWith: (substring: string) => Comparison;
|
|
51
|
+
matchesRegex: (regex: RegExp) => Comparison;
|
|
32
52
|
};
|
|
33
53
|
num: {
|
|
34
|
-
isGreaterThan: (value: number) =>
|
|
35
|
-
isGreaterThanOrEqual: (value: number) =>
|
|
36
|
-
isLessThan: (value: number) =>
|
|
37
|
-
isLessThanOrEqual: (value: number) =>
|
|
38
|
-
isInRange: (value: [number, number]) =>
|
|
54
|
+
isGreaterThan: (value: number) => Comparison;
|
|
55
|
+
isGreaterThanOrEqual: (value: number) => Comparison;
|
|
56
|
+
isLessThan: (value: number) => Comparison;
|
|
57
|
+
isLessThanOrEqual: (value: number) => Comparison;
|
|
58
|
+
isInRange: (value: [number, number]) => Comparison;
|
|
39
59
|
};
|
|
40
60
|
jsonString: {
|
|
41
|
-
hasPartial: (value: any) =>
|
|
61
|
+
hasPartial: (value: any) => Comparison;
|
|
42
62
|
};
|
|
43
|
-
equal: (value: any) =>
|
|
44
|
-
partialEqual: (value: any) =>
|
|
45
|
-
custom: (value: (target: unknown) => boolean) =>
|
|
63
|
+
equal: (value: any) => Comparison;
|
|
64
|
+
partialEqual: (value: any) => Comparison;
|
|
65
|
+
custom: (value: (target: unknown) => boolean) => Comparison;
|
|
46
66
|
};
|
|
47
67
|
};
|
|
48
68
|
declare function partialEqual(target: any, sub: any): boolean;
|
package/dist/partialEqual.d.ts
CHANGED
|
@@ -1,48 +1,68 @@
|
|
|
1
|
-
type ComparisonsType = [type: 'strStartsWith', value: string] | [type: 'strEndsWith', value: string] | [
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
1
|
+
type ComparisonsType = [type: 'strStartsWith', value: string] | [type: 'strEndsWith', value: string] | [
|
|
2
|
+
type: 'hasType',
|
|
3
|
+
value: 'string' | 'number' | 'boolean' | 'object' | 'array' | 'function'
|
|
4
|
+
] | [type: 'strContains', value: string] | [type: 'strMatchesRegex', value: RegExp] | [type: 'deepEqual', value: any] | [type: 'numIsGreaterThan', value: number] | [type: 'numIsGreaterThanOrEqual', value: number] | [type: 'numIsLessThan', value: number] | [type: 'numIsLessThanOrEqual', value: number] | [type: 'numIsInRange', value: [number, number]] | [type: 'jsonStringHasPartial', value: any] | [type: 'partialEqual', value: any] | [type: 'custom', value: (target: unknown) => boolean] | [type: 'isInstanceOf', value: new (...args: any[]) => any] | [type: 'not', value: ComparisonsType];
|
|
5
|
+
type Comparison = {
|
|
6
|
+
'~sc': ComparisonsType;
|
|
7
|
+
};
|
|
6
8
|
declare const match: {
|
|
9
|
+
hasType: {
|
|
10
|
+
string: Comparison;
|
|
11
|
+
number: Comparison;
|
|
12
|
+
boolean: Comparison;
|
|
13
|
+
object: Comparison;
|
|
14
|
+
array: Comparison;
|
|
15
|
+
function: Comparison;
|
|
16
|
+
};
|
|
17
|
+
isInstanceOf: (constructor: new (...args: any[]) => any) => Comparison;
|
|
7
18
|
str: {
|
|
8
|
-
contains: (substring: string) =>
|
|
9
|
-
startsWith: (substring: string) =>
|
|
10
|
-
endsWith: (substring: string) =>
|
|
11
|
-
matchesRegex: (regex: RegExp) =>
|
|
19
|
+
contains: (substring: string) => Comparison;
|
|
20
|
+
startsWith: (substring: string) => Comparison;
|
|
21
|
+
endsWith: (substring: string) => Comparison;
|
|
22
|
+
matchesRegex: (regex: RegExp) => Comparison;
|
|
12
23
|
};
|
|
13
24
|
num: {
|
|
14
|
-
isGreaterThan: (value: number) =>
|
|
15
|
-
isGreaterThanOrEqual: (value: number) =>
|
|
16
|
-
isLessThan: (value: number) =>
|
|
17
|
-
isLessThanOrEqual: (value: number) =>
|
|
18
|
-
isInRange: (value: [number, number]) =>
|
|
25
|
+
isGreaterThan: (value: number) => Comparison;
|
|
26
|
+
isGreaterThanOrEqual: (value: number) => Comparison;
|
|
27
|
+
isLessThan: (value: number) => Comparison;
|
|
28
|
+
isLessThanOrEqual: (value: number) => Comparison;
|
|
29
|
+
isInRange: (value: [number, number]) => Comparison;
|
|
19
30
|
};
|
|
20
31
|
jsonString: {
|
|
21
|
-
hasPartial: (value: any) =>
|
|
32
|
+
hasPartial: (value: any) => Comparison;
|
|
22
33
|
};
|
|
23
|
-
equal: (value: any) =>
|
|
24
|
-
partialEqual: (value: any) =>
|
|
25
|
-
custom: (isEqual: (value: unknown) => boolean) =>
|
|
34
|
+
equal: (value: any) => Comparison;
|
|
35
|
+
partialEqual: (value: any) => Comparison;
|
|
36
|
+
custom: (isEqual: (value: unknown) => boolean) => Comparison;
|
|
26
37
|
not: {
|
|
38
|
+
hasType: {
|
|
39
|
+
string: Comparison;
|
|
40
|
+
number: Comparison;
|
|
41
|
+
boolean: Comparison;
|
|
42
|
+
object: Comparison;
|
|
43
|
+
array: Comparison;
|
|
44
|
+
function: Comparison;
|
|
45
|
+
};
|
|
46
|
+
isInstanceOf: (constructor: new (...args: any[]) => any) => Comparison;
|
|
27
47
|
str: {
|
|
28
|
-
contains: (substring: string) =>
|
|
29
|
-
startsWith: (substring: string) =>
|
|
30
|
-
endsWith: (substring: string) =>
|
|
31
|
-
matchesRegex: (regex: RegExp) =>
|
|
48
|
+
contains: (substring: string) => Comparison;
|
|
49
|
+
startsWith: (substring: string) => Comparison;
|
|
50
|
+
endsWith: (substring: string) => Comparison;
|
|
51
|
+
matchesRegex: (regex: RegExp) => Comparison;
|
|
32
52
|
};
|
|
33
53
|
num: {
|
|
34
|
-
isGreaterThan: (value: number) =>
|
|
35
|
-
isGreaterThanOrEqual: (value: number) =>
|
|
36
|
-
isLessThan: (value: number) =>
|
|
37
|
-
isLessThanOrEqual: (value: number) =>
|
|
38
|
-
isInRange: (value: [number, number]) =>
|
|
54
|
+
isGreaterThan: (value: number) => Comparison;
|
|
55
|
+
isGreaterThanOrEqual: (value: number) => Comparison;
|
|
56
|
+
isLessThan: (value: number) => Comparison;
|
|
57
|
+
isLessThanOrEqual: (value: number) => Comparison;
|
|
58
|
+
isInRange: (value: [number, number]) => Comparison;
|
|
39
59
|
};
|
|
40
60
|
jsonString: {
|
|
41
|
-
hasPartial: (value: any) =>
|
|
61
|
+
hasPartial: (value: any) => Comparison;
|
|
42
62
|
};
|
|
43
|
-
equal: (value: any) =>
|
|
44
|
-
partialEqual: (value: any) =>
|
|
45
|
-
custom: (value: (target: unknown) => boolean) =>
|
|
63
|
+
equal: (value: any) => Comparison;
|
|
64
|
+
partialEqual: (value: any) => Comparison;
|
|
65
|
+
custom: (value: (target: unknown) => boolean) => Comparison;
|
|
46
66
|
};
|
|
47
67
|
};
|
|
48
68
|
declare function partialEqual(target: any, sub: any): boolean;
|
package/dist/partialEqual.js
CHANGED
|
@@ -4,52 +4,69 @@ import {
|
|
|
4
4
|
|
|
5
5
|
// src/partialEqual.ts
|
|
6
6
|
var has = Object.prototype.hasOwnProperty;
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
};
|
|
7
|
+
function createComparison(type) {
|
|
8
|
+
return {
|
|
9
|
+
"~sc": type
|
|
10
|
+
};
|
|
11
|
+
}
|
|
13
12
|
var match = {
|
|
13
|
+
hasType: {
|
|
14
|
+
string: createComparison(["hasType", "string"]),
|
|
15
|
+
number: createComparison(["hasType", "number"]),
|
|
16
|
+
boolean: createComparison(["hasType", "boolean"]),
|
|
17
|
+
object: createComparison(["hasType", "object"]),
|
|
18
|
+
array: createComparison(["hasType", "array"]),
|
|
19
|
+
function: createComparison(["hasType", "function"])
|
|
20
|
+
},
|
|
21
|
+
isInstanceOf: (constructor) => createComparison(["isInstanceOf", constructor]),
|
|
14
22
|
str: {
|
|
15
|
-
contains: (substring) =>
|
|
16
|
-
startsWith: (substring) =>
|
|
17
|
-
endsWith: (substring) =>
|
|
18
|
-
matchesRegex: (regex) =>
|
|
23
|
+
contains: (substring) => createComparison(["strContains", substring]),
|
|
24
|
+
startsWith: (substring) => createComparison(["strStartsWith", substring]),
|
|
25
|
+
endsWith: (substring) => createComparison(["strEndsWith", substring]),
|
|
26
|
+
matchesRegex: (regex) => createComparison(["strMatchesRegex", regex])
|
|
19
27
|
},
|
|
20
28
|
num: {
|
|
21
|
-
isGreaterThan: (value) =>
|
|
22
|
-
isGreaterThanOrEqual: (value) =>
|
|
23
|
-
isLessThan: (value) =>
|
|
24
|
-
isLessThanOrEqual: (value) =>
|
|
25
|
-
isInRange: (value) =>
|
|
29
|
+
isGreaterThan: (value) => createComparison(["numIsGreaterThan", value]),
|
|
30
|
+
isGreaterThanOrEqual: (value) => createComparison(["numIsGreaterThanOrEqual", value]),
|
|
31
|
+
isLessThan: (value) => createComparison(["numIsLessThan", value]),
|
|
32
|
+
isLessThanOrEqual: (value) => createComparison(["numIsLessThanOrEqual", value]),
|
|
33
|
+
isInRange: (value) => createComparison(["numIsInRange", value])
|
|
26
34
|
},
|
|
27
35
|
jsonString: {
|
|
28
|
-
hasPartial: (value) =>
|
|
36
|
+
hasPartial: (value) => createComparison(["jsonStringHasPartial", value])
|
|
29
37
|
},
|
|
30
|
-
equal: (value) =>
|
|
31
|
-
partialEqual: (value) =>
|
|
32
|
-
custom: (isEqual) =>
|
|
38
|
+
equal: (value) => createComparison(["deepEqual", value]),
|
|
39
|
+
partialEqual: (value) => createComparison(["partialEqual", value]),
|
|
40
|
+
custom: (isEqual) => createComparison(["custom", isEqual]),
|
|
33
41
|
not: {
|
|
42
|
+
hasType: {
|
|
43
|
+
string: createComparison(["not", ["hasType", "string"]]),
|
|
44
|
+
number: createComparison(["not", ["hasType", "number"]]),
|
|
45
|
+
boolean: createComparison(["not", ["hasType", "boolean"]]),
|
|
46
|
+
object: createComparison(["not", ["hasType", "object"]]),
|
|
47
|
+
array: createComparison(["not", ["hasType", "array"]]),
|
|
48
|
+
function: createComparison(["not", ["hasType", "function"]])
|
|
49
|
+
},
|
|
50
|
+
isInstanceOf: (constructor) => createComparison(["not", ["isInstanceOf", constructor]]),
|
|
34
51
|
str: {
|
|
35
|
-
contains: (substring) =>
|
|
36
|
-
startsWith: (substring) =>
|
|
37
|
-
endsWith: (substring) =>
|
|
38
|
-
matchesRegex: (regex) =>
|
|
52
|
+
contains: (substring) => createComparison(["not", ["strContains", substring]]),
|
|
53
|
+
startsWith: (substring) => createComparison(["not", ["strStartsWith", substring]]),
|
|
54
|
+
endsWith: (substring) => createComparison(["not", ["strEndsWith", substring]]),
|
|
55
|
+
matchesRegex: (regex) => createComparison(["not", ["strMatchesRegex", regex]])
|
|
39
56
|
},
|
|
40
57
|
num: {
|
|
41
|
-
isGreaterThan: (value) =>
|
|
42
|
-
isGreaterThanOrEqual: (value) =>
|
|
43
|
-
isLessThan: (value) =>
|
|
44
|
-
isLessThanOrEqual: (value) =>
|
|
45
|
-
isInRange: (value) =>
|
|
58
|
+
isGreaterThan: (value) => createComparison(["not", ["numIsGreaterThan", value]]),
|
|
59
|
+
isGreaterThanOrEqual: (value) => createComparison(["not", ["numIsGreaterThanOrEqual", value]]),
|
|
60
|
+
isLessThan: (value) => createComparison(["not", ["numIsLessThan", value]]),
|
|
61
|
+
isLessThanOrEqual: (value) => createComparison(["not", ["numIsLessThanOrEqual", value]]),
|
|
62
|
+
isInRange: (value) => createComparison(["not", ["numIsInRange", value]])
|
|
46
63
|
},
|
|
47
64
|
jsonString: {
|
|
48
|
-
hasPartial: (value) =>
|
|
65
|
+
hasPartial: (value) => createComparison(["not", ["jsonStringHasPartial", value]])
|
|
49
66
|
},
|
|
50
|
-
equal: (value) =>
|
|
51
|
-
partialEqual: (value) =>
|
|
52
|
-
custom: (value) =>
|
|
67
|
+
equal: (value) => createComparison(["not", ["deepEqual", value]]),
|
|
68
|
+
partialEqual: (value) => createComparison(["not", ["partialEqual", value]]),
|
|
69
|
+
custom: (value) => createComparison(["not", ["custom", value]])
|
|
53
70
|
}
|
|
54
71
|
};
|
|
55
72
|
function find(iter, tar) {
|
|
@@ -60,6 +77,25 @@ function find(iter, tar) {
|
|
|
60
77
|
function executeComparison(target, comparison) {
|
|
61
78
|
const [type, value] = comparison;
|
|
62
79
|
switch (type) {
|
|
80
|
+
case "hasType":
|
|
81
|
+
switch (value) {
|
|
82
|
+
case "string":
|
|
83
|
+
return typeof target === "string";
|
|
84
|
+
case "number":
|
|
85
|
+
return typeof target === "number";
|
|
86
|
+
case "boolean":
|
|
87
|
+
return typeof target === "boolean";
|
|
88
|
+
case "function":
|
|
89
|
+
return typeof target === "function";
|
|
90
|
+
case "array":
|
|
91
|
+
return Array.isArray(target);
|
|
92
|
+
case "object":
|
|
93
|
+
return typeof target === "object" && target !== null && !Array.isArray(target);
|
|
94
|
+
default:
|
|
95
|
+
return false;
|
|
96
|
+
}
|
|
97
|
+
case "isInstanceOf":
|
|
98
|
+
return target instanceof value;
|
|
63
99
|
case "strStartsWith":
|
|
64
100
|
return typeof target === "string" && target.startsWith(value);
|
|
65
101
|
case "strEndsWith":
|
|
@@ -100,8 +136,8 @@ function executeComparison(target, comparison) {
|
|
|
100
136
|
}
|
|
101
137
|
function partialEqual(target, sub) {
|
|
102
138
|
if (sub === target) return true;
|
|
103
|
-
if (sub
|
|
104
|
-
return executeComparison(target, sub
|
|
139
|
+
if (sub && typeof sub === "object" && "~sc" in sub) {
|
|
140
|
+
return executeComparison(target, sub["~sc"]);
|
|
105
141
|
}
|
|
106
142
|
if (sub && target && sub.constructor === target.constructor) {
|
|
107
143
|
const ctor = sub.constructor;
|