@oscarpalmer/atoms 0.186.2 → 0.187.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 +4 -4
- package/dist/array/find.d.mts +4 -4
- package/dist/array/first.d.mts +4 -4
- package/dist/array/get.d.mts +27 -1
- package/dist/array/get.mjs +5 -3
- package/dist/array/group-by.d.mts +6 -6
- package/dist/array/last.d.mts +4 -4
- package/dist/array/match.d.mts +7 -6
- package/dist/array/move.d.mts +7 -7
- package/dist/array/move.mjs +1 -1
- package/dist/array/select.d.mts +1 -0
- package/dist/array/slice.d.mts +3 -3
- package/dist/array/sort.d.mts +10 -7
- package/dist/array/sort.mjs +4 -3
- package/dist/array/swap.d.mts +1 -1
- package/dist/array/swap.mjs +1 -1
- package/dist/array/to-map.d.mts +32 -32
- package/dist/array/to-record.d.mts +6 -6
- package/dist/array/to-set.d.mts +6 -6
- package/dist/beacon.d.mts +6 -0
- package/dist/beacon.mjs +3 -0
- package/dist/color/index.d.mts +6 -2
- package/dist/color/index.mjs +6 -2
- package/dist/color/instance.d.mts +78 -14
- package/dist/color/instance.mjs +78 -14
- package/dist/color/misc/get.d.mts +39 -11
- package/dist/color/misc/get.mjs +39 -11
- package/dist/color/misc/is.d.mts +26 -11
- package/dist/color/misc/is.mjs +26 -11
- package/dist/color/misc/state.mjs +1 -1
- package/dist/color/models.d.mts +7 -4
- package/dist/color/space/hex.d.mts +15 -6
- package/dist/color/space/hex.mjs +15 -6
- package/dist/color/space/hsl.d.mts +10 -4
- package/dist/color/space/hsl.mjs +10 -4
- package/dist/color/space/rgb.d.mts +21 -12
- package/dist/color/space/rgb.mjs +21 -12
- package/dist/function/assert.d.mts +20 -14
- package/dist/function/assert.mjs +19 -13
- package/dist/function/limit.d.mts +8 -6
- package/dist/function/limit.mjs +8 -6
- package/dist/function/memoize.d.mts +15 -4
- package/dist/function/memoize.mjs +18 -4
- package/dist/function/once.d.mts +5 -3
- package/dist/function/once.mjs +5 -3
- package/dist/function/retry.d.mts +5 -2
- package/dist/function/retry.mjs +3 -1
- package/dist/function/work.d.mts +146 -98
- package/dist/{kalas.d.mts → herald.d.mts} +17 -8
- package/dist/{kalas.mjs → herald.mjs} +22 -13
- package/dist/index.d.mts +1464 -708
- package/dist/index.mjs +677 -324
- package/dist/internal/array/index-of.d.mts +4 -4
- package/dist/internal/array/insert.mjs +1 -1
- package/dist/internal/array/shuffle.d.mts +1 -0
- package/dist/internal/array/shuffle.mjs +2 -1
- package/dist/internal/is.d.mts +26 -8
- package/dist/internal/is.mjs +26 -8
- package/dist/internal/math/aggregate.d.mts +9 -9
- package/dist/internal/number.d.mts +13 -2
- package/dist/internal/number.mjs +13 -2
- package/dist/internal/random.d.mts +4 -2
- package/dist/internal/random.mjs +7 -5
- package/dist/internal/result.d.mts +17 -11
- package/dist/internal/result.mjs +10 -14
- package/dist/internal/string.d.mts +16 -1
- package/dist/internal/string.mjs +24 -1
- package/dist/internal/value/compare.d.mts +5 -2
- package/dist/internal/value/compare.mjs +5 -2
- package/dist/internal/value/equal.d.mts +12 -3
- package/dist/internal/value/equal.mjs +7 -4
- package/dist/internal/value/get.d.mts +17 -17
- package/dist/internal/value/has.d.mts +55 -11
- package/dist/internal/value/set.d.mts +24 -0
- package/dist/is.d.mts +12 -0
- package/dist/is.mjs +16 -1
- package/dist/logger.d.mts +7 -6
- package/dist/logger.mjs +6 -5
- package/dist/math.d.mts +36 -18
- package/dist/math.mjs +6 -3
- package/dist/models.d.mts +3 -3
- package/dist/promise/delay.d.mts +2 -0
- package/dist/promise/helpers.d.mts +6 -4
- package/dist/promise/helpers.mjs +6 -4
- package/dist/promise/index.d.mts +49 -38
- package/dist/promise/misc.d.mts +10 -7
- package/dist/promise/misc.mjs +4 -3
- package/dist/promise/models.d.mts +18 -19
- package/dist/promise/models.mjs +4 -3
- package/dist/promise/timed.d.mts +8 -6
- package/dist/query.d.mts +2 -0
- package/dist/query.mjs +2 -0
- package/dist/queue.d.mts +15 -4
- package/dist/queue.mjs +10 -3
- package/dist/random.d.mts +9 -2
- package/dist/random.mjs +7 -2
- package/dist/result/index.d.mts +14 -8
- package/dist/result/match.d.mts +18 -10
- package/dist/result/misc.d.mts +14 -7
- package/dist/result/misc.mjs +4 -2
- package/dist/result/models.d.mts +2 -0
- package/dist/result/work/flow.d.mts +86 -62
- package/dist/result/work/pipe.d.mts +55 -33
- package/dist/sized/map.d.mts +19 -16
- package/dist/sized/map.mjs +4 -4
- package/dist/sized/set.d.mts +20 -16
- package/dist/sized/set.mjs +8 -7
- package/dist/string/case.d.mts +8 -0
- package/dist/string/case.mjs +8 -0
- package/dist/string/fuzzy.d.mts +19 -5
- package/dist/string/fuzzy.mjs +7 -0
- package/dist/string/index.d.mts +17 -2
- package/dist/string/index.mjs +7 -9
- package/dist/string/match.d.mts +3 -0
- package/dist/string/match.mjs +3 -0
- package/dist/string/normalize.d.mts +6 -2
- package/dist/string/normalize.mjs +5 -2
- package/dist/string/template.d.mts +38 -9
- package/dist/string/template.mjs +19 -19
- package/dist/value/clone.d.mts +25 -4
- package/dist/value/clone.mjs +36 -22
- package/dist/value/collection.d.mts +9 -6
- package/dist/value/collection.mjs +3 -2
- package/dist/value/diff.d.mts +3 -1
- package/dist/value/diff.mjs +1 -0
- package/dist/value/freeze.d.mts +118 -9
- package/dist/value/freeze.mjs +56 -14
- package/dist/value/index.d.mts +1 -2
- package/dist/value/index.mjs +1 -2
- package/dist/value/merge.d.mts +11 -5
- package/dist/value/merge.mjs +2 -2
- package/dist/value/omit.d.mts +1 -0
- package/dist/value/omit.mjs +1 -0
- package/dist/value/pick.d.mts +1 -0
- package/dist/value/pick.mjs +1 -0
- package/dist/value/shake.d.mts +1 -0
- package/dist/value/shake.mjs +1 -0
- package/dist/value/smush.d.mts +1 -0
- package/dist/value/smush.mjs +1 -0
- package/dist/value/transform.d.mts +7 -3
- package/dist/value/unsmush.d.mts +1 -0
- package/dist/value/unsmush.mjs +1 -0
- package/package.json +11 -7
- package/src/array/filter.ts +4 -4
- package/src/array/find.ts +4 -4
- package/src/array/first.ts +4 -4
- package/src/array/get.ts +40 -5
- package/src/array/group-by.ts +6 -6
- package/src/array/last.ts +4 -4
- package/src/array/match.ts +7 -6
- package/src/array/move.ts +7 -7
- package/src/array/select.ts +1 -0
- package/src/array/slice.ts +3 -3
- package/src/array/sort.ts +15 -10
- package/src/array/swap.ts +1 -1
- package/src/array/to-map.ts +32 -32
- package/src/array/to-record.ts +6 -6
- package/src/array/to-set.ts +6 -6
- package/src/beacon.ts +6 -0
- package/src/color/index.ts +6 -2
- package/src/color/instance.ts +78 -14
- package/src/color/misc/get.ts +39 -11
- package/src/color/misc/is.ts +26 -11
- package/src/color/misc/state.ts +1 -1
- package/src/color/models.ts +7 -4
- package/src/color/space/hex.ts +15 -6
- package/src/color/space/hsl.ts +10 -4
- package/src/color/space/rgb.ts +21 -12
- package/src/function/assert.ts +20 -14
- package/src/function/limit.ts +8 -6
- package/src/function/memoize.ts +24 -5
- package/src/function/once.ts +5 -3
- package/src/function/retry.ts +7 -3
- package/src/function/work.ts +146 -98
- package/src/{kalas.ts → herald.ts} +23 -14
- package/src/index.ts +3 -2
- package/src/internal/array/index-of.ts +4 -4
- package/src/internal/array/insert.ts +1 -1
- package/src/internal/array/shuffle.ts +2 -1
- package/src/internal/is.ts +26 -8
- package/src/internal/math/aggregate.ts +9 -9
- package/src/internal/number.ts +13 -2
- package/src/internal/random.ts +10 -4
- package/src/internal/result.ts +30 -29
- package/src/internal/string.ts +28 -0
- package/src/internal/value/compare.ts +5 -2
- package/src/internal/value/equal.ts +13 -4
- package/src/internal/value/get.ts +17 -17
- package/src/internal/value/has.ts +54 -11
- package/src/internal/value/set.ts +24 -0
- package/src/is.ts +15 -1
- package/src/logger.ts +8 -7
- package/src/math.ts +36 -18
- package/src/models.ts +3 -3
- package/src/promise/delay.ts +2 -0
- package/src/promise/helpers.ts +6 -4
- package/src/promise/index.ts +49 -38
- package/src/promise/misc.ts +10 -7
- package/src/promise/models.ts +18 -19
- package/src/promise/timed.ts +8 -6
- package/src/query.ts +2 -0
- package/src/queue.ts +15 -4
- package/src/random.ts +8 -1
- package/src/result/index.ts +14 -8
- package/src/result/match.ts +18 -10
- package/src/result/misc.ts +17 -9
- package/src/result/models.ts +2 -0
- package/src/result/work/flow.ts +86 -62
- package/src/result/work/pipe.ts +55 -33
- package/src/sized/map.ts +20 -17
- package/src/sized/set.ts +21 -17
- package/src/string/case.ts +8 -0
- package/src/string/fuzzy.ts +19 -5
- package/src/string/index.ts +18 -15
- package/src/string/match.ts +3 -0
- package/src/string/normalize.ts +6 -2
- package/src/string/template.ts +69 -18
- package/src/value/clone.ts +51 -26
- package/src/value/collection.ts +9 -6
- package/src/value/diff.ts +3 -1
- package/src/value/freeze.ts +239 -25
- package/src/value/index.ts +0 -1
- package/src/value/merge.ts +11 -5
- package/src/value/omit.ts +1 -0
- package/src/value/pick.ts +1 -0
- package/src/value/shake.ts +1 -0
- package/src/value/smush.ts +1 -0
- package/src/value/transform.ts +7 -3
- package/src/value/unsmush.ts +1 -0
package/src/color/misc/is.ts
CHANGED
|
@@ -33,9 +33,10 @@ function isBytey(value: unknown): value is number {
|
|
|
33
33
|
}
|
|
34
34
|
|
|
35
35
|
/**
|
|
36
|
-
* Is the value a
|
|
36
|
+
* Is the value a _Color_?
|
|
37
|
+
*
|
|
37
38
|
* @param value Value to check
|
|
38
|
-
* @returns `true` if the value is a
|
|
39
|
+
* @returns `true` if the value is a _Color_, otherwise `false`
|
|
39
40
|
*/
|
|
40
41
|
export function isColor(value: unknown): value is Color {
|
|
41
42
|
return typeof value === 'object' && value !== null && '$color' in value && value.$color === true;
|
|
@@ -75,9 +76,19 @@ function isDegree(value: unknown): value is number {
|
|
|
75
76
|
|
|
76
77
|
/**
|
|
77
78
|
* Is the value a hex color?
|
|
79
|
+
*
|
|
78
80
|
* @param value Value to check
|
|
79
|
-
* @param alpha Allow alpha channel? _(defaults to `true`)_
|
|
81
|
+
* @param alpha Allow alpha channel _(opacity)_? _(defaults to `true`)_
|
|
80
82
|
* @returns `true` if the value is a hex color, otherwise `false`
|
|
83
|
+
*
|
|
84
|
+
* @example
|
|
85
|
+
* ```typescript
|
|
86
|
+
* isHexColor('ff0000'); // => true
|
|
87
|
+
* isHexColor('#ff0000'); // => true
|
|
88
|
+
*
|
|
89
|
+
* isHexColor('#ff000050'); // => true
|
|
90
|
+
* isHexColor('#ff000050', false); // => false
|
|
91
|
+
* ```
|
|
81
92
|
*/
|
|
82
93
|
export function isHexColor(value: unknown, alpha?: boolean): value is string {
|
|
83
94
|
if (typeof value !== 'string') {
|
|
@@ -96,18 +107,20 @@ export function isHexColor(value: unknown, alpha?: boolean): value is string {
|
|
|
96
107
|
}
|
|
97
108
|
|
|
98
109
|
/**
|
|
99
|
-
* Is the value an
|
|
110
|
+
* Is the value an _HSLA_ color?
|
|
111
|
+
*
|
|
100
112
|
* @param value Value to check
|
|
101
|
-
* @returns `true` if the value is an
|
|
113
|
+
* @returns `true` if the value is an _HSLA_ color, otherwise `false`
|
|
102
114
|
*/
|
|
103
115
|
export function isHslaColor(value: unknown): value is HSLAColor {
|
|
104
116
|
return isColorValue(value, KEYS_HSLA);
|
|
105
117
|
}
|
|
106
118
|
|
|
107
119
|
/**
|
|
108
|
-
* Is the value an
|
|
120
|
+
* Is the value an _HSL_ color?
|
|
121
|
+
*
|
|
109
122
|
* @param value Value to check
|
|
110
|
-
* @returns `true` if the value is an
|
|
123
|
+
* @returns `true` if the value is an _HSL_ color, otherwise `false`
|
|
111
124
|
*/
|
|
112
125
|
export function isHslColor(value: unknown): value is HSLColor {
|
|
113
126
|
return isColorValue(value, KEYS_HSLA) || isColorValue(value, KEYS_HSL);
|
|
@@ -118,18 +131,20 @@ export function isHslLike(value: unknown): value is Record<keyof HSLColor, unkno
|
|
|
118
131
|
}
|
|
119
132
|
|
|
120
133
|
/**
|
|
121
|
-
* Is the value an
|
|
134
|
+
* Is the value an _RGBA_ color?
|
|
135
|
+
*
|
|
122
136
|
* @param value Value to check
|
|
123
|
-
* @returns `true` if the value is an
|
|
137
|
+
* @returns `true` if the value is an _RGBA_ color, otherwise `false`
|
|
124
138
|
*/
|
|
125
139
|
export function isRgbaColor(value: unknown): value is RGBAColor {
|
|
126
140
|
return isColorValue(value, KEYS_RGBA);
|
|
127
141
|
}
|
|
128
142
|
|
|
129
143
|
/**
|
|
130
|
-
* Is the value an
|
|
144
|
+
* Is the value an _RGB_ color?
|
|
145
|
+
*
|
|
131
146
|
* @param value Value to check
|
|
132
|
-
* @returns `true` if the value is an
|
|
147
|
+
* @returns `true` if the value is an _RGB_ color, otherwise `false`
|
|
133
148
|
*/
|
|
134
149
|
export function isRgbColor(value: unknown): value is RGBColor {
|
|
135
150
|
return isColorValue(value, KEYS_RGBA) || isColorValue(value, KEYS_RGB);
|
package/src/color/misc/state.ts
CHANGED
package/src/color/models.ts
CHANGED
|
@@ -6,16 +6,19 @@ export type Alpha = {
|
|
|
6
6
|
};
|
|
7
7
|
|
|
8
8
|
type ColorWithAlpha = {
|
|
9
|
+
/**
|
|
10
|
+
* Alpha channel _(opacity)_ of the color _(in percentage; 0-100)_
|
|
11
|
+
*/
|
|
9
12
|
alpha: number;
|
|
10
13
|
};
|
|
11
14
|
|
|
12
15
|
/**
|
|
13
|
-
* An _HSL_
|
|
16
|
+
* An _HSL_ color with an alpha channel _(opacity)_
|
|
14
17
|
*/
|
|
15
18
|
export type HSLAColor = HSLColor & ColorWithAlpha;
|
|
16
19
|
|
|
17
20
|
/**
|
|
18
|
-
* An _HSL_
|
|
21
|
+
* An _HSL_ color
|
|
19
22
|
*/
|
|
20
23
|
export type HSLColor = {
|
|
21
24
|
/**
|
|
@@ -33,12 +36,12 @@ export type HSLColor = {
|
|
|
33
36
|
};
|
|
34
37
|
|
|
35
38
|
/**
|
|
36
|
-
* An _RGB_
|
|
39
|
+
* An _RGB_ color with an alpha channel _(opacity)_
|
|
37
40
|
*/
|
|
38
41
|
export type RGBAColor = RGBColor & ColorWithAlpha;
|
|
39
42
|
|
|
40
43
|
/**
|
|
41
|
-
* An _RGB_
|
|
44
|
+
* An _RGB_ color
|
|
42
45
|
*/
|
|
43
46
|
export type RGBColor = {
|
|
44
47
|
/**
|
package/src/color/space/hex.ts
CHANGED
|
@@ -36,9 +36,12 @@ function convertHexToRgba(value: string): RGBAColor {
|
|
|
36
36
|
|
|
37
37
|
/**
|
|
38
38
|
* Get the normalized hex color from a value
|
|
39
|
+
*
|
|
40
|
+
* _If the value is unable to be parsed or normalized, a hex color of `000000` will be returned, with the alpha channel _(opacity)_ value `0` included, if specified_
|
|
41
|
+
*
|
|
39
42
|
* @param value Value to normalize
|
|
40
|
-
* @param alpha Include alpha channel? _(defaults to `false`)_
|
|
41
|
-
* @returns Normalized hex color
|
|
43
|
+
* @param alpha Include alpha channel _(opacity)_? _(defaults to `false`)_
|
|
44
|
+
* @returns Normalized hex color
|
|
42
45
|
*/
|
|
43
46
|
export function getNormalizedHex(value: unknown, alpha?: boolean): string {
|
|
44
47
|
const includeAlpha = alpha ?? false;
|
|
@@ -78,9 +81,12 @@ export function hexToHsla(value: string): HSLAColor {
|
|
|
78
81
|
}
|
|
79
82
|
|
|
80
83
|
/**
|
|
81
|
-
* Convert a hex color to an
|
|
84
|
+
* Convert a hex color to an _RGB_ color
|
|
85
|
+
*
|
|
86
|
+
* _If the value is unable to be converted, a black RGB color will be returned_
|
|
87
|
+
*
|
|
82
88
|
* @param value Original value
|
|
83
|
-
* @returns
|
|
89
|
+
* @returns _RGB_ color
|
|
84
90
|
*/
|
|
85
91
|
export function hexToRgb(value: string): RGBColor {
|
|
86
92
|
const {blue, green, red} = convertHexToRgba(value);
|
|
@@ -89,9 +95,12 @@ export function hexToRgb(value: string): RGBColor {
|
|
|
89
95
|
}
|
|
90
96
|
|
|
91
97
|
/**
|
|
92
|
-
* Convert a hex color to an
|
|
98
|
+
* Convert a hex color to an _RGBA_ color
|
|
99
|
+
*
|
|
100
|
+
* _If the value is unable to be converted, a black RGBA color with an alpha channel (opacity) of `0` will be returned_
|
|
101
|
+
*
|
|
93
102
|
* @param value Original value
|
|
94
|
-
* @returns
|
|
103
|
+
* @returns _RGBA_ color
|
|
95
104
|
*/
|
|
96
105
|
export function hexToRgba(value: string): RGBAColor {
|
|
97
106
|
return convertHexToRgba(value);
|
package/src/color/space/hsl.ts
CHANGED
|
@@ -42,9 +42,12 @@ export function hslToHex(hsl: HSLAColor | HSLColor, alpha?: boolean): string {
|
|
|
42
42
|
}
|
|
43
43
|
|
|
44
44
|
/**
|
|
45
|
-
* Convert an
|
|
45
|
+
* Convert an _HSL(A)_ color to an _RGB_ color
|
|
46
|
+
*
|
|
47
|
+
* _If the value is unable to be converted, a black RGB color will be returned_
|
|
48
|
+
*
|
|
49
|
+
* _Thanks, https://github.com/color-js/color.js/blob/main/src/spaces/hsl.js#L61_
|
|
46
50
|
*
|
|
47
|
-
* Thanks, https://github.com/color-js/color.js/blob/main/src/spaces/hsl.js#L61
|
|
48
51
|
* @param hsl HSL(A) color
|
|
49
52
|
* @returns RGB color
|
|
50
53
|
*/
|
|
@@ -59,9 +62,12 @@ export function hslToRgb(hsl: HSLAColor | HSLColor): RGBColor {
|
|
|
59
62
|
}
|
|
60
63
|
|
|
61
64
|
/**
|
|
62
|
-
* Convert an
|
|
65
|
+
* Convert an _HSL(A)_ color to an _RGBA_ color
|
|
66
|
+
*
|
|
67
|
+
* _If the value is unable to be converted, a black RGBA color with an alpha channel (opactiy) of `0` will be returned_
|
|
68
|
+
*
|
|
69
|
+
* _Thanks, https://github.com/color-js/color.js/blob/main/src/spaces/hsl.js#L61_
|
|
63
70
|
*
|
|
64
|
-
* Thanks, https://github.com/color-js/color.js/blob/main/src/spaces/hsl.js#L61
|
|
65
71
|
* @param hsl HSL(A) color
|
|
66
72
|
* @returns RGBA color
|
|
67
73
|
*/
|
package/src/color/space/rgb.ts
CHANGED
|
@@ -77,21 +77,27 @@ export function getRgbValue(value: Record<keyof RGBColor, unknown>): RGBColor {
|
|
|
77
77
|
}
|
|
78
78
|
|
|
79
79
|
/**
|
|
80
|
-
* Convert an
|
|
81
|
-
*
|
|
82
|
-
*
|
|
83
|
-
*
|
|
80
|
+
* Convert an _RGB(A)_ color to a hex color _(with optional alpha channel, i.e., opacity)_
|
|
81
|
+
*
|
|
82
|
+
* _If the value is unable to be converted, a black hex color will be returned_
|
|
83
|
+
*
|
|
84
|
+
* @param rgb _RGB(A)_ color
|
|
85
|
+
* @param alpha Include alpha channel _(opacity)_? _(defaults to `false`)_
|
|
86
|
+
* @returns Hex color string
|
|
84
87
|
*/
|
|
85
88
|
export function rgbToHex(rgb: RGBAColor | RGBColor, alpha?: boolean): string {
|
|
86
89
|
return convertRgbToHex(isRgbLike(rgb) ? getRgbValue(rgb) : {...DEFAULT_RGB}, alpha ?? false);
|
|
87
90
|
}
|
|
88
91
|
|
|
89
92
|
/**
|
|
90
|
-
* Convert an
|
|
93
|
+
* Convert an _RGB(A)_ color to an _HSL_ color
|
|
94
|
+
*
|
|
95
|
+
* _If the value is unable to be converted, a black HSL color will be returned_
|
|
91
96
|
*
|
|
92
|
-
*
|
|
93
|
-
*
|
|
94
|
-
* @
|
|
97
|
+
* _Thanks, https://github.com/color-js/color.js/blob/main/src/spaces/hsl.js#L26_
|
|
98
|
+
*
|
|
99
|
+
* @param rgb _RGB(A)_ color
|
|
100
|
+
* @returns _HSL_ color
|
|
95
101
|
*/
|
|
96
102
|
export function rgbToHsl(rgb: RGBAColor | RGBColor): HSLColor {
|
|
97
103
|
const {hue, lightness, saturation} = convertRgbToHsla(rgb);
|
|
@@ -104,11 +110,14 @@ export function rgbToHsl(rgb: RGBAColor | RGBColor): HSLColor {
|
|
|
104
110
|
}
|
|
105
111
|
|
|
106
112
|
/**
|
|
107
|
-
* Convert an
|
|
113
|
+
* Convert an _RGB(A)_ color to an _HSLA_ color
|
|
114
|
+
*
|
|
115
|
+
* _If the value is unable to be converted, a black _HSLA_ color with an alpha channel (opacity) of `0` will be returned_
|
|
116
|
+
*
|
|
117
|
+
* _Thanks, https://github.com/color-js/color.js/blob/main/src/spaces/hsl.js#L26_
|
|
108
118
|
*
|
|
109
|
-
*
|
|
110
|
-
* @
|
|
111
|
-
* @returns HSLA color
|
|
119
|
+
* @param rgb _RGB(A)_ color
|
|
120
|
+
* @returns _HSLA_ color
|
|
112
121
|
*/
|
|
113
122
|
export function rgbToHsla(rgb: RGBAColor | RGBColor): HSLAColor {
|
|
114
123
|
return convertRgbToHsla(rgb);
|
package/src/function/assert.ts
CHANGED
|
@@ -4,7 +4,7 @@ import type {Constructor, NestedKeys, NestedValue, PlainObject} from '../models'
|
|
|
4
4
|
// #region Types
|
|
5
5
|
|
|
6
6
|
/**
|
|
7
|
-
* Asserter for a
|
|
7
|
+
* Asserter for a property of a value
|
|
8
8
|
*/
|
|
9
9
|
export type AssertProperty<
|
|
10
10
|
Value extends PlainObject,
|
|
@@ -33,6 +33,7 @@ type NestedPick<Value, Path extends string> = Value extends PlainObject
|
|
|
33
33
|
|
|
34
34
|
/**
|
|
35
35
|
* Asserts that a condition is true, throwing an error if it is not
|
|
36
|
+
*
|
|
36
37
|
* @param condition Condition to assert
|
|
37
38
|
* @param message Error message
|
|
38
39
|
* @param error Error constructor _(defaults to `Error`)_
|
|
@@ -54,13 +55,14 @@ assert.is = assertIs;
|
|
|
54
55
|
assert.property = assertProperty;
|
|
55
56
|
|
|
56
57
|
/**
|
|
57
|
-
* Creates an
|
|
58
|
+
* Creates an _Asserter_ that asserts a condition is true, throwing an error if it is not
|
|
59
|
+
*
|
|
60
|
+
* _Available as `assertCondition` and `assert.condition`_
|
|
58
61
|
*
|
|
59
|
-
* Available as `assertCondition` and `assert.condition`
|
|
60
62
|
* @param condition Condition to assert
|
|
61
63
|
* @param message Error message
|
|
62
64
|
* @param error Error constructor _(defaults to `Error`)_
|
|
63
|
-
* @returns
|
|
65
|
+
* @returns _Asserter_
|
|
64
66
|
*/
|
|
65
67
|
export function assertCondition<Value>(
|
|
66
68
|
condition: (value: unknown) => boolean,
|
|
@@ -75,7 +77,8 @@ export function assertCondition<Value>(
|
|
|
75
77
|
/**
|
|
76
78
|
* Asserts that a value is defined, throwing an error if it is not
|
|
77
79
|
*
|
|
78
|
-
*
|
|
80
|
+
* _Available as `assertDefined` and `assert.defined`_
|
|
81
|
+
*
|
|
79
82
|
* @param value Value to assert
|
|
80
83
|
* @param message Error message
|
|
81
84
|
* @param error Error constructor _(defaults to `Error`)_
|
|
@@ -89,13 +92,14 @@ export function assertDefined<Value>(
|
|
|
89
92
|
}
|
|
90
93
|
|
|
91
94
|
/**
|
|
92
|
-
* Creates an
|
|
95
|
+
* Creates an _Asserter_ that asserts a value is an instance of a constructor, throwing an error if it is not
|
|
96
|
+
*
|
|
97
|
+
* _Available as `assertInstanceOf` and `assert.instanceOf`_
|
|
93
98
|
*
|
|
94
|
-
* Available as `assertInstanceOf` and `assert.instanceOf`
|
|
95
99
|
* @param constructor Constructor to check against
|
|
96
100
|
* @param message Error message
|
|
97
101
|
* @param error Error constructor _(defaults to `Error`)_
|
|
98
|
-
* @returns
|
|
102
|
+
* @returns _Asserter_
|
|
99
103
|
*/
|
|
100
104
|
export function assertInstanceOf<Value>(
|
|
101
105
|
constructor: Constructor<Value>,
|
|
@@ -108,13 +112,14 @@ export function assertInstanceOf<Value>(
|
|
|
108
112
|
}
|
|
109
113
|
|
|
110
114
|
/**
|
|
111
|
-
* Creates an
|
|
115
|
+
* Creates an _Asserter_ that asserts a value is of a specific type, throwing an error if it is not
|
|
116
|
+
*
|
|
117
|
+
* _Available as `assertIs` and `assert.is`_
|
|
112
118
|
*
|
|
113
|
-
* Available as `assertIs` and `assert.is`
|
|
114
119
|
* @param condition Type guard function to check the value
|
|
115
120
|
* @param message Error message
|
|
116
121
|
* @param error Error constructor _(defaults to `Error`)_
|
|
117
|
-
* @returns
|
|
122
|
+
* @returns _Asserter_
|
|
118
123
|
*/
|
|
119
124
|
export function assertIs<Value>(
|
|
120
125
|
condition: (value: unknown) => value is Value,
|
|
@@ -127,14 +132,15 @@ export function assertIs<Value>(
|
|
|
127
132
|
}
|
|
128
133
|
|
|
129
134
|
/**
|
|
130
|
-
* Creates an
|
|
135
|
+
* Creates an _Asserter_ that asserts a property of a value exists and satisfies a condition, throwing an error if it does not
|
|
136
|
+
*
|
|
137
|
+
* _Available as `assertProperty` and `assert.property`_
|
|
131
138
|
*
|
|
132
|
-
* Available as `assertProperty` and `assert.property`
|
|
133
139
|
* @param path Path to the property to check, e.g., `foo.bar.baz` for a nested property
|
|
134
140
|
* @param condition Condition to assert for the property
|
|
135
141
|
* @param message Error message
|
|
136
142
|
* @param error Error constructor _(defaults to `Error`)_
|
|
137
|
-
* @returns
|
|
143
|
+
* @returns _Asserter_
|
|
138
144
|
*/
|
|
139
145
|
export function assertProperty<
|
|
140
146
|
Value extends PlainObject,
|
package/src/function/limit.ts
CHANGED
|
@@ -11,11 +11,11 @@ import type {
|
|
|
11
11
|
/**
|
|
12
12
|
* Debounce a function, ensuring it is only called after `time` milliseconds have passed
|
|
13
13
|
*
|
|
14
|
-
* When called, successful _(finished)_ results will resolve and errors will reject
|
|
14
|
+
* - When called, successful _(finished)_ results will resolve and errors will reject
|
|
15
|
+
* - On subsequent calls, existing calls will be canceled _(rejected)_, the timer reset, and will wait another `time` milliseconds before the new call is made _(and so on...)_
|
|
15
16
|
*
|
|
16
|
-
*
|
|
17
|
+
* _Available as `asyncDebounce` and `debounce.async`_
|
|
17
18
|
*
|
|
18
|
-
* Available as `asyncDebounce` and `debounce.async`
|
|
19
19
|
* @param callback Callback to debounce
|
|
20
20
|
* @param time Time in milliseconds to wait before calling the callback _(defaults to `0`; e.g., as soon as possible)_
|
|
21
21
|
* @returns Debounced callback handler with a `cancel` method
|
|
@@ -30,11 +30,11 @@ export function asyncDebounce<Callback extends GenericAsyncCallback | GenericCal
|
|
|
30
30
|
/**
|
|
31
31
|
* Throttle a function, ensuring it is only called once every `time` milliseconds
|
|
32
32
|
*
|
|
33
|
-
* When called, successful _(finished)_ results will resolve and errors will reject
|
|
33
|
+
* - When called, successful _(finished)_ results will resolve and errors will reject
|
|
34
|
+
* - On subsequent calls, existing calls will be canceled _(rejected)_ and will wait until the next valid time to call the callback again _(and so on...)_
|
|
34
35
|
*
|
|
35
|
-
*
|
|
36
|
+
* _Available as `asyncThrottle` and `throttle.async`_
|
|
36
37
|
*
|
|
37
|
-
* Available as `asyncThrottle` and `throttle.async`
|
|
38
38
|
* @param callback Callback to throttle
|
|
39
39
|
* @param time Time in milliseconds to wait before calling the callback again _(defaults to `0`; e.g., as soon as possible)_
|
|
40
40
|
* @returns Throttled callback handler with a `cancel` method
|
|
@@ -50,6 +50,7 @@ export function asyncThrottle<Callback extends GenericAsyncCallback | GenericCal
|
|
|
50
50
|
* Debounce a function, ensuring it is only called after `time` milliseconds have passed
|
|
51
51
|
*
|
|
52
52
|
* On subsequent calls, the timer is reset and will wait another `time` milliseconds _(and so on...)_
|
|
53
|
+
*
|
|
53
54
|
* @param callback Callback to debounce
|
|
54
55
|
* @param time Time in milliseconds to wait before calling the callback _(defaults to `0`; e.g., as soon as possible)_
|
|
55
56
|
* @returns Debounced callback handler with a `cancel` method
|
|
@@ -65,6 +66,7 @@ debounce.async = asyncDebounce;
|
|
|
65
66
|
|
|
66
67
|
/**
|
|
67
68
|
* Throttle a function, ensuring it is only called once every `time` milliseconds
|
|
69
|
+
*
|
|
68
70
|
* @param callback Callback to throttle
|
|
69
71
|
* @param time Time in milliseconds to wait before calling the callback again _(defaults to `0`; e.g., as soon as possible)_
|
|
70
72
|
* @returns Throttled callback handler with a `cancel` method
|
package/src/function/memoize.ts
CHANGED
|
@@ -6,13 +6,15 @@ import {SizedMap} from '../sized/map';
|
|
|
6
6
|
// #region Types
|
|
7
7
|
|
|
8
8
|
/**
|
|
9
|
-
* A
|
|
9
|
+
* A _Memoized_ function instance, caching and retrieving results based on the its parameters _(or a custom cache key)_
|
|
10
10
|
*/
|
|
11
11
|
class Memoized<Callback extends GenericCallback> {
|
|
12
12
|
readonly #state: MemoizedState<Callback>;
|
|
13
13
|
|
|
14
14
|
/**
|
|
15
15
|
* Maximum cache size
|
|
16
|
+
*
|
|
17
|
+
* @returns Maximum cache size _(or `Number.NaN` if the instance has been destroyed)_
|
|
16
18
|
*/
|
|
17
19
|
get maximum(): number {
|
|
18
20
|
return this.#state.cache?.maximum ?? Number.NaN;
|
|
@@ -20,6 +22,8 @@ class Memoized<Callback extends GenericCallback> {
|
|
|
20
22
|
|
|
21
23
|
/**
|
|
22
24
|
* Current cache size
|
|
25
|
+
*
|
|
26
|
+
* @returns Current cache size _(or `Number.NaN` if the instance has been destroyed)_
|
|
23
27
|
*/
|
|
24
28
|
get size(): number {
|
|
25
29
|
return this.#state.cache?.size ?? Number.NaN;
|
|
@@ -56,6 +60,7 @@ class Memoized<Callback extends GenericCallback> {
|
|
|
56
60
|
|
|
57
61
|
/**
|
|
58
62
|
* Delete a result from the cache
|
|
63
|
+
*
|
|
59
64
|
* @param key Key to delete
|
|
60
65
|
* @returns `true` if the key existed and was removed, otherwise `false`
|
|
61
66
|
*/
|
|
@@ -64,7 +69,9 @@ class Memoized<Callback extends GenericCallback> {
|
|
|
64
69
|
}
|
|
65
70
|
|
|
66
71
|
/**
|
|
67
|
-
* Destroy the instance
|
|
72
|
+
* Destroy the instance
|
|
73
|
+
*
|
|
74
|
+
* _(When a Memoized instance is destroyed, its cache and callback are removed, and calls to `run` will throw an error)_
|
|
68
75
|
*/
|
|
69
76
|
destroy(): void {
|
|
70
77
|
this.#state.cache?.clear();
|
|
@@ -75,6 +82,7 @@ class Memoized<Callback extends GenericCallback> {
|
|
|
75
82
|
|
|
76
83
|
/**
|
|
77
84
|
* Get a result from the cache
|
|
85
|
+
*
|
|
78
86
|
* @param key Key to get
|
|
79
87
|
* @returns Cached result or `undefined` if it does not exist
|
|
80
88
|
*/
|
|
@@ -84,6 +92,7 @@ class Memoized<Callback extends GenericCallback> {
|
|
|
84
92
|
|
|
85
93
|
/**
|
|
86
94
|
* Does the result exist?
|
|
95
|
+
*
|
|
87
96
|
* @param key Key to check
|
|
88
97
|
* @returns `true` if the result exists, otherwise `false`
|
|
89
98
|
*/
|
|
@@ -93,12 +102,13 @@ class Memoized<Callback extends GenericCallback> {
|
|
|
93
102
|
|
|
94
103
|
/**
|
|
95
104
|
* Run the callback with the provided parameters
|
|
105
|
+
*
|
|
96
106
|
* @param parameters Parameters to pass to the callback
|
|
97
107
|
* @returns Cached or computed _(then cached)_ result
|
|
98
108
|
*/
|
|
99
109
|
run(...parameters: Parameters<Callback>): ReturnType<Callback> {
|
|
100
110
|
if (this.#state.cache == null || this.#state.getter == null) {
|
|
101
|
-
throw new Error(
|
|
111
|
+
throw new Error(MEMOIZED_ERROR_DESTROYED);
|
|
102
112
|
}
|
|
103
113
|
|
|
104
114
|
return this.#state.getter(...parameters);
|
|
@@ -106,7 +116,7 @@ class Memoized<Callback extends GenericCallback> {
|
|
|
106
116
|
}
|
|
107
117
|
|
|
108
118
|
/**
|
|
109
|
-
* Options for
|
|
119
|
+
* Options for a _Memoized_ function
|
|
110
120
|
*/
|
|
111
121
|
type MemoizedOptions<Callback extends GenericCallback> = {
|
|
112
122
|
/**
|
|
@@ -146,14 +156,19 @@ function getMemoizationOptions<Callback extends GenericCallback>(
|
|
|
146
156
|
|
|
147
157
|
/**
|
|
148
158
|
* Memoize a function, caching and retrieving results based on the first parameter
|
|
159
|
+
*
|
|
149
160
|
* @param callback Callback to memoize
|
|
150
161
|
* @param options Memoization options
|
|
151
|
-
* @returns
|
|
162
|
+
* @returns _Memoized_ instance
|
|
152
163
|
*/
|
|
153
164
|
export function memoize<Callback extends GenericCallback>(
|
|
154
165
|
callback: Callback,
|
|
155
166
|
options?: MemoizedOptions<Callback>,
|
|
156
167
|
): Memoized<Callback> {
|
|
168
|
+
if (typeof callback !== 'function') {
|
|
169
|
+
throw new TypeError(MEMOIZED_ERROR_CALLBACK);
|
|
170
|
+
}
|
|
171
|
+
|
|
157
172
|
return new Memoized(callback, getMemoizationOptions(options));
|
|
158
173
|
}
|
|
159
174
|
|
|
@@ -163,6 +178,10 @@ export function memoize<Callback extends GenericCallback>(
|
|
|
163
178
|
|
|
164
179
|
const DEFAULT_CACHE_SIZE = 1024;
|
|
165
180
|
|
|
181
|
+
const MEMOIZED_ERROR_CALLBACK = 'Memoized requires a callback function';
|
|
182
|
+
|
|
183
|
+
const MEMOIZED_ERROR_DESTROYED = 'The Memoized instance has been destroyed';
|
|
184
|
+
|
|
166
185
|
const SEPARATOR = '_';
|
|
167
186
|
|
|
168
187
|
// #endregion
|
package/src/function/once.ts
CHANGED
|
@@ -32,9 +32,10 @@ type OnceState<Value> = {
|
|
|
32
32
|
/**
|
|
33
33
|
* Create an asynchronous function that can only be called once, rejecting or resolving the same result on subsequent calls
|
|
34
34
|
*
|
|
35
|
-
*
|
|
35
|
+
* _Available as `asyncOnce` and `once.async`_
|
|
36
|
+
*
|
|
36
37
|
* @param callback Callback to use once
|
|
37
|
-
* @returns
|
|
38
|
+
* @returns _Once_ callback
|
|
38
39
|
*/
|
|
39
40
|
export function asyncOnce<Callback extends GenericAsyncCallback>(
|
|
40
41
|
callback: Callback,
|
|
@@ -132,8 +133,9 @@ function handleOnceResult<Value>(
|
|
|
132
133
|
|
|
133
134
|
/**
|
|
134
135
|
* Create a function that can only be called once, returning the same value on subsequent calls
|
|
136
|
+
*
|
|
135
137
|
* @param callback Callback to use once
|
|
136
|
-
* @returns
|
|
138
|
+
* @returns _Once_ callback
|
|
137
139
|
*/
|
|
138
140
|
export function once<Callback extends GenericCallback>(callback: Callback): OnceCallback<Callback> {
|
|
139
141
|
assert(() => typeof callback === 'function', ONCE_MESSAGE_EXPECTATION);
|
package/src/function/retry.ts
CHANGED
|
@@ -31,7 +31,8 @@ export type RetryOptions = {
|
|
|
31
31
|
/**
|
|
32
32
|
* Retry a callback a specified number of times, with a delay between attempts
|
|
33
33
|
*
|
|
34
|
-
*
|
|
34
|
+
* _Available as `asyncRetry` and `retry.async`_
|
|
35
|
+
*
|
|
35
36
|
* @param callback Callback to retry
|
|
36
37
|
* @param options Retry options
|
|
37
38
|
* @returns Callback result
|
|
@@ -44,7 +45,8 @@ async function asyncRetry<Callback extends GenericAsyncCallback>(
|
|
|
44
45
|
/**
|
|
45
46
|
* Retry a callback a specified number of times, with a delay between attempts
|
|
46
47
|
*
|
|
47
|
-
*
|
|
48
|
+
* _Available as `asyncRetry` and `retry.async`_
|
|
49
|
+
*
|
|
48
50
|
* @param callback Callback to retry
|
|
49
51
|
* @param options Retry options
|
|
50
52
|
* @returns Callback result
|
|
@@ -57,7 +59,8 @@ async function asyncRetry<Callback extends GenericCallback>(
|
|
|
57
59
|
/**
|
|
58
60
|
* Retry a callback a specified number of times, with a delay between attempts
|
|
59
61
|
*
|
|
60
|
-
*
|
|
62
|
+
* _Available as `asyncRetry` and `retry.async`_
|
|
63
|
+
*
|
|
61
64
|
* @param callback Callback to retry
|
|
62
65
|
* @param options Retry options
|
|
63
66
|
* @returns Callback result
|
|
@@ -119,6 +122,7 @@ function getRetryOptions(input?: RetryOptions): Required<RetryOptions> {
|
|
|
119
122
|
|
|
120
123
|
/**
|
|
121
124
|
* Retry a callback a specified number of times
|
|
125
|
+
*
|
|
122
126
|
* @param callback Callback to retry
|
|
123
127
|
* @param options Retry options
|
|
124
128
|
* @returns Callback result
|