@oscarpalmer/atoms 0.75.0 → 0.76.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/js/array/chunk.cjs +2 -1
- package/dist/js/array/chunk.js +2 -1
- package/dist/js/array/count.cjs +10 -3
- package/dist/js/array/count.js +10 -3
- package/dist/js/array/exists.cjs +10 -3
- package/dist/js/array/exists.js +10 -3
- package/dist/js/array/filter.cjs +10 -3
- package/dist/js/array/filter.js +10 -3
- package/dist/js/array/find.cjs +10 -3
- package/dist/js/array/find.js +10 -3
- package/dist/js/array/group-by.cjs +18 -16
- package/dist/js/array/group-by.js +18 -16
- package/dist/js/array/index-of.cjs +10 -3
- package/dist/js/array/index-of.js +10 -3
- package/dist/js/array/index.cjs +2 -2
- package/dist/js/array/index.js +2 -2
- package/dist/js/array/insert.cjs +10 -4
- package/dist/js/array/insert.js +10 -4
- package/dist/js/array/splice.cjs +4 -4
- package/dist/js/array/splice.js +4 -4
- package/dist/js/array/to-map.cjs +11 -11
- package/dist/js/array/to-map.js +11 -11
- package/dist/js/array/to-record.cjs +3 -3
- package/dist/js/array/to-record.js +3 -3
- package/dist/js/array/unique.cjs +2 -2
- package/dist/js/array/unique.js +2 -2
- package/dist/js/colour/base.cjs +1 -1
- package/dist/js/colour/base.js +1 -1
- package/dist/js/colour/hex.cjs +2 -2
- package/dist/js/colour/hex.js +2 -2
- package/dist/js/colour/hsl.cjs +13 -7
- package/dist/js/colour/hsl.js +13 -7
- package/dist/js/colour/rgb.cjs +12 -6
- package/dist/js/colour/rgb.js +12 -6
- package/dist/js/emitter.cjs +8 -5
- package/dist/js/emitter.js +8 -5
- package/dist/js/function.cjs +6 -6
- package/dist/js/function.js +6 -6
- package/dist/js/index.cjs +0 -1
- package/dist/js/index.js +1 -2
- package/dist/js/internal/array/callbacks.cjs +23 -0
- package/dist/js/internal/array/callbacks.js +23 -0
- package/dist/js/internal/{array-find.cjs → array/find.cjs} +11 -12
- package/dist/js/internal/{array-find.js → array/find.js} +11 -12
- package/dist/js/logger.cjs +13 -13
- package/dist/js/logger.js +13 -13
- package/dist/js/query.cjs +0 -3
- package/dist/js/query.js +1 -4
- package/dist/js/random.cjs +0 -6
- package/dist/js/random.js +0 -6
- package/dist/js/sized.cjs +1 -1
- package/dist/js/sized.js +1 -1
- package/dist/js/string/index.cjs +7 -1
- package/dist/js/string/index.js +7 -1
- package/dist/js/value/compare.cjs +0 -1
- package/dist/js/value/compare.js +0 -1
- package/dist/js/value/get.cjs +3 -3
- package/dist/js/value/get.js +2 -2
- package/dist/js/value/set.cjs +4 -4
- package/dist/js/value/set.js +2 -2
- package/package.json +3 -2
- package/src/js/array/chunk.ts +6 -5
- package/src/js/array/compact.ts +8 -10
- package/src/js/array/count.ts +39 -19
- package/src/js/array/exists.ts +40 -16
- package/src/js/array/filter.ts +42 -20
- package/src/js/array/find.ts +45 -20
- package/src/js/array/group-by.ts +158 -27
- package/src/js/array/index-of.ts +40 -18
- package/src/js/array/index.ts +10 -9
- package/src/js/array/insert.ts +28 -14
- package/src/js/array/models.ts +18 -15
- package/src/js/array/shuffle.ts +3 -3
- package/src/js/array/sort.ts +28 -34
- package/src/js/array/splice.ts +22 -26
- package/src/js/array/to-map.ts +133 -45
- package/src/js/array/to-record.ts +137 -39
- package/src/js/array/unique.ts +20 -15
- package/src/js/colour/base.ts +3 -3
- package/src/js/colour/functions.ts +4 -6
- package/src/js/colour/hex.ts +5 -5
- package/src/js/colour/hsl.ts +18 -12
- package/src/js/colour/index.ts +1 -1
- package/src/js/colour/is.ts +3 -3
- package/src/js/colour/rgb.ts +17 -11
- package/src/js/emitter.ts +12 -9
- package/src/js/function.ts +12 -12
- package/src/js/index.ts +16 -16
- package/src/js/internal/array/callbacks.ts +33 -0
- package/src/js/internal/{array-find.ts → array/find.ts} +23 -24
- package/src/js/internal/{value-handle.ts → value/handle.ts} +1 -1
- package/src/js/is.ts +2 -2
- package/src/js/logger.ts +14 -14
- package/src/js/math.ts +1 -1
- package/src/js/models.ts +5 -5
- package/src/js/number.ts +2 -2
- package/src/js/query.ts +6 -10
- package/src/js/queue.ts +1 -1
- package/src/js/random.ts +9 -19
- package/src/js/sized.ts +145 -145
- package/src/js/string/case.ts +1 -1
- package/src/js/string/index.ts +13 -7
- package/src/js/string/template.ts +6 -3
- package/src/js/value/clone.ts +3 -7
- package/src/js/value/compare.ts +3 -5
- package/src/js/value/diff.ts +4 -4
- package/src/js/value/equal.ts +2 -2
- package/src/js/value/get.ts +3 -3
- package/src/js/value/index.ts +2 -2
- package/src/js/value/merge.ts +3 -3
- package/src/js/value/set.ts +3 -4
- package/src/js/value/smush.ts +4 -4
- package/src/js/value/unsmush.ts +4 -4
- package/types/array/chunk.d.cts +2 -2
- package/types/array/chunk.d.ts +2 -2
- package/types/array/compact.d.cts +4 -4
- package/types/array/compact.d.ts +4 -4
- package/types/array/count.d.cts +15 -8
- package/types/array/count.d.ts +13 -7
- package/types/array/exists.d.cts +14 -5
- package/types/array/exists.d.ts +12 -4
- package/types/array/filter.d.cts +16 -7
- package/types/array/filter.d.ts +14 -6
- package/types/array/find.d.cts +16 -7
- package/types/array/find.d.ts +14 -6
- package/types/array/group-by.d.cts +51 -5
- package/types/array/group-by.d.ts +49 -5
- package/types/array/index-of.d.cts +16 -7
- package/types/array/index-of.d.ts +14 -6
- package/types/array/index.d.cts +239 -95
- package/types/array/index.d.ts +7 -6
- package/types/array/insert.d.cts +9 -4
- package/types/array/insert.d.ts +10 -5
- package/types/array/models.d.cts +14 -11
- package/types/array/models.d.ts +14 -12
- package/types/array/shuffle.d.cts +2 -2
- package/types/array/shuffle.d.ts +2 -2
- package/types/array/sort.d.cts +11 -11
- package/types/array/sort.d.ts +10 -10
- package/types/array/splice.d.cts +4 -4
- package/types/array/splice.d.ts +4 -4
- package/types/array/to-map.d.cts +44 -20
- package/types/array/to-map.d.ts +42 -20
- package/types/array/to-record.d.cts +44 -20
- package/types/array/to-record.d.ts +42 -20
- package/types/array/unique.d.cts +11 -6
- package/types/array/unique.d.ts +10 -6
- package/types/colour/base.d.cts +28 -16
- package/types/colour/base.d.ts +2 -2
- package/types/colour/functions.d.cts +28 -16
- package/types/colour/functions.d.ts +3 -3
- package/types/colour/hex.d.cts +28 -16
- package/types/colour/hex.d.ts +4 -4
- package/types/colour/hsl.d.cts +28 -16
- package/types/colour/hsl.d.ts +16 -10
- package/types/colour/index.d.cts +28 -16
- package/types/colour/index.d.ts +1 -1
- package/types/colour/is.d.cts +28 -16
- package/types/colour/is.d.ts +3 -3
- package/types/colour/rgb.d.cts +28 -16
- package/types/colour/rgb.d.ts +15 -9
- package/types/emitter.d.cts +11 -8
- package/types/emitter.d.ts +11 -8
- package/types/function.d.cts +10 -10
- package/types/function.d.ts +11 -11
- package/types/index.d.cts +1061 -669
- package/types/index.d.ts +16 -16
- package/types/internal/array/callbacks.d.cts +11 -0
- package/types/internal/array/callbacks.d.ts +2 -0
- package/types/internal/array/find.d.cts +7 -0
- package/types/internal/array/find.d.ts +3 -0
- package/types/internal/{value-handle.d.ts → value/handle.d.ts} +1 -1
- package/types/is.d.ts +1 -1
- package/types/logger.d.cts +13 -13
- package/types/logger.d.ts +13 -13
- package/types/math.d.cts +1 -1
- package/types/math.d.ts +1 -1
- package/types/models.d.cts +4 -4
- package/types/models.d.ts +1 -4
- package/types/number.d.cts +2 -2
- package/types/number.d.ts +2 -2
- package/types/query.d.cts +2 -2
- package/types/query.d.ts +3 -3
- package/types/queue.d.cts +1 -1
- package/types/queue.d.ts +1 -1
- package/types/random.d.cts +8 -12
- package/types/random.d.ts +8 -12
- package/types/sized.d.cts +6 -6
- package/types/sized.d.ts +6 -6
- package/types/string/index.d.cts +6 -3
- package/types/string/index.d.ts +3 -3
- package/types/string/template.d.cts +3 -0
- package/types/string/template.d.ts +4 -1
- package/types/value/clone.d.cts +4 -2
- package/types/value/clone.d.ts +4 -2
- package/types/value/get.d.ts +1 -1
- package/types/value/index.d.cts +8 -6
- package/types/value/index.d.ts +2 -2
- package/types/value/merge.d.cts +1 -1
- package/types/value/merge.d.ts +2 -2
- package/types/value/set.d.ts +1 -1
- package/types/value/smush.d.cts +1 -1
- package/types/value/smush.d.ts +2 -2
- package/types/value/unsmush.d.cts +1 -1
- package/types/value/unsmush.d.ts +2 -2
- package/dist/js/internal/array-callbacks.cjs +0 -18
- package/dist/js/internal/array-callbacks.js +0 -18
- package/src/js/internal/array-callbacks.ts +0 -28
- package/types/internal/array-callbacks.d.cts +0 -13
- package/types/internal/array-callbacks.d.ts +0 -2
- package/types/internal/array-find.d.cts +0 -11
- package/types/internal/array-find.d.ts +0 -4
- /package/dist/js/internal/{value-handle.cjs → value/handle.cjs} +0 -0
- /package/dist/js/internal/{value-handle.js → value/handle.js} +0 -0
- /package/types/internal/{value-handle.d.cts → value/handle.d.cts} +0 -0
package/types/index.d.cts
CHANGED
|
@@ -1,91 +1,130 @@
|
|
|
1
1
|
// Generated by dts-bundle-generator v9.5.1
|
|
2
2
|
|
|
3
|
-
|
|
4
|
-
|
|
3
|
+
/**
|
|
4
|
+
* A Map with a maximum size
|
|
5
|
+
* - Maximum size defaults to _2^20_; any provided size will be clamped at _2^24_
|
|
6
|
+
* - Behaviour is similar to a _LRU_-cache, where the least recently used entries are removed
|
|
7
|
+
*/
|
|
8
|
+
export declare class SizedMap<Key = unknown, Value = unknown> extends Map<
|
|
9
|
+
Key,
|
|
10
|
+
Value
|
|
11
|
+
> {
|
|
12
|
+
private readonly maximumSize;
|
|
5
13
|
/**
|
|
6
|
-
* Is the
|
|
14
|
+
* Is the Map full?
|
|
7
15
|
*/
|
|
8
|
-
get
|
|
16
|
+
get full(): boolean;
|
|
9
17
|
/**
|
|
10
|
-
* The
|
|
18
|
+
* The maximum size of the Map
|
|
11
19
|
*/
|
|
12
|
-
get
|
|
20
|
+
get maximum(): number;
|
|
13
21
|
/**
|
|
14
|
-
*
|
|
22
|
+
* Create a new Map with entries and a maximum size _(2^20)_
|
|
15
23
|
*/
|
|
16
|
-
|
|
17
|
-
constructor(value: Value);
|
|
24
|
+
constructor(entries: Array<[Key, Value]>);
|
|
18
25
|
/**
|
|
19
|
-
*
|
|
26
|
+
* Create a new Map with a maximum size _(but clamped at 2^24)_
|
|
20
27
|
*/
|
|
21
|
-
|
|
28
|
+
constructor(maximum: number);
|
|
22
29
|
/**
|
|
23
|
-
*
|
|
30
|
+
* Create a new Map with _(optional)_ entries and a maximum size _(defaults to 2^20; clamped at 2^24)_
|
|
24
31
|
*/
|
|
25
|
-
|
|
32
|
+
constructor(entries?: Array<[Key, Value]>, maximum?: number);
|
|
26
33
|
/**
|
|
27
|
-
*
|
|
34
|
+
* @inheritdoc
|
|
28
35
|
*/
|
|
29
|
-
|
|
36
|
+
get(key: Key): Value | undefined;
|
|
30
37
|
/**
|
|
31
|
-
*
|
|
38
|
+
* @inheritdoc
|
|
32
39
|
*/
|
|
33
|
-
|
|
40
|
+
set(key: Key, value: Value): this;
|
|
34
41
|
}
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
42
|
+
/**
|
|
43
|
+
* A Set with a maximum size
|
|
44
|
+
* - Maximum size defaults to _2^20_; any provided size will be clamped at _2^24_
|
|
45
|
+
* - Behaviour is similar to a _LRU_-cache, where the oldest values are removed
|
|
46
|
+
*/
|
|
47
|
+
export declare class SizedSet<Value = unknown> extends Set<Value> {
|
|
48
|
+
private readonly maximumSize;
|
|
41
49
|
/**
|
|
42
|
-
*
|
|
50
|
+
* Is the Set full?
|
|
43
51
|
*/
|
|
44
|
-
|
|
52
|
+
get full(): boolean;
|
|
45
53
|
/**
|
|
46
|
-
*
|
|
54
|
+
* The maximum size of the Set
|
|
47
55
|
*/
|
|
48
|
-
|
|
49
|
-
onNext: (value: Value) => void,
|
|
50
|
-
onError?: (error: Error) => void,
|
|
51
|
-
onComplete?: () => void,
|
|
52
|
-
): Subscription<Value>;
|
|
53
|
-
}
|
|
54
|
-
export type ObservableState<Value> = {
|
|
55
|
-
emitter: Emitter<Value>;
|
|
56
|
-
observers: Map<Subscription<Value>, Observer<Value>>;
|
|
57
|
-
};
|
|
58
|
-
export type Observer<Value> = {
|
|
56
|
+
get maximum(): number;
|
|
59
57
|
/**
|
|
60
|
-
*
|
|
58
|
+
* Create a new Set with values and a maximum size _(2^20)_
|
|
61
59
|
*/
|
|
62
|
-
|
|
60
|
+
constructor(values: Value[]);
|
|
63
61
|
/**
|
|
64
|
-
*
|
|
62
|
+
* Create a new Set with a maximum size _(but clamped at 2^24)_
|
|
65
63
|
*/
|
|
66
|
-
|
|
64
|
+
constructor(maximum: number);
|
|
67
65
|
/**
|
|
68
|
-
*
|
|
66
|
+
* Create a new Set with _(optional)_ values and a maximum size _(defaults to 2^20; clamped at 2^24)_
|
|
69
67
|
*/
|
|
70
|
-
|
|
71
|
-
};
|
|
72
|
-
export declare class Subscription<Value> {
|
|
73
|
-
private readonly state;
|
|
74
|
-
constructor(state: ObservableState<Value>);
|
|
68
|
+
constructor(values?: Value[], maximum?: number);
|
|
75
69
|
/**
|
|
76
|
-
*
|
|
70
|
+
* @inheritdoc
|
|
77
71
|
*/
|
|
78
|
-
|
|
79
|
-
destroy(): void;
|
|
72
|
+
add(value: Value): this;
|
|
80
73
|
/**
|
|
81
|
-
*
|
|
74
|
+
* Get a value from an index in the Set, if it exists
|
|
75
|
+
* - Negative indices are counted from the end
|
|
76
|
+
* - Optionally move the value to the end with `update`
|
|
82
77
|
*/
|
|
83
|
-
|
|
78
|
+
at(index: number, update?: boolean): Value | undefined;
|
|
79
|
+
/**
|
|
80
|
+
* Get a value from the Set, if it exists _(and move it to the end)_
|
|
81
|
+
*/
|
|
82
|
+
get(value: Value, update?: boolean): Value | undefined;
|
|
84
83
|
}
|
|
85
84
|
/**
|
|
86
|
-
*
|
|
85
|
+
* Get a random boolean
|
|
87
86
|
*/
|
|
88
|
-
export declare function
|
|
87
|
+
export declare function getRandomBoolean(): boolean;
|
|
88
|
+
/**
|
|
89
|
+
* Get a random string of characters with a specified length
|
|
90
|
+
* - `selection` defaults to all lowercase letters in the English alphabet
|
|
91
|
+
*/
|
|
92
|
+
export declare function getRandomCharacters(
|
|
93
|
+
length: number,
|
|
94
|
+
selection?: string,
|
|
95
|
+
): string;
|
|
96
|
+
/**
|
|
97
|
+
* Get a random hexadecimal colour
|
|
98
|
+
*/
|
|
99
|
+
export declare function getRandomColour(): string;
|
|
100
|
+
/**
|
|
101
|
+
* Get a random floating-point number
|
|
102
|
+
*/
|
|
103
|
+
export declare function getRandomFloat(min?: number, max?: number): number;
|
|
104
|
+
/**
|
|
105
|
+
* Get a random hexadecimal character
|
|
106
|
+
*/
|
|
107
|
+
export declare function getRandomHex(): string;
|
|
108
|
+
/**
|
|
109
|
+
* Get a random integer
|
|
110
|
+
*/
|
|
111
|
+
export declare function getRandomInteger(min?: number, max?: number): number;
|
|
112
|
+
/**
|
|
113
|
+
* Get a random item from an array
|
|
114
|
+
*/
|
|
115
|
+
export declare function getRandomItem<Value>(array: Value[]): Value;
|
|
116
|
+
/**
|
|
117
|
+
* - Get an amount of random items from an array
|
|
118
|
+
* - If `amount` is not specified, a shuffled array will be returned instead
|
|
119
|
+
*/
|
|
120
|
+
export declare function getRandomItems<Value>(
|
|
121
|
+
array: Value[],
|
|
122
|
+
amount?: number,
|
|
123
|
+
): Value[];
|
|
124
|
+
/**
|
|
125
|
+
* Queue a callback to be executed at the next best time
|
|
126
|
+
*/
|
|
127
|
+
export declare function queue(callback: () => void): void;
|
|
89
128
|
/**
|
|
90
129
|
Matches any [primitive value](https://developer.mozilla.org/en-US/docs/Glossary/Primitive).
|
|
91
130
|
|
|
@@ -1485,382 +1524,882 @@ export type EventPosition = {
|
|
|
1485
1524
|
x: number;
|
|
1486
1525
|
y: number;
|
|
1487
1526
|
};
|
|
1527
|
+
export type KeyedValue<
|
|
1528
|
+
Item,
|
|
1529
|
+
Key extends keyof Item,
|
|
1530
|
+
> = Item[Key] extends PropertyKey ? Item[Key] : never;
|
|
1488
1531
|
export type NestedArrayType<Value> = Value extends Array<infer NestedValue>
|
|
1489
1532
|
? NestedArrayType<NestedValue>
|
|
1490
1533
|
: Value;
|
|
1491
1534
|
export type GenericCallback = (...args: any[]) => any;
|
|
1492
|
-
export type GetterSetter<Value> = {
|
|
1493
|
-
get(): Value;
|
|
1494
|
-
set(value: Value): void;
|
|
1495
|
-
};
|
|
1496
1535
|
export type Key = number | string;
|
|
1497
1536
|
export type PlainObject = UnknownRecord;
|
|
1498
1537
|
export type UnknownArrayOrRecord = UnknownArray | UnknownRecord;
|
|
1499
|
-
export type Debounced<Callback extends GenericCallback> = Callback & {
|
|
1500
|
-
/**
|
|
1501
|
-
* Cancels the debounce
|
|
1502
|
-
*/
|
|
1503
|
-
cancel: () => void;
|
|
1504
|
-
};
|
|
1505
|
-
declare class Memoised<Callback extends GenericCallback> {
|
|
1506
|
-
readonly state: MemoisedState<Callback>;
|
|
1507
|
-
constructor(callback: Callback);
|
|
1508
|
-
/**
|
|
1509
|
-
* Clears the cache
|
|
1510
|
-
*/
|
|
1511
|
-
clear(): void;
|
|
1512
|
-
/**
|
|
1513
|
-
* Deletes a result from the cache
|
|
1514
|
-
*/
|
|
1515
|
-
delete(key: Parameters<Callback>[0]): boolean;
|
|
1516
|
-
/**
|
|
1517
|
-
* Destroys the instance, clearing its cache and removing its callback
|
|
1518
|
-
*/
|
|
1519
|
-
destroy(): void;
|
|
1520
|
-
/**
|
|
1521
|
-
* Retrieves the result from the cache if it exists, or `undefined` otherwise
|
|
1522
|
-
*/
|
|
1523
|
-
get(key: Parameters<Callback>[0]): ReturnType<Callback> | undefined;
|
|
1524
|
-
/**
|
|
1525
|
-
* Checks if the cache has a result for a given key
|
|
1526
|
-
*/
|
|
1527
|
-
has(key: Parameters<Callback>[0]): boolean;
|
|
1528
|
-
/**
|
|
1529
|
-
* Retrieves the result from the cache if it exists, otherwise runs the callback, caches the result, and returns it
|
|
1530
|
-
*/
|
|
1531
|
-
run(...parameters: Parameters<Callback>): ReturnType<Callback>;
|
|
1532
|
-
}
|
|
1533
|
-
export type MemoisedState<Callback extends GenericCallback> = {
|
|
1534
|
-
cache: Map<Parameters<Callback>[0], ReturnType<Callback>>;
|
|
1535
|
-
getter: (...parameters: Parameters<Callback>) => ReturnType<Callback>;
|
|
1536
|
-
};
|
|
1537
|
-
/**
|
|
1538
|
-
* - Debounces a function, ensuring it is only called after `time` milliseconds have passed
|
|
1539
|
-
* - On subsequent calls, the timer is reset and will wait another `time` milliseconds _(and so on...)_
|
|
1540
|
-
* - Time is clamped between _0_ and _1000_ milliseconds
|
|
1541
|
-
* - Returns the callback with an added `cancel`-method for manually cancelling the debounce
|
|
1542
|
-
*/
|
|
1543
|
-
export declare function debounce<Callback extends GenericCallback>(
|
|
1544
|
-
callback: Callback,
|
|
1545
|
-
time?: number,
|
|
1546
|
-
): Debounced<Callback>;
|
|
1547
|
-
/**
|
|
1548
|
-
* Memoises a function, caching and retrieving results based on the first parameter
|
|
1549
|
-
*/
|
|
1550
|
-
export declare function memoise<Callback extends GenericCallback>(
|
|
1551
|
-
callback: Callback,
|
|
1552
|
-
): Memoised<Callback>;
|
|
1553
|
-
/**
|
|
1554
|
-
* A function that does nothing, which can be useful, I guess…
|
|
1555
|
-
*/
|
|
1556
|
-
export declare function noop(): void;
|
|
1557
|
-
/**
|
|
1558
|
-
* - Throttles a function, ensuring it is only called once every `time` milliseconds
|
|
1559
|
-
* - Time is clamped between _0_ and _1000_ milliseconds
|
|
1560
|
-
*/
|
|
1561
|
-
export declare function throttle<Callback extends GenericCallback>(
|
|
1562
|
-
callback: Callback,
|
|
1563
|
-
time?: number,
|
|
1564
|
-
): Callback;
|
|
1565
|
-
/**
|
|
1566
|
-
* Chunks an array into smaller arrays of a specified size
|
|
1567
|
-
*/
|
|
1568
|
-
export declare function chunk<Value>(array: Value[], size?: number): Value[][];
|
|
1569
|
-
/**
|
|
1570
|
-
* Compacts and returns an array with all falsey values removed
|
|
1571
|
-
*/
|
|
1572
|
-
export declare function compact<Value>(
|
|
1573
|
-
array: Value[],
|
|
1574
|
-
strict: true,
|
|
1575
|
-
): Exclude<Value, 0 | '' | false | null | undefined>[];
|
|
1576
|
-
/**
|
|
1577
|
-
* Compacts and returns an array with all `null` and `undefined` values removed
|
|
1578
|
-
*/
|
|
1579
|
-
export declare function compact<Value>(
|
|
1580
|
-
array: Value[],
|
|
1581
|
-
): Exclude<Value, null | undefined>[];
|
|
1582
|
-
export type ArrayCallback<Value, Returned> = (
|
|
1583
|
-
value: Value,
|
|
1584
|
-
index: number,
|
|
1585
|
-
array: Value[],
|
|
1586
|
-
) => Returned;
|
|
1587
|
-
export type BooleanCallback<Value> = ArrayCallback<Value, boolean>;
|
|
1588
|
-
export type KeyCallback<Value> = ArrayCallback<Value, Key>;
|
|
1589
|
-
export type SortKey<Value> = {
|
|
1590
|
-
direction: 'asc' | 'desc';
|
|
1591
|
-
value: Key | SortKeyCallback<Value>;
|
|
1592
|
-
};
|
|
1593
|
-
export type SortKeyCallback<Value> = (value: Value) => Key;
|
|
1594
|
-
/**
|
|
1595
|
-
* Returns the number of items _(count)_ that match the given value
|
|
1596
|
-
*/
|
|
1597
|
-
export declare function count<Model, Value>(
|
|
1598
|
-
array: Model[],
|
|
1599
|
-
value: Value | BooleanCallback<Model>,
|
|
1600
|
-
): number;
|
|
1601
1538
|
/**
|
|
1602
|
-
*
|
|
1603
|
-
* - Use `key` to find a comparison value to match with `value`
|
|
1539
|
+
* Convert a query string to a plain _(nested)_ object
|
|
1604
1540
|
*/
|
|
1605
|
-
export declare function
|
|
1606
|
-
array: Model[],
|
|
1607
|
-
value: Value,
|
|
1608
|
-
key: Key | KeyCallback<Model>,
|
|
1609
|
-
): number;
|
|
1541
|
+
export declare function fromQuery(query: string): PlainObject;
|
|
1610
1542
|
/**
|
|
1611
|
-
*
|
|
1543
|
+
* Convert a plain _(nested)_ object to a query string
|
|
1612
1544
|
*/
|
|
1613
|
-
export declare function
|
|
1614
|
-
array: Model[],
|
|
1615
|
-
value: Value | BooleanCallback<Model>,
|
|
1616
|
-
): boolean;
|
|
1545
|
+
export declare function toQuery(parameters: PlainObject): string;
|
|
1617
1546
|
/**
|
|
1618
|
-
*
|
|
1619
|
-
* - Use `key` to find a comparison value to match with `value`
|
|
1547
|
+
* Is the number between a minimum and maximum value?
|
|
1620
1548
|
*/
|
|
1621
|
-
export declare function
|
|
1622
|
-
|
|
1623
|
-
|
|
1624
|
-
|
|
1549
|
+
export declare function between(
|
|
1550
|
+
value: number,
|
|
1551
|
+
min: number,
|
|
1552
|
+
max: number,
|
|
1625
1553
|
): boolean;
|
|
1626
1554
|
/**
|
|
1627
|
-
*
|
|
1628
|
-
|
|
1629
|
-
export declare function filter<Model, Value>(
|
|
1630
|
-
array: Model[],
|
|
1631
|
-
value: Value | BooleanCallback<Model>,
|
|
1632
|
-
): Model[];
|
|
1633
|
-
/**
|
|
1634
|
-
* - Returns a filtered array of items
|
|
1635
|
-
* - Use `key` to find a comparison value to match with `value`
|
|
1636
|
-
*/
|
|
1637
|
-
export declare function filter<Model, Value = Model>(
|
|
1638
|
-
array: Model[],
|
|
1639
|
-
value: Value,
|
|
1640
|
-
key: Key | KeyCallback<Model>,
|
|
1641
|
-
): Model[];
|
|
1642
|
-
/**
|
|
1643
|
-
* Returns the first item matching `value`, or `undefined` if no match is found
|
|
1644
|
-
*/
|
|
1645
|
-
export declare function find<Model, Value>(
|
|
1646
|
-
array: Model[],
|
|
1647
|
-
value: Value | BooleanCallback<Model>,
|
|
1648
|
-
): Model | undefined;
|
|
1649
|
-
/**
|
|
1650
|
-
* - Returns the first matching item, or `undefined` if no match is found
|
|
1651
|
-
* - Use `key` to find a comparison value to match with `value`
|
|
1652
|
-
*/
|
|
1653
|
-
export declare function find<Model, Value = Model>(
|
|
1654
|
-
array: Model[],
|
|
1655
|
-
value: Value,
|
|
1656
|
-
key: Key | KeyCallback<Model>,
|
|
1657
|
-
): Model | undefined;
|
|
1658
|
-
/**
|
|
1659
|
-
* Groups an array of items using a key or callback
|
|
1555
|
+
* - Clamp a number between a minimum and maximum value
|
|
1556
|
+
* - If `loop` is `true`, when the value is less than the minimum, it will be clamped as the maximum, and vice versa
|
|
1660
1557
|
*/
|
|
1661
|
-
export declare function
|
|
1662
|
-
|
|
1663
|
-
|
|
1664
|
-
|
|
1558
|
+
export declare function clamp(
|
|
1559
|
+
value: number,
|
|
1560
|
+
min: number,
|
|
1561
|
+
max: number,
|
|
1562
|
+
loop?: boolean,
|
|
1563
|
+
): number;
|
|
1665
1564
|
/**
|
|
1666
|
-
*
|
|
1565
|
+
* - Get the number value from an unknown value
|
|
1566
|
+
* - Returns `NaN` if the value is `undefined`, `null`, or cannot be parsed
|
|
1567
|
+
* - Based on Lodash :-)
|
|
1667
1568
|
*/
|
|
1668
|
-
export declare function
|
|
1669
|
-
array: Model[],
|
|
1670
|
-
value: Value | BooleanCallback<Model>,
|
|
1671
|
-
): number;
|
|
1569
|
+
export declare function getNumber(value: unknown): number;
|
|
1672
1570
|
/**
|
|
1673
|
-
*
|
|
1674
|
-
* - Use `key` to find a comparison value to match with `value`
|
|
1571
|
+
* Get the average value from a list of numbers
|
|
1675
1572
|
*/
|
|
1676
|
-
export declare function
|
|
1677
|
-
array: Model[],
|
|
1678
|
-
value: Value,
|
|
1679
|
-
key: Key | KeyCallback<Model>,
|
|
1680
|
-
): number;
|
|
1573
|
+
export declare function average(values: number[]): number;
|
|
1681
1574
|
/**
|
|
1682
|
-
*
|
|
1683
|
-
* - Uses chunking to avoid stack overflow
|
|
1575
|
+
* Get the maximum value from a list of numbers
|
|
1684
1576
|
*/
|
|
1685
|
-
export declare function
|
|
1686
|
-
array: Value[],
|
|
1687
|
-
index: number,
|
|
1688
|
-
values: Value[],
|
|
1689
|
-
): void;
|
|
1577
|
+
export declare function max(values: number[]): number;
|
|
1690
1578
|
/**
|
|
1691
|
-
*
|
|
1579
|
+
* Get the minimum value from a list of numbers
|
|
1692
1580
|
*/
|
|
1693
|
-
export declare function
|
|
1581
|
+
export declare function min(values: number[]): number;
|
|
1694
1582
|
/**
|
|
1695
|
-
*
|
|
1583
|
+
* Round a number to a specific number of decimal places _(defaults to 0)_
|
|
1696
1584
|
*/
|
|
1697
|
-
export declare function
|
|
1698
|
-
array: Value[],
|
|
1699
|
-
descending?: boolean,
|
|
1700
|
-
): Value[];
|
|
1585
|
+
export declare function round(value: number, decimals?: number): number;
|
|
1701
1586
|
/**
|
|
1702
|
-
*
|
|
1703
|
-
* - Ascending by default, but can be changed by setting `descending` to `true`, or using a `SortKey`
|
|
1587
|
+
* Get the sum of a list of numbers
|
|
1704
1588
|
*/
|
|
1705
|
-
export declare function
|
|
1706
|
-
|
|
1707
|
-
|
|
1589
|
+
export declare function sum(values: number[]): number;
|
|
1590
|
+
declare class Logger {
|
|
1591
|
+
/**
|
|
1592
|
+
* Log any number of values at the "debug" log level
|
|
1593
|
+
*/
|
|
1594
|
+
get debug(): {
|
|
1595
|
+
(...data: any[]): void;
|
|
1596
|
+
(message?: any, ...optionalParams: any[]): void;
|
|
1597
|
+
};
|
|
1598
|
+
/**
|
|
1599
|
+
* Log the value and shows all its properties
|
|
1600
|
+
*/
|
|
1601
|
+
get dir(): {
|
|
1602
|
+
(item?: any, options?: any): void;
|
|
1603
|
+
(obj: any, options?: import('util').InspectOptions): void;
|
|
1604
|
+
};
|
|
1605
|
+
/**
|
|
1606
|
+
* Is logging to the console enabled? _(defaults to `true`)_
|
|
1607
|
+
*/
|
|
1608
|
+
get enabled(): boolean;
|
|
1609
|
+
/**
|
|
1610
|
+
* Enable or disable logging to the console
|
|
1611
|
+
*/
|
|
1612
|
+
set enabled(value: boolean);
|
|
1613
|
+
/**
|
|
1614
|
+
* Log any number of values at the "error" log level
|
|
1615
|
+
*/
|
|
1616
|
+
get error(): {
|
|
1617
|
+
(...data: any[]): void;
|
|
1618
|
+
(message?: any, ...optionalParams: any[]): void;
|
|
1619
|
+
};
|
|
1620
|
+
/**
|
|
1621
|
+
* Log any number of values at the "info" log level
|
|
1622
|
+
*/
|
|
1623
|
+
get info(): {
|
|
1624
|
+
(...data: any[]): void;
|
|
1625
|
+
(message?: any, ...optionalParams: any[]): void;
|
|
1626
|
+
};
|
|
1627
|
+
/**
|
|
1628
|
+
* Log any number of values at the "log" log level
|
|
1629
|
+
*/
|
|
1630
|
+
get log(): {
|
|
1631
|
+
(...data: any[]): void;
|
|
1632
|
+
(message?: any, ...optionalParams: any[]): void;
|
|
1633
|
+
};
|
|
1634
|
+
/**
|
|
1635
|
+
* Log data as a table, with optional properties to use as columns
|
|
1636
|
+
*/
|
|
1637
|
+
get table(): {
|
|
1638
|
+
(tabularData?: any, properties?: string[]): void;
|
|
1639
|
+
(tabularData: any, properties?: readonly string[]): void;
|
|
1640
|
+
};
|
|
1641
|
+
/**
|
|
1642
|
+
* Log any number of values together with a trace from where it was called
|
|
1643
|
+
*/
|
|
1644
|
+
get trace(): {
|
|
1645
|
+
(...data: any[]): void;
|
|
1646
|
+
(message?: any, ...optionalParams: any[]): void;
|
|
1647
|
+
};
|
|
1648
|
+
/**
|
|
1649
|
+
* Log any number of values at the "warn" log level
|
|
1650
|
+
*/
|
|
1651
|
+
get warn(): {
|
|
1652
|
+
(...data: any[]): void;
|
|
1653
|
+
(message?: any, ...optionalParams: any[]): void;
|
|
1654
|
+
};
|
|
1655
|
+
/**
|
|
1656
|
+
* - Start a logged timer with a label
|
|
1657
|
+
* - Returns a `Time`-object for logging the current duration of the timer and stopping the timer _(and logging the total duration)_
|
|
1658
|
+
*/
|
|
1659
|
+
time(label: string): Time;
|
|
1660
|
+
}
|
|
1661
|
+
declare class Time {
|
|
1662
|
+
private readonly state;
|
|
1663
|
+
constructor(label: string);
|
|
1664
|
+
/**
|
|
1665
|
+
* - Log the current duration of the timer
|
|
1666
|
+
* - _(Ignored if logging is disabled)_
|
|
1667
|
+
*/
|
|
1668
|
+
log(): void;
|
|
1669
|
+
/**
|
|
1670
|
+
* - Stop the timer and logs the total duration
|
|
1671
|
+
* - _(Will always log the total duration, even if logging is disabled)_
|
|
1672
|
+
*/
|
|
1673
|
+
stop(): void;
|
|
1674
|
+
}
|
|
1675
|
+
export declare const logger: Logger;
|
|
1676
|
+
/**
|
|
1677
|
+
* Is the value an array or a record?
|
|
1678
|
+
*/
|
|
1679
|
+
export declare function isArrayOrPlainObject(
|
|
1680
|
+
value: unknown,
|
|
1681
|
+
): value is ArrayOrPlainObject;
|
|
1682
|
+
/**
|
|
1683
|
+
* Is the array or object completely empty or only containing `null` or `undefined` values?
|
|
1684
|
+
*/
|
|
1685
|
+
export declare function isEmpty(value: ArrayOrPlainObject): boolean;
|
|
1686
|
+
/**
|
|
1687
|
+
* Is the value a key?
|
|
1688
|
+
*/
|
|
1689
|
+
export declare function isKey(value: unknown): value is Key;
|
|
1690
|
+
/**
|
|
1691
|
+
* Is the value undefined or null?
|
|
1692
|
+
*/
|
|
1693
|
+
export declare function isNullable(value: unknown): value is undefined | null;
|
|
1694
|
+
/**
|
|
1695
|
+
* Is the value undefined, null, or an empty string?
|
|
1696
|
+
*/
|
|
1697
|
+
export declare function isNullableOrEmpty(
|
|
1698
|
+
value: unknown,
|
|
1699
|
+
): value is undefined | null | '';
|
|
1700
|
+
/**
|
|
1701
|
+
* Is the value undefined, null, or a whitespace-only string?
|
|
1702
|
+
*/
|
|
1703
|
+
export declare function isNullableOrWhitespace(
|
|
1704
|
+
value: unknown,
|
|
1705
|
+
): value is undefined | null | '';
|
|
1706
|
+
/**
|
|
1707
|
+
* Is the value a number?
|
|
1708
|
+
*/
|
|
1709
|
+
export declare function isNumber(value: unknown): value is number;
|
|
1710
|
+
/**
|
|
1711
|
+
* Is the value a number, or a number-like string?
|
|
1712
|
+
*/
|
|
1713
|
+
export declare function isNumerical(
|
|
1714
|
+
value: unknown,
|
|
1715
|
+
): value is number | `${number}`;
|
|
1716
|
+
/**
|
|
1717
|
+
* Is the value an object?
|
|
1718
|
+
*/
|
|
1719
|
+
export declare function isObject(value: unknown): value is object;
|
|
1720
|
+
/**
|
|
1721
|
+
* Is the value a plain object?
|
|
1722
|
+
*/
|
|
1723
|
+
export declare function isPlainObject(value: unknown): value is PlainObject;
|
|
1724
|
+
/**
|
|
1725
|
+
* Is the value a primitive value?
|
|
1726
|
+
*/
|
|
1727
|
+
export declare function isPrimitive(value: unknown): value is Primitive;
|
|
1728
|
+
/**
|
|
1729
|
+
* Chunk an array _(into smaller arrays of a specified size)_
|
|
1730
|
+
*/
|
|
1731
|
+
export declare function chunk<Item>(array: Item[], size?: number): Item[][];
|
|
1732
|
+
/**
|
|
1733
|
+
* Compact an array _(removing all `null` and `undefined` values)_
|
|
1734
|
+
*/
|
|
1735
|
+
export declare function compact<Item>(
|
|
1736
|
+
array: Item[],
|
|
1737
|
+
): Exclude<Item, null | undefined>[];
|
|
1738
|
+
/**
|
|
1739
|
+
* Compact an array _(removing all falsey values)_
|
|
1740
|
+
*/
|
|
1741
|
+
export declare function compact<Item>(
|
|
1742
|
+
array: Item[],
|
|
1743
|
+
strict: true,
|
|
1744
|
+
): Exclude<Item, 0 | '' | false | null | undefined>[];
|
|
1745
|
+
export type ArrayCallback<Item, Value> = (
|
|
1746
|
+
item: Item,
|
|
1747
|
+
index: number,
|
|
1748
|
+
array: Item[],
|
|
1749
|
+
) => Value;
|
|
1750
|
+
export type BooleanCallback<Item> = ArrayCallback<Item, boolean>;
|
|
1751
|
+
export type KeyCallback<Item> = ArrayCallback<Item, Key>;
|
|
1752
|
+
export type SortKey<Item> = {
|
|
1753
|
+
direction: 'asc' | 'desc';
|
|
1754
|
+
value: Key | SortKeyCallback<Item>;
|
|
1755
|
+
};
|
|
1756
|
+
export type SortKeyCallback<Item> = (item: Item) => unknown;
|
|
1757
|
+
export type ValueCallback<Item> = ArrayCallback<Item, unknown>;
|
|
1758
|
+
/**
|
|
1759
|
+
* Get the number of items _(count)_ that match the given value
|
|
1760
|
+
*/
|
|
1761
|
+
export declare function count<Item>(array: Item[], value: Item): number;
|
|
1762
|
+
/**
|
|
1763
|
+
* Get the number of items _(count)_ that match the given value
|
|
1764
|
+
*/
|
|
1765
|
+
export declare function count<Item>(
|
|
1766
|
+
array: Item[],
|
|
1767
|
+
matches: BooleanCallback<Item>,
|
|
1768
|
+
): number;
|
|
1769
|
+
/**
|
|
1770
|
+
* Get the number of items _(count)_ that match the given value
|
|
1771
|
+
*/
|
|
1772
|
+
export declare function count<Item, Key extends keyof Item>(
|
|
1773
|
+
array: Item[],
|
|
1774
|
+
key: Key,
|
|
1775
|
+
value: Item[Key],
|
|
1776
|
+
): number;
|
|
1777
|
+
/**
|
|
1778
|
+
* Get the number of items _(count)_ that match the given value
|
|
1779
|
+
*/
|
|
1780
|
+
export declare function count<Item, Key extends KeyCallback<Item>>(
|
|
1781
|
+
array: Item[],
|
|
1782
|
+
key: Key,
|
|
1783
|
+
value: ReturnType<Key>,
|
|
1784
|
+
): number;
|
|
1785
|
+
/**
|
|
1786
|
+
* Does the value exist in array?
|
|
1787
|
+
*/
|
|
1788
|
+
export declare function exists<Item>(array: Item[], value: Item): boolean;
|
|
1789
|
+
/**
|
|
1790
|
+
* Does the value exist in array?
|
|
1791
|
+
*/
|
|
1792
|
+
export declare function exists<Item>(
|
|
1793
|
+
array: Item[],
|
|
1794
|
+
matches: BooleanCallback<Item>,
|
|
1795
|
+
): boolean;
|
|
1796
|
+
/**
|
|
1797
|
+
* - Does the value exist in array?
|
|
1798
|
+
* - Use `key` to find a comparison value to match with `value`
|
|
1799
|
+
*/
|
|
1800
|
+
export declare function exists<Item, Key extends keyof Item>(
|
|
1801
|
+
array: Item[],
|
|
1802
|
+
key: Key,
|
|
1803
|
+
value: Item[Key],
|
|
1804
|
+
): boolean;
|
|
1805
|
+
/**
|
|
1806
|
+
* - Does the value exist in array?
|
|
1807
|
+
* - Use `key` to find a comparison value to match with `value`
|
|
1808
|
+
*/
|
|
1809
|
+
export declare function exists<Item, Key extends KeyCallback<Item>>(
|
|
1810
|
+
array: Item[],
|
|
1811
|
+
key: Key,
|
|
1812
|
+
value: ReturnType<Key>,
|
|
1813
|
+
): boolean;
|
|
1814
|
+
/**
|
|
1815
|
+
* Get a filtered array of items matching `value`
|
|
1816
|
+
*/
|
|
1817
|
+
export declare function filter<Item>(array: Item[], value: Item): Item[];
|
|
1818
|
+
/**
|
|
1819
|
+
* Get a filtered array of items matching `value`
|
|
1820
|
+
*/
|
|
1821
|
+
export declare function filter<Item>(
|
|
1822
|
+
array: Item[],
|
|
1823
|
+
matches: BooleanCallback<Item>,
|
|
1824
|
+
): Item[];
|
|
1825
|
+
/**
|
|
1826
|
+
* - Get a filtered array of items
|
|
1827
|
+
* - Use `key` to find a comparison value to match with `value`
|
|
1828
|
+
*/
|
|
1829
|
+
export declare function filter<Item, Key extends keyof Item>(
|
|
1830
|
+
array: Item[],
|
|
1831
|
+
key: Key,
|
|
1832
|
+
value: Item[Key],
|
|
1833
|
+
): Item[];
|
|
1834
|
+
/**
|
|
1835
|
+
* - Get a filtered array of items
|
|
1836
|
+
* - Use `key` to find a comparison value to match with `value`
|
|
1837
|
+
*/
|
|
1838
|
+
export declare function filter<Item, Key extends KeyCallback<Item>>(
|
|
1839
|
+
array: Item[],
|
|
1840
|
+
key: Key,
|
|
1841
|
+
value: ReturnType<Key>,
|
|
1842
|
+
): Item[];
|
|
1843
|
+
/**
|
|
1844
|
+
* Get the first item matching `value` _(or `undefined` if no match is found)_
|
|
1845
|
+
*/
|
|
1846
|
+
export declare function find<Item>(
|
|
1847
|
+
array: Item[],
|
|
1848
|
+
value: Item,
|
|
1849
|
+
): Item | undefined;
|
|
1850
|
+
/**
|
|
1851
|
+
* Get the first item matching `value` _(or `undefined` if no match is found)_
|
|
1852
|
+
*/
|
|
1853
|
+
export declare function find<Item>(
|
|
1854
|
+
array: Item[],
|
|
1855
|
+
matches: BooleanCallback<Item>,
|
|
1856
|
+
): Item | undefined;
|
|
1857
|
+
/**
|
|
1858
|
+
* - Get the first matching item _(or `undefined` if no match is found)_
|
|
1859
|
+
* - Use `key` to find a comparison value to match with `value`
|
|
1860
|
+
*/
|
|
1861
|
+
export declare function find<Item, Key extends keyof Item>(
|
|
1862
|
+
array: Item[],
|
|
1863
|
+
key: Key,
|
|
1864
|
+
value: Item[Key],
|
|
1865
|
+
): Item | undefined;
|
|
1866
|
+
/**
|
|
1867
|
+
* - Get the first matching item _(or `undefined` if no match is found)_
|
|
1868
|
+
* - Use `key` to find a comparison value to match with `value`
|
|
1869
|
+
*/
|
|
1870
|
+
export declare function find<Item, Key extends KeyCallback<Item>>(
|
|
1871
|
+
array: Item[],
|
|
1872
|
+
key: Key,
|
|
1873
|
+
value: ReturnType<Key>,
|
|
1874
|
+
): Item | undefined;
|
|
1875
|
+
/**
|
|
1876
|
+
* Create a record from an array of items using a specific key
|
|
1877
|
+
*/
|
|
1878
|
+
export declare function groupBy<Item, Key extends keyof Item>(
|
|
1879
|
+
array: Item[],
|
|
1880
|
+
key: Key,
|
|
1881
|
+
): Record<KeyedValue<Item, Key>, Item>;
|
|
1882
|
+
/**
|
|
1883
|
+
* Create a record from an array of items using a specific key, and grouping them into arrays
|
|
1884
|
+
*/
|
|
1885
|
+
export declare function groupBy<Item, Key extends keyof Item>(
|
|
1886
|
+
array: Item[],
|
|
1887
|
+
key: Key,
|
|
1888
|
+
arrays: true,
|
|
1889
|
+
): Record<KeyedValue<Item, Key>, Item[]>;
|
|
1890
|
+
/**
|
|
1891
|
+
* Create a record from an array of items using a specific key
|
|
1892
|
+
*/
|
|
1893
|
+
export declare function groupBy<Item, Key extends KeyCallback<Item>>(
|
|
1894
|
+
array: Item[],
|
|
1895
|
+
key: Key,
|
|
1896
|
+
): Record<ReturnType<Key>, Item>;
|
|
1897
|
+
/**
|
|
1898
|
+
* Create a record from an array of items using a specific key, and grouping them into arrays
|
|
1899
|
+
*/
|
|
1900
|
+
export declare function groupBy<Item, Key extends KeyCallback<Item>>(
|
|
1901
|
+
array: Item[],
|
|
1902
|
+
key: Key,
|
|
1903
|
+
arrays: true,
|
|
1904
|
+
): Record<ReturnType<Key>, Item[]>;
|
|
1905
|
+
/**
|
|
1906
|
+
* Create a record from an array of items using a specific key and value
|
|
1907
|
+
*/
|
|
1908
|
+
export declare function groupBy<
|
|
1909
|
+
Item,
|
|
1910
|
+
Key extends keyof Item,
|
|
1911
|
+
Value extends keyof Item,
|
|
1912
|
+
>(
|
|
1913
|
+
array: Item[],
|
|
1914
|
+
key: Key,
|
|
1915
|
+
value: Value,
|
|
1916
|
+
): Record<KeyedValue<Item, Key>, KeyedValue<Item, Value>>;
|
|
1917
|
+
/**
|
|
1918
|
+
* Create a record from an array of items using a specific key and value, and grouping them into arrays
|
|
1919
|
+
*/
|
|
1920
|
+
export declare function groupBy<
|
|
1921
|
+
Item,
|
|
1922
|
+
Key extends keyof Item,
|
|
1923
|
+
Value extends keyof Item,
|
|
1924
|
+
>(
|
|
1925
|
+
array: Item[],
|
|
1926
|
+
key: Key,
|
|
1927
|
+
value: Value,
|
|
1928
|
+
arrays: true,
|
|
1929
|
+
): Record<KeyedValue<Item, Key>, Array<KeyedValue<Item, Value>>>;
|
|
1930
|
+
/**
|
|
1931
|
+
* Create a record from an array of items using a specific key and value
|
|
1932
|
+
*/
|
|
1933
|
+
export declare function groupBy<
|
|
1934
|
+
Item,
|
|
1935
|
+
Key extends keyof Item,
|
|
1936
|
+
Value extends ValueCallback<Item>,
|
|
1937
|
+
>(
|
|
1938
|
+
array: Item[],
|
|
1939
|
+
key: Key,
|
|
1940
|
+
value: Value,
|
|
1941
|
+
): Record<KeyedValue<Item, Key>, ReturnType<Value>>;
|
|
1942
|
+
/**
|
|
1943
|
+
* Create a record from an array of items using a specific key and value, and grouping them into arrays
|
|
1944
|
+
*/
|
|
1945
|
+
export declare function groupBy<
|
|
1946
|
+
Item,
|
|
1947
|
+
Key extends keyof Item,
|
|
1948
|
+
Value extends ValueCallback<Item>,
|
|
1949
|
+
>(
|
|
1950
|
+
array: Item[],
|
|
1951
|
+
key: Key,
|
|
1952
|
+
value: Value,
|
|
1953
|
+
arrays: true,
|
|
1954
|
+
): Record<KeyedValue<Item, Key>, Array<ReturnType<Value>>>;
|
|
1955
|
+
/**
|
|
1956
|
+
* Create a record from an array of items using a specific key and value
|
|
1957
|
+
*/
|
|
1958
|
+
export declare function groupBy<
|
|
1959
|
+
Item,
|
|
1960
|
+
Key extends KeyCallback<Item>,
|
|
1961
|
+
Value extends keyof Item,
|
|
1962
|
+
>(
|
|
1963
|
+
array: Item[],
|
|
1964
|
+
key: Key,
|
|
1965
|
+
value: Value,
|
|
1966
|
+
): Record<ReturnType<Key>, KeyedValue<Item, Value>>;
|
|
1967
|
+
/**
|
|
1968
|
+
* Create a record from an array of items using a specific key and value, and grouping them into arrays
|
|
1969
|
+
*/
|
|
1970
|
+
export declare function groupBy<
|
|
1971
|
+
Item,
|
|
1972
|
+
Key extends KeyCallback<Item>,
|
|
1973
|
+
Value extends keyof Item,
|
|
1974
|
+
>(
|
|
1975
|
+
array: Item[],
|
|
1976
|
+
key: Key,
|
|
1977
|
+
value: Value,
|
|
1978
|
+
arrays: true,
|
|
1979
|
+
): Record<ReturnType<Key>, Array<KeyedValue<Item, Value>>>;
|
|
1980
|
+
/**
|
|
1981
|
+
* Create a record from an array of items using a specific key and value
|
|
1982
|
+
*/
|
|
1983
|
+
export declare function groupBy<
|
|
1984
|
+
Item,
|
|
1985
|
+
Key extends KeyCallback<Item>,
|
|
1986
|
+
Value extends ValueCallback<Item>,
|
|
1987
|
+
>(
|
|
1988
|
+
array: Item[],
|
|
1989
|
+
key: Key,
|
|
1990
|
+
value: Value,
|
|
1991
|
+
): Record<ReturnType<Key>, ReturnType<Value>>;
|
|
1992
|
+
/**
|
|
1993
|
+
* Create a record from an array of items using a specific key and value, and grouping them into arrays
|
|
1994
|
+
*/
|
|
1995
|
+
export declare function groupBy<
|
|
1996
|
+
Item,
|
|
1997
|
+
Key extends KeyCallback<Item>,
|
|
1998
|
+
Value extends ValueCallback<Item>,
|
|
1999
|
+
>(
|
|
2000
|
+
array: Item[],
|
|
2001
|
+
key: Key,
|
|
2002
|
+
value: Value,
|
|
2003
|
+
arrays: true,
|
|
2004
|
+
): Record<ReturnType<Key>, Array<ReturnType<Value>>>;
|
|
2005
|
+
/**
|
|
2006
|
+
* Get the index for the first item matching `value` _(or `-1` if no match is found)_
|
|
2007
|
+
*/
|
|
2008
|
+
export declare function indexOf<Item>(array: Item[], value: Item): number;
|
|
2009
|
+
/**
|
|
2010
|
+
* Get the index for the first item matching `value` _(or `-1` if no match is found)_
|
|
2011
|
+
*/
|
|
2012
|
+
export declare function indexOf<Item>(
|
|
2013
|
+
array: Item[],
|
|
2014
|
+
matches: BooleanCallback<Item>,
|
|
2015
|
+
): number;
|
|
2016
|
+
/**
|
|
2017
|
+
* - Get the index for the first matching item _(or `-1` if no match is found)_
|
|
2018
|
+
* - Use `key` to find a comparison value to match with `value`
|
|
2019
|
+
*/
|
|
2020
|
+
export declare function indexOf<Item, Key extends keyof Item>(
|
|
2021
|
+
array: Item[],
|
|
2022
|
+
key: Key,
|
|
2023
|
+
value: Item[Key],
|
|
2024
|
+
): number;
|
|
2025
|
+
/**
|
|
2026
|
+
* - Get the index for the first matching item _(or `-1` if no match is found)_
|
|
2027
|
+
* - Use `key` to find a comparison value to match with `value`
|
|
2028
|
+
*/
|
|
2029
|
+
export declare function indexOf<Item, Key extends KeyCallback<Item>>(
|
|
2030
|
+
array: Item[],
|
|
2031
|
+
key: Key,
|
|
2032
|
+
value: ReturnType<Key>,
|
|
2033
|
+
): number;
|
|
2034
|
+
/**
|
|
2035
|
+
* - Insert values into an array _(at the end)_
|
|
2036
|
+
* - _(Uses chunking to avoid stack overflow_)
|
|
2037
|
+
*/
|
|
2038
|
+
export declare function insert<Item>(array: Item[], items: Item[]): void;
|
|
2039
|
+
/**
|
|
2040
|
+
* - Insert values into an array at a specified index
|
|
2041
|
+
* - _(Uses chunking to avoid stack overflow_)
|
|
2042
|
+
*/
|
|
2043
|
+
export declare function insert<Item>(
|
|
2044
|
+
array: Item[],
|
|
2045
|
+
index: number,
|
|
2046
|
+
items: Item[],
|
|
2047
|
+
): void;
|
|
2048
|
+
/**
|
|
2049
|
+
* Shuffle an array
|
|
2050
|
+
*/
|
|
2051
|
+
export declare function shuffle<Item>(array: Item[]): Item[];
|
|
2052
|
+
/**
|
|
2053
|
+
* Sort an array of items _(defaults to ascending)_
|
|
2054
|
+
*/
|
|
2055
|
+
export declare function sort<Item>(array: Item[], descending?: boolean): Item[];
|
|
2056
|
+
/**
|
|
2057
|
+
* - Sort an array of items, using a `key` to sort by a specific value
|
|
2058
|
+
* - Defaults to ascending, but can be changed by setting `descending` to `true`, or using a `SortKey`
|
|
2059
|
+
*/
|
|
2060
|
+
export declare function sort<Item>(
|
|
2061
|
+
array: Item[],
|
|
2062
|
+
key: Key | SortKey<Item> | SortKeyCallback<Item>,
|
|
1708
2063
|
descending?: boolean,
|
|
1709
|
-
):
|
|
2064
|
+
): Item[];
|
|
1710
2065
|
/**
|
|
1711
|
-
* -
|
|
1712
|
-
* -
|
|
2066
|
+
* - Sort an array of items, using multiple `keys` to sort by specific values
|
|
2067
|
+
* - Defaults to ascending, but can be changed by setting `descending` to `true`, or using `SortKey`
|
|
1713
2068
|
*/
|
|
1714
|
-
export declare function sort<
|
|
1715
|
-
array:
|
|
1716
|
-
keys: Array<Key | SortKey<
|
|
2069
|
+
export declare function sort<Item>(
|
|
2070
|
+
array: Item[],
|
|
2071
|
+
keys: Array<Key | SortKey<Item> | SortKeyCallback<Item>>,
|
|
1717
2072
|
descending?: boolean,
|
|
1718
|
-
):
|
|
2073
|
+
): Item[];
|
|
1719
2074
|
/**
|
|
1720
2075
|
* Removes and returns all items from an array starting from a specific index
|
|
1721
2076
|
*/
|
|
1722
|
-
export declare function splice<
|
|
2077
|
+
export declare function splice<Item>(array: Item[], start: number): Item[];
|
|
1723
2078
|
/**
|
|
1724
2079
|
* Removes and returns _(up to)_ a specific amount of items from an array, starting from a specific index
|
|
1725
2080
|
*/
|
|
1726
|
-
export declare function splice<
|
|
1727
|
-
array:
|
|
2081
|
+
export declare function splice<Item>(
|
|
2082
|
+
array: Item[],
|
|
1728
2083
|
start: number,
|
|
1729
2084
|
amount: number,
|
|
1730
|
-
):
|
|
2085
|
+
): Item[];
|
|
1731
2086
|
/**
|
|
1732
2087
|
* - Splices values into an array and returns any removed values
|
|
1733
2088
|
* - Uses chunking to avoid stack overflow
|
|
1734
2089
|
*/
|
|
1735
|
-
export declare function splice<
|
|
1736
|
-
array:
|
|
2090
|
+
export declare function splice<Item>(
|
|
2091
|
+
array: Item[],
|
|
1737
2092
|
start: number,
|
|
1738
|
-
|
|
1739
|
-
):
|
|
2093
|
+
added: Item[],
|
|
2094
|
+
): Item[];
|
|
1740
2095
|
/**
|
|
1741
2096
|
* - Splices values into an array and returns any removed values
|
|
1742
2097
|
* - Uses chunking to avoid stack overflow
|
|
1743
2098
|
*/
|
|
1744
|
-
export declare function splice<
|
|
1745
|
-
array:
|
|
2099
|
+
export declare function splice<Item>(
|
|
2100
|
+
array: Item[],
|
|
1746
2101
|
start: number,
|
|
1747
2102
|
amount: number,
|
|
1748
|
-
|
|
1749
|
-
):
|
|
2103
|
+
added: Item[],
|
|
2104
|
+
): Item[];
|
|
1750
2105
|
/**
|
|
1751
|
-
*
|
|
2106
|
+
* Create a map from an array of items _(using their indices as keys)_
|
|
1752
2107
|
*/
|
|
1753
|
-
export declare function toMap<
|
|
2108
|
+
export declare function toMap<Item>(array: Item[]): Map<number, Item>;
|
|
1754
2109
|
/**
|
|
1755
|
-
*
|
|
2110
|
+
* Create a map from an array of items using a specific key
|
|
1756
2111
|
*/
|
|
1757
|
-
export declare function toMap<
|
|
1758
|
-
array:
|
|
2112
|
+
export declare function toMap<Item, Key extends keyof Item>(
|
|
2113
|
+
array: Item[],
|
|
2114
|
+
key: Key,
|
|
2115
|
+
): Map<KeyedValue<Item, Key>, Item>;
|
|
2116
|
+
/**
|
|
2117
|
+
* Create a map from an array of items using a specific key, and grouping them into arrays
|
|
2118
|
+
*/
|
|
2119
|
+
export declare function toMap<Item, Key extends keyof Item>(
|
|
2120
|
+
array: Item[],
|
|
2121
|
+
key: Key,
|
|
1759
2122
|
arrays: true,
|
|
1760
|
-
): Map<
|
|
2123
|
+
): Map<KeyedValue<Item, Key>, Item[]>;
|
|
1761
2124
|
/**
|
|
1762
|
-
*
|
|
1763
|
-
* - Uses `key` to find an identifcation value to use as keys
|
|
2125
|
+
* Create a map from an array of items using a specific key
|
|
1764
2126
|
*/
|
|
1765
|
-
export declare function toMap<
|
|
2127
|
+
export declare function toMap<Item, Key extends KeyCallback<Item>>(
|
|
2128
|
+
array: Item[],
|
|
2129
|
+
key: Key,
|
|
2130
|
+
): Map<ReturnType<Key>, Item>;
|
|
1766
2131
|
/**
|
|
1767
|
-
*
|
|
1768
|
-
* - Uses `key` to find an identifcation value to use as keys
|
|
1769
|
-
* - Groups values into arrays
|
|
2132
|
+
* Create a map from an array of items using a specific key, and grouping them into arrays
|
|
1770
2133
|
*/
|
|
1771
|
-
export declare function toMap<
|
|
1772
|
-
array:
|
|
2134
|
+
export declare function toMap<Item, Key extends KeyCallback<Item>>(
|
|
2135
|
+
array: Item[],
|
|
1773
2136
|
key: Key,
|
|
1774
2137
|
arrays: true,
|
|
1775
|
-
): Map<Key
|
|
2138
|
+
): Map<ReturnType<Key>, Item[]>;
|
|
1776
2139
|
/**
|
|
1777
|
-
*
|
|
1778
|
-
* - Uses `key` to find an identifcation value to use as keys
|
|
2140
|
+
* Create a map from an array of items using a specific key and value
|
|
1779
2141
|
*/
|
|
1780
|
-
export declare function toMap<
|
|
1781
|
-
|
|
1782
|
-
|
|
1783
|
-
|
|
2142
|
+
export declare function toMap<
|
|
2143
|
+
Item,
|
|
2144
|
+
Key extends keyof Item,
|
|
2145
|
+
Value extends keyof Item,
|
|
2146
|
+
>(
|
|
2147
|
+
array: Item[],
|
|
2148
|
+
key: Key,
|
|
2149
|
+
value: Value,
|
|
2150
|
+
): Map<KeyedValue<Item, Key>, KeyedValue<Item, Value>>;
|
|
1784
2151
|
/**
|
|
1785
|
-
*
|
|
1786
|
-
* - Uses `key` to find an identifcation value to use as keys
|
|
1787
|
-
* - Groups values into arrays
|
|
2152
|
+
* Create a map from an array of items using a specific key and value, and grouping them into arrays
|
|
1788
2153
|
*/
|
|
1789
|
-
export declare function toMap<
|
|
1790
|
-
|
|
1791
|
-
|
|
2154
|
+
export declare function toMap<
|
|
2155
|
+
Item,
|
|
2156
|
+
Key extends keyof Item,
|
|
2157
|
+
Value extends keyof Item,
|
|
2158
|
+
>(
|
|
2159
|
+
array: Item[],
|
|
2160
|
+
key: Key,
|
|
2161
|
+
value: Value,
|
|
1792
2162
|
arrays: true,
|
|
1793
|
-
): Map<Key, Value
|
|
2163
|
+
): Map<KeyedValue<Item, Key>, Array<KeyedValue<Item, Value>>>;
|
|
1794
2164
|
/**
|
|
1795
|
-
*
|
|
2165
|
+
* Create a map from an array of items using a specific key and value
|
|
1796
2166
|
*/
|
|
1797
|
-
export declare function
|
|
2167
|
+
export declare function toMap<
|
|
2168
|
+
Item,
|
|
2169
|
+
Key extends keyof Item,
|
|
2170
|
+
Value extends ValueCallback<Item>,
|
|
2171
|
+
>(
|
|
2172
|
+
array: Item[],
|
|
2173
|
+
key: Key,
|
|
2174
|
+
value: Value,
|
|
2175
|
+
): Map<KeyedValue<Item, Key>, ReturnType<Value>>;
|
|
1798
2176
|
/**
|
|
1799
|
-
*
|
|
2177
|
+
* Create a map from an array of items using a specific key and value, and grouping them into arrays
|
|
1800
2178
|
*/
|
|
1801
|
-
export declare function
|
|
1802
|
-
|
|
2179
|
+
export declare function toMap<
|
|
2180
|
+
Item,
|
|
2181
|
+
Key extends keyof Item,
|
|
2182
|
+
Value extends ValueCallback<Item>,
|
|
2183
|
+
>(
|
|
2184
|
+
array: Item[],
|
|
2185
|
+
key: Key,
|
|
2186
|
+
value: Value,
|
|
1803
2187
|
arrays: true,
|
|
1804
|
-
):
|
|
2188
|
+
): Map<KeyedValue<Item, Key>, Array<ReturnType<Value>>>;
|
|
1805
2189
|
/**
|
|
1806
|
-
*
|
|
1807
|
-
* - Uses `key` to find an identifcation value to use as keys
|
|
2190
|
+
* Create a map from an array of items using a specific key and value
|
|
1808
2191
|
*/
|
|
1809
|
-
export declare function
|
|
1810
|
-
|
|
2192
|
+
export declare function toMap<
|
|
2193
|
+
Item,
|
|
2194
|
+
Key extends KeyCallback<Item>,
|
|
2195
|
+
Value extends keyof Item,
|
|
2196
|
+
>(
|
|
2197
|
+
array: Item[],
|
|
1811
2198
|
key: Key,
|
|
1812
|
-
|
|
2199
|
+
value: Value,
|
|
2200
|
+
): Map<ReturnType<Key>, KeyedValue<Item, Value>>;
|
|
1813
2201
|
/**
|
|
1814
|
-
*
|
|
1815
|
-
* - Uses `key` to find an identifcation value to use as keys
|
|
1816
|
-
* - Groups values into arrays
|
|
2202
|
+
* Create a map from an array of items using a specific key and value, and grouping them into arrays
|
|
1817
2203
|
*/
|
|
1818
|
-
export declare function
|
|
1819
|
-
|
|
2204
|
+
export declare function toMap<
|
|
2205
|
+
Item,
|
|
2206
|
+
Key extends KeyCallback<Item>,
|
|
2207
|
+
Value extends keyof Item,
|
|
2208
|
+
>(
|
|
2209
|
+
array: Item[],
|
|
2210
|
+
key: Key,
|
|
2211
|
+
value: Value,
|
|
2212
|
+
arrays: true,
|
|
2213
|
+
): Map<ReturnType<Key>, Array<KeyedValue<Item, Value>>>;
|
|
2214
|
+
/**
|
|
2215
|
+
* Create a map from an array of items using a specific key and value
|
|
2216
|
+
*/
|
|
2217
|
+
export declare function toMap<
|
|
2218
|
+
Item,
|
|
2219
|
+
Key extends KeyCallback<Item>,
|
|
2220
|
+
Value extends ValueCallback<Item>,
|
|
2221
|
+
>(
|
|
2222
|
+
array: Item[],
|
|
2223
|
+
key: Key,
|
|
2224
|
+
value: Value,
|
|
2225
|
+
): Map<ReturnType<Key>, ReturnType<Value>>;
|
|
2226
|
+
/**
|
|
2227
|
+
* Create a map from an array of items using a specific key and value, and grouping them into arrays
|
|
2228
|
+
*/
|
|
2229
|
+
export declare function toMap<
|
|
2230
|
+
Item,
|
|
2231
|
+
Key extends KeyCallback<Item>,
|
|
2232
|
+
Value extends ValueCallback<Item>,
|
|
2233
|
+
>(
|
|
2234
|
+
array: Item[],
|
|
1820
2235
|
key: Key,
|
|
2236
|
+
value: Value,
|
|
1821
2237
|
arrays: true,
|
|
1822
|
-
):
|
|
2238
|
+
): Map<ReturnType<Key>, Array<ReturnType<Value>>>;
|
|
1823
2239
|
/**
|
|
1824
|
-
*
|
|
1825
|
-
* - Uses `key` to find an identifcation value to use as keys
|
|
2240
|
+
* Create a record from an array of items _(using their indices as keys)_
|
|
1826
2241
|
*/
|
|
1827
|
-
export declare function toRecord<
|
|
1828
|
-
array: Value[],
|
|
1829
|
-
key: KeyCallback<Value>,
|
|
1830
|
-
): Record<Key, Value>;
|
|
2242
|
+
export declare function toRecord<Item>(array: Item[]): Record<number, Item>;
|
|
1831
2243
|
/**
|
|
1832
|
-
*
|
|
1833
|
-
* - Uses `key` to find an identifcation value to use as keys
|
|
1834
|
-
* - Groups values into arrays
|
|
2244
|
+
* Create a record from an array of items using a specific key
|
|
1835
2245
|
*/
|
|
1836
|
-
export declare function toRecord<
|
|
1837
|
-
array:
|
|
1838
|
-
key:
|
|
2246
|
+
export declare function toRecord<Item, Key extends keyof Item>(
|
|
2247
|
+
array: Item[],
|
|
2248
|
+
key: Key,
|
|
2249
|
+
): Record<KeyedValue<Item, Key>, Item>;
|
|
2250
|
+
/**
|
|
2251
|
+
* Create a record from an array of items using a specific key, and grouping them into arrays
|
|
2252
|
+
*/
|
|
2253
|
+
export declare function toRecord<Item, Key extends keyof Item>(
|
|
2254
|
+
array: Item[],
|
|
2255
|
+
key: Key,
|
|
2256
|
+
arrays: true,
|
|
2257
|
+
): Record<KeyedValue<Item, Key>, Item[]>;
|
|
2258
|
+
/**
|
|
2259
|
+
* Create a record from an array of items using a specific key
|
|
2260
|
+
*/
|
|
2261
|
+
export declare function toRecord<Item, Key extends KeyCallback<Item>>(
|
|
2262
|
+
array: Item[],
|
|
2263
|
+
key: Key,
|
|
2264
|
+
): Record<ReturnType<Key>, Item>;
|
|
2265
|
+
/**
|
|
2266
|
+
* Create a record from an array of items using a specific key, and grouping them into arrays
|
|
2267
|
+
*/
|
|
2268
|
+
export declare function toRecord<Item, Key extends KeyCallback<Item>>(
|
|
2269
|
+
array: Item[],
|
|
2270
|
+
key: Key,
|
|
2271
|
+
arrays: true,
|
|
2272
|
+
): Record<ReturnType<Key>, Item[]>;
|
|
2273
|
+
/**
|
|
2274
|
+
* Create a record from an array of items using a specific key and value
|
|
2275
|
+
*/
|
|
2276
|
+
export declare function toRecord<
|
|
2277
|
+
Item,
|
|
2278
|
+
Key extends keyof Item,
|
|
2279
|
+
Value extends keyof Item,
|
|
2280
|
+
>(
|
|
2281
|
+
array: Item[],
|
|
2282
|
+
key: Key,
|
|
2283
|
+
value: Value,
|
|
2284
|
+
): Record<KeyedValue<Item, Key>, KeyedValue<Item, Value>>;
|
|
2285
|
+
/**
|
|
2286
|
+
* Create a record from an array of items using a specific key and value, and grouping them into arrays
|
|
2287
|
+
*/
|
|
2288
|
+
export declare function toRecord<
|
|
2289
|
+
Item,
|
|
2290
|
+
Key extends keyof Item,
|
|
2291
|
+
Value extends keyof Item,
|
|
2292
|
+
>(
|
|
2293
|
+
array: Item[],
|
|
2294
|
+
key: Key,
|
|
2295
|
+
value: Value,
|
|
2296
|
+
arrays: true,
|
|
2297
|
+
): Record<KeyedValue<Item, Key>, Array<KeyedValue<Item, Value>>>;
|
|
2298
|
+
/**
|
|
2299
|
+
* Create a record from an array of items using a specific key and value
|
|
2300
|
+
*/
|
|
2301
|
+
export declare function toRecord<
|
|
2302
|
+
Item,
|
|
2303
|
+
Key extends keyof Item,
|
|
2304
|
+
Value extends ValueCallback<Item>,
|
|
2305
|
+
>(
|
|
2306
|
+
array: Item[],
|
|
2307
|
+
key: Key,
|
|
2308
|
+
value: Value,
|
|
2309
|
+
): Record<KeyedValue<Item, Key>, ReturnType<Value>>;
|
|
2310
|
+
/**
|
|
2311
|
+
* Create a record from an array of items using a specific key and value, and grouping them into arrays
|
|
2312
|
+
*/
|
|
2313
|
+
export declare function toRecord<
|
|
2314
|
+
Item,
|
|
2315
|
+
Key extends keyof Item,
|
|
2316
|
+
Value extends ValueCallback<Item>,
|
|
2317
|
+
>(
|
|
2318
|
+
array: Item[],
|
|
2319
|
+
key: Key,
|
|
2320
|
+
value: Value,
|
|
2321
|
+
arrays: true,
|
|
2322
|
+
): Record<KeyedValue<Item, Key>, Array<ReturnType<Value>>>;
|
|
2323
|
+
/**
|
|
2324
|
+
* Create a record from an array of items using a specific key and value
|
|
2325
|
+
*/
|
|
2326
|
+
export declare function toRecord<
|
|
2327
|
+
Item,
|
|
2328
|
+
Key extends KeyCallback<Item>,
|
|
2329
|
+
Value extends keyof Item,
|
|
2330
|
+
>(
|
|
2331
|
+
array: Item[],
|
|
2332
|
+
key: Key,
|
|
2333
|
+
value: Value,
|
|
2334
|
+
): Record<ReturnType<Key>, KeyedValue<Item, Value>>;
|
|
2335
|
+
/**
|
|
2336
|
+
* Create a record from an array of items using a specific key and value, and grouping them into arrays
|
|
2337
|
+
*/
|
|
2338
|
+
export declare function toRecord<
|
|
2339
|
+
Item,
|
|
2340
|
+
Key extends KeyCallback<Item>,
|
|
2341
|
+
Value extends keyof Item,
|
|
2342
|
+
>(
|
|
2343
|
+
array: Item[],
|
|
2344
|
+
key: Key,
|
|
2345
|
+
value: Value,
|
|
2346
|
+
arrays: true,
|
|
2347
|
+
): Record<ReturnType<Key>, Array<KeyedValue<Item, Value>>>;
|
|
2348
|
+
/**
|
|
2349
|
+
* Create a record from an array of items using a specific key and value
|
|
2350
|
+
*/
|
|
2351
|
+
export declare function toRecord<
|
|
2352
|
+
Item,
|
|
2353
|
+
Key extends KeyCallback<Item>,
|
|
2354
|
+
Value extends ValueCallback<Item>,
|
|
2355
|
+
>(
|
|
2356
|
+
array: Item[],
|
|
2357
|
+
key: Key,
|
|
2358
|
+
value: Value,
|
|
2359
|
+
): Record<ReturnType<Key>, ReturnType<Value>>;
|
|
2360
|
+
/**
|
|
2361
|
+
* Create a record from an array of items using a specific key and value, and grouping them into arrays
|
|
2362
|
+
*/
|
|
2363
|
+
export declare function toRecord<
|
|
2364
|
+
Item,
|
|
2365
|
+
Key extends KeyCallback<Item>,
|
|
2366
|
+
Value extends ValueCallback<Item>,
|
|
2367
|
+
>(
|
|
2368
|
+
array: Item[],
|
|
2369
|
+
key: Key,
|
|
2370
|
+
value: Value,
|
|
1839
2371
|
arrays: true,
|
|
1840
|
-
): Record<Key
|
|
2372
|
+
): Record<ReturnType<Key>, Array<ReturnType<Value>>>;
|
|
1841
2373
|
/**
|
|
1842
|
-
*
|
|
2374
|
+
* Get an array of unique items
|
|
1843
2375
|
*/
|
|
1844
|
-
export declare function unique<
|
|
2376
|
+
export declare function unique<Item>(array: Item[]): Item[];
|
|
1845
2377
|
/**
|
|
1846
|
-
* -
|
|
2378
|
+
* - Get an array of unique items
|
|
1847
2379
|
* - Use `key` to find a comparison value to match with `value`
|
|
1848
2380
|
*/
|
|
1849
|
-
export declare function unique<
|
|
1850
|
-
array:
|
|
1851
|
-
key: Key
|
|
1852
|
-
):
|
|
2381
|
+
export declare function unique<Item, Key extends keyof Item>(
|
|
2382
|
+
array: Item[],
|
|
2383
|
+
key: Key,
|
|
2384
|
+
): Item[];
|
|
1853
2385
|
/**
|
|
1854
|
-
*
|
|
2386
|
+
* - Get an array of unique items
|
|
2387
|
+
* - Use `key` to find a comparison value to match with `value`
|
|
1855
2388
|
*/
|
|
1856
|
-
export declare function
|
|
1857
|
-
array:
|
|
1858
|
-
|
|
2389
|
+
export declare function unique<Item, Key extends KeyCallback<Item>>(
|
|
2390
|
+
array: Item[],
|
|
2391
|
+
key: Key,
|
|
2392
|
+
): Item[];
|
|
1859
2393
|
/**
|
|
1860
|
-
*
|
|
1861
|
-
|
|
2394
|
+
* Flatten an array _(using native `flat` and maximum depth)_
|
|
2395
|
+
*/
|
|
2396
|
+
export declare function flatten<Item>(array: Item[]): NestedArrayType<Item>[];
|
|
2397
|
+
/**
|
|
2398
|
+
* - Push values to the end of an array
|
|
2399
|
+
* - Returns the new length
|
|
2400
|
+
* - _(Uses chunking to avoid stack overflow)_
|
|
1862
2401
|
*/
|
|
1863
|
-
export declare function push<
|
|
2402
|
+
export declare function push<Item>(array: Item[], pushed: Item[]): number;
|
|
1864
2403
|
export type HSLColourValue = {
|
|
1865
2404
|
hue: number;
|
|
1866
2405
|
lightness: number;
|
|
@@ -1868,35 +2407,41 @@ export type HSLColourValue = {
|
|
|
1868
2407
|
};
|
|
1869
2408
|
export declare class HSLColour extends Colour<HSLColourValue> {
|
|
1870
2409
|
/**
|
|
1871
|
-
*
|
|
2410
|
+
* Get the current hue
|
|
1872
2411
|
*/
|
|
1873
2412
|
get hue(): number;
|
|
1874
2413
|
/**
|
|
1875
|
-
*
|
|
2414
|
+
* Set the current hue
|
|
1876
2415
|
*/
|
|
1877
2416
|
set hue(value: number);
|
|
1878
2417
|
/**
|
|
1879
|
-
*
|
|
2418
|
+
* Get the current lightness
|
|
1880
2419
|
*/
|
|
1881
2420
|
get lightness(): number;
|
|
1882
2421
|
/**
|
|
1883
|
-
*
|
|
2422
|
+
* Set the current lightness
|
|
1884
2423
|
*/
|
|
1885
2424
|
set lightness(value: number);
|
|
1886
2425
|
/**
|
|
1887
|
-
*
|
|
2426
|
+
* Get the current saturation
|
|
1888
2427
|
*/
|
|
1889
2428
|
get saturation(): number;
|
|
1890
2429
|
/**
|
|
1891
|
-
*
|
|
2430
|
+
* Set the current saturation
|
|
1892
2431
|
*/
|
|
1893
2432
|
set saturation(value: number);
|
|
1894
2433
|
constructor(value: HSLColourValue);
|
|
2434
|
+
/**
|
|
2435
|
+
* @inheritdoc
|
|
2436
|
+
*/
|
|
1895
2437
|
toHex(): HexColour;
|
|
1896
2438
|
/**
|
|
1897
|
-
*
|
|
2439
|
+
* Convert the colour to an RGB-colour
|
|
1898
2440
|
*/
|
|
1899
2441
|
toRgb(): RGBColour;
|
|
2442
|
+
/**
|
|
2443
|
+
* @inheritdoc
|
|
2444
|
+
*/
|
|
1900
2445
|
toString(): string;
|
|
1901
2446
|
/**
|
|
1902
2447
|
* Convert an HSL-colour to an RGB-colour
|
|
@@ -1911,11 +2456,11 @@ export declare class HexColour {
|
|
|
1911
2456
|
private readonly $colour;
|
|
1912
2457
|
private readonly state;
|
|
1913
2458
|
/**
|
|
1914
|
-
*
|
|
2459
|
+
* Get the value of the colour
|
|
1915
2460
|
*/
|
|
1916
2461
|
get value(): string;
|
|
1917
2462
|
/**
|
|
1918
|
-
*
|
|
2463
|
+
* Set the value of the colour
|
|
1919
2464
|
*/
|
|
1920
2465
|
set value(value: string);
|
|
1921
2466
|
constructor(value: string);
|
|
@@ -1944,7 +2489,7 @@ declare abstract class Colour<Model> {
|
|
|
1944
2489
|
private readonly $colour;
|
|
1945
2490
|
protected readonly state: ColourState<Model>;
|
|
1946
2491
|
/**
|
|
1947
|
-
*
|
|
2492
|
+
* Get the current value of the colour
|
|
1948
2493
|
*/
|
|
1949
2494
|
get value(): Model;
|
|
1950
2495
|
constructor(
|
|
@@ -1972,390 +2517,232 @@ export type RGBColourValue = {
|
|
|
1972
2517
|
};
|
|
1973
2518
|
export declare class RGBColour extends Colour<RGBColourValue> {
|
|
1974
2519
|
/**
|
|
1975
|
-
*
|
|
2520
|
+
* Get the current blue value
|
|
1976
2521
|
*/
|
|
1977
2522
|
get blue(): number;
|
|
1978
2523
|
/**
|
|
1979
|
-
*
|
|
2524
|
+
* Set the current blue value
|
|
1980
2525
|
*/
|
|
1981
2526
|
set blue(value: number);
|
|
1982
2527
|
/**
|
|
1983
|
-
*
|
|
2528
|
+
* Get the current green value
|
|
1984
2529
|
*/
|
|
1985
2530
|
get green(): number;
|
|
1986
2531
|
/**
|
|
1987
|
-
*
|
|
2532
|
+
* Set the current green value
|
|
1988
2533
|
*/
|
|
1989
2534
|
set green(value: number);
|
|
1990
2535
|
/**
|
|
1991
|
-
*
|
|
2536
|
+
* Get the current red value
|
|
1992
2537
|
*/
|
|
1993
2538
|
get red(): number;
|
|
1994
2539
|
/**
|
|
1995
|
-
*
|
|
2540
|
+
* Set the current red value
|
|
1996
2541
|
*/
|
|
1997
2542
|
set red(value: number);
|
|
1998
2543
|
constructor(value: RGBColourValue);
|
|
1999
|
-
toHex(): HexColour;
|
|
2000
|
-
/**
|
|
2001
|
-
* Convert the colour to an HSL-colour
|
|
2002
|
-
*/
|
|
2003
|
-
toHsl(): HSLColour;
|
|
2004
|
-
toString(): string;
|
|
2005
|
-
/**
|
|
2006
|
-
* Convert an RGB-colour to a hex-colour
|
|
2007
|
-
*/
|
|
2008
|
-
static toHex(value: RGBColourValue): HexColour;
|
|
2009
|
-
/**
|
|
2010
|
-
* - Convert an RGB-colour to an HSL-colour
|
|
2011
|
-
*/
|
|
2012
|
-
static toHsl(rgb: RGBColourValue): HSLColour;
|
|
2013
|
-
}
|
|
2014
|
-
/**
|
|
2015
|
-
* Get an RGB-colour from a value-object
|
|
2016
|
-
*/
|
|
2017
|
-
export declare function getRGBColour(value: RGBColourValue): RGBColour;
|
|
2018
|
-
/**
|
|
2019
|
-
* Is the value a colour?
|
|
2020
|
-
*/
|
|
2021
|
-
export declare function isColour(
|
|
2022
|
-
value: unknown,
|
|
2023
|
-
): value is HexColour | HSLColour | RGBColour;
|
|
2024
|
-
/**
|
|
2025
|
-
* Is the value a hex-colour?
|
|
2026
|
-
*/
|
|
2027
|
-
export declare function isHexColour(value: unknown): value is HexColour;
|
|
2028
|
-
/**
|
|
2029
|
-
* Is the value an HSL-colour?
|
|
2030
|
-
*/
|
|
2031
|
-
export declare function isHSLColour(value: unknown): value is HSLColour;
|
|
2032
|
-
/**
|
|
2033
|
-
* Is the value an RGB-colour?
|
|
2034
|
-
*/
|
|
2035
|
-
export declare function isRGBColour(value: unknown): value is RGBColour;
|
|
2036
|
-
/**
|
|
2037
|
-
* Get a foreground colour _(usually text)_ based on a background colour's luminance
|
|
2038
|
-
*/
|
|
2039
|
-
export declare function getForegroundColour(value: RGBColourValue): string;
|
|
2040
|
-
/**
|
|
2041
|
-
* Is the value an array or a record?
|
|
2042
|
-
*/
|
|
2043
|
-
export declare function isArrayOrPlainObject(
|
|
2044
|
-
value: unknown,
|
|
2045
|
-
): value is ArrayOrPlainObject;
|
|
2046
|
-
/**
|
|
2047
|
-
* Is the array or object completely empty or only containing `null` or `undefined` values?
|
|
2048
|
-
*/
|
|
2049
|
-
export declare function isEmpty(value: ArrayOrPlainObject): boolean;
|
|
2050
|
-
/**
|
|
2051
|
-
* Is the value a key?
|
|
2052
|
-
*/
|
|
2053
|
-
export declare function isKey(value: unknown): value is Key;
|
|
2054
|
-
/**
|
|
2055
|
-
* Is the value undefined or null?
|
|
2056
|
-
*/
|
|
2057
|
-
export declare function isNullable(value: unknown): value is undefined | null;
|
|
2058
|
-
/**
|
|
2059
|
-
* Is the value undefined, null, or an empty string?
|
|
2060
|
-
*/
|
|
2061
|
-
export declare function isNullableOrEmpty(
|
|
2062
|
-
value: unknown,
|
|
2063
|
-
): value is undefined | null | '';
|
|
2064
|
-
/**
|
|
2065
|
-
* Is the value undefined, null, or a whitespace-only string?
|
|
2066
|
-
*/
|
|
2067
|
-
export declare function isNullableOrWhitespace(
|
|
2068
|
-
value: unknown,
|
|
2069
|
-
): value is undefined | null | '';
|
|
2070
|
-
/**
|
|
2071
|
-
* Is the value a number?
|
|
2072
|
-
*/
|
|
2073
|
-
export declare function isNumber(value: unknown): value is number;
|
|
2074
|
-
/**
|
|
2075
|
-
* Is the value a number, or a number-like string?
|
|
2076
|
-
*/
|
|
2077
|
-
export declare function isNumerical(
|
|
2078
|
-
value: unknown,
|
|
2079
|
-
): value is number | `${number}`;
|
|
2080
|
-
/**
|
|
2081
|
-
* Is the value an object?
|
|
2082
|
-
*/
|
|
2083
|
-
export declare function isObject(value: unknown): value is object;
|
|
2084
|
-
/**
|
|
2085
|
-
* Is the value a plain object?
|
|
2086
|
-
*/
|
|
2087
|
-
export declare function isPlainObject(value: unknown): value is PlainObject;
|
|
2088
|
-
/**
|
|
2089
|
-
* Is the value a primitive value?
|
|
2090
|
-
*/
|
|
2091
|
-
export declare function isPrimitive(value: unknown): value is Primitive;
|
|
2092
|
-
declare class Logger {
|
|
2093
|
-
/**
|
|
2094
|
-
* Logs any number of values at the "debug" log level
|
|
2095
|
-
*/
|
|
2096
|
-
get debug(): {
|
|
2097
|
-
(...data: any[]): void;
|
|
2098
|
-
(message?: any, ...optionalParams: any[]): void;
|
|
2099
|
-
};
|
|
2100
|
-
/**
|
|
2101
|
-
* Logs the value and shows all its properties
|
|
2102
|
-
*/
|
|
2103
|
-
get dir(): {
|
|
2104
|
-
(item?: any, options?: any): void;
|
|
2105
|
-
(obj: any, options?: import('util').InspectOptions): void;
|
|
2106
|
-
};
|
|
2107
|
-
/**
|
|
2108
|
-
* Is logging to the console enabled? _(defaults to `true`)_
|
|
2109
|
-
*/
|
|
2110
|
-
get enabled(): boolean;
|
|
2111
|
-
/**
|
|
2112
|
-
* Enable or disable logging to the console
|
|
2113
|
-
*/
|
|
2114
|
-
set enabled(value: boolean);
|
|
2115
|
-
/**
|
|
2116
|
-
* Logs any number of values at the "error" log level
|
|
2117
|
-
*/
|
|
2118
|
-
get error(): {
|
|
2119
|
-
(...data: any[]): void;
|
|
2120
|
-
(message?: any, ...optionalParams: any[]): void;
|
|
2121
|
-
};
|
|
2122
|
-
/**
|
|
2123
|
-
* Logs any number of values at the "info" log level
|
|
2124
|
-
*/
|
|
2125
|
-
get info(): {
|
|
2126
|
-
(...data: any[]): void;
|
|
2127
|
-
(message?: any, ...optionalParams: any[]): void;
|
|
2128
|
-
};
|
|
2129
|
-
/**
|
|
2130
|
-
* Logs any number of values at the "log" log level
|
|
2131
|
-
*/
|
|
2132
|
-
get log(): {
|
|
2133
|
-
(...data: any[]): void;
|
|
2134
|
-
(message?: any, ...optionalParams: any[]): void;
|
|
2135
|
-
};
|
|
2136
|
-
/**
|
|
2137
|
-
* Logs data as a table, with optional properties to use as columns
|
|
2138
|
-
*/
|
|
2139
|
-
get table(): {
|
|
2140
|
-
(tabularData?: any, properties?: string[]): void;
|
|
2141
|
-
(tabularData: any, properties?: readonly string[]): void;
|
|
2142
|
-
};
|
|
2143
|
-
/**
|
|
2144
|
-
* Logs any number of values together with a trace from where it was called
|
|
2145
|
-
*/
|
|
2146
|
-
get trace(): {
|
|
2147
|
-
(...data: any[]): void;
|
|
2148
|
-
(message?: any, ...optionalParams: any[]): void;
|
|
2149
|
-
};
|
|
2150
2544
|
/**
|
|
2151
|
-
*
|
|
2545
|
+
* @inheritdoc
|
|
2152
2546
|
*/
|
|
2153
|
-
|
|
2154
|
-
(...data: any[]): void;
|
|
2155
|
-
(message?: any, ...optionalParams: any[]): void;
|
|
2156
|
-
};
|
|
2547
|
+
toHex(): HexColour;
|
|
2157
2548
|
/**
|
|
2158
|
-
*
|
|
2159
|
-
* - Returns a `Time`-object for logging the current duration of the timer and stopping the timer _(and logging the total duration)_
|
|
2549
|
+
* Convert the colour to an HSL-colour
|
|
2160
2550
|
*/
|
|
2161
|
-
|
|
2162
|
-
}
|
|
2163
|
-
declare class Time {
|
|
2164
|
-
private readonly state;
|
|
2165
|
-
constructor(label: string);
|
|
2551
|
+
toHsl(): HSLColour;
|
|
2166
2552
|
/**
|
|
2167
|
-
*
|
|
2168
|
-
* - Ignored if logging is disabled
|
|
2553
|
+
* @inheritdoc
|
|
2169
2554
|
*/
|
|
2170
|
-
|
|
2555
|
+
toString(): string;
|
|
2171
2556
|
/**
|
|
2172
|
-
*
|
|
2173
|
-
* - Will always log the total duration, even if logging is disabled
|
|
2557
|
+
* Convert an RGB-colour to a hex-colour
|
|
2174
2558
|
*/
|
|
2175
|
-
|
|
2559
|
+
static toHex(value: RGBColourValue): HexColour;
|
|
2560
|
+
/**
|
|
2561
|
+
* - Convert an RGB-colour to an HSL-colour
|
|
2562
|
+
*/
|
|
2563
|
+
static toHsl(rgb: RGBColourValue): HSLColour;
|
|
2176
2564
|
}
|
|
2177
|
-
export declare const logger: Logger;
|
|
2178
|
-
/**
|
|
2179
|
-
* Get the average value from a list of numbers
|
|
2180
|
-
*/
|
|
2181
|
-
export declare function average(values: number[]): number;
|
|
2182
|
-
/**
|
|
2183
|
-
* Get the maximum value from a list of numbers
|
|
2184
|
-
*/
|
|
2185
|
-
export declare function max(values: number[]): number;
|
|
2186
|
-
/**
|
|
2187
|
-
* Get the minimum value from a list of numbers
|
|
2188
|
-
*/
|
|
2189
|
-
export declare function min(values: number[]): number;
|
|
2190
|
-
/**
|
|
2191
|
-
* Rounds a number to a specific number of decimal places _(defaults to 0)_
|
|
2192
|
-
*/
|
|
2193
|
-
export declare function round(value: number, decimals?: number): number;
|
|
2194
|
-
/**
|
|
2195
|
-
* Get the sum of a list of numbers
|
|
2196
|
-
*/
|
|
2197
|
-
export declare function sum(values: number[]): number;
|
|
2198
|
-
/**
|
|
2199
|
-
* Is the number between a minimum and maximum value?
|
|
2200
|
-
*/
|
|
2201
|
-
export declare function between(
|
|
2202
|
-
value: number,
|
|
2203
|
-
min: number,
|
|
2204
|
-
max: number,
|
|
2205
|
-
): boolean;
|
|
2206
|
-
/**
|
|
2207
|
-
* - Clamps a number between a minimum and maximum value
|
|
2208
|
-
* - If `loop` is `true`, when the value is less than the minimum, it will be clamped as the maximum, and vice versa
|
|
2209
|
-
*/
|
|
2210
|
-
export declare function clamp(
|
|
2211
|
-
value: number,
|
|
2212
|
-
min: number,
|
|
2213
|
-
max: number,
|
|
2214
|
-
loop?: boolean,
|
|
2215
|
-
): number;
|
|
2216
|
-
/**
|
|
2217
|
-
* - Gets the number value from an unknown value
|
|
2218
|
-
* - Returns `NaN` if the value is `undefined`, `null`, or cannot be parsed
|
|
2219
|
-
* - Based on Lodash :-)
|
|
2220
|
-
*/
|
|
2221
|
-
export declare function getNumber(value: unknown): number;
|
|
2222
|
-
/**
|
|
2223
|
-
* Converts a query string to a plain _(nested)_ object
|
|
2224
|
-
*/
|
|
2225
|
-
export declare function fromQuery(query: string): PlainObject;
|
|
2226
|
-
/**
|
|
2227
|
-
* Converts a plain _(nested)_ object to a query string
|
|
2228
|
-
*/
|
|
2229
|
-
export declare function toQuery(parameters: PlainObject): string;
|
|
2230
|
-
/**
|
|
2231
|
-
* Queues a callback to be executed at the next best time
|
|
2232
|
-
*/
|
|
2233
|
-
export declare function queue(callback: () => void): void;
|
|
2234
|
-
/**
|
|
2235
|
-
* Returns a random boolean
|
|
2236
|
-
*/
|
|
2237
|
-
export declare function getRandomBoolean(): boolean;
|
|
2238
|
-
/**
|
|
2239
|
-
* Returns a random string of characters with a specified length
|
|
2240
|
-
* - `selection` defaults to all lowercase letters in the English alphabet
|
|
2241
|
-
*/
|
|
2242
|
-
export declare function getRandomCharacters(
|
|
2243
|
-
length: number,
|
|
2244
|
-
selection?: string,
|
|
2245
|
-
): string;
|
|
2246
|
-
/**
|
|
2247
|
-
* Returns a random hexadecimal colour
|
|
2248
|
-
*/
|
|
2249
|
-
export declare function getRandomColour(): string;
|
|
2250
|
-
/**
|
|
2251
|
-
* Returns a random date
|
|
2252
|
-
*/
|
|
2253
|
-
export declare function getRandomDate(earliest?: Date, latest?: Date): Date;
|
|
2254
2565
|
/**
|
|
2255
|
-
*
|
|
2566
|
+
* Get an RGB-colour from a value-object
|
|
2256
2567
|
*/
|
|
2257
|
-
export declare function
|
|
2568
|
+
export declare function getRGBColour(value: RGBColourValue): RGBColour;
|
|
2258
2569
|
/**
|
|
2259
|
-
*
|
|
2570
|
+
* Is the value a colour?
|
|
2260
2571
|
*/
|
|
2261
|
-
export declare function
|
|
2572
|
+
export declare function isColour(
|
|
2573
|
+
value: unknown,
|
|
2574
|
+
): value is HexColour | HSLColour | RGBColour;
|
|
2262
2575
|
/**
|
|
2263
|
-
*
|
|
2576
|
+
* Is the value a hex-colour?
|
|
2264
2577
|
*/
|
|
2265
|
-
export declare function
|
|
2578
|
+
export declare function isHexColour(value: unknown): value is HexColour;
|
|
2266
2579
|
/**
|
|
2267
|
-
*
|
|
2580
|
+
* Is the value an HSL-colour?
|
|
2268
2581
|
*/
|
|
2269
|
-
export declare function
|
|
2582
|
+
export declare function isHSLColour(value: unknown): value is HSLColour;
|
|
2270
2583
|
/**
|
|
2271
|
-
*
|
|
2272
|
-
* - If `amount` is not specified, a shuffled array will be returned instead
|
|
2584
|
+
* Is the value an RGB-colour?
|
|
2273
2585
|
*/
|
|
2274
|
-
export declare function
|
|
2275
|
-
array: Value[],
|
|
2276
|
-
amount?: number,
|
|
2277
|
-
): Value[];
|
|
2586
|
+
export declare function isRGBColour(value: unknown): value is RGBColour;
|
|
2278
2587
|
/**
|
|
2279
|
-
*
|
|
2280
|
-
* - Maximum size defaults to _2^20_; any provided size will be clamped at _2^24_
|
|
2281
|
-
* - Behaviour is similar to a _LRU_-cache, where the least recently used entries are removed
|
|
2588
|
+
* Get a foreground colour _(usually text)_ based on a background colour's luminance
|
|
2282
2589
|
*/
|
|
2283
|
-
export declare
|
|
2284
|
-
|
|
2285
|
-
|
|
2286
|
-
> {
|
|
2287
|
-
private readonly maximumSize;
|
|
2590
|
+
export declare function getForegroundColour(value: RGBColourValue): string;
|
|
2591
|
+
export declare class Emitter<Value> {
|
|
2592
|
+
private readonly state;
|
|
2288
2593
|
/**
|
|
2289
|
-
* Is the
|
|
2594
|
+
* Is the emitter active?
|
|
2290
2595
|
*/
|
|
2291
|
-
get
|
|
2596
|
+
get active(): boolean;
|
|
2292
2597
|
/**
|
|
2293
|
-
* The
|
|
2598
|
+
* The observable that can be subscribed to
|
|
2294
2599
|
*/
|
|
2295
|
-
get
|
|
2600
|
+
get observable(): Observable<Value>;
|
|
2296
2601
|
/**
|
|
2297
|
-
*
|
|
2602
|
+
* The current value
|
|
2298
2603
|
*/
|
|
2299
|
-
|
|
2604
|
+
get value(): Value;
|
|
2605
|
+
constructor(value: Value);
|
|
2300
2606
|
/**
|
|
2301
|
-
*
|
|
2607
|
+
* Destroy the emitter
|
|
2302
2608
|
*/
|
|
2303
|
-
|
|
2609
|
+
destroy(): void;
|
|
2304
2610
|
/**
|
|
2305
|
-
*
|
|
2611
|
+
* Emit a new value _(and optionally finishes the emitter)_
|
|
2306
2612
|
*/
|
|
2307
|
-
|
|
2613
|
+
emit(value: Value, finish?: boolean): void;
|
|
2308
2614
|
/**
|
|
2309
|
-
*
|
|
2615
|
+
* Emit an error _(and optionally finishes the emitter)_
|
|
2310
2616
|
*/
|
|
2311
|
-
|
|
2617
|
+
error(error: Error, finish?: boolean): void;
|
|
2312
2618
|
/**
|
|
2313
|
-
*
|
|
2619
|
+
* Finish the emitter
|
|
2314
2620
|
*/
|
|
2315
|
-
|
|
2621
|
+
finish(): void;
|
|
2316
2622
|
}
|
|
2317
|
-
|
|
2318
|
-
|
|
2319
|
-
|
|
2320
|
-
|
|
2321
|
-
|
|
2322
|
-
|
|
2323
|
-
private readonly maximumSize;
|
|
2623
|
+
export declare class Observable<Value> {
|
|
2624
|
+
private readonly state;
|
|
2625
|
+
constructor(
|
|
2626
|
+
emitter: Emitter<Value>,
|
|
2627
|
+
observers: Map<Subscription<Value>, Observer<Value>>,
|
|
2628
|
+
);
|
|
2324
2629
|
/**
|
|
2325
|
-
*
|
|
2630
|
+
* Subscribe to value changes
|
|
2326
2631
|
*/
|
|
2327
|
-
|
|
2632
|
+
subscribe(observer: Observer<Value>): Subscription<Value>;
|
|
2328
2633
|
/**
|
|
2329
|
-
*
|
|
2634
|
+
* Subscribe to value changes
|
|
2330
2635
|
*/
|
|
2331
|
-
|
|
2636
|
+
subscribe(
|
|
2637
|
+
onNext: (value: Value) => void,
|
|
2638
|
+
onError?: (error: Error) => void,
|
|
2639
|
+
onComplete?: () => void,
|
|
2640
|
+
): Subscription<Value>;
|
|
2641
|
+
}
|
|
2642
|
+
export type ObservableState<Value> = {
|
|
2643
|
+
emitter: Emitter<Value>;
|
|
2644
|
+
observers: Map<Subscription<Value>, Observer<Value>>;
|
|
2645
|
+
};
|
|
2646
|
+
export type Observer<Value> = {
|
|
2332
2647
|
/**
|
|
2333
|
-
*
|
|
2648
|
+
* Callback for when the observable is complete
|
|
2334
2649
|
*/
|
|
2335
|
-
|
|
2650
|
+
complete?: () => void;
|
|
2336
2651
|
/**
|
|
2337
|
-
*
|
|
2652
|
+
* Callback for when the observable has an error
|
|
2338
2653
|
*/
|
|
2339
|
-
|
|
2654
|
+
error?: (error: Error) => void;
|
|
2340
2655
|
/**
|
|
2341
|
-
*
|
|
2656
|
+
* Callback for when the observable has a new value
|
|
2342
2657
|
*/
|
|
2343
|
-
|
|
2658
|
+
next?: (value: Value) => void;
|
|
2659
|
+
};
|
|
2660
|
+
export declare class Subscription<Value> {
|
|
2661
|
+
private readonly state;
|
|
2662
|
+
constructor(state: ObservableState<Value>);
|
|
2344
2663
|
/**
|
|
2345
|
-
*
|
|
2664
|
+
* Is the subscription closed?
|
|
2346
2665
|
*/
|
|
2347
|
-
|
|
2666
|
+
get closed(): boolean;
|
|
2348
2667
|
/**
|
|
2349
|
-
*
|
|
2350
|
-
* - Negative indices are counted from the end
|
|
2351
|
-
* - Optionally move the value to the end with `update`
|
|
2668
|
+
* Destroy the subscription
|
|
2352
2669
|
*/
|
|
2353
|
-
|
|
2670
|
+
destroy(): void;
|
|
2354
2671
|
/**
|
|
2355
|
-
*
|
|
2672
|
+
* Unsubscribe from its observable
|
|
2356
2673
|
*/
|
|
2357
|
-
|
|
2674
|
+
unsubscribe(): void;
|
|
2675
|
+
}
|
|
2676
|
+
/**
|
|
2677
|
+
* Create a new emitter
|
|
2678
|
+
*/
|
|
2679
|
+
export declare function emitter<Value>(value: Value): Emitter<Value>;
|
|
2680
|
+
export type Debounced<Callback extends GenericCallback> = Callback & {
|
|
2681
|
+
/**
|
|
2682
|
+
* Cancel the debounce
|
|
2683
|
+
*/
|
|
2684
|
+
cancel: () => void;
|
|
2685
|
+
};
|
|
2686
|
+
declare class Memoised<Callback extends GenericCallback> {
|
|
2687
|
+
readonly state: MemoisedState<Callback>;
|
|
2688
|
+
constructor(callback: Callback);
|
|
2689
|
+
/**
|
|
2690
|
+
* Clear the cache
|
|
2691
|
+
*/
|
|
2692
|
+
clear(): void;
|
|
2693
|
+
/**
|
|
2694
|
+
* Delete a result from the cache
|
|
2695
|
+
*/
|
|
2696
|
+
delete(key: Parameters<Callback>[0]): boolean;
|
|
2697
|
+
/**
|
|
2698
|
+
* Destroy the instance, clearing its cache and removing its callback
|
|
2699
|
+
*/
|
|
2700
|
+
destroy(): void;
|
|
2701
|
+
/**
|
|
2702
|
+
* Get a result from the cache if it exists _(or `undefined` otherwise)_
|
|
2703
|
+
*/
|
|
2704
|
+
get(key: Parameters<Callback>[0]): ReturnType<Callback> | undefined;
|
|
2705
|
+
/**
|
|
2706
|
+
* Does the result exist?
|
|
2707
|
+
*/
|
|
2708
|
+
has(key: Parameters<Callback>[0]): boolean;
|
|
2709
|
+
/**
|
|
2710
|
+
* Get the result from the cache if it exists; otherwise runs the callback, caches the result, and returns it
|
|
2711
|
+
*/
|
|
2712
|
+
run(...parameters: Parameters<Callback>): ReturnType<Callback>;
|
|
2358
2713
|
}
|
|
2714
|
+
export type MemoisedState<Callback extends GenericCallback> = {
|
|
2715
|
+
cache: Map<Parameters<Callback>[0], ReturnType<Callback>>;
|
|
2716
|
+
getter: (...parameters: Parameters<Callback>) => ReturnType<Callback>;
|
|
2717
|
+
};
|
|
2718
|
+
/**
|
|
2719
|
+
* - Debounce a function, ensuring it is only called after `time` milliseconds have passed
|
|
2720
|
+
* - On subsequent calls, the timer is reset and will wait another `time` milliseconds _(and so on...)_
|
|
2721
|
+
* - Time is clamped between _0_ and _1000_ milliseconds
|
|
2722
|
+
* - Returns the callback with an added `cancel`-method for manually cancelling the debounce
|
|
2723
|
+
*/
|
|
2724
|
+
export declare function debounce<Callback extends GenericCallback>(
|
|
2725
|
+
callback: Callback,
|
|
2726
|
+
time?: number,
|
|
2727
|
+
): Debounced<Callback>;
|
|
2728
|
+
/**
|
|
2729
|
+
* Memoise a function, caching and retrieving results based on the first parameter
|
|
2730
|
+
*/
|
|
2731
|
+
export declare function memoise<Callback extends GenericCallback>(
|
|
2732
|
+
callback: Callback,
|
|
2733
|
+
): Memoised<Callback>;
|
|
2734
|
+
/**
|
|
2735
|
+
* A function that does nothing, which can be useful, I guess…
|
|
2736
|
+
*/
|
|
2737
|
+
export declare function noop(): void;
|
|
2738
|
+
/**
|
|
2739
|
+
* - Throttle a function, ensuring it is only called once every `time` milliseconds
|
|
2740
|
+
* - Time is clamped between _0_ and _1000_ milliseconds
|
|
2741
|
+
*/
|
|
2742
|
+
export declare function throttle<Callback extends GenericCallback>(
|
|
2743
|
+
callback: Callback,
|
|
2744
|
+
time?: number,
|
|
2745
|
+
): Callback;
|
|
2359
2746
|
/**
|
|
2360
2747
|
* Convert a string to camel case _(thisIsCamelCase)_
|
|
2361
2748
|
*/
|
|
@@ -2390,6 +2777,9 @@ export type Options = {
|
|
|
2390
2777
|
*/
|
|
2391
2778
|
pattern?: RegExp;
|
|
2392
2779
|
};
|
|
2780
|
+
/**
|
|
2781
|
+
* Render a string from a template with variables
|
|
2782
|
+
*/
|
|
2393
2783
|
export declare function template(
|
|
2394
2784
|
value: string,
|
|
2395
2785
|
variables: PlainObject,
|
|
@@ -2404,18 +2794,18 @@ export declare function createUuid(): string;
|
|
|
2404
2794
|
*/
|
|
2405
2795
|
export declare function getString(value: unknown): string;
|
|
2406
2796
|
/**
|
|
2407
|
-
*
|
|
2797
|
+
* Join an array into a string while ignoring empty values _(with an optional delimiter)_
|
|
2408
2798
|
*/
|
|
2409
2799
|
export declare function join(value: unknown[], delimiter?: string): string;
|
|
2410
2800
|
/**
|
|
2411
|
-
*
|
|
2801
|
+
* Parse a JSON string into its proper value _(or `undefined` if it fails)_
|
|
2412
2802
|
*/
|
|
2413
2803
|
export declare function parse(
|
|
2414
2804
|
value: string,
|
|
2415
2805
|
reviver?: (this: unknown, key: string, value: unknown) => unknown,
|
|
2416
2806
|
): unknown;
|
|
2417
2807
|
/**
|
|
2418
|
-
*
|
|
2808
|
+
* Truncate a string to a specified length, when possible
|
|
2419
2809
|
* - Returned as-is if the string is already short enough
|
|
2420
2810
|
* - A suffix may be appended to the truncated string, e.g., an ellipsis
|
|
2421
2811
|
*/
|
|
@@ -2428,8 +2818,10 @@ export declare function truncate(
|
|
|
2428
2818
|
* Split a string into words _(and other readable parts)_
|
|
2429
2819
|
*/
|
|
2430
2820
|
export declare function words(value: string): string[];
|
|
2431
|
-
|
|
2432
|
-
|
|
2821
|
+
/**
|
|
2822
|
+
* Clone any kind of value _(deeply, if needed)_
|
|
2823
|
+
*/
|
|
2824
|
+
export declare function clone(value: unknown): {} | null | undefined;
|
|
2433
2825
|
/**
|
|
2434
2826
|
* Compare two values _(for sorting purposes)_
|
|
2435
2827
|
*/
|
|
@@ -2498,7 +2890,7 @@ export type MergeOptions = {
|
|
|
2498
2890
|
skipNullable?: boolean;
|
|
2499
2891
|
};
|
|
2500
2892
|
/**
|
|
2501
|
-
*
|
|
2893
|
+
* Merge multiple arrays or objects into a single one
|
|
2502
2894
|
*/
|
|
2503
2895
|
export declare function merge<Model extends ArrayOrPlainObject>(
|
|
2504
2896
|
values: Model[],
|
|
@@ -2531,7 +2923,7 @@ export type Smushed<Value> = Simplify<{
|
|
|
2531
2923
|
[Key in Paths<Value>]: Get<Value, ToString<Key>>;
|
|
2532
2924
|
}>;
|
|
2533
2925
|
/**
|
|
2534
|
-
*
|
|
2926
|
+
* Smush an object into a flat object that uses dot notation keys
|
|
2535
2927
|
*/
|
|
2536
2928
|
export declare function smush<Value extends PlainObject>(
|
|
2537
2929
|
value: Value,
|
|
@@ -2545,13 +2937,13 @@ export type Unsmushed<Value extends PlainObject> = Simplify<
|
|
|
2545
2937
|
>
|
|
2546
2938
|
>;
|
|
2547
2939
|
/**
|
|
2548
|
-
*
|
|
2940
|
+
* Unsmush a smushed object _(turning dot notation keys into nested keys)_
|
|
2549
2941
|
*/
|
|
2550
2942
|
export declare function unsmush<Value extends PlainObject>(
|
|
2551
2943
|
value: Value,
|
|
2552
2944
|
): Unsmushed<Value>;
|
|
2553
2945
|
/**
|
|
2554
|
-
*
|
|
2946
|
+
* Create a new object with only the specified keys
|
|
2555
2947
|
*/
|
|
2556
2948
|
export declare function partial<
|
|
2557
2949
|
Value extends PlainObject,
|