@oscarpalmer/atoms 0.186.2 → 0.187.1
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 +4 -4
- package/dist/array/find.d.mts +4 -4
- package/dist/array/first.d.mts +4 -4
- package/dist/array/get.d.mts +27 -1
- package/dist/array/get.mjs +5 -3
- package/dist/array/group-by.d.mts +6 -6
- package/dist/array/last.d.mts +4 -4
- package/dist/array/match.d.mts +7 -6
- package/dist/array/move.d.mts +7 -7
- package/dist/array/move.mjs +1 -1
- package/dist/array/select.d.mts +1 -0
- package/dist/array/slice.d.mts +3 -3
- package/dist/array/sort.d.mts +10 -7
- package/dist/array/sort.mjs +4 -3
- package/dist/array/swap.d.mts +1 -1
- package/dist/array/swap.mjs +1 -1
- package/dist/array/to-map.d.mts +32 -32
- package/dist/array/to-record.d.mts +6 -6
- package/dist/array/to-set.d.mts +6 -6
- package/dist/beacon.d.mts +6 -0
- package/dist/beacon.mjs +3 -0
- package/dist/color/index.d.mts +6 -2
- package/dist/color/index.mjs +6 -2
- package/dist/color/instance.d.mts +78 -14
- package/dist/color/instance.mjs +78 -14
- package/dist/color/misc/get.d.mts +39 -11
- package/dist/color/misc/get.mjs +39 -11
- package/dist/color/misc/is.d.mts +26 -11
- package/dist/color/misc/is.mjs +26 -11
- package/dist/color/misc/state.mjs +1 -1
- package/dist/color/models.d.mts +7 -4
- package/dist/color/space/hex.d.mts +15 -6
- package/dist/color/space/hex.mjs +15 -6
- package/dist/color/space/hsl.d.mts +10 -4
- package/dist/color/space/hsl.mjs +10 -4
- package/dist/color/space/rgb.d.mts +21 -12
- package/dist/color/space/rgb.mjs +21 -12
- package/dist/function/assert.d.mts +20 -14
- package/dist/function/assert.mjs +19 -13
- package/dist/function/limit.d.mts +8 -6
- package/dist/function/limit.mjs +8 -6
- package/dist/function/memoize.d.mts +15 -4
- package/dist/function/memoize.mjs +18 -4
- package/dist/function/once.d.mts +5 -3
- package/dist/function/once.mjs +5 -3
- package/dist/function/retry.d.mts +5 -2
- package/dist/function/retry.mjs +3 -1
- package/dist/function/work.d.mts +146 -98
- package/dist/{kalas.d.mts → herald.d.mts} +17 -8
- package/dist/{kalas.mjs → herald.mjs} +22 -13
- package/dist/index.d.mts +1464 -708
- package/dist/index.mjs +703 -342
- package/dist/internal/array/index-of.d.mts +4 -4
- package/dist/internal/array/insert.mjs +1 -1
- package/dist/internal/array/shuffle.d.mts +1 -0
- package/dist/internal/array/shuffle.mjs +2 -1
- package/dist/internal/is.d.mts +26 -8
- package/dist/internal/is.mjs +26 -8
- package/dist/internal/math/aggregate.d.mts +9 -9
- package/dist/internal/number.d.mts +13 -2
- package/dist/internal/number.mjs +13 -2
- package/dist/internal/random.d.mts +4 -2
- package/dist/internal/random.mjs +7 -5
- package/dist/internal/result.d.mts +17 -11
- package/dist/internal/result.mjs +10 -14
- package/dist/internal/string.d.mts +16 -1
- package/dist/internal/string.mjs +24 -1
- package/dist/internal/value/compare.d.mts +5 -2
- package/dist/internal/value/compare.mjs +5 -2
- package/dist/internal/value/equal.d.mts +12 -3
- package/dist/internal/value/equal.mjs +7 -4
- package/dist/internal/value/get.d.mts +17 -17
- package/dist/internal/value/has.d.mts +55 -11
- package/dist/internal/value/set.d.mts +24 -0
- package/dist/internal/value/set.mjs +1 -1
- package/dist/is.d.mts +12 -0
- package/dist/is.mjs +16 -1
- package/dist/logger.d.mts +7 -6
- package/dist/logger.mjs +6 -5
- package/dist/math.d.mts +36 -18
- package/dist/math.mjs +6 -3
- package/dist/models.d.mts +3 -3
- package/dist/promise/delay.d.mts +2 -0
- package/dist/promise/helpers.d.mts +6 -4
- package/dist/promise/helpers.mjs +6 -4
- package/dist/promise/index.d.mts +49 -38
- package/dist/promise/misc.d.mts +10 -7
- package/dist/promise/misc.mjs +4 -3
- package/dist/promise/models.d.mts +18 -19
- package/dist/promise/models.mjs +4 -3
- package/dist/promise/timed.d.mts +8 -6
- package/dist/query.d.mts +2 -0
- package/dist/query.mjs +27 -17
- package/dist/queue.d.mts +15 -4
- package/dist/queue.mjs +10 -3
- package/dist/random.d.mts +9 -2
- package/dist/random.mjs +7 -2
- package/dist/result/index.d.mts +14 -8
- package/dist/result/match.d.mts +18 -10
- package/dist/result/misc.d.mts +14 -7
- package/dist/result/misc.mjs +4 -2
- package/dist/result/models.d.mts +2 -0
- package/dist/result/work/flow.d.mts +86 -62
- package/dist/result/work/pipe.d.mts +55 -33
- package/dist/sized/map.d.mts +19 -16
- package/dist/sized/map.mjs +4 -4
- package/dist/sized/set.d.mts +20 -16
- package/dist/sized/set.mjs +8 -7
- package/dist/string/case.d.mts +8 -0
- package/dist/string/case.mjs +8 -0
- package/dist/string/fuzzy.d.mts +19 -5
- package/dist/string/fuzzy.mjs +7 -0
- package/dist/string/index.d.mts +17 -2
- package/dist/string/index.mjs +7 -9
- package/dist/string/match.d.mts +3 -0
- package/dist/string/match.mjs +3 -0
- package/dist/string/normalize.d.mts +6 -2
- package/dist/string/normalize.mjs +5 -2
- package/dist/string/template.d.mts +38 -9
- package/dist/string/template.mjs +19 -19
- package/dist/value/clone.d.mts +25 -4
- package/dist/value/clone.mjs +36 -22
- package/dist/value/collection.d.mts +9 -6
- package/dist/value/collection.mjs +3 -2
- package/dist/value/diff.d.mts +3 -1
- package/dist/value/diff.mjs +1 -0
- package/dist/value/freeze.d.mts +118 -9
- package/dist/value/freeze.mjs +56 -14
- package/dist/value/index.d.mts +1 -2
- package/dist/value/index.mjs +1 -2
- package/dist/value/merge.d.mts +11 -5
- package/dist/value/merge.mjs +2 -2
- package/dist/value/omit.d.mts +1 -0
- package/dist/value/omit.mjs +1 -0
- package/dist/value/pick.d.mts +1 -0
- package/dist/value/pick.mjs +1 -0
- package/dist/value/shake.d.mts +1 -0
- package/dist/value/shake.mjs +1 -0
- package/dist/value/smush.d.mts +1 -0
- package/dist/value/smush.mjs +1 -0
- package/dist/value/transform.d.mts +7 -3
- package/dist/value/unsmush.d.mts +1 -0
- package/dist/value/unsmush.mjs +1 -0
- package/package.json +12 -8
- package/src/array/filter.ts +4 -4
- package/src/array/find.ts +4 -4
- package/src/array/first.ts +4 -4
- package/src/array/get.ts +40 -5
- package/src/array/group-by.ts +6 -6
- package/src/array/last.ts +4 -4
- package/src/array/match.ts +7 -6
- package/src/array/move.ts +7 -7
- package/src/array/select.ts +1 -0
- package/src/array/slice.ts +3 -3
- package/src/array/sort.ts +15 -10
- package/src/array/swap.ts +1 -1
- package/src/array/to-map.ts +32 -32
- package/src/array/to-record.ts +6 -6
- package/src/array/to-set.ts +6 -6
- package/src/beacon.ts +6 -0
- package/src/color/index.ts +6 -2
- package/src/color/instance.ts +78 -14
- package/src/color/misc/get.ts +39 -11
- package/src/color/misc/is.ts +26 -11
- package/src/color/misc/state.ts +1 -1
- package/src/color/models.ts +7 -4
- package/src/color/space/hex.ts +15 -6
- package/src/color/space/hsl.ts +10 -4
- package/src/color/space/rgb.ts +21 -12
- package/src/function/assert.ts +20 -14
- package/src/function/limit.ts +8 -6
- package/src/function/memoize.ts +24 -5
- package/src/function/once.ts +5 -3
- package/src/function/retry.ts +7 -3
- package/src/function/work.ts +146 -98
- package/src/{kalas.ts → herald.ts} +23 -14
- package/src/index.ts +3 -2
- package/src/internal/array/index-of.ts +4 -4
- package/src/internal/array/insert.ts +1 -1
- package/src/internal/array/shuffle.ts +2 -1
- package/src/internal/is.ts +26 -8
- package/src/internal/math/aggregate.ts +9 -9
- package/src/internal/number.ts +13 -2
- package/src/internal/random.ts +10 -4
- package/src/internal/result.ts +30 -29
- package/src/internal/string.ts +28 -0
- package/src/internal/value/compare.ts +5 -2
- package/src/internal/value/equal.ts +13 -4
- package/src/internal/value/get.ts +17 -17
- package/src/internal/value/has.ts +54 -11
- package/src/internal/value/set.ts +25 -1
- package/src/is.ts +15 -1
- package/src/logger.ts +8 -7
- package/src/math.ts +36 -18
- package/src/models.ts +3 -3
- package/src/promise/delay.ts +2 -0
- package/src/promise/helpers.ts +6 -4
- package/src/promise/index.ts +49 -38
- package/src/promise/misc.ts +10 -7
- package/src/promise/models.ts +18 -19
- package/src/promise/timed.ts +8 -6
- package/src/query.ts +39 -28
- package/src/queue.ts +15 -4
- package/src/random.ts +8 -1
- package/src/result/index.ts +14 -8
- package/src/result/match.ts +18 -10
- package/src/result/misc.ts +17 -9
- package/src/result/models.ts +2 -0
- package/src/result/work/flow.ts +86 -62
- package/src/result/work/pipe.ts +55 -33
- package/src/sized/map.ts +20 -17
- package/src/sized/set.ts +21 -17
- package/src/string/case.ts +8 -0
- package/src/string/fuzzy.ts +19 -5
- package/src/string/index.ts +18 -15
- package/src/string/match.ts +3 -0
- package/src/string/normalize.ts +6 -2
- package/src/string/template.ts +69 -18
- package/src/value/clone.ts +51 -26
- package/src/value/collection.ts +9 -6
- package/src/value/diff.ts +3 -1
- package/src/value/freeze.ts +239 -25
- package/src/value/index.ts +0 -1
- package/src/value/merge.ts +11 -5
- package/src/value/omit.ts +1 -0
- package/src/value/pick.ts +1 -0
- package/src/value/shake.ts +1 -0
- package/src/value/smush.ts +1 -0
- package/src/value/transform.ts +7 -3
- package/src/value/unsmush.ts +1 -0
package/dist/value/unsmush.d.mts
CHANGED
|
@@ -11,6 +11,7 @@ type KeysOfUnion<ObjectType> = keyof UnionToIntersection<ObjectType extends unkn
|
|
|
11
11
|
type Unsmushed<Value extends PlainObject> = Simplify<Omit<{ [UnionKey in KeysOfUnion<Value>]: Value[UnionKey] }, `${string}.${string}`>>;
|
|
12
12
|
/**
|
|
13
13
|
* Unsmush a smushed object _(turning dot notation keys into nested keys)_
|
|
14
|
+
*
|
|
14
15
|
* @param value Object to unsmush
|
|
15
16
|
* @returns Unsmushed object with nested keys
|
|
16
17
|
*/
|
package/dist/value/unsmush.mjs
CHANGED
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@oscarpalmer/atoms",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.187.1",
|
|
4
4
|
"description": "Atomic utilities for making your JavaScript better.",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"helper",
|
|
@@ -101,14 +101,14 @@
|
|
|
101
101
|
"types": "./dist/function/work.d.mts",
|
|
102
102
|
"default": "./dist/function/work.mjs"
|
|
103
103
|
},
|
|
104
|
+
"./herald": {
|
|
105
|
+
"types": "./dist/herald.d.mts",
|
|
106
|
+
"default": "./dist/herald.mjs"
|
|
107
|
+
},
|
|
104
108
|
"./is": {
|
|
105
109
|
"types": "./dist/is.d.mts",
|
|
106
110
|
"default": "./dist/is.mjs"
|
|
107
111
|
},
|
|
108
|
-
"./kalas": {
|
|
109
|
-
"types": "./dist/kalas.d.mts",
|
|
110
|
-
"default": "./dist/kalas.mjs"
|
|
111
|
-
},
|
|
112
112
|
"./logger": {
|
|
113
113
|
"types": "./dist/logger.d.mts",
|
|
114
114
|
"default": "./dist/logger.mjs"
|
|
@@ -232,6 +232,10 @@
|
|
|
232
232
|
"types": "./dist/value/diff.d.mts",
|
|
233
233
|
"default": "./dist/value/diff.mjs"
|
|
234
234
|
},
|
|
235
|
+
"./value/freeze": {
|
|
236
|
+
"types": "./dist/value/freeze.d.mts",
|
|
237
|
+
"default": "./dist/value/freeze.mjs"
|
|
238
|
+
},
|
|
235
239
|
"./value/equal": {
|
|
236
240
|
"types": "./dist/internal/value/equal.d.mts",
|
|
237
241
|
"default": "./dist/internal/value/equal.mjs"
|
|
@@ -253,10 +257,10 @@
|
|
|
253
257
|
"watch": "npx vite build --watch"
|
|
254
258
|
},
|
|
255
259
|
"devDependencies": {
|
|
256
|
-
"@oxlint/plugins": "^1.
|
|
257
|
-
"@types/node": "^25.
|
|
260
|
+
"@oxlint/plugins": "^1.66",
|
|
261
|
+
"@types/node": "^25.9",
|
|
258
262
|
"@vitest/coverage-istanbul": "^4.1",
|
|
259
|
-
"eslint": "^10.
|
|
263
|
+
"eslint": "^10.4",
|
|
260
264
|
"jsdom": "^29.1",
|
|
261
265
|
"tsdown": "^0.22",
|
|
262
266
|
"typescript": "^6",
|
package/src/array/filter.ts
CHANGED
|
@@ -6,7 +6,7 @@ import type {PlainObject} from '../models';
|
|
|
6
6
|
/**
|
|
7
7
|
* Get a filtered array of items that do not match the value
|
|
8
8
|
*
|
|
9
|
-
*
|
|
9
|
+
* _Available as `exclude` and `filter.remove`_
|
|
10
10
|
*
|
|
11
11
|
* @param array Array to search in
|
|
12
12
|
* @param callback Callback to get an item's value for matching
|
|
@@ -30,7 +30,7 @@ export function exclude<
|
|
|
30
30
|
/**
|
|
31
31
|
* Get a filtered array of items that do not match the value
|
|
32
32
|
*
|
|
33
|
-
*
|
|
33
|
+
* _Available as `exclude` and `filter.remove`_
|
|
34
34
|
*
|
|
35
35
|
* @param array Array to search in
|
|
36
36
|
* @param key Key to get an item's value for matching
|
|
@@ -55,7 +55,7 @@ export function exclude<Item extends PlainObject, ItemKey extends keyof Item>(
|
|
|
55
55
|
/**
|
|
56
56
|
* Get a filtered array of items that do not match the filter
|
|
57
57
|
*
|
|
58
|
-
*
|
|
58
|
+
* _Available as `exclude` and `filter.remove`_
|
|
59
59
|
*
|
|
60
60
|
* @param array Array to search in
|
|
61
61
|
* @param filter Filter callback to match items
|
|
@@ -77,7 +77,7 @@ export function exclude<Item>(
|
|
|
77
77
|
/**
|
|
78
78
|
* Get a filtered array of items that do not match the given item
|
|
79
79
|
*
|
|
80
|
-
*
|
|
80
|
+
* _Available as `exclude` and `filter.remove`_
|
|
81
81
|
*
|
|
82
82
|
* @param array Array to search in
|
|
83
83
|
* @param item Item to match against
|
package/src/array/find.ts
CHANGED
|
@@ -92,7 +92,7 @@ find.last = findLast;
|
|
|
92
92
|
/**
|
|
93
93
|
* Get the last item matching the given value
|
|
94
94
|
*
|
|
95
|
-
*
|
|
95
|
+
* _Available as `findLast` and `find.last`_
|
|
96
96
|
*
|
|
97
97
|
* @param array Array to search in
|
|
98
98
|
* @param callback Callback to get an item's value for matching
|
|
@@ -116,7 +116,7 @@ export function findLast<
|
|
|
116
116
|
/**
|
|
117
117
|
* Get the last item matching the given value by key
|
|
118
118
|
*
|
|
119
|
-
*
|
|
119
|
+
* _Available as `findLast` and `find.last`_
|
|
120
120
|
*
|
|
121
121
|
* @param array Array to search in
|
|
122
122
|
* @param key Key to get an item's value for matching
|
|
@@ -141,7 +141,7 @@ export function findLast<Item extends PlainObject, ItemKey extends keyof Item>(
|
|
|
141
141
|
/**
|
|
142
142
|
* Get the last item matching the filter
|
|
143
143
|
*
|
|
144
|
-
*
|
|
144
|
+
* _Available as `findLast` and `find.last`_
|
|
145
145
|
*
|
|
146
146
|
* @param array Array to search in
|
|
147
147
|
* @param filter Filter callback to match items
|
|
@@ -163,7 +163,7 @@ export function findLast<Item>(
|
|
|
163
163
|
/**
|
|
164
164
|
* Get the last item matching the given value
|
|
165
165
|
*
|
|
166
|
-
*
|
|
166
|
+
* _Available as `findLast` and `find.last`_
|
|
167
167
|
*
|
|
168
168
|
* @param array Array to search in
|
|
169
169
|
* @param value Value to match against
|
package/src/array/first.ts
CHANGED
|
@@ -93,7 +93,7 @@ first.default = firstOrDefault;
|
|
|
93
93
|
/**
|
|
94
94
|
* Get the first item matching the given value, or a default value if no match is found
|
|
95
95
|
*
|
|
96
|
-
*
|
|
96
|
+
* _Available as `firstOrDefault` and `first.default`_
|
|
97
97
|
*
|
|
98
98
|
* @param array Array to search in
|
|
99
99
|
* @param defaultValue Default value to return if no match is found
|
|
@@ -119,7 +119,7 @@ export function firstOrDefault<
|
|
|
119
119
|
/**
|
|
120
120
|
* Get the first item matching the given value by key, or a default value if no match is found
|
|
121
121
|
*
|
|
122
|
-
*
|
|
122
|
+
* _Available as `firstOrDefault` and `first.default`_
|
|
123
123
|
*
|
|
124
124
|
* @param array Array to search in
|
|
125
125
|
* @param defaultValue Default value to return if no match is found
|
|
@@ -147,7 +147,7 @@ export function firstOrDefault<Item extends PlainObject, ItemKey extends keyof I
|
|
|
147
147
|
/**
|
|
148
148
|
* Get the first item matching the filter, or a default value if no match is found
|
|
149
149
|
*
|
|
150
|
-
*
|
|
150
|
+
* _Available as `firstOrDefault` and `first.default`_
|
|
151
151
|
*
|
|
152
152
|
* @param array Array to search in
|
|
153
153
|
* @param defaultValue Default value to return if no match is found
|
|
@@ -172,7 +172,7 @@ export function firstOrDefault<Item>(
|
|
|
172
172
|
/**
|
|
173
173
|
* Get the first item from an array, or a default value if the array is empty
|
|
174
174
|
*
|
|
175
|
-
*
|
|
175
|
+
* _Available as `firstOrDefault` and `first.default`_
|
|
176
176
|
*
|
|
177
177
|
* @param array Array to get from
|
|
178
178
|
* @param defaultValue Default value to return if the array is empty
|
package/src/array/get.ts
CHANGED
|
@@ -20,6 +20,21 @@ export function getArray<Value extends PlainObject>(
|
|
|
20
20
|
indiced: true,
|
|
21
21
|
): Value[NumericalKeys<Value>][];
|
|
22
22
|
|
|
23
|
+
/**
|
|
24
|
+
* Get an array from a map
|
|
25
|
+
*
|
|
26
|
+
* @param value Map to convert to an array
|
|
27
|
+
* @returns Array holding the entries of the map
|
|
28
|
+
*
|
|
29
|
+
* @example
|
|
30
|
+
* ```typescript
|
|
31
|
+
* getArray(
|
|
32
|
+
* new Map([['a', 1], ['b', 2], ['c', 3]]),
|
|
33
|
+
* ); // => [['a', 1], ['b', 2], ['c', 3]]
|
|
34
|
+
* ```
|
|
35
|
+
*/
|
|
36
|
+
export function getArray<Key, Value>(map: Map<Key, Value>): [Key, Value][];
|
|
37
|
+
|
|
23
38
|
/**
|
|
24
39
|
* Get an array from an object
|
|
25
40
|
*
|
|
@@ -32,7 +47,22 @@ export function getArray<Value extends PlainObject>(
|
|
|
32
47
|
* getArray({a: 'a', b: 'b', c: 'c', d: 'd'}); // => ['a', 'b', 'c', 'd']
|
|
33
48
|
* ```
|
|
34
49
|
*/
|
|
35
|
-
export function getArray<Value extends PlainObject>(
|
|
50
|
+
export function getArray<Value extends PlainObject>(
|
|
51
|
+
value: Value,
|
|
52
|
+
): [keyof Value, Value[keyof Value]][];
|
|
53
|
+
|
|
54
|
+
/**
|
|
55
|
+
* Get an array from a set
|
|
56
|
+
*
|
|
57
|
+
* @param value Set to convert to an array
|
|
58
|
+
* @returns Array holding the values of the set
|
|
59
|
+
*
|
|
60
|
+
* @example
|
|
61
|
+
* ```typescript
|
|
62
|
+
* getArray(new Set([123, 456, 789])); // => [123, 456, 789]
|
|
63
|
+
* ```
|
|
64
|
+
*/
|
|
65
|
+
export function getArray<Value>(set: Set<Value>): Value[];
|
|
36
66
|
|
|
37
67
|
/**
|
|
38
68
|
* Get an array from a value
|
|
@@ -65,7 +95,11 @@ export function getArray(value: unknown, indiced?: unknown): unknown[] {
|
|
|
65
95
|
return value;
|
|
66
96
|
}
|
|
67
97
|
|
|
68
|
-
if (value instanceof Map
|
|
98
|
+
if (value instanceof Map) {
|
|
99
|
+
return [...value.entries()];
|
|
100
|
+
}
|
|
101
|
+
|
|
102
|
+
if (value instanceof Set) {
|
|
69
103
|
return [...value.values()];
|
|
70
104
|
}
|
|
71
105
|
|
|
@@ -74,7 +108,7 @@ export function getArray(value: unknown, indiced?: unknown): unknown[] {
|
|
|
74
108
|
}
|
|
75
109
|
|
|
76
110
|
if (indiced !== true) {
|
|
77
|
-
return Object.
|
|
111
|
+
return Object.entries(value);
|
|
78
112
|
}
|
|
79
113
|
|
|
80
114
|
const keys = Object.keys(value);
|
|
@@ -84,9 +118,10 @@ export function getArray(value: unknown, indiced?: unknown): unknown[] {
|
|
|
84
118
|
|
|
85
119
|
for (let index = 0; index < length; index += 1) {
|
|
86
120
|
const key = keys[index];
|
|
121
|
+
const asNumber = Number.parseInt(key, 10);
|
|
87
122
|
|
|
88
|
-
if (!Number.isNaN(
|
|
89
|
-
array
|
|
123
|
+
if (!Number.isNaN(asNumber)) {
|
|
124
|
+
array[asNumber] = (value as Record<string, unknown>)[key];
|
|
90
125
|
}
|
|
91
126
|
}
|
|
92
127
|
|
package/src/array/group-by.ts
CHANGED
|
@@ -187,7 +187,7 @@ groupBy.arrays = groupArraysBy;
|
|
|
187
187
|
/**
|
|
188
188
|
* Create a record from an array of items using a specific key and value, grouping values into arrays
|
|
189
189
|
*
|
|
190
|
-
*
|
|
190
|
+
* _Available as `groupArraysBy` and `groupBy.arrays`_
|
|
191
191
|
*
|
|
192
192
|
* @param array Array to group
|
|
193
193
|
* @param key Callback to get an item's grouping key
|
|
@@ -219,7 +219,7 @@ export function groupArraysBy<
|
|
|
219
219
|
/**
|
|
220
220
|
* Create a record from an array of items using a specific key and value, grouping values into arrays
|
|
221
221
|
*
|
|
222
|
-
*
|
|
222
|
+
* _Available as `groupArraysBy` and `groupBy.arrays`_
|
|
223
223
|
*
|
|
224
224
|
* @param array Array to group
|
|
225
225
|
* @param key Callback to get an item's grouping key
|
|
@@ -251,7 +251,7 @@ export function groupArraysBy<
|
|
|
251
251
|
/**
|
|
252
252
|
* Create a record from an array of items using a specific key and value, grouping values into arrays
|
|
253
253
|
*
|
|
254
|
-
*
|
|
254
|
+
* _Available as `groupArraysBy` and `groupBy.arrays`_
|
|
255
255
|
*
|
|
256
256
|
* @param array Array to group
|
|
257
257
|
* @param key Key to use for grouping
|
|
@@ -283,7 +283,7 @@ export function groupArraysBy<
|
|
|
283
283
|
/**
|
|
284
284
|
* Create a record from an array of items using a specific key and value, grouping values into arrays
|
|
285
285
|
*
|
|
286
|
-
*
|
|
286
|
+
* _Available as `groupArraysBy` and `groupBy.arrays`_
|
|
287
287
|
*
|
|
288
288
|
* @param array Array to group
|
|
289
289
|
* @param key Key to use for grouping
|
|
@@ -315,7 +315,7 @@ export function groupArraysBy<
|
|
|
315
315
|
/**
|
|
316
316
|
* Create a record from an array of items using a specific key, grouping items into arrays
|
|
317
317
|
*
|
|
318
|
-
*
|
|
318
|
+
* _Available as `groupArraysBy` and `groupBy.arrays`_
|
|
319
319
|
*
|
|
320
320
|
* @param array Array to group
|
|
321
321
|
* @param callback Callback to get an item's grouping key
|
|
@@ -340,7 +340,7 @@ export function groupArraysBy<
|
|
|
340
340
|
/**
|
|
341
341
|
* Create a record from an array of items using a specific key, grouping items into arrays
|
|
342
342
|
*
|
|
343
|
-
*
|
|
343
|
+
* _Available as `groupArraysBy` and `groupBy.arrays`_
|
|
344
344
|
*
|
|
345
345
|
* @param array Array to group
|
|
346
346
|
* @param key Key to use for grouping
|
package/src/array/last.ts
CHANGED
|
@@ -91,7 +91,7 @@ last.default = lastOrDefault;
|
|
|
91
91
|
/**
|
|
92
92
|
* Get the last item matching the given value
|
|
93
93
|
*
|
|
94
|
-
*
|
|
94
|
+
* _Available as `lastOrDefault` and `last.default`_
|
|
95
95
|
*
|
|
96
96
|
* @param array Array to search in
|
|
97
97
|
* @param defaultValue Default value to return if no match is found
|
|
@@ -117,7 +117,7 @@ export function lastOrDefault<
|
|
|
117
117
|
/**
|
|
118
118
|
* Get the last item matching the given value by key
|
|
119
119
|
*
|
|
120
|
-
*
|
|
120
|
+
* _Available as `lastOrDefault` and `last.default`_
|
|
121
121
|
*
|
|
122
122
|
* @param array Array to search in
|
|
123
123
|
* @param defaultValue Default value to return if no match is found
|
|
@@ -145,7 +145,7 @@ export function lastOrDefault<Item extends PlainObject, ItemKey extends keyof It
|
|
|
145
145
|
/**
|
|
146
146
|
* Get the last item matching the filter
|
|
147
147
|
*
|
|
148
|
-
*
|
|
148
|
+
* _Available as `lastOrDefault` and `last.default`_
|
|
149
149
|
*
|
|
150
150
|
* @param array Array to search in
|
|
151
151
|
* @param defaultValue Default value to return if no match is found
|
|
@@ -170,7 +170,7 @@ export function lastOrDefault<Item>(
|
|
|
170
170
|
/**
|
|
171
171
|
* Get the last item from an array
|
|
172
172
|
*
|
|
173
|
-
*
|
|
173
|
+
* _Available as `lastOrDefault` and `last.default`_
|
|
174
174
|
*
|
|
175
175
|
* @param array Array to get from
|
|
176
176
|
* @param defaultValue Default value to return if the array is empty
|
package/src/array/match.ts
CHANGED
|
@@ -13,7 +13,8 @@ export type ArrayComparison = 'end' | 'inside' | 'invalid' | 'outside' | 'same'
|
|
|
13
13
|
// #region Functions
|
|
14
14
|
|
|
15
15
|
/**
|
|
16
|
-
*
|
|
16
|
+
* Is the needle array at the end of the haystack array?
|
|
17
|
+
*
|
|
17
18
|
* @param haystack Haystack array
|
|
18
19
|
* @param needle Needle array
|
|
19
20
|
* @param callback Callback to get an item's value for matching
|
|
@@ -35,7 +36,7 @@ export function endsWithArray<Item>(
|
|
|
35
36
|
): boolean;
|
|
36
37
|
|
|
37
38
|
/**
|
|
38
|
-
*
|
|
39
|
+
* Is the needle array at the end of the haystack array?
|
|
39
40
|
*
|
|
40
41
|
* @param haystack Haystack array
|
|
41
42
|
* @param needle Needle array
|
|
@@ -58,7 +59,7 @@ export function endsWithArray<Item extends PlainObject>(
|
|
|
58
59
|
): boolean;
|
|
59
60
|
|
|
60
61
|
/**
|
|
61
|
-
*
|
|
62
|
+
* Is the needle array at the end of the haystack array?
|
|
62
63
|
*
|
|
63
64
|
* @param haystack Haystack array
|
|
64
65
|
* @param needle Needle array
|
|
@@ -343,7 +344,7 @@ export function indexOfArray(haystack: unknown[], needle: unknown[], key?: unkno
|
|
|
343
344
|
}
|
|
344
345
|
|
|
345
346
|
/**
|
|
346
|
-
*
|
|
347
|
+
* Is the needle array at the start of the haystack array?
|
|
347
348
|
*
|
|
348
349
|
* @param haystack Haystack array
|
|
349
350
|
* @param needle Needle array
|
|
@@ -366,7 +367,7 @@ export function startsWithArray<Item>(
|
|
|
366
367
|
): boolean;
|
|
367
368
|
|
|
368
369
|
/**
|
|
369
|
-
*
|
|
370
|
+
* Is the needle array at the start of the haystack array?
|
|
370
371
|
*
|
|
371
372
|
* @param haystack Haystack array
|
|
372
373
|
* @param needle Needle array
|
|
@@ -389,7 +390,7 @@ export function startsWithArray<Item extends PlainObject>(
|
|
|
389
390
|
): boolean;
|
|
390
391
|
|
|
391
392
|
/**
|
|
392
|
-
*
|
|
393
|
+
* Is the needle array at the start of the haystack array?
|
|
393
394
|
*
|
|
394
395
|
* @param haystack Haystack array
|
|
395
396
|
* @param needle Needle array
|
package/src/array/move.ts
CHANGED
|
@@ -7,7 +7,7 @@ import {indexOfArray} from './match';
|
|
|
7
7
|
/**
|
|
8
8
|
* Move an item _(or array of items)_ to the position of another item _(or array of items)_ within an array
|
|
9
9
|
*
|
|
10
|
-
* When moving to the front of the array, the moved items will be placed __before__ the target item. When moving to the back of the array, the moved items will be placed __after__ the target item
|
|
10
|
+
* When moving to the front of the array, the moved items will be placed __before__ the target item. When moving to the back of the array, the moved items will be placed __after__ the target item
|
|
11
11
|
*
|
|
12
12
|
* If either of values are not present in the array, or if they overlap, the array will be returned unchanged
|
|
13
13
|
*
|
|
@@ -36,7 +36,7 @@ export function move<Item>(
|
|
|
36
36
|
/**
|
|
37
37
|
* Move an item _(or array of items)_ to the position of another item _(or array of items)_ within an array
|
|
38
38
|
*
|
|
39
|
-
* When moving to the front of the array, the moved items will be placed __before__ the target item. When moving to the back of the array, the moved items will be placed __after__ the target item
|
|
39
|
+
* When moving to the front of the array, the moved items will be placed __before__ the target item. When moving to the back of the array, the moved items will be placed __after__ the target item
|
|
40
40
|
*
|
|
41
41
|
* If either of values are not present in the array, or if they overlap, the array will be returned unchanged
|
|
42
42
|
*
|
|
@@ -65,7 +65,7 @@ export function move<Item extends PlainObject, ItemKey extends keyof Item>(
|
|
|
65
65
|
/**
|
|
66
66
|
* Move an item _(or array of items)_ to the position of another item _(or array of items)_ within an array
|
|
67
67
|
*
|
|
68
|
-
* When moving to the front of the array, the moved items will be placed __before__ the target item. When moving to the back of the array, the moved items will be placed __after__ the target item
|
|
68
|
+
* When moving to the front of the array, the moved items will be placed __before__ the target item. When moving to the back of the array, the moved items will be placed __after__ the target item
|
|
69
69
|
*
|
|
70
70
|
* If either of values are not present in the array, or if they overlap, the array will be returned unchanged
|
|
71
71
|
*
|
|
@@ -145,7 +145,7 @@ move.toIndex = moveToIndex;
|
|
|
145
145
|
*
|
|
146
146
|
* If the from index is out of bounds, the array will be returned unchanged
|
|
147
147
|
*
|
|
148
|
-
*
|
|
148
|
+
* _Available as `moveIndices` and `move.indices`_
|
|
149
149
|
*
|
|
150
150
|
* @param array Array to move within
|
|
151
151
|
* @param from Index to move from
|
|
@@ -195,7 +195,7 @@ export function moveIndices<Item>(array: Item[], from: number, to: number): Item
|
|
|
195
195
|
*
|
|
196
196
|
* If the value is not present in the array, or if the index is out of bounds, the array will be returned unchanged
|
|
197
197
|
*
|
|
198
|
-
*
|
|
198
|
+
* _Available as `moveToIndex` and `move.toIndex`_
|
|
199
199
|
*
|
|
200
200
|
* @example
|
|
201
201
|
* ```typescript
|
|
@@ -224,7 +224,7 @@ export function moveToIndex<Item>(
|
|
|
224
224
|
*
|
|
225
225
|
* If the value is not present in the array, or if the index is out of bounds, the array will be returned unchanged
|
|
226
226
|
*
|
|
227
|
-
*
|
|
227
|
+
* _Available as `moveToIndex` and `move.toIndex`_
|
|
228
228
|
*
|
|
229
229
|
* @param array Array to move within
|
|
230
230
|
* @param value Item or items to move
|
|
@@ -253,7 +253,7 @@ export function moveToIndex<Item extends PlainObject, ItemKey extends keyof Item
|
|
|
253
253
|
*
|
|
254
254
|
* If the value is not present in the array, or if the index is out of bounds, the array will be returned unchanged
|
|
255
255
|
*
|
|
256
|
-
*
|
|
256
|
+
* _Available as `moveToIndex` and `move.toIndex`_
|
|
257
257
|
*
|
|
258
258
|
* @param array Array to move within
|
|
259
259
|
* @param value Item or items to move
|
package/src/array/select.ts
CHANGED
package/src/array/slice.ts
CHANGED
|
@@ -173,7 +173,7 @@ function extract(
|
|
|
173
173
|
}
|
|
174
174
|
|
|
175
175
|
/**
|
|
176
|
-
* Slice an array
|
|
176
|
+
* Slice an array _(returning a new array with a specified range of items)_
|
|
177
177
|
*
|
|
178
178
|
* @param array Original array
|
|
179
179
|
* @param start Start index _(inclusive)_
|
|
@@ -188,7 +188,7 @@ function extract(
|
|
|
188
188
|
export function slice<Item>(array: Item[], start: number, end: number): Item[];
|
|
189
189
|
|
|
190
190
|
/**
|
|
191
|
-
* Slice an array
|
|
191
|
+
* Slice an array _(returning a new array with a specified number of items, from the start)_
|
|
192
192
|
*
|
|
193
193
|
* @param array Original array
|
|
194
194
|
* @param count Maximum size of the new array
|
|
@@ -202,7 +202,7 @@ export function slice<Item>(array: Item[], start: number, end: number): Item[];
|
|
|
202
202
|
export function slice<Item>(array: Item[], count: number): Item[];
|
|
203
203
|
|
|
204
204
|
/**
|
|
205
|
-
* Slice an array
|
|
205
|
+
* Slice an array _(returning a new array with all items)_
|
|
206
206
|
*
|
|
207
207
|
* @param array Array to slice
|
|
208
208
|
* @returns Sliced array
|
package/src/array/sort.ts
CHANGED
|
@@ -149,7 +149,7 @@ function getComparisonSorter(callback: Function, modifier: number): InternalSort
|
|
|
149
149
|
simple: callback,
|
|
150
150
|
},
|
|
151
151
|
get: false,
|
|
152
|
-
identifier:
|
|
152
|
+
identifier: callback.toString(),
|
|
153
153
|
};
|
|
154
154
|
}
|
|
155
155
|
|
|
@@ -253,7 +253,7 @@ function getObjectSorter(obj: PlainObject, modifier: number): InternalSorter | u
|
|
|
253
253
|
*
|
|
254
254
|
* _(If the array is not sorted, it will be treated as sorted, and the result may be inaccurate)_
|
|
255
255
|
*
|
|
256
|
-
*
|
|
256
|
+
* _Available as `getSortedIndex` and `sort.getIndex`_
|
|
257
257
|
*
|
|
258
258
|
* @param array Array to get the index from
|
|
259
259
|
* @param item Item to get the index for
|
|
@@ -273,7 +273,7 @@ export function getSortedIndex<Item>(
|
|
|
273
273
|
*
|
|
274
274
|
* _(If the array is not sorted, it will be treated as sorted, and the result may be inaccurate)_
|
|
275
275
|
*
|
|
276
|
-
*
|
|
276
|
+
* _Available as `getSortedIndex` and `sort.getIndex`_
|
|
277
277
|
*
|
|
278
278
|
* @param array Array to get the index from
|
|
279
279
|
* @param item Item to get the index for
|
|
@@ -293,7 +293,7 @@ export function getSortedIndex<Item>(
|
|
|
293
293
|
*
|
|
294
294
|
* _(If the array is not sorted, it will be treated as sorted, and the result may be inaccurate)_
|
|
295
295
|
*
|
|
296
|
-
*
|
|
296
|
+
* _Available as `getSortedIndex` and `sort.getIndex`_
|
|
297
297
|
*
|
|
298
298
|
* @param array Array to get the index from
|
|
299
299
|
* @param item Item to get the index for
|
|
@@ -360,18 +360,20 @@ function getSorters(value: unknown, modifier: number): InternalSorter[] {
|
|
|
360
360
|
}
|
|
361
361
|
|
|
362
362
|
function getValueSorter(value: string | Function, modifier: number): InternalSorter {
|
|
363
|
+
const isFunction = typeof value === 'function';
|
|
364
|
+
|
|
363
365
|
return {
|
|
364
366
|
modifier,
|
|
365
367
|
get: true,
|
|
366
|
-
identifier:
|
|
367
|
-
value:
|
|
368
|
+
identifier: isFunction ? value.toString() : value,
|
|
369
|
+
value: isFunction ? value : (item: unknown) => (item as PlainObject)[value],
|
|
368
370
|
};
|
|
369
371
|
}
|
|
370
372
|
|
|
371
373
|
/**
|
|
372
374
|
* Initialize a sort handler with sorters _(and an optional default direction)_
|
|
373
375
|
*
|
|
374
|
-
*
|
|
376
|
+
* _Available as `initializeSorter` and `sort.initialize`_
|
|
375
377
|
*
|
|
376
378
|
* @param sorters Sorters to use for sorting
|
|
377
379
|
* @param descending Sort in descending order? _(defaults to `false`; overridden by individual sorters)_
|
|
@@ -385,7 +387,7 @@ export function initializeSorter<Item>(
|
|
|
385
387
|
/**
|
|
386
388
|
* Initialize a sort handler with a sorter _(and an optional default direction)_
|
|
387
389
|
*
|
|
388
|
-
*
|
|
390
|
+
* _Available as `initializeSorter` and `sort.initialize`_
|
|
389
391
|
*
|
|
390
392
|
* @param sorter Sorter to use for sorting
|
|
391
393
|
* @param descending Sort in descending order? _(defaults to `false`; overridden by individual sorters)_
|
|
@@ -399,7 +401,7 @@ export function initializeSorter<Item>(
|
|
|
399
401
|
/**
|
|
400
402
|
* Initialize a sort handler _(with an optional default direction)_
|
|
401
403
|
*
|
|
402
|
-
*
|
|
404
|
+
* _Available as `initializeSorter` and `sort.initialize`_
|
|
403
405
|
*
|
|
404
406
|
* @param descending Sort in descending order? _(defaults to `false`)_
|
|
405
407
|
* @returns Sort handler
|
|
@@ -448,7 +450,7 @@ export function isSorted<Item>(
|
|
|
448
450
|
/**
|
|
449
451
|
* Is the array sorted?
|
|
450
452
|
*
|
|
451
|
-
*
|
|
453
|
+
* _Available as `isSorted` and `sort.is`_
|
|
452
454
|
*
|
|
453
455
|
* @param array Array to check
|
|
454
456
|
* @param descending Sorted in descending order? _(defaults to `false`)_
|
|
@@ -534,6 +536,7 @@ export function sort<Item>(
|
|
|
534
536
|
|
|
535
537
|
/**
|
|
536
538
|
* Sort an array of items, using multiple sorters to sort by specific values
|
|
539
|
+
*
|
|
537
540
|
* @param array Array to sort
|
|
538
541
|
* @param sorters Sorters to use for sorting
|
|
539
542
|
* @param descending Sort in descending order? _(defaults to `false`; overridden by individual sorters)_
|
|
@@ -547,6 +550,7 @@ export function sort<Item>(
|
|
|
547
550
|
|
|
548
551
|
/**
|
|
549
552
|
* Sort an array of items, using a single sorter to sort by a specific value
|
|
553
|
+
*
|
|
550
554
|
* @param array Array to sort
|
|
551
555
|
* @param sorter Sorter to use for sorting
|
|
552
556
|
* @param descending Sort in descending order? _(defaults to `false`; overridden by individual sorters)_
|
|
@@ -556,6 +560,7 @@ export function sort<Item>(array: Item[], sorter: ArraySorter<Item>, descending?
|
|
|
556
560
|
|
|
557
561
|
/**
|
|
558
562
|
* Sort an array of items
|
|
563
|
+
*
|
|
559
564
|
* @param array Array to sort
|
|
560
565
|
* @param descending Sort in descending order? _(defaults to `false`)_
|
|
561
566
|
* @returns Sorted array
|
package/src/array/swap.ts
CHANGED
|
@@ -270,7 +270,7 @@ function swapArrays(array: unknown[], from: unknown[], to: unknown[], key: unkno
|
|
|
270
270
|
*
|
|
271
271
|
* If either index is out of bounds, the array will be returned unchanged
|
|
272
272
|
*
|
|
273
|
-
*
|
|
273
|
+
* _Available as `swapIndices` and `swap.indices`_
|
|
274
274
|
*
|
|
275
275
|
* @param array Array of items to swap
|
|
276
276
|
* @param first First index _(can be negative to count from the end)_
|