@oscarpalmer/atoms 0.218.0 → 0.220.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/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/sort.d.mts +54 -0
- package/dist/color/space/hex.d.mts +8 -0
- package/dist/color/space/hex.mjs +8 -0
- package/dist/index.d.mts +764 -189
- package/dist/index.mjs +508 -207
- package/dist/internal/array/callbacks.mjs +1 -1
- package/dist/internal/array/find.d.mts +3 -3
- package/dist/internal/array/find.mjs +71 -52
- 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/misc.d.mts +14 -0
- package/dist/internal/math/misc.mjs +14 -0
- package/dist/internal/number.d.mts +18 -0
- package/dist/internal/number.mjs +18 -0
- 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 +20 -0
- 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/string/string.fuzzy.model.d.mts +46 -18
- package/dist/models/string/string.fuzzy.model.mjs +3 -1
- package/dist/models/value/value.merge.model.d.mts +3 -3
- package/dist/promise/misc.d.mts +6 -0
- package/dist/promise/misc.mjs +6 -0
- package/dist/promise/timed.d.mts +3 -0
- package/dist/promise/timed.mjs +3 -0
- package/dist/queue.d.mts +0 -1
- package/dist/queue.mjs +1 -1
- package/dist/string/fuzzy.d.mts +3 -3
- package/dist/string/fuzzy.mjs +171 -97
- package/dist/string/index.d.mts +15 -1
- package/dist/string/index.mjs +15 -1
- package/dist/string/match.d.mts +24 -0
- package/dist/string/match.mjs +24 -0
- package/dist/string/template.d.mts +4 -0
- package/package.json +1 -1
package/dist/index.d.mts
CHANGED
|
@@ -49,7 +49,7 @@ export type KeyOrCallbackValue<Item, Arg extends KeyOrCallback<Item>> = Arg exte
|
|
|
49
49
|
/**
|
|
50
50
|
* A nested array
|
|
51
51
|
*/
|
|
52
|
-
export type NestedArray<Value> = Value extends
|
|
52
|
+
export type NestedArray<Value> = Value extends ReadonlyArray<infer NestedValue> ? NestedArray<NestedValue> : Value;
|
|
53
53
|
/**
|
|
54
54
|
* All nested keys of an object as dot notation strings _(up to 5 levels deep)_
|
|
55
55
|
*/
|
|
@@ -145,7 +145,7 @@ export type Unsubscriber = () => void;
|
|
|
145
145
|
* ); // => [{id: 1}, {id: 3}]
|
|
146
146
|
* ```
|
|
147
147
|
*/
|
|
148
|
-
export declare function exclude<Item, Callback extends (item: Item, index: number, array: Item[]) => unknown>(array: Item[], callback: Callback, value: ReturnType<Callback>):
|
|
148
|
+
export declare function exclude<Item, Callback extends (item: Item, index: number, array: Item[]) => unknown>(array: Item[], callback: Callback, value: ReturnType<Callback>): Item[];
|
|
149
149
|
/**
|
|
150
150
|
* Get a filtered array of items that do not match the value
|
|
151
151
|
*
|
|
@@ -165,7 +165,25 @@ export declare function exclude<Item, Callback extends (item: Item, index: numbe
|
|
|
165
165
|
* ); // => [{id: 1}, {id: 3}]
|
|
166
166
|
* ```
|
|
167
167
|
*/
|
|
168
|
-
export declare function exclude<Item extends PlainObject, ItemKey extends keyof Item>(array: Item[], key: ItemKey, value: Item[ItemKey]):
|
|
168
|
+
export declare function exclude<Item extends PlainObject, ItemKey extends keyof Item>(array: Item[], key: ItemKey, value: Item[ItemKey]): Item[];
|
|
169
|
+
/**
|
|
170
|
+
* Get a narrowed array of items that do not match the filter
|
|
171
|
+
*
|
|
172
|
+
* _Available as `exclude` and `filter.remove`_
|
|
173
|
+
*
|
|
174
|
+
* @param array Array to search in
|
|
175
|
+
* @param filter Type guard to exclude and narrow down the items
|
|
176
|
+
* @returns Narrowed array of items that do not match the filter
|
|
177
|
+
*
|
|
178
|
+
* @example
|
|
179
|
+
* ```typescript
|
|
180
|
+
* exclude(
|
|
181
|
+
* [1, 'a', 2, 'b'],
|
|
182
|
+
* (item): item is string => typeof item === 'string',
|
|
183
|
+
* ); // => [1, 2]
|
|
184
|
+
* ```
|
|
185
|
+
*/
|
|
186
|
+
export declare function exclude<Item, Narrowed extends Item>(array: Item[], filter: (item: Item, index: number, array: Item[]) => item is Narrowed): Array<Exclude<Item, Narrowed>>;
|
|
169
187
|
/**
|
|
170
188
|
* Get a filtered array of items that do not match the filter
|
|
171
189
|
*
|
|
@@ -183,7 +201,7 @@ export declare function exclude<Item extends PlainObject, ItemKey extends keyof
|
|
|
183
201
|
* ); // => [{id: 1}, {id: 3}]
|
|
184
202
|
* ```
|
|
185
203
|
*/
|
|
186
|
-
export declare function exclude<Item>(array: Item[], filter: (item: Item, index: number, array: Item[]) => boolean):
|
|
204
|
+
export declare function exclude<Item>(array: Item[], filter: (item: Item, index: number, array: Item[]) => boolean): Item[];
|
|
187
205
|
/**
|
|
188
206
|
* Get a filtered array of items that do not match the given item
|
|
189
207
|
*
|
|
@@ -198,7 +216,7 @@ export declare function exclude<Item>(array: Item[], filter: (item: Item, index:
|
|
|
198
216
|
* exclude([1, 2, 3], 2); // => [1, 3]
|
|
199
217
|
* ```
|
|
200
218
|
*/
|
|
201
|
-
export declare function exclude<Item>(array: Item[], item: Item):
|
|
219
|
+
export declare function exclude<Item>(array: Item[], item: Item): Item[];
|
|
202
220
|
/**
|
|
203
221
|
* Get a filtered array of items
|
|
204
222
|
*
|
|
@@ -235,6 +253,22 @@ export declare function filter<Item, Callback extends (item: Item, index: number
|
|
|
235
253
|
* ```
|
|
236
254
|
*/
|
|
237
255
|
export declare function filter<Item extends PlainObject, ItemKey extends keyof Item>(array: Item[], key: ItemKey, value: Item[ItemKey]): Item[];
|
|
256
|
+
/**
|
|
257
|
+
* Get a narrowed array of items matching the filter
|
|
258
|
+
*
|
|
259
|
+
* @param array Array to search in
|
|
260
|
+
* @param filter Type guard to match and narrow down the items
|
|
261
|
+
* @returns Narrowed array of items
|
|
262
|
+
*
|
|
263
|
+
* @example
|
|
264
|
+
* ```typescript
|
|
265
|
+
* filter(
|
|
266
|
+
* [{id: 1, tags: ['a', 'b']}, {id: 2}, {id: 3, tags: ['c']}],
|
|
267
|
+
* (item): item is {id: number; tags: string[]} => item.tags != null,
|
|
268
|
+
* ); // => [{id: 1, tags: ['a', 'b']}, {id: 3, tags: ['c']}]
|
|
269
|
+
* ```
|
|
270
|
+
*/
|
|
271
|
+
export declare function filter<Item, Narrowed extends Item>(array: Item[], filter: (item: Item, index: number, array: Item[]) => item is Narrowed): Narrowed[];
|
|
238
272
|
/**
|
|
239
273
|
* Get a filtered array of items matching the filter
|
|
240
274
|
*
|
|
@@ -305,6 +339,22 @@ export declare function find<Item, Callback extends (item: Item, index: number,
|
|
|
305
339
|
* ```
|
|
306
340
|
*/
|
|
307
341
|
export declare function find<Item extends PlainObject, ItemKey extends keyof Item>(array: Item[], key: ItemKey, value: Item[ItemKey]): Item | undefined;
|
|
342
|
+
/**
|
|
343
|
+
* Get the first narrowed item matching the filter
|
|
344
|
+
*
|
|
345
|
+
* @param array Array to search in
|
|
346
|
+
* @param filter Type guard to match and narrow down the items
|
|
347
|
+
* @returns First narrowed item that matches the filter, or `undefined` if no match is found
|
|
348
|
+
*
|
|
349
|
+
* @example
|
|
350
|
+
* ```typescript
|
|
351
|
+
* find(
|
|
352
|
+
* [{id: 1, value: 10}, {id: 2, value: 'a'}, {id: 3, value: 'b'}],
|
|
353
|
+
* (item): item is {id: number; value: string} => typeof item.value === 'string',
|
|
354
|
+
* ); // => {id: 2, value: 'a'}
|
|
355
|
+
* ```
|
|
356
|
+
*/
|
|
357
|
+
export declare function find<Item, Narrowed extends Item>(array: Item[], filter: (item: Item, index: number, array: Item[]) => item is Narrowed): Narrowed | undefined;
|
|
308
358
|
/**
|
|
309
359
|
* Get the first item matching the filter
|
|
310
360
|
*
|
|
@@ -374,6 +424,24 @@ export declare function findLast<Item, Callback extends (item: Item, index: numb
|
|
|
374
424
|
* ```
|
|
375
425
|
*/
|
|
376
426
|
export declare function findLast<Item extends PlainObject, ItemKey extends keyof Item>(array: Item[], key: ItemKey, value: Item[ItemKey]): Item | undefined;
|
|
427
|
+
/**
|
|
428
|
+
* Get the last narrowed item matching the filter
|
|
429
|
+
*
|
|
430
|
+
* _Available as `findLast` and `find.last`_
|
|
431
|
+
*
|
|
432
|
+
* @param array Array to search in
|
|
433
|
+
* @param filter Type guard to match and narrow down the items
|
|
434
|
+
* @returns Last narrowed item that matches the filter, or `undefined` if no match is found
|
|
435
|
+
*
|
|
436
|
+
* @example
|
|
437
|
+
* ```typescript
|
|
438
|
+
* findLast(
|
|
439
|
+
* [{id: 1, value: 10}, {id: 2, value: 'a'}, {id: 3, value: 'b'}],
|
|
440
|
+
* (item): item is {id: number; value: string} => typeof item.value === 'string',
|
|
441
|
+
* ); // => {id: 3, value: 'b'}
|
|
442
|
+
* ```
|
|
443
|
+
*/
|
|
444
|
+
export declare function findLast<Item, Narrowed extends Item>(array: Item[], filter: (item: Item, index: number, array: Item[]) => item is Narrowed): Narrowed | undefined;
|
|
377
445
|
/**
|
|
378
446
|
* Get the last item matching the filter
|
|
379
447
|
*
|
|
@@ -448,6 +516,22 @@ export declare function first<Item, Callback extends (item: Item, index: number,
|
|
|
448
516
|
* ```
|
|
449
517
|
*/
|
|
450
518
|
export declare function first<Item extends PlainObject, ItemKey extends keyof Item>(array: Item[], key: ItemKey, value: Item[ItemKey]): Item | undefined;
|
|
519
|
+
/**
|
|
520
|
+
* Get the first narrowed item matching the filter
|
|
521
|
+
*
|
|
522
|
+
* @param array Array to search in
|
|
523
|
+
* @param filter Type guard to match and narrow down the items
|
|
524
|
+
* @returns First narrowed item that matches the filter, or `undefined` if no match is found
|
|
525
|
+
*
|
|
526
|
+
* @example
|
|
527
|
+
* ```typescript
|
|
528
|
+
* first(
|
|
529
|
+
* [{id: 1, value: 10}, {id: 2, value: 'a'}, {id: 3, value: 'b'}],
|
|
530
|
+
* (item): item is {id: number; value: string} => typeof item.value === 'string',
|
|
531
|
+
* ); // => {id: 2, value: 'a'}
|
|
532
|
+
* ```
|
|
533
|
+
*/
|
|
534
|
+
export declare function first<Item, Narrowed extends Item>(array: Item[], filter: (item: Item, index: number, array: Item[]) => item is Narrowed): Narrowed | undefined;
|
|
451
535
|
/**
|
|
452
536
|
* Get the first item matching the filter
|
|
453
537
|
*
|
|
@@ -481,7 +565,7 @@ export declare function first<Item>(array: Item[]): Item | undefined;
|
|
|
481
565
|
/**
|
|
482
566
|
* Get the first item matching the given value, or a default value if no match is found
|
|
483
567
|
*
|
|
484
|
-
* _Available as `firstOrDefault` and `first.
|
|
568
|
+
* _Available as `firstOrDefault` and `first.defaulted`_
|
|
485
569
|
*
|
|
486
570
|
* @param array Array to search in
|
|
487
571
|
* @param defaultValue Default value to return if no match is found
|
|
@@ -503,7 +587,7 @@ export declare function firstOrDefault<Item, Callback extends (item: Item, index
|
|
|
503
587
|
/**
|
|
504
588
|
* Get the first item matching the given value by key, or a default value if no match is found
|
|
505
589
|
*
|
|
506
|
-
* _Available as `firstOrDefault` and `first.
|
|
590
|
+
* _Available as `firstOrDefault` and `first.defaulted`_
|
|
507
591
|
*
|
|
508
592
|
* @param array Array to search in
|
|
509
593
|
* @param defaultValue Default value to return if no match is found
|
|
@@ -522,10 +606,30 @@ export declare function firstOrDefault<Item, Callback extends (item: Item, index
|
|
|
522
606
|
* ```
|
|
523
607
|
*/
|
|
524
608
|
export declare function firstOrDefault<Item extends PlainObject, ItemKey extends keyof Item>(array: Item[], defaultValue: Item, key: ItemKey, value: Item[ItemKey]): Item;
|
|
609
|
+
/**
|
|
610
|
+
* Get the first narrowed item matching the filter, or a default value if no match is found
|
|
611
|
+
*
|
|
612
|
+
* _Available as `firstOrDefault` and `first.defaulted`_
|
|
613
|
+
*
|
|
614
|
+
* @param array Array to search in
|
|
615
|
+
* @param defaultValue Default value to return if no match is found
|
|
616
|
+
* @param filter Type guard to match and narrow down the items
|
|
617
|
+
* @returns First narrowed item that matches the filter, or the default value if no match is found
|
|
618
|
+
*
|
|
619
|
+
* @example
|
|
620
|
+
* ```typescript
|
|
621
|
+
* firstOrDefault(
|
|
622
|
+
* [{id: 1, value: 10}, {id: 2, value: 'a'}, {id: 3, value: 'b'}],
|
|
623
|
+
* {id: -1, value: 'c'},
|
|
624
|
+
* (item): item is {id: number; value: string} => typeof item.value === 'string',
|
|
625
|
+
* ); // => {id: 2, value: 'a'}
|
|
626
|
+
* ```
|
|
627
|
+
*/
|
|
628
|
+
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;
|
|
525
629
|
/**
|
|
526
630
|
* Get the first item matching the filter, or a default value if no match is found
|
|
527
631
|
*
|
|
528
|
-
* _Available as `firstOrDefault` and `first.
|
|
632
|
+
* _Available as `firstOrDefault` and `first.defaulted`_
|
|
529
633
|
*
|
|
530
634
|
* @param array Array to search in
|
|
531
635
|
* @param defaultValue Default value to return if no match is found
|
|
@@ -545,7 +649,7 @@ export declare function firstOrDefault<Item>(array: Item[], defaultValue: Item,
|
|
|
545
649
|
/**
|
|
546
650
|
* Get the first item from an array, or a default value if the array is empty
|
|
547
651
|
*
|
|
548
|
-
* _Available as `firstOrDefault` and `first.
|
|
652
|
+
* _Available as `firstOrDefault` and `first.defaulted`_
|
|
549
653
|
*
|
|
550
654
|
* @param array Array to get from
|
|
551
655
|
* @param defaultValue Default value to return if the array is empty
|
|
@@ -787,9 +891,7 @@ export declare function getArray<Value>(value: Value): Value[];
|
|
|
787
891
|
* Comparison of an array within another array
|
|
788
892
|
*/
|
|
789
893
|
type ArrayComparison = "end" | "inside" | "invalid" | "outside" | "same" | "start";
|
|
790
|
-
type
|
|
791
|
-
type ArrayMapped<Item, Map extends ArrayMapKeyOrCallback<Item>> = Map extends ((item: Item, index: number, array: Item[]) => unknown) ? ReturnType<Map> : Map extends keyof Item ? Item[Map] : never;
|
|
792
|
-
type ArrayObjectKeysOf<Item> = { [Key in keyof Item]: Item[Key] extends PlainObject ? Key : never; }[keyof Item];
|
|
894
|
+
type ArrayFlattened<Value> = Value extends ReadonlyArray<infer Inner> ? Inner : Value;
|
|
793
895
|
//#endregion
|
|
794
896
|
//#region src/internal/array/match.d.ts
|
|
795
897
|
/**
|
|
@@ -1044,6 +1146,11 @@ export declare function startsWithArray<Item>(haystack: Item[], needle: Item[]):
|
|
|
1044
1146
|
*
|
|
1045
1147
|
* @param array Original array
|
|
1046
1148
|
* @returns Shuffled array
|
|
1149
|
+
*
|
|
1150
|
+
* @example
|
|
1151
|
+
* ```typescript
|
|
1152
|
+
* shuffle([1, 2, 3]); // => [3, 1, 2] (maybe? it's random, you know)
|
|
1153
|
+
* ```
|
|
1047
1154
|
*/
|
|
1048
1155
|
export declare function shuffle<Item>(array: Item[]): Item[];
|
|
1049
1156
|
//#endregion
|
|
@@ -1355,7 +1462,7 @@ export declare function intersection<First, Second>(first: First[], second: Seco
|
|
|
1355
1462
|
* @param array Array to search in
|
|
1356
1463
|
* @param callback Callback to get an item's value for matching
|
|
1357
1464
|
* @param value Value to match against
|
|
1358
|
-
* @returns
|
|
1465
|
+
* @returns Tuple of matching and non-matching items
|
|
1359
1466
|
*
|
|
1360
1467
|
* @example
|
|
1361
1468
|
* ```typescript
|
|
@@ -1366,14 +1473,14 @@ export declare function intersection<First, Second>(first: First[], second: Seco
|
|
|
1366
1473
|
* ); // => [[{id: 2}], [{id: 1}, {id: 3}]]
|
|
1367
1474
|
* ```
|
|
1368
1475
|
*/
|
|
1369
|
-
export declare function partition<Item, Callback extends (item: Item, index: number, array: Item[]) => unknown>(array: Item[], callback: Callback, value: ReturnType<Callback>): Item[][];
|
|
1476
|
+
export declare function partition<Item, Callback extends (item: Item, index: number, array: Item[]) => unknown>(array: Item[], callback: Callback, value: ReturnType<Callback>): [Item[], Item[]];
|
|
1370
1477
|
/**
|
|
1371
1478
|
* Get a partitioned array of items
|
|
1372
1479
|
*
|
|
1373
1480
|
* @param array Array to search in
|
|
1374
1481
|
* @param key Key to get an item's value for matching
|
|
1375
1482
|
* @param value Value to match against
|
|
1376
|
-
* @returns
|
|
1483
|
+
* @returns Tuple of matching and non-matching items
|
|
1377
1484
|
*
|
|
1378
1485
|
* @example
|
|
1379
1486
|
* ```typescript
|
|
@@ -1384,13 +1491,29 @@ export declare function partition<Item, Callback extends (item: Item, index: num
|
|
|
1384
1491
|
* ); // => [[{id: 2}], [{id: 1}, {id: 3}]]
|
|
1385
1492
|
* ```
|
|
1386
1493
|
*/
|
|
1387
|
-
export declare function partition<Item extends PlainObject, ItemKey extends keyof Item>(array: Item[], key: ItemKey, value: Item[ItemKey]): Item[][];
|
|
1494
|
+
export declare function partition<Item extends PlainObject, ItemKey extends keyof Item>(array: Item[], key: ItemKey, value: Item[ItemKey]): [Item[], Item[]];
|
|
1495
|
+
/**
|
|
1496
|
+
* Get a partitioned array of items
|
|
1497
|
+
*
|
|
1498
|
+
* @param array Array to search in
|
|
1499
|
+
* @param filter Type guard to match and narrow down the items
|
|
1500
|
+
* @returns Tuple of matching and non-matching items
|
|
1501
|
+
*
|
|
1502
|
+
* @example
|
|
1503
|
+
* ```typescript
|
|
1504
|
+
* partition(
|
|
1505
|
+
* [{id: 1, value: 10}, {id: 2, value: 'a'}, {id: 3, value: 'b'}],
|
|
1506
|
+
* (item): item is {id: number; value: string} => typeof item.value === 'string',
|
|
1507
|
+
* ); // => [[{id: 2, value: 'a'}, {id: 3, value: 'b'}], [{id: 1, value: 10}]]
|
|
1508
|
+
* ```
|
|
1509
|
+
*/
|
|
1510
|
+
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>>];
|
|
1388
1511
|
/**
|
|
1389
1512
|
* Get a partitioned array of items
|
|
1390
1513
|
*
|
|
1391
1514
|
* @param array Array to search in
|
|
1392
1515
|
* @param filter Filter callback to match items
|
|
1393
|
-
* @returns
|
|
1516
|
+
* @returns Tuple of matching and non-matching items
|
|
1394
1517
|
*
|
|
1395
1518
|
* @example
|
|
1396
1519
|
* ```typescript
|
|
@@ -1400,20 +1523,20 @@ export declare function partition<Item extends PlainObject, ItemKey extends keyo
|
|
|
1400
1523
|
* ); // => [[{id: 2}], [{id: 1}, {id: 3}]]
|
|
1401
1524
|
* ```
|
|
1402
1525
|
*/
|
|
1403
|
-
export declare function partition<Item>(array: Item[], filter: (item: Item, index: number, array: Item[]) => boolean): Item[][];
|
|
1526
|
+
export declare function partition<Item>(array: Item[], filter: (item: Item, index: number, array: Item[]) => boolean): [Item[], Item[]];
|
|
1404
1527
|
/**
|
|
1405
1528
|
* Get a partitioned array of items matching the given item
|
|
1406
1529
|
*
|
|
1407
1530
|
* @param array Array to search in
|
|
1408
1531
|
* @param item Item to match against
|
|
1409
|
-
* @returns
|
|
1532
|
+
* @returns Tuple of matching and non-matching items
|
|
1410
1533
|
*
|
|
1411
1534
|
* @example
|
|
1412
1535
|
* ```typescript
|
|
1413
1536
|
* partition([1, 2, 3, 4, 5], 3); // => [[3], [1, 2, 4, 5]]
|
|
1414
1537
|
* ```
|
|
1415
1538
|
*/
|
|
1416
|
-
export declare function partition<Item>(array: Item[], item: Item): Item[][];
|
|
1539
|
+
export declare function partition<Item>(array: Item[], item: Item): [Item[], Item[]];
|
|
1417
1540
|
//#endregion
|
|
1418
1541
|
//#region src/array/push.d.ts
|
|
1419
1542
|
/**
|
|
@@ -1438,6 +1561,12 @@ export declare function push<Item>(array: Item[], pushed: Item[]): number;
|
|
|
1438
1561
|
*
|
|
1439
1562
|
* @param array Array to reverse
|
|
1440
1563
|
* @returns Reversed array
|
|
1564
|
+
*
|
|
1565
|
+
* @example
|
|
1566
|
+
* ```typescript
|
|
1567
|
+
* reverse([1, 2, 3]); // => [3, 2, 1]
|
|
1568
|
+
* reverse(['a', 'b', 'c']); // => ['c', 'b', 'a']
|
|
1569
|
+
* ```
|
|
1441
1570
|
*/
|
|
1442
1571
|
export declare function reverse<Item>(array: Item[]): Item[];
|
|
1443
1572
|
//#endregion
|
|
@@ -1482,6 +1611,28 @@ export declare function single<Item, Callback extends (item: Item, index: number
|
|
|
1482
1611
|
* ```
|
|
1483
1612
|
*/
|
|
1484
1613
|
export declare function single<Item extends PlainObject, ItemKey extends keyof Item>(array: Item[], key: ItemKey, value: Item[ItemKey]): Item | undefined;
|
|
1614
|
+
/**
|
|
1615
|
+
* Get the _only_ narrowed item matching the filter
|
|
1616
|
+
*
|
|
1617
|
+
* _Throws an error if multiple items match the filter_
|
|
1618
|
+
*
|
|
1619
|
+
* @param array Array to search in
|
|
1620
|
+
* @param filter Type guard to match and narrow down the items
|
|
1621
|
+
* @returns Only narrowed item that matches the filter, or `undefined` if no match is found
|
|
1622
|
+
*
|
|
1623
|
+
* @example
|
|
1624
|
+
* ```typescript
|
|
1625
|
+
* single(
|
|
1626
|
+
* [{id: 1, value: 10}, {id: 2, value: 'a'}, {id: 3, value: 'b'}],
|
|
1627
|
+
* (item): item is {id: number; value: number} => typeof item.value === 'number',
|
|
1628
|
+
* ); // => {id: 1, value: 10}
|
|
1629
|
+
* single(
|
|
1630
|
+
* [{id: 1, value: 10}, {id: 2, value: 'a'}, {id: 3, value: 'b'}],
|
|
1631
|
+
* (item): item is {id: number; value: string} => typeof item.value === 'string',
|
|
1632
|
+
* ); // => throws an error as there are two matches
|
|
1633
|
+
* ```
|
|
1634
|
+
*/
|
|
1635
|
+
export declare function single<Item, Narrowed extends Item>(array: Item[], filter: (item: Item, index: number, array: Item[]) => item is Narrowed): Narrowed | undefined;
|
|
1485
1636
|
/**
|
|
1486
1637
|
* Get the _only_ item matching the filter
|
|
1487
1638
|
*
|
|
@@ -2024,7 +2175,7 @@ export declare function update<Item>(destination: Item[], updated: Item[]): Item
|
|
|
2024
2175
|
//#endregion
|
|
2025
2176
|
//#region src/array/last.d.ts
|
|
2026
2177
|
/**
|
|
2027
|
-
* Get the last
|
|
2178
|
+
* Get the last item matching the given value
|
|
2028
2179
|
*
|
|
2029
2180
|
* @param array Array to search in
|
|
2030
2181
|
* @param callback Callback to get an item's value for matching
|
|
@@ -2042,7 +2193,7 @@ export declare function update<Item>(destination: Item[], updated: Item[]): Item
|
|
|
2042
2193
|
*/
|
|
2043
2194
|
export declare function last<Item, Callback extends (item: Item, index: number, array: Item[]) => unknown>(array: Item[], callback: Callback, value: ReturnType<Callback>): Item | undefined;
|
|
2044
2195
|
/**
|
|
2045
|
-
* Get the
|
|
2196
|
+
* Get the last item matching the given value by key
|
|
2046
2197
|
*
|
|
2047
2198
|
* @param array Array to search in
|
|
2048
2199
|
* @param key Key to get an item's value for matching
|
|
@@ -2059,6 +2210,22 @@ export declare function last<Item, Callback extends (item: Item, index: number,
|
|
|
2059
2210
|
* ```
|
|
2060
2211
|
*/
|
|
2061
2212
|
export declare function last<Item extends PlainObject, ItemKey extends keyof Item>(array: Item[], key: ItemKey, value: Item[ItemKey]): Item | undefined;
|
|
2213
|
+
/**
|
|
2214
|
+
* Get the last narrowed item matching the filter
|
|
2215
|
+
*
|
|
2216
|
+
* @param array Array to search in
|
|
2217
|
+
* @param filter Type guard to match and narrow down the items
|
|
2218
|
+
* @returns Last narrowed item that matches the filter, or `undefined` if no match is found
|
|
2219
|
+
*
|
|
2220
|
+
* @example
|
|
2221
|
+
* ```typescript
|
|
2222
|
+
* last(
|
|
2223
|
+
* [{id: 1, value: 10}, {id: 2, value: 'a'}, {id: 3, value: 'b'}],
|
|
2224
|
+
* (item): item is {id: number; value: string} => typeof item.value === 'string',
|
|
2225
|
+
* ); // => {id: 3, value: 'b'}
|
|
2226
|
+
* ```
|
|
2227
|
+
*/
|
|
2228
|
+
export declare function last<Item, Narrowed extends Item>(array: Item[], filter: (item: Item, index: number, array: Item[]) => item is Narrowed): Narrowed | undefined;
|
|
2062
2229
|
/**
|
|
2063
2230
|
* Get the last item matching the filter
|
|
2064
2231
|
*
|
|
@@ -2088,9 +2255,9 @@ export declare function last<Item>(array: Item[], filter: (item: Item, index: nu
|
|
|
2088
2255
|
*/
|
|
2089
2256
|
export declare function last<Item>(array: Item[]): Item | undefined;
|
|
2090
2257
|
/**
|
|
2091
|
-
* Get the last item matching the given value
|
|
2258
|
+
* Get the last item matching the given value, or a default value if no match is found
|
|
2092
2259
|
*
|
|
2093
|
-
* _Available as `lastOrDefault` and `last.
|
|
2260
|
+
* _Available as `lastOrDefault` and `last.defaulted`_
|
|
2094
2261
|
*
|
|
2095
2262
|
* @param array Array to search in
|
|
2096
2263
|
* @param defaultValue Default value to return if no match is found
|
|
@@ -2110,9 +2277,9 @@ export declare function last<Item>(array: Item[]): Item | undefined;
|
|
|
2110
2277
|
*/
|
|
2111
2278
|
export declare function lastOrDefault<Item, Callback extends (item: Item, index: number, array: Item[]) => unknown>(array: Item[], defaultValue: Item, callback: Callback, value: ReturnType<Callback>): Item;
|
|
2112
2279
|
/**
|
|
2113
|
-
* Get the last item matching the given value by key
|
|
2280
|
+
* Get the last item matching the given value by key, or a default value if no match is found
|
|
2114
2281
|
*
|
|
2115
|
-
* _Available as `lastOrDefault` and `last.
|
|
2282
|
+
* _Available as `lastOrDefault` and `last.defaulted`_
|
|
2116
2283
|
*
|
|
2117
2284
|
* @param array Array to search in
|
|
2118
2285
|
* @param defaultValue Default value to return if no match is found
|
|
@@ -2132,9 +2299,29 @@ export declare function lastOrDefault<Item, Callback extends (item: Item, index:
|
|
|
2132
2299
|
*/
|
|
2133
2300
|
export declare function lastOrDefault<Item extends PlainObject, ItemKey extends keyof Item>(array: Item[], defaultValue: Item, key: ItemKey, value: Item[ItemKey]): Item;
|
|
2134
2301
|
/**
|
|
2135
|
-
* Get the last item matching the filter
|
|
2302
|
+
* Get the last narrowed item matching the filter, or a default value if no match is found
|
|
2303
|
+
*
|
|
2304
|
+
* _Available as `lastOrDefault` and `last.defaulted`_
|
|
2305
|
+
*
|
|
2306
|
+
* @param array Array to search in
|
|
2307
|
+
* @param defaultValue Default value to return if no match is found
|
|
2308
|
+
* @param filter Type guard to match and narrow down the items
|
|
2309
|
+
* @returns Last narrowed item that matches the filter, or the default value if no match is found
|
|
2310
|
+
*
|
|
2311
|
+
* @example
|
|
2312
|
+
* ```typescript
|
|
2313
|
+
* lastOrDefault(
|
|
2314
|
+
* [{id: 1, value: 10}, {id: 2, value: 'a'}, {id: 3, value: 'b'}],
|
|
2315
|
+
* {id: -1, value: 'c'},
|
|
2316
|
+
* (item): item is {id: number; value: string} => typeof item.value === 'string',
|
|
2317
|
+
* ); // => {id: 3, value: 'b'}
|
|
2318
|
+
* ```
|
|
2319
|
+
*/
|
|
2320
|
+
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;
|
|
2321
|
+
/**
|
|
2322
|
+
* Get the last item matching the filter, or a default value if no match is found
|
|
2136
2323
|
*
|
|
2137
|
-
* _Available as `lastOrDefault` and `last.
|
|
2324
|
+
* _Available as `lastOrDefault` and `last.defaulted`_
|
|
2138
2325
|
*
|
|
2139
2326
|
* @param array Array to search in
|
|
2140
2327
|
* @param defaultValue Default value to return if no match is found
|
|
@@ -2152,9 +2339,9 @@ export declare function lastOrDefault<Item extends PlainObject, ItemKey extends
|
|
|
2152
2339
|
*/
|
|
2153
2340
|
export declare function lastOrDefault<Item>(array: Item[], defaultValue: Item, filter: (item: Item, index: number, array: Item[]) => boolean): Item;
|
|
2154
2341
|
/**
|
|
2155
|
-
* Get the last item from an array
|
|
2342
|
+
* Get the last item from an array, or a default value if the array is empty
|
|
2156
2343
|
*
|
|
2157
|
-
* _Available as `lastOrDefault` and `last.
|
|
2344
|
+
* _Available as `lastOrDefault` and `last.defaulted`_
|
|
2158
2345
|
*
|
|
2159
2346
|
* @param array Array to get from
|
|
2160
2347
|
* @param defaultValue Default value to return if the array is empty
|
|
@@ -2336,190 +2523,172 @@ export declare namespace move {
|
|
|
2336
2523
|
//#endregion
|
|
2337
2524
|
//#region src/array/select.d.ts
|
|
2338
2525
|
/**
|
|
2339
|
-
* Get a
|
|
2526
|
+
* Get a narrowed, mapped, and flattened array of items
|
|
2340
2527
|
*
|
|
2341
|
-
*
|
|
2342
|
-
* @param filterCallback Callback to get an item's value for matching
|
|
2343
|
-
* @param filterValue Value to match against
|
|
2344
|
-
* @param map Callback or key to map the matched items
|
|
2345
|
-
* @returns Filtered and mapped array of items
|
|
2346
|
-
*
|
|
2347
|
-
* @example
|
|
2348
|
-
* ```typescript
|
|
2349
|
-
* select(
|
|
2350
|
-
* [{id: 1, name: 'Alice'}, {id: 2, name: 'Bob'}, {id: 3, name: 'Charlie'}],
|
|
2351
|
-
* item => item.id,
|
|
2352
|
-
* 2,
|
|
2353
|
-
* item => item.name,
|
|
2354
|
-
* ); // => ['Bob']
|
|
2355
|
-
* ```
|
|
2356
|
-
*/
|
|
2357
|
-
export declare function filterAndMap<Item, FilterCallback extends (item: Item, index: number, array: Item[]) => unknown, Map extends ArrayMapKeyOrCallback<Item>>(array: Item[], filterCallback: FilterCallback, filterValue: ReturnType<FilterCallback>, map: Map): Array<ArrayMapped<Item, Map>>;
|
|
2358
|
-
/**
|
|
2359
|
-
* Get a filtered and mapped array of items
|
|
2528
|
+
* _Available as `filterAndFlatMap`, `filterAndMap.flat`, and `select.flat`_
|
|
2360
2529
|
*
|
|
2361
|
-
* @param array Array to
|
|
2362
|
-
* @param
|
|
2363
|
-
* @param
|
|
2364
|
-
* @
|
|
2365
|
-
* @returns Filtered and mapped array of items
|
|
2530
|
+
* @param array Array to select from
|
|
2531
|
+
* @param filter Type guard to filter and narrow down the items
|
|
2532
|
+
* @param mapper Callback to map and flatten the narrowed items
|
|
2533
|
+
* @returns Narrowed, mapped, and flattened array of items
|
|
2366
2534
|
*
|
|
2367
2535
|
* @example
|
|
2368
2536
|
* ```typescript
|
|
2369
|
-
*
|
|
2370
|
-
* [{id: 1,
|
|
2371
|
-
*
|
|
2372
|
-
*
|
|
2373
|
-
*
|
|
2374
|
-
* ); // => ['Bob']
|
|
2537
|
+
* filterAndFlatMap(
|
|
2538
|
+
* [{id: 1, tags: ['a', 'b']}, {id: 2}, {id: 3, tags: ['c']}],
|
|
2539
|
+
* (item): item is {id: number; tags: string[]} => item.tags != null,
|
|
2540
|
+
* item => item.tags,
|
|
2541
|
+
* ); // => ['a', 'b', 'c']
|
|
2375
2542
|
* ```
|
|
2376
2543
|
*/
|
|
2377
|
-
export declare function
|
|
2544
|
+
export declare function filterAndFlatMap<Item, Narrowed extends Item, Mapped>(array: Item[], filter: (item: Item, index: number, array: Item[]) => item is Narrowed, mapper: (item: Narrowed, index: number, array: Item[]) => Mapped): Array<ArrayFlattened<Mapped>>;
|
|
2378
2545
|
/**
|
|
2379
|
-
* Get a filtered and
|
|
2546
|
+
* Get a filtered, mapped, and flattened array of items
|
|
2380
2547
|
*
|
|
2381
|
-
*
|
|
2382
|
-
*
|
|
2383
|
-
* @param
|
|
2384
|
-
* @
|
|
2548
|
+
* _Available as `filterAndFlatMap`, `filterAndMap.flat`, and `select.flat`_
|
|
2549
|
+
*
|
|
2550
|
+
* @param array Array to select from
|
|
2551
|
+
* @param filter Callback to filter the items
|
|
2552
|
+
* @param mapper Callback to map and flatten the filtered items
|
|
2553
|
+
* @returns Filtered, mapped, and flattened array of items
|
|
2385
2554
|
*
|
|
2386
2555
|
* @example
|
|
2387
2556
|
* ```typescript
|
|
2388
|
-
*
|
|
2389
|
-
* [{id: 1,
|
|
2390
|
-
* item => item.id
|
|
2391
|
-
* item => item.
|
|
2392
|
-
* ); // => ['
|
|
2557
|
+
* filterAndFlatMap(
|
|
2558
|
+
* [{id: 1, tags: ['a', 'b']}, {id: 2, tags: ['c']}, {id: 3, tags: ['d', 'e']}],
|
|
2559
|
+
* item => item.id !== 2,
|
|
2560
|
+
* item => item.tags,
|
|
2561
|
+
* ); // => ['a', 'b', 'd', 'e']
|
|
2393
2562
|
* ```
|
|
2394
2563
|
*/
|
|
2395
|
-
export declare function
|
|
2564
|
+
export declare function filterAndFlatMap<Item, Mapped>(array: Item[], filter: (item: Item, index: number, array: Item[]) => boolean, mapper: (item: Item, index: number, array: Item[]) => Mapped): Array<ArrayFlattened<Mapped>>;
|
|
2396
2565
|
/**
|
|
2397
|
-
* Get a
|
|
2566
|
+
* Get a narrowed and mapped array of items
|
|
2398
2567
|
*
|
|
2399
|
-
*
|
|
2400
|
-
*
|
|
2401
|
-
* @param
|
|
2402
|
-
* @
|
|
2568
|
+
* _Available as `filterAndMap` and `select`_
|
|
2569
|
+
*
|
|
2570
|
+
* @param array Array to select from
|
|
2571
|
+
* @param filter Type guard to filter and narrow down the items
|
|
2572
|
+
* @param mapper Callback to map the narrowed items
|
|
2573
|
+
* @returns Narrowed and mapped array of items
|
|
2403
2574
|
*
|
|
2404
2575
|
* @example
|
|
2405
2576
|
* ```typescript
|
|
2406
|
-
*
|
|
2407
|
-
* [1, 2, 3,
|
|
2408
|
-
*
|
|
2409
|
-
*
|
|
2410
|
-
* ); // => [
|
|
2577
|
+
* filterAndMap(
|
|
2578
|
+
* [{id: 1, name: 'Alice'}, {id: 2}, {id: 3, name: 'Charlie'}],
|
|
2579
|
+
* (item): item is {id: number; name: string} => item.name != null,
|
|
2580
|
+
* item => item.name.toUpperCase(),
|
|
2581
|
+
* ); // => ['ALICE', 'CHARLIE']
|
|
2411
2582
|
* ```
|
|
2412
2583
|
*/
|
|
2413
|
-
export declare function filterAndMap<Item,
|
|
2584
|
+
export declare function filterAndMap<Item, Narrowed extends Item, Mapped>(array: Item[], filter: (item: Item, index: number, array: Item[]) => item is Narrowed, mapper: (item: Narrowed, index: number, array: Item[]) => Mapped): Mapped[];
|
|
2414
2585
|
/**
|
|
2415
|
-
* Get a
|
|
2586
|
+
* Get a filtered and mapped array of items
|
|
2416
2587
|
*
|
|
2417
|
-
* _Available as `
|
|
2588
|
+
* _Available as `filterAndMap` and `select`_
|
|
2418
2589
|
*
|
|
2419
|
-
* @param array Array to
|
|
2420
|
-
* @param
|
|
2421
|
-
* @param
|
|
2422
|
-
* @
|
|
2423
|
-
* @returns Mapped and filtered array of items
|
|
2590
|
+
* @param array Array to select from
|
|
2591
|
+
* @param filter Callback to filter the items
|
|
2592
|
+
* @param mapper Callback to map the filtered items
|
|
2593
|
+
* @returns Filtered and mapped array of items
|
|
2424
2594
|
*
|
|
2425
2595
|
* @example
|
|
2426
2596
|
* ```typescript
|
|
2427
|
-
*
|
|
2597
|
+
* filterAndMap(
|
|
2428
2598
|
* [{id: 1, name: 'Alice'}, {id: 2, name: 'Bob'}, {id: 3, name: 'Charlie'}],
|
|
2599
|
+
* item => item.id === 2,
|
|
2429
2600
|
* item => item.name,
|
|
2430
|
-
* value => value.length,
|
|
2431
|
-
* 3,
|
|
2432
2601
|
* ); // => ['Bob']
|
|
2433
2602
|
* ```
|
|
2434
2603
|
*/
|
|
2435
|
-
export declare function
|
|
2604
|
+
export declare function filterAndMap<Item, Mapped>(array: Item[], filter: (item: Item, index: number, array: Item[]) => boolean, mapper: (item: Item, index: number, array: Item[]) => Mapped): Mapped[];
|
|
2436
2605
|
/**
|
|
2437
|
-
* Get a mapped and
|
|
2606
|
+
* Get a mapped, flattened, and narrowed array of items
|
|
2438
2607
|
*
|
|
2439
|
-
* _Available as `
|
|
2608
|
+
* _Available as `flatMapAndFilter`, `mapAndFilter.flat`, and `reverseSelect.flat`_
|
|
2440
2609
|
*
|
|
2441
|
-
* @param array Array to
|
|
2442
|
-
* @param
|
|
2443
|
-
* @param
|
|
2444
|
-
* @
|
|
2445
|
-
* @returns Mapped and filtered array of items
|
|
2610
|
+
* @param array Array to select from
|
|
2611
|
+
* @param mapper Callback to map and flatten the items
|
|
2612
|
+
* @param filter Type guard to filter and narrow down the flattened items
|
|
2613
|
+
* @returns Mapped, flattened, and narrowed array of items
|
|
2446
2614
|
*
|
|
2447
2615
|
* @example
|
|
2448
2616
|
* ```typescript
|
|
2449
|
-
*
|
|
2450
|
-
* [{id: 1,
|
|
2451
|
-
* item =>
|
|
2452
|
-
* '
|
|
2453
|
-
*
|
|
2454
|
-
* ); // => [{label: 'Bob'}]
|
|
2617
|
+
* flatMapAndFilter(
|
|
2618
|
+
* [{id: 1, values: [1, 'a']}, {id: 2, values: ['b', 2]}],
|
|
2619
|
+
* item => item.values,
|
|
2620
|
+
* (value): value is number => typeof value === 'number',
|
|
2621
|
+
* ); // => [1, 2]
|
|
2455
2622
|
* ```
|
|
2456
2623
|
*/
|
|
2457
|
-
export declare function
|
|
2624
|
+
export declare function flatMapAndFilter<Item, Mapped, Narrowed extends ArrayFlattened<Mapped>>(array: Item[], mapper: (item: Item, index: number, array: Item[]) => Mapped, filter: (item: ArrayFlattened<Mapped>, index: number, array: Item[]) => item is Narrowed): Narrowed[];
|
|
2458
2625
|
/**
|
|
2459
|
-
* Get a mapped and filtered array of items
|
|
2626
|
+
* Get a mapped, flattened, and filtered array of items
|
|
2460
2627
|
*
|
|
2461
|
-
* _Available as `
|
|
2628
|
+
* _Available as `flatMapAndFilter`, `mapAndFilter.flat`, and `reverseSelect.flat`_
|
|
2462
2629
|
*
|
|
2463
|
-
* @param array Array to
|
|
2464
|
-
* @param
|
|
2465
|
-
* @param
|
|
2466
|
-
* @
|
|
2467
|
-
* @returns Mapped and filtered array of items
|
|
2630
|
+
* @param array Array to select from
|
|
2631
|
+
* @param mapper Callback to map and flatten the items
|
|
2632
|
+
* @param filter Callback to filter the flattened items
|
|
2633
|
+
* @returns Mapped, flattened, and filtered array of items
|
|
2468
2634
|
*
|
|
2469
2635
|
* @example
|
|
2470
2636
|
* ```typescript
|
|
2471
|
-
*
|
|
2472
|
-
* [{
|
|
2473
|
-
*
|
|
2474
|
-
*
|
|
2475
|
-
*
|
|
2476
|
-
* ); // => [{tag: 'b'}]
|
|
2637
|
+
* flatMapAndFilter(
|
|
2638
|
+
* [{id: 1, tags: ['a', 'b']}, {id: 2, tags: ['c']}, {id: 3, tags: ['b', 'd']}],
|
|
2639
|
+
* item => item.tags,
|
|
2640
|
+
* tag => tag !== 'b',
|
|
2641
|
+
* ); // => ['a', 'c', 'd']
|
|
2477
2642
|
* ```
|
|
2478
2643
|
*/
|
|
2479
|
-
export declare function
|
|
2644
|
+
export declare function flatMapAndFilter<Item, Mapped>(array: Item[], mapper: (item: Item, index: number, array: Item[]) => Mapped, filter: (item: ArrayFlattened<Mapped>, index: number, array: Item[]) => boolean): Array<ArrayFlattened<Mapped>>;
|
|
2480
2645
|
/**
|
|
2481
|
-
* Get a mapped and
|
|
2646
|
+
* Get a mapped and narrowed array of items
|
|
2482
2647
|
*
|
|
2483
|
-
* _Available as `reverseSelect`
|
|
2648
|
+
* _Available as `mapAndFilter`, `reverseSelect`, `filterAndMap.reverse`, and `select.reverse`_
|
|
2484
2649
|
*
|
|
2485
|
-
* @param array Array to
|
|
2486
|
-
* @param
|
|
2487
|
-
* @param filter
|
|
2488
|
-
* @returns Mapped and
|
|
2650
|
+
* @param array Array to select from
|
|
2651
|
+
* @param mapper Callback to map the items
|
|
2652
|
+
* @param filter Type guard to filter and narrow down the mapped items
|
|
2653
|
+
* @returns Mapped and narrowed array of items
|
|
2489
2654
|
*
|
|
2490
2655
|
* @example
|
|
2491
2656
|
* ```typescript
|
|
2492
|
-
*
|
|
2493
|
-
* [{id: 1, name: 'Alice'}, {id: 2
|
|
2657
|
+
* mapAndFilter(
|
|
2658
|
+
* [{id: 1, name: 'Alice'}, {id: 2}, {id: 3, name: 'Charlie'}],
|
|
2494
2659
|
* item => item.name,
|
|
2495
|
-
*
|
|
2496
|
-
* ); // => ['
|
|
2660
|
+
* (name): name is string => name != null,
|
|
2661
|
+
* ); // => ['Alice', 'Charlie']
|
|
2497
2662
|
* ```
|
|
2498
2663
|
*/
|
|
2499
|
-
export declare function mapAndFilter<Item,
|
|
2664
|
+
export declare function mapAndFilter<Item, Mapped, Narrowed extends Mapped>(array: Item[], mapper: (item: Item, index: number, array: Item[]) => Mapped, filter: (item: Mapped, index: number, array: Item[]) => item is Narrowed): Narrowed[];
|
|
2500
2665
|
/**
|
|
2501
2666
|
* Get a mapped and filtered array of items
|
|
2502
2667
|
*
|
|
2503
|
-
* _Available as `reverseSelect`
|
|
2668
|
+
* _Available as `mapAndFilter`, `reverseSelect`, `filterAndMap.reverse`, and `select.reverse`_
|
|
2504
2669
|
*
|
|
2505
|
-
* @param array Array to
|
|
2506
|
-
* @param
|
|
2507
|
-
* @param
|
|
2670
|
+
* @param array Array to select from
|
|
2671
|
+
* @param mapper Callback to map the items
|
|
2672
|
+
* @param filter Callback to filter the mapped items
|
|
2508
2673
|
* @returns Mapped and filtered array of items
|
|
2509
2674
|
*
|
|
2510
2675
|
* @example
|
|
2511
2676
|
* ```typescript
|
|
2512
|
-
*
|
|
2513
|
-
* [1, 2,
|
|
2514
|
-
*
|
|
2515
|
-
*
|
|
2516
|
-
* ); // => [
|
|
2677
|
+
* mapAndFilter(
|
|
2678
|
+
* [{id: 1, name: 'Alice'}, {id: 2, name: 'Bob'}, {id: 3, name: 'Charlie'}],
|
|
2679
|
+
* item => item.name,
|
|
2680
|
+
* name => name.length > 3,
|
|
2681
|
+
* ); // => ['Alice', 'Charlie']
|
|
2517
2682
|
* ```
|
|
2518
2683
|
*/
|
|
2519
|
-
export declare function mapAndFilter<Item,
|
|
2684
|
+
export declare function mapAndFilter<Item, Mapped>(array: Item[], mapper: (item: Item, index: number, array: Item[]) => Mapped, filter: (item: Mapped, index: number, array: Item[]) => boolean): Mapped[];
|
|
2520
2685
|
export declare namespace filterAndMap {
|
|
2686
|
+
export var flat: typeof filterAndFlatMap;
|
|
2521
2687
|
export var reverse: typeof mapAndFilter;
|
|
2522
2688
|
}
|
|
2689
|
+
export declare namespace mapAndFilter {
|
|
2690
|
+
export var flat: typeof flatMapAndFilter;
|
|
2691
|
+
}
|
|
2523
2692
|
//#endregion
|
|
2524
2693
|
//#region src/models/array/array.sort.model.d.ts
|
|
2525
2694
|
/**
|
|
@@ -2649,6 +2818,11 @@ declare function Sorter(this: any, sorters: SortHandler[]): void;
|
|
|
2649
2818
|
* @param sorters Sorters to use to determine sorting
|
|
2650
2819
|
* @param descending Sorted in descending order? _(defaults to `false`; overridden by individual sorters)_
|
|
2651
2820
|
* @returns Index for item
|
|
2821
|
+
*
|
|
2822
|
+
* @example
|
|
2823
|
+
* ```typescript
|
|
2824
|
+
* getSortedIndex([1, 3, 2], 2, [{key: 'value', direction: 'asc'}]); // => 1
|
|
2825
|
+
* ```
|
|
2652
2826
|
*/
|
|
2653
2827
|
export declare function getSortedIndex<Item>(array: Item[], item: Item, sorters: Array<ArraySorter<Item>>, descending?: boolean): number;
|
|
2654
2828
|
/**
|
|
@@ -2663,6 +2837,11 @@ export declare function getSortedIndex<Item>(array: Item[], item: Item, sorters:
|
|
|
2663
2837
|
* @param sorter Sorter to use to determine sorting
|
|
2664
2838
|
* @param descending Sorted in descending order? _(defaults to `false`; overridden by individual sorters)_
|
|
2665
2839
|
* @returns Index for item
|
|
2840
|
+
*
|
|
2841
|
+
* @example
|
|
2842
|
+
* ```typescript
|
|
2843
|
+
* getSortedIndex([1, 3, 2], 2, {key: 'value', direction: 'asc'}); // => 1
|
|
2844
|
+
* ```
|
|
2666
2845
|
*/
|
|
2667
2846
|
export declare function getSortedIndex<Item>(array: Item[], item: Item, sorter: ArraySorter<Item>, descending?: boolean): number;
|
|
2668
2847
|
/**
|
|
@@ -2676,6 +2855,11 @@ export declare function getSortedIndex<Item>(array: Item[], item: Item, sorter:
|
|
|
2676
2855
|
* @param item Item to get the index for
|
|
2677
2856
|
* @param descending Sorted in descending order? _(defaults to `false`)_
|
|
2678
2857
|
* @returns Index for item
|
|
2858
|
+
*
|
|
2859
|
+
* @example
|
|
2860
|
+
* ```typescript
|
|
2861
|
+
* getSortedIndex([1, 3, 2], 2); // => 1
|
|
2862
|
+
* ```
|
|
2679
2863
|
*/
|
|
2680
2864
|
export declare function getSortedIndex<Item>(array: Item[], item: Item, descending?: boolean): number;
|
|
2681
2865
|
/**
|
|
@@ -2716,6 +2900,12 @@ export declare function initializeSorter<Item>(descending?: boolean): Sorter<Ite
|
|
|
2716
2900
|
* @param sorters Sorters to determine sorting
|
|
2717
2901
|
* @param descending Sorted in descending order? _(defaults to `false`; overridden by individual sorters)_
|
|
2718
2902
|
* @returns `true` if sorted, otherwise `false`
|
|
2903
|
+
*
|
|
2904
|
+
* @example
|
|
2905
|
+
* ```typescript
|
|
2906
|
+
* isSorted([1, 2, 3], [{key: 'value', direction: 'asc'}]); // => true
|
|
2907
|
+
* isSorted([3, 2, 1], [{key: 'value', direction: 'asc'}]); // => false
|
|
2908
|
+
* ```
|
|
2719
2909
|
*/
|
|
2720
2910
|
export declare function isSorted<Item>(array: Item[], sorters: Array<ArraySorter<Item>>, descending?: boolean): boolean;
|
|
2721
2911
|
/**
|
|
@@ -2727,6 +2917,12 @@ export declare function isSorted<Item>(array: Item[], sorters: Array<ArraySorter
|
|
|
2727
2917
|
* @param sorter Sorter to determine sorting
|
|
2728
2918
|
* @param descending Sorted in descending order? _(defaults to `false`; overridden by individual sorters)_
|
|
2729
2919
|
* @returns `true` if sorted, otherwise `false`
|
|
2920
|
+
*
|
|
2921
|
+
* @example
|
|
2922
|
+
* ```typescript
|
|
2923
|
+
* isSorted([1, 2, 3], {key: 'value', direction: 'asc'}); // => true
|
|
2924
|
+
* isSorted([3, 2, 1], {key: 'value', direction: 'asc'}); // => false
|
|
2925
|
+
* ```
|
|
2730
2926
|
*/
|
|
2731
2927
|
export declare function isSorted<Item>(array: Item[], sorter: ArraySorter<Item>, descending?: boolean): boolean;
|
|
2732
2928
|
/**
|
|
@@ -2737,6 +2933,12 @@ export declare function isSorted<Item>(array: Item[], sorter: ArraySorter<Item>,
|
|
|
2737
2933
|
* @param array Array to check
|
|
2738
2934
|
* @param descending Sorted in descending order? _(defaults to `false`)_
|
|
2739
2935
|
* @returns `true` if sorted, otherwise `false`
|
|
2936
|
+
*
|
|
2937
|
+
* @example
|
|
2938
|
+
* ```typescript
|
|
2939
|
+
* isSorted([1, 2, 3]); // => true
|
|
2940
|
+
* isSorted([3, 2, 1]); // => false
|
|
2941
|
+
* ```
|
|
2740
2942
|
*/
|
|
2741
2943
|
export declare function isSorted<Item>(array: Item[], descending?: boolean): boolean;
|
|
2742
2944
|
/**
|
|
@@ -2763,6 +2965,14 @@ export declare function sort<Item>(array: Item[], comparator: (first: Item, seco
|
|
|
2763
2965
|
* @param sorters Sorters to use for sorting
|
|
2764
2966
|
* @param descending Sort in descending order? _(defaults to `false`; overridden by individual sorters)_
|
|
2765
2967
|
* @returns Sorted array
|
|
2968
|
+
*
|
|
2969
|
+
* @example
|
|
2970
|
+
* ```typescript
|
|
2971
|
+
* sort(
|
|
2972
|
+
* [{id: 3}, {id: 1}, {id: 2}],
|
|
2973
|
+
* [{key: 'id', direction: 'asc'}],
|
|
2974
|
+
* ); // => [{id: 1}, {id: 2}, {id: 3}]
|
|
2975
|
+
* ```
|
|
2766
2976
|
*/
|
|
2767
2977
|
export declare function sort<Item>(array: Item[], sorters: Array<ArraySorter<Item>>, descending?: boolean): Item[];
|
|
2768
2978
|
/**
|
|
@@ -2772,6 +2982,14 @@ export declare function sort<Item>(array: Item[], sorters: Array<ArraySorter<Ite
|
|
|
2772
2982
|
* @param sorter Sorter to use for sorting
|
|
2773
2983
|
* @param descending Sort in descending order? _(defaults to `false`; overridden by individual sorters)_
|
|
2774
2984
|
* @returns Sorted array
|
|
2985
|
+
*
|
|
2986
|
+
* @example
|
|
2987
|
+
* ```typescript
|
|
2988
|
+
* sort(
|
|
2989
|
+
* [{id: 3}, {id: 1}, {id: 2}],
|
|
2990
|
+
* {key: 'id', direction: 'asc'},
|
|
2991
|
+
* ); // => [{id: 1}, {id: 2}, {id: 3}]
|
|
2992
|
+
* ```
|
|
2775
2993
|
*/
|
|
2776
2994
|
export declare function sort<Item>(array: Item[], sorter: ArraySorter<Item>, descending?: boolean): Item[];
|
|
2777
2995
|
/**
|
|
@@ -2780,6 +2998,11 @@ export declare function sort<Item>(array: Item[], sorter: ArraySorter<Item>, des
|
|
|
2780
2998
|
* @param array Array to sort
|
|
2781
2999
|
* @param descending Sort in descending order? _(defaults to `false`)_
|
|
2782
3000
|
* @returns Sorted array
|
|
3001
|
+
*
|
|
3002
|
+
* @example
|
|
3003
|
+
* ```typescript
|
|
3004
|
+
* sort([3, 1, 2]); // => [1, 2, 3]
|
|
3005
|
+
* ```
|
|
2783
3006
|
*/
|
|
2784
3007
|
export declare function sort<Item>(array: Item[], descending?: boolean): Item[];
|
|
2785
3008
|
export declare namespace sort {
|
|
@@ -4200,6 +4423,14 @@ export declare namespace pipe {
|
|
|
4200
4423
|
*
|
|
4201
4424
|
* @param value String to convert
|
|
4202
4425
|
* @returns Camel-cased string
|
|
4426
|
+
*
|
|
4427
|
+
* @example
|
|
4428
|
+
* ```typescript
|
|
4429
|
+
* camelCase('this is camel case'); // => 'thisIsCamelCase'
|
|
4430
|
+
* camelCase('ThisIsCamelCase'); // => 'thisIsCamelCase'
|
|
4431
|
+
* camelCase('this-is-camel-case'); // => 'thisIsCamelCase'
|
|
4432
|
+
* camelCase('this_is_camel_case'); // => 'thisIsCamelCase'
|
|
4433
|
+
* ```
|
|
4203
4434
|
*/
|
|
4204
4435
|
export declare function camelCase(value: string): string;
|
|
4205
4436
|
/**
|
|
@@ -4207,6 +4438,14 @@ export declare function camelCase(value: string): string;
|
|
|
4207
4438
|
*
|
|
4208
4439
|
* @param value String to capitalize
|
|
4209
4440
|
* @returns Capitalized string
|
|
4441
|
+
*
|
|
4442
|
+
* @example
|
|
4443
|
+
* ```typescript
|
|
4444
|
+
* capitalize('this is a test'); // => 'This is a test'
|
|
4445
|
+
* capitalize('This Is A Test'); // => 'This is a test'
|
|
4446
|
+
* capitalize('t'); // => 'T'
|
|
4447
|
+
* capitalize(''); // => ''
|
|
4448
|
+
* ```
|
|
4210
4449
|
*/
|
|
4211
4450
|
export declare function capitalize(value: string): string;
|
|
4212
4451
|
/**
|
|
@@ -4214,6 +4453,14 @@ export declare function capitalize(value: string): string;
|
|
|
4214
4453
|
*
|
|
4215
4454
|
* @param value String to convert
|
|
4216
4455
|
* @returns Kebab-cased string
|
|
4456
|
+
*
|
|
4457
|
+
* @example
|
|
4458
|
+
* ```typescript
|
|
4459
|
+
* kebabCase('this is kebab case'); // => 'this-is-kebab-case'
|
|
4460
|
+
* kebabCase('ThisIsKebabCase'); // => 'this-is-kebab-case'
|
|
4461
|
+
* kebabCase('this-is-kebab-case'); // => 'this-is-kebab-case'
|
|
4462
|
+
* kebabCase('this_is_kebab_case'); // => 'this-is-kebab-case'
|
|
4463
|
+
* ```
|
|
4217
4464
|
*/
|
|
4218
4465
|
export declare function kebabCase(value: string): string;
|
|
4219
4466
|
/**
|
|
@@ -4221,6 +4468,13 @@ export declare function kebabCase(value: string): string;
|
|
|
4221
4468
|
*
|
|
4222
4469
|
* @param value String to convert
|
|
4223
4470
|
* @returns Lower-cased string
|
|
4471
|
+
*
|
|
4472
|
+
* @example
|
|
4473
|
+
* ```typescript
|
|
4474
|
+
* lowerCase('THIS IS A TEST'); // => 'this is a test'
|
|
4475
|
+
* lowerCase('this is a test'); // => 'this is a test'
|
|
4476
|
+
* lowerCase('t'); // => 't'
|
|
4477
|
+
* ```
|
|
4224
4478
|
*/
|
|
4225
4479
|
export declare function lowerCase(value: string): string;
|
|
4226
4480
|
/**
|
|
@@ -4228,6 +4482,14 @@ export declare function lowerCase(value: string): string;
|
|
|
4228
4482
|
*
|
|
4229
4483
|
* @param value String to convert
|
|
4230
4484
|
* @returns Pascal-cased string
|
|
4485
|
+
*
|
|
4486
|
+
* @example
|
|
4487
|
+
* ```typescript
|
|
4488
|
+
* pascalCase('this is pascal case'); // => 'ThisIsPascalCase'
|
|
4489
|
+
* pascalCase('ThisIsPascalCase'); // => 'ThisIsPascalCase'
|
|
4490
|
+
* pascalCase('this-is-pascal-case'); // => 'ThisIsPascalCase'
|
|
4491
|
+
* pascalCase('this_is_pascal_case'); // => 'ThisIsPascalCase'
|
|
4492
|
+
* ```
|
|
4231
4493
|
*/
|
|
4232
4494
|
export declare function pascalCase(value: string): string;
|
|
4233
4495
|
/**
|
|
@@ -4235,6 +4497,14 @@ export declare function pascalCase(value: string): string;
|
|
|
4235
4497
|
*
|
|
4236
4498
|
* @param value String to convert
|
|
4237
4499
|
* @returns Snake-cased string
|
|
4500
|
+
*
|
|
4501
|
+
* @example
|
|
4502
|
+
* ```typescript
|
|
4503
|
+
* snakeCase('this is snake case'); // => 'this_is_snake_case'
|
|
4504
|
+
* snakeCase('ThisIsSnakeCase'); // => 'this_is_snake_case'
|
|
4505
|
+
* snakeCase('this-is-snake-case'); // => 'this_is_snake_case'
|
|
4506
|
+
* snakeCase('this_is_snake_case'); // => 'this_is_snake_case'
|
|
4507
|
+
* ```
|
|
4238
4508
|
*/
|
|
4239
4509
|
export declare function snakeCase(value: string): string;
|
|
4240
4510
|
/**
|
|
@@ -4242,6 +4512,14 @@ export declare function snakeCase(value: string): string;
|
|
|
4242
4512
|
*
|
|
4243
4513
|
* @param value String to convert
|
|
4244
4514
|
* @returns Title-cased string
|
|
4515
|
+
*
|
|
4516
|
+
* @example
|
|
4517
|
+
* ```typescript
|
|
4518
|
+
* titleCase('this is a test'); // => 'This Is A Test'
|
|
4519
|
+
* titleCase('This Is A Test'); // => 'This Is A Test'
|
|
4520
|
+
* titleCase('t'); // => 'T'
|
|
4521
|
+
* titleCase(''); // => ''
|
|
4522
|
+
* ```
|
|
4245
4523
|
*/
|
|
4246
4524
|
export declare function titleCase(value: string): string;
|
|
4247
4525
|
/**
|
|
@@ -4249,6 +4527,14 @@ export declare function titleCase(value: string): string;
|
|
|
4249
4527
|
*
|
|
4250
4528
|
* @param value String to convert
|
|
4251
4529
|
* @returns Upper-cased string
|
|
4530
|
+
*
|
|
4531
|
+
* @example
|
|
4532
|
+
* ```typescript
|
|
4533
|
+
* upperCase('this is a test'); // => 'THIS IS A TEST'
|
|
4534
|
+
* upperCase('This Is A Test'); // => 'THIS IS A TEST'
|
|
4535
|
+
* upperCase('t'); // => 'T'
|
|
4536
|
+
* upperCase(''); // => ''
|
|
4537
|
+
* ```
|
|
4252
4538
|
*/
|
|
4253
4539
|
export declare function upperCase(value: string): string;
|
|
4254
4540
|
//#endregion
|
|
@@ -4271,7 +4557,13 @@ export declare function upperCase(value: string): string;
|
|
|
4271
4557
|
* ```
|
|
4272
4558
|
*/
|
|
4273
4559
|
export declare function getString(value: unknown): string;
|
|
4560
|
+
/**
|
|
4561
|
+
* @internal
|
|
4562
|
+
*/
|
|
4274
4563
|
export declare function ignoreKey(key: string): boolean;
|
|
4564
|
+
/**
|
|
4565
|
+
* @internal
|
|
4566
|
+
*/
|
|
4275
4567
|
export declare function interpolate(strings: TemplateStringsArray, values: unknown[]): string;
|
|
4276
4568
|
/**
|
|
4277
4569
|
* Join an array of values into a string _(while ignoring empty values)_
|
|
@@ -4281,9 +4573,23 @@ export declare function interpolate(strings: TemplateStringsArray, values: unkno
|
|
|
4281
4573
|
* @param array Array of values
|
|
4282
4574
|
* @param delimiter Delimiter to use between values
|
|
4283
4575
|
* @returns Joined string
|
|
4576
|
+
* @example
|
|
4577
|
+
* ```typescript
|
|
4578
|
+
* join(['a', 'b', 'c']); // => 'abc'
|
|
4579
|
+
* join(['a', 'b', 'c'], ', '); // => 'a, b, c'
|
|
4580
|
+
* join(['a', '', 'c']); // => 'ac'
|
|
4581
|
+
* join([null, 'b', undefined]); // => 'b'
|
|
4582
|
+
* join([]); // => ''
|
|
4583
|
+
* ```
|
|
4284
4584
|
*/
|
|
4285
4585
|
export declare function join(array: unknown[], delimiter?: string): string;
|
|
4586
|
+
/**
|
|
4587
|
+
* @internal
|
|
4588
|
+
*/
|
|
4286
4589
|
export declare function tryDecode(value: string): string;
|
|
4590
|
+
/**
|
|
4591
|
+
* @internal
|
|
4592
|
+
*/
|
|
4287
4593
|
export declare function tryEncode(value: boolean | number | string): unknown;
|
|
4288
4594
|
/**
|
|
4289
4595
|
* Split a string into words _(and other readable parts)_
|
|
@@ -5530,7 +5836,13 @@ export declare function isRejected(value: unknown): value is RejectedPromise;
|
|
|
5530
5836
|
* @returns Cancelable _Promise_
|
|
5531
5837
|
*/
|
|
5532
5838
|
export declare function cancelable<Value>(executor: (resolve: (value: Value) => void, reject: (reason: unknown) => void) => void): CancelablePromise<Value>;
|
|
5839
|
+
/**
|
|
5840
|
+
* @internal
|
|
5841
|
+
*/
|
|
5533
5842
|
export declare function handleResult(status: string, parameters: PromiseParameters): void;
|
|
5843
|
+
/**
|
|
5844
|
+
* @internal
|
|
5845
|
+
*/
|
|
5534
5846
|
export declare function settlePromise(settler: (value: any) => void, value: unknown, aborter?: Aborter): void;
|
|
5535
5847
|
/**
|
|
5536
5848
|
* Converts a _Promise_ to a promised result
|
|
@@ -5548,6 +5860,9 @@ export declare function toResult<Value>(callback: () => Promise<Value>): Promise
|
|
|
5548
5860
|
export declare function toResult<Value>(promise: Promise<Value>): Promise<Result<Value>>;
|
|
5549
5861
|
//#endregion
|
|
5550
5862
|
//#region src/promise/timed.d.ts
|
|
5863
|
+
/**
|
|
5864
|
+
* @internal
|
|
5865
|
+
*/
|
|
5551
5866
|
export declare function getTimedPromise<Value>(promise: Promise<Value>, time: number, signal?: AbortSignal): Promise<Value>;
|
|
5552
5867
|
/**
|
|
5553
5868
|
* Create a _Promise_ that should be settled within a certain amount of time
|
|
@@ -6052,26 +6367,28 @@ type Fuzzy<Item> = {
|
|
|
6052
6367
|
*
|
|
6053
6368
|
* @param value Value to search for
|
|
6054
6369
|
* @param options Search options
|
|
6055
|
-
* @returns Search results, with exact
|
|
6370
|
+
* @returns Search results, with exact, included, and similar matches
|
|
6056
6371
|
*/
|
|
6057
6372
|
search(value: string, options?: FuzzyOptions): FuzzyResult<Item>;
|
|
6058
6373
|
/**
|
|
6059
6374
|
* Search for items matching the given value
|
|
6060
6375
|
*
|
|
6061
6376
|
* @param value Value to search for
|
|
6062
|
-
* @param limit Maximum number of combined items to return in `exact` and `similar`
|
|
6063
|
-
* @returns Search results, with exact
|
|
6377
|
+
* @param limit Maximum number of combined items to return in `exact`, `included`, and `similar`
|
|
6378
|
+
* @returns Search results, with exact, included, and similar matches
|
|
6064
6379
|
*/
|
|
6065
6380
|
search(value: string, limit: number): FuzzyResult<Item>;
|
|
6066
6381
|
};
|
|
6067
6382
|
type FuzzyConfiguration<Item> = {
|
|
6383
|
+
handler?: (item: Item) => string;
|
|
6068
6384
|
/**
|
|
6069
|
-
*
|
|
6385
|
+
* Function to compare the stringified items for results _(defaults to `Intl.Collator().compare`)_
|
|
6070
6386
|
*
|
|
6071
|
-
*
|
|
6072
|
-
*
|
|
6387
|
+
* @param first First string to compare
|
|
6388
|
+
* @param second Second string to compare
|
|
6389
|
+
* @returns Comparison result, similar to `Array.prototype.sort` callback
|
|
6073
6390
|
*/
|
|
6074
|
-
|
|
6391
|
+
compare?: (first: string, second: string) => number;
|
|
6075
6392
|
} & (Item extends PlainObject ? {
|
|
6076
6393
|
/**
|
|
6077
6394
|
* Key to use to stringify items
|
|
@@ -6080,13 +6397,13 @@ type FuzzyConfiguration<Item> = {
|
|
|
6080
6397
|
*/
|
|
6081
6398
|
key?: keyof Item;
|
|
6082
6399
|
} : {}) & FuzzyOptions;
|
|
6083
|
-
type FuzzyItem<
|
|
6084
|
-
|
|
6085
|
-
|
|
6400
|
+
type FuzzyItem<Data> = {
|
|
6401
|
+
data: Data;
|
|
6402
|
+
string: FuzzyString;
|
|
6086
6403
|
};
|
|
6087
6404
|
type FuzzyOptions = {
|
|
6088
6405
|
/**
|
|
6089
|
-
* Maximum number of combined items to return in `exact` and `similar` _(defaults to all matches)_
|
|
6406
|
+
* Maximum number of combined items to return in `exact`, `included`, and `similar` _(defaults to all matches)_
|
|
6090
6407
|
*/
|
|
6091
6408
|
limit?: number;
|
|
6092
6409
|
/**
|
|
@@ -6097,29 +6414,56 @@ type FuzzyOptions = {
|
|
|
6097
6414
|
*/
|
|
6098
6415
|
tolerance?: number;
|
|
6099
6416
|
};
|
|
6417
|
+
type FuzzyRanked<Data> = {
|
|
6418
|
+
position: number;
|
|
6419
|
+
/**
|
|
6420
|
+
* `0` for starting with the value, `1` for the value starting a word, `2` for anything else
|
|
6421
|
+
*/
|
|
6422
|
+
rank: number;
|
|
6423
|
+
} & FuzzyItem<Data>;
|
|
6100
6424
|
/**
|
|
6101
|
-
* Search results from a fuzzy search, with exact and similar matches
|
|
6425
|
+
* Search results from a fuzzy search, with exact, included, and similar matches
|
|
6102
6426
|
*/
|
|
6103
6427
|
type FuzzyResult<Item> = {
|
|
6104
6428
|
/**
|
|
6105
|
-
*
|
|
6429
|
+
* Items whose strings exactly match the search value, ordered alphabetically
|
|
6106
6430
|
*/
|
|
6107
6431
|
exact: Item[];
|
|
6108
6432
|
/**
|
|
6109
|
-
*
|
|
6433
|
+
* Items whose strings contain the search value, ordered alphabetically
|
|
6434
|
+
*/
|
|
6435
|
+
included: Item[];
|
|
6436
|
+
/**
|
|
6437
|
+
* Items whose strings are similar to the search value, ranked by relevance, sorted by score, and ordered alphabetically within the same score
|
|
6110
6438
|
*/
|
|
6111
6439
|
similar: Item[];
|
|
6112
6440
|
};
|
|
6113
6441
|
type FuzzyState<Item> = {
|
|
6442
|
+
compare: FuzzyStateCompare<Item>;
|
|
6114
6443
|
handler(item: Item): string;
|
|
6115
|
-
items: Item
|
|
6116
|
-
limit
|
|
6117
|
-
strings: string[];
|
|
6444
|
+
items: FuzzyStateItems<Item>;
|
|
6445
|
+
limit: number;
|
|
6118
6446
|
tolerance: number;
|
|
6119
6447
|
};
|
|
6448
|
+
type FuzzyStateCompare<Item = unknown> = {
|
|
6449
|
+
item: (first: FuzzyItem<Item>, second: FuzzyItem<Item>) => number;
|
|
6450
|
+
ranked: (first: FuzzyRanked<Item>, second: FuzzyRanked<Item>) => number;
|
|
6451
|
+
};
|
|
6452
|
+
type FuzzyStateItems<Item> = {
|
|
6453
|
+
original: Array<FuzzyItem<Item>>;
|
|
6454
|
+
sorted?: Array<FuzzyItem<Item>>;
|
|
6455
|
+
};
|
|
6456
|
+
type FuzzyString = {
|
|
6457
|
+
lowercase: string;
|
|
6458
|
+
original: string;
|
|
6459
|
+
};
|
|
6460
|
+
type InternalFuzzy<Item = unknown> = {
|
|
6461
|
+
[FUZZY_SYMBOL]: FuzzyState<Item>;
|
|
6462
|
+
} & Fuzzy<Item>;
|
|
6463
|
+
declare const FUZZY_SYMBOL: unique symbol;
|
|
6120
6464
|
//#endregion
|
|
6121
6465
|
//#region src/string/fuzzy.d.ts
|
|
6122
|
-
declare function Fuzzy(this:
|
|
6466
|
+
declare function Fuzzy(this: InternalFuzzy, state: FuzzyState<unknown>): void;
|
|
6123
6467
|
/**
|
|
6124
6468
|
* Create a fuzzy searcher for an array of items
|
|
6125
6469
|
*
|
|
@@ -6200,7 +6544,7 @@ export declare function getUuid(): string;
|
|
|
6200
6544
|
*
|
|
6201
6545
|
* @param value JSON string to parse
|
|
6202
6546
|
* @param reviver Reviver function to transform the parsed values
|
|
6203
|
-
* @returns Parsed value or `undefined` if parsing fails
|
|
6547
|
+
* @returns Parsed value, or `undefined` if parsing fails
|
|
6204
6548
|
*/
|
|
6205
6549
|
export declare function parse(value: string, reviver?: (this: unknown, key: string, value: unknown) => unknown): unknown;
|
|
6206
6550
|
/**
|
|
@@ -6208,6 +6552,13 @@ export declare function parse(value: string, reviver?: (this: unknown, key: stri
|
|
|
6208
6552
|
*
|
|
6209
6553
|
* @param value String to trim
|
|
6210
6554
|
* @returns Trimmed string
|
|
6555
|
+
* @example
|
|
6556
|
+
* ```typescript
|
|
6557
|
+
* trim(' this is a test '); // => 'this is a test'
|
|
6558
|
+
* trim('this is a test'); // => 'this is a test'
|
|
6559
|
+
* trim(' '); // => ''
|
|
6560
|
+
* trim(''); // => ''
|
|
6561
|
+
* ```
|
|
6211
6562
|
*/
|
|
6212
6563
|
export declare function trim(value: string): string;
|
|
6213
6564
|
/**
|
|
@@ -6217,6 +6568,13 @@ export declare function trim(value: string): string;
|
|
|
6217
6568
|
* @param length Maximum length of the string after truncation
|
|
6218
6569
|
* @param suffix Suffix to append to the truncated string
|
|
6219
6570
|
* @returns Truncated string
|
|
6571
|
+
* @example
|
|
6572
|
+
* ```typescript
|
|
6573
|
+
* truncate('this is a test', 7); // => 'this is'
|
|
6574
|
+
* truncate('this is a test', 7, '...'); // => 'this ...'
|
|
6575
|
+
* truncate('this is a test', 20); // => 'this is a test'
|
|
6576
|
+
* truncate('this is a test', 0); // => ''
|
|
6577
|
+
* ```
|
|
6220
6578
|
*/
|
|
6221
6579
|
export declare function truncate(value: string, length: number, suffix?: string): string;
|
|
6222
6580
|
//#endregion
|
|
@@ -6228,6 +6586,14 @@ export declare function truncate(value: string, length: number, suffix?: string)
|
|
|
6228
6586
|
* @param needle String to look for
|
|
6229
6587
|
* @param ignoreCase Ignore case when matching? _(defaults to `false`)_
|
|
6230
6588
|
* @returns `true` if the string ends with the given substring, otherwise `false`
|
|
6589
|
+
*
|
|
6590
|
+
* @example
|
|
6591
|
+
* ```typescript
|
|
6592
|
+
* endsWith('this is a test', 'test'); // => true
|
|
6593
|
+
* endsWith('this is a test', 'Test'); // => false
|
|
6594
|
+
* endsWith('this is a test', 'Test', true); // => true
|
|
6595
|
+
* endsWith('this is a test', 'not'); // => false
|
|
6596
|
+
* ```
|
|
6231
6597
|
*/
|
|
6232
6598
|
export declare function endsWith(haystack: string, needle: string, ignoreCase?: boolean): boolean;
|
|
6233
6599
|
/**
|
|
@@ -6237,6 +6603,14 @@ export declare function endsWith(haystack: string, needle: string, ignoreCase?:
|
|
|
6237
6603
|
* @param needle String to look for
|
|
6238
6604
|
* @param ignoreCase Ignore case when matching? _(defaults to `false`)_
|
|
6239
6605
|
* @returns `true` if the string includes the given substring, otherwise `false`
|
|
6606
|
+
*
|
|
6607
|
+
* @example
|
|
6608
|
+
* ```typescript
|
|
6609
|
+
* includes('this is a test', 'is'); // => true
|
|
6610
|
+
* includes('this is a test', 'Is'); // => false
|
|
6611
|
+
* includes('this is a test', 'Is', true); // => true
|
|
6612
|
+
* includes('this is a test', 'not'); // => false
|
|
6613
|
+
* ```
|
|
6240
6614
|
*/
|
|
6241
6615
|
export declare function includes(haystack: string, needle: string, ignoreCase?: boolean): boolean;
|
|
6242
6616
|
/**
|
|
@@ -6246,6 +6620,14 @@ export declare function includes(haystack: string, needle: string, ignoreCase?:
|
|
|
6246
6620
|
* @param needle String to look for
|
|
6247
6621
|
* @param ignoreCase Ignore case when matching? _(defaults to `false`)_
|
|
6248
6622
|
* @returns `true` if the string starts with the given substring, otherwise `false`
|
|
6623
|
+
*
|
|
6624
|
+
* @example
|
|
6625
|
+
* ```typescript
|
|
6626
|
+
* startsWith('this is a test', 'this'); // => true
|
|
6627
|
+
* startsWith('this is a test', 'This'); // => false
|
|
6628
|
+
* startsWith('this is a test', 'This', true); // => true
|
|
6629
|
+
* startsWith('this is a test', 'not'); // => false
|
|
6630
|
+
* ```
|
|
6249
6631
|
*/
|
|
6250
6632
|
export declare function startsWith(haystack: string, needle: string, ignoreCase?: boolean): boolean;
|
|
6251
6633
|
//#endregion
|
|
@@ -6391,6 +6773,10 @@ export declare function template(strings: TemplateStringsArray, ...values: unkno
|
|
|
6391
6773
|
* @param variables Variables to use
|
|
6392
6774
|
* @param options Templating options
|
|
6393
6775
|
* @returns Templated string
|
|
6776
|
+
* @example
|
|
6777
|
+
* ```typescript
|
|
6778
|
+
* template('Hello, {{name}}!', {name: 'World'}); // => 'Hello, World!'
|
|
6779
|
+
* ```
|
|
6394
6780
|
*/
|
|
6395
6781
|
export declare function template(value: string, variables?: PlainObject, options?: Partial<TemplateOptions>): string;
|
|
6396
6782
|
export declare namespace template {
|
|
@@ -6769,7 +7155,7 @@ type BaseOptions = {
|
|
|
6769
7155
|
/**
|
|
6770
7156
|
* Key _(or key epxressions)_ for values that should be replaced
|
|
6771
7157
|
*
|
|
6772
|
-
* ```
|
|
7158
|
+
* ```typescript
|
|
6773
7159
|
* merge([{items: [1, 2, 3]}, {items: [99]}]); // => {items: [99]}
|
|
6774
7160
|
* ```
|
|
6775
7161
|
*/
|
|
@@ -6777,7 +7163,7 @@ type BaseOptions = {
|
|
|
6777
7163
|
/**
|
|
6778
7164
|
* Skip nullable values when merging objects?
|
|
6779
7165
|
*
|
|
6780
|
-
* ```
|
|
7166
|
+
* ```typescript
|
|
6781
7167
|
* merge({a: 1, b: 2}, {b: null, c: 3}, {d: null}); // => {a: 1, b: 2, c: 3}
|
|
6782
7168
|
* ```
|
|
6783
7169
|
*/
|
|
@@ -6785,7 +7171,7 @@ type BaseOptions = {
|
|
|
6785
7171
|
/**
|
|
6786
7172
|
* Skip nullable values when merging arrays?
|
|
6787
7173
|
*
|
|
6788
|
-
* ```
|
|
7174
|
+
* ```typescript
|
|
6789
7175
|
* merge([1, 2, 3], [null, null, 99]); // => [1, 2, 99]
|
|
6790
7176
|
* ```
|
|
6791
7177
|
*/
|
|
@@ -7676,6 +8062,14 @@ export declare function isRgbColor(value: unknown): value is RGBColor;
|
|
|
7676
8062
|
* @param value Value to normalize
|
|
7677
8063
|
* @param alpha Include alpha channel _(opacity)_? _(defaults to `false`)_
|
|
7678
8064
|
* @returns Normalized hex color
|
|
8065
|
+
*
|
|
8066
|
+
* @example
|
|
8067
|
+
* ```typescript
|
|
8068
|
+
* getNormalizedHex('#abc'); // => '#aabbcc'
|
|
8069
|
+
* getNormalizedHex('#abc', true); // => '#aabbccff'
|
|
8070
|
+
* getNormalizedHex(123); // => '#000000'
|
|
8071
|
+
* getNormalizedHex(123, true); // => '#000000ff'
|
|
8072
|
+
* ```
|
|
7679
8073
|
*/
|
|
7680
8074
|
export declare function getNormalizedHex(value: unknown, alpha?: boolean): string;
|
|
7681
8075
|
/**
|
|
@@ -8220,7 +8614,19 @@ type TimeLogger = {
|
|
|
8220
8614
|
//#endregion
|
|
8221
8615
|
//#region src/logger.d.ts
|
|
8222
8616
|
declare function TimeLogger(this: any, label: string): void;
|
|
8617
|
+
/**
|
|
8618
|
+
* Is the value a _Logger_?
|
|
8619
|
+
*
|
|
8620
|
+
* @param value Value to check
|
|
8621
|
+
* @returns `true` if the value is a _Logger_, otherwise `false`
|
|
8622
|
+
*/
|
|
8223
8623
|
declare function isLogger(value: unknown): value is Lumberjack;
|
|
8624
|
+
/**
|
|
8625
|
+
* Is the value a _TimeLogger_?
|
|
8626
|
+
*
|
|
8627
|
+
* @param value Value to check
|
|
8628
|
+
* @returns `true` if the value is a _TimeLogger_, otherwise `false`
|
|
8629
|
+
*/
|
|
8224
8630
|
declare function isTimeLogger(value: unknown): value is TimeLogger;
|
|
8225
8631
|
/**
|
|
8226
8632
|
* A logger that can be used to log messages to the console
|
|
@@ -8233,6 +8639,11 @@ declare const Logger: Lumberjack;
|
|
|
8233
8639
|
/**
|
|
8234
8640
|
* Get the maximum value from a list of items
|
|
8235
8641
|
*
|
|
8642
|
+
* @param items List of items
|
|
8643
|
+
* @param callback Callback to get an item's value
|
|
8644
|
+
* @param first Return only the first item with the maximum value
|
|
8645
|
+
* @returns Item with the maximum value, or `undefined` if no maximum can be found
|
|
8646
|
+
*
|
|
8236
8647
|
* @example
|
|
8237
8648
|
* ```typescript
|
|
8238
8649
|
* max(
|
|
@@ -8242,16 +8653,16 @@ declare const Logger: Lumberjack;
|
|
|
8242
8653
|
*
|
|
8243
8654
|
* max([], item => item.value); // => []
|
|
8244
8655
|
* ```
|
|
8245
|
-
*
|
|
8246
|
-
* @param items List of items
|
|
8247
|
-
* @param callback Callback to get an item's value
|
|
8248
|
-
* @param first Return only the first item with the maximum value
|
|
8249
|
-
* @returns Item with the maximum value, or `undefined` if no maximum can be found
|
|
8250
8656
|
*/
|
|
8251
8657
|
export declare function max<Item>(items: Item[], callback: (item: Item, index: number, array: Item[]) => number, first: true): Item | undefined;
|
|
8252
8658
|
/**
|
|
8253
8659
|
* Get the maximum value from a list of items
|
|
8254
8660
|
*
|
|
8661
|
+
* @param items List of items
|
|
8662
|
+
* @param key Key to use for value
|
|
8663
|
+
* @param first Return only the first item with the maximum value
|
|
8664
|
+
* @returns Item with the maximum value, or `undefined` if no maximum can be found
|
|
8665
|
+
*
|
|
8255
8666
|
* @example
|
|
8256
8667
|
* ```typescript
|
|
8257
8668
|
* max(
|
|
@@ -8261,16 +8672,15 @@ export declare function max<Item>(items: Item[], callback: (item: Item, index: n
|
|
|
8261
8672
|
*
|
|
8262
8673
|
* max([], 'value'); // => []
|
|
8263
8674
|
* ```
|
|
8264
|
-
*
|
|
8265
|
-
* @param items List of items
|
|
8266
|
-
* @param key Key to use for value
|
|
8267
|
-
* @param first Return only the first item with the maximum value
|
|
8268
|
-
* @returns Item with the maximum value, or `undefined` if no maximum can be found
|
|
8269
8675
|
*/
|
|
8270
8676
|
export declare function max<Item extends PlainObject>(items: Item[], key: keyof NumericalValues<Item>, first: true): Item | undefined;
|
|
8271
8677
|
/**
|
|
8272
8678
|
* Get the maximum value from a list of items
|
|
8273
8679
|
*
|
|
8680
|
+
* @param items List of items
|
|
8681
|
+
* @param callback Callback to get an item's value
|
|
8682
|
+
* @returns Items with the maximum value
|
|
8683
|
+
*
|
|
8274
8684
|
* @example
|
|
8275
8685
|
* ```typescript
|
|
8276
8686
|
* max(
|
|
@@ -8280,15 +8690,15 @@ export declare function max<Item extends PlainObject>(items: Item[], key: keyof
|
|
|
8280
8690
|
*
|
|
8281
8691
|
* max([], item => item.value); // => []
|
|
8282
8692
|
* ```
|
|
8283
|
-
*
|
|
8284
|
-
* @param items List of items
|
|
8285
|
-
* @param callback Callback to get an item's value
|
|
8286
|
-
* @returns Items with the maximum value
|
|
8287
8693
|
*/
|
|
8288
8694
|
export declare function max<Item>(items: Item[], callback: (item: Item, index: number, array: Item[]) => number): Item[];
|
|
8289
8695
|
/**
|
|
8290
8696
|
* Get the maximum value from a list of items
|
|
8291
8697
|
*
|
|
8698
|
+
* @param items List of items
|
|
8699
|
+
* @param key Key to use for value
|
|
8700
|
+
* @returns Items with the maximum value
|
|
8701
|
+
*
|
|
8292
8702
|
* @example
|
|
8293
8703
|
* ```typescript
|
|
8294
8704
|
* max(
|
|
@@ -8298,23 +8708,19 @@ export declare function max<Item>(items: Item[], callback: (item: Item, index: n
|
|
|
8298
8708
|
*
|
|
8299
8709
|
* max([], 'value'); // => []
|
|
8300
8710
|
* ```
|
|
8301
|
-
*
|
|
8302
|
-
* @param items List of items
|
|
8303
|
-
* @param key Key to use for value
|
|
8304
|
-
* @returns Items with the maximum value
|
|
8305
8711
|
*/
|
|
8306
8712
|
export declare function max<Item extends PlainObject>(items: Item[], key: keyof NumericalValues<Item>): Item[];
|
|
8307
8713
|
/**
|
|
8308
8714
|
* Get the maximum value from a list of numbers
|
|
8309
8715
|
*
|
|
8716
|
+
* @param values List of numbers
|
|
8717
|
+
* @returns Maximum value, or `Number.NaN` if no maximum can be found
|
|
8718
|
+
*
|
|
8310
8719
|
* @example
|
|
8311
8720
|
* ```typescript
|
|
8312
8721
|
* max([10, 20]); // => 20
|
|
8313
8722
|
* max([]); // => Number.NaN
|
|
8314
8723
|
* ```
|
|
8315
|
-
*
|
|
8316
|
-
* @param values List of numbers
|
|
8317
|
-
* @returns Maximum value, or `Number.NaN` if no maximum can be found
|
|
8318
8724
|
*/
|
|
8319
8725
|
export declare function max(values: number[]): number;
|
|
8320
8726
|
/**
|
|
@@ -8324,6 +8730,17 @@ export declare function max(values: number[]): number;
|
|
|
8324
8730
|
* @param callback Callback to get an item's value
|
|
8325
8731
|
* @param first Return only the first item with the minimum value
|
|
8326
8732
|
* @returns First item with the minimum value, or `undefined` if no minimum can be found
|
|
8733
|
+
*
|
|
8734
|
+
* @example
|
|
8735
|
+
* ```typescript
|
|
8736
|
+
* min(
|
|
8737
|
+
* [{id: 1, value: 10}, {id: 2, value: 5}],
|
|
8738
|
+
* item => item.value,
|
|
8739
|
+
* true,
|
|
8740
|
+
* ); // => {id: 2, value: 5}
|
|
8741
|
+
*
|
|
8742
|
+
* min([], item => item.value, true); // => undefined
|
|
8743
|
+
* ```
|
|
8327
8744
|
*/
|
|
8328
8745
|
export declare function min<Item>(items: Item[], callback: (item: Item, index: number, array: Item[]) => number, first: true): Item | undefined;
|
|
8329
8746
|
/**
|
|
@@ -8333,6 +8750,17 @@ export declare function min<Item>(items: Item[], callback: (item: Item, index: n
|
|
|
8333
8750
|
* @param key Key to use for value
|
|
8334
8751
|
* @param first Return only the first item with the minimum value
|
|
8335
8752
|
* @returns First item with the minimum value, or `undefined` if no minimum can be found
|
|
8753
|
+
*
|
|
8754
|
+
* @example
|
|
8755
|
+
* ```typescript
|
|
8756
|
+
* min(
|
|
8757
|
+
* [{id: 1, value: 10}, {id: 2, value: 5}],
|
|
8758
|
+
* 'value',
|
|
8759
|
+
* true,
|
|
8760
|
+
* ); // => {id: 2, value: 5}
|
|
8761
|
+
*
|
|
8762
|
+
* min([], 'value', true); // => undefined
|
|
8763
|
+
* ```
|
|
8336
8764
|
*/
|
|
8337
8765
|
export declare function min<Item extends PlainObject>(items: Item[], key: keyof NumericalValues<Item>, first: true): Item | undefined;
|
|
8338
8766
|
/**
|
|
@@ -8341,6 +8769,16 @@ export declare function min<Item extends PlainObject>(items: Item[], key: keyof
|
|
|
8341
8769
|
* @param items List of items
|
|
8342
8770
|
* @param callback Callback to get an item's value
|
|
8343
8771
|
* @returns Items with the minimum value
|
|
8772
|
+
*
|
|
8773
|
+
* @example
|
|
8774
|
+
* ```typescript
|
|
8775
|
+
* min(
|
|
8776
|
+
* [{id: 1, value: 10}, {id: 2, value: 5}],
|
|
8777
|
+
* item => item.value,
|
|
8778
|
+
* ); // => [{id: 2, value: 5}]
|
|
8779
|
+
*
|
|
8780
|
+
* min([], item => item.value); // => []
|
|
8781
|
+
* ```
|
|
8344
8782
|
*/
|
|
8345
8783
|
export declare function min<Item>(items: Item[], callback: (item: Item, index: number, array: Item[]) => number): Item[];
|
|
8346
8784
|
/**
|
|
@@ -8349,6 +8787,16 @@ export declare function min<Item>(items: Item[], callback: (item: Item, index: n
|
|
|
8349
8787
|
* @param items List of items
|
|
8350
8788
|
* @param key Key to use for value
|
|
8351
8789
|
* @returns Items with the minimum value
|
|
8790
|
+
*
|
|
8791
|
+
* @example
|
|
8792
|
+
* ```typescript
|
|
8793
|
+
* min(
|
|
8794
|
+
* [{id: 1, value: 10}, {id: 2, value: 5}],
|
|
8795
|
+
* 'value',
|
|
8796
|
+
* ); // => [{id: 2, value: 5}]
|
|
8797
|
+
*
|
|
8798
|
+
* min([], 'value'); // => []
|
|
8799
|
+
* ```
|
|
8352
8800
|
*/
|
|
8353
8801
|
export declare function min<Item extends PlainObject>(items: Item[], key: keyof NumericalValues<Item>): Item[];
|
|
8354
8802
|
/**
|
|
@@ -8356,6 +8804,12 @@ export declare function min<Item extends PlainObject>(items: Item[], key: keyof
|
|
|
8356
8804
|
*
|
|
8357
8805
|
* @param values List of numbers
|
|
8358
8806
|
* @returns Minimum value, or `Number.NaN` if no minimum can be found
|
|
8807
|
+
*
|
|
8808
|
+
* @example
|
|
8809
|
+
* ```typescript
|
|
8810
|
+
* min([10, 20]); // => 10
|
|
8811
|
+
* min([]); // => Number.NaN
|
|
8812
|
+
* ```
|
|
8359
8813
|
*/
|
|
8360
8814
|
export declare function min(values: number[]): number;
|
|
8361
8815
|
//#endregion
|
|
@@ -8366,6 +8820,13 @@ export declare function min(values: number[]): number;
|
|
|
8366
8820
|
* @param value Number to round down
|
|
8367
8821
|
* @param decimals Number of decimal places to round to _(defaults to `0`)_
|
|
8368
8822
|
* @returns Rounded number, or `Number.NaN` if the value if unable to be rounded
|
|
8823
|
+
*
|
|
8824
|
+
* @example
|
|
8825
|
+
* ```typescript
|
|
8826
|
+
* floor(10.567, 2); // => 10.56
|
|
8827
|
+
* floor(10.567); // => 10
|
|
8828
|
+
* floor('abc'); // => Number.NaN
|
|
8829
|
+
* ```
|
|
8369
8830
|
*/
|
|
8370
8831
|
export declare function floor(value: number, decimals?: number): number;
|
|
8371
8832
|
/**
|
|
@@ -8374,6 +8835,13 @@ export declare function floor(value: number, decimals?: number): number;
|
|
|
8374
8835
|
* @param value Number to round
|
|
8375
8836
|
* @param decimals Number of decimal places to round to _(defaults to `0`)_
|
|
8376
8837
|
* @returns Rounded number, or `Number.NaN` if the value if unable to be rounded
|
|
8838
|
+
*
|
|
8839
|
+
* @example
|
|
8840
|
+
* ```typescript
|
|
8841
|
+
* round(10.567, 2); // => 10.57
|
|
8842
|
+
* round(10.567); // => 11
|
|
8843
|
+
* round('abc'); // => Number.NaN
|
|
8844
|
+
* ```
|
|
8377
8845
|
*/
|
|
8378
8846
|
export declare function round(value: number, decimals?: number): number;
|
|
8379
8847
|
//#endregion
|
|
@@ -8384,6 +8852,16 @@ export declare function round(value: number, decimals?: number): number;
|
|
|
8384
8852
|
* @param items List of items
|
|
8385
8853
|
* @param callback Callback to get an item's value
|
|
8386
8854
|
* @returns Average value, or `Number.NaN` if no average can be calculated
|
|
8855
|
+
*
|
|
8856
|
+
* @example
|
|
8857
|
+
* ```typescript
|
|
8858
|
+
* average([
|
|
8859
|
+
* {value: 1},
|
|
8860
|
+
* {value: 2},
|
|
8861
|
+
* {value: 3},
|
|
8862
|
+
* ], item => item.value); // => 2
|
|
8863
|
+
* average([{value: 1}], item => item.nope); // => Number.NaN
|
|
8864
|
+
* ```
|
|
8387
8865
|
*/
|
|
8388
8866
|
export declare function average<Item>(items: Item[], callback: (item: Item, index: number, array: Item[]) => number): number;
|
|
8389
8867
|
/**
|
|
@@ -8392,6 +8870,12 @@ export declare function average<Item>(items: Item[], callback: (item: Item, inde
|
|
|
8392
8870
|
* @param items List of items
|
|
8393
8871
|
* @param key Key to use for value
|
|
8394
8872
|
* @returns Average value, or `Number.NaN` if no average can be calculated
|
|
8873
|
+
*
|
|
8874
|
+
* @example
|
|
8875
|
+
* ```typescript
|
|
8876
|
+
* average([{value: 1}, {value: 2}, {value: 3}], 'value'); // => 2
|
|
8877
|
+
* average([{value: 1}], 'nope'); // => Number.NaN
|
|
8878
|
+
* ```
|
|
8395
8879
|
*/
|
|
8396
8880
|
export declare function average<Item extends PlainObject>(items: Item[], key: keyof NumericalValues<Item>): number;
|
|
8397
8881
|
/**
|
|
@@ -8399,6 +8883,12 @@ export declare function average<Item extends PlainObject>(items: Item[], key: ke
|
|
|
8399
8883
|
*
|
|
8400
8884
|
* @param numbers List of numbers
|
|
8401
8885
|
* @returns Average value, or `Number.NaN` if no average can be calculated
|
|
8886
|
+
*
|
|
8887
|
+
* @example
|
|
8888
|
+
* ```typescript
|
|
8889
|
+
* average([1, 2, 3, 4, 5]); // => 3
|
|
8890
|
+
* average([]); // => Number.NaN
|
|
8891
|
+
* ```
|
|
8402
8892
|
*/
|
|
8403
8893
|
export declare function average(numbers: number[]): number;
|
|
8404
8894
|
/**
|
|
@@ -8407,6 +8897,13 @@ export declare function average(numbers: number[]): number;
|
|
|
8407
8897
|
* @param value Number to round up
|
|
8408
8898
|
* @param decimals Number of decimal places to round to _(defaults to `0`)_
|
|
8409
8899
|
* @returns Rounded number, or `Number.NaN` if the value if unable to be rounded
|
|
8900
|
+
*
|
|
8901
|
+
* @example
|
|
8902
|
+
* ```typescript
|
|
8903
|
+
* ceil(1.234, 2); // => 1.24
|
|
8904
|
+
* ceil(1.234); // => 2
|
|
8905
|
+
* ceil('abc'); // => Number.NaN
|
|
8906
|
+
* ```
|
|
8410
8907
|
*/
|
|
8411
8908
|
export declare function ceil(value: number, decimals?: number): number;
|
|
8412
8909
|
/**
|
|
@@ -8416,6 +8913,14 @@ export declare function ceil(value: number, decimals?: number): number;
|
|
|
8416
8913
|
* @param callback Callback to get an item's value
|
|
8417
8914
|
* @param value Value to match and count
|
|
8418
8915
|
* @returns Number of items that match the condition, or `Number.NaN` if no count can be calculated
|
|
8916
|
+
*
|
|
8917
|
+
* @example
|
|
8918
|
+
* ```typescript
|
|
8919
|
+
* count([1, 2, 3, 2], (item) => item, 2); // => 2
|
|
8920
|
+
* count([{value: 1}, {value: 2}, {value: 3}], 'value', 2); // => 1
|
|
8921
|
+
* count([1, 2, 3], (item) => item, 4); // => 0
|
|
8922
|
+
* count([], (item) => item, 1); // => Number.NaN
|
|
8923
|
+
* ```
|
|
8419
8924
|
*/
|
|
8420
8925
|
export declare function count<Item>(array: Item[], callback: (item: Item, index: number, array: Item[]) => unknown, value: unknown): number;
|
|
8421
8926
|
/**
|
|
@@ -8425,6 +8930,12 @@ export declare function count<Item>(array: Item[], callback: (item: Item, index:
|
|
|
8425
8930
|
* @param key Key to use for value
|
|
8426
8931
|
* @param value Value to match and count
|
|
8427
8932
|
* @returns Number of items with the specified key value, or `Number.NaN` if no count can be calculated
|
|
8933
|
+
*
|
|
8934
|
+
* @example
|
|
8935
|
+
* ```typescript
|
|
8936
|
+
* count([{value: 1}, {value: 2}, {value: 3}], 'value', 2); // => 1
|
|
8937
|
+
* count([{value: 1}], 'nope', 1); // => Number.NaN
|
|
8938
|
+
* ```
|
|
8428
8939
|
*/
|
|
8429
8940
|
export declare function count<Item extends PlainObject, ItemKey extends keyof Item>(array: Item[], key: ItemKey, value: Item[ItemKey]): number;
|
|
8430
8941
|
/**
|
|
@@ -8432,6 +8943,12 @@ export declare function count<Item extends PlainObject, ItemKey extends keyof It
|
|
|
8432
8943
|
*
|
|
8433
8944
|
* @param values Array to count for
|
|
8434
8945
|
* @returns Number of items, or `Number.NaN` if no count can be calculated
|
|
8946
|
+
*
|
|
8947
|
+
* @example
|
|
8948
|
+
* ```typescript
|
|
8949
|
+
* count([1, 2, 3]); // => 3
|
|
8950
|
+
* count([]); // => Number.NaN
|
|
8951
|
+
* ```
|
|
8435
8952
|
*/
|
|
8436
8953
|
export declare function count(values: unknown[]): number;
|
|
8437
8954
|
/**
|
|
@@ -8440,6 +8957,13 @@ export declare function count(values: unknown[]): number;
|
|
|
8440
8957
|
* @param array List of items
|
|
8441
8958
|
* @param callback Callback to get an item's value
|
|
8442
8959
|
* @returns Median value, or `Number.NaN` if no median can be calculated
|
|
8960
|
+
*
|
|
8961
|
+
* @example
|
|
8962
|
+
* ```typescript
|
|
8963
|
+
* median([1, 2, 3, 4, 5]); // => 3
|
|
8964
|
+
* median([1, 2, 3, 4]); // => 2.5
|
|
8965
|
+
* median([]); // => Number.NaN
|
|
8966
|
+
* ```
|
|
8443
8967
|
*/
|
|
8444
8968
|
export declare function median<Item>(array: Item[], callback: (item: Item, index: number, array: Item[]) => number): number;
|
|
8445
8969
|
/**
|
|
@@ -8448,6 +8972,13 @@ export declare function median<Item>(array: Item[], callback: (item: Item, index
|
|
|
8448
8972
|
* @param array List of items
|
|
8449
8973
|
* @param key Key to use for value
|
|
8450
8974
|
* @returns Median value, or `Number.NaN` if no median can be calculated
|
|
8975
|
+
*
|
|
8976
|
+
* @example
|
|
8977
|
+
* ```typescript
|
|
8978
|
+
* median([{value: 1}, {value: 2}, {value: 3}], 'value'); // => 2
|
|
8979
|
+
* median([{value: 1}, {value: 2}, {value: 3}, {value: 4}], 'value'); // => 2.5
|
|
8980
|
+
* median([], 'value'); // => Number.NaN
|
|
8981
|
+
* ```
|
|
8451
8982
|
*/
|
|
8452
8983
|
export declare function median<Item extends PlainObject>(array: Item[], key: keyof NumericalValues<Item>): number;
|
|
8453
8984
|
/**
|
|
@@ -8455,6 +8986,13 @@ export declare function median<Item extends PlainObject>(array: Item[], key: key
|
|
|
8455
8986
|
*
|
|
8456
8987
|
* @param array List of numbers
|
|
8457
8988
|
* @returns Median value, or `Number.NaN` if no median can be calculated
|
|
8989
|
+
*
|
|
8990
|
+
* @example
|
|
8991
|
+
* ```typescript
|
|
8992
|
+
* median([1, 2, 3, 4, 5]); // => 3
|
|
8993
|
+
* median([1, 2, 3, 4]); // => 2.5
|
|
8994
|
+
* median([]); // => Number.NaN
|
|
8995
|
+
* ```
|
|
8458
8996
|
*/
|
|
8459
8997
|
export declare function median(array: number[]): number;
|
|
8460
8998
|
/**
|
|
@@ -8463,6 +9001,13 @@ export declare function median(array: number[]): number;
|
|
|
8463
9001
|
* @param items List of items
|
|
8464
9002
|
* @param callback Callback to get an item's value
|
|
8465
9003
|
* @returns Sum of the values, or `Number.NaN` if no sum can be calculated
|
|
9004
|
+
*
|
|
9005
|
+
* @example
|
|
9006
|
+
* ```typescript
|
|
9007
|
+
* sum([{value: 1}, {value: 2}, {value: 3}], 'value'); // => 6
|
|
9008
|
+
* sum([{value: 1}, {value: 2}, {value: 3}], item => item.value); // => 6
|
|
9009
|
+
* sum([]); // => Number.NaN
|
|
9010
|
+
* ```
|
|
8466
9011
|
*/
|
|
8467
9012
|
export declare function sum<Item>(items: Item[], callback: (item: Item, index: number, array: Item[]) => number): number;
|
|
8468
9013
|
/**
|
|
@@ -8471,6 +9016,13 @@ export declare function sum<Item>(items: Item[], callback: (item: Item, index: n
|
|
|
8471
9016
|
* @param items List of items
|
|
8472
9017
|
* @param key Key to use for value
|
|
8473
9018
|
* @returns Sum of the values, or `Number.NaN` if no sum can be calculated
|
|
9019
|
+
*
|
|
9020
|
+
* @example
|
|
9021
|
+
* ```typescript
|
|
9022
|
+
* sum([{value: 1}, {value: 2}, {value: 3}], 'value'); // => 6
|
|
9023
|
+
* sum([{value: 1}, {value: 2}, {value: 3}], item => item.value); // => 6
|
|
9024
|
+
* sum([]); // => Number.NaN
|
|
9025
|
+
* ```
|
|
8474
9026
|
*/
|
|
8475
9027
|
export declare function sum<Item extends PlainObject>(items: Item[], key: keyof NumericalValues<Item>): number;
|
|
8476
9028
|
/**
|
|
@@ -8478,6 +9030,12 @@ export declare function sum<Item extends PlainObject>(items: Item[], key: keyof
|
|
|
8478
9030
|
*
|
|
8479
9031
|
* @param values List of numbers
|
|
8480
9032
|
* @returns Sum of the numbers, or `Number.NaN` if no sum can be calculated
|
|
9033
|
+
*
|
|
9034
|
+
* @example
|
|
9035
|
+
* ```typescript
|
|
9036
|
+
* sum([1, 2, 3]); // => 6
|
|
9037
|
+
* sum([]); // => Number.NaN
|
|
9038
|
+
* ```
|
|
8481
9039
|
*/
|
|
8482
9040
|
export declare function sum(values: number[]): number;
|
|
8483
9041
|
//#endregion
|
|
@@ -8489,6 +9047,13 @@ export declare function sum(values: number[]): number;
|
|
|
8489
9047
|
* @param minimum Minimum value
|
|
8490
9048
|
* @param maximum Maximum value _(inclusive)_
|
|
8491
9049
|
* @returns `true` if the value is between the minimum and maximum, otherwise `false`
|
|
9050
|
+
*
|
|
9051
|
+
* @example
|
|
9052
|
+
* ```typescript
|
|
9053
|
+
* between(5, 1, 10); // => true
|
|
9054
|
+
* between(0, 1, 10); // => false
|
|
9055
|
+
* between(10, 10, 10); // => true
|
|
9056
|
+
* ```
|
|
8492
9057
|
*/
|
|
8493
9058
|
export declare function between(value: number, minimum: number, maximum: number): boolean;
|
|
8494
9059
|
/**
|
|
@@ -8514,6 +9079,17 @@ export declare function clamp(value: number, minimum: number, maximum: number, l
|
|
|
8514
9079
|
*
|
|
8515
9080
|
* @param value Original value
|
|
8516
9081
|
* @returns Original value as a number, or `Number.NaN` if the value is unable to be parsed
|
|
9082
|
+
*
|
|
9083
|
+
* @example
|
|
9084
|
+
* ```typescript
|
|
9085
|
+
* getNumber(null) // => Number.NaN
|
|
9086
|
+
* getNumber('foo') // => Number.NaN
|
|
9087
|
+
* getNumber('123') // => 123
|
|
9088
|
+
* getNumber(true) // => 1
|
|
9089
|
+
* getNumber([1, 2, 3]) // => Number.NaN
|
|
9090
|
+
* getNumber({a: 1}) // => Number.NaN
|
|
9091
|
+
* getNumber(() => 123) // => 123
|
|
9092
|
+
* ```
|
|
8517
9093
|
*/
|
|
8518
9094
|
export declare function getNumber(value: unknown): number;
|
|
8519
9095
|
//#endregion
|
|
@@ -8744,7 +9320,6 @@ export declare function isKeyedQueue(value: unknown): value is KeyedQueue<Generi
|
|
|
8744
9320
|
* @returns `true` if the value is a queue, otherwise `false`
|
|
8745
9321
|
*/
|
|
8746
9322
|
export declare function isQueue(value: unknown): value is Queue<GenericCallback | GenericAsyncCallback>;
|
|
8747
|
-
export declare function isQueueInstance<Instance>(name: string, value: unknown): value is Instance;
|
|
8748
9323
|
/**
|
|
8749
9324
|
* Create a keyed queue for an asynchronous callback function, where each key has its own queue
|
|
8750
9325
|
*
|
|
@@ -8907,4 +9482,4 @@ export declare class SizedSet<Value = unknown> extends Set<Value> {
|
|
|
8907
9482
|
get(value: Value, update?: boolean): Value | undefined;
|
|
8908
9483
|
}
|
|
8909
9484
|
//#endregion
|
|
8910
|
-
export { type ArrayComparisonSorter, type ArrayKeySorter, type ArrayKeySorters, type ArraySorter, type ArraySorters, type ArrayValueSorter, type Asserter, type AssignOptions, type Assigner, type AsyncFailure, type AsyncFlow, type AsyncLimiter, type AsyncOnce, type AsyncPlan, type AsyncPlanned, type AsyncStep, type AsyncSuccess, type Beacon, type BeaconOptions, type CloneOptions, type Cloner, type Color, type ColorType, type ColorTypeExtended, type ColorValue, type ColorValueExtended, type CompareCallback, type ComparisonSorter, type DiffOptions, type DiffResult, type EqualOptions, type Equalizer, type Failure, type Flow, type FulfilledPromise, type Fuzzy, type
|
|
9485
|
+
export { type ArrayComparisonSorter, type ArrayKeySorter, type ArrayKeySorters, type ArraySorter, type ArraySorters, type ArrayValueSorter, type Asserter, type AssignOptions, type Assigner, type AsyncFailure, type AsyncFlow, type AsyncLimiter, type AsyncOnce, type AsyncPlan, type AsyncPlanned, type AsyncStep, type AsyncSuccess, type Beacon, type BeaconOptions, type CloneOptions, type Cloner, type Color, type ColorType, type ColorTypeExtended, type ColorValue, type ColorValueExtended, type CompareCallback, type ComparisonSorter, type DiffOptions, type DiffResult, type EqualOptions, type Equalizer, type Failure, type Flow, type FulfilledPromise, type Fuzzy, type FuzzyOptions, type FuzzyResult, type HSLAColor, type HSLColor, type HWBAColor, type HWBColor, type Herald, type HeraldEvents, type HeraldOptions, Key$1 as Key, type KeyedQueue, type Limiter, Logger, type Memoized, type MemoizedOptions, type MergeOptions, type Merger, type NormalizeOptions, type Normalizer, type Observable, type Observer, type Once, type Plan, type PlanError, type PlanOk, type PlanReturned, type Planned, type PromiseOptions, type PromiseStrategy, type PromisesOptions, type Queue, type QueueOptions, type Queued, type RGBAColor, type RGBColor, type RejectedPromise, type Renderer, type Shaken, type Smushed, type SortDirection, type Sorter, type Step, type Subscription, type SubscriptionParameters, type SubscriptionProperty, type Subscriptions, type SubscriptionsParameters, type Success, type TemplateOptions, type Templater, type TemplaterOptions, type TemplaterRenderer, type TimeLogger, type TransformCallback, type TransformCallbacks, type Transformer, type Unsmushed, push as append, filterAndMap as select, toPromise as fromResult, getRandomFloatingNumber as getRandomFloat, isLogger, isTimeLogger, mapAndFilter as reverseSelect };
|