atomic-fns 0.4.2 → 0.4.3
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/README.md +0 -11
- package/dist/collections/deque.d.ts +1 -1
- package/dist/collections/deque.js +6 -8
- package/dist/collections/index.d.ts +207 -105
- package/dist/collections/index.js +179 -436
- package/dist/functools/index.d.ts +4 -4
- package/dist/functools/index.js +1 -1
- package/dist/globals/decimal.d.ts +142 -0
- package/dist/globals/decimal.js +371 -0
- package/dist/globals/index.d.ts +19 -15
- package/dist/globals/index.js +10 -24
- package/dist/i18n/currency.d.ts +24 -0
- package/dist/i18n/currency.js +85 -0
- package/dist/i18n/date/index.d.ts +9 -9
- package/dist/i18n/date/utils.d.ts +3 -3
- package/dist/i18n/date/utils.js +6 -28
- package/dist/i18n/format.d.ts +2 -2
- package/dist/i18n/format.js +1 -1
- package/dist/i18n/index.d.ts +1 -0
- package/dist/i18n/index.js +1 -0
- package/dist/itertools/index.d.ts +51 -23
- package/dist/itertools/index.js +4 -32
- package/dist/math/index.d.ts +6 -7
- package/dist/math/index.js +3 -1
- package/dist/operators/index.d.ts +2 -2
- package/dist/operators/index.js +0 -6
- package/dist/random/index.d.ts +1 -1
- package/dist/random/index.js +2 -2
- package/package.json +1 -1
|
@@ -4,41 +4,58 @@
|
|
|
4
4
|
* @module Collections
|
|
5
5
|
*/
|
|
6
6
|
import { Iteratee } from '../globals/index.js';
|
|
7
|
+
import { compare } from '../operators/index.js';
|
|
7
8
|
export * from './abc.js';
|
|
8
9
|
export * from './BTree.js';
|
|
9
10
|
export * from './deque.js';
|
|
10
11
|
export * from './frozenset.js';
|
|
11
12
|
export * from './Heap.js';
|
|
12
13
|
export * from './LRUCache.js';
|
|
13
|
-
export * from './SortedSet.js';
|
|
14
14
|
export * from './SortedMap.js';
|
|
15
|
+
export * from './SortedSet.js';
|
|
15
16
|
export * from './SortedTree.js';
|
|
16
17
|
export * from './SplayTree.js';
|
|
17
18
|
/**
|
|
18
19
|
* Creates a new array with all falsy and empty values removed.
|
|
19
20
|
* @param arr The array to compact
|
|
20
|
-
* @returns A new array with the filtered values.
|
|
21
21
|
* @example
|
|
22
22
|
```js
|
|
23
23
|
compact([0, 1, false, 2, '', 3])
|
|
24
|
-
//
|
|
24
|
+
// [1, 2, 3]
|
|
25
25
|
```
|
|
26
|
+
* @returns A new array with the filtered values
|
|
26
27
|
*/
|
|
27
|
-
export declare function compact(arr:
|
|
28
|
-
export declare function compact(arr:
|
|
29
|
-
|
|
28
|
+
export declare function compact<T>(arr: T[]): T[];
|
|
29
|
+
export declare function compact<T>(arr: T): Partial<T>;
|
|
30
|
+
/**
|
|
31
|
+
* Creates an object composed of keys from the results of running elements of `collection` thru `iteratee`. The corresponding value of each key is the number of times the key was returned by `iteratee`.
|
|
32
|
+
* @param iterable
|
|
33
|
+
* @param func
|
|
34
|
+
* @returns {Object} Returns an Object with the frequency values
|
|
35
|
+
* @example
|
|
36
|
+
```js
|
|
37
|
+
count([6.1, 4.2, 6.3], Math.floor);
|
|
38
|
+
// { '4': 1, '6': 2 }
|
|
39
|
+
|
|
40
|
+
// property iteratee shorthand.
|
|
41
|
+
count(['one', 'two', 'three'], x => x.length);
|
|
42
|
+
// { '3': 2, '5': 1 }
|
|
43
|
+
```
|
|
44
|
+
*/
|
|
45
|
+
export declare function count<T>(obj: T[], fn: Iteratee<T>): Record<string, number>;
|
|
46
|
+
export declare function count<T>(obj: Object, fn: Iteratee<T>): Record<string, number>;
|
|
30
47
|
/**
|
|
31
48
|
* Creates a function that can be used to create named tuple-like objects.
|
|
32
49
|
* @example
|
|
33
50
|
```js
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
51
|
+
let Point = namedtuple('x', 'y', 'z')
|
|
52
|
+
let userObj = User(0, 0, 0)
|
|
53
|
+
// {x: 0, y: 0, z: 0}
|
|
37
54
|
```
|
|
38
55
|
* @param fields - A list of field names
|
|
39
56
|
* @returns A function that can be called with the field values
|
|
40
57
|
*/
|
|
41
|
-
export declare
|
|
58
|
+
export declare const namedtuple: (...fields: string[]) => (...args: any[]) => any;
|
|
42
59
|
/**
|
|
43
60
|
* Iterates over elements of collection, returning an array of all elements where predicate returns truthy value.
|
|
44
61
|
*
|
|
@@ -46,67 +63,62 @@ export declare function namedtuple(...fields: string[]): (...args: any[]) => any
|
|
|
46
63
|
*
|
|
47
64
|
* @example
|
|
48
65
|
```js
|
|
49
|
-
|
|
66
|
+
let users = [
|
|
50
67
|
{ 'user': 'barney', 'age': 36, 'active': true },
|
|
51
68
|
{ 'user': 'fred', 'age': 40, 'active': false }
|
|
52
69
|
]
|
|
53
70
|
|
|
54
71
|
filter(users, o => !o.active)
|
|
55
|
-
//
|
|
72
|
+
// objects for ['fred']
|
|
56
73
|
|
|
57
74
|
// The shape iteratee shorthand.
|
|
58
75
|
filter(users, { age: 36, active: true })
|
|
59
|
-
//
|
|
76
|
+
// objects for ['barney']
|
|
60
77
|
|
|
61
78
|
// The property iteratee shorthand.
|
|
62
79
|
filter(users, 'active')
|
|
63
|
-
//
|
|
80
|
+
// objects for ['barney']
|
|
64
81
|
```
|
|
65
82
|
* @param {Array} arr The collection to iterate over
|
|
66
83
|
* @param {Function} fn The predicate function invoked for each item
|
|
67
84
|
* @returns {Array} The new filtered array
|
|
68
85
|
*/
|
|
69
|
-
export declare function filter(arr:
|
|
86
|
+
export declare function filter<T>(arr: T[], fn?: Iteratee<T>): T[];
|
|
87
|
+
export declare function filter<T>(arr: T[], fn?: Object): T[];
|
|
88
|
+
export declare function filter<T>(arr: Object, fn?: Iteratee<T>): T[];
|
|
89
|
+
export declare function filter<T>(arr: Object, fn?: Object): T[];
|
|
70
90
|
/**
|
|
71
91
|
* Iterates over elements of collection, returning the first element where predicate returns truthy value. The predicate is invoked with three arguments: `(value, index|key, collection)`.
|
|
72
92
|
* @example
|
|
73
93
|
```js
|
|
74
|
-
|
|
94
|
+
let users = [
|
|
75
95
|
{ 'user': 'barney', 'age': 36, 'active': true },
|
|
76
96
|
{ 'user': 'fred', 'age': 40, 'active': false },
|
|
77
97
|
{ 'user': 'pebbles', 'age': 1, 'active': true }
|
|
78
98
|
]
|
|
79
99
|
|
|
80
100
|
find(users, (o) => o.age < 40)
|
|
81
|
-
//
|
|
101
|
+
// object for 'barney'
|
|
82
102
|
|
|
83
103
|
// The shape iteratee shorthand.
|
|
84
104
|
find(users, { 'age': 1, 'active': true })
|
|
85
|
-
//
|
|
105
|
+
// object for 'pebbles'
|
|
86
106
|
|
|
87
107
|
// The `property` iteratee shorthand.
|
|
88
108
|
find(users, 'active')
|
|
89
|
-
//
|
|
90
|
-
```
|
|
91
|
-
* @param {Array} arr The collection to iterate over.
|
|
92
|
-
* @param {Function} fn The function invoked per iteration.
|
|
93
|
-
* @returns {*} The matched element, else `undefined`.
|
|
94
|
-
* @see {@link findRight}
|
|
95
|
-
*/
|
|
96
|
-
export declare function find(arr: any, fn: Iteratee | PropertyKey | Object): any;
|
|
97
|
-
/**
|
|
98
|
-
* This method is like {@link find} except that it iterates from right to left.
|
|
99
|
-
* @example
|
|
100
|
-
```js
|
|
101
|
-
findRight([1, 2, 3, 4], (n) => n % 2 === 1)
|
|
102
|
-
// => 3
|
|
109
|
+
// object for 'barney'
|
|
103
110
|
```
|
|
104
111
|
* @param {Array} arr The collection to iterate over.
|
|
105
112
|
* @param {Function} fn The function invoked per iteration.
|
|
106
113
|
* @returns {*} The matched element, else `undefined`.
|
|
107
|
-
* @see {@link
|
|
114
|
+
* @see {@link findLast}
|
|
108
115
|
*/
|
|
109
|
-
export declare function
|
|
116
|
+
export declare function find<T>(arr: T[], fn: Iteratee<T>): T | undefined;
|
|
117
|
+
export declare function find<T>(arr: T[], fn: Object): T | undefined;
|
|
118
|
+
export declare function find<T>(arr: T[], fn: PropertyKey): T | undefined;
|
|
119
|
+
export declare function find<T>(arr: Object, fn: Iteratee<T>): T | undefined;
|
|
120
|
+
export declare function find<T>(arr: Object, fn: Object): T | undefined;
|
|
121
|
+
export declare function find<T>(arr: Object, fn: PropertyKey): T | undefined;
|
|
110
122
|
/**
|
|
111
123
|
* Performs an efficient array insert operation in the given array. If the index or the array is invalid, it just returns the given array.
|
|
112
124
|
*
|
|
@@ -117,7 +129,7 @@ export declare function findRight(arr: any, fn: Iteratee | PropertyKey | Object)
|
|
|
117
129
|
* @param {*} value The value to insert in the array at the given `index`.
|
|
118
130
|
* @returns {Array<*>} The given array.
|
|
119
131
|
*/
|
|
120
|
-
export declare function insert(arr:
|
|
132
|
+
export declare function insert<T>(arr: T[], index: number, value: T): T[];
|
|
121
133
|
/**
|
|
122
134
|
* Creates a function that performs a partial deep comparison between a given object and `shape`, returning `true` if the given object has equivalent property values, else `false`.
|
|
123
135
|
* @example
|
|
@@ -128,7 +140,7 @@ let objects = [
|
|
|
128
140
|
]
|
|
129
141
|
|
|
130
142
|
filter(objects, matches({ a: 4, c: 6 }))
|
|
131
|
-
//
|
|
143
|
+
// [{ a: 4, b: 5, c: 6 }]
|
|
132
144
|
```
|
|
133
145
|
* @param shape
|
|
134
146
|
* @returns
|
|
@@ -141,12 +153,12 @@ export declare const matches: (shape: any) => (obj: any) => boolean;
|
|
|
141
153
|
forEach([1, 2], (value) => {
|
|
142
154
|
console.log(value)
|
|
143
155
|
})
|
|
144
|
-
//
|
|
156
|
+
// Logs `1` then `2`.
|
|
145
157
|
|
|
146
158
|
forEach({ 'a': 1, 'b': 2 }, (value, key) => {
|
|
147
159
|
console.log(key)
|
|
148
160
|
})
|
|
149
|
-
//
|
|
161
|
+
// Logs 'a' then 'b' (iteration order is not guaranteed).
|
|
150
162
|
```
|
|
151
163
|
* @param {Array|Object} collection The collection to iterate over.
|
|
152
164
|
* @param {Iteratee} fn The function invoked per iteration.
|
|
@@ -155,9 +167,24 @@ forEach({ 'a': 1, 'b': 2 }, (value, key) => {
|
|
|
155
167
|
* @see {@link filter}
|
|
156
168
|
* @see {@link map}
|
|
157
169
|
*/
|
|
158
|
-
export declare function forEach<T>(collection: T
|
|
159
|
-
export declare function forEach<T>(collection:
|
|
160
|
-
|
|
170
|
+
export declare function forEach<T>(collection: Iterable<T>, fn: Iteratee<T>): void;
|
|
171
|
+
export declare function forEach<T>(collection: Object, fn: Iteratee<T>): void;
|
|
172
|
+
/**
|
|
173
|
+
* This method is like {@link find} except that it iterates from right to left.
|
|
174
|
+
* @example
|
|
175
|
+
```js
|
|
176
|
+
findLast([1, 2, 3, 4], (n) => n % 2 === 1)
|
|
177
|
+
// => 3
|
|
178
|
+
```
|
|
179
|
+
* @param {Array} arr The collection to iterate over.
|
|
180
|
+
* @param {Function} fn The function invoked per iteration.
|
|
181
|
+
* @returns {*} The matched element, else `undefined`.
|
|
182
|
+
* @see {@link find}
|
|
183
|
+
*/
|
|
184
|
+
export declare function findLast<T>(arr: Iterable<T>, fn: Iteratee<T>): T | undefined;
|
|
185
|
+
export declare function findLast<T>(arr: Iterable<T>, fn: Object): T | undefined;
|
|
186
|
+
export declare function findLast<T>(arr: Object, fn: Iteratee<T>): T | undefined;
|
|
187
|
+
export declare function findLast<T>(arr: Object, fn: Object): T | undefined;
|
|
161
188
|
/**
|
|
162
189
|
* This method is like {@link forEach} except that it iterates over the collection from right to left.
|
|
163
190
|
|
|
@@ -166,7 +193,7 @@ export declare function forEach<T>(collection: Object, fn: Iteratee<T>): any;
|
|
|
166
193
|
forEachRight([1, 2], (value) => {
|
|
167
194
|
console.log(value)
|
|
168
195
|
})
|
|
169
|
-
//
|
|
196
|
+
// Logs `2` then `1`.
|
|
170
197
|
```
|
|
171
198
|
* @param {Array|Object} collection The collection to iterate over.
|
|
172
199
|
* @param {Iteratee} fn The function invoked per iteration.
|
|
@@ -175,13 +202,14 @@ forEachRight([1, 2], (value) => {
|
|
|
175
202
|
* @see {@link filter}
|
|
176
203
|
* @see {@link map}
|
|
177
204
|
*/
|
|
178
|
-
export declare function forEachRight(collection:
|
|
205
|
+
export declare function forEachRight<T>(collection: T[], fn: Iteratee<T>): void;
|
|
206
|
+
export declare function forEachRight<T>(collection: Object, fn: Iteratee<T>): void;
|
|
179
207
|
/**
|
|
180
208
|
* Flattens an array or object. Arrays will be flattened recursively up to `depth` times. Objects will be flattened recursively.
|
|
181
209
|
* @example
|
|
182
210
|
```js
|
|
183
211
|
flatten([1, [2, [3, [4]], 5]])
|
|
184
|
-
//
|
|
212
|
+
// [1, 2, [3, [4]], 5]
|
|
185
213
|
|
|
186
214
|
flatten({
|
|
187
215
|
dates: {
|
|
@@ -199,7 +227,7 @@ flatten({
|
|
|
199
227
|
value: 1500
|
|
200
228
|
}
|
|
201
229
|
})
|
|
202
|
-
//
|
|
230
|
+
// {
|
|
203
231
|
'dates.expiry_date': '30 sep 2018',
|
|
204
232
|
'dates.available': '30 sep 2017',
|
|
205
233
|
'dates.min_contract_period[0].id': 1,
|
|
@@ -213,7 +241,8 @@ flatten({
|
|
|
213
241
|
* @returns {*} The new flattened array or object.
|
|
214
242
|
* @see {@link https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/flat Array.flat()}
|
|
215
243
|
*/
|
|
216
|
-
export declare function flatten(arr:
|
|
244
|
+
export declare function flatten<T>(arr: T[], depth?: boolean | number): T[];
|
|
245
|
+
export declare function flatten<T>(arr: Object, depth?: boolean | number): Object;
|
|
217
246
|
/**
|
|
218
247
|
* Creates an array of values by running each element in collection thru iteratee. The iteratee is invoked with three arguments: `(value, index|key, collection)`.
|
|
219
248
|
* @example
|
|
@@ -223,10 +252,10 @@ function square(n) {
|
|
|
223
252
|
}
|
|
224
253
|
|
|
225
254
|
map([4, 8], square)
|
|
226
|
-
//
|
|
255
|
+
// [16, 64]
|
|
227
256
|
|
|
228
257
|
map({ a: 4, b: 8 }, square)
|
|
229
|
-
//
|
|
258
|
+
// [16, 64] (iteration order is not guaranteed)
|
|
230
259
|
|
|
231
260
|
let users = [
|
|
232
261
|
{ user: 'barney' },
|
|
@@ -235,14 +264,17 @@ let users = [
|
|
|
235
264
|
|
|
236
265
|
// The `property` iteratee shorthand.
|
|
237
266
|
map(users, 'user')
|
|
238
|
-
//
|
|
267
|
+
// ['barney', 'fred']
|
|
239
268
|
```
|
|
240
269
|
* @param {Array|Object} arr The collection to iterate over.
|
|
241
|
-
* @param {Iteratee
|
|
270
|
+
* @param {Iteratee} fn The function invoked per iteration.
|
|
242
271
|
* @returns Returns the new mapped array.
|
|
243
272
|
* @see {@link https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/map Array.map()}
|
|
244
273
|
*/
|
|
245
|
-
export declare function map(arr:
|
|
274
|
+
export declare function map<T, TResult>(arr: T[], fn: Iteratee<T, PropertyKey, TResult>): TResult[];
|
|
275
|
+
export declare function map<T, TResult>(arr: T[], fn: PropertyKey): TResult[];
|
|
276
|
+
export declare function map<T, TResult>(arr: Object, fn: Iteratee<T, PropertyKey, TResult>): TResult[];
|
|
277
|
+
export declare function map<T, TResult>(arr: Object, fn: PropertyKey): TResult[];
|
|
246
278
|
/**
|
|
247
279
|
* Creates an object composed of the picked object properties.
|
|
248
280
|
* @param {Object} obj The source object.
|
|
@@ -253,15 +285,16 @@ export declare function map(arr: any, fn: Iteratee | PropertyKey): any[];
|
|
|
253
285
|
let object = { a: 1, b: '2', c: 3 }
|
|
254
286
|
|
|
255
287
|
pick(object, ['a', 'c'])
|
|
256
|
-
//
|
|
288
|
+
// { a: 1, c: 3 }
|
|
257
289
|
|
|
258
290
|
pick(object, (x) => isNumber(x))
|
|
259
|
-
//
|
|
291
|
+
// { a: 1, c: 3 }
|
|
260
292
|
```
|
|
261
293
|
*
|
|
262
294
|
* @see {@link omit}
|
|
263
295
|
*/
|
|
264
|
-
export declare function pick(obj:
|
|
296
|
+
export declare function pick<T>(obj: T, paths: Iteratee): Partial<T>;
|
|
297
|
+
export declare function pick<T>(obj: T, paths: PropertyKey[]): Partial<T>;
|
|
265
298
|
/**
|
|
266
299
|
* The opposite of {@link pick} - this method creates an object composed of the own and inherited enumerable property paths of `object` that are not omitted.
|
|
267
300
|
* @example
|
|
@@ -269,17 +302,18 @@ export declare function pick(obj: Object, paths: Iteratee | PropertyKey[]): {};
|
|
|
269
302
|
let object = { 'a': 1, 'b': '2', 'c': 3 }
|
|
270
303
|
|
|
271
304
|
omit(object, ['a', 'c'])
|
|
272
|
-
//
|
|
305
|
+
// { 'b': '2' }
|
|
273
306
|
|
|
274
307
|
omit(object, (x) => isNumber(x))
|
|
275
|
-
//
|
|
308
|
+
// { 'b': '2' }
|
|
276
309
|
```
|
|
277
310
|
* @param {Object} obj The source object.
|
|
278
311
|
* @param {Iteratee|PropertyKey[]} paths The property paths to omit.
|
|
279
312
|
* @returns {Object} Returns the new object.
|
|
280
313
|
* @see {@link pick}
|
|
281
314
|
*/
|
|
282
|
-
export declare function omit(obj:
|
|
315
|
+
export declare function omit<T>(obj: T, paths: Iteratee): Partial<T>;
|
|
316
|
+
export declare function omit<T>(obj: T, paths: PropertyKey[]): Partial<T>;
|
|
283
317
|
/**
|
|
284
318
|
* This method is like {@link find} except that it returns the index of the first element `predicate` returns truthy for instead of the element itself.
|
|
285
319
|
* @param {Array} obj The array to inspect.
|
|
@@ -294,24 +328,26 @@ let users = [
|
|
|
294
328
|
{ 'user': 'pebbles', 'active': true }
|
|
295
329
|
]
|
|
296
330
|
|
|
297
|
-
|
|
298
|
-
//
|
|
331
|
+
findIndex(users, (o) => o.user == 'barney')
|
|
332
|
+
// 0
|
|
299
333
|
|
|
300
334
|
// The `shape` iteratee shorthand.
|
|
301
|
-
|
|
302
|
-
//
|
|
335
|
+
findIndex(users, { 'user': 'fred', 'active': false })
|
|
336
|
+
// 1
|
|
303
337
|
|
|
304
338
|
// The `property` iteratee shorthand.
|
|
305
|
-
|
|
306
|
-
//
|
|
339
|
+
findIndex(users, 'active')
|
|
340
|
+
// 2
|
|
307
341
|
```
|
|
308
342
|
* @see {@link indexOf}
|
|
309
|
-
* @see {@link
|
|
343
|
+
* @see {@link findLastIndex}
|
|
310
344
|
*
|
|
311
345
|
*/
|
|
312
|
-
export declare function
|
|
346
|
+
export declare function findIndex<T>(obj: T[], fn: Iteratee<T>, start?: number): number;
|
|
347
|
+
export declare function findIndex<T>(obj: T[], fn: Object, start?: number): number;
|
|
348
|
+
export declare function findIndex<T>(obj: T[], fn: PropertyKey, start?: number): number;
|
|
313
349
|
/**
|
|
314
|
-
* This method is like {@link
|
|
350
|
+
* This method is like {@link findIndex} except that it searches for a given value directly, instead of using a predicate function.
|
|
315
351
|
* @param {Array} obj The array to inspect.
|
|
316
352
|
* @param {*} value The value to find
|
|
317
353
|
* @param {number} [start=0] The index to search from.
|
|
@@ -319,19 +355,19 @@ export declare function index(obj: any, fn: Iteratee | string | Object, start?:
|
|
|
319
355
|
* @example
|
|
320
356
|
```js
|
|
321
357
|
indexOf([1, 2, 1, 2], 2)
|
|
322
|
-
//
|
|
358
|
+
// 1
|
|
323
359
|
|
|
324
360
|
// Search from a `start` index.
|
|
325
361
|
indexOf([1, 2, 1, 2], 2, 2)
|
|
326
|
-
//
|
|
362
|
+
// 3
|
|
327
363
|
```
|
|
328
|
-
* @see {@link
|
|
364
|
+
* @see {@link findIndex}
|
|
329
365
|
* @see {@link lastIndexOf}
|
|
330
366
|
*/
|
|
331
|
-
export declare function indexOf(obj:
|
|
367
|
+
export declare function indexOf<T>(obj: T[], value: T, start?: number): number;
|
|
332
368
|
/**
|
|
333
|
-
* This method is like {@link
|
|
334
|
-
* @param {Array}
|
|
369
|
+
* This method is like {@link findIndex} except that it iterates the collection from right to left.
|
|
370
|
+
* @param {Array} arr The array to inspect.
|
|
335
371
|
* @param {string|Iteratee|Object} fn The function invoked per iteration.
|
|
336
372
|
* @param {number} [start] The index to search from.
|
|
337
373
|
* @returns {number} The index of the found value, else -1
|
|
@@ -344,20 +380,22 @@ let users = [
|
|
|
344
380
|
]
|
|
345
381
|
|
|
346
382
|
findLastIndex(users, (o) => o.user == 'pebbles')
|
|
347
|
-
//
|
|
383
|
+
// 2
|
|
348
384
|
|
|
349
385
|
// The `shape` iteratee shorthand.
|
|
350
386
|
findLastIndex(users, { 'user': 'barney', 'active': true })
|
|
351
|
-
//
|
|
387
|
+
// 0
|
|
352
388
|
|
|
353
389
|
// The `property` iteratee shorthand.
|
|
354
390
|
findLastIndex(users, 'active')
|
|
355
|
-
//
|
|
391
|
+
// 0
|
|
356
392
|
```
|
|
357
|
-
* @see {@link
|
|
393
|
+
* @see {@link findIndex}
|
|
358
394
|
* @see {@link lastIndexOf}
|
|
359
395
|
*/
|
|
360
|
-
export declare function
|
|
396
|
+
export declare function findLastIndex<T>(arr: T[], fn: Iteratee<T>, start?: number): number;
|
|
397
|
+
export declare function findLastIndex<T>(arr: T[], fn: Object, start?: number): number;
|
|
398
|
+
export declare function findLastIndex<T>(arr: T[], fn: PropertyKey, start?: number): number;
|
|
361
399
|
/**
|
|
362
400
|
* This method is like {@link indexOf} except that it iterates the collection from right to left.
|
|
363
401
|
* @param {Array} obj The array to inspect.
|
|
@@ -367,16 +405,16 @@ export declare function lastIndex(obj: any[], fn: string | Iteratee | Object, st
|
|
|
367
405
|
* @example
|
|
368
406
|
```js
|
|
369
407
|
lastIndexOf([1, 2, 1, 2], 2)
|
|
370
|
-
//
|
|
408
|
+
// 3
|
|
371
409
|
|
|
372
410
|
// Search from the `fromIndex`.
|
|
373
411
|
lastIndexOf([1, 2, 1, 2], 2, 2)
|
|
374
|
-
//
|
|
412
|
+
// 1
|
|
375
413
|
```
|
|
376
|
-
* @see {@link
|
|
414
|
+
* @see {@link findLastIndex}
|
|
377
415
|
* @see {@link indexOf}
|
|
378
416
|
*/
|
|
379
|
-
export declare function lastIndexOf(obj:
|
|
417
|
+
export declare function lastIndexOf<T>(obj: T[], value: T, start?: number): number;
|
|
380
418
|
/**
|
|
381
419
|
* Creates a shallow clone of `value`. If `deep` is `true` it will clone it recursively.
|
|
382
420
|
* @param {*} value
|
|
@@ -385,7 +423,8 @@ export declare function lastIndexOf(obj: any[], value: any, start?: any): any;
|
|
|
385
423
|
* @see {@link cloneArray}
|
|
386
424
|
* @see {@link cloneTypedArray}
|
|
387
425
|
*/
|
|
388
|
-
export declare function clone(value:
|
|
426
|
+
export declare function clone<T>(value: T, deep?: boolean): T;
|
|
427
|
+
export declare function clone<T>(value: T[], deep?: boolean): T[];
|
|
389
428
|
/**
|
|
390
429
|
* Clones an array. If `deep` is `false` (default) the clone will be shallow. Otherwise {@link https://developer.mozilla.org/en-US/docs/Web/API/structuredClone structuredClone} is used.
|
|
391
430
|
* @param arr The array to clone
|
|
@@ -393,7 +432,7 @@ export declare function clone(value: any, deep?: boolean): any;
|
|
|
393
432
|
* @returns The new array
|
|
394
433
|
* @see {@link clone}
|
|
395
434
|
*/
|
|
396
|
-
export declare function cloneArray(arr:
|
|
435
|
+
export declare function cloneArray<T>(arr: T[], deep?: boolean): T[];
|
|
397
436
|
/**
|
|
398
437
|
* Clones a typed array. If `deep` is `false` (default) the clone will be shallow. Otherwise {@link https://developer.mozilla.org/en-US/docs/Web/API/structuredClone structuredClone} is used.
|
|
399
438
|
* @param arr The array to clone
|
|
@@ -401,7 +440,7 @@ export declare function cloneArray(arr: any, deep?: boolean): any;
|
|
|
401
440
|
* @returns The new array
|
|
402
441
|
* @see {@link clone}
|
|
403
442
|
*/
|
|
404
|
-
export declare function cloneTypedArray(typedArray: any, isDeep
|
|
443
|
+
export declare function cloneTypedArray(typedArray: any, isDeep?: boolean): any;
|
|
405
444
|
/**
|
|
406
445
|
* Creates a duplicate-free version of an array, using a `Set` for equality comparisons, in which only the first occurrence of each element is kept. The order of result values is not guaranteed.
|
|
407
446
|
* @param arr The array containing duplicated elements
|
|
@@ -410,15 +449,16 @@ export declare function cloneTypedArray(typedArray: any, isDeep: any): any;
|
|
|
410
449
|
* @example
|
|
411
450
|
```js
|
|
412
451
|
uniq([2, 1, 2])
|
|
413
|
-
//
|
|
452
|
+
// [2, 1]
|
|
414
453
|
|
|
415
454
|
uniq([2.1, 1.2, 2.3], Math.floor)
|
|
416
|
-
//
|
|
455
|
+
// [2.1, 1.2]
|
|
417
456
|
```
|
|
418
457
|
*
|
|
419
458
|
* @see {@link sortedUniq}
|
|
420
459
|
*/
|
|
421
|
-
export declare function uniq<T
|
|
460
|
+
export declare function uniq<T>(arr: Iterable<T>, fn?: Iteratee<T>): T[];
|
|
461
|
+
export declare function uniq<T>(arr: Iterable<T>, fn?: PropertyKey): T[];
|
|
422
462
|
/**
|
|
423
463
|
* This method is like {@link uniq} except that it sorts the results in ascending order
|
|
424
464
|
* @param arr The array containing duplicated elements
|
|
@@ -427,11 +467,12 @@ export declare function uniq<T = any>(arr: T[], fn?: PropertyKey | Iteratee): T[
|
|
|
427
467
|
* @example
|
|
428
468
|
```js
|
|
429
469
|
uniq([2, 1, 2])
|
|
430
|
-
//
|
|
470
|
+
// [1, 2]
|
|
431
471
|
```
|
|
432
472
|
* @see {@link uniq}
|
|
433
473
|
*/
|
|
434
|
-
export declare function sortedUniq(arr:
|
|
474
|
+
export declare function sortedUniq<T>(arr: Iterable<T>, fn?: Iteratee<T>): T[];
|
|
475
|
+
export declare function sortedUniq<T>(arr: Iterable<T>, fn?: PropertyKey): T[];
|
|
435
476
|
/**
|
|
436
477
|
* Recursively merges own and inherited enumerable string keyed properties of source objects into the destination object. Source properties that resolve to `undefined` are skipped if a destination value exists. Array and plain object properties are merged recursively. Other objects and value types are overridden by assignment. Source objects are applied from left to right. Subsequent sources overwrite property assignments of previous sources.
|
|
437
478
|
*
|
|
@@ -453,10 +494,10 @@ let other = {
|
|
|
453
494
|
}
|
|
454
495
|
|
|
455
496
|
merge(object, other)
|
|
456
|
-
//
|
|
497
|
+
// { 'a': [{ 'b': 2, 'c': 3 }, { 'd': 4, 'e': 5 }] }
|
|
457
498
|
```
|
|
458
499
|
*/
|
|
459
|
-
export declare function merge(object:
|
|
500
|
+
export declare function merge(object: Object, ...sources: Object[]): Object;
|
|
460
501
|
/**
|
|
461
502
|
* Assigns own and inherited enumerable string keyed properties of source objects to the destination object for all destination properties that resolve to `undefined`. Source objects are applied from left to right. Once a property is set, additional values of the same property are ignored.
|
|
462
503
|
* **Note:** This method mutates `object`.
|
|
@@ -467,7 +508,7 @@ export declare function merge(object: any, ...sources: any[]): Object;
|
|
|
467
508
|
* @example
|
|
468
509
|
```js
|
|
469
510
|
defaults({ 'a': 1 }, { 'b': 2 }, { 'a': 3 })
|
|
470
|
-
//
|
|
511
|
+
// { 'a': 1, 'b': 2 }
|
|
471
512
|
```
|
|
472
513
|
*/
|
|
473
514
|
export declare function defaults(object: Object, ...sources: Object[]): Object;
|
|
@@ -477,36 +518,36 @@ export declare function defaults(object: Object, ...sources: Object[]): Object;
|
|
|
477
518
|
* @example
|
|
478
519
|
```js
|
|
479
520
|
[...difference([2, 1], [2, 3])]
|
|
480
|
-
//
|
|
521
|
+
// [1]
|
|
481
522
|
```
|
|
482
523
|
* @see {@link union}
|
|
483
524
|
* @see {@link intersection}
|
|
484
525
|
*/
|
|
485
|
-
export declare function difference(...args: Array<Iterable<
|
|
526
|
+
export declare function difference<T>(...args: Array<Iterable<T>>): Generator<T, void, unknown>;
|
|
486
527
|
/**
|
|
487
528
|
* Creates a generator of unique values that are included in all given arrays.
|
|
488
529
|
* @param args The arrays to inspect
|
|
489
530
|
* @example
|
|
490
531
|
```js
|
|
491
532
|
[...intersection([2, 1], [2, 3])]
|
|
492
|
-
//
|
|
533
|
+
// [2]
|
|
493
534
|
```
|
|
494
535
|
* @see {@link difference}
|
|
495
536
|
* @see {@link union}
|
|
496
537
|
*/
|
|
497
|
-
export declare function intersection(...args: Array<Iterable<
|
|
538
|
+
export declare function intersection<T>(...args: Array<Iterable<T>>): Generator<T, void, unknown>;
|
|
498
539
|
/**
|
|
499
540
|
* Creates a generator of unique values from all given arrays using `Set` for equality comparisons.
|
|
500
541
|
* @param args The arrays to perform union on.
|
|
501
542
|
* @example
|
|
502
543
|
```js
|
|
503
544
|
[...union([2], [1, 2])]
|
|
504
|
-
//
|
|
545
|
+
// [2, 1]
|
|
505
546
|
```
|
|
506
547
|
* @see {@link difference}
|
|
507
548
|
* @see {@link intersection}
|
|
508
549
|
*/
|
|
509
|
-
export declare function union(...args: Array<Iterable<
|
|
550
|
+
export declare function union<T>(...args: Array<Iterable<T>>): Generator<T, void, unknown>;
|
|
510
551
|
/**
|
|
511
552
|
* Creates an object composed of keys generated from the results of running each element of `arr` thru `func`. The order of grouped values is determined by the order they occur in `arr`. The corresponding value of each key is an array of elements responsible for generating the key.
|
|
512
553
|
*
|
|
@@ -517,14 +558,17 @@ export declare function union(...args: Array<Iterable<any>>): Generator<unknown,
|
|
|
517
558
|
* @example
|
|
518
559
|
```js
|
|
519
560
|
groupBy([6.1, 4.2, 6.3], Math.floor)
|
|
520
|
-
//
|
|
561
|
+
// { '4': [4.2], '6': [6.1, 6.3] }
|
|
521
562
|
|
|
522
563
|
// The `property` iteratee shorthand.
|
|
523
564
|
groupBy(['one', 'two', 'three'], 'length')
|
|
524
|
-
//
|
|
565
|
+
// { '3': ['one', 'two'], '5': ['three'] }
|
|
525
566
|
```
|
|
526
567
|
*/
|
|
527
|
-
export declare function groupBy(arr: Iterable<
|
|
568
|
+
export declare function groupBy<T>(arr: Iterable<T>, fn: Iteratee<T>): Record<PropertyKey, T[]>;
|
|
569
|
+
export declare function groupBy<T>(arr: Iterable<T>, fn: PropertyKey): Record<PropertyKey, T[]>;
|
|
570
|
+
export declare function groupBy<T>(arr: Object, fn: Iteratee<T>): Record<PropertyKey, T[]>;
|
|
571
|
+
export declare function groupBy<T>(arr: Object, fn: PropertyKey): Record<PropertyKey, T[]>;
|
|
528
572
|
/**
|
|
529
573
|
* Similar to {@link groupBy} but it returns a {@link https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Map Map} object with the results.
|
|
530
574
|
*
|
|
@@ -536,18 +580,76 @@ export declare function groupBy(arr: Iterable<any> | Object, func?: Iteratee | P
|
|
|
536
580
|
* @example
|
|
537
581
|
```js
|
|
538
582
|
groupByMap([6.1, 4.2, 6.3], Math.floor)
|
|
539
|
-
//
|
|
583
|
+
// Map { 4: [4.2], 6: [6.1, 6.3] }
|
|
540
584
|
|
|
541
585
|
// The `property` iteratee shorthand.
|
|
542
586
|
groupByMap(['one', 'two', 'three'], 'length')
|
|
543
|
-
//
|
|
587
|
+
// Map { 3: ['one', 'two'], 5: ['three'] }
|
|
544
588
|
```
|
|
545
589
|
*/
|
|
546
|
-
export declare function groupByMap<
|
|
590
|
+
export declare function groupByMap<V>(arr: Iterable<V>, fn: Iteratee<V>): Map<any, V[]>;
|
|
591
|
+
export declare function groupByMap<V>(arr: Iterable<V>, fn: PropertyKey): Map<any, V[]>;
|
|
592
|
+
export declare function groupByMap<V>(arr: Object, fn: Iteratee<V>): Map<any, V[]>;
|
|
593
|
+
export declare function groupByMap<V>(arr: Object, fn: PropertyKey): Map<any, V[]>;
|
|
547
594
|
/**
|
|
548
595
|
* Removes all elements from array that `func` returns truthy for and returns an array of the removed elements.
|
|
549
596
|
* @param arr The array to remove from.
|
|
550
597
|
* @param func The function invoked per iteration or value(s) or value to remove.
|
|
551
598
|
* @returns
|
|
552
599
|
*/
|
|
553
|
-
export declare function remove<T>(arr: T[], func:
|
|
600
|
+
export declare function remove<T>(arr: T[], func: T): T[];
|
|
601
|
+
export declare function remove<T>(arr: T[], func: T[]): T[];
|
|
602
|
+
export declare function remove<T>(arr: T[], func: Iteratee<T>): T[];
|
|
603
|
+
/**
|
|
604
|
+
* Returns the index of `x` in a **sorted** array if found, in `O(log n)` using binary search.
|
|
605
|
+
* If the element is not found, returns a negative integer.
|
|
606
|
+
* @param arr The array to sort
|
|
607
|
+
* @param x The element to find
|
|
608
|
+
* @param lo The starting index
|
|
609
|
+
* @param hi The end index to search within
|
|
610
|
+
* @param comp The compare function to check for `x`
|
|
611
|
+
* @returns {number} The index if the element is found or a negative integer.
|
|
612
|
+
*/
|
|
613
|
+
export declare function binarySearch(arr: any[], x: any, lo?: number, hi?: any, comp?: typeof compare): number;
|
|
614
|
+
/**
|
|
615
|
+
* Returns an insertion index which comes after any existing entries of `x` in a **sorted** array, using binary search.
|
|
616
|
+
* @param arr The array to sort
|
|
617
|
+
* @param x The element to find
|
|
618
|
+
* @param lo The starting index
|
|
619
|
+
* @param hi The end index to search within
|
|
620
|
+
* @param comp The compare function to check for `x`
|
|
621
|
+
* @returns {number}
|
|
622
|
+
*/
|
|
623
|
+
export declare function bisect(arr: any[], x: any, lo?: number, hi?: any, comp?: typeof compare): number;
|
|
624
|
+
/**
|
|
625
|
+
* Returns an insertion index which comes before any existing entries of `x` in a **sorted** array, using binary search.
|
|
626
|
+
* @param arr The array to sort
|
|
627
|
+
* @param x The element to find
|
|
628
|
+
* @param lo The starting index
|
|
629
|
+
* @param hi The end index to search within
|
|
630
|
+
* @param comp The compare function to check for `x`
|
|
631
|
+
* @returns {number}
|
|
632
|
+
*/
|
|
633
|
+
export declare function bisectLeft(arr: any[], x: any, lo?: number, hi?: any, comp?: typeof compare): number;
|
|
634
|
+
/**
|
|
635
|
+
* Runs {@link bisect} first to locate an insertion point, and inserts the value `x` in the sorted array after any existing entries of `x` to maintain sort order.
|
|
636
|
+
* Please note this method is `O(n)` because insertion resizes the array.
|
|
637
|
+
* @param arr The array to insert into
|
|
638
|
+
* @param x The element to insert
|
|
639
|
+
* @param lo The starting index
|
|
640
|
+
* @param hi The end index to search within
|
|
641
|
+
* @param comp The compare function to check for `x`
|
|
642
|
+
* @returns {Array}
|
|
643
|
+
*/
|
|
644
|
+
export declare function insort<T>(arr: T[], x: any, lo?: number, hi?: any, comp?: typeof compare): T[];
|
|
645
|
+
/**
|
|
646
|
+
* Runs {@link bisectLeft} first to locate an insertion point, and inserts the value `x` in the sorted array before any existing entries of `x` to maintain sort order.
|
|
647
|
+
* Please note this method is `O(n)` because insertion resizes the array.
|
|
648
|
+
* @param arr The array to insert into
|
|
649
|
+
* @param x The element to insert
|
|
650
|
+
* @param lo The starting index
|
|
651
|
+
* @param hi The end index to search within
|
|
652
|
+
* @param comp The compare function to check for `x`
|
|
653
|
+
* @returns {Array}
|
|
654
|
+
*/
|
|
655
|
+
export declare function insortLeft<T>(arr: T[], x: any, lo?: number, hi?: any, comp?: typeof compare): T[];
|