@oscarpalmer/atoms 0.155.0 → 0.157.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/array/difference.js +5 -0
- package/dist/array/exists.js +2 -2
- package/dist/array/find.js +2 -2
- package/dist/array/index-of.js +2 -2
- package/dist/array/{misc.js → index.js} +6 -2
- package/dist/array/intersection.js +5 -0
- package/dist/array/slice.js +51 -0
- package/dist/array/union.js +5 -0
- package/dist/array/unique.js +2 -2
- package/dist/atoms.full.js +197 -113
- package/dist/index.js +9 -5
- package/dist/internal/array/find.js +5 -1
- package/dist/internal/array/sets.js +30 -0
- package/dist/value/merge.js +0 -6
- package/package.json +12 -12
- package/src/array/difference.ts +40 -0
- package/src/array/exists.ts +2 -2
- package/src/array/filter.ts +3 -3
- package/src/array/find.ts +2 -2
- package/src/array/index-of.ts +2 -2
- package/src/array/{misc.ts → index.ts} +4 -0
- package/src/array/intersection.ts +39 -0
- package/src/array/partition.ts +2 -2
- package/src/array/select.ts +2 -2
- package/src/array/slice.ts +245 -0
- package/src/array/union.ts +39 -0
- package/src/array/unique.ts +2 -2
- package/src/index.ts +3 -6
- package/src/internal/array/find.ts +14 -3
- package/src/internal/array/sets.ts +74 -0
- package/src/value/merge.ts +18 -2
- package/types/array/difference.d.ts +24 -0
- package/types/array/{misc.d.ts → index.d.ts} +4 -0
- package/types/array/intersection.d.ts +23 -0
- package/types/array/slice.d.ts +82 -0
- package/types/array/union.d.ts +23 -0
- package/types/index.d.ts +3 -6
- package/types/internal/array/find.d.ts +4 -0
- package/types/internal/array/sets.d.ts +6 -0
- package/types/value/merge.d.ts +7 -0
- /package/dist/string/{misc.js → index.js} +0 -0
- /package/dist/value/{misc.js → index.js} +0 -0
- /package/src/string/{misc.ts → index.ts} +0 -0
- /package/src/value/{misc.ts → index.ts} +0 -0
- /package/types/string/{misc.d.ts → index.d.ts} +0 -0
- /package/types/value/{misc.d.ts → index.d.ts} +0 -0
package/dist/array/exists.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
import { findValue } from "../internal/array/find.js";
|
|
1
|
+
import { FIND_VALUE_INDEX, findValue } from "../internal/array/find.js";
|
|
2
2
|
function exists(array, ...parameters) {
|
|
3
3
|
if (parameters.length === 1 && typeof parameters[0] !== "function") return Array.isArray(array) ? array.includes(parameters[0]) : false;
|
|
4
|
-
return findValue(
|
|
4
|
+
return findValue(FIND_VALUE_INDEX, array, parameters) > -1;
|
|
5
5
|
}
|
|
6
6
|
export { exists };
|
package/dist/array/find.js
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import { findValue } from "../internal/array/find.js";
|
|
1
|
+
import { FIND_VALUE_VALUE, findValue } from "../internal/array/find.js";
|
|
2
2
|
function find(array, ...parameters) {
|
|
3
|
-
return findValue(
|
|
3
|
+
return findValue(FIND_VALUE_VALUE, array, parameters);
|
|
4
4
|
}
|
|
5
5
|
export { find };
|
package/dist/array/index-of.js
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import { findValue } from "../internal/array/find.js";
|
|
1
|
+
import { FIND_VALUE_INDEX, findValue } from "../internal/array/find.js";
|
|
2
2
|
function indexOf(array, ...parameters) {
|
|
3
|
-
return findValue(
|
|
3
|
+
return findValue(FIND_VALUE_INDEX, array, parameters);
|
|
4
4
|
}
|
|
5
5
|
export { indexOf };
|
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import { difference } from "./difference.js";
|
|
1
2
|
import { exists } from "./exists.js";
|
|
2
3
|
import { filter } from "./filter.js";
|
|
3
4
|
import { find } from "./find.js";
|
|
@@ -6,15 +7,18 @@ import { range, times } from "./from.js";
|
|
|
6
7
|
import { getArray } from "./get.js";
|
|
7
8
|
import { indexOf } from "./index-of.js";
|
|
8
9
|
import { chunk } from "../internal/array/chunk.js";
|
|
9
|
-
import { insert } from "./insert.js";
|
|
10
10
|
import { compact } from "../internal/array/compact.js";
|
|
11
11
|
import { shuffle } from "../internal/array/shuffle.js";
|
|
12
|
+
import { insert } from "./insert.js";
|
|
13
|
+
import { intersection } from "./intersection.js";
|
|
12
14
|
import { partition } from "./partition.js";
|
|
13
15
|
import { push } from "./push.js";
|
|
14
16
|
import { select } from "./select.js";
|
|
17
|
+
import { drop, slice, take } from "./slice.js";
|
|
15
18
|
import { sort } from "./sort.js";
|
|
16
19
|
import { splice } from "./splice.js";
|
|
17
20
|
import { toSet } from "./to-set.js";
|
|
18
21
|
import { toggle } from "./toggle.js";
|
|
22
|
+
import { union } from "./union.js";
|
|
19
23
|
import { update } from "./update.js";
|
|
20
|
-
export { chunk, compact, exists, filter, find, flatten, getArray, indexOf, insert, partition, push, range, select, shuffle, sort, splice, times, toSet, toggle, update };
|
|
24
|
+
export { chunk, compact, difference, drop, exists, filter, find, flatten, getArray, indexOf, insert, intersection, partition, push, range, select, shuffle, slice, sort, splice, take, times, toSet, toggle, union, update };
|
|
@@ -0,0 +1,51 @@
|
|
|
1
|
+
import { getArrayCallbacks } from "../internal/array/callbacks.js";
|
|
2
|
+
function drop(array, first, second) {
|
|
3
|
+
return extract(EXTRACT_DROP, array, first, second);
|
|
4
|
+
}
|
|
5
|
+
function extract(type, array, first, second) {
|
|
6
|
+
if (!Array.isArray(array)) return [];
|
|
7
|
+
const { length } = array;
|
|
8
|
+
if (length === 0) return [];
|
|
9
|
+
const isTake = type === EXTRACT_TAKE;
|
|
10
|
+
if (typeof first === "number") {
|
|
11
|
+
if (Math.abs(first) >= length) return isTake ? array.slice() : [];
|
|
12
|
+
if (first === 0) return isTake ? [] : array.slice();
|
|
13
|
+
if (isTake) return first >= 0 ? array.slice(0, first) : array.slice(array.length + first);
|
|
14
|
+
return first >= 0 ? array.slice(first) : array.slice(0, array.length + first);
|
|
15
|
+
}
|
|
16
|
+
const callbacks = second == null ? getArrayCallbacks(first) : getArrayCallbacks(void 0, void 0, first);
|
|
17
|
+
const isBoolean = callbacks?.bool != null;
|
|
18
|
+
if (callbacks?.bool == null && callbacks?.value == null) return isTake ? array.slice() : [];
|
|
19
|
+
const extracted = [];
|
|
20
|
+
let push = false;
|
|
21
|
+
for (let index = 0; index < length; index += 1) {
|
|
22
|
+
const item = array[index];
|
|
23
|
+
const matches = isBoolean ? callbacks.bool(item, index, array) : Object.is(callbacks.value(item, index, array), second);
|
|
24
|
+
if (isTake) {
|
|
25
|
+
if (isBoolean ? !matches : matches) break;
|
|
26
|
+
extracted.push(item);
|
|
27
|
+
continue;
|
|
28
|
+
}
|
|
29
|
+
if (push) extracted.push(item);
|
|
30
|
+
else if (isBoolean ? !matches : matches) {
|
|
31
|
+
push = true;
|
|
32
|
+
if (isBoolean) extracted.push(item);
|
|
33
|
+
}
|
|
34
|
+
}
|
|
35
|
+
return extracted;
|
|
36
|
+
}
|
|
37
|
+
function slice(array, first, second) {
|
|
38
|
+
if (!Array.isArray(array) || array.length === 0) return [];
|
|
39
|
+
const firstIsNumber = typeof first === "number";
|
|
40
|
+
const secondIsNumber = typeof second === "number";
|
|
41
|
+
if (!firstIsNumber && !secondIsNumber) return array.slice();
|
|
42
|
+
if (!secondIsNumber) return first >= 0 ? array.slice(0, first) : array.slice(array.length + first);
|
|
43
|
+
if (!firstIsNumber) return array.slice();
|
|
44
|
+
return first >= 0 ? array.slice(first, second) : array.slice(array.length + first, array.length + second);
|
|
45
|
+
}
|
|
46
|
+
function take(array, first, second) {
|
|
47
|
+
return extract(EXTRACT_TAKE, array, first, second);
|
|
48
|
+
}
|
|
49
|
+
var EXTRACT_DROP = "drop";
|
|
50
|
+
var EXTRACT_TAKE = "take";
|
|
51
|
+
export { drop, slice, take };
|
package/dist/array/unique.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
import { findValues } from "../internal/array/find.js";
|
|
1
|
+
import { FIND_VALUES_UNIQUE, findValues } from "../internal/array/find.js";
|
|
2
2
|
function unique(array, key) {
|
|
3
3
|
if (!Array.isArray(array)) return [];
|
|
4
|
-
return array.length > 1 ? findValues(
|
|
4
|
+
return array.length > 1 ? findValues(FIND_VALUES_UNIQUE, array, [key, void 0]).matched : array;
|
|
5
5
|
}
|
|
6
6
|
export { unique };
|
package/dist/atoms.full.js
CHANGED
|
@@ -184,6 +184,37 @@ function shuffle(array) {
|
|
|
184
184
|
}
|
|
185
185
|
return shuffled;
|
|
186
186
|
}
|
|
187
|
+
function compareSets(type, first, second, key) {
|
|
188
|
+
if (!Array.isArray(first)) return [];
|
|
189
|
+
const isDifference = type === COMPARE_SETS_DIFFERENCE;
|
|
190
|
+
const isIntersection = type === COMPARE_SETS_INTERSECTION;
|
|
191
|
+
const isUnion = type === COMPARE_SETS_UNION;
|
|
192
|
+
if (first.length === 0) return isDifference ? [...first] : isIntersection ? [] : [...second];
|
|
193
|
+
if (!Array.isArray(second) || second.length === 0) return isIntersection ? [] : [...first];
|
|
194
|
+
const callback = getArrayCallback(key);
|
|
195
|
+
const values = isUnion ? first : second;
|
|
196
|
+
let { length } = values;
|
|
197
|
+
const set = /* @__PURE__ */ new Set([]);
|
|
198
|
+
for (let index = 0; index < length; index += 1) {
|
|
199
|
+
const item = values[index];
|
|
200
|
+
set.add(callback?.(item, index, values) ?? item);
|
|
201
|
+
}
|
|
202
|
+
const source = isUnion ? second : first;
|
|
203
|
+
length = source.length;
|
|
204
|
+
const result = isUnion ? [...first] : [];
|
|
205
|
+
for (let index = 0; index < length; index += 1) {
|
|
206
|
+
const item = source[index];
|
|
207
|
+
const value = callback?.(item, index, source) ?? item;
|
|
208
|
+
if (isIntersection ? set.has(value) : !set.has(value)) result.push(item);
|
|
209
|
+
}
|
|
210
|
+
return result;
|
|
211
|
+
}
|
|
212
|
+
const COMPARE_SETS_DIFFERENCE = "difference";
|
|
213
|
+
const COMPARE_SETS_INTERSECTION = "intersection";
|
|
214
|
+
const COMPARE_SETS_UNION = "union";
|
|
215
|
+
function difference(first, second, key) {
|
|
216
|
+
return compareSets(COMPARE_SETS_DIFFERENCE, first, second, key);
|
|
217
|
+
}
|
|
187
218
|
function findValue(type, array, parameters) {
|
|
188
219
|
const findIndex = type === "index";
|
|
189
220
|
if (!Array.isArray(array) || array.length === 0) return findIndex ? -1 : void 0;
|
|
@@ -213,12 +244,12 @@ function findValues(type, array, parameters, mapper) {
|
|
|
213
244
|
const { length } = array;
|
|
214
245
|
const { bool, key, value } = getParameters(parameters);
|
|
215
246
|
const callbacks = getArrayCallbacks(bool, key);
|
|
216
|
-
if (type ===
|
|
247
|
+
if (type === FIND_VALUES_UNIQUE && callbacks?.keyed == null && length >= UNIQUE_THRESHOLD) {
|
|
217
248
|
result.matched = [...new Set(array)];
|
|
218
249
|
return result;
|
|
219
250
|
}
|
|
220
251
|
const mapCallback = typeof mapper === "function" ? mapper : void 0;
|
|
221
|
-
if (callbacks?.bool != null || type ===
|
|
252
|
+
if (callbacks?.bool != null || type === FIND_VALUES_ALL && key == null) {
|
|
222
253
|
const callback = callbacks?.bool ?? ((item) => Object.is(item, value));
|
|
223
254
|
for (let index = 0; index < length; index += 1) {
|
|
224
255
|
const item = array[index];
|
|
@@ -231,7 +262,7 @@ function findValues(type, array, parameters, mapper) {
|
|
|
231
262
|
for (let index = 0; index < length; index += 1) {
|
|
232
263
|
const item = array[index];
|
|
233
264
|
const keyed = callbacks?.keyed?.(item, index, array) ?? item;
|
|
234
|
-
if (type ===
|
|
265
|
+
if (type === FIND_VALUES_ALL && Object.is(keyed, value) || type === FIND_VALUES_UNIQUE && !keys.has(keyed)) {
|
|
235
266
|
keys.add(keyed);
|
|
236
267
|
result.matched.push(mapCallback?.(item, index, array) ?? item);
|
|
237
268
|
} else result.notMatched.push(item);
|
|
@@ -246,20 +277,24 @@ function getParameters(original) {
|
|
|
246
277
|
value: length === 1 && typeof original[0] !== "function" ? original[0] : original[1]
|
|
247
278
|
};
|
|
248
279
|
}
|
|
280
|
+
const FIND_VALUE_INDEX = "index";
|
|
281
|
+
const FIND_VALUE_VALUE = "value";
|
|
282
|
+
const FIND_VALUES_ALL = "all";
|
|
283
|
+
const FIND_VALUES_UNIQUE = "unique";
|
|
249
284
|
const UNIQUE_THRESHOLD = 100;
|
|
250
285
|
function exists(array, ...parameters) {
|
|
251
286
|
if (parameters.length === 1 && typeof parameters[0] !== "function") return Array.isArray(array) ? array.includes(parameters[0]) : false;
|
|
252
|
-
return findValue(
|
|
287
|
+
return findValue(FIND_VALUE_INDEX, array, parameters) > -1;
|
|
253
288
|
}
|
|
254
289
|
function filter(array, ...parameters) {
|
|
255
|
-
return findValues(
|
|
290
|
+
return findValues(FIND_VALUES_ALL, array, parameters).matched;
|
|
256
291
|
}
|
|
257
292
|
filter.remove = removeFiltered;
|
|
258
293
|
function removeFiltered(array, ...parameters) {
|
|
259
|
-
return findValues(
|
|
294
|
+
return findValues(FIND_VALUES_ALL, array, parameters).notMatched;
|
|
260
295
|
}
|
|
261
296
|
function find(array, ...parameters) {
|
|
262
|
-
return findValue(
|
|
297
|
+
return findValue(FIND_VALUE_VALUE, array, parameters);
|
|
263
298
|
}
|
|
264
299
|
/**
|
|
265
300
|
* Flatten an array _(using native `flat` and maximum depth)_
|
|
@@ -301,7 +336,7 @@ function getArray(value, indiced) {
|
|
|
301
336
|
return array;
|
|
302
337
|
}
|
|
303
338
|
function indexOf(array, ...parameters) {
|
|
304
|
-
return findValue(
|
|
339
|
+
return findValue(FIND_VALUE_INDEX, array, parameters);
|
|
305
340
|
}
|
|
306
341
|
function insertChunkedValues(type, array, items, start, deleteCount) {
|
|
307
342
|
const actualDeleteCount = deleteCount < 0 ? 0 : deleteCount;
|
|
@@ -327,8 +362,11 @@ function insertValues(type, array, items, start, deleteCount) {
|
|
|
327
362
|
function insert(array, indexOrItems, items) {
|
|
328
363
|
return insertValues("insert", array, items == null ? indexOrItems : items, typeof indexOrItems === "number" ? indexOrItems : array?.length, 0);
|
|
329
364
|
}
|
|
365
|
+
function intersection(first, second, key) {
|
|
366
|
+
return compareSets(COMPARE_SETS_INTERSECTION, first, second, key);
|
|
367
|
+
}
|
|
330
368
|
function partition(array, ...parameters) {
|
|
331
|
-
const { matched, notMatched } = findValues(
|
|
369
|
+
const { matched, notMatched } = findValues(FIND_VALUES_ALL, array, parameters);
|
|
332
370
|
return [matched, notMatched];
|
|
333
371
|
}
|
|
334
372
|
/**
|
|
@@ -341,8 +379,57 @@ function push(array, pushed) {
|
|
|
341
379
|
return insertValues("push", array, pushed, array.length, 0);
|
|
342
380
|
}
|
|
343
381
|
function select(array, ...parameters) {
|
|
344
|
-
return findValues(
|
|
382
|
+
return findValues(FIND_VALUES_ALL, array, parameters, parameters.pop()).matched;
|
|
345
383
|
}
|
|
384
|
+
function drop(array, first, second) {
|
|
385
|
+
return extract(EXTRACT_DROP, array, first, second);
|
|
386
|
+
}
|
|
387
|
+
function extract(type, array, first, second) {
|
|
388
|
+
if (!Array.isArray(array)) return [];
|
|
389
|
+
const { length } = array;
|
|
390
|
+
if (length === 0) return [];
|
|
391
|
+
const isTake = type === EXTRACT_TAKE;
|
|
392
|
+
if (typeof first === "number") {
|
|
393
|
+
if (Math.abs(first) >= length) return isTake ? array.slice() : [];
|
|
394
|
+
if (first === 0) return isTake ? [] : array.slice();
|
|
395
|
+
if (isTake) return first >= 0 ? array.slice(0, first) : array.slice(array.length + first);
|
|
396
|
+
return first >= 0 ? array.slice(first) : array.slice(0, array.length + first);
|
|
397
|
+
}
|
|
398
|
+
const callbacks = second == null ? getArrayCallbacks(first) : getArrayCallbacks(void 0, void 0, first);
|
|
399
|
+
const isBoolean = callbacks?.bool != null;
|
|
400
|
+
if (callbacks?.bool == null && callbacks?.value == null) return isTake ? array.slice() : [];
|
|
401
|
+
const extracted = [];
|
|
402
|
+
let push = false;
|
|
403
|
+
for (let index = 0; index < length; index += 1) {
|
|
404
|
+
const item = array[index];
|
|
405
|
+
const matches = isBoolean ? callbacks.bool(item, index, array) : Object.is(callbacks.value(item, index, array), second);
|
|
406
|
+
if (isTake) {
|
|
407
|
+
if (isBoolean ? !matches : matches) break;
|
|
408
|
+
extracted.push(item);
|
|
409
|
+
continue;
|
|
410
|
+
}
|
|
411
|
+
if (push) extracted.push(item);
|
|
412
|
+
else if (isBoolean ? !matches : matches) {
|
|
413
|
+
push = true;
|
|
414
|
+
if (isBoolean) extracted.push(item);
|
|
415
|
+
}
|
|
416
|
+
}
|
|
417
|
+
return extracted;
|
|
418
|
+
}
|
|
419
|
+
function slice(array, first, second) {
|
|
420
|
+
if (!Array.isArray(array) || array.length === 0) return [];
|
|
421
|
+
const firstIsNumber = typeof first === "number";
|
|
422
|
+
const secondIsNumber = typeof second === "number";
|
|
423
|
+
if (!firstIsNumber && !secondIsNumber) return array.slice();
|
|
424
|
+
if (!secondIsNumber) return first >= 0 ? array.slice(0, first) : array.slice(array.length + first);
|
|
425
|
+
if (!firstIsNumber) return array.slice();
|
|
426
|
+
return first >= 0 ? array.slice(first, second) : array.slice(array.length + first, array.length + second);
|
|
427
|
+
}
|
|
428
|
+
function take(array, first, second) {
|
|
429
|
+
return extract(EXTRACT_TAKE, array, first, second);
|
|
430
|
+
}
|
|
431
|
+
const EXTRACT_DROP = "drop";
|
|
432
|
+
const EXTRACT_TAKE = "take";
|
|
346
433
|
function aggregate(type, array, key) {
|
|
347
434
|
const length = Array.isArray(array) ? array.length : 0;
|
|
348
435
|
if (length === 0) return {
|
|
@@ -648,6 +735,9 @@ function updateInArray(array, items, key, replace) {
|
|
|
648
735
|
function toggle(array, values, key) {
|
|
649
736
|
return updateInArray(array, values, key, false);
|
|
650
737
|
}
|
|
738
|
+
function union(first, second, key) {
|
|
739
|
+
return compareSets(COMPARE_SETS_UNION, first, second, key);
|
|
740
|
+
}
|
|
651
741
|
function update(array, values, key) {
|
|
652
742
|
return updateInArray(array, values, key, true);
|
|
653
743
|
}
|
|
@@ -684,7 +774,7 @@ function toRecordArrays(array, first, second) {
|
|
|
684
774
|
}
|
|
685
775
|
function unique(array, key) {
|
|
686
776
|
if (!Array.isArray(array)) return [];
|
|
687
|
-
return array.length > 1 ? findValues(
|
|
777
|
+
return array.length > 1 ? findValues(FIND_VALUES_UNIQUE, array, [key, void 0]).matched : array;
|
|
688
778
|
}
|
|
689
779
|
function getInterval(value) {
|
|
690
780
|
return typeof value === "number" && value > 0 ? value : 0;
|
|
@@ -1527,45 +1617,6 @@ const REPLACEMENT_CAMEL_CASE = "$1-$2";
|
|
|
1527
1617
|
let memoizedCapitalize;
|
|
1528
1618
|
let memoizedTitleCase;
|
|
1529
1619
|
/**
|
|
1530
|
-
* Check if a string ends with a specified substring
|
|
1531
|
-
* @param haystack String to look in
|
|
1532
|
-
* @param needle String to look for
|
|
1533
|
-
* @param ignoreCase Ignore case when matching? _(defaults to `false`)_
|
|
1534
|
-
* @returns `true` if the string ends with the given substring, otherwise `false`
|
|
1535
|
-
*/
|
|
1536
|
-
function endsWith(haystack, needle, ignoreCase) {
|
|
1537
|
-
return match("endsWith", haystack, needle, ignoreCase === true);
|
|
1538
|
-
}
|
|
1539
|
-
/**
|
|
1540
|
-
* Check if a string includes a specified substring
|
|
1541
|
-
* @param haystack String to look in
|
|
1542
|
-
* @param needle String to look for
|
|
1543
|
-
* @param ignoreCase Ignore case when matching? _(defaults to `false`)_
|
|
1544
|
-
* @returns `true` if the string includes the given substring, otherwise `false`
|
|
1545
|
-
*/
|
|
1546
|
-
function includes(haystack, needle, ignoreCase) {
|
|
1547
|
-
return match("includes", haystack, needle, ignoreCase === true);
|
|
1548
|
-
}
|
|
1549
|
-
function match(type, haystack, needle, ignoreCase) {
|
|
1550
|
-
if (typeof haystack !== "string" || typeof needle !== "string") return false;
|
|
1551
|
-
matchMemoizers[type] ??= memoize(matchCallback.bind(type));
|
|
1552
|
-
return matchMemoizers[type].run(haystack, needle, ignoreCase);
|
|
1553
|
-
}
|
|
1554
|
-
function matchCallback(haystack, needle, ignoreCase) {
|
|
1555
|
-
return (ignoreCase ? haystack.toLocaleLowerCase() : haystack)[this](ignoreCase ? needle.toLocaleLowerCase() : needle);
|
|
1556
|
-
}
|
|
1557
|
-
/**
|
|
1558
|
-
* Check if a string starts with a specified substring
|
|
1559
|
-
* @param haystack String to look in
|
|
1560
|
-
* @param needle String to look for
|
|
1561
|
-
* @param ignoreCase Ignore case when matching? _(defaults to `false`)_
|
|
1562
|
-
* @returns `true` if the string starts with the given substring, otherwise `false`
|
|
1563
|
-
*/
|
|
1564
|
-
function startsWith(haystack, needle, ignoreCase) {
|
|
1565
|
-
return match("startsWith", haystack, needle, ignoreCase === true);
|
|
1566
|
-
}
|
|
1567
|
-
const matchMemoizers = {};
|
|
1568
|
-
/**
|
|
1569
1620
|
* Get a new UUID-string _(version 4)_
|
|
1570
1621
|
* @returns UUID string
|
|
1571
1622
|
*/
|
|
@@ -1620,6 +1671,45 @@ function truncate(value, length, suffix) {
|
|
|
1620
1671
|
const truncatedLength = length - actualSuffixLength;
|
|
1621
1672
|
return `${value.slice(0, truncatedLength)}${actualSuffix}`;
|
|
1622
1673
|
}
|
|
1674
|
+
/**
|
|
1675
|
+
* Check if a string ends with a specified substring
|
|
1676
|
+
* @param haystack String to look in
|
|
1677
|
+
* @param needle String to look for
|
|
1678
|
+
* @param ignoreCase Ignore case when matching? _(defaults to `false`)_
|
|
1679
|
+
* @returns `true` if the string ends with the given substring, otherwise `false`
|
|
1680
|
+
*/
|
|
1681
|
+
function endsWith(haystack, needle, ignoreCase) {
|
|
1682
|
+
return match("endsWith", haystack, needle, ignoreCase === true);
|
|
1683
|
+
}
|
|
1684
|
+
/**
|
|
1685
|
+
* Check if a string includes a specified substring
|
|
1686
|
+
* @param haystack String to look in
|
|
1687
|
+
* @param needle String to look for
|
|
1688
|
+
* @param ignoreCase Ignore case when matching? _(defaults to `false`)_
|
|
1689
|
+
* @returns `true` if the string includes the given substring, otherwise `false`
|
|
1690
|
+
*/
|
|
1691
|
+
function includes(haystack, needle, ignoreCase) {
|
|
1692
|
+
return match("includes", haystack, needle, ignoreCase === true);
|
|
1693
|
+
}
|
|
1694
|
+
function match(type, haystack, needle, ignoreCase) {
|
|
1695
|
+
if (typeof haystack !== "string" || typeof needle !== "string") return false;
|
|
1696
|
+
matchMemoizers[type] ??= memoize(matchCallback.bind(type));
|
|
1697
|
+
return matchMemoizers[type].run(haystack, needle, ignoreCase);
|
|
1698
|
+
}
|
|
1699
|
+
function matchCallback(haystack, needle, ignoreCase) {
|
|
1700
|
+
return (ignoreCase ? haystack.toLocaleLowerCase() : haystack)[this](ignoreCase ? needle.toLocaleLowerCase() : needle);
|
|
1701
|
+
}
|
|
1702
|
+
/**
|
|
1703
|
+
* Check if a string starts with a specified substring
|
|
1704
|
+
* @param haystack String to look in
|
|
1705
|
+
* @param needle String to look for
|
|
1706
|
+
* @param ignoreCase Ignore case when matching? _(defaults to `false`)_
|
|
1707
|
+
* @returns `true` if the string starts with the given substring, otherwise `false`
|
|
1708
|
+
*/
|
|
1709
|
+
function startsWith(haystack, needle, ignoreCase) {
|
|
1710
|
+
return match("startsWith", haystack, needle, ignoreCase === true);
|
|
1711
|
+
}
|
|
1712
|
+
const matchMemoizers = {};
|
|
1623
1713
|
function getTemplateOptions(input) {
|
|
1624
1714
|
const options = isPlainObject(input) ? input : {};
|
|
1625
1715
|
return {
|
|
@@ -1876,68 +1966,6 @@ function setChanges(parameters) {
|
|
|
1876
1966
|
const diffsLength = diffs.length;
|
|
1877
1967
|
for (let diffIndex = 0; diffIndex < diffsLength; diffIndex += 1) changes.push(diffs[diffIndex]);
|
|
1878
1968
|
}
|
|
1879
|
-
function getMergeOptions(options) {
|
|
1880
|
-
const actual = {
|
|
1881
|
-
replaceableObjects: void 0,
|
|
1882
|
-
skipNullableAny: false,
|
|
1883
|
-
skipNullableInArrays: false
|
|
1884
|
-
};
|
|
1885
|
-
if (typeof options !== "object" || options == null) return actual;
|
|
1886
|
-
actual.replaceableObjects = getReplaceableObjects(options.replaceableObjects);
|
|
1887
|
-
actual.skipNullableAny = options.skipNullableAny === true;
|
|
1888
|
-
actual.skipNullableInArrays = options.skipNullableInArrays === true;
|
|
1889
|
-
return actual;
|
|
1890
|
-
}
|
|
1891
|
-
function getReplaceableObjects(value) {
|
|
1892
|
-
const items = (Array.isArray(value) ? value : [value]).filter((item) => typeof item === "string" || item instanceof RegExp);
|
|
1893
|
-
if (items.length > 0) return (name) => items.some((item) => typeof item === "string" ? item === name : item.test(name));
|
|
1894
|
-
}
|
|
1895
|
-
function handleMerge(values, options) {
|
|
1896
|
-
return !Array.isArray(values) || values.length === 0 ? {} : mergeValues(values, options, true);
|
|
1897
|
-
}
|
|
1898
|
-
/**
|
|
1899
|
-
* Merge multiple arrays or objects into a single one
|
|
1900
|
-
* @param values Values to merge
|
|
1901
|
-
* @param options Merging options
|
|
1902
|
-
* @returns Merged value
|
|
1903
|
-
*/
|
|
1904
|
-
function merge(values, options) {
|
|
1905
|
-
return handleMerge(values, getMergeOptions(options));
|
|
1906
|
-
}
|
|
1907
|
-
merge.initialize = initializeMerger;
|
|
1908
|
-
/**
|
|
1909
|
-
* Create a merger with predefined options
|
|
1910
|
-
* @param options Merging options
|
|
1911
|
-
* @returns Merger function
|
|
1912
|
-
*/
|
|
1913
|
-
function initializeMerger(options) {
|
|
1914
|
-
const actual = getMergeOptions(options);
|
|
1915
|
-
return (values) => handleMerge(values, actual);
|
|
1916
|
-
}
|
|
1917
|
-
function mergeObjects(values, options, prefix) {
|
|
1918
|
-
const { length } = values;
|
|
1919
|
-
const isArray = values.every(Array.isArray);
|
|
1920
|
-
const merged = isArray ? [] : {};
|
|
1921
|
-
for (let outerIndex = 0; outerIndex < length; outerIndex += 1) {
|
|
1922
|
-
const item = values[outerIndex];
|
|
1923
|
-
const keys = Object.keys(item);
|
|
1924
|
-
const size = keys.length;
|
|
1925
|
-
for (let innerIndex = 0; innerIndex < size; innerIndex += 1) {
|
|
1926
|
-
const key = keys[innerIndex];
|
|
1927
|
-
const full = join([prefix, key], ".");
|
|
1928
|
-
const next = item[key];
|
|
1929
|
-
const previous = merged[key];
|
|
1930
|
-
if (next == null && (options.skipNullableAny || isArray && options.skipNullableInArrays)) continue;
|
|
1931
|
-
if (isArrayOrPlainObject(next) && isArrayOrPlainObject(previous) && !(options.replaceableObjects?.(full) ?? false)) merged[key] = mergeValues([previous, next], options, false, full);
|
|
1932
|
-
else merged[key] = next;
|
|
1933
|
-
}
|
|
1934
|
-
}
|
|
1935
|
-
return merged;
|
|
1936
|
-
}
|
|
1937
|
-
function mergeValues(values, options, validate, prefix) {
|
|
1938
|
-
const actual = validate ? values.filter(isArrayOrPlainObject) : values;
|
|
1939
|
-
return actual.length > 1 ? mergeObjects(actual, options, prefix) : actual[0] ?? {};
|
|
1940
|
-
}
|
|
1941
1969
|
function partial(value, providedKeys, omit) {
|
|
1942
1970
|
if (typeof value !== "object" || value === null) return {};
|
|
1943
1971
|
const keys = omit ? Object.keys(value) : Array.isArray(providedKeys) ? providedKeys : [];
|
|
@@ -2034,6 +2062,62 @@ function unsmush(value) {
|
|
|
2034
2062
|
}
|
|
2035
2063
|
return unsmushed;
|
|
2036
2064
|
}
|
|
2065
|
+
function getMergeOptions(options) {
|
|
2066
|
+
const actual = {
|
|
2067
|
+
replaceableObjects: void 0,
|
|
2068
|
+
skipNullableAny: false,
|
|
2069
|
+
skipNullableInArrays: false
|
|
2070
|
+
};
|
|
2071
|
+
if (typeof options !== "object" || options == null) return actual;
|
|
2072
|
+
actual.replaceableObjects = getReplaceableObjects(options.replaceableObjects);
|
|
2073
|
+
actual.skipNullableAny = options.skipNullableAny === true;
|
|
2074
|
+
actual.skipNullableInArrays = options.skipNullableInArrays === true;
|
|
2075
|
+
return actual;
|
|
2076
|
+
}
|
|
2077
|
+
function getReplaceableObjects(value) {
|
|
2078
|
+
const items = (Array.isArray(value) ? value : [value]).filter((item) => typeof item === "string" || item instanceof RegExp);
|
|
2079
|
+
if (items.length > 0) return (name) => items.some((item) => typeof item === "string" ? item === name : item.test(name));
|
|
2080
|
+
}
|
|
2081
|
+
function handleMerge(values, options) {
|
|
2082
|
+
return !Array.isArray(values) || values.length === 0 ? {} : mergeValues(values, options, true);
|
|
2083
|
+
}
|
|
2084
|
+
function merge(values, options) {
|
|
2085
|
+
return handleMerge(values, getMergeOptions(options));
|
|
2086
|
+
}
|
|
2087
|
+
merge.initialize = initializeMerger;
|
|
2088
|
+
/**
|
|
2089
|
+
* Create a merger with predefined options
|
|
2090
|
+
* @param options Merging options
|
|
2091
|
+
* @returns Merger function
|
|
2092
|
+
*/
|
|
2093
|
+
function initializeMerger(options) {
|
|
2094
|
+
const actual = getMergeOptions(options);
|
|
2095
|
+
return (values) => handleMerge(values, actual);
|
|
2096
|
+
}
|
|
2097
|
+
function mergeObjects(values, options, prefix) {
|
|
2098
|
+
const { length } = values;
|
|
2099
|
+
const isArray = values.every(Array.isArray);
|
|
2100
|
+
const merged = isArray ? [] : {};
|
|
2101
|
+
for (let outerIndex = 0; outerIndex < length; outerIndex += 1) {
|
|
2102
|
+
const item = values[outerIndex];
|
|
2103
|
+
const keys = Object.keys(item);
|
|
2104
|
+
const size = keys.length;
|
|
2105
|
+
for (let innerIndex = 0; innerIndex < size; innerIndex += 1) {
|
|
2106
|
+
const key = keys[innerIndex];
|
|
2107
|
+
const full = join([prefix, key], ".");
|
|
2108
|
+
const next = item[key];
|
|
2109
|
+
const previous = merged[key];
|
|
2110
|
+
if (next == null && (options.skipNullableAny || isArray && options.skipNullableInArrays)) continue;
|
|
2111
|
+
if (isArrayOrPlainObject(next) && isArrayOrPlainObject(previous) && !(options.replaceableObjects?.(full) ?? false)) merged[key] = mergeValues([previous, next], options, false, full);
|
|
2112
|
+
else merged[key] = next;
|
|
2113
|
+
}
|
|
2114
|
+
}
|
|
2115
|
+
return merged;
|
|
2116
|
+
}
|
|
2117
|
+
function mergeValues(values, options, validate, prefix) {
|
|
2118
|
+
const actual = validate ? values.filter(isArrayOrPlainObject) : values;
|
|
2119
|
+
return actual.length > 1 ? mergeObjects(actual, options, prefix) : actual[0] ?? {};
|
|
2120
|
+
}
|
|
2037
2121
|
var Beacon = class {
|
|
2038
2122
|
#options;
|
|
2039
2123
|
#state;
|
|
@@ -3839,4 +3923,4 @@ var SizedSet = class extends Set {
|
|
|
3839
3923
|
}
|
|
3840
3924
|
}
|
|
3841
3925
|
};
|
|
3842
|
-
export { CancelablePromise, PromiseTimeoutError, QueueError, RetryError, SizedMap, SizedSet, attempt, attemptPromise, average, beacon, between, camelCase, cancelable, capitalize, ceil, chunk, clamp, clone, compact, compare, count, debounce, delay, diff, endsWith, equal, error, exists, filter, find, flatten, floor, flow, toResult as fromPromise, toResult, fromQuery, toPromise as fromResult, toPromise, getArray, getColor, getForegroundColor, getHexColor, getHexaColor, getHslColor, getHslaColor, getNormalizedHex, getNumber, getRandomBoolean, getRandomCharacters, getRandomColor, getRandomFloat, getRandomHex, getRandomInteger, getRandomItem, getRandomItems, getRgbColor, getRgbaColor, getString, getUuid, getValue, groupBy, hasValue, hexToHsl, hexToHsla, hexToRgb, hexToRgba, hslToHex, hslToRgb, hslToRgba, ignoreKey, includes, indexOf, insert, isArrayOrPlainObject, isColor, isConstructor, isEmpty, isError, isFulfilled, isHexColor, isHslColor, isHslLike, isHslaColor, isInstanceOf, isKey, isNonNullable, isNullable, isNullableOrEmpty, isNullableOrWhitespace, isNumber, isNumerical, isObject, isOk, isPlainObject, isPrimitive, isRejected, isResult, isRgbColor, isRgbLike, isRgbaColor, isTypedArray, join, kebabCase, logger, lowerCase, max, median, memoize, merge, min, noop, ok, omit, parse, partition, pascalCase, pick, pipe, promises, push, queue, range, retry, rgbToHex, rgbToHsl, rgbToHsla, round, select, setValue, shuffle, smush, snakeCase, sort, splice, startsWith, sum, template, throttle, timed, times, titleCase, toMap, toQuery, toRecord, toSet, toggle, trim, truncate, tryDecode, tryEncode, unique, unsmush, unwrap, update, upperCase, words };
|
|
3926
|
+
export { CancelablePromise, PromiseTimeoutError, QueueError, RetryError, SizedMap, SizedSet, attempt, attemptPromise, average, beacon, between, camelCase, cancelable, capitalize, ceil, chunk, clamp, clone, compact, compare, count, debounce, delay, diff, difference, drop, endsWith, equal, error, exists, filter, find, flatten, floor, flow, toResult as fromPromise, toResult, fromQuery, toPromise as fromResult, toPromise, getArray, getColor, getForegroundColor, getHexColor, getHexaColor, getHslColor, getHslaColor, getNormalizedHex, getNumber, getRandomBoolean, getRandomCharacters, getRandomColor, getRandomFloat, getRandomHex, getRandomInteger, getRandomItem, getRandomItems, getRgbColor, getRgbaColor, getString, getUuid, getValue, groupBy, hasValue, hexToHsl, hexToHsla, hexToRgb, hexToRgba, hslToHex, hslToRgb, hslToRgba, ignoreKey, includes, indexOf, insert, intersection, isArrayOrPlainObject, isColor, isConstructor, isEmpty, isError, isFulfilled, isHexColor, isHslColor, isHslLike, isHslaColor, isInstanceOf, isKey, isNonNullable, isNullable, isNullableOrEmpty, isNullableOrWhitespace, isNumber, isNumerical, isObject, isOk, isPlainObject, isPrimitive, isRejected, isResult, isRgbColor, isRgbLike, isRgbaColor, isTypedArray, join, kebabCase, logger, lowerCase, max, median, memoize, merge, min, noop, ok, omit, parse, partition, pascalCase, pick, pipe, promises, push, queue, range, retry, rgbToHex, rgbToHsl, rgbToHsla, round, select, setValue, shuffle, slice, smush, snakeCase, sort, splice, startsWith, sum, take, template, throttle, timed, times, titleCase, toMap, toQuery, toRecord, toSet, toggle, trim, truncate, tryDecode, tryEncode, union, unique, unsmush, unwrap, update, upperCase, words };
|
package/dist/index.js
CHANGED
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import { difference } from "./array/difference.js";
|
|
1
2
|
import { exists } from "./array/exists.js";
|
|
2
3
|
import { filter } from "./array/filter.js";
|
|
3
4
|
import { find } from "./array/find.js";
|
|
@@ -8,13 +9,15 @@ import { getArray } from "./array/get.js";
|
|
|
8
9
|
import { groupBy } from "./array/group-by.js";
|
|
9
10
|
import { indexOf } from "./array/index-of.js";
|
|
10
11
|
import { chunk } from "./internal/array/chunk.js";
|
|
11
|
-
import { insert } from "./array/insert.js";
|
|
12
12
|
import { compact } from "./internal/array/compact.js";
|
|
13
13
|
import { getRandomFloat, getRandomInteger } from "./internal/random.js";
|
|
14
14
|
import { shuffle } from "./internal/array/shuffle.js";
|
|
15
|
+
import { insert } from "./array/insert.js";
|
|
16
|
+
import { intersection } from "./array/intersection.js";
|
|
15
17
|
import { partition } from "./array/partition.js";
|
|
16
18
|
import { push } from "./array/push.js";
|
|
17
19
|
import { select } from "./array/select.js";
|
|
20
|
+
import { drop, slice, take } from "./array/slice.js";
|
|
18
21
|
import { max } from "./internal/math/aggregate.js";
|
|
19
22
|
import { getString, ignoreKey, join, tryDecode, tryEncode, words } from "./internal/string.js";
|
|
20
23
|
import { compare } from "./internal/value/compare.js";
|
|
@@ -22,8 +25,9 @@ import { sort } from "./array/sort.js";
|
|
|
22
25
|
import { splice } from "./array/splice.js";
|
|
23
26
|
import { toSet } from "./array/to-set.js";
|
|
24
27
|
import { toggle } from "./array/toggle.js";
|
|
28
|
+
import { union } from "./array/union.js";
|
|
25
29
|
import { update } from "./array/update.js";
|
|
26
|
-
import "./array/
|
|
30
|
+
import "./array/index.js";
|
|
27
31
|
import { toMap } from "./array/to-map.js";
|
|
28
32
|
import { toRecord } from "./array/to-record.js";
|
|
29
33
|
import { unique } from "./array/unique.js";
|
|
@@ -47,16 +51,16 @@ import { getValue } from "./internal/value/get.js";
|
|
|
47
51
|
import { hasValue } from "./internal/value/has.js";
|
|
48
52
|
import { setValue } from "./internal/value/set.js";
|
|
49
53
|
import { camelCase, capitalize, kebabCase, lowerCase, pascalCase, snakeCase, titleCase, upperCase } from "./string/case.js";
|
|
54
|
+
import { getUuid, parse, trim, truncate } from "./string/index.js";
|
|
50
55
|
import { endsWith, includes, startsWith } from "./string/match.js";
|
|
51
|
-
import { getUuid, parse, trim, truncate } from "./string/misc.js";
|
|
52
56
|
import { template } from "./string/template.js";
|
|
53
57
|
import { clone } from "./value/clone.js";
|
|
54
58
|
import { diff } from "./value/diff.js";
|
|
55
|
-
import { merge } from "./value/merge.js";
|
|
56
59
|
import { omit } from "./value/omit.js";
|
|
57
60
|
import { pick } from "./value/pick.js";
|
|
58
61
|
import { smush } from "./value/smush.js";
|
|
59
62
|
import { unsmush } from "./value/unsmush.js";
|
|
63
|
+
import { merge } from "./value/merge.js";
|
|
60
64
|
import { isEmpty, isNonNullable, isNullable, isNullableOrEmpty, isNullableOrWhitespace, isNumerical, isObject, isPrimitive } from "./is.js";
|
|
61
65
|
import { logger } from "./logger.js";
|
|
62
66
|
import { average, ceil, count, floor, median, min, round, sum } from "./math.js";
|
|
@@ -72,4 +76,4 @@ import { QueueError, queue } from "./queue.js";
|
|
|
72
76
|
import { getRandomBoolean, getRandomCharacters, getRandomColor, getRandomHex, getRandomItem, getRandomItems } from "./random.js";
|
|
73
77
|
import { attempt } from "./result/index.js";
|
|
74
78
|
import { SizedSet } from "./sized/set.js";
|
|
75
|
-
export { CancelablePromise, PromiseTimeoutError, QueueError, RetryError, SizedMap, SizedSet, attempt, attemptPromise, average, beacon, between, camelCase, cancelable, capitalize, ceil, chunk, clamp, clone, compact, compare, count, debounce, delay, diff, endsWith, equal, error, exists, filter, find, flatten, floor, flow, toResult as fromPromise, fromQuery, toPromise as fromResult, getArray, getColor, getForegroundColor, getHexColor, getHexaColor, getHslColor, getHslaColor, getNormalizedHex, getNumber, getRandomBoolean, getRandomCharacters, getRandomColor, getRandomFloat, getRandomHex, getRandomInteger, getRandomItem, getRandomItems, getRgbColor, getRgbaColor, getString, getUuid, getValue, groupBy, hasValue, hexToHsl, hexToHsla, hexToRgb, hexToRgba, hslToHex, hslToRgb, hslToRgba, ignoreKey, includes, indexOf, insert, isArrayOrPlainObject, isColor, isConstructor, isEmpty, isError, isFulfilled, isHexColor, isHslColor, isHslLike, isHslaColor, isInstanceOf, isKey, isNonNullable, isNullable, isNullableOrEmpty, isNullableOrWhitespace, isNumber, isNumerical, isObject, isOk, isPlainObject, isPrimitive, isRejected, isResult, isRgbColor, isRgbLike, isRgbaColor, isTypedArray, join, kebabCase, logger, lowerCase, max, median, memoize, merge, min, noop, ok, omit, parse, partition, pascalCase, pick, pipe, promises, push, queue, range, retry, rgbToHex, rgbToHsl, rgbToHsla, round, select, setValue, shuffle, smush, snakeCase, sort, splice, startsWith, sum, template, throttle, timed, times, titleCase, toMap, toPromise, toQuery, toRecord, toResult, toSet, toggle, trim, truncate, tryDecode, tryEncode, unique, unsmush, unwrap, update, upperCase, words };
|
|
79
|
+
export { CancelablePromise, PromiseTimeoutError, QueueError, RetryError, SizedMap, SizedSet, attempt, attemptPromise, average, beacon, between, camelCase, cancelable, capitalize, ceil, chunk, clamp, clone, compact, compare, count, debounce, delay, diff, difference, drop, endsWith, equal, error, exists, filter, find, flatten, floor, flow, toResult as fromPromise, fromQuery, toPromise as fromResult, getArray, getColor, getForegroundColor, getHexColor, getHexaColor, getHslColor, getHslaColor, getNormalizedHex, getNumber, getRandomBoolean, getRandomCharacters, getRandomColor, getRandomFloat, getRandomHex, getRandomInteger, getRandomItem, getRandomItems, getRgbColor, getRgbaColor, getString, getUuid, getValue, groupBy, hasValue, hexToHsl, hexToHsla, hexToRgb, hexToRgba, hslToHex, hslToRgb, hslToRgba, ignoreKey, includes, indexOf, insert, intersection, isArrayOrPlainObject, isColor, isConstructor, isEmpty, isError, isFulfilled, isHexColor, isHslColor, isHslLike, isHslaColor, isInstanceOf, isKey, isNonNullable, isNullable, isNullableOrEmpty, isNullableOrWhitespace, isNumber, isNumerical, isObject, isOk, isPlainObject, isPrimitive, isRejected, isResult, isRgbColor, isRgbLike, isRgbaColor, isTypedArray, join, kebabCase, logger, lowerCase, max, median, memoize, merge, min, noop, ok, omit, parse, partition, pascalCase, pick, pipe, promises, push, queue, range, retry, rgbToHex, rgbToHsl, rgbToHsla, round, select, setValue, shuffle, slice, smush, snakeCase, sort, splice, startsWith, sum, take, template, throttle, timed, times, titleCase, toMap, toPromise, toQuery, toRecord, toResult, toSet, toggle, trim, truncate, tryDecode, tryEncode, union, unique, unsmush, unwrap, update, upperCase, words };
|
|
@@ -61,5 +61,9 @@ function getParameters(original) {
|
|
|
61
61
|
value: length === 1 && typeof original[0] !== "function" ? original[0] : original[1]
|
|
62
62
|
};
|
|
63
63
|
}
|
|
64
|
+
const FIND_VALUE_INDEX = "index";
|
|
65
|
+
const FIND_VALUE_VALUE = "value";
|
|
66
|
+
const FIND_VALUES_ALL = "all";
|
|
67
|
+
const FIND_VALUES_UNIQUE = "unique";
|
|
64
68
|
var UNIQUE_THRESHOLD = 100;
|
|
65
|
-
export { findValue, findValues };
|
|
69
|
+
export { FIND_VALUES_ALL, FIND_VALUES_UNIQUE, FIND_VALUE_INDEX, FIND_VALUE_VALUE, findValue, findValues };
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
import { getArrayCallback } from "./callbacks.js";
|
|
2
|
+
function compareSets(type, first, second, key) {
|
|
3
|
+
if (!Array.isArray(first)) return [];
|
|
4
|
+
const isDifference = type === COMPARE_SETS_DIFFERENCE;
|
|
5
|
+
const isIntersection = type === COMPARE_SETS_INTERSECTION;
|
|
6
|
+
const isUnion = type === COMPARE_SETS_UNION;
|
|
7
|
+
if (first.length === 0) return isDifference ? [...first] : isIntersection ? [] : [...second];
|
|
8
|
+
if (!Array.isArray(second) || second.length === 0) return isIntersection ? [] : [...first];
|
|
9
|
+
const callback = getArrayCallback(key);
|
|
10
|
+
const values = isUnion ? first : second;
|
|
11
|
+
let { length } = values;
|
|
12
|
+
const set = /* @__PURE__ */ new Set([]);
|
|
13
|
+
for (let index = 0; index < length; index += 1) {
|
|
14
|
+
const item = values[index];
|
|
15
|
+
set.add(callback?.(item, index, values) ?? item);
|
|
16
|
+
}
|
|
17
|
+
const source = isUnion ? second : first;
|
|
18
|
+
length = source.length;
|
|
19
|
+
const result = isUnion ? [...first] : [];
|
|
20
|
+
for (let index = 0; index < length; index += 1) {
|
|
21
|
+
const item = source[index];
|
|
22
|
+
const value = callback?.(item, index, source) ?? item;
|
|
23
|
+
if (isIntersection ? set.has(value) : !set.has(value)) result.push(item);
|
|
24
|
+
}
|
|
25
|
+
return result;
|
|
26
|
+
}
|
|
27
|
+
const COMPARE_SETS_DIFFERENCE = "difference";
|
|
28
|
+
const COMPARE_SETS_INTERSECTION = "intersection";
|
|
29
|
+
const COMPARE_SETS_UNION = "union";
|
|
30
|
+
export { COMPARE_SETS_DIFFERENCE, COMPARE_SETS_INTERSECTION, COMPARE_SETS_UNION, compareSets };
|