@oscarpalmer/atoms 0.179.1 → 0.180.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/filter.d.mts +36 -28
- package/dist/array/filter.mjs +5 -5
- package/dist/array/first.d.mts +13 -5
- package/dist/array/first.mjs +1 -1
- package/dist/array/group-by.d.mts +13 -1
- package/dist/array/group-by.mjs +1 -1
- package/dist/array/last.d.mts +9 -1
- package/dist/array/last.mjs +1 -1
- package/dist/array/move.d.mts +9 -1
- package/dist/array/move.mjs +3 -1
- package/dist/array/reverse.d.mts +5 -0
- package/dist/array/reverse.mjs +5 -0
- package/dist/array/select.d.mts +2 -2
- package/dist/array/sort.d.mts +23 -9
- package/dist/array/sort.mjs +22 -22
- package/dist/array/swap.d.mts +2 -0
- package/dist/array/swap.mjs +2 -0
- package/dist/array/to-map.d.mts +13 -1
- package/dist/array/to-map.mjs +1 -1
- package/dist/array/to-record.d.mts +13 -1
- package/dist/array/to-record.mjs +1 -1
- package/dist/function/assert.d.mts +9 -1
- package/dist/function/assert.mjs +9 -1
- package/dist/function/limit.d.mts +5 -1
- package/dist/function/limit.mjs +5 -1
- package/dist/function/once.d.mts +3 -1
- package/dist/function/once.mjs +3 -1
- package/dist/function/retry.d.mts +4 -0
- package/dist/function/retry.mjs +2 -0
- package/dist/function/work.d.mts +49 -1
- package/dist/function/work.mjs +1 -1
- package/dist/index.d.mts +415 -242
- package/dist/index.mjs +223 -166
- package/dist/internal/function/timer.mjs +3 -1
- package/dist/internal/value/compare.d.mts +13 -9
- package/dist/internal/value/compare.mjs +13 -9
- package/dist/internal/value/equal.d.mts +29 -15
- package/dist/internal/value/equal.mjs +41 -35
- package/dist/internal/value/handlers.d.mts +4 -4
- package/dist/internal/value/handlers.mjs +19 -11
- package/dist/internal/value/has.d.mts +9 -8
- package/dist/internal/value/has.mjs +3 -3
- package/dist/internal/value/misc.d.mts +4 -8
- package/dist/internal/value/misc.mjs +6 -17
- package/dist/promise/index.d.mts +11 -1
- package/dist/promise/index.mjs +1 -1
- package/dist/result/index.d.mts +9 -1
- package/dist/result/index.mjs +1 -1
- package/dist/result/match.d.mts +5 -1
- package/dist/result/match.mjs +1 -1
- package/dist/result/misc.d.mts +3 -3
- package/dist/result/work/flow.d.mts +49 -1
- package/dist/result/work/flow.mjs +1 -1
- package/dist/result/work/pipe.d.mts +67 -155
- package/dist/result/work/pipe.mjs +3 -3
- package/dist/string/fuzzy.d.mts +11 -1
- package/dist/string/fuzzy.mjs +22 -6
- package/dist/string/template.d.mts +3 -1
- package/dist/string/template.mjs +3 -1
- package/dist/value/clone.d.mts +13 -9
- package/dist/value/clone.mjs +21 -17
- package/dist/value/merge.d.mts +9 -7
- package/dist/value/merge.mjs +7 -5
- package/package.json +2 -2
- package/plugin/helpers.js +2 -2
- package/src/array/filter.ts +44 -36
- package/src/array/first.ts +18 -9
- package/src/array/group-by.ts +22 -10
- package/src/array/last.ts +17 -5
- package/src/array/move.ts +18 -5
- package/src/array/reverse.ts +5 -0
- package/src/array/select.ts +2 -2
- package/src/array/sort.ts +110 -86
- package/src/array/swap.ts +2 -0
- package/src/array/to-map.ts +22 -10
- package/src/array/to-record.ts +22 -10
- package/src/function/assert.ts +12 -4
- package/src/function/limit.ts +6 -2
- package/src/function/once.ts +3 -1
- package/src/function/retry.ts +8 -2
- package/src/function/work.ts +92 -26
- package/src/internal/function/timer.ts +4 -2
- package/src/internal/string.ts +2 -0
- package/src/internal/value/compare.ts +14 -11
- package/src/internal/value/equal.ts +79 -67
- package/src/internal/value/handlers.ts +19 -11
- package/src/internal/value/has.ts +16 -16
- package/src/internal/value/misc.ts +10 -8
- package/src/promise/index.ts +14 -4
- package/src/result/index.ts +15 -5
- package/src/result/match.ts +7 -3
- package/src/result/misc.ts +3 -3
- package/src/result/work/flow.ts +68 -13
- package/src/result/work/pipe.ts +97 -392
- package/src/string/fuzzy.ts +34 -8
- package/src/string/template.ts +3 -1
- package/src/value/clone.ts +25 -22
- package/src/value/merge.ts +14 -12
package/dist/array/filter.d.mts
CHANGED
|
@@ -2,67 +2,75 @@ import { PlainObject } from "../models.mjs";
|
|
|
2
2
|
|
|
3
3
|
//#region src/array/filter.d.ts
|
|
4
4
|
/**
|
|
5
|
-
* Get a filtered array of items
|
|
5
|
+
* Get a filtered array of items that do not match the filter
|
|
6
|
+
*
|
|
7
|
+
* Available as `exclude` and `filter.remove`
|
|
6
8
|
* @param array Array to search in
|
|
7
9
|
* @param callback Callback to get an item's value for matching
|
|
8
10
|
* @param value Value to match against
|
|
9
|
-
* @returns Filtered array of items
|
|
11
|
+
* @returns Filtered array of items that do not match the filter
|
|
10
12
|
*/
|
|
11
|
-
declare function
|
|
13
|
+
declare function exclude<Item, Callback extends (item: Item, index: number, array: Item[]) => unknown>(array: Item[], callback: Callback, value: ReturnType<Callback>): unknown[];
|
|
12
14
|
/**
|
|
13
|
-
* Get a filtered array of items
|
|
15
|
+
* Get a filtered array of items that do not match the filter
|
|
16
|
+
*
|
|
17
|
+
* Available as `exclude` and `filter.remove`
|
|
14
18
|
* @param array Array to search in
|
|
15
19
|
* @param key Key to get an item's value for matching
|
|
16
20
|
* @param value Value to match against
|
|
17
|
-
* @returns Filtered array of items
|
|
21
|
+
* @returns Filtered array of items that do not match the filter
|
|
18
22
|
*/
|
|
19
|
-
declare function
|
|
23
|
+
declare function exclude<Item extends PlainObject, ItemKey extends keyof Item>(array: Item[], key: ItemKey, value: Item[ItemKey]): unknown[];
|
|
20
24
|
/**
|
|
21
|
-
* Get a filtered array of items
|
|
25
|
+
* Get a filtered array of items that do not match the filter
|
|
26
|
+
*
|
|
27
|
+
* Available as `exclude` and `filter.remove`
|
|
22
28
|
* @param array Array to search in
|
|
23
29
|
* @param filter Filter callback to match items
|
|
24
|
-
* @returns Filtered array of items
|
|
30
|
+
* @returns Filtered array of items that do not match the filter
|
|
25
31
|
*/
|
|
26
|
-
declare function
|
|
32
|
+
declare function exclude<Item>(array: Item[], filter: (item: Item, index: number, array: Item[]) => boolean): unknown[];
|
|
27
33
|
/**
|
|
28
|
-
* Get a filtered array of items
|
|
34
|
+
* Get a filtered array of items that do not match the given item
|
|
35
|
+
*
|
|
36
|
+
* Available as `exclude` and `filter.remove`
|
|
29
37
|
* @param array Array to search in
|
|
30
38
|
* @param item Item to match against
|
|
31
|
-
* @returns Filtered array of items
|
|
39
|
+
* @returns Filtered array of items that do not match the given item
|
|
32
40
|
*/
|
|
33
|
-
declare function
|
|
34
|
-
declare namespace filter {
|
|
35
|
-
var remove: typeof removeFiltered;
|
|
36
|
-
}
|
|
41
|
+
declare function exclude<Item>(array: Item[], item: Item): unknown[];
|
|
37
42
|
/**
|
|
38
|
-
* Get a filtered array of items
|
|
43
|
+
* Get a filtered array of items
|
|
39
44
|
* @param array Array to search in
|
|
40
45
|
* @param callback Callback to get an item's value for matching
|
|
41
46
|
* @param value Value to match against
|
|
42
|
-
* @returns Filtered array of items
|
|
47
|
+
* @returns Filtered array of items
|
|
43
48
|
*/
|
|
44
|
-
declare function
|
|
49
|
+
declare function filter<Item, Callback extends (item: Item, index: number, array: Item[]) => unknown>(array: Item[], callback: Callback, value: ReturnType<Callback>): Item[];
|
|
45
50
|
/**
|
|
46
|
-
* Get a filtered array of items
|
|
51
|
+
* Get a filtered array of items
|
|
47
52
|
* @param array Array to search in
|
|
48
53
|
* @param key Key to get an item's value for matching
|
|
49
54
|
* @param value Value to match against
|
|
50
|
-
* @returns Filtered array of items
|
|
55
|
+
* @returns Filtered array of items
|
|
51
56
|
*/
|
|
52
|
-
declare function
|
|
57
|
+
declare function filter<Item extends PlainObject, ItemKey extends keyof Item>(array: Item[], key: ItemKey, value: Item[ItemKey]): Item[];
|
|
53
58
|
/**
|
|
54
|
-
* Get a filtered array of items
|
|
59
|
+
* Get a filtered array of items matching the filter
|
|
55
60
|
* @param array Array to search in
|
|
56
61
|
* @param filter Filter callback to match items
|
|
57
|
-
* @returns Filtered array of items
|
|
62
|
+
* @returns Filtered array of items
|
|
58
63
|
*/
|
|
59
|
-
declare function
|
|
64
|
+
declare function filter<Item>(array: Item[], filter: (item: Item, index: number, array: Item[]) => boolean): Item[];
|
|
60
65
|
/**
|
|
61
|
-
* Get a filtered array of items
|
|
66
|
+
* Get a filtered array of items matching the given item
|
|
62
67
|
* @param array Array to search in
|
|
63
68
|
* @param item Item to match against
|
|
64
|
-
* @returns Filtered array of items
|
|
69
|
+
* @returns Filtered array of items
|
|
65
70
|
*/
|
|
66
|
-
declare function
|
|
71
|
+
declare function filter<Item>(array: Item[], item: Item): Item[];
|
|
72
|
+
declare namespace filter {
|
|
73
|
+
var remove: typeof exclude;
|
|
74
|
+
}
|
|
67
75
|
//#endregion
|
|
68
|
-
export { filter };
|
|
76
|
+
export { exclude, filter };
|
package/dist/array/filter.mjs
CHANGED
|
@@ -1,11 +1,11 @@
|
|
|
1
1
|
import { findValues } from "../internal/array/find.mjs";
|
|
2
2
|
//#region src/array/filter.ts
|
|
3
|
+
function exclude(array, ...parameters) {
|
|
4
|
+
return findValues("all", array, parameters).notMatched;
|
|
5
|
+
}
|
|
3
6
|
function filter(array, ...parameters) {
|
|
4
7
|
return findValues("all", array, parameters).matched;
|
|
5
8
|
}
|
|
6
|
-
filter.remove =
|
|
7
|
-
function removeFiltered(array, ...parameters) {
|
|
8
|
-
return findValues("all", array, parameters).notMatched;
|
|
9
|
-
}
|
|
9
|
+
filter.remove = exclude;
|
|
10
10
|
//#endregion
|
|
11
|
-
export { filter };
|
|
11
|
+
export { exclude, filter };
|
package/dist/array/first.d.mts
CHANGED
|
@@ -35,7 +35,9 @@ declare namespace first {
|
|
|
35
35
|
export { _a as default };
|
|
36
36
|
}
|
|
37
37
|
/**
|
|
38
|
-
* Get the first item matching the given value
|
|
38
|
+
* Get the first item matching the given value, or a default value if no match is found
|
|
39
|
+
*
|
|
40
|
+
* Available as `firstOrDefault` and `first.default`
|
|
39
41
|
* @param array Array to search in
|
|
40
42
|
* @param defaultValue Default value to return if no match is found
|
|
41
43
|
* @param callback Callback to get an item's value for matching
|
|
@@ -44,7 +46,9 @@ declare namespace first {
|
|
|
44
46
|
*/
|
|
45
47
|
declare function firstOrDefault<Item, Callback extends (item: Item, index: number, array: Item[]) => unknown>(array: Item[], defaultValue: Item, callback: Callback, value: ReturnType<Callback>): Item;
|
|
46
48
|
/**
|
|
47
|
-
* Get the first item matching the given value by key
|
|
49
|
+
* Get the first item matching the given value by key, or a default value if no match is found
|
|
50
|
+
*
|
|
51
|
+
* Available as `firstOrDefault` and `first.default`
|
|
48
52
|
* @param array Array to search in
|
|
49
53
|
* @param defaultValue Default value to return if no match is found
|
|
50
54
|
* @param key Key to get an item's value for matching
|
|
@@ -53,7 +57,9 @@ declare function firstOrDefault<Item, Callback extends (item: Item, index: numbe
|
|
|
53
57
|
*/
|
|
54
58
|
declare function firstOrDefault<Item extends PlainObject, ItemKey extends keyof Item>(array: Item[], defaultValue: Item, key: ItemKey, value: Item[ItemKey]): Item;
|
|
55
59
|
/**
|
|
56
|
-
* Get the first item matching the filter
|
|
60
|
+
* Get the first item matching the filter, or a default value if no match is found
|
|
61
|
+
*
|
|
62
|
+
* Available as `firstOrDefault` and `first.default`
|
|
57
63
|
* @param array Array to search in
|
|
58
64
|
* @param defaultValue Default value to return if no match is found
|
|
59
65
|
* @param filter Filter callback to match items
|
|
@@ -61,11 +67,13 @@ declare function firstOrDefault<Item extends PlainObject, ItemKey extends keyof
|
|
|
61
67
|
*/
|
|
62
68
|
declare function firstOrDefault<Item>(array: Item[], defaultValue: Item, filter: (item: Item, index: number, array: Item[]) => boolean): Item;
|
|
63
69
|
/**
|
|
64
|
-
* Get the first item from an array
|
|
70
|
+
* Get the first item from an array, or a default value if the array is empty
|
|
71
|
+
*
|
|
72
|
+
* Available as `firstOrDefault` and `first.default`
|
|
65
73
|
* @param array Array to get from
|
|
66
74
|
* @param defaultValue Default value to return if the array is empty
|
|
67
75
|
* @return First item from the array, or the default value if the array is empty
|
|
68
76
|
*/
|
|
69
77
|
declare function firstOrDefault<Item>(array: Item[], defaultValue: Item): Item;
|
|
70
78
|
//#endregion
|
|
71
|
-
export { first };
|
|
79
|
+
export { first, firstOrDefault };
|
package/dist/array/first.mjs
CHANGED
|
@@ -70,6 +70,8 @@ declare namespace groupBy {
|
|
|
70
70
|
}
|
|
71
71
|
/**
|
|
72
72
|
* Create a record from an array of items using a specific key and value, grouping values into arrays
|
|
73
|
+
*
|
|
74
|
+
* Available as `groupArraysBy` and `groupBy.arrays`
|
|
73
75
|
* @param array Array to group
|
|
74
76
|
* @param key Callback to get an item's grouping key
|
|
75
77
|
* @param value Callback to get an item's value
|
|
@@ -78,6 +80,8 @@ declare namespace groupBy {
|
|
|
78
80
|
declare function groupArraysBy<Item, KeyCallback extends (item: Item, index: number, array: Item[]) => Key, ValueCallback extends (item: Item, index: number, array: Item[]) => unknown>(array: Item[], key: KeyCallback, value: ValueCallback): Record<ReturnType<KeyCallback>, ReturnType<ValueCallback>[]>;
|
|
79
81
|
/**
|
|
80
82
|
* Create a record from an array of items using a specific key and value, grouping values into arrays
|
|
83
|
+
*
|
|
84
|
+
* Available as `groupArraysBy` and `groupBy.arrays`
|
|
81
85
|
* @param array Array to group
|
|
82
86
|
* @param key Callback to get an item's grouping key
|
|
83
87
|
* @param value Key to use for value
|
|
@@ -86,6 +90,8 @@ declare function groupArraysBy<Item, KeyCallback extends (item: Item, index: num
|
|
|
86
90
|
declare function groupArraysBy<Item extends PlainObject, KeyCallback extends (item: Item, index: number, array: Item[]) => Key, ItemValue extends keyof Item>(array: Item[], key: KeyCallback, value: ItemValue): Record<ReturnType<KeyCallback>, Item[ItemValue][]>;
|
|
87
91
|
/**
|
|
88
92
|
* Create a record from an array of items using a specific key and value, grouping values into arrays
|
|
93
|
+
*
|
|
94
|
+
* Available as `groupArraysBy` and `groupBy.arrays`
|
|
89
95
|
* @param array Array to group
|
|
90
96
|
* @param key Key to use for grouping
|
|
91
97
|
* @param value Callback to get an item's value
|
|
@@ -94,6 +100,8 @@ declare function groupArraysBy<Item extends PlainObject, KeyCallback extends (it
|
|
|
94
100
|
declare function groupArraysBy<Item extends PlainObject, ItemKey extends keyof Item, ValueCallback extends (item: Item, index: number, array: Item[]) => unknown>(array: Item[], key: ItemKey, value: ValueCallback): Simplify<Record<KeyedValue<Item, ItemKey>, ReturnType<ValueCallback>[]>>;
|
|
95
101
|
/**
|
|
96
102
|
* Create a record from an array of items using a specific key and value, grouping values into arrays
|
|
103
|
+
*
|
|
104
|
+
* Available as `groupArraysBy` and `groupBy.arrays`
|
|
97
105
|
* @param array Array to group
|
|
98
106
|
* @param key Key to use for grouping
|
|
99
107
|
* @param value Key to use for value
|
|
@@ -102,6 +110,8 @@ declare function groupArraysBy<Item extends PlainObject, ItemKey extends keyof I
|
|
|
102
110
|
declare function groupArraysBy<Item extends PlainObject, ItemKey extends keyof Item, ItemValue extends keyof Item>(array: Item[], key: ItemKey, value: ItemValue): Simplify<Record<KeyedValue<Item, ItemKey>, Item[ItemValue][]>>;
|
|
103
111
|
/**
|
|
104
112
|
* Create a record from an array of items using a specific key, grouping items into arrays
|
|
113
|
+
*
|
|
114
|
+
* Available as `groupArraysBy` and `groupBy.arrays`
|
|
105
115
|
* @param array Array to group
|
|
106
116
|
* @param callback Callback to get an item's grouping key
|
|
107
117
|
* @returns Record of keyed items
|
|
@@ -109,10 +119,12 @@ declare function groupArraysBy<Item extends PlainObject, ItemKey extends keyof I
|
|
|
109
119
|
declare function groupArraysBy<Item, Callback extends (item: Item, index: number, array: Item[]) => Key>(array: Item[], callback: Callback): Record<ReturnType<Callback>, Item[]>;
|
|
110
120
|
/**
|
|
111
121
|
* Create a record from an array of items using a specific key, grouping items into arrays
|
|
122
|
+
*
|
|
123
|
+
* Available as `groupArraysBy` and `groupBy.arrays`
|
|
112
124
|
* @param array Array to group
|
|
113
125
|
* @param key Key to use for grouping
|
|
114
126
|
* @returns Record of keyed items
|
|
115
127
|
*/
|
|
116
128
|
declare function groupArraysBy<Item extends PlainObject, ItemKey extends keyof Item>(array: Item[], key: ItemKey): Simplify<Record<KeyedValue<Item, ItemKey>, Item[]>>;
|
|
117
129
|
//#endregion
|
|
118
|
-
export { groupBy };
|
|
130
|
+
export { groupArraysBy, groupBy };
|
package/dist/array/group-by.mjs
CHANGED
package/dist/array/last.d.mts
CHANGED
|
@@ -36,6 +36,8 @@ declare namespace last {
|
|
|
36
36
|
}
|
|
37
37
|
/**
|
|
38
38
|
* Get the last item matching the given value
|
|
39
|
+
*
|
|
40
|
+
* Available as `lastOrDefault` and `last.default`
|
|
39
41
|
* @param array Array to search in
|
|
40
42
|
* @param defaultValue Default value to return if no match is found
|
|
41
43
|
* @param callback Callback to get an item's value for matching
|
|
@@ -45,6 +47,8 @@ declare namespace last {
|
|
|
45
47
|
declare function lastOrDefault<Item, Callback extends (item: Item, index: number, array: Item[]) => unknown>(array: Item[], defaultValue: Item, callback: Callback, value: ReturnType<Callback>): Item;
|
|
46
48
|
/**
|
|
47
49
|
* Get the last item matching the given value by key
|
|
50
|
+
*
|
|
51
|
+
* Available as `lastOrDefault` and `last.default`
|
|
48
52
|
* @param array Array to search in
|
|
49
53
|
* @param defaultValue Default value to return if no match is found
|
|
50
54
|
* @param key Key to get an item's value for matching
|
|
@@ -54,6 +58,8 @@ declare function lastOrDefault<Item, Callback extends (item: Item, index: number
|
|
|
54
58
|
declare function lastOrDefault<Item extends PlainObject, ItemKey extends keyof Item>(array: Item[], defaultValue: Item, key: ItemKey, value: Item[ItemKey]): Item;
|
|
55
59
|
/**
|
|
56
60
|
* Get the last item matching the filter
|
|
61
|
+
*
|
|
62
|
+
* Available as `lastOrDefault` and `last.default`
|
|
57
63
|
* @param array Array to search in
|
|
58
64
|
* @param defaultValue Default value to return if no match is found
|
|
59
65
|
* @param filter Filter callback to match items
|
|
@@ -62,10 +68,12 @@ declare function lastOrDefault<Item extends PlainObject, ItemKey extends keyof I
|
|
|
62
68
|
declare function lastOrDefault<Item>(array: Item[], defaultValue: Item, filter: (item: Item, index: number, array: Item[]) => boolean): Item;
|
|
63
69
|
/**
|
|
64
70
|
* Get the last item from an array
|
|
71
|
+
*
|
|
72
|
+
* Available as `lastOrDefault` and `last.default`
|
|
65
73
|
* @param array Array to get from
|
|
66
74
|
* @param defaultValue Default value to return if the array is empty
|
|
67
75
|
* @return Last item from the array, or the default value if the array is empty
|
|
68
76
|
*/
|
|
69
77
|
declare function lastOrDefault<Item>(array: Item[], defaultValue: Item): Item;
|
|
70
78
|
//#endregion
|
|
71
|
-
export { last };
|
|
79
|
+
export { last, lastOrDefault };
|
package/dist/array/last.mjs
CHANGED
package/dist/array/move.d.mts
CHANGED
|
@@ -47,6 +47,8 @@ declare namespace move {
|
|
|
47
47
|
* Move an item from one index to another within an array
|
|
48
48
|
*
|
|
49
49
|
* If the from index is out of bounds, the array will be returned unchanged
|
|
50
|
+
*
|
|
51
|
+
* Available as `moveIndices` and `move.indices`
|
|
50
52
|
* @param array Array to move within
|
|
51
53
|
* @param from Index to move from
|
|
52
54
|
* @param to Index to move to
|
|
@@ -57,6 +59,8 @@ declare function moveIndices<Item>(array: Item[], from: number, to: number): Ite
|
|
|
57
59
|
* Move an item _(or array of items)_ to an index within an array
|
|
58
60
|
*
|
|
59
61
|
* If the value is not present in the array, or if the index is out of bounds, the array will be returned unchanged
|
|
62
|
+
*
|
|
63
|
+
* Available as `moveToIndex` and `move.toIndex`
|
|
60
64
|
* @param array Array to move within
|
|
61
65
|
* @param value Item or items to move
|
|
62
66
|
* @param index Index to move to
|
|
@@ -68,6 +72,8 @@ declare function moveToIndex<Item extends PlainObject, ItemKey extends keyof Ite
|
|
|
68
72
|
* Move an item _(or array of items)_ to an index within an array
|
|
69
73
|
*
|
|
70
74
|
* If the value is not present in the array, or if the index is out of bounds, the array will be returned unchanged
|
|
75
|
+
*
|
|
76
|
+
* Available as `moveToIndex` and `move.toIndex`
|
|
71
77
|
* @param array Array to move within
|
|
72
78
|
* @param value Item or items to move
|
|
73
79
|
* @param index Index to move to
|
|
@@ -79,6 +85,8 @@ declare function moveToIndex<Item>(array: Item[], value: Item | Item[], index: n
|
|
|
79
85
|
* Move an item _(or array of items)_ to an index within an array
|
|
80
86
|
*
|
|
81
87
|
* If the value is not present in the array, or if the index is out of bounds, the array will be returned unchanged
|
|
88
|
+
*
|
|
89
|
+
* Available as `moveToIndex` and `move.toIndex`
|
|
82
90
|
* @param array Array to move within
|
|
83
91
|
* @param value Item or items to move
|
|
84
92
|
* @param index Index to move to
|
|
@@ -86,4 +94,4 @@ declare function moveToIndex<Item>(array: Item[], value: Item | Item[], index: n
|
|
|
86
94
|
*/
|
|
87
95
|
declare function moveToIndex<Item>(array: Item[], value: Item | Item[], index: number): Item[];
|
|
88
96
|
//#endregion
|
|
89
|
-
export { move };
|
|
97
|
+
export { move, moveIndices, moveToIndex };
|
package/dist/array/move.mjs
CHANGED
|
@@ -29,6 +29,8 @@ move.toIndex = moveToIndex;
|
|
|
29
29
|
* Move an item from one index to another within an array
|
|
30
30
|
*
|
|
31
31
|
* If the from index is out of bounds, the array will be returned unchanged
|
|
32
|
+
*
|
|
33
|
+
* Available as `moveIndices` and `move.indices`
|
|
32
34
|
* @param array Array to move within
|
|
33
35
|
* @param from Index to move from
|
|
34
36
|
* @param to Index to move to
|
|
@@ -61,4 +63,4 @@ function moveToIndex(array, value, index, key) {
|
|
|
61
63
|
return array;
|
|
62
64
|
}
|
|
63
65
|
//#endregion
|
|
64
|
-
export { move };
|
|
66
|
+
export { move, moveIndices, moveToIndex };
|
package/dist/array/reverse.d.mts
CHANGED
package/dist/array/reverse.mjs
CHANGED
package/dist/array/select.d.mts
CHANGED
|
@@ -76,7 +76,7 @@ declare function select<Item extends PlainObject, MapKey extends keyof Item>(arr
|
|
|
76
76
|
* @param map Callback to map the matched items
|
|
77
77
|
* @returns Filtered and mapped array of items
|
|
78
78
|
*/
|
|
79
|
-
declare function select<Item, MapCallback extends (item: Item, index: number, array: Item[]) => unknown>(array: Item[],
|
|
79
|
+
declare function select<Item, MapCallback extends (item: Item, index: number, array: Item[]) => unknown>(array: Item[], item: Item, map: MapCallback): Array<ReturnType<MapCallback>>;
|
|
80
80
|
/**
|
|
81
81
|
* Get a filtered and mapped array of items
|
|
82
82
|
* @param array Array to search in
|
|
@@ -84,6 +84,6 @@ declare function select<Item, MapCallback extends (item: Item, index: number, ar
|
|
|
84
84
|
* @param map Key to get an item's value for mapping
|
|
85
85
|
* @returns Filtered and mapped array of items
|
|
86
86
|
*/
|
|
87
|
-
declare function select<Item extends PlainObject, MapKey extends keyof Item>(array: Item[],
|
|
87
|
+
declare function select<Item extends PlainObject, MapKey extends keyof Item>(array: Item[], item: Item, map: MapKey): Array<Item[MapKey]>;
|
|
88
88
|
//#endregion
|
|
89
89
|
export { select };
|
package/dist/array/sort.d.mts
CHANGED
|
@@ -92,54 +92,66 @@ type Sorter<Item> = {
|
|
|
92
92
|
* Get the index for an item _(to be inserted into an array of items)_ based on sorters _(and an optional default direction)_
|
|
93
93
|
*
|
|
94
94
|
* _(If the array is not sorted, it will be treated as sorted, and the result may be inaccurate)_
|
|
95
|
+
*
|
|
96
|
+
* Available as `getSortedIndex` and `sort.index`
|
|
95
97
|
* @param array Array to get the index from
|
|
96
98
|
* @param item Item to get the index for
|
|
97
99
|
* @param sorters Sorters to use to determine sorting
|
|
98
100
|
* @param descending Sorted in descending order? _(defaults to `false`; overridden by individual sorters)_
|
|
99
101
|
* @returns Index for item
|
|
100
102
|
*/
|
|
101
|
-
declare function
|
|
103
|
+
declare function getSortedIndex<Item>(array: Item[], item: Item, sorters: Array<ArraySorter<Item>>, descending?: boolean): number;
|
|
102
104
|
/**
|
|
103
105
|
* Get the index for an item _(to be inserted into an array of items)_ based on a sorter _(and an optional default direction)_
|
|
104
106
|
*
|
|
105
107
|
* _(If the array is not sorted, it will be treated as sorted, and the result may be inaccurate)_
|
|
108
|
+
*
|
|
109
|
+
* Available as `getSortedIndex` and `sort.index`
|
|
106
110
|
* @param array Array to get the index from
|
|
107
111
|
* @param item Item to get the index for
|
|
108
112
|
* @param sorter Sorter to use to determine sorting
|
|
109
113
|
* @param descending Sorted in descending order? _(defaults to `false`; overridden by individual sorters)_
|
|
110
114
|
* @returns Index for item
|
|
111
115
|
*/
|
|
112
|
-
declare function
|
|
116
|
+
declare function getSortedIndex<Item>(array: Item[], item: Item, sorter: ArraySorter<Item>, descending?: boolean): number;
|
|
113
117
|
/**
|
|
114
118
|
* Get the index for an item _(to be inserted into an array of items)_ based on an optional default direction_
|
|
115
119
|
*
|
|
116
120
|
* _(If the array is not sorted, it will be treated as sorted, and the result may be inaccurate)_
|
|
121
|
+
*
|
|
122
|
+
* Available as `getSortedIndex` and `sort.index`
|
|
117
123
|
* @param array Array to get the index from
|
|
118
124
|
* @param item Item to get the index for
|
|
119
125
|
* @param descending Sorted in descending order? _(defaults to `false`)_
|
|
120
126
|
* @returns Index for item
|
|
121
127
|
*/
|
|
122
|
-
declare function
|
|
128
|
+
declare function getSortedIndex<Item>(array: Item[], item: Item, descending?: boolean): number;
|
|
123
129
|
/**
|
|
124
130
|
* Initialize a sort handler with sorters _(and an optional default direction)_
|
|
131
|
+
*
|
|
132
|
+
* Available as `initializeSorter` and `sort.initialize`
|
|
125
133
|
* @param sorters Sorters to use for sorting
|
|
126
134
|
* @param descending Sort in descending order? _(defaults to `false`; overridden by individual sorters)_
|
|
127
135
|
* @returns Sort handler
|
|
128
136
|
*/
|
|
129
|
-
declare function
|
|
137
|
+
declare function initializeSorter<Item>(sorters: Array<ArraySorter<Item>>, descending?: boolean): Sorter<Item>;
|
|
130
138
|
/**
|
|
131
139
|
* Initialize a sort handler with a sorter _(and an optional default direction)_
|
|
140
|
+
*
|
|
141
|
+
* Available as `initializeSorter` and `sort.initialize`
|
|
132
142
|
* @param sorter Sorter to use for sorting
|
|
133
143
|
* @param descending Sort in descending order? _(defaults to `false`; overridden by individual sorters)_
|
|
134
144
|
* @returns Sort handler
|
|
135
145
|
*/
|
|
136
|
-
declare function
|
|
146
|
+
declare function initializeSorter<Item>(sorter: ArraySorter<Item>, descending?: boolean): Sorter<Item>;
|
|
137
147
|
/**
|
|
138
148
|
* Initialize a sort handler _(with an optional default direction)_
|
|
149
|
+
*
|
|
150
|
+
* Available as `initializeSorter` and `sort.initialize`
|
|
139
151
|
* @param descending Sort in descending order? _(defaults to `false`)_
|
|
140
152
|
* @returns Sort handler
|
|
141
153
|
*/
|
|
142
|
-
declare function
|
|
154
|
+
declare function initializeSorter<Item>(descending?: boolean): Sorter<Item>;
|
|
143
155
|
/**
|
|
144
156
|
* Is the array sorted according to the sorters _(and the optional default direction)_?
|
|
145
157
|
* @param array Array to check
|
|
@@ -158,6 +170,8 @@ declare function isSorted<Item>(array: Item[], sorters: Array<ArraySorter<Item>>
|
|
|
158
170
|
declare function isSorted<Item>(array: Item[], sorter: ArraySorter<Item>, descending?: boolean): boolean;
|
|
159
171
|
/**
|
|
160
172
|
* Is the array sorted?
|
|
173
|
+
*
|
|
174
|
+
* Available as `isSorted` and `sort.is`
|
|
161
175
|
* @param array Array to check
|
|
162
176
|
* @param descending Sorted in descending order? _(defaults to `false`)_
|
|
163
177
|
* @returns `true` if sorted, otherwise `false`
|
|
@@ -187,11 +201,11 @@ declare function sort<Item>(array: Item[], sorter: ArraySorter<Item>, descending
|
|
|
187
201
|
*/
|
|
188
202
|
declare function sort<Item>(array: Item[], descending?: boolean): Item[];
|
|
189
203
|
declare namespace sort {
|
|
190
|
-
var index: typeof
|
|
191
|
-
var initialize: typeof
|
|
204
|
+
var index: typeof getSortedIndex;
|
|
205
|
+
var initialize: typeof initializeSorter;
|
|
192
206
|
var is: typeof isSorted;
|
|
193
207
|
}
|
|
194
208
|
declare const SORT_DIRECTION_ASCENDING: SortDirection;
|
|
195
209
|
declare const SORT_DIRECTION_DESCENDING: SortDirection;
|
|
196
210
|
//#endregion
|
|
197
|
-
export { ArrayComparisonSorter, ArrayKeySorter, ArrayValueSorter, SORT_DIRECTION_ASCENDING, SORT_DIRECTION_DESCENDING, SortDirection, Sorter, sort };
|
|
211
|
+
export { ArrayComparisonSorter, ArrayKeySorter, ArrayValueSorter, SORT_DIRECTION_ASCENDING, SORT_DIRECTION_DESCENDING, SortDirection, Sorter, getSortedIndex, initializeSorter, isSorted, sort };
|
package/dist/array/sort.mjs
CHANGED
|
@@ -18,23 +18,7 @@ function getComparisonValue(first, second, sorters, length) {
|
|
|
18
18
|
}
|
|
19
19
|
return 0;
|
|
20
20
|
}
|
|
21
|
-
function getIndex(array, item,
|
|
22
|
-
return getSortedIndex(array, item, getSorters(first, getModifier(first, second)));
|
|
23
|
-
}
|
|
24
|
-
function getModifier(first, second) {
|
|
25
|
-
return modifiers[first === true || second === true ? SORT_DIRECTION_DESCENDING : SORT_DIRECTION_ASCENDING];
|
|
26
|
-
}
|
|
27
|
-
function getObjectSorter(obj, modifier) {
|
|
28
|
-
let sorter;
|
|
29
|
-
if (typeof obj.comparison === "function") sorter = getComparisonSorter(obj.comparison, modifier);
|
|
30
|
-
else if (typeof obj.key === "string") {
|
|
31
|
-
sorter = getValueSorter(obj.key, modifier);
|
|
32
|
-
if (typeof obj.compare === "function") sorter.compare = { complex: obj.compare };
|
|
33
|
-
} else if (typeof obj.value === "function") sorter = getValueSorter(obj.value, modifier);
|
|
34
|
-
if (sorter != null && typeof obj.direction === "string") sorter.modifier = modifiers[obj.direction] ?? modifier;
|
|
35
|
-
return sorter;
|
|
36
|
-
}
|
|
37
|
-
function getSortedIndex(array, item, sorters) {
|
|
21
|
+
function getIndex(array, item, sorters) {
|
|
38
22
|
if (!Array.isArray(array)) return -1;
|
|
39
23
|
const { length } = array;
|
|
40
24
|
if (length === 0) return 0;
|
|
@@ -50,6 +34,22 @@ function getSortedIndex(array, item, sorters) {
|
|
|
50
34
|
}
|
|
51
35
|
return low;
|
|
52
36
|
}
|
|
37
|
+
function getModifier(first, second) {
|
|
38
|
+
return modifiers[first === true || second === true ? SORT_DIRECTION_DESCENDING : SORT_DIRECTION_ASCENDING];
|
|
39
|
+
}
|
|
40
|
+
function getObjectSorter(obj, modifier) {
|
|
41
|
+
let sorter;
|
|
42
|
+
if (typeof obj.comparison === "function") sorter = getComparisonSorter(obj.comparison, modifier);
|
|
43
|
+
else if (typeof obj.key === "string") {
|
|
44
|
+
sorter = getValueSorter(obj.key, modifier);
|
|
45
|
+
if (typeof obj.compare === "function") sorter.compare = { complex: obj.compare };
|
|
46
|
+
} else if (typeof obj.value === "function") sorter = getValueSorter(obj.value, modifier);
|
|
47
|
+
if (sorter != null && typeof obj.direction === "string") sorter.modifier = modifiers[obj.direction] ?? modifier;
|
|
48
|
+
return sorter;
|
|
49
|
+
}
|
|
50
|
+
function getSortedIndex(array, item, first, second) {
|
|
51
|
+
return getIndex(array, item, getSorters(first, getModifier(first, second)));
|
|
52
|
+
}
|
|
53
53
|
function getSorter(value, modifier) {
|
|
54
54
|
switch (true) {
|
|
55
55
|
case typeof value === "function": return getComparisonSorter(value, modifier);
|
|
@@ -82,10 +82,10 @@ function getValueSorter(value, modifier) {
|
|
|
82
82
|
value: typeof value === "function" ? value : (item) => item[value]
|
|
83
83
|
};
|
|
84
84
|
}
|
|
85
|
-
function
|
|
85
|
+
function initializeSorter(first, second) {
|
|
86
86
|
const sorters = getSorters(first, getModifier(first, second));
|
|
87
87
|
const sorter = (array) => sortArray(array, sorters);
|
|
88
|
-
sorter.index = (array, item) =>
|
|
88
|
+
sorter.index = (array, item) => getIndex(array, item, sorters);
|
|
89
89
|
sorter.is = (array) => isSortedArray(array, sorters);
|
|
90
90
|
return sorter;
|
|
91
91
|
}
|
|
@@ -124,8 +124,8 @@ function sortArray(array, sorters) {
|
|
|
124
124
|
const { length } = sorters;
|
|
125
125
|
return array.length > 1 ? array.sort((first, second) => getComparisonValue(first, second, sorters, length)) : array;
|
|
126
126
|
}
|
|
127
|
-
sort.index =
|
|
128
|
-
sort.initialize =
|
|
127
|
+
sort.index = getSortedIndex;
|
|
128
|
+
sort.initialize = initializeSorter;
|
|
129
129
|
sort.is = isSorted;
|
|
130
130
|
const ARRAY_PEEK_PERCENTAGE = 10;
|
|
131
131
|
const ARRAY_THRESHOLD = 100;
|
|
@@ -136,4 +136,4 @@ const modifiers = {
|
|
|
136
136
|
[SORT_DIRECTION_DESCENDING]: -1
|
|
137
137
|
};
|
|
138
138
|
//#endregion
|
|
139
|
-
export { SORT_DIRECTION_ASCENDING, SORT_DIRECTION_DESCENDING, sort };
|
|
139
|
+
export { SORT_DIRECTION_ASCENDING, SORT_DIRECTION_DESCENDING, getSortedIndex, initializeSorter, isSorted, sort };
|
package/dist/array/swap.d.mts
CHANGED
|
@@ -70,6 +70,8 @@ declare namespace swap {
|
|
|
70
70
|
* Swap two indiced items in an array
|
|
71
71
|
*
|
|
72
72
|
* If either index is out of bounds, the array will be returned unchanged
|
|
73
|
+
*
|
|
74
|
+
* Available as `swapIndices` and `swap.indices`
|
|
73
75
|
* @param array Array of items to swap
|
|
74
76
|
* @param first First index _(can be negative to count from the end)_
|
|
75
77
|
* @param second Second index _(can be negative to count from the end)_
|
package/dist/array/swap.mjs
CHANGED
|
@@ -32,6 +32,8 @@ function swapArrays(array, from, to, key) {
|
|
|
32
32
|
* Swap two indiced items in an array
|
|
33
33
|
*
|
|
34
34
|
* If either index is out of bounds, the array will be returned unchanged
|
|
35
|
+
*
|
|
36
|
+
* Available as `swapIndices` and `swap.indices`
|
|
35
37
|
* @param array Array of items to swap
|
|
36
38
|
* @param first First index _(can be negative to count from the end)_
|
|
37
39
|
* @param second Second index _(can be negative to count from the end)_
|
package/dist/array/to-map.d.mts
CHANGED
|
@@ -70,6 +70,8 @@ declare namespace toMap {
|
|
|
70
70
|
}
|
|
71
71
|
/**
|
|
72
72
|
* Create a Map from an array of items using callbacks, grouping values into arrays
|
|
73
|
+
*
|
|
74
|
+
* Available as `toMapArrays` and `toMap.arrays`
|
|
73
75
|
* @param array Array to convert
|
|
74
76
|
* @param key Callback to get an item's grouping key
|
|
75
77
|
* @param value Callback to get an item's value
|
|
@@ -78,6 +80,8 @@ declare namespace toMap {
|
|
|
78
80
|
declare function toMapArrays<Item, KeyCallback extends (item: Item, index: number, array: Item[]) => Key, ValueCallback extends (item: Item, index: number, array: Item[]) => unknown>(array: Item[], key: KeyCallback, value: ValueCallback): Map<ReturnType<KeyCallback>, ReturnType<ValueCallback>[]>;
|
|
79
81
|
/**
|
|
80
82
|
* Create a Map from an array of items using a callback and value, grouping values into arrays
|
|
83
|
+
*
|
|
84
|
+
* Available as `toMapArrays` and `toMap.arrays`
|
|
81
85
|
* @param array Array to convert
|
|
82
86
|
* @param key Callback to get an item's grouping key
|
|
83
87
|
* @param value Key to use for value
|
|
@@ -86,6 +90,8 @@ declare function toMapArrays<Item, KeyCallback extends (item: Item, index: numbe
|
|
|
86
90
|
declare function toMapArrays<Item extends PlainObject, KeyCallback extends (item: Item, index: number, array: Item[]) => Key, ItemValue extends keyof Item>(array: Item[], key: KeyCallback, value: ItemValue): Map<ReturnType<KeyCallback>, Item[ItemValue][]>;
|
|
87
91
|
/**
|
|
88
92
|
* Create a Map from an array of items using a key and callback, grouping values into arrays
|
|
93
|
+
*
|
|
94
|
+
* Available as `toMapArrays` and `toMap.arrays`
|
|
89
95
|
* @param array Array to convert
|
|
90
96
|
* @param key Key to use for grouping
|
|
91
97
|
* @param value Callback to get an item's value
|
|
@@ -94,6 +100,8 @@ declare function toMapArrays<Item extends PlainObject, KeyCallback extends (item
|
|
|
94
100
|
declare function toMapArrays<Item extends PlainObject, ItemKey extends keyof Item, ValueCallback extends (item: Item, index: number, array: Item[]) => unknown>(array: Item[], key: ItemKey, value: ValueCallback): Map<Item[ItemKey], ReturnType<ValueCallback>[]>;
|
|
95
101
|
/**
|
|
96
102
|
* Create a Map from an array of items using a key and value, grouping values into arrays
|
|
103
|
+
*
|
|
104
|
+
* Available as `toMapArrays` and `toMap.arrays`
|
|
97
105
|
* @param array Array to convert
|
|
98
106
|
* @param key Key to use for grouping
|
|
99
107
|
* @param value Key to use for value
|
|
@@ -102,6 +110,8 @@ declare function toMapArrays<Item extends PlainObject, ItemKey extends keyof Ite
|
|
|
102
110
|
declare function toMapArrays<Item extends PlainObject, ItemKey extends keyof Item, ItemValue extends keyof Item>(array: Item[], key: ItemKey, value: ItemValue): Map<Item[ItemKey], Item[ItemValue][]>;
|
|
103
111
|
/**
|
|
104
112
|
* Create a Map from an array of items using a callback, grouping items into arrays
|
|
113
|
+
*
|
|
114
|
+
* Available as `toMapArrays` and `toMap.arrays`
|
|
105
115
|
* @param array Array to convert
|
|
106
116
|
* @param callback Callback to get an item's grouping key
|
|
107
117
|
* @returns Map of keyed arrays of items
|
|
@@ -109,10 +119,12 @@ declare function toMapArrays<Item extends PlainObject, ItemKey extends keyof Ite
|
|
|
109
119
|
declare function toMapArrays<Item, Callback extends (item: Item, index: number, array: Item[]) => Key>(array: Item[], callback: Callback): Map<ReturnType<Callback>, Item[]>;
|
|
110
120
|
/**
|
|
111
121
|
* Create a Map from an array of items using a key, grouping items into arrays
|
|
122
|
+
*
|
|
123
|
+
* Available as `toMapArrays` and `toMap.arrays`
|
|
112
124
|
* @param array Array to convert
|
|
113
125
|
* @param key Key to use for grouping
|
|
114
126
|
* @returns Map of keyed arrays of items
|
|
115
127
|
*/
|
|
116
128
|
declare function toMapArrays<Item extends PlainObject, ItemKey extends keyof Item>(array: Item[], key: ItemKey): Map<Item[ItemKey], Item[]>;
|
|
117
129
|
//#endregion
|
|
118
|
-
export { toMap };
|
|
130
|
+
export { toMap, toMapArrays };
|
package/dist/array/to-map.mjs
CHANGED