@oscarpalmer/atoms 0.217.0 → 0.219.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 +38 -4
- package/dist/array/find.d.mts +34 -0
- package/dist/array/first.d.mts +40 -4
- package/dist/array/insert.mjs +1 -1
- package/dist/array/last.d.mts +46 -10
- package/dist/array/partition.d.mts +24 -8
- package/dist/array/reverse.d.mts +6 -0
- package/dist/array/reverse.mjs +6 -0
- package/dist/array/select.d.mts +97 -116
- package/dist/array/select.mjs +19 -15
- package/dist/array/single.d.mts +22 -0
- package/dist/array/single.mjs +1 -1
- package/dist/array/slice.mjs +27 -14
- package/dist/array/sort.d.mts +54 -0
- package/dist/array/sort.mjs +2 -1
- package/dist/color/misc/get.mjs +3 -1
- package/dist/color/space/hex.d.mts +8 -0
- package/dist/color/space/hex.mjs +9 -1
- package/dist/function/retry.d.mts +1 -1
- package/dist/function/retry.mjs +5 -2
- package/dist/index.d.mts +879 -324
- package/dist/index.mjs +480 -173
- package/dist/internal/array/callbacks.mjs +1 -1
- package/dist/internal/array/find.d.mts +3 -3
- package/dist/internal/array/find.mjs +90 -48
- package/dist/internal/array/insert.mjs +1 -1
- package/dist/internal/array/match.mjs +21 -17
- package/dist/internal/array/sets.mjs +7 -1
- package/dist/internal/array/shuffle.d.mts +5 -0
- package/dist/internal/array/shuffle.mjs +5 -0
- package/dist/internal/math/aggregate.d.mts +69 -21
- package/dist/internal/math/aggregate.mjs +4 -1
- package/dist/internal/math/misc.d.mts +14 -0
- package/dist/internal/math/misc.mjs +14 -0
- package/dist/internal/number.d.mts +19 -1
- package/dist/internal/number.mjs +22 -2
- package/dist/internal/plan/plan.generate.mjs +3 -3
- package/dist/internal/random.d.mts +6 -0
- package/dist/internal/random.mjs +13 -2
- package/dist/internal/result/attempt.mjs +4 -4
- package/dist/internal/string/case.d.mts +63 -0
- package/dist/internal/string/case.mjs +63 -0
- package/dist/internal/string/misc.d.mts +20 -0
- package/dist/internal/string/misc.mjs +22 -1
- package/dist/internal/subscription.mjs +1 -1
- package/dist/internal/value/equal.mjs +2 -1
- package/dist/internal/value/partial.mjs +3 -1
- package/dist/logger.d.mts +12 -0
- package/dist/logger.mjs +12 -0
- package/dist/math.d.mts +90 -0
- package/dist/math.mjs +7 -0
- package/dist/models/array/array.find.model.d.mts +26 -0
- package/dist/models/array/array.misc.model.d.mts +2 -4
- package/dist/models/index.d.mts +1 -1
- package/dist/models/plan.model.d.mts +2 -0
- package/dist/models/plan.model.mjs +3 -1
- package/dist/models/string/string.fuzzy.model.d.mts +1 -1
- package/dist/models/string/string.misc.model.mjs +1 -1
- package/dist/models/value/value.merge.model.d.mts +4 -4
- package/dist/plan/index.d.mts +1 -4
- package/dist/plan/index.mjs +2 -3
- package/dist/plan/use.mjs +4 -4
- package/dist/promise/index.d.mts +6 -4
- package/dist/promise/index.mjs +4 -4
- package/dist/promise/misc.d.mts +6 -0
- package/dist/promise/misc.mjs +11 -2
- package/dist/promise/timed.d.mts +3 -0
- package/dist/promise/timed.mjs +5 -2
- package/dist/queue.d.mts +0 -1
- package/dist/queue.mjs +5 -6
- package/dist/random.d.mts +2 -2
- package/dist/random.mjs +3 -3
- package/dist/result/match.mjs +2 -2
- package/dist/result/misc.mjs +3 -10
- package/dist/result/work/pipe.d.mts +24 -22
- package/dist/result/work/pipe.mjs +7 -3
- package/dist/string/fuzzy.mjs +1 -1
- package/dist/string/index.d.mts +15 -1
- package/dist/string/index.mjs +16 -2
- package/dist/string/match.d.mts +24 -0
- package/dist/string/match.mjs +24 -0
- package/dist/string/template.d.mts +4 -0
- package/dist/value/clone.mjs +1 -1
- package/dist/value/merge.mjs +17 -4
- package/package.json +1 -1
package/dist/array/filter.d.mts
CHANGED
|
@@ -19,7 +19,7 @@ import { PlainObject } from "../models/index.mjs";
|
|
|
19
19
|
* ); // => [{id: 1}, {id: 3}]
|
|
20
20
|
* ```
|
|
21
21
|
*/
|
|
22
|
-
export declare function exclude<Item, Callback extends (item: Item, index: number, array: Item[]) => unknown>(array: Item[], callback: Callback, value: ReturnType<Callback>):
|
|
22
|
+
export declare function exclude<Item, Callback extends (item: Item, index: number, array: Item[]) => unknown>(array: Item[], callback: Callback, value: ReturnType<Callback>): Item[];
|
|
23
23
|
/**
|
|
24
24
|
* Get a filtered array of items that do not match the value
|
|
25
25
|
*
|
|
@@ -39,7 +39,25 @@ export declare function exclude<Item, Callback extends (item: Item, index: numbe
|
|
|
39
39
|
* ); // => [{id: 1}, {id: 3}]
|
|
40
40
|
* ```
|
|
41
41
|
*/
|
|
42
|
-
export declare function exclude<Item extends PlainObject, ItemKey extends keyof Item>(array: Item[], key: ItemKey, value: Item[ItemKey]):
|
|
42
|
+
export declare function exclude<Item extends PlainObject, ItemKey extends keyof Item>(array: Item[], key: ItemKey, value: Item[ItemKey]): Item[];
|
|
43
|
+
/**
|
|
44
|
+
* Get a narrowed array of items that do not match the filter
|
|
45
|
+
*
|
|
46
|
+
* _Available as `exclude` and `filter.remove`_
|
|
47
|
+
*
|
|
48
|
+
* @param array Array to search in
|
|
49
|
+
* @param filter Type guard to exclude and narrow down the items
|
|
50
|
+
* @returns Narrowed array of items that do not match the filter
|
|
51
|
+
*
|
|
52
|
+
* @example
|
|
53
|
+
* ```typescript
|
|
54
|
+
* exclude(
|
|
55
|
+
* [1, 'a', 2, 'b'],
|
|
56
|
+
* (item): item is string => typeof item === 'string',
|
|
57
|
+
* ); // => [1, 2]
|
|
58
|
+
* ```
|
|
59
|
+
*/
|
|
60
|
+
export declare function exclude<Item, Narrowed extends Item>(array: Item[], filter: (item: Item, index: number, array: Item[]) => item is Narrowed): Array<Exclude<Item, Narrowed>>;
|
|
43
61
|
/**
|
|
44
62
|
* Get a filtered array of items that do not match the filter
|
|
45
63
|
*
|
|
@@ -57,7 +75,7 @@ export declare function exclude<Item extends PlainObject, ItemKey extends keyof
|
|
|
57
75
|
* ); // => [{id: 1}, {id: 3}]
|
|
58
76
|
* ```
|
|
59
77
|
*/
|
|
60
|
-
export declare function exclude<Item>(array: Item[], filter: (item: Item, index: number, array: Item[]) => boolean):
|
|
78
|
+
export declare function exclude<Item>(array: Item[], filter: (item: Item, index: number, array: Item[]) => boolean): Item[];
|
|
61
79
|
/**
|
|
62
80
|
* Get a filtered array of items that do not match the given item
|
|
63
81
|
*
|
|
@@ -72,7 +90,7 @@ export declare function exclude<Item>(array: Item[], filter: (item: Item, index:
|
|
|
72
90
|
* exclude([1, 2, 3], 2); // => [1, 3]
|
|
73
91
|
* ```
|
|
74
92
|
*/
|
|
75
|
-
export declare function exclude<Item>(array: Item[], item: Item):
|
|
93
|
+
export declare function exclude<Item>(array: Item[], item: Item): Item[];
|
|
76
94
|
/**
|
|
77
95
|
* Get a filtered array of items
|
|
78
96
|
*
|
|
@@ -109,6 +127,22 @@ export declare function filter<Item, Callback extends (item: Item, index: number
|
|
|
109
127
|
* ```
|
|
110
128
|
*/
|
|
111
129
|
export declare function filter<Item extends PlainObject, ItemKey extends keyof Item>(array: Item[], key: ItemKey, value: Item[ItemKey]): Item[];
|
|
130
|
+
/**
|
|
131
|
+
* Get a narrowed array of items matching the filter
|
|
132
|
+
*
|
|
133
|
+
* @param array Array to search in
|
|
134
|
+
* @param filter Type guard to match and narrow down the items
|
|
135
|
+
* @returns Narrowed array of items
|
|
136
|
+
*
|
|
137
|
+
* @example
|
|
138
|
+
* ```typescript
|
|
139
|
+
* filter(
|
|
140
|
+
* [{id: 1, tags: ['a', 'b']}, {id: 2}, {id: 3, tags: ['c']}],
|
|
141
|
+
* (item): item is {id: number; tags: string[]} => item.tags != null,
|
|
142
|
+
* ); // => [{id: 1, tags: ['a', 'b']}, {id: 3, tags: ['c']}]
|
|
143
|
+
* ```
|
|
144
|
+
*/
|
|
145
|
+
export declare function filter<Item, Narrowed extends Item>(array: Item[], filter: (item: Item, index: number, array: Item[]) => item is Narrowed): Narrowed[];
|
|
112
146
|
/**
|
|
113
147
|
* Get a filtered array of items matching the filter
|
|
114
148
|
*
|
package/dist/array/find.d.mts
CHANGED
|
@@ -36,6 +36,22 @@ export declare function find<Item, Callback extends (item: Item, index: number,
|
|
|
36
36
|
* ```
|
|
37
37
|
*/
|
|
38
38
|
export declare function find<Item extends PlainObject, ItemKey extends keyof Item>(array: Item[], key: ItemKey, value: Item[ItemKey]): Item | undefined;
|
|
39
|
+
/**
|
|
40
|
+
* Get the first narrowed item matching the filter
|
|
41
|
+
*
|
|
42
|
+
* @param array Array to search in
|
|
43
|
+
* @param filter Type guard to match and narrow down the items
|
|
44
|
+
* @returns First narrowed item that matches the filter, or `undefined` if no match is found
|
|
45
|
+
*
|
|
46
|
+
* @example
|
|
47
|
+
* ```typescript
|
|
48
|
+
* find(
|
|
49
|
+
* [{id: 1, value: 10}, {id: 2, value: 'a'}, {id: 3, value: 'b'}],
|
|
50
|
+
* (item): item is {id: number; value: string} => typeof item.value === 'string',
|
|
51
|
+
* ); // => {id: 2, value: 'a'}
|
|
52
|
+
* ```
|
|
53
|
+
*/
|
|
54
|
+
export declare function find<Item, Narrowed extends Item>(array: Item[], filter: (item: Item, index: number, array: Item[]) => item is Narrowed): Narrowed | undefined;
|
|
39
55
|
/**
|
|
40
56
|
* Get the first item matching the filter
|
|
41
57
|
*
|
|
@@ -105,6 +121,24 @@ export declare function findLast<Item, Callback extends (item: Item, index: numb
|
|
|
105
121
|
* ```
|
|
106
122
|
*/
|
|
107
123
|
export declare function findLast<Item extends PlainObject, ItemKey extends keyof Item>(array: Item[], key: ItemKey, value: Item[ItemKey]): Item | undefined;
|
|
124
|
+
/**
|
|
125
|
+
* Get the last narrowed item matching the filter
|
|
126
|
+
*
|
|
127
|
+
* _Available as `findLast` and `find.last`_
|
|
128
|
+
*
|
|
129
|
+
* @param array Array to search in
|
|
130
|
+
* @param filter Type guard to match and narrow down the items
|
|
131
|
+
* @returns Last narrowed item that matches the filter, or `undefined` if no match is found
|
|
132
|
+
*
|
|
133
|
+
* @example
|
|
134
|
+
* ```typescript
|
|
135
|
+
* findLast(
|
|
136
|
+
* [{id: 1, value: 10}, {id: 2, value: 'a'}, {id: 3, value: 'b'}],
|
|
137
|
+
* (item): item is {id: number; value: string} => typeof item.value === 'string',
|
|
138
|
+
* ); // => {id: 3, value: 'b'}
|
|
139
|
+
* ```
|
|
140
|
+
*/
|
|
141
|
+
export declare function findLast<Item, Narrowed extends Item>(array: Item[], filter: (item: Item, index: number, array: Item[]) => item is Narrowed): Narrowed | undefined;
|
|
108
142
|
/**
|
|
109
143
|
* Get the last item matching the filter
|
|
110
144
|
*
|
package/dist/array/first.d.mts
CHANGED
|
@@ -36,6 +36,22 @@ export declare function first<Item, Callback extends (item: Item, index: number,
|
|
|
36
36
|
* ```
|
|
37
37
|
*/
|
|
38
38
|
export declare function first<Item extends PlainObject, ItemKey extends keyof Item>(array: Item[], key: ItemKey, value: Item[ItemKey]): Item | undefined;
|
|
39
|
+
/**
|
|
40
|
+
* Get the first narrowed item matching the filter
|
|
41
|
+
*
|
|
42
|
+
* @param array Array to search in
|
|
43
|
+
* @param filter Type guard to match and narrow down the items
|
|
44
|
+
* @returns First narrowed item that matches the filter, or `undefined` if no match is found
|
|
45
|
+
*
|
|
46
|
+
* @example
|
|
47
|
+
* ```typescript
|
|
48
|
+
* first(
|
|
49
|
+
* [{id: 1, value: 10}, {id: 2, value: 'a'}, {id: 3, value: 'b'}],
|
|
50
|
+
* (item): item is {id: number; value: string} => typeof item.value === 'string',
|
|
51
|
+
* ); // => {id: 2, value: 'a'}
|
|
52
|
+
* ```
|
|
53
|
+
*/
|
|
54
|
+
export declare function first<Item, Narrowed extends Item>(array: Item[], filter: (item: Item, index: number, array: Item[]) => item is Narrowed): Narrowed | undefined;
|
|
39
55
|
/**
|
|
40
56
|
* Get the first item matching the filter
|
|
41
57
|
*
|
|
@@ -69,7 +85,7 @@ export declare function first<Item>(array: Item[]): Item | undefined;
|
|
|
69
85
|
/**
|
|
70
86
|
* Get the first item matching the given value, or a default value if no match is found
|
|
71
87
|
*
|
|
72
|
-
* _Available as `firstOrDefault` and `first.
|
|
88
|
+
* _Available as `firstOrDefault` and `first.defaulted`_
|
|
73
89
|
*
|
|
74
90
|
* @param array Array to search in
|
|
75
91
|
* @param defaultValue Default value to return if no match is found
|
|
@@ -91,7 +107,7 @@ export declare function firstOrDefault<Item, Callback extends (item: Item, index
|
|
|
91
107
|
/**
|
|
92
108
|
* Get the first item matching the given value by key, or a default value if no match is found
|
|
93
109
|
*
|
|
94
|
-
* _Available as `firstOrDefault` and `first.
|
|
110
|
+
* _Available as `firstOrDefault` and `first.defaulted`_
|
|
95
111
|
*
|
|
96
112
|
* @param array Array to search in
|
|
97
113
|
* @param defaultValue Default value to return if no match is found
|
|
@@ -110,10 +126,30 @@ export declare function firstOrDefault<Item, Callback extends (item: Item, index
|
|
|
110
126
|
* ```
|
|
111
127
|
*/
|
|
112
128
|
export declare function firstOrDefault<Item extends PlainObject, ItemKey extends keyof Item>(array: Item[], defaultValue: Item, key: ItemKey, value: Item[ItemKey]): Item;
|
|
129
|
+
/**
|
|
130
|
+
* Get the first narrowed item matching the filter, or a default value if no match is found
|
|
131
|
+
*
|
|
132
|
+
* _Available as `firstOrDefault` and `first.defaulted`_
|
|
133
|
+
*
|
|
134
|
+
* @param array Array to search in
|
|
135
|
+
* @param defaultValue Default value to return if no match is found
|
|
136
|
+
* @param filter Type guard to match and narrow down the items
|
|
137
|
+
* @returns First narrowed item that matches the filter, or the default value if no match is found
|
|
138
|
+
*
|
|
139
|
+
* @example
|
|
140
|
+
* ```typescript
|
|
141
|
+
* firstOrDefault(
|
|
142
|
+
* [{id: 1, value: 10}, {id: 2, value: 'a'}, {id: 3, value: 'b'}],
|
|
143
|
+
* {id: -1, value: 'c'},
|
|
144
|
+
* (item): item is {id: number; value: string} => typeof item.value === 'string',
|
|
145
|
+
* ); // => {id: 2, value: 'a'}
|
|
146
|
+
* ```
|
|
147
|
+
*/
|
|
148
|
+
export declare function firstOrDefault<Item, Narrowed extends Item, Default>(array: Item[], defaultValue: Default, filter: (item: Item, index: number, array: Item[]) => item is Narrowed): Narrowed | Default;
|
|
113
149
|
/**
|
|
114
150
|
* Get the first item matching the filter, or a default value if no match is found
|
|
115
151
|
*
|
|
116
|
-
* _Available as `firstOrDefault` and `first.
|
|
152
|
+
* _Available as `firstOrDefault` and `first.defaulted`_
|
|
117
153
|
*
|
|
118
154
|
* @param array Array to search in
|
|
119
155
|
* @param defaultValue Default value to return if no match is found
|
|
@@ -133,7 +169,7 @@ export declare function firstOrDefault<Item>(array: Item[], defaultValue: Item,
|
|
|
133
169
|
/**
|
|
134
170
|
* Get the first item from an array, or a default value if the array is empty
|
|
135
171
|
*
|
|
136
|
-
* _Available as `firstOrDefault` and `first.
|
|
172
|
+
* _Available as `firstOrDefault` and `first.defaulted`_
|
|
137
173
|
*
|
|
138
174
|
* @param array Array to get from
|
|
139
175
|
* @param defaultValue Default value to return if the array is empty
|
package/dist/array/insert.mjs
CHANGED
|
@@ -2,7 +2,7 @@ import { ARRAY_INSERT_TYPE_INSERT } from "../models/array/array.misc.model.mjs";
|
|
|
2
2
|
import { insertValues } from "../internal/array/insert.mjs";
|
|
3
3
|
//#region src/array/insert.ts
|
|
4
4
|
function insert(array, indexOrItems, items) {
|
|
5
|
-
return insertValues(ARRAY_INSERT_TYPE_INSERT, array, items
|
|
5
|
+
return insertValues(ARRAY_INSERT_TYPE_INSERT, array, items ?? indexOrItems, typeof indexOrItems === "number" ? indexOrItems : array?.length, 0);
|
|
6
6
|
}
|
|
7
7
|
//#endregion
|
|
8
8
|
export { insert };
|
package/dist/array/last.d.mts
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { PlainObject } from "../models/index.mjs";
|
|
2
2
|
//#region src/array/last.d.ts
|
|
3
3
|
/**
|
|
4
|
-
* Get the last
|
|
4
|
+
* Get the last item matching the given value
|
|
5
5
|
*
|
|
6
6
|
* @param array Array to search in
|
|
7
7
|
* @param callback Callback to get an item's value for matching
|
|
@@ -19,7 +19,7 @@ import { PlainObject } from "../models/index.mjs";
|
|
|
19
19
|
*/
|
|
20
20
|
export declare function last<Item, Callback extends (item: Item, index: number, array: Item[]) => unknown>(array: Item[], callback: Callback, value: ReturnType<Callback>): Item | undefined;
|
|
21
21
|
/**
|
|
22
|
-
* Get the
|
|
22
|
+
* Get the last item matching the given value by key
|
|
23
23
|
*
|
|
24
24
|
* @param array Array to search in
|
|
25
25
|
* @param key Key to get an item's value for matching
|
|
@@ -36,6 +36,22 @@ export declare function last<Item, Callback extends (item: Item, index: number,
|
|
|
36
36
|
* ```
|
|
37
37
|
*/
|
|
38
38
|
export declare function last<Item extends PlainObject, ItemKey extends keyof Item>(array: Item[], key: ItemKey, value: Item[ItemKey]): Item | undefined;
|
|
39
|
+
/**
|
|
40
|
+
* Get the last narrowed item matching the filter
|
|
41
|
+
*
|
|
42
|
+
* @param array Array to search in
|
|
43
|
+
* @param filter Type guard to match and narrow down the items
|
|
44
|
+
* @returns Last narrowed item that matches the filter, or `undefined` if no match is found
|
|
45
|
+
*
|
|
46
|
+
* @example
|
|
47
|
+
* ```typescript
|
|
48
|
+
* last(
|
|
49
|
+
* [{id: 1, value: 10}, {id: 2, value: 'a'}, {id: 3, value: 'b'}],
|
|
50
|
+
* (item): item is {id: number; value: string} => typeof item.value === 'string',
|
|
51
|
+
* ); // => {id: 3, value: 'b'}
|
|
52
|
+
* ```
|
|
53
|
+
*/
|
|
54
|
+
export declare function last<Item, Narrowed extends Item>(array: Item[], filter: (item: Item, index: number, array: Item[]) => item is Narrowed): Narrowed | undefined;
|
|
39
55
|
/**
|
|
40
56
|
* Get the last item matching the filter
|
|
41
57
|
*
|
|
@@ -65,9 +81,9 @@ export declare function last<Item>(array: Item[], filter: (item: Item, index: nu
|
|
|
65
81
|
*/
|
|
66
82
|
export declare function last<Item>(array: Item[]): Item | undefined;
|
|
67
83
|
/**
|
|
68
|
-
* Get the last item matching the given value
|
|
84
|
+
* Get the last item matching the given value, or a default value if no match is found
|
|
69
85
|
*
|
|
70
|
-
* _Available as `lastOrDefault` and `last.
|
|
86
|
+
* _Available as `lastOrDefault` and `last.defaulted`_
|
|
71
87
|
*
|
|
72
88
|
* @param array Array to search in
|
|
73
89
|
* @param defaultValue Default value to return if no match is found
|
|
@@ -87,9 +103,9 @@ export declare function last<Item>(array: Item[]): Item | undefined;
|
|
|
87
103
|
*/
|
|
88
104
|
export declare function lastOrDefault<Item, Callback extends (item: Item, index: number, array: Item[]) => unknown>(array: Item[], defaultValue: Item, callback: Callback, value: ReturnType<Callback>): Item;
|
|
89
105
|
/**
|
|
90
|
-
* Get the last item matching the given value by key
|
|
106
|
+
* Get the last item matching the given value by key, or a default value if no match is found
|
|
91
107
|
*
|
|
92
|
-
* _Available as `lastOrDefault` and `last.
|
|
108
|
+
* _Available as `lastOrDefault` and `last.defaulted`_
|
|
93
109
|
*
|
|
94
110
|
* @param array Array to search in
|
|
95
111
|
* @param defaultValue Default value to return if no match is found
|
|
@@ -109,9 +125,29 @@ export declare function lastOrDefault<Item, Callback extends (item: Item, index:
|
|
|
109
125
|
*/
|
|
110
126
|
export declare function lastOrDefault<Item extends PlainObject, ItemKey extends keyof Item>(array: Item[], defaultValue: Item, key: ItemKey, value: Item[ItemKey]): Item;
|
|
111
127
|
/**
|
|
112
|
-
* Get the last item matching the filter
|
|
128
|
+
* Get the last narrowed item matching the filter, or a default value if no match is found
|
|
113
129
|
*
|
|
114
|
-
* _Available as `lastOrDefault` and `last.
|
|
130
|
+
* _Available as `lastOrDefault` and `last.defaulted`_
|
|
131
|
+
*
|
|
132
|
+
* @param array Array to search in
|
|
133
|
+
* @param defaultValue Default value to return if no match is found
|
|
134
|
+
* @param filter Type guard to match and narrow down the items
|
|
135
|
+
* @returns Last narrowed item that matches the filter, or the default value if no match is found
|
|
136
|
+
*
|
|
137
|
+
* @example
|
|
138
|
+
* ```typescript
|
|
139
|
+
* lastOrDefault(
|
|
140
|
+
* [{id: 1, value: 10}, {id: 2, value: 'a'}, {id: 3, value: 'b'}],
|
|
141
|
+
* {id: -1, value: 'c'},
|
|
142
|
+
* (item): item is {id: number; value: string} => typeof item.value === 'string',
|
|
143
|
+
* ); // => {id: 3, value: 'b'}
|
|
144
|
+
* ```
|
|
145
|
+
*/
|
|
146
|
+
export declare function lastOrDefault<Item, Narrowed extends Item, Default>(array: Item[], defaultValue: Default, filter: (item: Item, index: number, array: Item[]) => item is Narrowed): Narrowed | Default;
|
|
147
|
+
/**
|
|
148
|
+
* Get the last item matching the filter, or a default value if no match is found
|
|
149
|
+
*
|
|
150
|
+
* _Available as `lastOrDefault` and `last.defaulted`_
|
|
115
151
|
*
|
|
116
152
|
* @param array Array to search in
|
|
117
153
|
* @param defaultValue Default value to return if no match is found
|
|
@@ -129,9 +165,9 @@ export declare function lastOrDefault<Item extends PlainObject, ItemKey extends
|
|
|
129
165
|
*/
|
|
130
166
|
export declare function lastOrDefault<Item>(array: Item[], defaultValue: Item, filter: (item: Item, index: number, array: Item[]) => boolean): Item;
|
|
131
167
|
/**
|
|
132
|
-
* Get the last item from an array
|
|
168
|
+
* Get the last item from an array, or a default value if the array is empty
|
|
133
169
|
*
|
|
134
|
-
* _Available as `lastOrDefault` and `last.
|
|
170
|
+
* _Available as `lastOrDefault` and `last.defaulted`_
|
|
135
171
|
*
|
|
136
172
|
* @param array Array to get from
|
|
137
173
|
* @param defaultValue Default value to return if the array is empty
|
|
@@ -6,7 +6,7 @@ import { PlainObject } from "../models/index.mjs";
|
|
|
6
6
|
* @param array Array to search in
|
|
7
7
|
* @param callback Callback to get an item's value for matching
|
|
8
8
|
* @param value Value to match against
|
|
9
|
-
* @returns
|
|
9
|
+
* @returns Tuple of matching and non-matching items
|
|
10
10
|
*
|
|
11
11
|
* @example
|
|
12
12
|
* ```typescript
|
|
@@ -17,14 +17,14 @@ import { PlainObject } from "../models/index.mjs";
|
|
|
17
17
|
* ); // => [[{id: 2}], [{id: 1}, {id: 3}]]
|
|
18
18
|
* ```
|
|
19
19
|
*/
|
|
20
|
-
export declare function partition<Item, Callback extends (item: Item, index: number, array: Item[]) => unknown>(array: Item[], callback: Callback, value: ReturnType<Callback>): Item[][];
|
|
20
|
+
export declare function partition<Item, Callback extends (item: Item, index: number, array: Item[]) => unknown>(array: Item[], callback: Callback, value: ReturnType<Callback>): [Item[], Item[]];
|
|
21
21
|
/**
|
|
22
22
|
* Get a partitioned array of items
|
|
23
23
|
*
|
|
24
24
|
* @param array Array to search in
|
|
25
25
|
* @param key Key to get an item's value for matching
|
|
26
26
|
* @param value Value to match against
|
|
27
|
-
* @returns
|
|
27
|
+
* @returns Tuple of matching and non-matching items
|
|
28
28
|
*
|
|
29
29
|
* @example
|
|
30
30
|
* ```typescript
|
|
@@ -35,13 +35,29 @@ export declare function partition<Item, Callback extends (item: Item, index: num
|
|
|
35
35
|
* ); // => [[{id: 2}], [{id: 1}, {id: 3}]]
|
|
36
36
|
* ```
|
|
37
37
|
*/
|
|
38
|
-
export declare function partition<Item extends PlainObject, ItemKey extends keyof Item>(array: Item[], key: ItemKey, value: Item[ItemKey]): Item[][];
|
|
38
|
+
export declare function partition<Item extends PlainObject, ItemKey extends keyof Item>(array: Item[], key: ItemKey, value: Item[ItemKey]): [Item[], Item[]];
|
|
39
|
+
/**
|
|
40
|
+
* Get a partitioned array of items
|
|
41
|
+
*
|
|
42
|
+
* @param array Array to search in
|
|
43
|
+
* @param filter Type guard to match and narrow down the items
|
|
44
|
+
* @returns Tuple of matching and non-matching items
|
|
45
|
+
*
|
|
46
|
+
* @example
|
|
47
|
+
* ```typescript
|
|
48
|
+
* partition(
|
|
49
|
+
* [{id: 1, value: 10}, {id: 2, value: 'a'}, {id: 3, value: 'b'}],
|
|
50
|
+
* (item): item is {id: number; value: string} => typeof item.value === 'string',
|
|
51
|
+
* ); // => [[{id: 2, value: 'a'}, {id: 3, value: 'b'}], [{id: 1, value: 10}]]
|
|
52
|
+
* ```
|
|
53
|
+
*/
|
|
54
|
+
export declare function partition<Item, Narrowed extends Item>(array: Item[], filter: (item: Item, index: number, array: Item[]) => item is Narrowed): [Narrowed[], Array<Exclude<Item, Narrowed>>];
|
|
39
55
|
/**
|
|
40
56
|
* Get a partitioned array of items
|
|
41
57
|
*
|
|
42
58
|
* @param array Array to search in
|
|
43
59
|
* @param filter Filter callback to match items
|
|
44
|
-
* @returns
|
|
60
|
+
* @returns Tuple of matching and non-matching items
|
|
45
61
|
*
|
|
46
62
|
* @example
|
|
47
63
|
* ```typescript
|
|
@@ -51,18 +67,18 @@ export declare function partition<Item extends PlainObject, ItemKey extends keyo
|
|
|
51
67
|
* ); // => [[{id: 2}], [{id: 1}, {id: 3}]]
|
|
52
68
|
* ```
|
|
53
69
|
*/
|
|
54
|
-
export declare function partition<Item>(array: Item[], filter: (item: Item, index: number, array: Item[]) => boolean): Item[][];
|
|
70
|
+
export declare function partition<Item>(array: Item[], filter: (item: Item, index: number, array: Item[]) => boolean): [Item[], Item[]];
|
|
55
71
|
/**
|
|
56
72
|
* Get a partitioned array of items matching the given item
|
|
57
73
|
*
|
|
58
74
|
* @param array Array to search in
|
|
59
75
|
* @param item Item to match against
|
|
60
|
-
* @returns
|
|
76
|
+
* @returns Tuple of matching and non-matching items
|
|
61
77
|
*
|
|
62
78
|
* @example
|
|
63
79
|
* ```typescript
|
|
64
80
|
* partition([1, 2, 3, 4, 5], 3); // => [[3], [1, 2, 4, 5]]
|
|
65
81
|
* ```
|
|
66
82
|
*/
|
|
67
|
-
export declare function partition<Item>(array: Item[], item: Item): Item[][];
|
|
83
|
+
export declare function partition<Item>(array: Item[], item: Item): [Item[], Item[]];
|
|
68
84
|
//#endregion
|
package/dist/array/reverse.d.mts
CHANGED
|
@@ -4,6 +4,12 @@
|
|
|
4
4
|
*
|
|
5
5
|
* @param array Array to reverse
|
|
6
6
|
* @returns Reversed array
|
|
7
|
+
*
|
|
8
|
+
* @example
|
|
9
|
+
* ```typescript
|
|
10
|
+
* reverse([1, 2, 3]); // => [3, 2, 1]
|
|
11
|
+
* reverse(['a', 'b', 'c']); // => ['c', 'b', 'a']
|
|
12
|
+
* ```
|
|
7
13
|
*/
|
|
8
14
|
export declare function reverse<Item>(array: Item[]): Item[];
|
|
9
15
|
//#endregion
|
package/dist/array/reverse.mjs
CHANGED
|
@@ -5,6 +5,12 @@ import { floor } from "../internal/math/misc.mjs";
|
|
|
5
5
|
*
|
|
6
6
|
* @param array Array to reverse
|
|
7
7
|
* @returns Reversed array
|
|
8
|
+
*
|
|
9
|
+
* @example
|
|
10
|
+
* ```typescript
|
|
11
|
+
* reverse([1, 2, 3]); // => [3, 2, 1]
|
|
12
|
+
* reverse(['a', 'b', 'c']); // => ['c', 'b', 'a']
|
|
13
|
+
* ```
|
|
8
14
|
*/
|
|
9
15
|
function reverse(array) {
|
|
10
16
|
if (!Array.isArray(array)) return [];
|