@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.
@@ -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
- var Comparisons = class {
95
- type;
96
- constructor(type) {
97
- this.type = type;
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) => new Comparisons(["strContains", substring]),
103
- startsWith: (substring) => new Comparisons(["strStartsWith", substring]),
104
- endsWith: (substring) => new Comparisons(["strEndsWith", substring]),
105
- matchesRegex: (regex) => new Comparisons(["strMatchesRegex", 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) => new Comparisons(["numIsGreaterThan", value]),
109
- isGreaterThanOrEqual: (value) => new Comparisons(["numIsGreaterThanOrEqual", value]),
110
- isLessThan: (value) => new Comparisons(["numIsLessThan", value]),
111
- isLessThanOrEqual: (value) => new Comparisons(["numIsLessThanOrEqual", value]),
112
- isInRange: (value) => new Comparisons(["numIsInRange", 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) => new Comparisons(["jsonStringHasPartial", value])
123
+ hasPartial: (value) => createComparison(["jsonStringHasPartial", value])
116
124
  },
117
- equal: (value) => new Comparisons(["deepEqual", value]),
118
- partialEqual: (value) => new Comparisons(["partialEqual", value]),
119
- custom: (isEqual) => new Comparisons(["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) => new Comparisons(["not", ["strContains", substring]]),
123
- startsWith: (substring) => new Comparisons(["not", ["strStartsWith", substring]]),
124
- endsWith: (substring) => new Comparisons(["not", ["strEndsWith", substring]]),
125
- matchesRegex: (regex) => new Comparisons(["not", ["strMatchesRegex", 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) => new Comparisons(["not", ["numIsGreaterThan", value]]),
129
- isGreaterThanOrEqual: (value) => new Comparisons(["not", ["numIsGreaterThanOrEqual", value]]),
130
- isLessThan: (value) => new Comparisons(["not", ["numIsLessThan", value]]),
131
- isLessThanOrEqual: (value) => new Comparisons(["not", ["numIsLessThanOrEqual", value]]),
132
- isInRange: (value) => new Comparisons(["not", ["numIsInRange", 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) => new Comparisons(["not", ["jsonStringHasPartial", value]])
152
+ hasPartial: (value) => createComparison(["not", ["jsonStringHasPartial", value]])
136
153
  },
137
- equal: (value) => new Comparisons(["not", ["deepEqual", value]]),
138
- partialEqual: (value) => new Comparisons(["not", ["partialEqual", value]]),
139
- custom: (value) => new Comparisons(["not", ["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 instanceof Comparisons) {
191
- return executeComparison(target, sub.type);
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;
@@ -1,48 +1,68 @@
1
- type ComparisonsType = [type: 'strStartsWith', value: string] | [type: 'strEndsWith', value: string] | [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: 'not', value: ComparisonsType];
2
- declare class Comparisons {
3
- type: ComparisonsType;
4
- constructor(type: ComparisonsType);
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) => Comparisons;
9
- startsWith: (substring: string) => Comparisons;
10
- endsWith: (substring: string) => Comparisons;
11
- matchesRegex: (regex: RegExp) => Comparisons;
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) => Comparisons;
15
- isGreaterThanOrEqual: (value: number) => Comparisons;
16
- isLessThan: (value: number) => Comparisons;
17
- isLessThanOrEqual: (value: number) => Comparisons;
18
- isInRange: (value: [number, number]) => Comparisons;
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) => Comparisons;
32
+ hasPartial: (value: any) => Comparison;
22
33
  };
23
- equal: (value: any) => Comparisons;
24
- partialEqual: (value: any) => Comparisons;
25
- custom: (isEqual: (value: unknown) => boolean) => Comparisons;
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) => Comparisons;
29
- startsWith: (substring: string) => Comparisons;
30
- endsWith: (substring: string) => Comparisons;
31
- matchesRegex: (regex: RegExp) => Comparisons;
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) => Comparisons;
35
- isGreaterThanOrEqual: (value: number) => Comparisons;
36
- isLessThan: (value: number) => Comparisons;
37
- isLessThanOrEqual: (value: number) => Comparisons;
38
- isInRange: (value: [number, number]) => Comparisons;
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) => Comparisons;
61
+ hasPartial: (value: any) => Comparison;
42
62
  };
43
- equal: (value: any) => Comparisons;
44
- partialEqual: (value: any) => Comparisons;
45
- custom: (value: (target: unknown) => boolean) => Comparisons;
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;
@@ -1,48 +1,68 @@
1
- type ComparisonsType = [type: 'strStartsWith', value: string] | [type: 'strEndsWith', value: string] | [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: 'not', value: ComparisonsType];
2
- declare class Comparisons {
3
- type: ComparisonsType;
4
- constructor(type: ComparisonsType);
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) => Comparisons;
9
- startsWith: (substring: string) => Comparisons;
10
- endsWith: (substring: string) => Comparisons;
11
- matchesRegex: (regex: RegExp) => Comparisons;
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) => Comparisons;
15
- isGreaterThanOrEqual: (value: number) => Comparisons;
16
- isLessThan: (value: number) => Comparisons;
17
- isLessThanOrEqual: (value: number) => Comparisons;
18
- isInRange: (value: [number, number]) => Comparisons;
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) => Comparisons;
32
+ hasPartial: (value: any) => Comparison;
22
33
  };
