@oscarpalmer/atoms 0.155.0 → 0.156.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} +5 -2
- package/dist/array/intersection.js +5 -0
- package/dist/array/union.js +5 -0
- package/dist/array/unique.js +2 -2
- package/dist/atoms.full.js +148 -113
- package/dist/index.js +8 -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} +3 -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/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} +3 -0
- package/types/array/intersection.d.ts +23 -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,9 +7,10 @@ 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";
|
|
@@ -16,5 +18,6 @@ import { sort } from "./sort.js";
|
|
|
16
18
|
import { splice } from "./splice.js";
|
|
17
19
|
import { toSet } from "./to-set.js";
|
|
18
20
|
import { toggle } from "./toggle.js";
|
|
21
|
+
import { union } from "./union.js";
|
|
19
22
|
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 };
|
|
23
|
+
export { chunk, compact, difference, exists, filter, find, flatten, getArray, indexOf, insert, intersection, partition, push, range, select, shuffle, sort, splice, times, toSet, toggle, union, update };
|
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,7 +379,7 @@ 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
|
}
|
|
346
384
|
function aggregate(type, array, key) {
|
|
347
385
|
const length = Array.isArray(array) ? array.length : 0;
|
|
@@ -648,6 +686,9 @@ function updateInArray(array, items, key, replace) {
|
|
|
648
686
|
function toggle(array, values, key) {
|
|
649
687
|
return updateInArray(array, values, key, false);
|
|
650
688
|
}
|
|
689
|
+
function union(first, second, key) {
|
|
690
|
+
return compareSets(COMPARE_SETS_UNION, first, second, key);
|
|
691
|
+
}
|
|
651
692
|
function update(array, values, key) {
|
|
652
693
|
return updateInArray(array, values, key, true);
|
|
653
694
|
}
|
|
@@ -684,7 +725,7 @@ function toRecordArrays(array, first, second) {
|
|
|
684
725
|
}
|
|
685
726
|
function unique(array, key) {
|
|
686
727
|
if (!Array.isArray(array)) return [];
|
|
687
|
-
return array.length > 1 ? findValues(
|
|
728
|
+
return array.length > 1 ? findValues(FIND_VALUES_UNIQUE, array, [key, void 0]).matched : array;
|
|
688
729
|
}
|
|
689
730
|
function getInterval(value) {
|
|
690
731
|
return typeof value === "number" && value > 0 ? value : 0;
|
|
@@ -1527,45 +1568,6 @@ const REPLACEMENT_CAMEL_CASE = "$1-$2";
|
|
|
1527
1568
|
let memoizedCapitalize;
|
|
1528
1569
|
let memoizedTitleCase;
|
|
1529
1570
|
/**
|
|
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
1571
|
* Get a new UUID-string _(version 4)_
|
|
1570
1572
|
* @returns UUID string
|
|
1571
1573
|
*/
|
|
@@ -1620,6 +1622,45 @@ function truncate(value, length, suffix) {
|
|
|
1620
1622
|
const truncatedLength = length - actualSuffixLength;
|
|
1621
1623
|
return `${value.slice(0, truncatedLength)}${actualSuffix}`;
|
|
1622
1624
|
}
|
|
1625
|
+
/**
|
|
1626
|
+
* Check if a string ends with a specified substring
|
|
1627
|
+
* @param haystack String to look in
|
|
1628
|
+
* @param needle String to look for
|
|
1629
|
+
* @param ignoreCase Ignore case when matching? _(defaults to `false`)_
|
|
1630
|
+
* @returns `true` if the string ends with the given substring, otherwise `false`
|
|
1631
|
+
*/
|
|
1632
|
+
function endsWith(haystack, needle, ignoreCase) {
|
|
1633
|
+
return match("endsWith", haystack, needle, ignoreCase === true);
|
|
1634
|
+
}
|
|
1635
|
+
/**
|
|
1636
|
+
* Check if a string includes a specified substring
|
|
1637
|
+
* @param haystack String to look in
|
|
1638
|
+
* @param needle String to look for
|
|
1639
|
+
* @param ignoreCase Ignore case when matching? _(defaults to `false`)_
|
|
1640
|
+
* @returns `true` if the string includes the given substring, otherwise `false`
|
|
1641
|
+
*/
|
|
1642
|
+
function includes(haystack, needle, ignoreCase) {
|
|
1643
|
+
return match("includes", haystack, needle, ignoreCase === true);
|
|
1644
|
+
}
|
|
1645
|
+
function match(type, haystack, needle, ignoreCase) {
|
|
1646
|
+
if (typeof haystack !== "string" || typeof needle !== "string") return false;
|
|
1647
|
+
matchMemoizers[type] ??= memoize(matchCallback.bind(type));
|
|
1648
|
+
return matchMemoizers[type].run(haystack, needle, ignoreCase);
|
|
1649
|
+
}
|
|
1650
|
+
function matchCallback(haystack, needle, ignoreCase) {
|
|
1651
|
+
return (ignoreCase ? haystack.toLocaleLowerCase() : haystack)[this](ignoreCase ? needle.toLocaleLowerCase() : needle);
|
|
1652
|
+
}
|
|
1653
|
+
/**
|
|
1654
|
+
* Check if a string starts with a specified substring
|
|
1655
|
+
* @param haystack String to look in
|
|
1656
|
+
* @param needle String to look for
|
|
1657
|
+
* @param ignoreCase Ignore case when matching? _(defaults to `false`)_
|
|
1658
|
+
* @returns `true` if the string starts with the given substring, otherwise `false`
|
|
1659
|
+
*/
|
|
1660
|
+
function startsWith(haystack, needle, ignoreCase) {
|
|
1661
|
+
return match("startsWith", haystack, needle, ignoreCase === true);
|
|
1662
|
+
}
|
|
1663
|
+
const matchMemoizers = {};
|
|
1623
1664
|
function getTemplateOptions(input) {
|
|
1624
1665
|
const options = isPlainObject(input) ? input : {};
|
|
1625
1666
|
return {
|
|
@@ -1876,68 +1917,6 @@ function setChanges(parameters) {
|
|
|
1876
1917
|
const diffsLength = diffs.length;
|
|
1877
1918
|
for (let diffIndex = 0; diffIndex < diffsLength; diffIndex += 1) changes.push(diffs[diffIndex]);
|
|
1878
1919
|
}
|
|
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
1920
|
function partial(value, providedKeys, omit) {
|
|
1942
1921
|
if (typeof value !== "object" || value === null) return {};
|
|
1943
1922
|
const keys = omit ? Object.keys(value) : Array.isArray(providedKeys) ? providedKeys : [];
|
|
@@ -2034,6 +2013,62 @@ function unsmush(value) {
|
|
|
2034
2013
|
}
|
|
2035
2014
|
return unsmushed;
|
|
2036
2015
|
}
|
|
2016
|
+
function getMergeOptions(options) {
|
|
2017
|
+
const actual = {
|
|
2018
|
+
replaceableObjects: void 0,
|
|
2019
|
+
skipNullableAny: false,
|
|
2020
|
+
skipNullableInArrays: false
|
|
2021
|
+
};
|
|
2022
|
+
if (typeof options !== "object" || options == null) return actual;
|
|
2023
|
+
actual.replaceableObjects = getReplaceableObjects(options.replaceableObjects);
|
|
2024
|
+
actual.skipNullableAny = options.skipNullableAny === true;
|
|
2025
|
+
actual.skipNullableInArrays = options.skipNullableInArrays === true;
|
|
2026
|
+
return actual;
|
|
2027
|
+
}
|
|
2028
|
+
function getReplaceableObjects(value) {
|
|
2029
|
+
const items = (Array.isArray(value) ? value : [value]).filter((item) => typeof item === "string" || item instanceof RegExp);
|
|
2030
|
+
if (items.length > 0) return (name) => items.some((item) => typeof item === "string" ? item === name : item.test(name));
|
|
2031
|
+
}
|
|
2032
|
+
function handleMerge(values, options) {
|
|
2033
|
+
return !Array.isArray(values) || values.length === 0 ? {} : mergeValues(values, options, true);
|
|
2034
|
+
}
|
|
2035
|
+
function merge(values, options) {
|
|
2036
|
+
return handleMerge(values, getMergeOptions(options));
|
|
2037
|
+
}
|
|
2038
|
+
merge.initialize = initializeMerger;
|
|
2039
|
+
/**
|
|
2040
|
+
* Create a merger with predefined options
|
|
2041
|
+
* @param options Merging options
|
|
2042
|
+
* @returns Merger function
|
|
2043
|
+
*/
|
|
2044
|
+
function initializeMerger(options) {
|
|
2045
|
+
const actual = getMergeOptions(options);
|
|
2046
|
+
return (values) => handleMerge(values, actual);
|
|
2047
|
+
}
|
|
2048
|
+
function mergeObjects(values, options, prefix) {
|
|
2049
|
+
const { length } = values;
|
|
2050
|
+
const isArray = values.every(Array.isArray);
|
|
2051
|
+
const merged = isArray ? [] : {};
|
|
2052
|
+
for (let outerIndex = 0; outerIndex < length; outerIndex += 1) {
|
|
2053
|
+
const item = values[outerIndex];
|
|
2054
|
+
const keys = Object.keys(item);
|
|
2055
|
+
const size = keys.length;
|
|
2056
|
+
for (let innerIndex = 0; innerIndex < size; innerIndex += 1) {
|
|
2057
|
+
const key = keys[innerIndex];
|
|
2058
|
+
const full = join([prefix, key], ".");
|
|
2059
|
+
const next = item[key];
|
|
2060
|
+
const previous = merged[key];
|
|
2061
|
+
if (next == null && (options.skipNullableAny || isArray && options.skipNullableInArrays)) continue;
|
|
2062
|
+
if (isArrayOrPlainObject(next) && isArrayOrPlainObject(previous) && !(options.replaceableObjects?.(full) ?? false)) merged[key] = mergeValues([previous, next], options, false, full);
|
|
2063
|
+
else merged[key] = next;
|
|
2064
|
+
}
|
|
2065
|
+
}
|
|
2066
|
+
return merged;
|
|
2067
|
+
}
|
|
2068
|
+
function mergeValues(values, options, validate, prefix) {
|
|
2069
|
+
const actual = validate ? values.filter(isArrayOrPlainObject) : values;
|
|
2070
|
+
return actual.length > 1 ? mergeObjects(actual, options, prefix) : actual[0] ?? {};
|
|
2071
|
+
}
|
|
2037
2072
|
var Beacon = class {
|
|
2038
2073
|
#options;
|
|
2039
2074
|
#state;
|
|
@@ -3839,4 +3874,4 @@ var SizedSet = class extends Set {
|
|
|
3839
3874
|
}
|
|
3840
3875
|
}
|
|
3841
3876
|
};
|
|
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 };
|
|
3877
|
+
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, 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, smush, snakeCase, sort, splice, startsWith, sum, 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,10 +9,11 @@ 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";
|
|
@@ -22,8 +24,9 @@ import { sort } from "./array/sort.js";
|
|
|
22
24
|
import { splice } from "./array/splice.js";
|
|
23
25
|
import { toSet } from "./array/to-set.js";
|
|
24
26
|
import { toggle } from "./array/toggle.js";
|
|
27
|
+
import { union } from "./array/union.js";
|
|
25
28
|
import { update } from "./array/update.js";
|
|
26
|
-
import "./array/
|
|
29
|
+
import "./array/index.js";
|
|
27
30
|
import { toMap } from "./array/to-map.js";
|
|
28
31
|
import { toRecord } from "./array/to-record.js";
|
|
29
32
|
import { unique } from "./array/unique.js";
|
|
@@ -47,16 +50,16 @@ import { getValue } from "./internal/value/get.js";
|
|
|
47
50
|
import { hasValue } from "./internal/value/has.js";
|
|
48
51
|
import { setValue } from "./internal/value/set.js";
|
|
49
52
|
import { camelCase, capitalize, kebabCase, lowerCase, pascalCase, snakeCase, titleCase, upperCase } from "./string/case.js";
|
|
53
|
+
import { getUuid, parse, trim, truncate } from "./string/index.js";
|
|
50
54
|
import { endsWith, includes, startsWith } from "./string/match.js";
|
|
51
|
-
import { getUuid, parse, trim, truncate } from "./string/misc.js";
|
|
52
55
|
import { template } from "./string/template.js";
|
|
53
56
|
import { clone } from "./value/clone.js";
|
|
54
57
|
import { diff } from "./value/diff.js";
|
|
55
|
-
import { merge } from "./value/merge.js";
|
|
56
58
|
import { omit } from "./value/omit.js";
|
|
57
59
|
import { pick } from "./value/pick.js";
|
|
58
60
|
import { smush } from "./value/smush.js";
|
|
59
61
|
import { unsmush } from "./value/unsmush.js";
|
|
62
|
+
import { merge } from "./value/merge.js";
|
|
60
63
|
import { isEmpty, isNonNullable, isNullable, isNullableOrEmpty, isNullableOrWhitespace, isNumerical, isObject, isPrimitive } from "./is.js";
|
|
61
64
|
import { logger } from "./logger.js";
|
|
62
65
|
import { average, ceil, count, floor, median, min, round, sum } from "./math.js";
|
|
@@ -72,4 +75,4 @@ import { QueueError, queue } from "./queue.js";
|
|
|
72
75
|
import { getRandomBoolean, getRandomCharacters, getRandomColor, getRandomHex, getRandomItem, getRandomItems } from "./random.js";
|
|
73
76
|
import { attempt } from "./result/index.js";
|
|
74
77
|
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 };
|
|
78
|
+
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, 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, smush, snakeCase, sort, splice, startsWith, sum, 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 };
|
package/dist/value/merge.js
CHANGED
|
@@ -19,12 +19,6 @@ function getReplaceableObjects(value) {
|
|
|
19
19
|
function handleMerge(values, options) {
|
|
20
20
|
return !Array.isArray(values) || values.length === 0 ? {} : mergeValues(values, options, true);
|
|
21
21
|
}
|
|
22
|
-
/**
|
|
23
|
-
* Merge multiple arrays or objects into a single one
|
|
24
|
-
* @param values Values to merge
|
|
25
|
-
* @param options Merging options
|
|
26
|
-
* @returns Merged value
|
|
27
|
-
*/
|
|
28
22
|
function merge(values, options) {
|
|
29
23
|
return handleMerge(values, getMergeOptions(options));
|
|
30
24
|
}
|
package/package.json
CHANGED
|
@@ -26,9 +26,9 @@
|
|
|
26
26
|
"types": "./types/array/group-by.d.ts",
|
|
27
27
|
"default": "./dist/array/group-by.js"
|
|
28
28
|
},
|
|
29
|
-
"./array
|
|
30
|
-
"types": "./types/array/
|
|
31
|
-
"default": "./dist/array/
|
|
29
|
+
"./array": {
|
|
30
|
+
"types": "./types/array/index.d.ts",
|
|
31
|
+
"default": "./dist/array/index.js"
|
|
32
32
|
},
|
|
33
33
|
"./array/to-map": {
|
|
34
34
|
"types": "./types/array/to-map.d.ts",
|
|
@@ -113,6 +113,10 @@
|
|
|
113
113
|
"types": "./types/sized/set.d.ts",
|
|
114
114
|
"default": "./dist/sized/set.js"
|
|
115
115
|
},
|
|
116
|
+
"./string": {
|
|
117
|
+
"types": "./types/string/index.d.ts",
|
|
118
|
+
"default": "./dist/string/index.js"
|
|
119
|
+
},
|
|
116
120
|
"./string/case": {
|
|
117
121
|
"types": "./types/string/case.d.ts",
|
|
118
122
|
"default": "./dist/string/case.js"
|
|
@@ -121,14 +125,14 @@
|
|
|
121
125
|
"types": "./types/string/match.d.ts",
|
|
122
126
|
"default": "./dist/string/match.js"
|
|
123
127
|
},
|
|
124
|
-
"./string/misc": {
|
|
125
|
-
"types": "./types/string/misc.d.ts",
|
|
126
|
-
"default": "./dist/string/misc.js"
|
|
127
|
-
},
|
|
128
128
|
"./string/template": {
|
|
129
129
|
"types": "./types/string/template.d.ts",
|
|
130
130
|
"default": "./dist/string/template.js"
|
|
131
131
|
},
|
|
132
|
+
"./value": {
|
|
133
|
+
"types": "./types/value/index.d.ts",
|
|
134
|
+
"default": "./dist/value/index.js"
|
|
135
|
+
},
|
|
132
136
|
"./value/clone": {
|
|
133
137
|
"types": "./types/value/clone.d.ts",
|
|
134
138
|
"default": "./dist/value/clone.js"
|
|
@@ -152,10 +156,6 @@
|
|
|
152
156
|
"./value/merge": {
|
|
153
157
|
"types": "./types/value/merge.d.ts",
|
|
154
158
|
"default": "./dist/value/merge.js"
|
|
155
|
-
},
|
|
156
|
-
"./value/misc": {
|
|
157
|
-
"types": "./types/value/misc.d.ts",
|
|
158
|
-
"default": "./dist/value/misc.js"
|
|
159
159
|
}
|
|
160
160
|
},
|
|
161
161
|
"files": [
|
|
@@ -184,5 +184,5 @@
|
|
|
184
184
|
},
|
|
185
185
|
"type": "module",
|
|
186
186
|
"types": "./types/index.d.ts",
|
|
187
|
-
"version": "0.
|
|
187
|
+
"version": "0.156.0"
|
|
188
188
|
}
|
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
import {COMPARE_SETS_DIFFERENCE, compareSets} from '../internal/array/sets';
|
|
2
|
+
import type {PlainObject} from '../models';
|
|
3
|
+
|
|
4
|
+
/**
|
|
5
|
+
* Get the items from the first array that are not in the second array
|
|
6
|
+
* @param first First array
|
|
7
|
+
* @param second Second array
|
|
8
|
+
* @param callback Callback to get an item's value for comparison
|
|
9
|
+
* @returns Unique values from the first array
|
|
10
|
+
*/
|
|
11
|
+
export function difference<First, Second>(
|
|
12
|
+
first: First[],
|
|
13
|
+
second: Second[],
|
|
14
|
+
callback: (item: First | Second) => unknown,
|
|
15
|
+
): First[];
|
|
16
|
+
|
|
17
|
+
/**
|
|
18
|
+
* Get the items from the first array that are not in the second array
|
|
19
|
+
* @param first First array
|
|
20
|
+
* @param second Second array
|
|
21
|
+
* @param key Key to get an item's value for comparison
|
|
22
|
+
* @returns Unique values from the first array
|
|
23
|
+
*/
|
|
24
|
+
export function difference<
|
|
25
|
+
First extends PlainObject,
|
|
26
|
+
Second extends PlainObject,
|
|
27
|
+
Key extends keyof First & keyof Second,
|
|
28
|
+
>(first: First[], second: Second[], key: Key): First[];
|
|
29
|
+
|
|
30
|
+
/**
|
|
31
|
+
* Get the items from the first array that are not in the second array
|
|
32
|
+
* @param first First array
|
|
33
|
+
* @param second Second array
|
|
34
|
+
* @returns Unique values from the first array
|
|
35
|
+
*/
|
|
36
|
+
export function difference<First, Second>(first: First[], second: Second[]): First[];
|
|
37
|
+
|
|
38
|
+
export function difference(first: unknown[], second: unknown[], key?: unknown): unknown[] {
|
|
39
|
+
return compareSets(COMPARE_SETS_DIFFERENCE, first, second, key);
|
|
40
|
+
}
|
package/src/array/exists.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import {findValue} from '../internal/array/find';
|
|
1
|
+
import {FIND_VALUE_INDEX, findValue} from '../internal/array/find';
|
|
2
2
|
import type {PlainObject} from '../models';
|
|
3
3
|
|
|
4
4
|
// #region Functions
|
|
@@ -52,7 +52,7 @@ export function exists(array: unknown[], ...parameters: unknown[]): boolean {
|
|
|
52
52
|
return Array.isArray(array) ? array.includes(parameters[0]) : false;
|
|
53
53
|
}
|
|
54
54
|
|
|
55
|
-
return (findValue(
|
|
55
|
+
return (findValue(FIND_VALUE_INDEX, array, parameters) as number) > -1;
|
|
56
56
|
}
|
|
57
57
|
|
|
58
58
|
// #endregion
|
package/src/array/filter.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import {findValues} from '../internal/array/find';
|
|
1
|
+
import {FIND_VALUES_ALL, findValues} from '../internal/array/find';
|
|
2
2
|
import type {PlainObject} from '../models';
|
|
3
3
|
|
|
4
4
|
// #region Functions
|
|
@@ -48,7 +48,7 @@ export function filter<Item>(
|
|
|
48
48
|
export function filter<Item>(array: Item[], item: Item): Item[];
|
|
49
49
|
|
|
50
50
|
export function filter(array: unknown[], ...parameters: unknown[]): unknown[] {
|
|
51
|
-
return findValues(
|
|
51
|
+
return findValues(FIND_VALUES_ALL, array, parameters).matched;
|
|
52
52
|
}
|
|
53
53
|
|
|
54
54
|
filter.remove = removeFiltered;
|
|
@@ -72,7 +72,7 @@ function removeFiltered<Item>(
|
|
|
72
72
|
function removeFiltered<Item>(array: Item[], item: Item): unknown[];
|
|
73
73
|
|
|
74
74
|
function removeFiltered(array: unknown[], ...parameters: unknown[]): unknown[] {
|
|
75
|
-
return findValues(
|
|
75
|
+
return findValues(FIND_VALUES_ALL, array, parameters).notMatched;
|
|
76
76
|
}
|
|
77
77
|
|
|
78
78
|
// #endregion
|
package/src/array/find.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import {findValue} from '../internal/array/find';
|
|
1
|
+
import {FIND_VALUE_VALUE, findValue} from '../internal/array/find';
|
|
2
2
|
import type {PlainObject} from '../models';
|
|
3
3
|
|
|
4
4
|
// #region Functions
|
|
@@ -49,7 +49,7 @@ export function find<Item>(
|
|
|
49
49
|
export function find<Item>(array: Item[], value: Item): Item | undefined;
|
|
50
50
|
|
|
51
51
|
export function find<Item>(array: unknown[], ...parameters: unknown[]): Item | undefined {
|
|
52
|
-
return findValue(
|
|
52
|
+
return findValue(FIND_VALUE_VALUE, array, parameters) as Item | undefined;
|
|
53
53
|
}
|
|
54
54
|
|
|
55
55
|
// #endregion
|
package/src/array/index-of.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import {findValue} from '../internal/array/find';
|
|
1
|
+
import {FIND_VALUE_INDEX, findValue} from '../internal/array/find';
|
|
2
2
|
import type {PlainObject} from '../models';
|
|
3
3
|
|
|
4
4
|
// #region Functions
|
|
@@ -48,7 +48,7 @@ export function indexOf<Item>(
|
|
|
48
48
|
export function indexOf<Item>(array: Item[], item: Item): number;
|
|
49
49
|
|
|
50
50
|
export function indexOf(array: unknown[], ...parameters: unknown[]): number {
|
|
51
|
-
return findValue(
|
|
51
|
+
return findValue(FIND_VALUE_INDEX, array, parameters) as number;
|
|
52
52
|
}
|
|
53
53
|
|
|
54
54
|
// #endregion
|
|
@@ -2,6 +2,7 @@ export * from '../internal/array/chunk';
|
|
|
2
2
|
export * from '../internal/array/compact';
|
|
3
3
|
export * from '../internal/array/shuffle';
|
|
4
4
|
|
|
5
|
+
export * from './difference';
|
|
5
6
|
export * from './exists';
|
|
6
7
|
export * from './filter';
|
|
7
8
|
export * from './find';
|
|
@@ -10,6 +11,7 @@ export * from './from';
|
|
|
10
11
|
export * from './get';
|
|
11
12
|
export * from './index-of';
|
|
12
13
|
export * from './insert';
|
|
14
|
+
export * from './intersection';
|
|
13
15
|
export * from './partition';
|
|
14
16
|
export * from './push';
|
|
15
17
|
export * from './select';
|
|
@@ -17,4 +19,5 @@ export * from './sort';
|
|
|
17
19
|
export * from './splice';
|
|
18
20
|
export * from './to-set';
|
|
19
21
|
export * from './toggle';
|
|
22
|
+
export * from './union';
|
|
20
23
|
export * from './update';
|
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
import {COMPARE_SETS_INTERSECTION, compareSets} from '../internal/array/sets';
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* Get the common values between two arrays
|
|
5
|
+
* @param first First array
|
|
6
|
+
* @param second Second array
|
|
7
|
+
* @param callback Callback to get an item's value for comparison
|
|
8
|
+
* @returns Common values from both arrays
|
|
9
|
+
*/
|
|
10
|
+
export function intersection<First, Second>(
|
|
11
|
+
first: First[],
|
|
12
|
+
second: Second[],
|
|
13
|
+
callback: (item: First | Second) => unknown,
|
|
14
|
+
): First[];
|
|
15
|
+
|
|
16
|
+
/**
|
|
17
|
+
* Get the common values between two arrays
|
|
18
|
+
* @param first First array
|
|
19
|
+
* @param second Second array
|
|
20
|
+
* @param key Key to get an item's value for comparison
|
|
21
|
+
* @returns Common values from both arrays
|
|
22
|
+
*/
|
|
23
|
+
export function intersection<
|
|
24
|
+
First extends Record<string, unknown>,
|
|
25
|
+
Second extends Record<string, unknown>,
|
|
26
|
+
Key extends keyof First & keyof Second,
|
|
27
|
+
>(first: First[], second: Second[], key: Key): First[];
|
|
28
|
+
|
|
29
|
+
/**
|
|
30
|
+
* Get the common values between two arrays
|
|
31
|
+
* @param first First array
|
|
32
|
+
* @param second Second array
|
|
33
|
+
* @returns Common values from both arrays
|
|
34
|
+
*/
|
|
35
|
+
export function intersection<First, Second>(first: First[], second: Second[]): First[];
|
|
36
|
+
|
|
37
|
+
export function intersection(first: unknown[], second: unknown[], key?: unknown): unknown[] {
|
|
38
|
+
return compareSets(COMPARE_SETS_INTERSECTION, first, second, key);
|
|
39
|
+
}
|
package/src/array/partition.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import {findValues} from '../internal/array/find';
|
|
1
|
+
import {FIND_VALUES_ALL, findValues} from '../internal/array/find';
|
|
2
2
|
import type {PlainObject} from '../models';
|
|
3
3
|
|
|
4
4
|
// #region Functions
|
|
@@ -48,7 +48,7 @@ export function partition<Item>(
|
|
|
48
48
|
export function partition<Item>(array: Item[], item: Item): Item[][];
|
|
49
49
|
|
|
50
50
|
export function partition(array: unknown[], ...parameters: unknown[]): unknown[][] {
|
|
51
|
-
const {matched, notMatched} = findValues(
|
|
51
|
+
const {matched, notMatched} = findValues(FIND_VALUES_ALL, array, parameters);
|
|
52
52
|
|
|
53
53
|
return [matched, notMatched];
|
|
54
54
|
}
|
package/src/array/select.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import {findValues} from '../internal/array/find';
|
|
1
|
+
import {FIND_VALUES_ALL, findValues} from '../internal/array/find';
|
|
2
2
|
import type {PlainObject} from '../models';
|
|
3
3
|
|
|
4
4
|
/**
|
|
@@ -88,5 +88,5 @@ export function select<
|
|
|
88
88
|
export function select(array: unknown[], ...parameters: unknown[]): unknown[] {
|
|
89
89
|
const mapper = parameters.pop();
|
|
90
90
|
|
|
91
|
-
return findValues(
|
|
91
|
+
return findValues(FIND_VALUES_ALL, array, parameters, mapper).matched;
|
|
92
92
|
}
|
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
import {COMPARE_SETS_UNION, compareSets} from '../internal/array/sets';
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* Get the combined, unique values from two arrays
|
|
5
|
+
* @param first First array
|
|
6
|
+
* @param second Second array
|
|
7
|
+
* @param callback Callback to get an item's value for comparison
|
|
8
|
+
* @returns Combined, unique values from both arrays
|
|
9
|
+
*/
|
|
10
|
+
export function union<First, Second>(
|
|
11
|
+
first: First[],
|
|
12
|
+
second: Second[],
|
|
13
|
+
callback: (item: First | Second) => unknown,
|
|
14
|
+
): (First | Second)[];
|
|
15
|
+
|
|
16
|
+
/**
|
|
17
|
+
* Get the combined, unique values from two arrays
|
|
18
|
+
* @param first First array
|
|
19
|
+
* @param second Second array
|
|
20
|
+
* @param key Key to get an item's value for comparison
|
|
21
|
+
* @returns Combined, unique values from both arrays
|
|
22
|
+
*/
|
|
23
|
+
export function union<
|
|
24
|
+
First extends Record<string, unknown>,
|
|
25
|
+
Second extends Record<string, unknown>,
|
|
26
|
+
Key extends keyof First & keyof Second,
|
|
27
|
+
>(first: First[], second: Second[], key: Key): (First | Second)[];
|
|
28
|
+
|
|
29
|
+
/**
|
|
30
|
+
* Get the combined, unique values from two arrays
|
|
31
|
+
* @param first First array
|
|
32
|
+
* @param second Second array
|
|
33
|
+
* @returns Combined, unique values from both arrays
|
|
34
|
+
*/
|
|
35
|
+
export function union<First, Second>(first: First[], second: Second[]): (First | Second)[];
|
|
36
|
+
|
|
37
|
+
export function union(first: unknown[], second: unknown[], key?: unknown): unknown[] {
|
|
38
|
+
return compareSets(COMPARE_SETS_UNION, first, second, key);
|
|
39
|
+
}
|
package/src/array/unique.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import {findValues} from '../internal/array/find';
|
|
1
|
+
import {FIND_VALUES_UNIQUE, findValues} from '../internal/array/find';
|
|
2
2
|
import type {PlainObject} from '../models';
|
|
3
3
|
|
|
4
4
|
// #region Functions
|
|
@@ -37,7 +37,7 @@ export function unique(array: unknown[], key?: unknown): unknown[] {
|
|
|
37
37
|
return [];
|
|
38
38
|
}
|
|
39
39
|
|
|
40
|
-
return array.length > 1 ? findValues(
|
|
40
|
+
return array.length > 1 ? findValues(FIND_VALUES_UNIQUE, array, [key, undefined]).matched : array;
|
|
41
41
|
}
|
|
42
42
|
|
|
43
43
|
// #endregion
|
package/src/index.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
export * from './array/group-by';
|
|
2
|
-
export * from './array/
|
|
2
|
+
export * from './array/index';
|
|
3
3
|
export * from './array/to-map';
|
|
4
4
|
export * from './array/to-record';
|
|
5
5
|
export * from './array/unique';
|
|
@@ -17,17 +17,14 @@ export * from './internal/value/has';
|
|
|
17
17
|
export * from './internal/value/set';
|
|
18
18
|
|
|
19
19
|
export * from './string/case';
|
|
20
|
+
export * from './string/index';
|
|
20
21
|
export * from './string/match';
|
|
21
|
-
export * from './string/misc';
|
|
22
22
|
export * from './string/template';
|
|
23
23
|
|
|
24
24
|
export * from './value/clone';
|
|
25
25
|
export * from './value/diff';
|
|
26
|
+
export * from './value/index';
|
|
26
27
|
export * from './value/merge';
|
|
27
|
-
export * from './value/omit';
|
|
28
|
-
export * from './value/pick';
|
|
29
|
-
export * from './value/smush';
|
|
30
|
-
export * from './value/unsmush';
|
|
31
28
|
|
|
32
29
|
export * from './beacon';
|
|
33
30
|
export * from './color';
|
|
@@ -83,7 +83,7 @@ export function findValues(
|
|
|
83
83
|
const {bool, key, value} = getParameters(parameters);
|
|
84
84
|
const callbacks = getArrayCallbacks(bool, key);
|
|
85
85
|
|
|
86
|
-
if (type ===
|
|
86
|
+
if (type === FIND_VALUES_UNIQUE && callbacks?.keyed == null && length >= UNIQUE_THRESHOLD) {
|
|
87
87
|
result.matched = [...new Set(array)];
|
|
88
88
|
|
|
89
89
|
return result;
|
|
@@ -91,7 +91,7 @@ export function findValues(
|
|
|
91
91
|
|
|
92
92
|
const mapCallback = typeof mapper === 'function' ? mapper : undefined;
|
|
93
93
|
|
|
94
|
-
if (callbacks?.bool != null || (type ===
|
|
94
|
+
if (callbacks?.bool != null || (type === FIND_VALUES_ALL && key == null)) {
|
|
95
95
|
const callback = callbacks?.bool ?? (item => Object.is(item, value));
|
|
96
96
|
|
|
97
97
|
for (let index = 0; index < length; index += 1) {
|
|
@@ -113,7 +113,10 @@ export function findValues(
|
|
|
113
113
|
const item = array[index];
|
|
114
114
|
const keyed = callbacks?.keyed?.(item, index, array) ?? item;
|
|
115
115
|
|
|
116
|
-
if (
|
|
116
|
+
if (
|
|
117
|
+
(type === FIND_VALUES_ALL && Object.is(keyed, value)) ||
|
|
118
|
+
(type === FIND_VALUES_UNIQUE && !keys.has(keyed))
|
|
119
|
+
) {
|
|
117
120
|
keys.add(keyed);
|
|
118
121
|
result.matched.push(mapCallback?.(item, index, array) ?? item);
|
|
119
122
|
} else {
|
|
@@ -138,6 +141,14 @@ function getParameters(original: unknown[]): Parameters {
|
|
|
138
141
|
|
|
139
142
|
// #region Variables
|
|
140
143
|
|
|
144
|
+
export const FIND_VALUE_INDEX: FindValueType = 'index';
|
|
145
|
+
|
|
146
|
+
export const FIND_VALUE_VALUE: FindValueType = 'value';
|
|
147
|
+
|
|
148
|
+
export const FIND_VALUES_ALL: FindValuesType = 'all';
|
|
149
|
+
|
|
150
|
+
export const FIND_VALUES_UNIQUE: FindValuesType = 'unique';
|
|
151
|
+
|
|
141
152
|
const UNIQUE_THRESHOLD = 100;
|
|
142
153
|
|
|
143
154
|
// #endregion
|
|
@@ -0,0 +1,74 @@
|
|
|
1
|
+
import {getArrayCallback} from './callbacks';
|
|
2
|
+
|
|
3
|
+
// #region Types
|
|
4
|
+
|
|
5
|
+
type CompareSetsType = 'difference' | 'intersection' | 'union';
|
|
6
|
+
|
|
7
|
+
// #endregion
|
|
8
|
+
|
|
9
|
+
// #region Functions
|
|
10
|
+
|
|
11
|
+
export function compareSets(
|
|
12
|
+
type: CompareSetsType,
|
|
13
|
+
first: unknown[],
|
|
14
|
+
second: unknown[],
|
|
15
|
+
key?: unknown,
|
|
16
|
+
): unknown[] {
|
|
17
|
+
if (!Array.isArray(first)) {
|
|
18
|
+
return [];
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
const isDifference = type === COMPARE_SETS_DIFFERENCE;
|
|
22
|
+
const isIntersection = type === COMPARE_SETS_INTERSECTION;
|
|
23
|
+
const isUnion = type === COMPARE_SETS_UNION;
|
|
24
|
+
|
|
25
|
+
if (first.length === 0) {
|
|
26
|
+
return isDifference ? [...first] : isIntersection ? [] : [...second];
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
if (!Array.isArray(second) || second.length === 0) {
|
|
30
|
+
return isIntersection ? [] : [...first];
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
const callback = getArrayCallback(key);
|
|
34
|
+
|
|
35
|
+
const values = isUnion ? first : second;
|
|
36
|
+
let {length} = values;
|
|
37
|
+
|
|
38
|
+
const set = new Set<unknown>([]);
|
|
39
|
+
|
|
40
|
+
for (let index = 0; index < length; index += 1) {
|
|
41
|
+
const item = values[index];
|
|
42
|
+
|
|
43
|
+
set.add(callback?.(item, index, values) ?? item);
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
const source = isUnion ? second : first;
|
|
47
|
+
|
|
48
|
+
length = source.length;
|
|
49
|
+
|
|
50
|
+
const result: unknown[] = isUnion ? [...first] : [];
|
|
51
|
+
|
|
52
|
+
for (let index = 0; index < length; index += 1) {
|
|
53
|
+
const item = source[index];
|
|
54
|
+
const value = callback?.(item, index, source) ?? item;
|
|
55
|
+
|
|
56
|
+
if (isIntersection ? set.has(value) : !set.has(value)) {
|
|
57
|
+
result.push(item);
|
|
58
|
+
}
|
|
59
|
+
}
|
|
60
|
+
|
|
61
|
+
return result;
|
|
62
|
+
}
|
|
63
|
+
|
|
64
|
+
// #endregion
|
|
65
|
+
|
|
66
|
+
// #region Variables
|
|
67
|
+
|
|
68
|
+
export const COMPARE_SETS_DIFFERENCE: CompareSetsType = 'difference';
|
|
69
|
+
|
|
70
|
+
export const COMPARE_SETS_INTERSECTION: CompareSetsType = 'intersection';
|
|
71
|
+
|
|
72
|
+
export const COMPARE_SETS_UNION: CompareSetsType = 'union';
|
|
73
|
+
|
|
74
|
+
// #endregion
|
package/src/value/merge.ts
CHANGED
|
@@ -89,8 +89,24 @@ function handleMerge(values: ArrayOrPlainObject[], options: Options): ArrayOrPla
|
|
|
89
89
|
export function merge<Model extends ArrayOrPlainObject>(
|
|
90
90
|
values: NestedPartial<Model>[],
|
|
91
91
|
options?: MergeOptions,
|
|
92
|
-
): Model
|
|
93
|
-
|
|
92
|
+
): Model;
|
|
93
|
+
|
|
94
|
+
/**
|
|
95
|
+
* Merge multiple arrays or objects into a single one
|
|
96
|
+
* @param values Values to merge
|
|
97
|
+
* @param options Merging options
|
|
98
|
+
* @returns Merged value
|
|
99
|
+
*/
|
|
100
|
+
export function merge(
|
|
101
|
+
values: NestedPartial<ArrayOrPlainObject>[],
|
|
102
|
+
options?: MergeOptions,
|
|
103
|
+
): ArrayOrPlainObject;
|
|
104
|
+
|
|
105
|
+
export function merge(
|
|
106
|
+
values: NestedPartial<ArrayOrPlainObject>[],
|
|
107
|
+
options?: MergeOptions,
|
|
108
|
+
): ArrayOrPlainObject {
|
|
109
|
+
return handleMerge(values, getMergeOptions(options));
|
|
94
110
|
}
|
|
95
111
|
|
|
96
112
|
merge.initialize = initializeMerger;
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
import type { PlainObject } from '../models';
|
|
2
|
+
/**
|
|
3
|
+
* Get the items from the first array that are not in the second array
|
|
4
|
+
* @param first First array
|
|
5
|
+
* @param second Second array
|
|
6
|
+
* @param callback Callback to get an item's value for comparison
|
|
7
|
+
* @returns Unique values from the first array
|
|
8
|
+
*/
|
|
9
|
+
export declare function difference<First, Second>(first: First[], second: Second[], callback: (item: First | Second) => unknown): First[];
|
|
10
|
+
/**
|
|
11
|
+
* Get the items from the first array that are not in the second array
|
|
12
|
+
* @param first First array
|
|
13
|
+
* @param second Second array
|
|
14
|
+
* @param key Key to get an item's value for comparison
|
|
15
|
+
* @returns Unique values from the first array
|
|
16
|
+
*/
|
|
17
|
+
export declare function difference<First extends PlainObject, Second extends PlainObject, Key extends keyof First & keyof Second>(first: First[], second: Second[], key: Key): First[];
|
|
18
|
+
/**
|
|
19
|
+
* Get the items from the first array that are not in the second array
|
|
20
|
+
* @param first First array
|
|
21
|
+
* @param second Second array
|
|
22
|
+
* @returns Unique values from the first array
|
|
23
|
+
*/
|
|
24
|
+
export declare function difference<First, Second>(first: First[], second: Second[]): First[];
|
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
export * from '../internal/array/chunk';
|
|
2
2
|
export * from '../internal/array/compact';
|
|
3
3
|
export * from '../internal/array/shuffle';
|
|
4
|
+
export * from './difference';
|
|
4
5
|
export * from './exists';
|
|
5
6
|
export * from './filter';
|
|
6
7
|
export * from './find';
|
|
@@ -9,6 +10,7 @@ export * from './from';
|
|
|
9
10
|
export * from './get';
|
|
10
11
|
export * from './index-of';
|
|
11
12
|
export * from './insert';
|
|
13
|
+
export * from './intersection';
|
|
12
14
|
export * from './partition';
|
|
13
15
|
export * from './push';
|
|
14
16
|
export * from './select';
|
|
@@ -16,4 +18,5 @@ export * from './sort';
|
|
|
16
18
|
export * from './splice';
|
|
17
19
|
export * from './to-set';
|
|
18
20
|
export * from './toggle';
|
|
21
|
+
export * from './union';
|
|
19
22
|
export * from './update';
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Get the common values between two arrays
|
|
3
|
+
* @param first First array
|
|
4
|
+
* @param second Second array
|
|
5
|
+
* @param callback Callback to get an item's value for comparison
|
|
6
|
+
* @returns Common values from both arrays
|
|
7
|
+
*/
|
|
8
|
+
export declare function intersection<First, Second>(first: First[], second: Second[], callback: (item: First | Second) => unknown): First[];
|
|
9
|
+
/**
|
|
10
|
+
* Get the common values between two arrays
|
|
11
|
+
* @param first First array
|
|
12
|
+
* @param second Second array
|
|
13
|
+
* @param key Key to get an item's value for comparison
|
|
14
|
+
* @returns Common values from both arrays
|
|
15
|
+
*/
|
|
16
|
+
export declare function intersection<First extends Record<string, unknown>, Second extends Record<string, unknown>, Key extends keyof First & keyof Second>(first: First[], second: Second[], key: Key): First[];
|
|
17
|
+
/**
|
|
18
|
+
* Get the common values between two arrays
|
|
19
|
+
* @param first First array
|
|
20
|
+
* @param second Second array
|
|
21
|
+
* @returns Common values from both arrays
|
|
22
|
+
*/
|
|
23
|
+
export declare function intersection<First, Second>(first: First[], second: Second[]): First[];
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Get the combined, unique values from two arrays
|
|
3
|
+
* @param first First array
|
|
4
|
+
* @param second Second array
|
|
5
|
+
* @param callback Callback to get an item's value for comparison
|
|
6
|
+
* @returns Combined, unique values from both arrays
|
|
7
|
+
*/
|
|
8
|
+
export declare function union<First, Second>(first: First[], second: Second[], callback: (item: First | Second) => unknown): (First | Second)[];
|
|
9
|
+
/**
|
|
10
|
+
* Get the combined, unique values from two arrays
|
|
11
|
+
* @param first First array
|
|
12
|
+
* @param second Second array
|
|
13
|
+
* @param key Key to get an item's value for comparison
|
|
14
|
+
* @returns Combined, unique values from both arrays
|
|
15
|
+
*/
|
|
16
|
+
export declare function union<First extends Record<string, unknown>, Second extends Record<string, unknown>, Key extends keyof First & keyof Second>(first: First[], second: Second[], key: Key): (First | Second)[];
|
|
17
|
+
/**
|
|
18
|
+
* Get the combined, unique values from two arrays
|
|
19
|
+
* @param first First array
|
|
20
|
+
* @param second Second array
|
|
21
|
+
* @returns Combined, unique values from both arrays
|
|
22
|
+
*/
|
|
23
|
+
export declare function union<First, Second>(first: First[], second: Second[]): (First | Second)[];
|
package/types/index.d.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
export * from './array/group-by';
|
|
2
|
-
export * from './array/
|
|
2
|
+
export * from './array/index';
|
|
3
3
|
export * from './array/to-map';
|
|
4
4
|
export * from './array/to-record';
|
|
5
5
|
export * from './array/unique';
|
|
@@ -14,16 +14,13 @@ export * from './internal/value/get';
|
|
|
14
14
|
export * from './internal/value/has';
|
|
15
15
|
export * from './internal/value/set';
|
|
16
16
|
export * from './string/case';
|
|
17
|
+
export * from './string/index';
|
|
17
18
|
export * from './string/match';
|
|
18
|
-
export * from './string/misc';
|
|
19
19
|
export * from './string/template';
|
|
20
20
|
export * from './value/clone';
|
|
21
21
|
export * from './value/diff';
|
|
22
|
+
export * from './value/index';
|
|
22
23
|
export * from './value/merge';
|
|
23
|
-
export * from './value/omit';
|
|
24
|
-
export * from './value/pick';
|
|
25
|
-
export * from './value/smush';
|
|
26
|
-
export * from './value/unsmush';
|
|
27
24
|
export * from './beacon';
|
|
28
25
|
export * from './color';
|
|
29
26
|
export * from './is';
|
|
@@ -6,4 +6,8 @@ type FindValuesResult = {
|
|
|
6
6
|
type FindValuesType = 'all' | 'unique';
|
|
7
7
|
export declare function findValue(type: FindValueType, array: unknown[], parameters: unknown[]): unknown;
|
|
8
8
|
export declare function findValues(type: FindValuesType, array: unknown[], parameters: unknown[], mapper?: unknown): FindValuesResult;
|
|
9
|
+
export declare const FIND_VALUE_INDEX: FindValueType;
|
|
10
|
+
export declare const FIND_VALUE_VALUE: FindValueType;
|
|
11
|
+
export declare const FIND_VALUES_ALL: FindValuesType;
|
|
12
|
+
export declare const FIND_VALUES_UNIQUE: FindValuesType;
|
|
9
13
|
export {};
|
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
type CompareSetsType = 'difference' | 'intersection' | 'union';
|
|
2
|
+
export declare function compareSets(type: CompareSetsType, first: unknown[], second: unknown[], key?: unknown): unknown[];
|
|
3
|
+
export declare const COMPARE_SETS_DIFFERENCE: CompareSetsType;
|
|
4
|
+
export declare const COMPARE_SETS_INTERSECTION: CompareSetsType;
|
|
5
|
+
export declare const COMPARE_SETS_UNION: CompareSetsType;
|
|
6
|
+
export {};
|
package/types/value/merge.d.ts
CHANGED
|
@@ -32,6 +32,13 @@ export type Merger<Model extends ArrayOrPlainObject = ArrayOrPlainObject> = (val
|
|
|
32
32
|
* @returns Merged value
|
|
33
33
|
*/
|
|
34
34
|
export declare function merge<Model extends ArrayOrPlainObject>(values: NestedPartial<Model>[], options?: MergeOptions): Model;
|
|
35
|
+
/**
|
|
36
|
+
* Merge multiple arrays or objects into a single one
|
|
37
|
+
* @param values Values to merge
|
|
38
|
+
* @param options Merging options
|
|
39
|
+
* @returns Merged value
|
|
40
|
+
*/
|
|
41
|
+
export declare function merge(values: NestedPartial<ArrayOrPlainObject>[], options?: MergeOptions): ArrayOrPlainObject;
|
|
35
42
|
export declare namespace merge {
|
|
36
43
|
var initialize: typeof initializeMerger;
|
|
37
44
|
}
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|