@ls-stack/utils 3.45.0 → 3.46.0
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 +138 -5
- package/dist/partialEqual.d.cts +10 -34
- package/dist/partialEqual.d.ts +10 -34
- package/dist/partialEqual.js +138 -5
- package/package.json +1 -1
package/dist/partialEqual.cjs
CHANGED
|
@@ -92,11 +92,13 @@ function deepEqual(foo, bar, maxDepth = 20) {
|
|
|
92
92
|
// src/partialEqual.ts
|
|
93
93
|
var has2 = Object.prototype.hasOwnProperty;
|
|
94
94
|
function createComparison(type) {
|
|
95
|
-
return {
|
|
96
|
-
"~sc": type
|
|
97
|
-
};
|
|
95
|
+
return { "~sc": type };
|
|
98
96
|
}
|
|
99
97
|
var match = {
|
|
98
|
+
noExtraKeys: (partialShape) => createComparison(["withNoExtraKeys", partialShape]),
|
|
99
|
+
deepNoExtraKeys: (partialShape) => createComparison(["withDeepNoExtraKeys", partialShape]),
|
|
100
|
+
noExtraDefinedKeys: (partialShape) => createComparison(["noExtraDefinedKeys", partialShape]),
|
|
101
|
+
deepNoExtraDefinedKeys: (partialShape) => createComparison(["deepNoExtraDefinedKeys", partialShape]),
|
|
100
102
|
hasType: {
|
|
101
103
|
string: createComparison(["hasType", "string"]),
|
|
102
104
|
number: createComparison(["hasType", "number"]),
|
|
@@ -137,6 +139,7 @@ var match = {
|
|
|
137
139
|
array: createComparison(["not", ["hasType", "array"]]),
|
|
138
140
|
function: createComparison(["not", ["hasType", "function"]])
|
|
139
141
|
},
|
|
142
|
+
keyNotBePresent: createComparison(["not", ["keyNotBePresent", null]]),
|
|
140
143
|
isInstanceOf: (constructor) => createComparison(["not", ["isInstanceOf", constructor]]),
|
|
141
144
|
str: {
|
|
142
145
|
contains: (substring) => createComparison(["not", ["strContains", substring]]),
|
|
@@ -158,7 +161,11 @@ var match = {
|
|
|
158
161
|
partialEqual: (value) => createComparison(["not", ["partialEqual", value]]),
|
|
159
162
|
custom: (value) => createComparison(["not", ["custom", value]]),
|
|
160
163
|
any: (...comparisons) => createComparison(["not", ["any", comparisons.map((c) => c["~sc"])]]),
|
|
161
|
-
all: (...comparisons) => createComparison(["not", ["all", comparisons.map((c) => c["~sc"])]])
|
|
164
|
+
all: (...comparisons) => createComparison(["not", ["all", comparisons.map((c) => c["~sc"])]]),
|
|
165
|
+
noExtraKeys: (partialShape) => createComparison(["not", ["withNoExtraKeys", partialShape]]),
|
|
166
|
+
deepNoExtraKeys: (partialShape) => createComparison(["not", ["withDeepNoExtraKeys", partialShape]]),
|
|
167
|
+
noExtraDefinedKeys: (partialShape) => createComparison(["not", ["noExtraDefinedKeys", partialShape]]),
|
|
168
|
+
deepNoExtraDefinedKeys: (partialShape) => createComparison(["not", ["deepNoExtraDefinedKeys", partialShape]])
|
|
162
169
|
}
|
|
163
170
|
};
|
|
164
171
|
function find2(iter, tar) {
|
|
@@ -256,6 +263,128 @@ function executeComparison(target, comparison) {
|
|
|
256
263
|
return true;
|
|
257
264
|
case "not":
|
|
258
265
|
return !executeComparison(target, value);
|
|
266
|
+
case "withNoExtraKeys":
|
|
267
|
+
if (typeof target !== "object" || target === null || Array.isArray(target)) {
|
|
268
|
+
return false;
|
|
269
|
+
}
|
|
270
|
+
if (typeof value !== "object" || value === null || Array.isArray(value)) {
|
|
271
|
+
return false;
|
|
272
|
+
}
|
|
273
|
+
for (const key in target) {
|
|
274
|
+
if (has2.call(target, key) && !has2.call(value, key)) {
|
|
275
|
+
return false;
|
|
276
|
+
}
|
|
277
|
+
}
|
|
278
|
+
for (const key in value) {
|
|
279
|
+
if (has2.call(value, key)) {
|
|
280
|
+
if (!has2.call(target, key)) {
|
|
281
|
+
return false;
|
|
282
|
+
}
|
|
283
|
+
if (!partialEqual(target[key], value[key])) {
|
|
284
|
+
return false;
|
|
285
|
+
}
|
|
286
|
+
}
|
|
287
|
+
}
|
|
288
|
+
return true;
|
|
289
|
+
case "withDeepNoExtraKeys":
|
|
290
|
+
if (typeof target !== "object" || target === null || Array.isArray(target)) {
|
|
291
|
+
return false;
|
|
292
|
+
}
|
|
293
|
+
if (typeof value !== "object" || value === null || Array.isArray(value)) {
|
|
294
|
+
return false;
|
|
295
|
+
}
|
|
296
|
+
for (const key in target) {
|
|
297
|
+
if (has2.call(target, key) && !has2.call(value, key)) {
|
|
298
|
+
return false;
|
|
299
|
+
}
|
|
300
|
+
}
|
|
301
|
+
for (const key in value) {
|
|
302
|
+
if (has2.call(value, key)) {
|
|
303
|
+
if (!has2.call(target, key)) {
|
|
304
|
+
return false;
|
|
305
|
+
}
|
|
306
|
+
const targetValue = target[key];
|
|
307
|
+
const partialValue = value[key];
|
|
308
|
+
if (partialValue && typeof partialValue === "object" && "~sc" in partialValue && partialValue["~sc"][0] === "withDeepNoExtraKeys") {
|
|
309
|
+
if (!executeComparison(targetValue, partialValue["~sc"])) {
|
|
310
|
+
return false;
|
|
311
|
+
}
|
|
312
|
+
} else if (partialValue && typeof partialValue === "object" && !Array.isArray(partialValue) && partialValue.constructor === Object && targetValue && typeof targetValue === "object" && !Array.isArray(targetValue) && targetValue.constructor === Object) {
|
|
313
|
+
if (!executeComparison(targetValue, [
|
|
314
|
+
"withDeepNoExtraKeys",
|
|
315
|
+
partialValue
|
|
316
|
+
])) {
|
|
317
|
+
return false;
|
|
318
|
+
}
|
|
319
|
+
} else {
|
|
320
|
+
if (!partialEqual(targetValue, partialValue)) {
|
|
321
|
+
return false;
|
|
322
|
+
}
|
|
323
|
+
}
|
|
324
|
+
}
|
|
325
|
+
}
|
|
326
|
+
return true;
|
|
327
|
+
case "noExtraDefinedKeys":
|
|
328
|
+
if (typeof target !== "object" || target === null || Array.isArray(target)) {
|
|
329
|
+
return false;
|
|
330
|
+
}
|
|
331
|
+
if (typeof value !== "object" || value === null || Array.isArray(value)) {
|
|
332
|
+
return false;
|
|
333
|
+
}
|
|
334
|
+
for (const key in target) {
|
|
335
|
+
if (has2.call(target, key) && target[key] !== void 0 && !has2.call(value, key)) {
|
|
336
|
+
return false;
|
|
337
|
+
}
|
|
338
|
+
}
|
|
339
|
+
for (const key in value) {
|
|
340
|
+
if (has2.call(value, key)) {
|
|
341
|
+
if (!has2.call(target, key)) {
|
|
342
|
+
return false;
|
|
343
|
+
}
|
|
344
|
+
if (!partialEqual(target[key], value[key])) {
|
|
345
|
+
return false;
|
|
346
|
+
}
|
|
347
|
+
}
|
|
348
|
+
}
|
|
349
|
+
return true;
|
|
350
|
+
case "deepNoExtraDefinedKeys":
|
|
351
|
+
if (typeof target !== "object" || target === null || Array.isArray(target)) {
|
|
352
|
+
return false;
|
|
353
|
+
}
|
|
354
|
+
if (typeof value !== "object" || value === null || Array.isArray(value)) {
|
|
355
|
+
return false;
|
|
356
|
+
}
|
|
357
|
+
for (const key in target) {
|
|
358
|
+
if (has2.call(target, key) && target[key] !== void 0 && !has2.call(value, key)) {
|
|
359
|
+
return false;
|
|
360
|
+
}
|
|
361
|
+
}
|
|
362
|
+
for (const key in value) {
|
|
363
|
+
if (has2.call(value, key)) {
|
|
364
|
+
if (!has2.call(target, key)) {
|
|
365
|
+
return false;
|
|
366
|
+
}
|
|
367
|
+
const targetValue = target[key];
|
|
368
|
+
const partialValue = value[key];
|
|
369
|
+
if (partialValue && typeof partialValue === "object" && "~sc" in partialValue && partialValue["~sc"][0] === "deepNoExtraDefinedKeys") {
|
|
370
|
+
if (!executeComparison(targetValue, partialValue["~sc"])) {
|
|
371
|
+
return false;
|
|
372
|
+
}
|
|
373
|
+
} else if (partialValue && typeof partialValue === "object" && !Array.isArray(partialValue) && partialValue.constructor === Object && targetValue && typeof targetValue === "object" && !Array.isArray(targetValue) && targetValue.constructor === Object) {
|
|
374
|
+
if (!executeComparison(targetValue, [
|
|
375
|
+
"deepNoExtraDefinedKeys",
|
|
376
|
+
partialValue
|
|
377
|
+
])) {
|
|
378
|
+
return false;
|
|
379
|
+
}
|
|
380
|
+
} else {
|
|
381
|
+
if (!partialEqual(targetValue, partialValue)) {
|
|
382
|
+
return false;
|
|
383
|
+
}
|
|
384
|
+
}
|
|
385
|
+
}
|
|
386
|
+
}
|
|
387
|
+
return true;
|
|
259
388
|
default:
|
|
260
389
|
return false;
|
|
261
390
|
}
|
|
@@ -318,7 +447,11 @@ function partialEqual(target, sub) {
|
|
|
318
447
|
} else if (subValue && typeof subValue === "object" && "~sc" in subValue && subValue["~sc"][0] === "any") {
|
|
319
448
|
const targetHasKey = has2.call(target, key);
|
|
320
449
|
const targetValue = targetHasKey ? target[key] : void 0;
|
|
321
|
-
if (!executeComparisonWithKeyContext(
|
|
450
|
+
if (!executeComparisonWithKeyContext(
|
|
451
|
+
targetValue,
|
|
452
|
+
subValue["~sc"],
|
|
453
|
+
targetHasKey
|
|
454
|
+
)) {
|
|
322
455
|
return false;
|
|
323
456
|
}
|
|
324
457
|
} else {
|
package/dist/partialEqual.d.cts
CHANGED
|
@@ -1,11 +1,15 @@
|
|
|
1
1
|
type ComparisonsType = [type: 'strStartsWith', value: string] | [type: 'strEndsWith', value: string] | [
|
|
2
2
|
type: 'hasType',
|
|
3
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: 'keyNotBePresent', value: null] | [type: 'not', value: ComparisonsType] | [type: 'any', value: ComparisonsType[]] | [type: 'all', value: ComparisonsType[]];
|
|
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: 'keyNotBePresent', value: null] | [type: 'not', value: ComparisonsType] | [type: 'any', value: ComparisonsType[]] | [type: 'all', value: ComparisonsType[]] | [type: 'withNoExtraKeys', partialShape: any] | [type: 'withDeepNoExtraKeys', partialShape: any] | [type: 'noExtraDefinedKeys', partialShape: any] | [type: 'deepNoExtraDefinedKeys', partialShape: any];
|
|
5
5
|
type Comparison = {
|
|
6
6
|
'~sc': ComparisonsType;
|
|
7
7
|
};
|
|
8
|
-
|
|
8
|
+
type BaseMatch = {
|
|
9
|
+
noExtraKeys: (partialShape: any) => Comparison;
|
|
10
|
+
deepNoExtraKeys: (partialShape: any) => Comparison;
|
|
11
|
+
noExtraDefinedKeys: (partialShape: any) => Comparison;
|
|
12
|
+
deepNoExtraDefinedKeys: (partialShape: any) => Comparison;
|
|
9
13
|
hasType: {
|
|
10
14
|
string: Comparison;
|
|
11
15
|
number: Comparison;
|
|
@@ -37,39 +41,11 @@ declare const match: {
|
|
|
37
41
|
keyNotBePresent: Comparison;
|
|
38
42
|
any: (...comparisons: Comparison[]) => Comparison;
|
|
39
43
|
all: (...comparisons: Comparison[]) => Comparison;
|
|
40
|
-
not: {
|
|
41
|
-
hasType: {
|
|
42
|
-
string: Comparison;
|
|
43
|
-
number: Comparison;
|
|
44
|
-
boolean: Comparison;
|
|
45
|
-
object: Comparison;
|
|
46
|
-
array: Comparison;
|
|
47
|
-
function: Comparison;
|
|
48
|
-
};
|
|
49
|
-
isInstanceOf: (constructor: new (...args: any[]) => any) => Comparison;
|
|
50
|
-
str: {
|
|
51
|
-
contains: (substring: string) => Comparison;
|
|
52
|
-
startsWith: (substring: string) => Comparison;
|
|
53
|
-
endsWith: (substring: string) => Comparison;
|
|
54
|
-
matchesRegex: (regex: RegExp) => Comparison;
|
|
55
|
-
};
|
|
56
|
-
num: {
|
|
57
|
-
isGreaterThan: (value: number) => Comparison;
|
|
58
|
-
isGreaterThanOrEqual: (value: number) => Comparison;
|
|
59
|
-
isLessThan: (value: number) => Comparison;
|
|
60
|
-
isLessThanOrEqual: (value: number) => Comparison;
|
|
61
|
-
isInRange: (value: [number, number]) => Comparison;
|
|
62
|
-
};
|
|
63
|
-
jsonString: {
|
|
64
|
-
hasPartial: (value: any) => Comparison;
|
|
65
|
-
};
|
|
66
|
-
equal: (value: any) => Comparison;
|
|
67
|
-
partialEqual: (value: any) => Comparison;
|
|
68
|
-
custom: (value: (target: unknown) => boolean) => Comparison;
|
|
69
|
-
any: (...comparisons: Comparison[]) => Comparison;
|
|
70
|
-
all: (...comparisons: Comparison[]) => Comparison;
|
|
71
|
-
};
|
|
72
44
|
};
|
|
45
|
+
type Match = BaseMatch & {
|
|
46
|
+
not: BaseMatch;
|
|
47
|
+
};
|
|
48
|
+
declare const match: Match;
|
|
73
49
|
declare function partialEqual(target: any, sub: any): boolean;
|
|
74
50
|
|
|
75
51
|
export { match, partialEqual };
|
package/dist/partialEqual.d.ts
CHANGED
|
@@ -1,11 +1,15 @@
|
|
|
1
1
|
type ComparisonsType = [type: 'strStartsWith', value: string] | [type: 'strEndsWith', value: string] | [
|
|
2
2
|
type: 'hasType',
|
|
3
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: 'keyNotBePresent', value: null] | [type: 'not', value: ComparisonsType] | [type: 'any', value: ComparisonsType[]] | [type: 'all', value: ComparisonsType[]];
|
|
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: 'keyNotBePresent', value: null] | [type: 'not', value: ComparisonsType] | [type: 'any', value: ComparisonsType[]] | [type: 'all', value: ComparisonsType[]] | [type: 'withNoExtraKeys', partialShape: any] | [type: 'withDeepNoExtraKeys', partialShape: any] | [type: 'noExtraDefinedKeys', partialShape: any] | [type: 'deepNoExtraDefinedKeys', partialShape: any];
|
|
5
5
|
type Comparison = {
|
|
6
6
|
'~sc': ComparisonsType;
|
|
7
7
|
};
|
|
8
|
-
|
|
8
|
+
type BaseMatch = {
|
|
9
|
+
noExtraKeys: (partialShape: any) => Comparison;
|
|
10
|
+
deepNoExtraKeys: (partialShape: any) => Comparison;
|
|
11
|
+
noExtraDefinedKeys: (partialShape: any) => Comparison;
|
|
12
|
+
deepNoExtraDefinedKeys: (partialShape: any) => Comparison;
|
|
9
13
|
hasType: {
|
|
10
14
|
string: Comparison;
|
|
11
15
|
number: Comparison;
|
|
@@ -37,39 +41,11 @@ declare const match: {
|
|
|
37
41
|
keyNotBePresent: Comparison;
|
|
38
42
|
any: (...comparisons: Comparison[]) => Comparison;
|
|
39
43
|
all: (...comparisons: Comparison[]) => Comparison;
|
|
40
|
-
not: {
|
|
41
|
-
hasType: {
|
|
42
|
-
string: Comparison;
|
|
43
|
-
number: Comparison;
|
|
44
|
-
boolean: Comparison;
|
|
45
|
-
object: Comparison;
|
|
46
|
-
array: Comparison;
|
|
47
|
-
function: Comparison;
|
|
48
|
-
};
|
|
49
|
-
isInstanceOf: (constructor: new (...args: any[]) => any) => Comparison;
|
|
50
|
-
str: {
|
|
51
|
-
contains: (substring: string) => Comparison;
|
|
52
|
-
startsWith: (substring: string) => Comparison;
|
|
53
|
-
endsWith: (substring: string) => Comparison;
|
|
54
|
-
matchesRegex: (regex: RegExp) => Comparison;
|
|
55
|
-
};
|
|
56
|
-
num: {
|
|
57
|
-
isGreaterThan: (value: number) => Comparison;
|
|
58
|
-
isGreaterThanOrEqual: (value: number) => Comparison;
|
|
59
|
-
isLessThan: (value: number) => Comparison;
|
|
60
|
-
isLessThanOrEqual: (value: number) => Comparison;
|
|
61
|
-
isInRange: (value: [number, number]) => Comparison;
|
|
62
|
-
};
|
|
63
|
-
jsonString: {
|
|
64
|
-
hasPartial: (value: any) => Comparison;
|
|
65
|
-
};
|
|
66
|
-
equal: (value: any) => Comparison;
|
|
67
|
-
partialEqual: (value: any) => Comparison;
|
|
68
|
-
custom: (value: (target: unknown) => boolean) => Comparison;
|
|
69
|
-
any: (...comparisons: Comparison[]) => Comparison;
|
|
70
|
-
all: (...comparisons: Comparison[]) => Comparison;
|
|
71
|
-
};
|
|
72
44
|
};
|
|
45
|
+
type Match = BaseMatch & {
|
|
46
|
+
not: BaseMatch;
|
|
47
|
+
};
|
|
48
|
+
declare const match: Match;
|
|
73
49
|
declare function partialEqual(target: any, sub: any): boolean;
|
|
74
50
|
|
|
75
51
|
export { match, partialEqual };
|
package/dist/partialEqual.js
CHANGED
|
@@ -5,11 +5,13 @@ import {
|
|
|
5
5
|
// src/partialEqual.ts
|
|
6
6
|
var has = Object.prototype.hasOwnProperty;
|
|
7
7
|
function createComparison(type) {
|
|
8
|
-
return {
|
|
9
|
-
"~sc": type
|
|
10
|
-
};
|
|
8
|
+
return { "~sc": type };
|
|
11
9
|
}
|
|
12
10
|
var match = {
|
|
11
|
+
noExtraKeys: (partialShape) => createComparison(["withNoExtraKeys", partialShape]),
|
|
12
|
+
deepNoExtraKeys: (partialShape) => createComparison(["withDeepNoExtraKeys", partialShape]),
|
|
13
|
+
noExtraDefinedKeys: (partialShape) => createComparison(["noExtraDefinedKeys", partialShape]),
|
|
14
|
+
deepNoExtraDefinedKeys: (partialShape) => createComparison(["deepNoExtraDefinedKeys", partialShape]),
|
|
13
15
|
hasType: {
|
|
14
16
|
string: createComparison(["hasType", "string"]),
|
|
15
17
|
number: createComparison(["hasType", "number"]),
|
|
@@ -50,6 +52,7 @@ var match = {
|
|
|
50
52
|
array: createComparison(["not", ["hasType", "array"]]),
|
|
51
53
|
function: createComparison(["not", ["hasType", "function"]])
|
|
52
54
|
},
|
|
55
|
+
keyNotBePresent: createComparison(["not", ["keyNotBePresent", null]]),
|
|
53
56
|
isInstanceOf: (constructor) => createComparison(["not", ["isInstanceOf", constructor]]),
|
|
54
57
|
str: {
|
|
55
58
|
contains: (substring) => createComparison(["not", ["strContains", substring]]),
|
|
@@ -71,7 +74,11 @@ var match = {
|
|
|
71
74
|
partialEqual: (value) => createComparison(["not", ["partialEqual", value]]),
|
|
72
75
|
custom: (value) => createComparison(["not", ["custom", value]]),
|
|
73
76
|
any: (...comparisons) => createComparison(["not", ["any", comparisons.map((c) => c["~sc"])]]),
|
|
74
|
-
all: (...comparisons) => createComparison(["not", ["all", comparisons.map((c) => c["~sc"])]])
|
|
77
|
+
all: (...comparisons) => createComparison(["not", ["all", comparisons.map((c) => c["~sc"])]]),
|
|
78
|
+
noExtraKeys: (partialShape) => createComparison(["not", ["withNoExtraKeys", partialShape]]),
|
|
79
|
+
deepNoExtraKeys: (partialShape) => createComparison(["not", ["withDeepNoExtraKeys", partialShape]]),
|
|
80
|
+
noExtraDefinedKeys: (partialShape) => createComparison(["not", ["noExtraDefinedKeys", partialShape]]),
|
|
81
|
+
deepNoExtraDefinedKeys: (partialShape) => createComparison(["not", ["deepNoExtraDefinedKeys", partialShape]])
|
|
75
82
|
}
|
|
76
83
|
};
|
|
77
84
|
function find(iter, tar) {
|
|
@@ -169,6 +176,128 @@ function executeComparison(target, comparison) {
|
|
|
169
176
|
return true;
|
|
170
177
|
case "not":
|
|
171
178
|
return !executeComparison(target, value);
|
|
179
|
+
case "withNoExtraKeys":
|
|
180
|
+
if (typeof target !== "object" || target === null || Array.isArray(target)) {
|
|
181
|
+
return false;
|
|
182
|
+
}
|
|
183
|
+
if (typeof value !== "object" || value === null || Array.isArray(value)) {
|
|
184
|
+
return false;
|
|
185
|
+
}
|
|
186
|
+
for (const key in target) {
|
|
187
|
+
if (has.call(target, key) && !has.call(value, key)) {
|
|
188
|
+
return false;
|
|
189
|
+
}
|
|
190
|
+
}
|
|
191
|
+
for (const key in value) {
|
|
192
|
+
if (has.call(value, key)) {
|
|
193
|
+
if (!has.call(target, key)) {
|
|
194
|
+
return false;
|
|
195
|
+
}
|
|
196
|
+
if (!partialEqual(target[key], value[key])) {
|
|
197
|
+
return false;
|
|
198
|
+
}
|
|
199
|
+
}
|
|
200
|
+
}
|
|
201
|
+
return true;
|
|
202
|
+
case "withDeepNoExtraKeys":
|
|
203
|
+
if (typeof target !== "object" || target === null || Array.isArray(target)) {
|
|
204
|
+
return false;
|
|
205
|
+
}
|
|
206
|
+
if (typeof value !== "object" || value === null || Array.isArray(value)) {
|
|
207
|
+
return false;
|
|
208
|
+
}
|
|
209
|
+
for (const key in target) {
|
|
210
|
+
if (has.call(target, key) && !has.call(value, key)) {
|
|
211
|
+
return false;
|
|
212
|
+
}
|
|
213
|
+
}
|
|
214
|
+
for (const key in value) {
|
|
215
|
+
if (has.call(value, key)) {
|
|
216
|
+
if (!has.call(target, key)) {
|
|
217
|
+
return false;
|
|
218
|
+
}
|
|
219
|
+
const targetValue = target[key];
|
|
220
|
+
const partialValue = value[key];
|
|
221
|
+
if (partialValue && typeof partialValue === "object" && "~sc" in partialValue && partialValue["~sc"][0] === "withDeepNoExtraKeys") {
|
|
222
|
+
if (!executeComparison(targetValue, partialValue["~sc"])) {
|
|
223
|
+
return false;
|
|
224
|
+
}
|
|
225
|
+
} else if (partialValue && typeof partialValue === "object" && !Array.isArray(partialValue) && partialValue.constructor === Object && targetValue && typeof targetValue === "object" && !Array.isArray(targetValue) && targetValue.constructor === Object) {
|
|
226
|
+
if (!executeComparison(targetValue, [
|
|
227
|
+
"withDeepNoExtraKeys",
|
|
228
|
+
partialValue
|
|
229
|
+
])) {
|
|
230
|
+
return false;
|
|
231
|
+
}
|
|
232
|
+
} else {
|
|
233
|
+
if (!partialEqual(targetValue, partialValue)) {
|
|
234
|
+
return false;
|
|
235
|
+
}
|
|
236
|
+
}
|
|
237
|
+
}
|
|
238
|
+
}
|
|
239
|
+
return true;
|
|
240
|
+
case "noExtraDefinedKeys":
|
|
241
|
+
if (typeof target !== "object" || target === null || Array.isArray(target)) {
|
|
242
|
+
return false;
|
|
243
|
+
}
|
|
244
|
+
if (typeof value !== "object" || value === null || Array.isArray(value)) {
|
|
245
|
+
return false;
|
|
246
|
+
}
|
|
247
|
+
for (const key in target) {
|
|
248
|
+
if (has.call(target, key) && target[key] !== void 0 && !has.call(value, key)) {
|
|
249
|
+
return false;
|
|
250
|
+
}
|
|
251
|
+
}
|
|
252
|
+
for (const key in value) {
|
|
253
|
+
if (has.call(value, key)) {
|
|
254
|
+
if (!has.call(target, key)) {
|
|
255
|
+
return false;
|
|
256
|
+
}
|
|
257
|
+
if (!partialEqual(target[key], value[key])) {
|
|
258
|
+
return false;
|
|
259
|
+
}
|
|
260
|
+
}
|
|
261
|
+
}
|
|
262
|
+
return true;
|
|
263
|
+
case "deepNoExtraDefinedKeys":
|
|
264
|
+
if (typeof target !== "object" || target === null || Array.isArray(target)) {
|
|
265
|
+
return false;
|
|
266
|
+
}
|
|
267
|
+
if (typeof value !== "object" || value === null || Array.isArray(value)) {
|
|
268
|
+
return false;
|
|
269
|
+
}
|
|
270
|
+
for (const key in target) {
|
|
271
|
+
if (has.call(target, key) && target[key] !== void 0 && !has.call(value, key)) {
|
|
272
|
+
return false;
|
|
273
|
+
}
|
|
274
|
+
}
|
|
275
|
+
for (const key in value) {
|
|
276
|
+
if (has.call(value, key)) {
|
|
277
|
+
if (!has.call(target, key)) {
|
|
278
|
+
return false;
|
|
279
|
+
}
|
|
280
|
+
const targetValue = target[key];
|
|
281
|
+
const partialValue = value[key];
|
|
282
|
+
if (partialValue && typeof partialValue === "object" && "~sc" in partialValue && partialValue["~sc"][0] === "deepNoExtraDefinedKeys") {
|
|
283
|
+
if (!executeComparison(targetValue, partialValue["~sc"])) {
|
|
284
|
+
return false;
|
|
285
|
+
}
|
|
286
|
+
} else if (partialValue && typeof partialValue === "object" && !Array.isArray(partialValue) && partialValue.constructor === Object && targetValue && typeof targetValue === "object" && !Array.isArray(targetValue) && targetValue.constructor === Object) {
|
|
287
|
+
if (!executeComparison(targetValue, [
|
|
288
|
+
"deepNoExtraDefinedKeys",
|
|
289
|
+
partialValue
|
|
290
|
+
])) {
|
|
291
|
+
return false;
|
|
292
|
+
}
|
|
293
|
+
} else {
|
|
294
|
+
if (!partialEqual(targetValue, partialValue)) {
|
|
295
|
+
return false;
|
|
296
|
+
}
|
|
297
|
+
}
|
|
298
|
+
}
|
|
299
|
+
}
|
|
300
|
+
return true;
|
|
172
301
|
default:
|
|
173
302
|
return false;
|
|
174
303
|
}
|
|
@@ -231,7 +360,11 @@ function partialEqual(target, sub) {
|
|
|
231
360
|
} else if (subValue && typeof subValue === "object" && "~sc" in subValue && subValue["~sc"][0] === "any") {
|
|
232
361
|
const targetHasKey = has.call(target, key);
|
|
233
362
|
const targetValue = targetHasKey ? target[key] : void 0;
|
|
234
|
-
if (!executeComparisonWithKeyContext(
|
|
363
|
+
if (!executeComparisonWithKeyContext(
|
|
364
|
+
targetValue,
|
|
365
|
+
subValue["~sc"],
|
|
366
|
+
targetHasKey
|
|
367
|
+
)) {
|
|
235
368
|
return false;
|
|
236
369
|
}
|
|
237
370
|
} else {
|