@ls-stack/utils 3.47.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.
@@ -1,7 +1,11 @@
1
+ import { Result } from 't-result';
2
+
1
3
  type ComparisonsType = [type: 'strStartsWith', value: string] | [type: 'strEndsWith', value: string] | [
2
4
  type: 'hasType',
3
5
  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[]] | [type: 'withNoExtraKeys', partialShape: any] | [type: 'withDeepNoExtraKeys', partialShape: any] | [type: 'noExtraDefinedKeys', partialShape: any] | [type: 'deepNoExtraDefinedKeys', partialShape: any];
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];
5
9
  type Comparison = {
6
10
  '~sc': ComparisonsType;
7
11
  };
@@ -37,15 +41,53 @@ type BaseMatch = {
37
41
  };
38
42
  equal: (value: any) => Comparison;
39
43
  partialEqual: (value: any) => Comparison;
40
- custom: (isEqual: (value: unknown) => boolean) => Comparison;
44
+ custom: (isEqual: (value: unknown) => boolean | {
45
+ error: string;
46
+ }) => Comparison;
41
47
  keyNotBePresent: Comparison;
42
- any: (...comparisons: Comparison[]) => Comparison;
43
- all: (...comparisons: Comparison[]) => Comparison;
48
+ any: (...values: any[]) => Comparison;
49
+ all: (...values: any[]) => Comparison;
44
50
  };
45
51
  type Match = BaseMatch & {
46
52
  not: BaseMatch;
47
53
  };
48
54
  declare const match: Match;
55
+ type PartialError = {
56
+ path: string;
57
+ message: string;
58
+ received?: any;
59
+ expected?: any;
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
+ */
90
+ declare function partialEqual(target: any, sub: any, returnErrors: true): Result<void, PartialError[]>;
49
91
  declare function partialEqual(target: any, sub: any): boolean;
50
92
 
51
93
  export { match, partialEqual };
@@ -1,7 +1,11 @@
1
+ import { Result } from 't-result';
2
+
1
3
  type ComparisonsType = [type: 'strStartsWith', value: string] | [type: 'strEndsWith', value: string] | [
2
4
  type: 'hasType',
3
5
  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[]] | [type: 'withNoExtraKeys', partialShape: any] | [type: 'withDeepNoExtraKeys', partialShape: any] | [type: 'noExtraDefinedKeys', partialShape: any] | [type: 'deepNoExtraDefinedKeys', partialShape: any];
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];
5
9
  type Comparison = {
6
10
  '~sc': ComparisonsType;
7
11
  };
@@ -37,15 +41,53 @@ type BaseMatch = {
37
41
  };
38
42
  equal: (value: any) => Comparison;
39
43
  partialEqual: (value: any) => Comparison;
40
- custom: (isEqual: (value: unknown) => boolean) => Comparison;
44
+ custom: (isEqual: (value: unknown) => boolean | {
45
+ error: string;
46
+ }) => Comparison;
41
47
  keyNotBePresent: Comparison;
42
- any: (...comparisons: Comparison[]) => Comparison;
43
- all: (...comparisons: Comparison[]) => Comparison;
48
+ any: (...values: any[]) => Comparison;
49
+ all: (...values: any[]) => Comparison;
44
50
  };
45
51
  type Match = BaseMatch & {
46
52
  not: BaseMatch;
47
53
  };
48
54
  declare const match: Match;
55
+ type PartialError = {
56
+ path: string;
57
+ message: string;
58
+ received?: any;
59
+ expected?: any;
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
+ */
90
+ declare function partialEqual(target: any, sub: any, returnErrors: true): Result<void, PartialError[]>;
49
91
  declare function partialEqual(target: any, sub: any): boolean;
50
92
 
51
93
  export { match, partialEqual };