@oscarpalmer/atoms 0.184.0 → 0.184.2
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/single.mjs +2 -2
- package/dist/array/sort.mjs +5 -5
- package/dist/color/instance.mjs +2 -2
- package/dist/color/misc/get.mjs +8 -8
- package/dist/color/misc/state.d.mts +2 -2
- package/dist/color/misc/state.mjs +2 -2
- package/dist/function/once.mjs +9 -9
- package/dist/function/retry.mjs +8 -8
- package/dist/index.d.mts +5 -6
- package/dist/index.mjs +49 -53
- package/dist/internal/number.d.mts +2 -1
- package/dist/internal/number.mjs +4 -1
- package/dist/internal/result.d.mts +2 -2
- package/dist/internal/value/equal.mjs +5 -5
- package/dist/models.d.mts +1 -1
- package/dist/promise/helpers.mjs +3 -5
- package/dist/queue.mjs +5 -7
- package/dist/string/fuzzy.mjs +2 -2
- package/dist/value/freeze.d.mts +2 -2
- package/dist/value/merge.d.mts +0 -1
- package/dist/value/merge.mjs +0 -1
- package/package.json +2 -2
- package/src/array/single.ts +2 -2
- package/src/array/sort.ts +5 -5
- package/src/color/instance.ts +2 -2
- package/src/color/misc/get.ts +8 -8
- package/src/color/misc/state.ts +1 -1
- package/src/function/once.ts +9 -9
- package/src/function/retry.ts +8 -8
- package/src/internal/number.ts +6 -0
- package/src/internal/result.ts +3 -3
- package/src/internal/value/equal.ts +5 -5
- package/src/internal/value/get.ts +2 -1
- package/src/internal/value/set.ts +3 -1
- package/src/models.ts +1 -1
- package/src/promise/helpers.ts +3 -6
- package/src/queue.ts +10 -10
- package/src/string/fuzzy.ts +2 -2
- package/src/value/freeze.ts +2 -2
- package/src/value/merge.ts +0 -1
package/dist/array/single.mjs
CHANGED
|
@@ -2,9 +2,9 @@ import { findValues } from "../internal/array/find.mjs";
|
|
|
2
2
|
//#region src/array/single.ts
|
|
3
3
|
function single(array, ...parameters) {
|
|
4
4
|
const { matched } = findValues("all", array, parameters);
|
|
5
|
-
if (matched.length > 1) throw new Error(
|
|
5
|
+
if (matched.length > 1) throw new Error(SINGLE_MESSAGE);
|
|
6
6
|
return matched[0];
|
|
7
7
|
}
|
|
8
|
-
const
|
|
8
|
+
const SINGLE_MESSAGE = "Multiple items were found";
|
|
9
9
|
//#endregion
|
|
10
10
|
export { single };
|
package/dist/array/sort.mjs
CHANGED
|
@@ -98,9 +98,9 @@ function isSortedArray(array, sorters) {
|
|
|
98
98
|
if (length < 2) return true;
|
|
99
99
|
const sortersLength = sorters.length;
|
|
100
100
|
let offset = 0;
|
|
101
|
-
if (length >=
|
|
102
|
-
offset = Math.round(length /
|
|
103
|
-
offset = offset >
|
|
101
|
+
if (length >= SORT_THRESHOLD) {
|
|
102
|
+
offset = Math.round(length / SORT_PEEK_PERCENTAGE);
|
|
103
|
+
offset = offset > SORT_THRESHOLD ? SORT_THRESHOLD : offset;
|
|
104
104
|
for (let index = 0; index < offset; index += 1) {
|
|
105
105
|
const [firstItem, firstOffset] = [array[index], array[index + 1]];
|
|
106
106
|
const [secondItem, secondOffset] = [array[length - index - 2], array[length - index - 1]];
|
|
@@ -127,8 +127,8 @@ function sortArray(array, sorters) {
|
|
|
127
127
|
sort.index = getSortedIndex;
|
|
128
128
|
sort.initialize = initializeSorter;
|
|
129
129
|
sort.is = isSorted;
|
|
130
|
-
const
|
|
131
|
-
const
|
|
130
|
+
const SORT_PEEK_PERCENTAGE = 10;
|
|
131
|
+
const SORT_THRESHOLD = 100;
|
|
132
132
|
const SORT_DIRECTION_ASCENDING = "ascending";
|
|
133
133
|
const SORT_DIRECTION_DESCENDING = "descending";
|
|
134
134
|
const modifiers = {
|
package/dist/color/instance.mjs
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import "./constants.mjs";
|
|
2
2
|
import { formatColor } from "./misc/index.mjs";
|
|
3
3
|
import { getAlpha } from "./misc/alpha.mjs";
|
|
4
|
-
import {
|
|
4
|
+
import { getColorState, setHSLColor, setHexColor, setRGBColor } from "./misc/state.mjs";
|
|
5
5
|
//#region src/color/instance.ts
|
|
6
6
|
var Color = class {
|
|
7
7
|
#state;
|
|
@@ -96,7 +96,7 @@ var Color = class {
|
|
|
96
96
|
setRGBColor(this.#state, value, true);
|
|
97
97
|
}
|
|
98
98
|
constructor(value) {
|
|
99
|
-
this.#state =
|
|
99
|
+
this.#state = getColorState(value);
|
|
100
100
|
Object.defineProperty(this, "$color", { value: true });
|
|
101
101
|
}
|
|
102
102
|
toHexString(alpha) {
|
package/dist/color/misc/get.mjs
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { clamp } from "../../internal/number.mjs";
|
|
2
2
|
import { HEX_BLACK, HEX_WHITE, SRGB_LUMINANCE_EXPONENT, SRGB_LUMINANCE_MODIFIER, SRGB_LUMINANCE_MULTIPLIER, SRGB_LUMINANCE_OFFSET } from "../constants.mjs";
|
|
3
|
-
import {
|
|
3
|
+
import { getColorState } from "./state.mjs";
|
|
4
4
|
import { Color } from "../instance.mjs";
|
|
5
5
|
//#region src/color/misc/get.ts
|
|
6
6
|
function getClampedValue(value, minimum, maximum) {
|
|
@@ -12,7 +12,7 @@ function getClampedValue(value, minimum, maximum) {
|
|
|
12
12
|
* @returns Foreground color
|
|
13
13
|
*/
|
|
14
14
|
function getForegroundColor(value) {
|
|
15
|
-
const { blue, green, red } =
|
|
15
|
+
const { blue, green, red } = getColorState(value).rgb;
|
|
16
16
|
const values = [
|
|
17
17
|
blue / 255,
|
|
18
18
|
green / 255,
|
|
@@ -32,7 +32,7 @@ function getForegroundColor(value) {
|
|
|
32
32
|
* @returns Hex color
|
|
33
33
|
*/
|
|
34
34
|
function getHexaColor(value) {
|
|
35
|
-
const { alpha, hex } =
|
|
35
|
+
const { alpha, hex } = getColorState(value);
|
|
36
36
|
return `${hex}${alpha.hex}`;
|
|
37
37
|
}
|
|
38
38
|
/**
|
|
@@ -41,7 +41,7 @@ function getHexaColor(value) {
|
|
|
41
41
|
* @returns Hex color
|
|
42
42
|
*/
|
|
43
43
|
function getHexColor(value) {
|
|
44
|
-
return
|
|
44
|
+
return getColorState(value).hex;
|
|
45
45
|
}
|
|
46
46
|
function getHexValue(value) {
|
|
47
47
|
return getClampedValue(value, 0, 255);
|
|
@@ -55,7 +55,7 @@ function getDegrees(value) {
|
|
|
55
55
|
* @returns HSLA color
|
|
56
56
|
*/
|
|
57
57
|
function getHslaColor(value) {
|
|
58
|
-
const { alpha, hsl } =
|
|
58
|
+
const { alpha, hsl } = getColorState(value);
|
|
59
59
|
return {
|
|
60
60
|
...hsl,
|
|
61
61
|
alpha: alpha.value
|
|
@@ -67,7 +67,7 @@ function getHslaColor(value) {
|
|
|
67
67
|
* @returns HSL color
|
|
68
68
|
*/
|
|
69
69
|
function getHslColor(value) {
|
|
70
|
-
return
|
|
70
|
+
return getColorState(value).hsl;
|
|
71
71
|
}
|
|
72
72
|
function getPercentage(value) {
|
|
73
73
|
return getClampedValue(value, 0, 100);
|
|
@@ -78,7 +78,7 @@ function getPercentage(value) {
|
|
|
78
78
|
* @returns RGBA color
|
|
79
79
|
*/
|
|
80
80
|
function getRgbaColor(value) {
|
|
81
|
-
const { alpha, rgb } =
|
|
81
|
+
const { alpha, rgb } = getColorState(value);
|
|
82
82
|
return {
|
|
83
83
|
...rgb,
|
|
84
84
|
alpha: alpha.value
|
|
@@ -90,7 +90,7 @@ function getRgbaColor(value) {
|
|
|
90
90
|
* @returns RGB color
|
|
91
91
|
*/
|
|
92
92
|
function getRgbColor(value) {
|
|
93
|
-
return
|
|
93
|
+
return getColorState(value).rgb;
|
|
94
94
|
}
|
|
95
95
|
//#endregion
|
|
96
96
|
export { getDegrees, getForegroundColor, getHexColor, getHexValue, getHexaColor, getHslColor, getHslaColor, getPercentage, getRgbColor, getRgbaColor };
|
|
@@ -1,9 +1,9 @@
|
|
|
1
1
|
import { ColorState } from "../models.mjs";
|
|
2
2
|
|
|
3
3
|
//#region src/color/misc/state.d.ts
|
|
4
|
-
declare function
|
|
4
|
+
declare function getColorState(value: unknown): ColorState;
|
|
5
5
|
declare function setHexColor(state: ColorState, value: string, alpha: boolean): void;
|
|
6
6
|
declare function setHSLColor(state: ColorState, value: unknown, alpha: boolean): void;
|
|
7
7
|
declare function setRGBColor(state: ColorState, value: unknown, alpha: boolean): void;
|
|
8
8
|
//#endregion
|
|
9
|
-
export {
|
|
9
|
+
export { getColorState, setHSLColor, setHexColor, setRGBColor };
|
|
@@ -6,7 +6,7 @@ import { getRgbValue, rgbToHex, rgbToHsl } from "../space/rgb.mjs";
|
|
|
6
6
|
import { getNormalizedHex, hexToRgb } from "../space/hex.mjs";
|
|
7
7
|
import { getHslValue, hslToRgb } from "../space/hsl.mjs";
|
|
8
8
|
//#region src/color/misc/state.ts
|
|
9
|
-
function
|
|
9
|
+
function getColorState(value) {
|
|
10
10
|
if (typeof value === "string") {
|
|
11
11
|
const normalized = getNormalizedHex(value, true);
|
|
12
12
|
const hex = normalized.slice(0, 6);
|
|
@@ -82,4 +82,4 @@ function setRGBColor(state, value, alpha) {
|
|
|
82
82
|
if (alpha) state.alpha = getAlpha(value.alpha);
|
|
83
83
|
}
|
|
84
84
|
//#endregion
|
|
85
|
-
export {
|
|
85
|
+
export { getColorState, setHSLColor, setHexColor, setRGBColor };
|
package/dist/function/once.mjs
CHANGED
|
@@ -8,7 +8,7 @@ import { assert } from "./assert.mjs";
|
|
|
8
8
|
* @returns Once callback
|
|
9
9
|
*/
|
|
10
10
|
function asyncOnce(callback) {
|
|
11
|
-
assert(() => typeof callback === "function",
|
|
11
|
+
assert(() => typeof callback === "function", ONCE_MESSAGE_EXPECTATION);
|
|
12
12
|
const state = {
|
|
13
13
|
called: false,
|
|
14
14
|
cleared: false,
|
|
@@ -18,7 +18,7 @@ function asyncOnce(callback) {
|
|
|
18
18
|
value: void 0
|
|
19
19
|
};
|
|
20
20
|
const fn = (...parameters) => {
|
|
21
|
-
if (state.cleared) return Promise.reject(new Error(
|
|
21
|
+
if (state.cleared) return Promise.reject(new Error(ONCE_MESSAGE_CLEARED));
|
|
22
22
|
if (state.finished) return state.error ? Promise.reject(state.value) : Promise.resolve(state.value);
|
|
23
23
|
if (state.called) return new Promise((resolve, reject) => {
|
|
24
24
|
state.items.push({
|
|
@@ -33,9 +33,9 @@ function asyncOnce(callback) {
|
|
|
33
33
|
resolve
|
|
34
34
|
});
|
|
35
35
|
callback(...parameters).then((value) => {
|
|
36
|
-
|
|
36
|
+
handleOnceResult(state, value, false);
|
|
37
37
|
}).catch((error) => {
|
|
38
|
-
|
|
38
|
+
handleOnceResult(state, error, true);
|
|
39
39
|
});
|
|
40
40
|
});
|
|
41
41
|
};
|
|
@@ -52,7 +52,7 @@ function asyncOnce(callback) {
|
|
|
52
52
|
};
|
|
53
53
|
return fn;
|
|
54
54
|
}
|
|
55
|
-
function
|
|
55
|
+
function handleOnceResult(state, value, error) {
|
|
56
56
|
state.error = error;
|
|
57
57
|
state.finished = true;
|
|
58
58
|
state.value = value;
|
|
@@ -70,14 +70,14 @@ function handleResult(state, value, error) {
|
|
|
70
70
|
* @returns Once callback
|
|
71
71
|
*/
|
|
72
72
|
function once(callback) {
|
|
73
|
-
assert(() => typeof callback === "function",
|
|
73
|
+
assert(() => typeof callback === "function", ONCE_MESSAGE_EXPECTATION);
|
|
74
74
|
const state = {
|
|
75
75
|
called: false,
|
|
76
76
|
cleared: false,
|
|
77
77
|
value: void 0
|
|
78
78
|
};
|
|
79
79
|
const fn = (...parameters) => {
|
|
80
|
-
if (state.cleared) throw new Error(
|
|
80
|
+
if (state.cleared) throw new Error(ONCE_MESSAGE_CLEARED);
|
|
81
81
|
if (state.called) return state.value;
|
|
82
82
|
state.called = true;
|
|
83
83
|
state.value = callback(...parameters);
|
|
@@ -95,7 +95,7 @@ function once(callback) {
|
|
|
95
95
|
return fn;
|
|
96
96
|
}
|
|
97
97
|
once.async = asyncOnce;
|
|
98
|
-
const
|
|
99
|
-
const
|
|
98
|
+
const ONCE_MESSAGE_CLEARED = "Once has been cleared";
|
|
99
|
+
const ONCE_MESSAGE_EXPECTATION = "Once expected a function";
|
|
100
100
|
//#endregion
|
|
101
101
|
export { asyncOnce, once };
|
package/dist/function/retry.mjs
CHANGED
|
@@ -5,7 +5,7 @@ var RetryError = class extends Error {
|
|
|
5
5
|
constructor(message, original) {
|
|
6
6
|
super(message);
|
|
7
7
|
this.original = original;
|
|
8
|
-
this.name =
|
|
8
|
+
this.name = RETRY_ERROR_NAME;
|
|
9
9
|
}
|
|
10
10
|
};
|
|
11
11
|
/**
|
|
@@ -17,13 +17,13 @@ var RetryError = class extends Error {
|
|
|
17
17
|
* @returns Callback result
|
|
18
18
|
*/
|
|
19
19
|
async function asyncRetry(callback, options) {
|
|
20
|
-
if (typeof callback !== "function") throw new TypeError(
|
|
20
|
+
if (typeof callback !== "function") throw new TypeError(RETRY_MESSAGE_EXPECTATION);
|
|
21
21
|
async function handle() {
|
|
22
22
|
try {
|
|
23
23
|
const result = await callback();
|
|
24
24
|
resolver(result);
|
|
25
25
|
} catch (error) {
|
|
26
|
-
if (attempts >= times || !when(error)) rejector(new RetryError(
|
|
26
|
+
if (attempts >= times || !when(error)) rejector(new RetryError(RETRY_MESSAGE_FAILED, error));
|
|
27
27
|
else {
|
|
28
28
|
attempts += 1;
|
|
29
29
|
timer();
|
|
@@ -59,7 +59,7 @@ function getRetryOptions(input) {
|
|
|
59
59
|
* @returns Callback result
|
|
60
60
|
*/
|
|
61
61
|
function retry(callback, options) {
|
|
62
|
-
if (typeof callback !== "function") throw new TypeError(
|
|
62
|
+
if (typeof callback !== "function") throw new TypeError(RETRY_MESSAGE_EXPECTATION);
|
|
63
63
|
const { times, when } = getRetryOptions(options);
|
|
64
64
|
let last;
|
|
65
65
|
for (let index = 0; index <= times; index += 1) try {
|
|
@@ -70,14 +70,14 @@ function retry(callback, options) {
|
|
|
70
70
|
break;
|
|
71
71
|
}
|
|
72
72
|
}
|
|
73
|
-
throw new RetryError(
|
|
73
|
+
throw new RetryError(RETRY_MESSAGE_FAILED, last);
|
|
74
74
|
}
|
|
75
75
|
retry.async = asyncRetry;
|
|
76
76
|
function shouldRetry() {
|
|
77
77
|
return true;
|
|
78
78
|
}
|
|
79
|
-
const
|
|
80
|
-
const
|
|
81
|
-
const
|
|
79
|
+
const RETRY_ERROR_NAME = "RetryError";
|
|
80
|
+
const RETRY_MESSAGE_EXPECTATION = "Retry expected a function";
|
|
81
|
+
const RETRY_MESSAGE_FAILED = "Retry failed";
|
|
82
82
|
//#endregion
|
|
83
83
|
export { RetryError, retry };
|
package/dist/index.d.mts
CHANGED
|
@@ -13,7 +13,7 @@ type AsyncCancelableCallback<Callback extends GenericAsyncCallback | GenericCall
|
|
|
13
13
|
cancel: () => void;
|
|
14
14
|
};
|
|
15
15
|
/**
|
|
16
|
-
* For
|
|
16
|
+
* For matching any `void`, `Date`, primitive, or `RegExp` values
|
|
17
17
|
*
|
|
18
18
|
* (Thanks, type-fest!)
|
|
19
19
|
*/
|
|
@@ -3392,8 +3392,8 @@ type Frozen<Value extends ArrayOrPlainObject> = { readonly [Key in keyof Value]:
|
|
|
3392
3392
|
*/
|
|
3393
3393
|
declare function freeze<Item>(array: Item[]): Frozen<Item[]>;
|
|
3394
3394
|
/**
|
|
3395
|
-
* Freeze a
|
|
3396
|
-
* @param
|
|
3395
|
+
* Freeze a function
|
|
3396
|
+
* @param fn Function to freeze
|
|
3397
3397
|
* @returns Frozen function
|
|
3398
3398
|
*/
|
|
3399
3399
|
declare function freeze<Fn extends GenericCallback>(fn: Fn): Readonly<Fn>;
|
|
@@ -3558,7 +3558,6 @@ declare function merge<Model extends ArrayOrPlainObject>(values: NestedPartial<M
|
|
|
3558
3558
|
*/
|
|
3559
3559
|
declare function merge(values: NestedPartial<ArrayOrPlainObject>[], options?: MergeOptions): ArrayOrPlainObject;
|
|
3560
3560
|
declare namespace merge {
|
|
3561
|
-
var assign: typeof assign;
|
|
3562
3561
|
var initialize: typeof initializeMerger;
|
|
3563
3562
|
}
|
|
3564
3563
|
//#endregion
|
|
@@ -4577,13 +4576,13 @@ declare function resultPromises<Value>(items: Promise<Value>[], signal?: AbortSi
|
|
|
4577
4576
|
* @param result Result to check
|
|
4578
4577
|
* @returns `true` if the result is an extended error, `false` otherwise
|
|
4579
4578
|
*/
|
|
4580
|
-
declare function isError<Value, E = Error>(
|
|
4579
|
+
declare function isError<Value, E = Error>(result: ExtendedErr<E> | Result<Value, E>, extended: true): result is ExtendedErr<E>;
|
|
4581
4580
|
/**
|
|
4582
4581
|
* Is the result an error?
|
|
4583
4582
|
* @param result Result to check
|
|
4584
4583
|
* @returns `true` if the result is an error, `false` otherwise
|
|
4585
4584
|
*/
|
|
4586
|
-
declare function isError<Value, E = Error>(
|
|
4585
|
+
declare function isError<Value, E = Error>(result: Result<Value, E>): result is Err<E>;
|
|
4587
4586
|
/**
|
|
4588
4587
|
* Is the value an error?
|
|
4589
4588
|
* @param value Value to check
|
package/dist/index.mjs
CHANGED
|
@@ -620,10 +620,10 @@ function select(array, ...parameters) {
|
|
|
620
620
|
//#region src/array/single.ts
|
|
621
621
|
function single(array, ...parameters) {
|
|
622
622
|
const { matched } = findValues("all", array, parameters);
|
|
623
|
-
if (matched.length > 1) throw new Error(
|
|
623
|
+
if (matched.length > 1) throw new Error(SINGLE_MESSAGE);
|
|
624
624
|
return matched[0];
|
|
625
625
|
}
|
|
626
|
-
const
|
|
626
|
+
const SINGLE_MESSAGE = "Multiple items were found";
|
|
627
627
|
//#endregion
|
|
628
628
|
//#region src/array/slice.ts
|
|
629
629
|
function drop(array, first, second) {
|
|
@@ -1170,9 +1170,9 @@ function isSortedArray(array, sorters) {
|
|
|
1170
1170
|
if (length < 2) return true;
|
|
1171
1171
|
const sortersLength = sorters.length;
|
|
1172
1172
|
let offset = 0;
|
|
1173
|
-
if (length >=
|
|
1174
|
-
offset = Math.round(length /
|
|
1175
|
-
offset = offset >
|
|
1173
|
+
if (length >= SORT_THRESHOLD) {
|
|
1174
|
+
offset = Math.round(length / SORT_PEEK_PERCENTAGE);
|
|
1175
|
+
offset = offset > SORT_THRESHOLD ? SORT_THRESHOLD : offset;
|
|
1176
1176
|
for (let index = 0; index < offset; index += 1) {
|
|
1177
1177
|
const [firstItem, firstOffset] = [array[index], array[index + 1]];
|
|
1178
1178
|
const [secondItem, secondOffset] = [array[length - index - 2], array[length - index - 1]];
|
|
@@ -1199,8 +1199,8 @@ function sortArray(array, sorters) {
|
|
|
1199
1199
|
sort.index = getSortedIndex;
|
|
1200
1200
|
sort.initialize = initializeSorter;
|
|
1201
1201
|
sort.is = isSorted;
|
|
1202
|
-
const
|
|
1203
|
-
const
|
|
1202
|
+
const SORT_PEEK_PERCENTAGE = 10;
|
|
1203
|
+
const SORT_THRESHOLD = 100;
|
|
1204
1204
|
const SORT_DIRECTION_ASCENDING = "ascending";
|
|
1205
1205
|
const SORT_DIRECTION_DESCENDING = "descending";
|
|
1206
1206
|
const modifiers = {
|
|
@@ -1427,6 +1427,9 @@ function getNumber(value) {
|
|
|
1427
1427
|
if (isBinary || EXPRESSION_OCTAL.test(trimmed)) return Number.parseInt(trimmed.slice(2), isBinary ? 2 : OCTAL_VALUE);
|
|
1428
1428
|
return Number(trimmed);
|
|
1429
1429
|
}
|
|
1430
|
+
function getNumberOrDefault(value, defaultValue, minimum) {
|
|
1431
|
+
return typeof value === "number" && !Number.isNaN(value) && value >= (minimum ?? 0) ? Math.floor(value) : defaultValue;
|
|
1432
|
+
}
|
|
1430
1433
|
const EXPRESSION_BINARY = /^0b[01]+$/i;
|
|
1431
1434
|
const EXPRESSION_OCTAL = /^0o[0-7]+$/i;
|
|
1432
1435
|
const EXPRESSION_ZEROISH = /^\s*0+\s*$/;
|
|
@@ -1739,7 +1742,7 @@ throttle.async = asyncThrottle;
|
|
|
1739
1742
|
* @returns Once callback
|
|
1740
1743
|
*/
|
|
1741
1744
|
function asyncOnce(callback) {
|
|
1742
|
-
assert(() => typeof callback === "function",
|
|
1745
|
+
assert(() => typeof callback === "function", ONCE_MESSAGE_EXPECTATION);
|
|
1743
1746
|
const state = {
|
|
1744
1747
|
called: false,
|
|
1745
1748
|
cleared: false,
|
|
@@ -1749,7 +1752,7 @@ function asyncOnce(callback) {
|
|
|
1749
1752
|
value: void 0
|
|
1750
1753
|
};
|
|
1751
1754
|
const fn = (...parameters) => {
|
|
1752
|
-
if (state.cleared) return Promise.reject(new Error(
|
|
1755
|
+
if (state.cleared) return Promise.reject(new Error(ONCE_MESSAGE_CLEARED));
|
|
1753
1756
|
if (state.finished) return state.error ? Promise.reject(state.value) : Promise.resolve(state.value);
|
|
1754
1757
|
if (state.called) return new Promise((resolve, reject) => {
|
|
1755
1758
|
state.items.push({
|
|
@@ -1764,9 +1767,9 @@ function asyncOnce(callback) {
|
|
|
1764
1767
|
resolve
|
|
1765
1768
|
});
|
|
1766
1769
|
callback(...parameters).then((value) => {
|
|
1767
|
-
|
|
1770
|
+
handleOnceResult(state, value, false);
|
|
1768
1771
|
}).catch((error) => {
|
|
1769
|
-
|
|
1772
|
+
handleOnceResult(state, error, true);
|
|
1770
1773
|
});
|
|
1771
1774
|
});
|
|
1772
1775
|
};
|
|
@@ -1783,7 +1786,7 @@ function asyncOnce(callback) {
|
|
|
1783
1786
|
};
|
|
1784
1787
|
return fn;
|
|
1785
1788
|
}
|
|
1786
|
-
function
|
|
1789
|
+
function handleOnceResult(state, value, error) {
|
|
1787
1790
|
state.error = error;
|
|
1788
1791
|
state.finished = true;
|
|
1789
1792
|
state.value = value;
|
|
@@ -1801,14 +1804,14 @@ function handleResult$2(state, value, error) {
|
|
|
1801
1804
|
* @returns Once callback
|
|
1802
1805
|
*/
|
|
1803
1806
|
function once(callback) {
|
|
1804
|
-
assert(() => typeof callback === "function",
|
|
1807
|
+
assert(() => typeof callback === "function", ONCE_MESSAGE_EXPECTATION);
|
|
1805
1808
|
const state = {
|
|
1806
1809
|
called: false,
|
|
1807
1810
|
cleared: false,
|
|
1808
1811
|
value: void 0
|
|
1809
1812
|
};
|
|
1810
1813
|
const fn = (...parameters) => {
|
|
1811
|
-
if (state.cleared) throw new Error(
|
|
1814
|
+
if (state.cleared) throw new Error(ONCE_MESSAGE_CLEARED);
|
|
1812
1815
|
if (state.called) return state.value;
|
|
1813
1816
|
state.called = true;
|
|
1814
1817
|
state.value = callback(...parameters);
|
|
@@ -1826,15 +1829,15 @@ function once(callback) {
|
|
|
1826
1829
|
return fn;
|
|
1827
1830
|
}
|
|
1828
1831
|
once.async = asyncOnce;
|
|
1829
|
-
const
|
|
1830
|
-
const
|
|
1832
|
+
const ONCE_MESSAGE_CLEARED = "Once has been cleared";
|
|
1833
|
+
const ONCE_MESSAGE_EXPECTATION = "Once expected a function";
|
|
1831
1834
|
//#endregion
|
|
1832
1835
|
//#region src/function/retry.ts
|
|
1833
1836
|
var RetryError = class extends Error {
|
|
1834
1837
|
constructor(message, original) {
|
|
1835
1838
|
super(message);
|
|
1836
1839
|
this.original = original;
|
|
1837
|
-
this.name =
|
|
1840
|
+
this.name = RETRY_ERROR_NAME;
|
|
1838
1841
|
}
|
|
1839
1842
|
};
|
|
1840
1843
|
/**
|
|
@@ -1846,13 +1849,13 @@ var RetryError = class extends Error {
|
|
|
1846
1849
|
* @returns Callback result
|
|
1847
1850
|
*/
|
|
1848
1851
|
async function asyncRetry(callback, options) {
|
|
1849
|
-
if (typeof callback !== "function") throw new TypeError(
|
|
1852
|
+
if (typeof callback !== "function") throw new TypeError(RETRY_MESSAGE_EXPECTATION);
|
|
1850
1853
|
async function handle() {
|
|
1851
1854
|
try {
|
|
1852
1855
|
const result = await callback();
|
|
1853
1856
|
resolver(result);
|
|
1854
1857
|
} catch (error) {
|
|
1855
|
-
if (attempts >= times || !when(error)) rejector(new RetryError(
|
|
1858
|
+
if (attempts >= times || !when(error)) rejector(new RetryError(RETRY_MESSAGE_FAILED, error));
|
|
1856
1859
|
else {
|
|
1857
1860
|
attempts += 1;
|
|
1858
1861
|
timer();
|
|
@@ -1888,7 +1891,7 @@ function getRetryOptions(input) {
|
|
|
1888
1891
|
* @returns Callback result
|
|
1889
1892
|
*/
|
|
1890
1893
|
function retry(callback, options) {
|
|
1891
|
-
if (typeof callback !== "function") throw new TypeError(
|
|
1894
|
+
if (typeof callback !== "function") throw new TypeError(RETRY_MESSAGE_EXPECTATION);
|
|
1892
1895
|
const { times, when } = getRetryOptions(options);
|
|
1893
1896
|
let last;
|
|
1894
1897
|
for (let index = 0; index <= times; index += 1) try {
|
|
@@ -1899,15 +1902,15 @@ function retry(callback, options) {
|
|
|
1899
1902
|
break;
|
|
1900
1903
|
}
|
|
1901
1904
|
}
|
|
1902
|
-
throw new RetryError(
|
|
1905
|
+
throw new RetryError(RETRY_MESSAGE_FAILED, last);
|
|
1903
1906
|
}
|
|
1904
1907
|
retry.async = asyncRetry;
|
|
1905
1908
|
function shouldRetry() {
|
|
1906
1909
|
return true;
|
|
1907
1910
|
}
|
|
1908
|
-
const
|
|
1909
|
-
const
|
|
1910
|
-
const
|
|
1911
|
+
const RETRY_ERROR_NAME = "RetryError";
|
|
1912
|
+
const RETRY_MESSAGE_EXPECTATION = "Retry expected a function";
|
|
1913
|
+
const RETRY_MESSAGE_FAILED = "Retry failed";
|
|
1911
1914
|
//#endregion
|
|
1912
1915
|
//#region src/internal/result.ts
|
|
1913
1916
|
function _isResult(value, okValue) {
|
|
@@ -2023,9 +2026,9 @@ function equalArray(first, second, options) {
|
|
|
2023
2026
|
const { length } = first;
|
|
2024
2027
|
if (length !== second.length) return false;
|
|
2025
2028
|
let offset = 0;
|
|
2026
|
-
if (length >=
|
|
2027
|
-
offset = Math.round(length /
|
|
2028
|
-
offset = offset >
|
|
2029
|
+
if (length >= EQUAL_ARRAY_THRESHOLD) {
|
|
2030
|
+
offset = Math.round(length / EQUAL_ARRAY_PEEK_PERCENTAGE);
|
|
2031
|
+
offset = offset > EQUAL_ARRAY_THRESHOLD ? EQUAL_ARRAY_THRESHOLD : offset;
|
|
2029
2032
|
for (let index = 0; index < offset; index += 1) if (!(equalValue(first[index], second[index], options) && equalValue(first[length - index - 1], second[length - index - 1], options))) return false;
|
|
2030
2033
|
}
|
|
2031
2034
|
const end = length - offset;
|
|
@@ -2160,8 +2163,8 @@ function initializeEqualizer(options) {
|
|
|
2160
2163
|
function registerEqualizer(constructor, handler) {
|
|
2161
2164
|
equal.handlers.register(constructor, handler);
|
|
2162
2165
|
}
|
|
2163
|
-
const
|
|
2164
|
-
const
|
|
2166
|
+
const EQUAL_ARRAY_PEEK_PERCENTAGE = 10;
|
|
2167
|
+
const EQUAL_ARRAY_THRESHOLD = 100;
|
|
2165
2168
|
const ERROR_PROPERTIES = ["name", "message"];
|
|
2166
2169
|
const EXPRESSION_PROPERTIES = ["source", "flags"];
|
|
2167
2170
|
const MINIMUM_LENGTH_FOR_SET = 16;
|
|
@@ -2710,7 +2713,7 @@ function getFuzzyOptions(input, state) {
|
|
|
2710
2713
|
options.tolerance = getTolerance(options.tolerance, state);
|
|
2711
2714
|
return options;
|
|
2712
2715
|
}
|
|
2713
|
-
function
|
|
2716
|
+
function getFuzzyState(items, input) {
|
|
2714
2717
|
const handler = getHandler(input);
|
|
2715
2718
|
const options = getFuzzyOptions(input);
|
|
2716
2719
|
return {
|
|
@@ -2727,7 +2730,7 @@ function getTolerance(input, state) {
|
|
|
2727
2730
|
}
|
|
2728
2731
|
function fuzzy(items, configuration) {
|
|
2729
2732
|
if (!Array.isArray(items)) throw new TypeError(MESSAGE_ARRAY);
|
|
2730
|
-
return new Fuzzy(
|
|
2733
|
+
return new Fuzzy(getFuzzyState(items, configuration));
|
|
2731
2734
|
}
|
|
2732
2735
|
fuzzy.match = fuzzyMatch;
|
|
2733
2736
|
/**
|
|
@@ -3537,7 +3540,6 @@ function initializeMerger(options) {
|
|
|
3537
3540
|
function merge(values, options) {
|
|
3538
3541
|
return handleMerge(values, getMergeOptions(options));
|
|
3539
3542
|
}
|
|
3540
|
-
merge.assign = assign;
|
|
3541
3543
|
merge.initialize = initializeMerger;
|
|
3542
3544
|
function mergeObjects(values, options, prefix) {
|
|
3543
3545
|
const { length } = values;
|
|
@@ -3954,7 +3956,7 @@ function getClampedValue(value, minimum, maximum) {
|
|
|
3954
3956
|
* @returns Foreground color
|
|
3955
3957
|
*/
|
|
3956
3958
|
function getForegroundColor(value) {
|
|
3957
|
-
const { blue, green, red } =
|
|
3959
|
+
const { blue, green, red } = getColorState(value).rgb;
|
|
3958
3960
|
const values = [
|
|
3959
3961
|
blue / 255,
|
|
3960
3962
|
green / 255,
|
|
@@ -3974,7 +3976,7 @@ function getForegroundColor(value) {
|
|
|
3974
3976
|
* @returns Hex color
|
|
3975
3977
|
*/
|
|
3976
3978
|
function getHexaColor(value) {
|
|
3977
|
-
const { alpha, hex } =
|
|
3979
|
+
const { alpha, hex } = getColorState(value);
|
|
3978
3980
|
return `${hex}${alpha.hex}`;
|
|
3979
3981
|
}
|
|
3980
3982
|
/**
|
|
@@ -3983,7 +3985,7 @@ function getHexaColor(value) {
|
|
|
3983
3985
|
* @returns Hex color
|
|
3984
3986
|
*/
|
|
3985
3987
|
function getHexColor(value) {
|
|
3986
|
-
return
|
|
3988
|
+
return getColorState(value).hex;
|
|
3987
3989
|
}
|
|
3988
3990
|
function getHexValue(value) {
|
|
3989
3991
|
return getClampedValue(value, 0, 255);
|
|
@@ -3997,7 +3999,7 @@ function getDegrees(value) {
|
|
|
3997
3999
|
* @returns HSLA color
|
|
3998
4000
|
*/
|
|
3999
4001
|
function getHslaColor(value) {
|
|
4000
|
-
const { alpha, hsl } =
|
|
4002
|
+
const { alpha, hsl } = getColorState(value);
|
|
4001
4003
|
return {
|
|
4002
4004
|
...hsl,
|
|
4003
4005
|
alpha: alpha.value
|
|
@@ -4009,7 +4011,7 @@ function getHslaColor(value) {
|
|
|
4009
4011
|
* @returns HSL color
|
|
4010
4012
|
*/
|
|
4011
4013
|
function getHslColor(value) {
|
|
4012
|
-
return
|
|
4014
|
+
return getColorState(value).hsl;
|
|
4013
4015
|
}
|
|
4014
4016
|
function getPercentage(value) {
|
|
4015
4017
|
return getClampedValue(value, 0, 100);
|
|
@@ -4020,7 +4022,7 @@ function getPercentage(value) {
|
|
|
4020
4022
|
* @returns RGBA color
|
|
4021
4023
|
*/
|
|
4022
4024
|
function getRgbaColor(value) {
|
|
4023
|
-
const { alpha, rgb } =
|
|
4025
|
+
const { alpha, rgb } = getColorState(value);
|
|
4024
4026
|
return {
|
|
4025
4027
|
...rgb,
|
|
4026
4028
|
alpha: alpha.value
|
|
@@ -4032,7 +4034,7 @@ function getRgbaColor(value) {
|
|
|
4032
4034
|
* @returns RGB color
|
|
4033
4035
|
*/
|
|
4034
4036
|
function getRgbColor(value) {
|
|
4035
|
-
return
|
|
4037
|
+
return getColorState(value).rgb;
|
|
4036
4038
|
}
|
|
4037
4039
|
//#endregion
|
|
4038
4040
|
//#region src/color/space/rgb.ts
|
|
@@ -4238,7 +4240,7 @@ function hslToRgba(hsl) {
|
|
|
4238
4240
|
}
|
|
4239
4241
|
//#endregion
|
|
4240
4242
|
//#region src/color/misc/state.ts
|
|
4241
|
-
function
|
|
4243
|
+
function getColorState(value) {
|
|
4242
4244
|
if (typeof value === "string") {
|
|
4243
4245
|
const normalized = getNormalizedHex(value, true);
|
|
4244
4246
|
const hex = normalized.slice(0, 6);
|
|
@@ -4408,7 +4410,7 @@ var Color = class {
|
|
|
4408
4410
|
setRGBColor(this.#state, value, true);
|
|
4409
4411
|
}
|
|
4410
4412
|
constructor(value) {
|
|
4411
|
-
this.#state =
|
|
4413
|
+
this.#state = getColorState(value);
|
|
4412
4414
|
Object.defineProperty(this, "$color", { value: true });
|
|
4413
4415
|
}
|
|
4414
4416
|
toHexString(alpha) {
|
|
@@ -4659,11 +4661,8 @@ const PROMISE_TYPE_FULFILLED = "fulfilled";
|
|
|
4659
4661
|
const PROMISE_TYPE_REJECTED = "rejected";
|
|
4660
4662
|
//#endregion
|
|
4661
4663
|
//#region src/promise/helpers.ts
|
|
4662
|
-
function getNumberOrDefault$1(value) {
|
|
4663
|
-
return typeof value === "number" && value > 0 ? value : 0;
|
|
4664
|
-
}
|
|
4665
4664
|
function getPromiseOptions(input) {
|
|
4666
|
-
if (typeof input === "number") return { time: getNumberOrDefault
|
|
4665
|
+
if (typeof input === "number") return { time: getNumberOrDefault(input, 0) };
|
|
4667
4666
|
if (input instanceof AbortSignal) return {
|
|
4668
4667
|
signal: input,
|
|
4669
4668
|
time: 0
|
|
@@ -4671,7 +4670,7 @@ function getPromiseOptions(input) {
|
|
|
4671
4670
|
const options = typeof input === "object" && input !== null ? input : {};
|
|
4672
4671
|
return {
|
|
4673
4672
|
signal: options.signal instanceof AbortSignal ? options.signal : void 0,
|
|
4674
|
-
time: getNumberOrDefault
|
|
4673
|
+
time: getNumberOrDefault(options.time, 0)
|
|
4675
4674
|
};
|
|
4676
4675
|
}
|
|
4677
4676
|
function getPromisesOptions(input) {
|
|
@@ -5258,11 +5257,11 @@ var Queue = class {
|
|
|
5258
5257
|
if (this.#paused) {
|
|
5259
5258
|
const paused = item;
|
|
5260
5259
|
this.#handled.push(() => {
|
|
5261
|
-
|
|
5260
|
+
handleQueuedResult(paused, error, result, this.#items.length === 0);
|
|
5262
5261
|
});
|
|
5263
5262
|
break;
|
|
5264
5263
|
}
|
|
5265
|
-
|
|
5264
|
+
handleQueuedResult(item, error, result, this.#items.length === 0);
|
|
5266
5265
|
item = this.#items.shift();
|
|
5267
5266
|
}
|
|
5268
5267
|
this.#runners -= 1;
|
|
@@ -5277,18 +5276,15 @@ var QueueError = class extends Error {
|
|
|
5277
5276
|
function getBooleanOrDefault(value, defaultValue) {
|
|
5278
5277
|
return typeof value === "boolean" ? value : defaultValue;
|
|
5279
5278
|
}
|
|
5280
|
-
function getNumberOrDefault(value, defaultValue) {
|
|
5281
|
-
return typeof value === "number" && value > 0 ? Math.floor(value) : defaultValue;
|
|
5282
|
-
}
|
|
5283
5279
|
function getOptions(input) {
|
|
5284
5280
|
const options = typeof input === "object" && input != null ? input : {};
|
|
5285
5281
|
return {
|
|
5286
5282
|
autostart: getBooleanOrDefault(options.autostart, true),
|
|
5287
|
-
concurrency: getNumberOrDefault(options.concurrency, 1),
|
|
5283
|
+
concurrency: getNumberOrDefault(options.concurrency, 1, 1),
|
|
5288
5284
|
maximum: getNumberOrDefault(options.maximum, 0)
|
|
5289
5285
|
};
|
|
5290
5286
|
}
|
|
5291
|
-
function
|
|
5287
|
+
function handleQueuedResult(item, error, result, finished) {
|
|
5292
5288
|
item.signal?.removeEventListener(EVENT_NAME, item.abort);
|
|
5293
5289
|
if (item.signal?.aborted ?? false) item.reject();
|
|
5294
5290
|
else if (error) item.reject(result);
|
|
@@ -22,5 +22,6 @@ declare function clamp(value: number, minimum: number, maximum: number, loop?: b
|
|
|
22
22
|
* @returns Original value as a number, or `NaN` if the value is unable to be parsed
|
|
23
23
|
*/
|
|
24
24
|
declare function getNumber(value: unknown): number;
|
|
25
|
+
declare function getNumberOrDefault(value: unknown, defaultValue: number, minimum?: number): number;
|
|
25
26
|
//#endregion
|
|
26
|
-
export { between, clamp, getNumber };
|
|
27
|
+
export { between, clamp, getNumber, getNumberOrDefault };
|