@oscarpalmer/atoms 0.166.0 → 0.166.2
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/index.d.mts +2 -1
- package/dist/array/index.mjs +2 -1
- package/dist/index.d.mts +22 -22
- package/dist/index.mjs +7 -7
- package/dist/internal/function/timer.mjs +1 -1
- package/package.json +1 -1
- package/src/array/index.ts +1 -0
- package/src/internal/function/timer.ts +2 -4
package/dist/array/index.d.mts
CHANGED
|
@@ -20,5 +20,6 @@ import { splice } from "./splice.mjs";
|
|
|
20
20
|
import { toSet } from "./to-set.mjs";
|
|
21
21
|
import { toggle } from "./toggle.mjs";
|
|
22
22
|
import { union } from "./union.mjs";
|
|
23
|
+
import { unique } from "./unique.mjs";
|
|
23
24
|
import { update } from "./update.mjs";
|
|
24
|
-
export { ArrayComparisonSorter, ArrayKeySorter, ArrayPosition, ArrayValueSorter, SORT_DIRECTION_ASCENDING, SORT_DIRECTION_DESCENDING, SortDirection, chunk, compact, difference, drop, endsWithArray, exists, find, flatten, getArray, getArrayPosition, includesArray, indexOf, indexOfArray, insert, intersection, partition, push, range, select, shuffle, slice, sort, splice, startsWithArray, take, times, toSet, toggle, union, update };
|
|
25
|
+
export { ArrayComparisonSorter, ArrayKeySorter, ArrayPosition, ArrayValueSorter, SORT_DIRECTION_ASCENDING, SORT_DIRECTION_DESCENDING, SortDirection, chunk, compact, difference, drop, endsWithArray, exists, find, flatten, getArray, getArrayPosition, includesArray, indexOf, indexOfArray, insert, intersection, partition, push, range, select, shuffle, slice, sort, splice, startsWithArray, take, times, toSet, toggle, union, unique, update };
|
package/dist/array/index.mjs
CHANGED
|
@@ -20,5 +20,6 @@ import { splice } from "./splice.mjs";
|
|
|
20
20
|
import { toSet } from "./to-set.mjs";
|
|
21
21
|
import { toggle } from "./toggle.mjs";
|
|
22
22
|
import { union } from "./union.mjs";
|
|
23
|
+
import { unique } from "./unique.mjs";
|
|
23
24
|
import { update } from "./update.mjs";
|
|
24
|
-
export { SORT_DIRECTION_ASCENDING, SORT_DIRECTION_DESCENDING, chunk, compact, difference, drop, endsWithArray, exists, find, flatten, getArray, getArrayPosition, includesArray, indexOf, indexOfArray, insert, intersection, partition, push, range, select, shuffle, slice, sort, splice, startsWithArray, take, times, toSet, toggle, union, update };
|
|
25
|
+
export { SORT_DIRECTION_ASCENDING, SORT_DIRECTION_DESCENDING, chunk, compact, difference, drop, endsWithArray, exists, find, flatten, getArray, getArrayPosition, includesArray, indexOf, indexOfArray, insert, intersection, partition, push, range, select, shuffle, slice, sort, splice, startsWithArray, take, times, toSet, toggle, union, unique, update };
|
package/dist/index.d.mts
CHANGED
|
@@ -1050,6 +1050,28 @@ declare function union<First extends Record<string, unknown>, Second extends Rec
|
|
|
1050
1050
|
*/
|
|
1051
1051
|
declare function union<First, Second>(first: First[], second: Second[]): (First | Second)[];
|
|
1052
1052
|
//#endregion
|
|
1053
|
+
//#region src/array/unique.d.ts
|
|
1054
|
+
/**
|
|
1055
|
+
* Get an array of unique items
|
|
1056
|
+
* @param array Original array
|
|
1057
|
+
* @param callback Callback to get an item's value
|
|
1058
|
+
* @returns Array of unique items
|
|
1059
|
+
*/
|
|
1060
|
+
declare function unique<Item>(array: Item[], callback: (item: Item, index: number, array: Item[]) => unknown): Item[];
|
|
1061
|
+
/**
|
|
1062
|
+
* Get an array of unique items
|
|
1063
|
+
* @param array Original array
|
|
1064
|
+
* @param key Key to use for unique value
|
|
1065
|
+
* @returns Array of unique items
|
|
1066
|
+
*/
|
|
1067
|
+
declare function unique<Item extends PlainObject, ItemKey extends keyof Item>(array: Item[], key: ItemKey): Item[];
|
|
1068
|
+
/**
|
|
1069
|
+
* Get an array of unique items
|
|
1070
|
+
* @param array Original array
|
|
1071
|
+
* @returns Array of unique items
|
|
1072
|
+
*/
|
|
1073
|
+
declare function unique<Item>(array: Item[]): Item[];
|
|
1074
|
+
//#endregion
|
|
1053
1075
|
//#region src/array/update.d.ts
|
|
1054
1076
|
/**
|
|
1055
1077
|
* Update an item in an array: if the item exists, it will be updated; if it doesn't, it will be added
|
|
@@ -1468,28 +1490,6 @@ declare function toRecordArrays<Item, Callback extends (item: Item, index: numbe
|
|
|
1468
1490
|
*/
|
|
1469
1491
|
declare function toRecordArrays<Item extends PlainObject, ItemKey extends keyof Item>(array: Item[], key: ItemKey): Simplify<Record<KeyedValue<Item, ItemKey>, Item[]>>;
|
|
1470
1492
|
//#endregion
|
|
1471
|
-
//#region src/array/unique.d.ts
|
|
1472
|
-
/**
|
|
1473
|
-
* Get an array of unique items
|
|
1474
|
-
* @param array Original array
|
|
1475
|
-
* @param callback Callback to get an item's value
|
|
1476
|
-
* @returns Array of unique items
|
|
1477
|
-
*/
|
|
1478
|
-
declare function unique<Item>(array: Item[], callback: (item: Item, index: number, array: Item[]) => unknown): Item[];
|
|
1479
|
-
/**
|
|
1480
|
-
* Get an array of unique items
|
|
1481
|
-
* @param array Original array
|
|
1482
|
-
* @param key Key to use for unique value
|
|
1483
|
-
* @returns Array of unique items
|
|
1484
|
-
*/
|
|
1485
|
-
declare function unique<Item extends PlainObject, ItemKey extends keyof Item>(array: Item[], key: ItemKey): Item[];
|
|
1486
|
-
/**
|
|
1487
|
-
* Get an array of unique items
|
|
1488
|
-
* @param array Original array
|
|
1489
|
-
* @returns Array of unique items
|
|
1490
|
-
*/
|
|
1491
|
-
declare function unique<Item>(array: Item[]): Item[];
|
|
1492
|
-
//#endregion
|
|
1493
1493
|
//#region src/function/assert.d.ts
|
|
1494
1494
|
type Asserter<Value> = (value: unknown) => asserts value is Value;
|
|
1495
1495
|
/**
|
package/dist/index.mjs
CHANGED
|
@@ -877,6 +877,12 @@ function union(first, second, key) {
|
|
|
877
877
|
return compareSets(COMPARE_SETS_UNION, first, second, key);
|
|
878
878
|
}
|
|
879
879
|
//#endregion
|
|
880
|
+
//#region src/array/unique.ts
|
|
881
|
+
function unique(array, key) {
|
|
882
|
+
if (!Array.isArray(array)) return [];
|
|
883
|
+
return array.length > 1 ? findValues(FIND_VALUES_UNIQUE, array, [key, void 0]).matched : array;
|
|
884
|
+
}
|
|
885
|
+
//#endregion
|
|
880
886
|
//#region src/array/update.ts
|
|
881
887
|
function update(array, values, key) {
|
|
882
888
|
return updateInArray(array, values, key, true);
|
|
@@ -1052,12 +1058,6 @@ function toRecordArrays(array, first, second) {
|
|
|
1052
1058
|
return groupValues(array, first, second, true);
|
|
1053
1059
|
}
|
|
1054
1060
|
//#endregion
|
|
1055
|
-
//#region src/array/unique.ts
|
|
1056
|
-
function unique(array, key) {
|
|
1057
|
-
if (!Array.isArray(array)) return [];
|
|
1058
|
-
return array.length > 1 ? findValues(FIND_VALUES_UNIQUE, array, [key, void 0]).matched : array;
|
|
1059
|
-
}
|
|
1060
|
-
//#endregion
|
|
1061
1061
|
//#region src/function/assert.ts
|
|
1062
1062
|
/**
|
|
1063
1063
|
* Asserts that a condition is true, throwing an error if it is not
|
|
@@ -1127,7 +1127,7 @@ function getTimer(type, callback, time) {
|
|
|
1127
1127
|
function run(now) {
|
|
1128
1128
|
start ??= now;
|
|
1129
1129
|
if (interval === 0 || now - start >= interval - OFFSET) {
|
|
1130
|
-
|
|
1130
|
+
start = throttle ? now : void 0;
|
|
1131
1131
|
callback(...args);
|
|
1132
1132
|
} else frame = requestAnimationFrame(run);
|
|
1133
1133
|
}
|
|
@@ -7,7 +7,7 @@ function getTimer(type, callback, time) {
|
|
|
7
7
|
function run(now) {
|
|
8
8
|
start ??= now;
|
|
9
9
|
if (interval === 0 || now - start >= interval - OFFSET) {
|
|
10
|
-
|
|
10
|
+
start = throttle ? now : void 0;
|
|
11
11
|
callback(...args);
|
|
12
12
|
} else frame = requestAnimationFrame(run);
|
|
13
13
|
}
|
package/package.json
CHANGED
package/src/array/index.ts
CHANGED
|
@@ -23,9 +23,7 @@ export function getTimer<Callback extends GenericCallback>(
|
|
|
23
23
|
start ??= now;
|
|
24
24
|
|
|
25
25
|
if (interval === 0 || now - start >= interval - OFFSET) {
|
|
26
|
-
|
|
27
|
-
start = now;
|
|
28
|
-
}
|
|
26
|
+
start = throttle ? now : undefined;
|
|
29
27
|
|
|
30
28
|
callback(...args);
|
|
31
29
|
} else {
|
|
@@ -37,7 +35,7 @@ export function getTimer<Callback extends GenericCallback>(
|
|
|
37
35
|
|
|
38
36
|
let args: Parameters<Callback>;
|
|
39
37
|
let frame: DOMHighResTimeStamp | undefined;
|
|
40
|
-
let start: DOMHighResTimeStamp;
|
|
38
|
+
let start: DOMHighResTimeStamp | undefined;
|
|
41
39
|
|
|
42
40
|
const timer = (...parameters: Parameters<Callback>): void => {
|
|
43
41
|
timer.cancel();
|