@ls-stack/utils 3.48.0 → 3.49.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 +551 -695
- package/dist/partialEqual.d.cts +38 -5
- package/dist/partialEqual.d.ts +38 -5
- package/dist/partialEqual.js +550 -634
- package/package.json +1 -1
package/dist/partialEqual.d.cts
CHANGED
|
@@ -3,7 +3,9 @@ import { Result } from 't-result';
|
|
|
3
3
|
type ComparisonsType = [type: 'strStartsWith', value: string] | [type: 'strEndsWith', value: string] | [
|
|
4
4
|
type: 'hasType',
|
|
5
5
|
value: 'string' | 'number' | 'boolean' | 'object' | 'array' | 'function'
|
|
6
|
-
] | [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
|
|
6
|
+
] | [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 | {
|
|
7
|
+
error: string;
|
|
8
|
+
}] | [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];
|
|
7
9
|
type Comparison = {
|
|
8
10
|
'~sc': ComparisonsType;
|
|
9
11
|
};
|
|
@@ -39,10 +41,12 @@ type BaseMatch = {
|
|
|
39
41
|
};
|
|
40
42
|
equal: (value: any) => Comparison;
|
|
41
43
|
partialEqual: (value: any) => Comparison;
|
|
42
|
-
custom: (isEqual: (value: unknown) => boolean
|
|
44
|
+
custom: (isEqual: (value: unknown) => boolean | {
|
|
45
|
+
error: string;
|
|
46
|
+
}) => Comparison;
|
|
43
47
|
keyNotBePresent: Comparison;
|
|
44
|
-
any: (...
|
|
45
|
-
all: (...
|
|
48
|
+
any: (...values: any[]) => Comparison;
|
|
49
|
+
all: (...values: any[]) => Comparison;
|
|
46
50
|
};
|
|
47
51
|
type Match = BaseMatch & {
|
|
48
52
|
not: BaseMatch;
|
|
@@ -51,9 +55,38 @@ declare const match: Match;
|
|
|
51
55
|
type PartialError = {
|
|
52
56
|
path: string;
|
|
53
57
|
message: string;
|
|
54
|
-
received
|
|
58
|
+
received?: any;
|
|
55
59
|
expected?: any;
|
|
56
60
|
};
|
|
61
|
+
/**
|
|
62
|
+
* Checks if sub is a partial match of target (all properties in sub exist and
|
|
63
|
+
* match in target). Supports special comparison matchers for flexible pattern
|
|
64
|
+
* matching.
|
|
65
|
+
*
|
|
66
|
+
* @example
|
|
67
|
+
* // Basic partial matching
|
|
68
|
+
* partialEqual({ a: 1, b: 2 }, { a: 1 }); // true - sub is subset of target
|
|
69
|
+
* partialEqual([1, 2, 3], [1, 2]); // true - sub array is prefix of target
|
|
70
|
+
*
|
|
71
|
+
* // Special comparisons
|
|
72
|
+
* partialEqual('hello world', match.str.contains('world')); // true
|
|
73
|
+
* partialEqual(25, match.num.isGreaterThan(18)); // true
|
|
74
|
+
* partialEqual(
|
|
75
|
+
* 'test@example.com',
|
|
76
|
+
* match.custom((v) => typeof v === 'string' && v.includes('@')),
|
|
77
|
+
* ); // true
|
|
78
|
+
*
|
|
79
|
+
* // Complex nested matching
|
|
80
|
+
* partialEqual(
|
|
81
|
+
* { user: { name: 'John', age: 30 } },
|
|
82
|
+
* {
|
|
83
|
+
* user: {
|
|
84
|
+
* name: match.str.startsWith('J'),
|
|
85
|
+
* age: match.num.isGreaterThan(25),
|
|
86
|
+
* },
|
|
87
|
+
* },
|
|
88
|
+
* ); // true
|
|
89
|
+
*/
|
|
57
90
|
declare function partialEqual(target: any, sub: any, returnErrors: true): Result<void, PartialError[]>;
|
|
58
91
|
declare function partialEqual(target: any, sub: any): boolean;
|
|
59
92
|
|
package/dist/partialEqual.d.ts
CHANGED
|
@@ -3,7 +3,9 @@ import { Result } from 't-result';
|
|
|
3
3
|
type ComparisonsType = [type: 'strStartsWith', value: string] | [type: 'strEndsWith', value: string] | [
|
|
4
4
|
type: 'hasType',
|
|
5
5
|
value: 'string' | 'number' | 'boolean' | 'object' | 'array' | 'function'
|
|
6
|
-
] | [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
|
|
6
|
+
] | [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 | {
|
|
7
|
+
error: string;
|
|
8
|
+
}] | [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];
|
|
7
9
|
type Comparison = {
|
|
8
10
|
'~sc': ComparisonsType;
|
|
9
11
|
};
|
|
@@ -39,10 +41,12 @@ type BaseMatch = {
|
|
|
39
41
|
};
|
|
40
42
|
equal: (value: any) => Comparison;
|
|
41
43
|
partialEqual: (value: any) => Comparison;
|
|
42
|
-
custom: (isEqual: (value: unknown) => boolean
|
|
44
|
+
custom: (isEqual: (value: unknown) => boolean | {
|
|
45
|
+
error: string;
|
|
46
|
+
}) => Comparison;
|
|
43
47
|
keyNotBePresent: Comparison;
|
|
44
|
-
any: (...
|
|
45
|
-
all: (...
|
|
48
|
+
any: (...values: any[]) => Comparison;
|
|
49
|
+
all: (...values: any[]) => Comparison;
|
|
46
50
|
};
|
|
47
51
|
type Match = BaseMatch & {
|
|
48
52
|
not: BaseMatch;
|
|
@@ -51,9 +55,38 @@ declare const match: Match;
|
|
|
51
55
|
type PartialError = {
|
|
52
56
|
path: string;
|
|
53
57
|
message: string;
|
|
54
|
-
received
|
|
58
|
+
received?: any;
|
|
55
59
|
expected?: any;
|
|
56
60
|
};
|
|
61
|
+
/**
|
|
62
|
+
* Checks if sub is a partial match of target (all properties in sub exist and
|
|
63
|
+
* match in target). Supports special comparison matchers for flexible pattern
|
|
64
|
+
* matching.
|
|
65
|
+
*
|
|
66
|
+
* @example
|
|
67
|
+
* // Basic partial matching
|
|
68
|
+
* partialEqual({ a: 1, b: 2 }, { a: 1 }); // true - sub is subset of target
|
|
69
|
+
* partialEqual([1, 2, 3], [1, 2]); // true - sub array is prefix of target
|
|
70
|
+
*
|
|
71
|
+
* // Special comparisons
|
|
72
|
+
* partialEqual('hello world', match.str.contains('world')); // true
|
|
73
|
+
* partialEqual(25, match.num.isGreaterThan(18)); // true
|
|
74
|
+
* partialEqual(
|
|
75
|
+
* 'test@example.com',
|
|
76
|
+
* match.custom((v) => typeof v === 'string' && v.includes('@')),
|
|
77
|
+
* ); // true
|
|
78
|
+
*
|
|
79
|
+
* // Complex nested matching
|
|
80
|
+
* partialEqual(
|
|
81
|
+
* { user: { name: 'John', age: 30 } },
|
|
82
|
+
* {
|
|
83
|
+
* user: {
|
|
84
|
+
* name: match.str.startsWith('J'),
|
|
85
|
+
* age: match.num.isGreaterThan(25),
|
|
86
|
+
* },
|
|
87
|
+
* },
|
|
88
|
+
* ); // true
|
|
89
|
+
*/
|
|
57
90
|
declare function partialEqual(target: any, sub: any, returnErrors: true): Result<void, PartialError[]>;
|
|
58
91
|
declare function partialEqual(target: any, sub: any): boolean;
|
|
59
92
|
|