23
- equal: (value: any) => Comparisons;
24
- partialEqual: (value: any) => Comparisons;
25
- custom: (isEqual: (value: unknown) => boolean) => Comparisons;
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) => Comparisons;
29
- startsWith: (substring: string) => Comparisons;
30
- endsWith: (substring: string) => Comparisons;
31
- matchesRegex: (regex: RegExp) => Comparisons;
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) => Comparisons;
35
- isGreaterThanOrEqual: (value: number) => Comparisons;
36
- isLessThan: (value: number) => Comparisons;
37
- isLessThanOrEqual: (value: number) => Comparisons;
38
- isInRange: (value: [number, number]) => Comparisons;
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) => Comparisons;
61
+ hasPartial: (value: any) => Comparison;
42
62
  };
43
- equal: (value: any) => Comparisons;
44
- partialEqual: (value: any) => Comparisons;
45
- custom: (value: (target: unknown) => boolean) => Comparisons;
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;
@@ -4,52 +4,69 @@ import {
4
4
 
5
5
  // src/partialEqual.ts
6
6
  var has = Object.prototype.hasOwnProperty;
7
- var Comparisons = class {
8
- type;
9
- constructor(type) {
10
- this.type = type;
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) => new Comparisons(["strContains", substring]),
16
- startsWith: (substring) => new Comparisons(["strStartsWith", substring]),
17
- endsWith: (substring) => new Comparisons(["strEndsWith", substring]),
18
- matchesRegex: (regex) => new Comparisons(["strMatchesRegex", 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) => new Comparisons(["numIsGreaterThan", value]),
22
- isGreaterThanOrEqual: (value) => new Comparisons(["numIsGreaterThanOrEqual", value]),
23
- isLessThan: (value) => new Comparisons(["numIsLessThan", value]),
24
- isLessThanOrEqual: (value) => new Comparisons(["numIsLessThanOrEqual", value]),
25
- isInRange: (value) => new Comparisons(["numIsInRange", 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) => new Comparisons(["jsonStringHasPartial", value])
36
+ hasPartial: (value) => createComparison(["jsonStringHasPartial", value])
29
37
  },
30
- equal: (value) => new Comparisons(["deepEqual", value]),
31
- partialEqual: (value) => new Comparisons(["partialEqual", value]),
32
- custom: (isEqual) => new Comparisons(["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) => new Comparisons(["not", ["strContains", substring]]),
36
- startsWith: (substring) => new Comparisons(["not", ["strStartsWith", substring]]),
37
- endsWith: (substring) => new Comparisons(["not", ["strEndsWith", substring]]),
38
- matchesRegex: (regex) => new Comparisons(["not", ["strMatchesRegex", 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) => new Comparisons(["not", ["numIsGreaterThan", value]]),
42
- isGreaterThanOrEqual: (value) => new Comparisons(["not", ["numIsGreaterThanOrEqual", value]]),
43
- isLessThan: (value) => new Comparisons(["not", ["numIsLessThan", value]]),
44
- isLessThanOrEqual: (value) => new Comparisons(["not", ["numIsLessThanOrEqual", value]]),
45
- isInRange: (value) => new Comparisons(["not", ["numIsInRange", 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) => new Comparisons(["not", ["jsonStringHasPartial", value]])
65
+ hasPartial: (value) => createComparison(["not", ["jsonStringHasPartial", value]])
49
66
  },
50
- equal: (value) => new Comparisons(["not", ["deepEqual", value]]),
51
- partialEqual: (value) => new Comparisons(["not", ["partialEqual", value]]),
52
- custom: (value) => new Comparisons(["not", ["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 instanceof Comparisons) {
104
- return executeComparison(target, sub.type);
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;
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@ls-stack/utils",
3
3
  "description": "Universal TypeScript utilities for browser and Node.js",
4
- "version": "3.43.0",
4
+ "version": "3.44.1",
5
5
  "license": "MIT",
6
6
  "files": [
7
7
  "dist",