@oscarpalmer/atoms 0.160.0 → 0.161.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/index.js +3 -2
- package/dist/array/insert.js +2 -2
- package/dist/array/push.js +2 -2
- package/dist/array/sort.js +4 -2
- package/dist/array/splice.js +2 -2
- package/dist/array/swap.js +56 -0
- package/dist/atoms.full.js +198 -118
- package/dist/beacon.js +5 -3
- package/dist/color/instance.js +1 -0
- package/dist/color/misc/index.js +3 -2
- package/dist/function/memoize.js +2 -1
- package/dist/index.js +3 -2
- package/dist/internal/array/find.js +3 -3
- package/dist/{array → internal/array}/index-of.js +2 -2
- package/dist/internal/array/insert.js +4 -1
- package/dist/internal/math/aggregate.js +5 -1
- package/dist/internal/number.js +1 -1
- package/dist/internal/result.js +3 -1
- package/dist/internal/value/compare.js +3 -2
- package/dist/internal/value/equal.js +4 -2
- package/dist/math.js +2 -2
- package/dist/promise/delay.js +2 -2
- package/dist/promise/index.js +3 -3
- package/dist/promise/misc.js +2 -2
- package/dist/promise/models.js +2 -2
- package/dist/promise/timed.js +3 -3
- package/dist/query.js +2 -1
- package/dist/queue.js +2 -2
- package/dist/string/case.js +20 -12
- package/dist/string/index.js +2 -1
- package/dist/string/match.js +6 -3
- package/dist/value/clone.js +2 -1
- package/dist/value/diff.js +7 -4
- package/package.json +1 -1
- package/src/array/index.ts +3 -2
- package/src/array/insert.ts +2 -2
- package/src/array/push.ts +2 -2
- package/src/array/sort.ts +18 -6
- package/src/array/splice.ts +2 -2
- package/src/array/swap.ts +203 -0
- package/src/beacon.ts +7 -3
- package/src/color/instance.ts +3 -2
- package/src/color/misc/index.ts +5 -3
- package/src/function/memoize.ts +3 -1
- package/src/internal/array/find.ts +3 -3
- package/src/{array → internal/array}/index-of.ts +2 -2
- package/src/internal/array/insert.ts +13 -3
- package/src/internal/math/aggregate.ts +12 -2
- package/src/internal/number.ts +2 -2
- package/src/internal/result.ts +9 -1
- package/src/internal/value/compare.ts +8 -2
- package/src/internal/value/equal.ts +6 -2
- package/src/math.ts +11 -4
- package/src/promise/delay.ts +2 -2
- package/src/promise/index.ts +3 -3
- package/src/promise/misc.ts +2 -2
- package/src/promise/models.ts +2 -2
- package/src/promise/timed.ts +3 -3
- package/src/query.ts +3 -1
- package/src/queue.ts +3 -3
- package/src/string/case.ts +28 -12
- package/src/string/index.ts +7 -1
- package/src/string/match.ts +9 -3
- package/src/value/clone.ts +7 -1
- package/src/value/diff.ts +14 -4
- package/types/array/index.d.ts +3 -2
- package/types/array/sort.d.ts +5 -2
- package/types/array/swap.d.ts +77 -0
- package/types/{array → internal/array}/index-of.d.ts +1 -1
- package/types/internal/array/insert.d.ts +3 -0
- package/types/internal/math/aggregate.d.ts +6 -1
- package/types/promise/models.d.ts +1 -1
package/dist/array/index.js
CHANGED
|
@@ -5,9 +5,9 @@ import { find } from "./find.js";
|
|
|
5
5
|
import { flatten } from "./flatten.js";
|
|
6
6
|
import { range, times } from "./from.js";
|
|
7
7
|
import { getArray } from "./get.js";
|
|
8
|
-
import { indexOf } from "./index-of.js";
|
|
9
8
|
import { chunk } from "../internal/array/chunk.js";
|
|
10
9
|
import { compact } from "../internal/array/compact.js";
|
|
10
|
+
import { indexOf } from "../internal/array/index-of.js";
|
|
11
11
|
import { shuffle } from "../internal/array/shuffle.js";
|
|
12
12
|
import { insert } from "./insert.js";
|
|
13
13
|
import { intersection } from "./intersection.js";
|
|
@@ -18,8 +18,9 @@ import { select } from "./select.js";
|
|
|
18
18
|
import { drop, slice, take } from "./slice.js";
|
|
19
19
|
import { sort } from "./sort.js";
|
|
20
20
|
import { splice } from "./splice.js";
|
|
21
|
+
import { swap } from "./swap.js";
|
|
21
22
|
import { toSet } from "./to-set.js";
|
|
22
23
|
import { toggle } from "./toggle.js";
|
|
23
24
|
import { union } from "./union.js";
|
|
24
25
|
import { update } from "./update.js";
|
|
25
|
-
export { chunk, compact, difference, drop, endsWithArray, exists, filter, find, flatten, getArray, getArrayPosition, includesArray, indexOf, indexOfArray, insert, intersection, partition, push, range, select, shuffle, slice, sort, splice, startsWithArray, take, times, toSet, toggle, union, update };
|
|
26
|
+
export { chunk, compact, difference, drop, endsWithArray, exists, filter, find, flatten, getArray, getArrayPosition, includesArray, indexOf, indexOfArray, insert, intersection, partition, push, range, select, shuffle, slice, sort, splice, startsWithArray, swap, take, times, toSet, toggle, union, update };
|
package/dist/array/insert.js
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
|
-
import { insertValues } from "../internal/array/insert.js";
|
|
1
|
+
import { INSERT_TYPE_INSERT, insertValues } from "../internal/array/insert.js";
|
|
2
2
|
//#region src/array/insert.ts
|
|
3
3
|
function insert(array, indexOrItems, items) {
|
|
4
|
-
return insertValues(
|
|
4
|
+
return insertValues(INSERT_TYPE_INSERT, array, items == null ? indexOrItems : items, typeof indexOrItems === "number" ? indexOrItems : array?.length, 0);
|
|
5
5
|
}
|
|
6
6
|
//#endregion
|
|
7
7
|
export { insert };
|
package/dist/array/push.js
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { insertValues } from "../internal/array/insert.js";
|
|
1
|
+
import { INSERT_TYPE_PUSH, insertValues } from "../internal/array/insert.js";
|
|
2
2
|
//#region src/array/push.ts
|
|
3
3
|
/**
|
|
4
4
|
* Push items into an array _(at the end)_
|
|
@@ -7,7 +7,7 @@ import { insertValues } from "../internal/array/insert.js";
|
|
|
7
7
|
* @returns New length of the array
|
|
8
8
|
*/
|
|
9
9
|
function push(array, pushed) {
|
|
10
|
-
return insertValues(
|
|
10
|
+
return insertValues(INSERT_TYPE_PUSH, array, pushed, array.length, 0);
|
|
11
11
|
}
|
|
12
12
|
//#endregion
|
|
13
13
|
export { push };
|
package/dist/array/sort.js
CHANGED
|
@@ -33,7 +33,7 @@ function getSorter(value, modifier) {
|
|
|
33
33
|
function sort(array, first, second) {
|
|
34
34
|
if (!Array.isArray(array)) return [];
|
|
35
35
|
if (array.length < 2) return array;
|
|
36
|
-
const modifier = (first === true || second === true ? "
|
|
36
|
+
const modifier = (first === true || second === true ? "descending" : "ascending") === "ascending" ? 1 : -1;
|
|
37
37
|
const sorters = (Array.isArray(first) ? first : [first]).map((item) => getSorter(item, modifier)).filter((sorter) => sorter != null).filter((current, index, filtered) => filtered.findIndex((next) => next.identifier === current.identifier) === index);
|
|
38
38
|
const { length } = sorters;
|
|
39
39
|
if (length === 0) return array.sort((firstItem, secondItem) => compare(firstItem, secondItem) * modifier);
|
|
@@ -58,5 +58,7 @@ function sort(array, first, second) {
|
|
|
58
58
|
return 0;
|
|
59
59
|
});
|
|
60
60
|
}
|
|
61
|
+
var SORT_DIRECTION_ASCENDING = "ascending";
|
|
62
|
+
var SORT_DIRECTION_DESCENDING = "descending";
|
|
61
63
|
//#endregion
|
|
62
|
-
export { sort };
|
|
64
|
+
export { SORT_DIRECTION_ASCENDING, SORT_DIRECTION_DESCENDING, sort };
|
package/dist/array/splice.js
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
|
-
import { insertValues } from "../internal/array/insert.js";
|
|
1
|
+
import { INSERT_TYPE_SPLICE, insertValues } from "../internal/array/insert.js";
|
|
2
2
|
//#region src/array/splice.ts
|
|
3
3
|
function splice(array, start, deleteCountOrItems, items) {
|
|
4
|
-
return insertValues(
|
|
4
|
+
return insertValues(INSERT_TYPE_SPLICE, array, typeof deleteCountOrItems === "number" ? items : deleteCountOrItems, start, typeof deleteCountOrItems === "number" ? deleteCountOrItems : 0);
|
|
5
5
|
}
|
|
6
6
|
//#endregion
|
|
7
7
|
export { splice };
|
|
@@ -0,0 +1,56 @@
|
|
|
1
|
+
import { getArrayCallback } from "../internal/array/callbacks.js";
|
|
2
|
+
import { indexOf } from "../internal/array/index-of.js";
|
|
3
|
+
import { indexOfArray } from "./position.js";
|
|
4
|
+
//#region src/array/swap.ts
|
|
5
|
+
function swap(array, first, second, third) {
|
|
6
|
+
if (!Array.isArray(array)) return [];
|
|
7
|
+
if (array.length === 0) return array;
|
|
8
|
+
if (Array.isArray(first) && Array.isArray(second)) return swapArrays(array, first, second, third);
|
|
9
|
+
return swapValues(array, first, second, third);
|
|
10
|
+
}
|
|
11
|
+
swap.indices = swapIndices;
|
|
12
|
+
function swapArrays(array, from, to, key) {
|
|
13
|
+
if (from.length === 0 || to.length === 0) return array;
|
|
14
|
+
if (from.length === 1 && to.length === 1) return swapValues(array, from[0], to[0], key);
|
|
15
|
+
const fromIndex = indexOfArray(array, from, key);
|
|
16
|
+
const toIndex = indexOfArray(array, to, key);
|
|
17
|
+
if (fromIndex === -1 || toIndex === -1) return array;
|
|
18
|
+
const first = fromIndex < toIndex ? from : to;
|
|
19
|
+
const second = fromIndex < toIndex ? to : from;
|
|
20
|
+
const firstIndex = first === from ? fromIndex : toIndex;
|
|
21
|
+
const secondIndex = first === from ? toIndex : fromIndex;
|
|
22
|
+
const firstEnd = firstIndex + first.length - 1;
|
|
23
|
+
if (firstIndex <= secondIndex + second.length - 1 && firstEnd >= secondIndex) return array;
|
|
24
|
+
array.splice(firstIndex, first.length, ...second);
|
|
25
|
+
array.splice(secondIndex, second.length, ...first);
|
|
26
|
+
return array;
|
|
27
|
+
}
|
|
28
|
+
/**
|
|
29
|
+
* Swap two indiced items in an array
|
|
30
|
+
*
|
|
31
|
+
* If either index is out of bounds, the array will be returned unchanged
|
|
32
|
+
* @param array Array of items to swap
|
|
33
|
+
* @param first First index _(can be negative to count from the end)_
|
|
34
|
+
* @param second Second index _(can be negative to count from the end)_
|
|
35
|
+
* @returns Original array with items swapped _(or unchanged if unable to swap)_
|
|
36
|
+
*/
|
|
37
|
+
function swapIndices(array, first, second) {
|
|
38
|
+
if (!Array.isArray(array) || array.length === 0) return [];
|
|
39
|
+
if (typeof first !== "number" || typeof second !== "number") return array;
|
|
40
|
+
const firstIndex = first < 0 ? array.length + first : first;
|
|
41
|
+
const secondIndex = second < 0 ? array.length + second : second;
|
|
42
|
+
if (firstIndex === secondIndex || firstIndex >= array.length || secondIndex >= array.length) return array;
|
|
43
|
+
const temp = array[firstIndex];
|
|
44
|
+
array[firstIndex] = array[secondIndex];
|
|
45
|
+
array[secondIndex] = temp;
|
|
46
|
+
return array;
|
|
47
|
+
}
|
|
48
|
+
function swapValues(array, from, to, key) {
|
|
49
|
+
const callback = getArrayCallback(key);
|
|
50
|
+
const first = callback == null ? array.indexOf(from) : indexOf(array, callback, callback(from, void 0, []));
|
|
51
|
+
const second = callback == null ? array.indexOf(to) : indexOf(array, callback, callback(to, void 0, []));
|
|
52
|
+
if (first === second || first === -1 || second === -1) return array;
|
|
53
|
+
return swapIndices(array, first, second);
|
|
54
|
+
}
|
|
55
|
+
//#endregion
|
|
56
|
+
export { swap };
|