@oscarpalmer/atoms 0.185.0 → 0.186.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/difference.d.mts +29 -0
- package/dist/array/exists.d.mts +35 -0
- package/dist/array/filter.d.mts +72 -2
- package/dist/array/find.d.mts +70 -0
- package/dist/array/first.d.mts +77 -2
- package/dist/array/flatten.d.mts +6 -0
- package/dist/array/flatten.mjs +6 -0
- package/dist/array/from.d.mts +36 -0
- package/dist/array/get.d.mts +21 -13
- package/dist/array/group-by.d.mts +142 -0
- package/dist/array/insert.d.mts +16 -0
- package/dist/array/intersection.d.mts +29 -0
- package/dist/array/last.d.mts +75 -2
- package/dist/array/match.d.mts +161 -32
- package/dist/array/move.d.mts +78 -8
- package/dist/array/move.mjs +10 -0
- package/dist/array/partition.d.mts +35 -0
- package/dist/array/push.d.mts +8 -0
- package/dist/array/push.mjs +8 -0
- package/dist/array/reverse.d.mts +1 -0
- package/dist/array/reverse.mjs +1 -0
- package/dist/array/select.d.mts +94 -8
- package/dist/array/single.d.mts +29 -0
- package/dist/array/slice.d.mts +106 -16
- package/dist/array/sort.d.mts +21 -0
- package/dist/array/splice.d.mts +48 -0
- package/dist/array/splice.mjs +2 -1
- package/dist/array/swap.d.mts +113 -8
- package/dist/array/swap.mjs +1 -0
- package/dist/array/to-map.d.mts +124 -0
- package/dist/array/to-record.d.mts +124 -0
- package/dist/array/to-set.d.mts +24 -0
- package/dist/array/toggle.d.mts +38 -3
- package/dist/array/union.d.mts +29 -0
- package/dist/array/unique.d.mts +24 -0
- package/dist/array/update.d.mts +38 -3
- package/dist/index.d.mts +1892 -135
- package/dist/index.mjs +64 -18
- package/dist/internal/array/chunk.d.mts +6 -0
- package/dist/internal/array/chunk.mjs +6 -0
- package/dist/internal/array/compact.d.mts +12 -0
- package/dist/internal/array/index-of.d.mts +70 -0
- package/dist/internal/math/aggregate.d.mts +29 -0
- package/dist/internal/value/get.d.mts +25 -3
- package/dist/internal/value/has.d.mts +4 -4
- package/dist/models.d.mts +14 -1
- package/dist/value/collection.d.mts +1 -1
- package/dist/value/merge.d.mts +28 -25
- package/dist/value/merge.mjs +29 -18
- package/dist/value/transform.d.mts +1 -1
- package/dist/value/unsmush.d.mts +1 -5
- package/package.json +5 -5
- package/src/array/difference.ts +29 -0
- package/src/array/exists.ts +35 -0
- package/src/array/filter.ts +72 -2
- package/src/array/find.ts +70 -0
- package/src/array/first.ts +77 -3
- package/src/array/flatten.ts +6 -0
- package/src/array/from.ts +36 -0
- package/src/array/get.ts +21 -15
- package/src/array/group-by.ts +142 -0
- package/src/array/insert.ts +16 -2
- package/src/array/intersection.ts +29 -0
- package/src/array/last.ts +75 -2
- package/src/array/match.ts +171 -42
- package/src/array/move.ts +82 -12
- package/src/array/partition.ts +35 -0
- package/src/array/push.ts +8 -2
- package/src/array/reverse.ts +1 -0
- package/src/array/select.ts +94 -13
- package/src/array/single.ts +29 -0
- package/src/array/slice.ts +114 -24
- package/src/array/sort.ts +21 -0
- package/src/array/splice.ts +52 -4
- package/src/array/swap.ts +117 -12
- package/src/array/to-map.ts +124 -0
- package/src/array/to-record.ts +124 -0
- package/src/array/to-set.ts +24 -0
- package/src/array/toggle.ts +38 -3
- package/src/array/union.ts +29 -0
- package/src/array/unique.ts +24 -0
- package/src/array/update.ts +38 -3
- package/src/internal/array/chunk.ts +6 -0
- package/src/internal/array/compact.ts +12 -0
- package/src/internal/array/index-of.ts +70 -0
- package/src/internal/math/aggregate.ts +29 -0
- package/src/internal/string.ts +0 -2
- package/src/internal/value/get.ts +25 -3
- package/src/internal/value/has.ts +4 -4
- package/src/models.ts +18 -0
- package/src/value/collection.ts +1 -1
- package/src/value/merge.ts +88 -66
- package/src/value/transform.ts +1 -1
- package/src/value/unsmush.ts +1 -10
|
@@ -3,25 +3,54 @@ import { PlainObject } from "../models.mjs";
|
|
|
3
3
|
//#region src/array/difference.d.ts
|
|
4
4
|
/**
|
|
5
5
|
* Get the items from the first array that are not in the second array
|
|
6
|
+
*
|
|
6
7
|
* @param first First array
|
|
7
8
|
* @param second Second array
|
|
8
9
|
* @param callback Callback to get an item's value for comparison
|
|
9
10
|
* @returns Unique values from the first array
|
|
11
|
+
*
|
|
12
|
+
* @example
|
|
13
|
+
* ```typescript
|
|
14
|
+
* difference(
|
|
15
|
+
* [{id: 1}, {id: 2}, {id: 3}],
|
|
16
|
+
* [{id: 2}, {id: 4}],
|
|
17
|
+
* item => item.id,
|
|
18
|
+
* ); // => [{id: 1}, {id: 3}]
|
|
19
|
+
* ```
|
|
10
20
|
*/
|
|
11
21
|
declare function difference<First, Second>(first: First[], second: Second[], callback: (item: First | Second) => unknown): First[];
|
|
12
22
|
/**
|
|
13
23
|
* Get the items from the first array that are not in the second array
|
|
24
|
+
*
|
|
14
25
|
* @param first First array
|
|
15
26
|
* @param second Second array
|
|
16
27
|
* @param key Key to get an item's value for comparison
|
|
17
28
|
* @returns Unique values from the first array
|
|
29
|
+
*
|
|
30
|
+
* @example
|
|
31
|
+
* ```typescript
|
|
32
|
+
* difference(
|
|
33
|
+
* [{id: 1}, {id: 2}, {id: 3}],
|
|
34
|
+
* [{id: 2}, {id: 4}],
|
|
35
|
+
* 'id',
|
|
36
|
+
* ); // => [{id: 1}, {id: 3}]
|
|
37
|
+
* ```
|
|
18
38
|
*/
|
|
19
39
|
declare function difference<First extends PlainObject, Second extends PlainObject, SharedKey extends keyof First & keyof Second>(first: First[], second: Second[], key: SharedKey): First[];
|
|
20
40
|
/**
|
|
21
41
|
* Get the items from the first array that are not in the second array
|
|
42
|
+
*
|
|
22
43
|
* @param first First array
|
|
23
44
|
* @param second Second array
|
|
24
45
|
* @returns Unique values from the first array
|
|
46
|
+
*
|
|
47
|
+
* @example
|
|
48
|
+
* ```typescript
|
|
49
|
+
* difference(
|
|
50
|
+
* [1, 2, 3],
|
|
51
|
+
* [2, 4],
|
|
52
|
+
* ); // => [1, 3]
|
|
53
|
+
* ```
|
|
25
54
|
*/
|
|
26
55
|
declare function difference<First, Second>(first: First[], second: Second[]): First[];
|
|
27
56
|
//#endregion
|
package/dist/array/exists.d.mts
CHANGED
|
@@ -3,32 +3,67 @@ import { PlainObject } from "../models.mjs";
|
|
|
3
3
|
//#region src/array/exists.d.ts
|
|
4
4
|
/**
|
|
5
5
|
* Does an item with a specific value exist in the array?
|
|
6
|
+
*
|
|
6
7
|
* @param array Array to search in
|
|
7
8
|
* @param callback Callback to get an item's value for matching
|
|
8
9
|
* @param value Value to match against
|
|
9
10
|
* @returns `true` if the item exists in the array, otherwise `false`
|
|
11
|
+
*
|
|
12
|
+
* @example
|
|
13
|
+
* ```typescript
|
|
14
|
+
* exists(
|
|
15
|
+
* [{id: 1}, {id: 2}, {id: 3}],
|
|
16
|
+
* item => item.id,
|
|
17
|
+
* 2,
|
|
18
|
+
* ); // => true
|
|
19
|
+
* ```
|
|
10
20
|
*/
|
|
11
21
|
declare function exists<Item, Callback extends (item: Item, index: number, array: Item[]) => unknown>(array: Item[], callback: Callback, value: ReturnType<Callback>): boolean;
|
|
12
22
|
/**
|
|
13
23
|
* Does an item with a specific value exist in the array?
|
|
24
|
+
*
|
|
14
25
|
* @param array Array to search in
|
|
15
26
|
* @param key Key to get an item's value for matching
|
|
16
27
|
* @param value Value to match against
|
|
17
28
|
* @returns `true` if the item exists in the array, otherwise `false`
|
|
29
|
+
*
|
|
30
|
+
* @example
|
|
31
|
+
* ```typescript
|
|
32
|
+
* exists(
|
|
33
|
+
* [{id: 1}, {id: 2}, {id: 3}],
|
|
34
|
+
* 'id',
|
|
35
|
+
* 2,
|
|
36
|
+
* ); // => true
|
|
37
|
+
* ```
|
|
18
38
|
*/
|
|
19
39
|
declare function exists<Item extends PlainObject, ItemKey extends keyof Item>(array: Item[], key: ItemKey, value: Item[ItemKey]): boolean;
|
|
20
40
|
/**
|
|
21
41
|
* Does an item in the array match the filter?
|
|
42
|
+
*
|
|
22
43
|
* @param array Array to search in
|
|
23
44
|
* @param filter Filter callback to match items
|
|
24
45
|
* @returns `true` if a matching item exists, otherwise `false`
|
|
46
|
+
*
|
|
47
|
+
* @example
|
|
48
|
+
* ```typescript
|
|
49
|
+
* exists(
|
|
50
|
+
* [{id: 1}, {id: 2}, {id: 3}],
|
|
51
|
+
* item => item.id === 2,
|
|
52
|
+
* ); // => true
|
|
53
|
+
* ```
|
|
25
54
|
*/
|
|
26
55
|
declare function exists<Item>(array: Item[], filter: (item: Item, index: number, array: Item[]) => boolean): boolean;
|
|
27
56
|
/**
|
|
28
57
|
* Does the item exist in the array?
|
|
58
|
+
*
|
|
29
59
|
* @param array Array to search in
|
|
30
60
|
* @param item Item to search for
|
|
31
61
|
* @returns `true` if the item exists in the array, otherwise `false`
|
|
62
|
+
*
|
|
63
|
+
* @example
|
|
64
|
+
* ```typescript
|
|
65
|
+
* exists([1, 2, 3], 2); // => true
|
|
66
|
+
* ```
|
|
32
67
|
*/
|
|
33
68
|
declare function exists<Item>(array: Item[], item: Item): boolean;
|
|
34
69
|
//#endregion
|
package/dist/array/filter.d.mts
CHANGED
|
@@ -2,71 +2,141 @@ import { PlainObject } from "../models.mjs";
|
|
|
2
2
|
|
|
3
3
|
//#region src/array/filter.d.ts
|
|
4
4
|
/**
|
|
5
|
-
* Get a filtered array of items that do not match the
|
|
5
|
+
* Get a filtered array of items that do not match the value
|
|
6
6
|
*
|
|
7
7
|
* Available as `exclude` and `filter.remove`
|
|
8
|
+
*
|
|
8
9
|
* @param array Array to search in
|
|
9
10
|
* @param callback Callback to get an item's value for matching
|
|
10
11
|
* @param value Value to match against
|
|
11
12
|
* @returns Filtered array of items that do not match the filter
|
|
13
|
+
*
|
|
14
|
+
* @example
|
|
15
|
+
* ```typescript
|
|
16
|
+
* exclude(
|
|
17
|
+
* [{id: 1}, {id: 2}, {id: 3}],
|
|
18
|
+
* item => item.id,
|
|
19
|
+
* 2,
|
|
20
|
+
* ); // => [{id: 1}, {id: 3}]
|
|
21
|
+
* ```
|
|
12
22
|
*/
|
|
13
23
|
declare function exclude<Item, Callback extends (item: Item, index: number, array: Item[]) => unknown>(array: Item[], callback: Callback, value: ReturnType<Callback>): unknown[];
|
|
14
24
|
/**
|
|
15
|
-
* Get a filtered array of items that do not match the
|
|
25
|
+
* Get a filtered array of items that do not match the value
|
|
16
26
|
*
|
|
17
27
|
* Available as `exclude` and `filter.remove`
|
|
28
|
+
*
|
|
18
29
|
* @param array Array to search in
|
|
19
30
|
* @param key Key to get an item's value for matching
|
|
20
31
|
* @param value Value to match against
|
|
21
32
|
* @returns Filtered array of items that do not match the filter
|
|
33
|
+
*
|
|
34
|
+
* @example
|
|
35
|
+
* ```typescript
|
|
36
|
+
* exclude(
|
|
37
|
+
* [{id: 1}, {id: 2}, {id: 3}],
|
|
38
|
+
* 'id',
|
|
39
|
+
* 2,
|
|
40
|
+
* ); // => [{id: 1}, {id: 3}]
|
|
41
|
+
* ```
|
|
22
42
|
*/
|
|
23
43
|
declare function exclude<Item extends PlainObject, ItemKey extends keyof Item>(array: Item[], key: ItemKey, value: Item[ItemKey]): unknown[];
|
|
24
44
|
/**
|
|
25
45
|
* Get a filtered array of items that do not match the filter
|
|
26
46
|
*
|
|
27
47
|
* Available as `exclude` and `filter.remove`
|
|
48
|
+
*
|
|
28
49
|
* @param array Array to search in
|
|
29
50
|
* @param filter Filter callback to match items
|
|
30
51
|
* @returns Filtered array of items that do not match the filter
|
|
52
|
+
*
|
|
53
|
+
* @example
|
|
54
|
+
* ```typescript
|
|
55
|
+
* exclude(
|
|
56
|
+
* [{id: 1}, {id: 2}, {id: 3}],
|
|
57
|
+
* item => item.id === 2,
|
|
58
|
+
* ); // => [{id: 1}, {id: 3}]
|
|
59
|
+
* ```
|
|
31
60
|
*/
|
|
32
61
|
declare function exclude<Item>(array: Item[], filter: (item: Item, index: number, array: Item[]) => boolean): unknown[];
|
|
33
62
|
/**
|
|
34
63
|
* Get a filtered array of items that do not match the given item
|
|
35
64
|
*
|
|
36
65
|
* Available as `exclude` and `filter.remove`
|
|
66
|
+
*
|
|
37
67
|
* @param array Array to search in
|
|
38
68
|
* @param item Item to match against
|
|
39
69
|
* @returns Filtered array of items that do not match the given item
|
|
70
|
+
*
|
|
71
|
+
* @example
|
|
72
|
+
* ```typescript
|
|
73
|
+
* exclude([1, 2, 3], 2); // => [1, 3]
|
|
74
|
+
* ```
|
|
40
75
|
*/
|
|
41
76
|
declare function exclude<Item>(array: Item[], item: Item): unknown[];
|
|
42
77
|
/**
|
|
43
78
|
* Get a filtered array of items
|
|
79
|
+
*
|
|
44
80
|
* @param array Array to search in
|
|
45
81
|
* @param callback Callback to get an item's value for matching
|
|
46
82
|
* @param value Value to match against
|
|
47
83
|
* @returns Filtered array of items
|
|
84
|
+
*
|
|
85
|
+
* @example
|
|
86
|
+
* ```typescript
|
|
87
|
+
* filter(
|
|
88
|
+
* [{id: 1}, {id: 2}, {id: 3}],
|
|
89
|
+
* item => item.id,
|
|
90
|
+
* 2,
|
|
91
|
+
* ); // => [{id: 2}]
|
|
92
|
+
* ```
|
|
48
93
|
*/
|
|
49
94
|
declare function filter<Item, Callback extends (item: Item, index: number, array: Item[]) => unknown>(array: Item[], callback: Callback, value: ReturnType<Callback>): Item[];
|
|
50
95
|
/**
|
|
51
96
|
* Get a filtered array of items
|
|
97
|
+
*
|
|
52
98
|
* @param array Array to search in
|
|
53
99
|
* @param key Key to get an item's value for matching
|
|
54
100
|
* @param value Value to match against
|
|
55
101
|
* @returns Filtered array of items
|
|
102
|
+
*
|
|
103
|
+
* @example
|
|
104
|
+
* ```typescript
|
|
105
|
+
* filter(
|
|
106
|
+
* [{id: 1}, {id: 2}, {id: 3}],
|
|
107
|
+
* 'id',
|
|
108
|
+
* 2,
|
|
109
|
+
* ); // => [{id: 2}]
|
|
110
|
+
* ```
|
|
56
111
|
*/
|
|
57
112
|
declare function filter<Item extends PlainObject, ItemKey extends keyof Item>(array: Item[], key: ItemKey, value: Item[ItemKey]): Item[];
|
|
58
113
|
/**
|
|
59
114
|
* Get a filtered array of items matching the filter
|
|
115
|
+
*
|
|
60
116
|
* @param array Array to search in
|
|
61
117
|
* @param filter Filter callback to match items
|
|
62
118
|
* @returns Filtered array of items
|
|
119
|
+
*
|
|
120
|
+
* @example
|
|
121
|
+
* ```typescript
|
|
122
|
+
* filter(
|
|
123
|
+
* [{id: 1}, {id: 2}, {id: 3}],
|
|
124
|
+
* item => item.id === 2,
|
|
125
|
+
* ); // => [{id: 2}]
|
|
126
|
+
* ```
|
|
63
127
|
*/
|
|
64
128
|
declare function filter<Item>(array: Item[], filter: (item: Item, index: number, array: Item[]) => boolean): Item[];
|
|
65
129
|
/**
|
|
66
130
|
* Get a filtered array of items matching the given item
|
|
131
|
+
*
|
|
67
132
|
* @param array Array to search in
|
|
68
133
|
* @param item Item to match against
|
|
69
134
|
* @returns Filtered array of items
|
|
135
|
+
*
|
|
136
|
+
* @example
|
|
137
|
+
* ```typescript
|
|
138
|
+
* filter([1, 2, 3], 2); // => [2]
|
|
139
|
+
* ```
|
|
70
140
|
*/
|
|
71
141
|
declare function filter<Item>(array: Item[], item: Item): Item[];
|
|
72
142
|
declare namespace filter {
|
package/dist/array/find.d.mts
CHANGED
|
@@ -3,32 +3,67 @@ import { PlainObject } from "../models.mjs";
|
|
|
3
3
|
//#region src/array/find.d.ts
|
|
4
4
|
/**
|
|
5
5
|
* Get the first item matching the given value
|
|
6
|
+
*
|
|
6
7
|
* @param array Array to search in
|
|
7
8
|
* @param callback Callback to get an item's value for matching
|
|
8
9
|
* @param value Value to match against
|
|
9
10
|
* @returns First item that matches the value, or `undefined` if no match is found
|
|
11
|
+
*
|
|
12
|
+
* @example
|
|
13
|
+
* ```typescript
|
|
14
|
+
* find(
|
|
15
|
+
* [{id: 1, value: 10}, {id: 2, value: 20}, {id: 3, value: 10}],
|
|
16
|
+
* item => item.value,
|
|
17
|
+
* 10,
|
|
18
|
+
* ); // => {id: 1, value: 10}
|
|
19
|
+
* ```
|
|
10
20
|
*/
|
|
11
21
|
declare function find<Item, Callback extends (item: Item, index: number, array: Item[]) => unknown>(array: Item[], callback: Callback, value: ReturnType<Callback>): Item | undefined;
|
|
12
22
|
/**
|
|
13
23
|
* Get the first item matching the given value by key
|
|
24
|
+
*
|
|
14
25
|
* @param array Array to search in
|
|
15
26
|
* @param key Key to get an item's value for matching
|
|
16
27
|
* @param value Value to match against
|
|
17
28
|
* @returns First item that matches the value, or `undefined` if no match is found
|
|
29
|
+
*
|
|
30
|
+
* @example
|
|
31
|
+
* ```typescript
|
|
32
|
+
* find(
|
|
33
|
+
* [{id: 1, value: 10}, {id: 2, value: 20}, {id: 3, value: 10}],
|
|
34
|
+
* 'value',
|
|
35
|
+
* 10,
|
|
36
|
+
* ); // => {id: 1, value: 10}
|
|
37
|
+
* ```
|
|
18
38
|
*/
|
|
19
39
|
declare function find<Item extends PlainObject, ItemKey extends keyof Item>(array: Item[], key: ItemKey, value: Item[ItemKey]): Item | undefined;
|
|
20
40
|
/**
|
|
21
41
|
* Get the first item matching the filter
|
|
42
|
+
*
|
|
22
43
|
* @param array Array to search in
|
|
23
44
|
* @param filter Filter callback to match items
|
|
24
45
|
* @returns First item that matches the filter, or `undefined` if no match is found
|
|
46
|
+
*
|
|
47
|
+
* @example
|
|
48
|
+
* ```typescript
|
|
49
|
+
* find(
|
|
50
|
+
* [{id: 1, value: 10}, {id: 2, value: 20}, {id: 3, value: 10}],
|
|
51
|
+
* item => item.value === 10,
|
|
52
|
+
* ); // => {id: 1, value: 10}
|
|
53
|
+
* ```
|
|
25
54
|
*/
|
|
26
55
|
declare function find<Item>(array: Item[], filter: (item: Item, index: number, array: Item[]) => boolean): Item | undefined;
|
|
27
56
|
/**
|
|
28
57
|
* Get the first item matching the given value
|
|
58
|
+
*
|
|
29
59
|
* @param array Array to search in
|
|
30
60
|
* @param value Value to match against
|
|
31
61
|
* @returns First item that matches the value, or `undefined` if no match is found
|
|
62
|
+
*
|
|
63
|
+
* @example
|
|
64
|
+
* ```typescript
|
|
65
|
+
* find([1, 2, 3, 2, 1], 1); // => 1
|
|
66
|
+
* ```
|
|
32
67
|
*/
|
|
33
68
|
declare function find<Item>(array: Item[], value: Item): Item | undefined;
|
|
34
69
|
declare namespace find {
|
|
@@ -38,38 +73,73 @@ declare namespace find {
|
|
|
38
73
|
* Get the last item matching the given value
|
|
39
74
|
*
|
|
40
75
|
* Available as `findLast` and `find.last`
|
|
76
|
+
*
|
|
41
77
|
* @param array Array to search in
|
|
42
78
|
* @param callback Callback to get an item's value for matching
|
|
43
79
|
* @param value Value to match against
|
|
44
80
|
* @returns Last item that matches the value, or `undefined` if no match is found
|
|
81
|
+
*
|
|
82
|
+
* @example
|
|
83
|
+
* ```typescript
|
|
84
|
+
* findLast(
|
|
85
|
+
* [{id: 1, value: 10}, {id: 2, value: 20}, {id: 3, value: 10}],
|
|
86
|
+
* item => item.value,
|
|
87
|
+
* 10,
|
|
88
|
+
* ); // => {id: 3, value: 10}
|
|
89
|
+
* ```
|
|
45
90
|
*/
|
|
46
91
|
declare function findLast<Item, Callback extends (item: Item, index: number, array: Item[]) => unknown>(array: Item[], callback: Callback, value: ReturnType<Callback>): Item | undefined;
|
|
47
92
|
/**
|
|
48
93
|
* Get the last item matching the given value by key
|
|
49
94
|
*
|
|
50
95
|
* Available as `findLast` and `find.last`
|
|
96
|
+
*
|
|
51
97
|
* @param array Array to search in
|
|
52
98
|
* @param key Key to get an item's value for matching
|
|
53
99
|
* @param value Value to match against
|
|
54
100
|
* @returns Last item that matches the value, or `undefined` if no match is found
|
|
101
|
+
*
|
|
102
|
+
* @example
|
|
103
|
+
* ```typescript
|
|
104
|
+
* findLast(
|
|
105
|
+
* [{id: 1, value: 10}, {id: 2, value: 20}, {id: 3, value: 10}],
|
|
106
|
+
* 'value',
|
|
107
|
+
* 10,
|
|
108
|
+
* ); // => {id: 3, value: 10}
|
|
109
|
+
* ```
|
|
55
110
|
*/
|
|
56
111
|
declare function findLast<Item extends PlainObject, ItemKey extends keyof Item>(array: Item[], key: ItemKey, value: Item[ItemKey]): Item | undefined;
|
|
57
112
|
/**
|
|
58
113
|
* Get the last item matching the filter
|
|
59
114
|
*
|
|
60
115
|
* Available as `findLast` and `find.last`
|
|
116
|
+
*
|
|
61
117
|
* @param array Array to search in
|
|
62
118
|
* @param filter Filter callback to match items
|
|
63
119
|
* @returns Last item that matches the filter, or `undefined` if no match is found
|
|
120
|
+
*
|
|
121
|
+
* @example
|
|
122
|
+
* ```typescript
|
|
123
|
+
* findLast(
|
|
124
|
+
* [{id: 1, value: 10}, {id: 2, value: 20}, {id: 3, value: 10}],
|
|
125
|
+
* item => item.value === 10,
|
|
126
|
+
* ); // => {id: 3, value: 10}
|
|
127
|
+
* ```
|
|
64
128
|
*/
|
|
65
129
|
declare function findLast<Item>(array: Item[], filter: (item: Item, index: number, array: Item[]) => boolean): Item | undefined;
|
|
66
130
|
/**
|
|
67
131
|
* Get the last item matching the given value
|
|
68
132
|
*
|
|
69
133
|
* Available as `findLast` and `find.last`
|
|
134
|
+
*
|
|
70
135
|
* @param array Array to search in
|
|
71
136
|
* @param value Value to match against
|
|
72
137
|
* @returns Last item that matches the value, or `undefined` if no match is found
|
|
138
|
+
*
|
|
139
|
+
* @example
|
|
140
|
+
* ```typescript
|
|
141
|
+
* findLast([1, 2, 3, 2, 1], 1); // => 1
|
|
142
|
+
* ```
|
|
73
143
|
*/
|
|
74
144
|
declare function findLast<Item>(array: Item[], value: Item): Item | undefined;
|
|
75
145
|
//#endregion
|
package/dist/array/first.d.mts
CHANGED
|
@@ -3,31 +3,68 @@ import { PlainObject } from "../models.mjs";
|
|
|
3
3
|
//#region src/array/first.d.ts
|
|
4
4
|
/**
|
|
5
5
|
* Get the first item matching the given value
|
|
6
|
+
*
|
|
6
7
|
* @param array Array to search in
|
|
7
8
|
* @param callback Callback to get an item's value for matching
|
|
8
9
|
* @param value Value to match against
|
|
9
10
|
* @returns First item that matches the value, or `undefined` if no match is found
|
|
11
|
+
*
|
|
12
|
+
* @example
|
|
13
|
+
* ```typescript
|
|
14
|
+
* first(
|
|
15
|
+
* [{id: 1, value: 10}, {id: 2, value: 20}, {id: 3, value: 10}],
|
|
16
|
+
* item => item.value,
|
|
17
|
+
* 10,
|
|
18
|
+
* ); // => {id: 1, value: 10}
|
|
19
|
+
* ```
|
|
10
20
|
*/
|
|
11
21
|
declare function first<Item, Callback extends (item: Item, index: number, array: Item[]) => unknown>(array: Item[], callback: Callback, value: ReturnType<Callback>): Item | undefined;
|
|
12
22
|
/**
|
|
13
23
|
* Get the first item matching the given value by key
|
|
24
|
+
*
|
|
14
25
|
* @param array Array to search in
|
|
15
26
|
* @param key Key to get an item's value for matching
|
|
16
27
|
* @param value Value to match against
|
|
17
28
|
* @returns First item that matches the value, or `undefined` if no match is found
|
|
29
|
+
*
|
|
30
|
+
* @example
|
|
31
|
+
* ```typescript
|
|
32
|
+
* first(
|
|
33
|
+
* [{id: 1, value: 10}, {id: 2, value: 20}, {id: 3, value: 10}],
|
|
34
|
+
* 'value',
|
|
35
|
+
* 10,
|
|
36
|
+
* ); // => {id: 1, value: 10}
|
|
37
|
+
* ```
|
|
18
38
|
*/
|
|
19
39
|
declare function first<Item extends PlainObject, ItemKey extends keyof Item>(array: Item[], key: ItemKey, value: Item[ItemKey]): Item | undefined;
|
|
20
40
|
/**
|
|
21
41
|
* Get the first item matching the filter
|
|
42
|
+
*
|
|
22
43
|
* @param array Array to search in
|
|
23
44
|
* @param filter Filter callback to match items
|
|
24
45
|
* @returns First item that matches the filter, or `undefined` if no match is found
|
|
46
|
+
*
|
|
47
|
+
* @example
|
|
48
|
+
* ```typescript
|
|
49
|
+
* first(
|
|
50
|
+
* [{id: 1, value: 10}, {id: 2, value: 20}, {id: 3, value: 10}],
|
|
51
|
+
* item => item.value === 10,
|
|
52
|
+
* ); // => {id: 1, value: 10}
|
|
53
|
+
* ```
|
|
25
54
|
*/
|
|
26
55
|
declare function first<Item>(array: Item[], filter: (item: Item, index: number, array: Item[]) => boolean): Item | undefined;
|
|
27
56
|
/**
|
|
28
57
|
* Get the first item from an array
|
|
58
|
+
*
|
|
29
59
|
* @param array Array to get from
|
|
30
|
-
* @
|
|
60
|
+
* @returns First item from the array, or `undefined` if the array is empty
|
|
61
|
+
*
|
|
62
|
+
* @example
|
|
63
|
+
* ```typescript
|
|
64
|
+
* first(
|
|
65
|
+
* [{id: 1, value: 10}, {id: 2, value: 20}, {id: 3, value: 10}],
|
|
66
|
+
* ); // => {id: 1, value: 10}
|
|
67
|
+
* ```
|
|
31
68
|
*/
|
|
32
69
|
declare function first<Item>(array: Item[]): Item | undefined;
|
|
33
70
|
declare namespace first {
|
|
@@ -38,41 +75,79 @@ declare namespace first {
|
|
|
38
75
|
* Get the first item matching the given value, or a default value if no match is found
|
|
39
76
|
*
|
|
40
77
|
* Available as `firstOrDefault` and `first.default`
|
|
78
|
+
*
|
|
41
79
|
* @param array Array to search in
|
|
42
80
|
* @param defaultValue Default value to return if no match is found
|
|
43
81
|
* @param callback Callback to get an item's value for matching
|
|
44
82
|
* @param value Value to match against
|
|
45
83
|
* @returns First item that matches the value, or the default value if no match is found
|
|
84
|
+
*
|
|
85
|
+
* @example
|
|
86
|
+
* ```typescript
|
|
87
|
+
* firstOrDefault(
|
|
88
|
+
* [{id: 1, value: 10}, {id: 2, value: 20}, {id: 3, value: 10}],
|
|
89
|
+
* {id: -1, value: 30},
|
|
90
|
+
* item => item.value,
|
|
91
|
+
* 30,
|
|
92
|
+
* ); // => {id: -1, value: 30}
|
|
93
|
+
* ```
|
|
46
94
|
*/
|
|
47
95
|
declare function firstOrDefault<Item, Callback extends (item: Item, index: number, array: Item[]) => unknown>(array: Item[], defaultValue: Item, callback: Callback, value: ReturnType<Callback>): Item;
|
|
48
96
|
/**
|
|
49
97
|
* Get the first item matching the given value by key, or a default value if no match is found
|
|
50
98
|
*
|
|
51
99
|
* Available as `firstOrDefault` and `first.default`
|
|
100
|
+
*
|
|
52
101
|
* @param array Array to search in
|
|
53
102
|
* @param defaultValue Default value to return if no match is found
|
|
54
103
|
* @param key Key to get an item's value for matching
|
|
55
104
|
* @param value Value to match against
|
|
56
105
|
* @returns First item that matches the value, or the default value if no match is found
|
|
106
|
+
*
|
|
107
|
+
* @example
|
|
108
|
+
* ```typescript
|
|
109
|
+
* firstOrDefault(
|
|
110
|
+
* [{id: 1, value: 10}, {id: 2, value: 20}, {id: 3, value: 10}],
|
|
111
|
+
* {id: -1, value: 30},
|
|
112
|
+
* 'value',
|
|
113
|
+
* 30,
|
|
114
|
+
* ); // => {id: -1, value: 30}
|
|
115
|
+
* ```
|
|
57
116
|
*/
|
|
58
117
|
declare function firstOrDefault<Item extends PlainObject, ItemKey extends keyof Item>(array: Item[], defaultValue: Item, key: ItemKey, value: Item[ItemKey]): Item;
|
|
59
118
|
/**
|
|
60
119
|
* Get the first item matching the filter, or a default value if no match is found
|
|
61
120
|
*
|
|
62
121
|
* Available as `firstOrDefault` and `first.default`
|
|
122
|
+
*
|
|
63
123
|
* @param array Array to search in
|
|
64
124
|
* @param defaultValue Default value to return if no match is found
|
|
65
125
|
* @param filter Filter callback to match items
|
|
66
126
|
* @returns First item that matches the filter, or the default value if no match is found
|
|
127
|
+
*
|
|
128
|
+
* @example
|
|
129
|
+
* ```typescript
|
|
130
|
+
* firstOrDefault(
|
|
131
|
+
* [{id: 1, value: 10}, {id: 2, value: 20}, {id: 3, value: 10}],
|
|
132
|
+
* {id: -1, value: 30},
|
|
133
|
+
* item => item.value === 30,
|
|
134
|
+
* ); // => {id: -1, value: 30}
|
|
135
|
+
* ```
|
|
67
136
|
*/
|
|
68
137
|
declare function firstOrDefault<Item>(array: Item[], defaultValue: Item, filter: (item: Item, index: number, array: Item[]) => boolean): Item;
|
|
69
138
|
/**
|
|
70
139
|
* Get the first item from an array, or a default value if the array is empty
|
|
71
140
|
*
|
|
72
141
|
* Available as `firstOrDefault` and `first.default`
|
|
142
|
+
*
|
|
73
143
|
* @param array Array to get from
|
|
74
144
|
* @param defaultValue Default value to return if the array is empty
|
|
75
|
-
* @
|
|
145
|
+
* @returns First item from the array, or the default value if the array is empty
|
|
146
|
+
*
|
|
147
|
+
* @example
|
|
148
|
+
* ```typescript
|
|
149
|
+
* firstOrDefault([], {id: -1, value: 30}); // => {id: -1, value: 30}
|
|
150
|
+
* ```
|
|
76
151
|
*/
|
|
77
152
|
declare function firstOrDefault<Item>(array: Item[], defaultValue: Item): Item;
|
|
78
153
|
//#endregion
|
package/dist/array/flatten.d.mts
CHANGED
|
@@ -3,8 +3,14 @@ import { NestedArray } from "../models.mjs";
|
|
|
3
3
|
//#region src/array/flatten.d.ts
|
|
4
4
|
/**
|
|
5
5
|
* Flatten an array _(using native `flat` and maximum depth)_
|
|
6
|
+
*
|
|
6
7
|
* @param array Array to flatten
|
|
7
8
|
* @returns Flattened array
|
|
9
|
+
*
|
|
10
|
+
* @example
|
|
11
|
+
* ```typescript
|
|
12
|
+
* flatten([1, [2, [3, 4], 5], 6]); // => [1, 2, 3, 4, 5, 6]
|
|
13
|
+
* ```
|
|
8
14
|
*/
|
|
9
15
|
declare function flatten<Item>(array: Item[]): NestedArray<Item>[];
|
|
10
16
|
//#endregion
|
package/dist/array/flatten.mjs
CHANGED
|
@@ -1,8 +1,14 @@
|
|
|
1
1
|
//#region src/array/flatten.ts
|
|
2
2
|
/**
|
|
3
3
|
* Flatten an array _(using native `flat` and maximum depth)_
|
|
4
|
+
*
|
|
4
5
|
* @param array Array to flatten
|
|
5
6
|
* @returns Flattened array
|
|
7
|
+
*
|
|
8
|
+
* @example
|
|
9
|
+
* ```typescript
|
|
10
|
+
* flatten([1, [2, [3, 4], 5], 6]); // => [1, 2, 3, 4, 5, 6]
|
|
11
|
+
* ```
|
|
6
12
|
*/
|
|
7
13
|
function flatten(array) {
|
|
8
14
|
return Array.isArray(array) ? array.flat(Number.POSITIVE_INFINITY) : [];
|
package/dist/array/from.d.mts
CHANGED
|
@@ -1,43 +1,79 @@
|
|
|
1
1
|
//#region src/array/from.d.ts
|
|
2
2
|
/**
|
|
3
3
|
* Get an array with a specified length, filled with indices
|
|
4
|
+
*
|
|
4
5
|
* @param length Length of the array
|
|
5
6
|
* @returns Array of indices
|
|
7
|
+
*
|
|
8
|
+
* @example
|
|
9
|
+
* ```typescript
|
|
10
|
+
* range(5); // => [0, 1, 2, 3, 4]
|
|
11
|
+
* ```
|
|
6
12
|
*/
|
|
7
13
|
declare function range(length: number): number[];
|
|
8
14
|
/**
|
|
9
15
|
* Get an array of numbers in a specified range
|
|
16
|
+
*
|
|
10
17
|
* @param start Starting number _(inclusive)_
|
|
11
18
|
* @param end Ending number _(exclusive)_
|
|
12
19
|
* @returns Array of numbers in range
|
|
20
|
+
*
|
|
21
|
+
* @example
|
|
22
|
+
* ```typescript
|
|
23
|
+
* range(2, 5); // => [2, 3, 4]
|
|
24
|
+
* ```
|
|
13
25
|
*/
|
|
14
26
|
declare function range(start: number, end: number): number[];
|
|
15
27
|
/**
|
|
16
28
|
* Get an array of numbers in a specified range with a specified step
|
|
29
|
+
*
|
|
17
30
|
* @param start Starting number _(inclusive)_
|
|
18
31
|
* @param end Ending number _(exclusive)_
|
|
19
32
|
* @param step Step between numbers
|
|
20
33
|
* @returns Array of numbers in range
|
|
34
|
+
*
|
|
35
|
+
* @example
|
|
36
|
+
* ```typescript
|
|
37
|
+
* range(0, 10, 2); // => [0, 2, 4, 6, 8]
|
|
38
|
+
* ```
|
|
21
39
|
*/
|
|
22
40
|
declare function range(start: number, end: number, step: number): number[];
|
|
23
41
|
/**
|
|
24
42
|
* Get an array with a specified length, filled with indices
|
|
43
|
+
*
|
|
25
44
|
* @param length Length of the array
|
|
26
45
|
* @returns Array of indices
|
|
46
|
+
*
|
|
47
|
+
* @example
|
|
48
|
+
* ```typescript
|
|
49
|
+
* times(5); // => [0, 1, 2, 3, 4]
|
|
50
|
+
* ```
|
|
27
51
|
*/
|
|
28
52
|
declare function times(length: number): number[];
|
|
29
53
|
/**
|
|
30
54
|
* Get an array with a specified length, filled by values from a callback
|
|
55
|
+
*
|
|
31
56
|
* @param length Length of the array
|
|
32
57
|
* @param callback Callback function to generate values
|
|
33
58
|
* @returns Array of values generated by the callback
|
|
59
|
+
*
|
|
60
|
+
* @example
|
|
61
|
+
* ```typescript
|
|
62
|
+
* times(5, index => index * 2); // => [0, 2, 4, 6, 8]
|
|
63
|
+
* ```
|
|
34
64
|
*/
|
|
35
65
|
declare function times<Callback extends (index: number) => unknown>(length: number, callback: Callback): ReturnType<Callback>[];
|
|
36
66
|
/**
|
|
37
67
|
* Get an array with a specified length, filled with a specified value
|
|
68
|
+
*
|
|
38
69
|
* @param length Length of the array
|
|
39
70
|
* @param value Value to fill the array with
|
|
40
71
|
* @returns Array filled with the specified value
|
|
72
|
+
*
|
|
73
|
+
* @example
|
|
74
|
+
* ```typescript
|
|
75
|
+
* times(5, 'a'); // => ['a', 'a', 'a', 'a', 'a']
|
|
76
|
+
* ```
|
|
41
77
|
*/
|
|
42
78
|
declare function times<Value>(length: number, value: Value): Value[];
|
|
43
79
|
//#endregion
|