@oscarpalmer/atoms 0.218.0 → 0.219.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/array/filter.d.mts +38 -4
- package/dist/array/find.d.mts +34 -0
- package/dist/array/first.d.mts +40 -4
- package/dist/array/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 +716 -170
- package/dist/index.mjs +293 -68
- 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/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/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
|
@@ -7,6 +7,14 @@ import { STRING_CASE_CAMEL, STRING_CASE_KEBAB, STRING_CASE_PASCAL, STRING_CASE_S
|
|
|
7
7
|
*
|
|
8
8
|
* @param value String to convert
|
|
9
9
|
* @returns Camel-cased string
|
|
10
|
+
*
|
|
11
|
+
* @example
|
|
12
|
+
* ```typescript
|
|
13
|
+
* camelCase('this is camel case'); // => 'thisIsCamelCase'
|
|
14
|
+
* camelCase('ThisIsCamelCase'); // => 'thisIsCamelCase'
|
|
15
|
+
* camelCase('this-is-camel-case'); // => 'thisIsCamelCase'
|
|
16
|
+
* camelCase('this_is_camel_case'); // => 'thisIsCamelCase'
|
|
17
|
+
* ```
|
|
10
18
|
*/
|
|
11
19
|
function camelCase(value) {
|
|
12
20
|
return toCase(STRING_CASE_CAMEL, value, true, false);
|
|
@@ -16,6 +24,14 @@ function camelCase(value) {
|
|
|
16
24
|
*
|
|
17
25
|
* @param value String to capitalize
|
|
18
26
|
* @returns Capitalized string
|
|
27
|
+
*
|
|
28
|
+
* @example
|
|
29
|
+
* ```typescript
|
|
30
|
+
* capitalize('this is a test'); // => 'This is a test'
|
|
31
|
+
* capitalize('This Is A Test'); // => 'This is a test'
|
|
32
|
+
* capitalize('t'); // => 'T'
|
|
33
|
+
* capitalize(''); // => ''
|
|
34
|
+
* ```
|
|
19
35
|
*/
|
|
20
36
|
function capitalize(value) {
|
|
21
37
|
if (typeof value !== "string" || value.length === 0) return "";
|
|
@@ -27,6 +43,14 @@ function capitalize(value) {
|
|
|
27
43
|
*
|
|
28
44
|
* @param value String to convert
|
|
29
45
|
* @returns Kebab-cased string
|
|
46
|
+
*
|
|
47
|
+
* @example
|
|
48
|
+
* ```typescript
|
|
49
|
+
* kebabCase('this is kebab case'); // => 'this-is-kebab-case'
|
|
50
|
+
* kebabCase('ThisIsKebabCase'); // => 'this-is-kebab-case'
|
|
51
|
+
* kebabCase('this-is-kebab-case'); // => 'this-is-kebab-case'
|
|
52
|
+
* kebabCase('this_is_kebab_case'); // => 'this-is-kebab-case'
|
|
53
|
+
* ```
|
|
30
54
|
*/
|
|
31
55
|
function kebabCase(value) {
|
|
32
56
|
return toCase(STRING_CASE_KEBAB, value, false, false);
|
|
@@ -36,6 +60,13 @@ function kebabCase(value) {
|
|
|
36
60
|
*
|
|
37
61
|
* @param value String to convert
|
|
38
62
|
* @returns Lower-cased string
|
|
63
|
+
*
|
|
64
|
+
* @example
|
|
65
|
+
* ```typescript
|
|
66
|
+
* lowerCase('THIS IS A TEST'); // => 'this is a test'
|
|
67
|
+
* lowerCase('this is a test'); // => 'this is a test'
|
|
68
|
+
* lowerCase('t'); // => 't'
|
|
69
|
+
* ```
|
|
39
70
|
*/
|
|
40
71
|
function lowerCase(value) {
|
|
41
72
|
if (typeof value !== "string") return "";
|
|
@@ -47,6 +78,14 @@ function lowerCase(value) {
|
|
|
47
78
|
*
|
|
48
79
|
* @param value String to convert
|
|
49
80
|
* @returns Pascal-cased string
|
|
81
|
+
*
|
|
82
|
+
* @example
|
|
83
|
+
* ```typescript
|
|
84
|
+
* pascalCase('this is pascal case'); // => 'ThisIsPascalCase'
|
|
85
|
+
* pascalCase('ThisIsPascalCase'); // => 'ThisIsPascalCase'
|
|
86
|
+
* pascalCase('this-is-pascal-case'); // => 'ThisIsPascalCase'
|
|
87
|
+
* pascalCase('this_is_pascal_case'); // => 'ThisIsPascalCase'
|
|
88
|
+
* ```
|
|
50
89
|
*/
|
|
51
90
|
function pascalCase(value) {
|
|
52
91
|
return toCase(STRING_CASE_PASCAL, value, true, true);
|
|
@@ -56,6 +95,14 @@ function pascalCase(value) {
|
|
|
56
95
|
*
|
|
57
96
|
* @param value String to convert
|
|
58
97
|
* @returns Snake-cased string
|
|
98
|
+
*
|
|
99
|
+
* @example
|
|
100
|
+
* ```typescript
|
|
101
|
+
* snakeCase('this is snake case'); // => 'this_is_snake_case'
|
|
102
|
+
* snakeCase('ThisIsSnakeCase'); // => 'this_is_snake_case'
|
|
103
|
+
* snakeCase('this-is-snake-case'); // => 'this_is_snake_case'
|
|
104
|
+
* snakeCase('this_is_snake_case'); // => 'this_is_snake_case'
|
|
105
|
+
* ```
|
|
59
106
|
*/
|
|
60
107
|
function snakeCase(value) {
|
|
61
108
|
return toCase(STRING_CASE_SNAKE, value, false, false);
|
|
@@ -65,6 +112,14 @@ function snakeCase(value) {
|
|
|
65
112
|
*
|
|
66
113
|
* @param value String to convert
|
|
67
114
|
* @returns Title-cased string
|
|
115
|
+
*
|
|
116
|
+
* @example
|
|
117
|
+
* ```typescript
|
|
118
|
+
* titleCase('this is a test'); // => 'This Is A Test'
|
|
119
|
+
* titleCase('This Is A Test'); // => 'This Is A Test'
|
|
120
|
+
* titleCase('t'); // => 'T'
|
|
121
|
+
* titleCase(''); // => ''
|
|
122
|
+
* ```
|
|
68
123
|
*/
|
|
69
124
|
function titleCase(value) {
|
|
70
125
|
if (typeof value !== "string" || value.length === 0) return "";
|
|
@@ -107,6 +162,14 @@ function toCaseCallback(value) {
|
|
|
107
162
|
*
|
|
108
163
|
* @param value String to convert
|
|
109
164
|
* @returns Upper-cased string
|
|
165
|
+
*
|
|
166
|
+
* @example
|
|
167
|
+
* ```typescript
|
|
168
|
+
* upperCase('this is a test'); // => 'THIS IS A TEST'
|
|
169
|
+
* upperCase('This Is A Test'); // => 'THIS IS A TEST'
|
|
170
|
+
* upperCase('t'); // => 'T'
|
|
171
|
+
* upperCase(''); // => ''
|
|
172
|
+
* ```
|
|
110
173
|
*/
|
|
111
174
|
function upperCase(value) {
|
|
112
175
|
if (typeof value !== "string" || value.length === 0) return "";
|
|
@@ -17,7 +17,13 @@
|
|
|
17
17
|
* ```
|
|
18
18
|
*/
|
|
19
19
|
export declare function getString(value: unknown): string;
|
|
20
|
+
/**
|
|
21
|
+
* @internal
|
|
22
|
+
*/
|
|
20
23
|
export declare function ignoreKey(key: string): boolean;
|
|
24
|
+
/**
|
|
25
|
+
* @internal
|
|
26
|
+
*/
|
|
21
27
|
export declare function interpolate(strings: TemplateStringsArray, values: unknown[]): string;
|
|
22
28
|
/**
|
|
23
29
|
* Join an array of values into a string _(while ignoring empty values)_
|
|
@@ -27,9 +33,23 @@ export declare function interpolate(strings: TemplateStringsArray, values: unkno
|
|
|
27
33
|
* @param array Array of values
|
|
28
34
|
* @param delimiter Delimiter to use between values
|
|
29
35
|
* @returns Joined string
|
|
36
|
+
* @example
|
|
37
|
+
* ```typescript
|
|
38
|
+
* join(['a', 'b', 'c']); // => 'abc'
|
|
39
|
+
* join(['a', 'b', 'c'], ', '); // => 'a, b, c'
|
|
40
|
+
* join(['a', '', 'c']); // => 'ac'
|
|
41
|
+
* join([null, 'b', undefined]); // => 'b'
|
|
42
|
+
* join([]); // => ''
|
|
43
|
+
* ```
|
|
30
44
|
*/
|
|
31
45
|
export declare function join(array: unknown[], delimiter?: string): string;
|
|
46
|
+
/**
|
|
47
|
+
* @internal
|
|
48
|
+
*/
|
|
32
49
|
export declare function tryDecode(value: string): string;
|
|
50
|
+
/**
|
|
51
|
+
* @internal
|
|
52
|
+
*/
|
|
33
53
|
export declare function tryEncode(value: boolean | number | string): unknown;
|
|
34
54
|
/**
|
|
35
55
|
* Split a string into words _(and other readable parts)_
|
|
@@ -27,9 +27,15 @@ function getString(value) {
|
|
|
27
27
|
const asString = String(value.valueOf?.() ?? value);
|
|
28
28
|
return asString.startsWith("[object ") ? JSON.stringify(value) : asString;
|
|
29
29
|
}
|
|
30
|
+
/**
|
|
31
|
+
* @internal
|
|
32
|
+
*/
|
|
30
33
|
function ignoreKey(key) {
|
|
31
34
|
return STRING_EXPRESSION_IGNORED.test(key);
|
|
32
35
|
}
|
|
36
|
+
/**
|
|
37
|
+
* @internal
|
|
38
|
+
*/
|
|
33
39
|
function interpolate(strings, values) {
|
|
34
40
|
const { length } = strings;
|
|
35
41
|
let interpolated = "";
|
|
@@ -47,6 +53,14 @@ function interpolate(strings, values) {
|
|
|
47
53
|
* @param array Array of values
|
|
48
54
|
* @param delimiter Delimiter to use between values
|
|
49
55
|
* @returns Joined string
|
|
56
|
+
* @example
|
|
57
|
+
* ```typescript
|
|
58
|
+
* join(['a', 'b', 'c']); // => 'abc'
|
|
59
|
+
* join(['a', 'b', 'c'], ', '); // => 'a, b, c'
|
|
60
|
+
* join(['a', '', 'c']); // => 'ac'
|
|
61
|
+
* join([null, 'b', undefined]); // => 'b'
|
|
62
|
+
* join([]); // => ''
|
|
63
|
+
* ```
|
|
50
64
|
*/
|
|
51
65
|
function join(array, delimiter) {
|
|
52
66
|
if (!Array.isArray(array)) return "";
|
|
@@ -62,9 +76,15 @@ function join(array, delimiter) {
|
|
|
62
76
|
function tryCallback(value, callback) {
|
|
63
77
|
return unwrap(attempt(() => callback(value)), value);
|
|
64
78
|
}
|
|
79
|
+
/**
|
|
80
|
+
* @internal
|
|
81
|
+
*/
|
|
65
82
|
function tryDecode(value) {
|
|
66
83
|
return tryCallback(value, decodeURIComponent);
|
|
67
84
|
}
|
|
85
|
+
/**
|
|
86
|
+
* @internal
|
|
87
|
+
*/
|
|
68
88
|
function tryEncode(value) {
|
|
69
89
|
return tryCallback(value, encodeURIComponent);
|
|
70
90
|
}
|
package/dist/logger.d.mts
CHANGED
|
@@ -1,7 +1,19 @@
|
|
|
1
1
|
import { Lumberjack, TimeLogger } from "./models/logger.model.mjs";
|
|
2
2
|
//#region src/logger.d.ts
|
|
3
3
|
declare function TimeLogger(this: any, label: string): void;
|
|
4
|
+
/**
|
|
5
|
+
* Is the value a _Logger_?
|
|
6
|
+
*
|
|
7
|
+
* @param value Value to check
|
|
8
|
+
* @returns `true` if the value is a _Logger_, otherwise `false`
|
|
9
|
+
*/
|
|
4
10
|
declare function isLogger(value: unknown): value is Lumberjack;
|
|
11
|
+
/**
|
|
12
|
+
* Is the value a _TimeLogger_?
|
|
13
|
+
*
|
|
14
|
+
* @param value Value to check
|
|
15
|
+
* @returns `true` if the value is a _TimeLogger_, otherwise `false`
|
|
16
|
+
*/
|
|
5
17
|
declare function isTimeLogger(value: unknown): value is TimeLogger;
|
|
6
18
|
/**
|
|
7
19
|
* A logger that can be used to log messages to the console
|
package/dist/logger.mjs
CHANGED
|
@@ -64,12 +64,24 @@ function getTimeLoggerStop() {
|
|
|
64
64
|
}
|
|
65
65
|
return noop;
|
|
66
66
|
}
|
|
67
|
+
/**
|
|
68
|
+
* Is the value a _Logger_?
|
|
69
|
+
*
|
|
70
|
+
* @param value Value to check
|
|
71
|
+
* @returns `true` if the value is a _Logger_, otherwise `false`
|
|
72
|
+
*/
|
|
67
73
|
function isLogger(value) {
|
|
68
74
|
return isLoggerInstance(LOGGER_NAME, value);
|
|
69
75
|
}
|
|
70
76
|
function isLoggerInstance(name, value) {
|
|
71
77
|
return typeof value === "object" && value !== null && "$logger" in value && value["$logger"] === name;
|
|
72
78
|
}
|
|
79
|
+
/**
|
|
80
|
+
* Is the value a _TimeLogger_?
|
|
81
|
+
*
|
|
82
|
+
* @param value Value to check
|
|
83
|
+
* @returns `true` if the value is a _TimeLogger_, otherwise `false`
|
|
84
|
+
*/
|
|
73
85
|
function isTimeLogger(value) {
|
|
74
86
|
return isLoggerInstance(LOGGER_NAME_TIMED, value);
|
|
75
87
|
}
|
package/dist/math.d.mts
CHANGED
|
@@ -8,6 +8,16 @@ import { floor, round } from "./internal/math/misc.mjs";
|
|
|
8
8
|
* @param items List of items
|
|
9
9
|
* @param callback Callback to get an item's value
|
|
10
10
|
* @returns Average value, or `Number.NaN` if no average can be calculated
|
|
11
|
+
*
|
|
12
|
+
* @example
|
|
13
|
+
* ```typescript
|
|
14
|
+
* average([
|
|
15
|
+
* {value: 1},
|
|
16
|
+
* {value: 2},
|
|
17
|
+
* {value: 3},
|
|
18
|
+
* ], item => item.value); // => 2
|
|
19
|
+
* average([{value: 1}], item => item.nope); // => Number.NaN
|
|
20
|
+
* ```
|
|
11
21
|
*/
|
|
12
22
|
export declare function average<Item>(items: Item[], callback: (item: Item, index: number, array: Item[]) => number): number;
|
|
13
23
|
/**
|
|
@@ -16,6 +26,12 @@ export declare function average<Item>(items: Item[], callback: (item: Item, inde
|
|
|
16
26
|
* @param items List of items
|
|
17
27
|
* @param key Key to use for value
|
|
18
28
|
* @returns Average value, or `Number.NaN` if no average can be calculated
|
|
29
|
+
*
|
|
30
|
+
* @example
|
|
31
|
+
* ```typescript
|
|
32
|
+
* average([{value: 1}, {value: 2}, {value: 3}], 'value'); // => 2
|
|
33
|
+
* average([{value: 1}], 'nope'); // => Number.NaN
|
|
34
|
+
* ```
|
|
19
35
|
*/
|
|
20
36
|
export declare function average<Item extends PlainObject>(items: Item[], key: keyof NumericalValues<Item>): number;
|
|
21
37
|
/**
|
|
@@ -23,6 +39,12 @@ export declare function average<Item extends PlainObject>(items: Item[], key: ke
|
|
|
23
39
|
*
|
|
24
40
|
* @param numbers List of numbers
|
|
25
41
|
* @returns Average value, or `Number.NaN` if no average can be calculated
|
|
42
|
+
*
|
|
43
|
+
* @example
|
|
44
|
+
* ```typescript
|
|
45
|
+
* average([1, 2, 3, 4, 5]); // => 3
|
|
46
|
+
* average([]); // => Number.NaN
|
|
47
|
+
* ```
|
|
26
48
|
*/
|
|
27
49
|
export declare function average(numbers: number[]): number;
|
|
28
50
|
/**
|
|
@@ -31,6 +53,13 @@ export declare function average(numbers: number[]): number;
|
|
|
31
53
|
* @param value Number to round up
|
|
32
54
|
* @param decimals Number of decimal places to round to _(defaults to `0`)_
|
|
33
55
|
* @returns Rounded number, or `Number.NaN` if the value if unable to be rounded
|
|
56
|
+
*
|
|
57
|
+
* @example
|
|
58
|
+
* ```typescript
|
|
59
|
+
* ceil(1.234, 2); // => 1.24
|
|
60
|
+
* ceil(1.234); // => 2
|
|
61
|
+
* ceil('abc'); // => Number.NaN
|
|
62
|
+
* ```
|
|
34
63
|
*/
|
|
35
64
|
export declare function ceil(value: number, decimals?: number): number;
|
|
36
65
|
/**
|
|
@@ -40,6 +69,14 @@ export declare function ceil(value: number, decimals?: number): number;
|
|
|
40
69
|
* @param callback Callback to get an item's value
|
|
41
70
|
* @param value Value to match and count
|
|
42
71
|
* @returns Number of items that match the condition, or `Number.NaN` if no count can be calculated
|
|
72
|
+
*
|
|
73
|
+
* @example
|
|
74
|
+
* ```typescript
|
|
75
|
+
* count([1, 2, 3, 2], (item) => item, 2); // => 2
|
|
76
|
+
* count([{value: 1}, {value: 2}, {value: 3}], 'value', 2); // => 1
|
|
77
|
+
* count([1, 2, 3], (item) => item, 4); // => 0
|
|
78
|
+
* count([], (item) => item, 1); // => Number.NaN
|
|
79
|
+
* ```
|
|
43
80
|
*/
|
|
44
81
|
export declare function count<Item>(array: Item[], callback: (item: Item, index: number, array: Item[]) => unknown, value: unknown): number;
|
|
45
82
|
/**
|
|
@@ -49,6 +86,12 @@ export declare function count<Item>(array: Item[], callback: (item: Item, index:
|
|
|
49
86
|
* @param key Key to use for value
|
|
50
87
|
* @param value Value to match and count
|
|
51
88
|
* @returns Number of items with the specified key value, or `Number.NaN` if no count can be calculated
|
|
89
|
+
*
|
|
90
|
+
* @example
|
|
91
|
+
* ```typescript
|
|
92
|
+
* count([{value: 1}, {value: 2}, {value: 3}], 'value', 2); // => 1
|
|
93
|
+
* count([{value: 1}], 'nope', 1); // => Number.NaN
|
|
94
|
+
* ```
|
|
52
95
|
*/
|
|
53
96
|
export declare function count<Item extends PlainObject, ItemKey extends keyof Item>(array: Item[], key: ItemKey, value: Item[ItemKey]): number;
|
|
54
97
|
/**
|
|
@@ -56,6 +99,12 @@ export declare function count<Item extends PlainObject, ItemKey extends keyof It
|
|
|
56
99
|
*
|
|
57
100
|
* @param values Array to count for
|
|
58
101
|
* @returns Number of items, or `Number.NaN` if no count can be calculated
|
|
102
|
+
*
|
|
103
|
+
* @example
|
|
104
|
+
* ```typescript
|
|
105
|
+
* count([1, 2, 3]); // => 3
|
|
106
|
+
* count([]); // => Number.NaN
|
|
107
|
+
* ```
|
|
59
108
|
*/
|
|
60
109
|
export declare function count(values: unknown[]): number;
|
|
61
110
|
/**
|
|
@@ -64,6 +113,13 @@ export declare function count(values: unknown[]): number;
|
|
|
64
113
|
* @param array List of items
|
|
65
114
|
* @param callback Callback to get an item's value
|
|
66
115
|
* @returns Median value, or `Number.NaN` if no median can be calculated
|
|
116
|
+
*
|
|
117
|
+
* @example
|
|
118
|
+
* ```typescript
|
|
119
|
+
* median([1, 2, 3, 4, 5]); // => 3
|
|
120
|
+
* median([1, 2, 3, 4]); // => 2.5
|
|
121
|
+
* median([]); // => Number.NaN
|
|
122
|
+
* ```
|
|
67
123
|
*/
|
|
68
124
|
export declare function median<Item>(array: Item[], callback: (item: Item, index: number, array: Item[]) => number): number;
|
|
69
125
|
/**
|
|
@@ -72,6 +128,13 @@ export declare function median<Item>(array: Item[], callback: (item: Item, index
|
|
|
72
128
|
* @param array List of items
|
|
73
129
|
* @param key Key to use for value
|
|
74
130
|
* @returns Median value, or `Number.NaN` if no median can be calculated
|
|
131
|
+
*
|
|
132
|
+
* @example
|
|
133
|
+
* ```typescript
|
|
134
|
+
* median([{value: 1}, {value: 2}, {value: 3}], 'value'); // => 2
|
|
135
|
+
* median([{value: 1}, {value: 2}, {value: 3}, {value: 4}], 'value'); // => 2.5
|
|
136
|
+
* median([], 'value'); // => Number.NaN
|
|
137
|
+
* ```
|
|
75
138
|
*/
|
|
76
139
|
export declare function median<Item extends PlainObject>(array: Item[], key: keyof NumericalValues<Item>): number;
|
|
77
140
|
/**
|
|
@@ -79,6 +142,13 @@ export declare function median<Item extends PlainObject>(array: Item[], key: key
|
|
|
79
142
|
*
|
|
80
143
|
* @param array List of numbers
|
|
81
144
|
* @returns Median value, or `Number.NaN` if no median can be calculated
|
|
145
|
+
*
|
|
146
|
+
* @example
|
|
147
|
+
* ```typescript
|
|
148
|
+
* median([1, 2, 3, 4, 5]); // => 3
|
|
149
|
+
* median([1, 2, 3, 4]); // => 2.5
|
|
150
|
+
* median([]); // => Number.NaN
|
|
151
|
+
* ```
|
|
82
152
|
*/
|
|
83
153
|
export declare function median(array: number[]): number;
|
|
84
154
|
/**
|
|
@@ -87,6 +157,13 @@ export declare function median(array: number[]): number;
|
|
|
87
157
|
* @param items List of items
|
|
88
158
|
* @param callback Callback to get an item's value
|
|
89
159
|
* @returns Sum of the values, or `Number.NaN` if no sum can be calculated
|
|
160
|
+
*
|
|
161
|
+
* @example
|
|
162
|
+
* ```typescript
|
|
163
|
+
* sum([{value: 1}, {value: 2}, {value: 3}], 'value'); // => 6
|
|
164
|
+
* sum([{value: 1}, {value: 2}, {value: 3}], item => item.value); // => 6
|
|
165
|
+
* sum([]); // => Number.NaN
|
|
166
|
+
* ```
|
|
90
167
|
*/
|
|
91
168
|
export declare function sum<Item>(items: Item[], callback: (item: Item, index: number, array: Item[]) => number): number;
|
|
92
169
|
/**
|
|
@@ -95,6 +172,13 @@ export declare function sum<Item>(items: Item[], callback: (item: Item, index: n
|
|
|
95
172
|
* @param items List of items
|
|
96
173
|
* @param key Key to use for value
|
|
97
174
|
* @returns Sum of the values, or `Number.NaN` if no sum can be calculated
|
|
175
|
+
*
|
|
176
|
+
* @example
|
|
177
|
+
* ```typescript
|
|
178
|
+
* sum([{value: 1}, {value: 2}, {value: 3}], 'value'); // => 6
|
|
179
|
+
* sum([{value: 1}, {value: 2}, {value: 3}], item => item.value); // => 6
|
|
180
|
+
* sum([]); // => Number.NaN
|
|
181
|
+
* ```
|
|
98
182
|
*/
|
|
99
183
|
export declare function sum<Item extends PlainObject>(items: Item[], key: keyof NumericalValues<Item>): number;
|
|
100
184
|
/**
|
|
@@ -102,6 +186,12 @@ export declare function sum<Item extends PlainObject>(items: Item[], key: keyof
|
|
|
102
186
|
*
|
|
103
187
|
* @param values List of numbers
|
|
104
188
|
* @returns Sum of the numbers, or `Number.NaN` if no sum can be calculated
|
|
189
|
+
*
|
|
190
|
+
* @example
|
|
191
|
+
* ```typescript
|
|
192
|
+
* sum([1, 2, 3]); // => 6
|
|
193
|
+
* sum([]); // => Number.NaN
|
|
194
|
+
* ```
|
|
105
195
|
*/
|
|
106
196
|
export declare function sum(values: number[]): number;
|
|
107
197
|
//#endregion
|
package/dist/math.mjs
CHANGED
|
@@ -13,6 +13,13 @@ function average(array, key) {
|
|
|
13
13
|
* @param value Number to round up
|
|
14
14
|
* @param decimals Number of decimal places to round to _(defaults to `0`)_
|
|
15
15
|
* @returns Rounded number, or `Number.NaN` if the value if unable to be rounded
|
|
16
|
+
*
|
|
17
|
+
* @example
|
|
18
|
+
* ```typescript
|
|
19
|
+
* ceil(1.234, 2); // => 1.24
|
|
20
|
+
* ceil(1.234); // => 2
|
|
21
|
+
* ceil('abc'); // => Number.NaN
|
|
22
|
+
* ```
|
|
16
23
|
*/
|
|
17
24
|
function ceil(value, decimals) {
|
|
18
25
|
return roundNumber(Math.ceil, value, decimals);
|
|
@@ -1,8 +1,34 @@
|
|
|
1
|
+
import { GenericCallback } from "../index.mjs";
|
|
1
2
|
//#region src/models/array/array.find.model.d.ts
|
|
3
|
+
export type ArrayFindLimitOptions = {
|
|
4
|
+
limit?: number;
|
|
5
|
+
map?: never;
|
|
6
|
+
};
|
|
7
|
+
export type ArrayFindMapOptions = {
|
|
8
|
+
limit?: never;
|
|
9
|
+
map?: ArrayFindMapper;
|
|
10
|
+
};
|
|
2
11
|
export type ArrayFindMapper = {
|
|
3
12
|
callback: unknown;
|
|
13
|
+
flat: boolean;
|
|
4
14
|
reverse: boolean;
|
|
5
15
|
};
|
|
16
|
+
export type ArrayFindOptions = ArrayFindMapOptions | ArrayFindLimitOptions;
|
|
17
|
+
export type ArrayFindParameters = {
|
|
18
|
+
array: unknown[];
|
|
19
|
+
arrayLength: number;
|
|
20
|
+
callback?: GenericCallback;
|
|
21
|
+
flat: boolean;
|
|
22
|
+
limit: number;
|
|
23
|
+
map?: ArrayFindParametersMap;
|
|
24
|
+
result: ArrayFindValuesResult;
|
|
25
|
+
type: ArrayFindValuesType;
|
|
26
|
+
value: unknown;
|
|
27
|
+
};
|
|
28
|
+
export type ArrayFindParametersMap = {
|
|
29
|
+
after?: GenericCallback;
|
|
30
|
+
before?: GenericCallback;
|
|
31
|
+
};
|
|
6
32
|
export type ArrayFindValueType = "index" | "item";
|
|
7
33
|
export type ArrayFindValuesResult = {
|
|
8
34
|
matched: unknown[];
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { GenericCallback
|
|
1
|
+
import { GenericCallback } from "../index.mjs";
|
|
2
2
|
//#region src/models/array/array.misc.model.d.ts
|
|
3
3
|
export type ArrayCompareSetsType = "difference" | "intersection" | "union";
|
|
4
4
|
/**
|
|
@@ -6,6 +6,7 @@ export type ArrayCompareSetsType = "difference" | "intersection" | "union";
|
|
|
6
6
|
*/
|
|
7
7
|
export type ArrayComparison = "end" | "inside" | "invalid" | "outside" | "same" | "start";
|
|
8
8
|
export type ArrayExtractType = "drop" | "take";
|
|
9
|
+
export type ArrayFlattened<Value> = Value extends ReadonlyArray<infer Inner> ? Inner : Value;
|
|
9
10
|
export type ArrayGetCallbacks = {
|
|
10
11
|
bool?: GenericCallback;
|
|
11
12
|
keyed?: GenericCallback;
|
|
@@ -16,9 +17,6 @@ export type ArrayOverlapItem = {
|
|
|
16
17
|
array: unknown[];
|
|
17
18
|
index: number;
|
|
18
19
|
};
|
|
19
|
-
export type ArrayMapKeyOrCallback<Item> = ((item: Item, index: number, array: Item[]) => unknown) | (Item extends PlainObject ? keyof Item : never);
|
|
20
|
-
export 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;
|
|
21
|
-
export type ArrayObjectKeysOf<Item> = { [Key in keyof Item]: Item[Key] extends PlainObject ? Key : never; }[keyof Item];
|
|
22
20
|
export type ArrayOverlapResult = {
|
|
23
21
|
first: ArrayOverlapItem;
|
|
24
22
|
second: ArrayOverlapItem;
|
package/dist/models/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
|
*/
|
|
@@ -8,7 +8,7 @@ type BaseOptions = {
|
|
|
8
8
|
/**
|
|
9
9
|
* Key _(or key epxressions)_ for values that should be replaced
|
|
10
10
|
*
|
|
11
|
-
* ```
|
|
11
|
+
* ```typescript
|
|
12
12
|
* merge([{items: [1, 2, 3]}, {items: [99]}]); // => {items: [99]}
|
|
13
13
|
* ```
|
|
14
14
|
*/
|
|
@@ -16,7 +16,7 @@ type BaseOptions = {
|
|
|
16
16
|
/**
|
|
17
17
|
* Skip nullable values when merging objects?
|
|
18
18
|
*
|
|
19
|
-
* ```
|
|
19
|
+
* ```typescript
|
|
20
20
|
* merge({a: 1, b: 2}, {b: null, c: 3}, {d: null}); // => {a: 1, b: 2, c: 3}
|
|
21
21
|
* ```
|
|
22
22
|
*/
|
|
@@ -24,7 +24,7 @@ type BaseOptions = {
|
|
|
24
24
|
/**
|
|
25
25
|
* Skip nullable values when merging arrays?
|
|
26
26
|
*
|
|
27
|
-
* ```
|
|
27
|
+
* ```typescript
|
|
28
28
|
* merge([1, 2, 3], [null, null, 99]); // => [1, 2, 99]
|
|
29
29
|
* ```
|
|
30
30
|
*/
|
package/dist/promise/misc.d.mts
CHANGED
|
@@ -11,7 +11,13 @@ import { isFulfilled, isRejected } from "./helpers.mjs";
|
|
|
11
11
|
* @returns Cancelable _Promise_
|
|
12
12
|
*/
|
|
13
13
|
export declare function cancelable<Value>(executor: (resolve: (value: Value) => void, reject: (reason: unknown) => void) => void): CancelablePromise<Value>;
|
|
14
|
+
/**
|
|
15
|
+
* @internal
|
|
16
|
+
*/
|
|
14
17
|
export declare function handleResult(status: string, parameters: PromiseParameters): void;
|
|
18
|
+
/**
|
|
19
|
+
* @internal
|
|
20
|
+
*/
|
|
15
21
|
export declare function settlePromise(settler: (value: any) => void, value: unknown, aborter?: Aborter): void;
|
|
16
22
|
/**
|
|
17
23
|
* Converts a _Promise_ to a promised result
|
package/dist/promise/misc.mjs
CHANGED
|
@@ -12,6 +12,9 @@ import { isFulfilled, isRejected } from "./helpers.mjs";
|
|
|
12
12
|
function cancelable(executor) {
|
|
13
13
|
return new CancelablePromise(executor);
|
|
14
14
|
}
|
|
15
|
+
/**
|
|
16
|
+
* @internal
|
|
17
|
+
*/
|
|
15
18
|
function handleResult(status, parameters) {
|
|
16
19
|
const { aborter, complete, data, handlers, index, key, value } = parameters;
|
|
17
20
|
if (aborter?.signal.aborted ?? false) return;
|
|
@@ -35,6 +38,9 @@ function handleResult(status, parameters) {
|
|
|
35
38
|
handlers.resolve(data.result);
|
|
36
39
|
}
|
|
37
40
|
}
|
|
41
|
+
/**
|
|
42
|
+
* @internal
|
|
43
|
+
*/
|
|
38
44
|
function settlePromise(settler, value, aborter) {
|
|
39
45
|
aborter?.cancel();
|
|
40
46
|
settler(value);
|
package/dist/promise/timed.d.mts
CHANGED
|
@@ -1,6 +1,9 @@
|
|
|
1
1
|
import { RequiredKeys } from "../models/index.mjs";
|
|
2
2
|
import { PromiseOptions } from "../models/promise.model.mjs";
|
|
3
3
|
//#region src/promise/timed.d.ts
|
|
4
|
+
/**
|
|
5
|
+
* @internal
|
|
6
|
+
*/
|
|
4
7
|
export declare function getTimedPromise<Value>(promise: Promise<Value>, time: number, signal?: AbortSignal): Promise<Value>;
|
|
5
8
|
/**
|
|
6
9
|
* Create a _Promise_ that should be settled within a certain amount of time
|
package/dist/promise/timed.mjs
CHANGED
|
@@ -5,6 +5,9 @@ import { PROMISE_MESSAGE_EXPECTATION_TIMED, PromiseTimeoutError } from "../model
|
|
|
5
5
|
import { createPromiseOptions } from "./helpers.mjs";
|
|
6
6
|
import { settlePromise } from "./misc.mjs";
|
|
7
7
|
//#region src/promise/timed.ts
|
|
8
|
+
/**
|
|
9
|
+
* @internal
|
|
10
|
+
*/
|
|
8
11
|
async function getTimedPromise(promise, time, signal) {
|
|
9
12
|
const aborter = createAborter(signal, () => {
|
|
10
13
|
limiter.cancel();
|
package/dist/queue.d.mts
CHANGED
|
@@ -17,7 +17,6 @@ export declare function isKeyedQueue(value: unknown): value is KeyedQueue<Generi
|
|
|
17
17
|
* @returns `true` if the value is a queue, otherwise `false`
|
|
18
18
|
*/
|
|
19
19
|
export declare function isQueue(value: unknown): value is Queue<GenericCallback | GenericAsyncCallback>;
|
|
20
|
-
export declare function isQueueInstance<Instance>(name: string, value: unknown): value is Instance;
|
|
21
20
|
/**
|
|
22
21
|
* Create a keyed queue for an asynchronous callback function, where each key has its own queue
|
|
23
22
|
*
|
package/dist/queue.mjs
CHANGED
package/dist/string/index.d.mts
CHANGED
|
@@ -31,7 +31,7 @@ export declare function getUuid(): string;
|
|
|
31
31
|
*
|
|
32
32
|
* @param value JSON string to parse
|
|
33
33
|
* @param reviver Reviver function to transform the parsed values
|
|
34
|
-
* @returns Parsed value or `undefined` if parsing fails
|
|
34
|
+
* @returns Parsed value, or `undefined` if parsing fails
|
|
35
35
|
*/
|
|
36
36
|
export declare function parse(value: string, reviver?: (this: unknown, key: string, value: unknown) => unknown): unknown;
|
|
37
37
|
/**
|
|
@@ -39,6 +39,13 @@ export declare function parse(value: string, reviver?: (this: unknown, key: stri
|
|
|
39
39
|
*
|
|
40
40
|
* @param value String to trim
|
|
41
41
|
* @returns Trimmed string
|
|
42
|
+
* @example
|
|
43
|
+
* ```typescript
|
|
44
|
+
* trim(' this is a test '); // => 'this is a test'
|
|
45
|
+
* trim('this is a test'); // => 'this is a test'
|
|
46
|
+
* trim(' '); // => ''
|
|
47
|
+
* trim(''); // => ''
|
|
48
|
+
* ```
|
|
42
49
|
*/
|
|
43
50
|
export declare function trim(value: string): string;
|
|
44
51
|
/**
|
|
@@ -48,6 +55,13 @@ export declare function trim(value: string): string;
|
|
|
48
55
|
* @param length Maximum length of the string after truncation
|
|
49
56
|
* @param suffix Suffix to append to the truncated string
|
|
50
57
|
* @returns Truncated string
|
|
58
|
+
* @example
|
|
59
|
+
* ```typescript
|
|
60
|
+
* truncate('this is a test', 7); // => 'this is'
|
|
61
|
+
* truncate('this is a test', 7, '...'); // => 'this ...'
|
|
62
|
+
* truncate('this is a test', 20); // => 'this is a test'
|
|
63
|
+
* truncate('this is a test', 0); // => ''
|
|
64
|
+
* ```
|
|
51
65
|
*/
|
|
52
66
|
export declare function truncate(value: string, length: number, suffix?: string): string;
|
|
53
67
|
//#endregion
|