@oscarpalmer/atoms 0.184.1 → 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 +1 -2
- package/dist/index.mjs +49 -53
- package/dist/internal/number.d.mts +2 -1
- package/dist/internal/number.mjs +4 -1
- 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/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/value/equal.ts +5 -5
- 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/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
|
*/
|
|
@@ -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
|
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 };
|
package/dist/internal/number.mjs
CHANGED
|
@@ -53,9 +53,12 @@ function getNumber(value) {
|
|
|
53
53
|
if (isBinary || EXPRESSION_OCTAL.test(trimmed)) return Number.parseInt(trimmed.slice(2), isBinary ? 2 : OCTAL_VALUE);
|
|
54
54
|
return Number(trimmed);
|
|
55
55
|
}
|
|
56
|
+
function getNumberOrDefault(value, defaultValue, minimum) {
|
|
57
|
+
return typeof value === "number" && !Number.isNaN(value) && value >= (minimum ?? 0) ? Math.floor(value) : defaultValue;
|
|
58
|
+
}
|
|
56
59
|
const EXPRESSION_BINARY = /^0b[01]+$/i;
|
|
57
60
|
const EXPRESSION_OCTAL = /^0o[0-7]+$/i;
|
|
58
61
|
const EXPRESSION_ZEROISH = /^\s*0+\s*$/;
|
|
59
62
|
const OCTAL_VALUE = 8;
|
|
60
63
|
//#endregion
|
|
61
|
-
export { between, clamp, getNumber };
|
|
64
|
+
export { between, clamp, getNumber, getNumberOrDefault };
|
|
@@ -27,9 +27,9 @@ function equalArray(first, second, options) {
|
|
|
27
27
|
const { length } = first;
|
|
28
28
|
if (length !== second.length) return false;
|
|
29
29
|
let offset = 0;
|
|
30
|
-
if (length >=
|
|
31
|
-
offset = Math.round(length /
|
|
32
|
-
offset = offset >
|
|
30
|
+
if (length >= EQUAL_ARRAY_THRESHOLD) {
|
|
31
|
+
offset = Math.round(length / EQUAL_ARRAY_PEEK_PERCENTAGE);
|
|
32
|
+
offset = offset > EQUAL_ARRAY_THRESHOLD ? EQUAL_ARRAY_THRESHOLD : offset;
|
|
33
33
|
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;
|
|
34
34
|
}
|
|
35
35
|
const end = length - offset;
|
|
@@ -164,8 +164,8 @@ function initializeEqualizer(options) {
|
|
|
164
164
|
function registerEqualizer(constructor, handler) {
|
|
165
165
|
equal.handlers.register(constructor, handler);
|
|
166
166
|
}
|
|
167
|
-
const
|
|
168
|
-
const
|
|
167
|
+
const EQUAL_ARRAY_PEEK_PERCENTAGE = 10;
|
|
168
|
+
const EQUAL_ARRAY_THRESHOLD = 100;
|
|
169
169
|
const ERROR_PROPERTIES = ["name", "message"];
|
|
170
170
|
const EXPRESSION_PROPERTIES = ["source", "flags"];
|
|
171
171
|
const MINIMUM_LENGTH_FOR_SET = 16;
|
package/dist/models.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
|
*/
|
package/dist/promise/helpers.mjs
CHANGED
|
@@ -1,11 +1,9 @@
|
|
|
1
|
+
import { getNumberOrDefault } from "../internal/number.mjs";
|
|
1
2
|
import { error, ok } from "../result/misc.mjs";
|
|
2
3
|
import { PROMISE_STRATEGY_ALL, PROMISE_STRATEGY_DEFAULT, PROMISE_TYPE_FULFILLED, PROMISE_TYPE_REJECTED } from "./models.mjs";
|
|
3
4
|
//#region src/promise/helpers.ts
|
|
4
|
-
function getNumberOrDefault(value) {
|
|
5
|
-
return typeof value === "number" && value > 0 ? value : 0;
|
|
6
|
-
}
|
|
7
5
|
function getPromiseOptions(input) {
|
|
8
|
-
if (typeof input === "number") return { time: getNumberOrDefault(input) };
|
|
6
|
+
if (typeof input === "number") return { time: getNumberOrDefault(input, 0) };
|
|
9
7
|
if (input instanceof AbortSignal) return {
|
|
10
8
|
signal: input,
|
|
11
9
|
time: 0
|
|
@@ -13,7 +11,7 @@ function getPromiseOptions(input) {
|
|
|
13
11
|
const options = typeof input === "object" && input !== null ? input : {};
|
|
14
12
|
return {
|
|
15
13
|
signal: options.signal instanceof AbortSignal ? options.signal : void 0,
|
|
16
|
-
time: getNumberOrDefault(options.time)
|
|
14
|
+
time: getNumberOrDefault(options.time, 0)
|
|
17
15
|
};
|
|
18
16
|
}
|
|
19
17
|
function getPromisesOptions(input) {
|
package/dist/queue.mjs
CHANGED
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import { getNumberOrDefault } from "./internal/number.mjs";
|
|
1
2
|
//#region src/queue.ts
|
|
2
3
|
var KeyedQueue = class {
|
|
3
4
|
#callback;
|
|
@@ -315,11 +316,11 @@ var Queue = class {
|
|
|
315
316
|
if (this.#paused) {
|
|
316
317
|
const paused = item;
|
|
317
318
|
this.#handled.push(() => {
|
|
318
|
-
|
|
319
|
+
handleQueuedResult(paused, error, result, this.#items.length === 0);
|
|
319
320
|
});
|
|
320
321
|
break;
|
|
321
322
|
}
|
|
322
|
-
|
|
323
|
+
handleQueuedResult(item, error, result, this.#items.length === 0);
|
|
323
324
|
item = this.#items.shift();
|
|
324
325
|
}
|
|
325
326
|
this.#runners -= 1;
|
|
@@ -334,18 +335,15 @@ var QueueError = class extends Error {
|
|
|
334
335
|
function getBooleanOrDefault(value, defaultValue) {
|
|
335
336
|
return typeof value === "boolean" ? value : defaultValue;
|
|
336
337
|
}
|
|
337
|
-
function getNumberOrDefault(value, defaultValue) {
|
|
338
|
-
return typeof value === "number" && value > 0 ? Math.floor(value) : defaultValue;
|
|
339
|
-
}
|
|
340
338
|
function getOptions(input) {
|
|
341
339
|
const options = typeof input === "object" && input != null ? input : {};
|
|
342
340
|
return {
|
|
343
341
|
autostart: getBooleanOrDefault(options.autostart, true),
|
|
344
|
-
concurrency: getNumberOrDefault(options.concurrency, 1),
|
|
342
|
+
concurrency: getNumberOrDefault(options.concurrency, 1, 1),
|
|
345
343
|
maximum: getNumberOrDefault(options.maximum, 0)
|
|
346
344
|
};
|
|
347
345
|
}
|
|
348
|
-
function
|
|
346
|
+
function handleQueuedResult(item, error, result, finished) {
|
|
349
347
|
item.signal?.removeEventListener(EVENT_NAME, item.abort);
|
|
350
348
|
if (item.signal?.aborted ?? false) item.reject();
|
|
351
349
|
else if (error) item.reject(result);
|
package/dist/string/fuzzy.mjs
CHANGED
|
@@ -57,7 +57,7 @@ function getFuzzyOptions(input, state) {
|
|
|
57
57
|
options.tolerance = getTolerance(options.tolerance, state);
|
|
58
58
|
return options;
|
|
59
59
|
}
|
|
60
|
-
function
|
|
60
|
+
function getFuzzyState(items, input) {
|
|
61
61
|
const handler = getHandler(input);
|
|
62
62
|
const options = getFuzzyOptions(input);
|
|
63
63
|
return {
|
|
@@ -74,7 +74,7 @@ function getTolerance(input, state) {
|
|
|
74
74
|
}
|
|
75
75
|
function fuzzy(items, configuration) {
|
|
76
76
|
if (!Array.isArray(items)) throw new TypeError(MESSAGE_ARRAY);
|
|
77
|
-
return new Fuzzy(
|
|
77
|
+
return new Fuzzy(getFuzzyState(items, configuration));
|
|
78
78
|
}
|
|
79
79
|
fuzzy.match = fuzzyMatch;
|
|
80
80
|
/**
|
package/dist/value/merge.d.mts
CHANGED
|
@@ -93,7 +93,6 @@ declare function merge<Model extends ArrayOrPlainObject>(values: NestedPartial<M
|
|
|
93
93
|
*/
|
|
94
94
|
declare function merge(values: NestedPartial<ArrayOrPlainObject>[], options?: MergeOptions): ArrayOrPlainObject;
|
|
95
95
|
declare namespace merge {
|
|
96
|
-
var assign: typeof assign;
|
|
97
96
|
var initialize: typeof initializeMerger;
|
|
98
97
|
}
|
|
99
98
|
//#endregion
|
package/dist/value/merge.mjs
CHANGED
|
@@ -61,7 +61,6 @@ function initializeMerger(options) {
|
|
|
61
61
|
function merge(values, options) {
|
|
62
62
|
return handleMerge(values, getMergeOptions(options));
|
|
63
63
|
}
|
|
64
|
-
merge.assign = assign;
|
|
65
64
|
merge.initialize = initializeMerger;
|
|
66
65
|
function mergeObjects(values, options, prefix) {
|
|
67
66
|
const { length } = values;
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@oscarpalmer/atoms",
|
|
3
|
-
"version": "0.184.
|
|
3
|
+
"version": "0.184.2",
|
|
4
4
|
"description": "Atomic utilities for making your JavaScript better.",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"helper",
|
|
@@ -257,7 +257,7 @@
|
|
|
257
257
|
"@types/node": "^25.6",
|
|
258
258
|
"@vitest/coverage-istanbul": "^4.1",
|
|
259
259
|
"eslint": "^10.2",
|
|
260
|
-
"jsdom": "^29.
|
|
260
|
+
"jsdom": "^29.1",
|
|
261
261
|
"tsdown": "^0.21",
|
|
262
262
|
"typescript": "^5.9",
|
|
263
263
|
"vite": "npm:@voidzero-dev/vite-plus-core@latest",
|
package/src/array/single.ts
CHANGED
|
@@ -49,7 +49,7 @@ export function single(array: unknown[], ...parameters: unknown[]): unknown {
|
|
|
49
49
|
const {matched} = findValues(FIND_VALUES_ALL, array, parameters);
|
|
50
50
|
|
|
51
51
|
if (matched.length > 1) {
|
|
52
|
-
throw new Error(
|
|
52
|
+
throw new Error(SINGLE_MESSAGE);
|
|
53
53
|
}
|
|
54
54
|
|
|
55
55
|
return matched[0];
|
|
@@ -59,6 +59,6 @@ export function single(array: unknown[], ...parameters: unknown[]): unknown {
|
|
|
59
59
|
|
|
60
60
|
// #region Variables
|
|
61
61
|
|
|
62
|
-
const
|
|
62
|
+
const SINGLE_MESSAGE = 'Multiple items were found';
|
|
63
63
|
|
|
64
64
|
// #endregion
|
package/src/array/sort.ts
CHANGED
|
@@ -458,9 +458,9 @@ function isSortedArray(array: unknown[], sorters: InternalSorter[]): boolean {
|
|
|
458
458
|
|
|
459
459
|
let offset = 0;
|
|
460
460
|
|
|
461
|
-
if (length >=
|
|
462
|
-
offset = Math.round(length /
|
|
463
|
-
offset = offset >
|
|
461
|
+
if (length >= SORT_THRESHOLD) {
|
|
462
|
+
offset = Math.round(length / SORT_PEEK_PERCENTAGE);
|
|
463
|
+
offset = offset > SORT_THRESHOLD ? SORT_THRESHOLD : offset;
|
|
464
464
|
|
|
465
465
|
for (let index = 0; index < offset; index += 1) {
|
|
466
466
|
const [firstItem, firstOffset] = [array[index], array[index + 1]];
|
|
@@ -560,9 +560,9 @@ sort.is = isSorted;
|
|
|
560
560
|
|
|
561
561
|
// #region Variables
|
|
562
562
|
|
|
563
|
-
const
|
|
563
|
+
const SORT_PEEK_PERCENTAGE = 10;
|
|
564
564
|
|
|
565
|
-
const
|
|
565
|
+
const SORT_THRESHOLD = 100;
|
|
566
566
|
|
|
567
567
|
export const SORT_DIRECTION_ASCENDING: SortDirection = 'ascending';
|
|
568
568
|
|
package/src/color/instance.ts
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import {SPACE_HSL, SPACE_RGB} from './constants';
|
|
2
2
|
import {formatColor} from './misc';
|
|
3
3
|
import {getAlpha} from './misc/alpha';
|
|
4
|
-
import {
|
|
4
|
+
import {getColorState, setHexColor, setHSLColor, setRGBColor} from './misc/state';
|
|
5
5
|
import type {ColorState, HSLAColor, HSLColor, RGBAColor, RGBColor} from './models';
|
|
6
6
|
|
|
7
7
|
// #region Classes
|
|
@@ -118,7 +118,7 @@ export class Color {
|
|
|
118
118
|
}
|
|
119
119
|
|
|
120
120
|
constructor(value: unknown) {
|
|
121
|
-
this.#state =
|
|
121
|
+
this.#state = getColorState(value);
|
|
122
122
|
|
|
123
123
|
Object.defineProperty(this, '$color', {
|
|
124
124
|
value: true,
|
package/src/color/misc/get.ts
CHANGED
|
@@ -17,7 +17,7 @@ import {
|
|
|
17
17
|
} from '../constants';
|
|
18
18
|
import {Color} from '../instance';
|
|
19
19
|
import type {HSLAColor, HSLColor, RGBAColor, RGBColor} from '../models';
|
|
20
|
-
import {
|
|
20
|
+
import {getColorState} from './state';
|
|
21
21
|
|
|
22
22
|
// #region Functions
|
|
23
23
|
|
|
@@ -31,7 +31,7 @@ function getClampedValue(value: unknown, minimum: number, maximum: number): numb
|
|
|
31
31
|
* @returns Foreground color
|
|
32
32
|
*/
|
|
33
33
|
export function getForegroundColor(value: unknown): Color {
|
|
34
|
-
const state =
|
|
34
|
+
const state = getColorState(value);
|
|
35
35
|
const {blue, green, red} = state.rgb;
|
|
36
36
|
|
|
37
37
|
const values = [blue / MAX_HEX, green / MAX_HEX, red / MAX_HEX];
|
|
@@ -63,7 +63,7 @@ export function getForegroundColor(value: unknown): Color {
|
|
|
63
63
|
* @returns Hex color
|
|
64
64
|
*/
|
|
65
65
|
export function getHexaColor(value: unknown): string {
|
|
66
|
-
const {alpha, hex} =
|
|
66
|
+
const {alpha, hex} = getColorState(value);
|
|
67
67
|
|
|
68
68
|
return `${hex}${alpha.hex}`;
|
|
69
69
|
}
|
|
@@ -74,7 +74,7 @@ export function getHexaColor(value: unknown): string {
|
|
|
74
74
|
* @returns Hex color
|
|
75
75
|
*/
|
|
76
76
|
export function getHexColor(value: unknown): string {
|
|
77
|
-
return
|
|
77
|
+
return getColorState(value).hex;
|
|
78
78
|
}
|
|
79
79
|
|
|
80
80
|
export function getHexValue(value: unknown): number {
|
|
@@ -91,7 +91,7 @@ export function getDegrees(value: unknown): number {
|
|
|
91
91
|
* @returns HSLA color
|
|
92
92
|
*/
|
|
93
93
|
export function getHslaColor(value: unknown): HSLAColor {
|
|
94
|
-
const {alpha, hsl} =
|
|
94
|
+
const {alpha, hsl} = getColorState(value);
|
|
95
95
|
|
|
96
96
|
return {
|
|
97
97
|
...hsl,
|
|
@@ -105,7 +105,7 @@ export function getHslaColor(value: unknown): HSLAColor {
|
|
|
105
105
|
* @returns HSL color
|
|
106
106
|
*/
|
|
107
107
|
export function getHslColor(value: unknown): HSLColor {
|
|
108
|
-
return
|
|
108
|
+
return getColorState(value).hsl;
|
|
109
109
|
}
|
|
110
110
|
|
|
111
111
|
export function getPercentage(value: unknown): number {
|
|
@@ -118,7 +118,7 @@ export function getPercentage(value: unknown): number {
|
|
|
118
118
|
* @returns RGBA color
|
|
119
119
|
*/
|
|
120
120
|
export function getRgbaColor(value: unknown): RGBAColor {
|
|
121
|
-
const {alpha, rgb} =
|
|
121
|
+
const {alpha, rgb} = getColorState(value);
|
|
122
122
|
|
|
123
123
|
return {
|
|
124
124
|
...rgb,
|
|
@@ -132,7 +132,7 @@ export function getRgbaColor(value: unknown): RGBAColor {
|
|
|
132
132
|
* @returns RGB color
|
|
133
133
|
*/
|
|
134
134
|
export function getRgbColor(value: unknown): RGBColor {
|
|
135
|
-
return
|
|
135
|
+
return getColorState(value).rgb;
|
|
136
136
|
}
|
|
137
137
|
|
|
138
138
|
// #endregion
|
package/src/color/misc/state.ts
CHANGED
|
@@ -17,7 +17,7 @@ import {isColor, isHexColor, isHslLike, isRgbLike} from './is';
|
|
|
17
17
|
|
|
18
18
|
// #region Functions
|
|
19
19
|
|
|
20
|
-
export function
|
|
20
|
+
export function getColorState(value: unknown): ColorState {
|
|
21
21
|
if (typeof value === 'string') {
|
|
22
22
|
const normalized = getNormalizedHex(value, true);
|
|
23
23
|
const hex = normalized.slice(0, LENGTH_LONG);
|
package/src/function/once.ts
CHANGED
|
@@ -39,7 +39,7 @@ type OnceState<Value> = {
|
|
|
39
39
|
export function asyncOnce<Callback extends GenericAsyncCallback>(
|
|
40
40
|
callback: Callback,
|
|
41
41
|
): OnceAsyncCallback<Callback> {
|
|
42
|
-
assert(() => typeof callback === 'function',
|
|
42
|
+
assert(() => typeof callback === 'function', ONCE_MESSAGE_EXPECTATION);
|
|
43
43
|
|
|
44
44
|
const state: OnceAsyncState<Awaited<ReturnType<Callback>>> = {
|
|
45
45
|
called: false,
|
|
@@ -52,7 +52,7 @@ export function asyncOnce<Callback extends GenericAsyncCallback>(
|
|
|
52
52
|
|
|
53
53
|
const fn = (...parameters: Parameters<Callback>): Promise<Awaited<ReturnType<Callback>>> => {
|
|
54
54
|
if (state.cleared) {
|
|
55
|
-
return Promise.reject(new Error(
|
|
55
|
+
return Promise.reject(new Error(ONCE_MESSAGE_CLEARED));
|
|
56
56
|
}
|
|
57
57
|
|
|
58
58
|
if (state.finished) {
|
|
@@ -72,10 +72,10 @@ export function asyncOnce<Callback extends GenericAsyncCallback>(
|
|
|
72
72
|
|
|
73
73
|
void callback(...parameters)
|
|
74
74
|
.then(value => {
|
|
75
|
-
|
|
75
|
+
handleOnceResult(state, value, false);
|
|
76
76
|
})
|
|
77
77
|
.catch(error => {
|
|
78
|
-
|
|
78
|
+
handleOnceResult(state, error, true);
|
|
79
79
|
});
|
|
80
80
|
});
|
|
81
81
|
};
|
|
@@ -107,7 +107,7 @@ export function asyncOnce<Callback extends GenericAsyncCallback>(
|
|
|
107
107
|
return fn as OnceAsyncCallback<Callback>;
|
|
108
108
|
}
|
|
109
109
|
|
|
110
|
-
function
|
|
110
|
+
function handleOnceResult<Value>(state: OnceAsyncState<Value>, value: unknown, error: boolean): void {
|
|
111
111
|
state.error = error;
|
|
112
112
|
state.finished = true;
|
|
113
113
|
state.value = value as Value;
|
|
@@ -132,7 +132,7 @@ function handleResult<Value>(state: OnceAsyncState<Value>, value: unknown, error
|
|
|
132
132
|
* @returns Once callback
|
|
133
133
|
*/
|
|
134
134
|
export function once<Callback extends GenericCallback>(callback: Callback): OnceCallback<Callback> {
|
|
135
|
-
assert(() => typeof callback === 'function',
|
|
135
|
+
assert(() => typeof callback === 'function', ONCE_MESSAGE_EXPECTATION);
|
|
136
136
|
|
|
137
137
|
const state: OnceState<ReturnType<Callback>> = {
|
|
138
138
|
called: false,
|
|
@@ -142,7 +142,7 @@ export function once<Callback extends GenericCallback>(callback: Callback): Once
|
|
|
142
142
|
|
|
143
143
|
const fn = (...parameters: Parameters<Callback>): ReturnType<Callback> => {
|
|
144
144
|
if (state.cleared) {
|
|
145
|
-
throw new Error(
|
|
145
|
+
throw new Error(ONCE_MESSAGE_CLEARED);
|
|
146
146
|
}
|
|
147
147
|
|
|
148
148
|
if (state.called) {
|
|
@@ -183,8 +183,8 @@ once.async = asyncOnce;
|
|
|
183
183
|
|
|
184
184
|
// #region Variables
|
|
185
185
|
|
|
186
|
-
const
|
|
186
|
+
const ONCE_MESSAGE_CLEARED = 'Once has been cleared';
|
|
187
187
|
|
|
188
|
-
const
|
|
188
|
+
const ONCE_MESSAGE_EXPECTATION = 'Once expected a function';
|
|
189
189
|
|
|
190
190
|
// #endregion
|
package/src/function/retry.ts
CHANGED
|
@@ -11,7 +11,7 @@ export class RetryError extends Error {
|
|
|
11
11
|
) {
|
|
12
12
|
super(message);
|
|
13
13
|
|
|
14
|
-
this.name =
|
|
14
|
+
this.name = RETRY_ERROR_NAME;
|
|
15
15
|
}
|
|
16
16
|
}
|
|
17
17
|
|
|
@@ -64,7 +64,7 @@ async function asyncRetry<Callback extends GenericCallback>(
|
|
|
64
64
|
options?: RetryOptions,
|
|
65
65
|
): Promise<ReturnType<Callback>> {
|
|
66
66
|
if (typeof callback !== 'function') {
|
|
67
|
-
throw new TypeError(
|
|
67
|
+
throw new TypeError(RETRY_MESSAGE_EXPECTATION);
|
|
68
68
|
}
|
|
69
69
|
|
|
70
70
|
async function handle(): Promise<void> {
|
|
@@ -74,7 +74,7 @@ async function asyncRetry<Callback extends GenericCallback>(
|
|
|
74
74
|
resolver(result);
|
|
75
75
|
} catch (error) {
|
|
76
76
|
if (attempts >= times || !when(error)) {
|
|
77
|
-
rejector(new RetryError(
|
|
77
|
+
rejector(new RetryError(RETRY_MESSAGE_FAILED, error));
|
|
78
78
|
} else {
|
|
79
79
|
attempts += 1;
|
|
80
80
|
|
|
@@ -125,7 +125,7 @@ export function retry<Callback extends GenericCallback>(
|
|
|
125
125
|
options?: Omit<RetryOptions, 'delay'>,
|
|
126
126
|
): ReturnType<Callback> {
|
|
127
127
|
if (typeof callback !== 'function') {
|
|
128
|
-
throw new TypeError(
|
|
128
|
+
throw new TypeError(RETRY_MESSAGE_EXPECTATION);
|
|
129
129
|
}
|
|
130
130
|
|
|
131
131
|
const {times, when} = getRetryOptions(options);
|
|
@@ -146,7 +146,7 @@ export function retry<Callback extends GenericCallback>(
|
|
|
146
146
|
}
|
|
147
147
|
}
|
|
148
148
|
|
|
149
|
-
throw new RetryError(
|
|
149
|
+
throw new RetryError(RETRY_MESSAGE_FAILED, last);
|
|
150
150
|
}
|
|
151
151
|
|
|
152
152
|
retry.async = asyncRetry;
|
|
@@ -159,10 +159,10 @@ function shouldRetry(): boolean {
|
|
|
159
159
|
|
|
160
160
|
// #region Variables
|
|
161
161
|
|
|
162
|
-
const
|
|
162
|
+
const RETRY_ERROR_NAME = 'RetryError';
|
|
163
163
|
|
|
164
|
-
const
|
|
164
|
+
const RETRY_MESSAGE_EXPECTATION = 'Retry expected a function';
|
|
165
165
|
|
|
166
|
-
const
|
|
166
|
+
const RETRY_MESSAGE_FAILED = 'Retry failed';
|
|
167
167
|
|
|
168
168
|
// #endregion
|
package/src/internal/number.ts
CHANGED
|
@@ -97,6 +97,12 @@ export function getNumber(value: unknown): number {
|
|
|
97
97
|
return Number(trimmed);
|
|
98
98
|
}
|
|
99
99
|
|
|
100
|
+
export function getNumberOrDefault(value: unknown, defaultValue: number, minimum?: number): number {
|
|
101
|
+
return typeof value === 'number' && !Number.isNaN(value) && value >= (minimum ?? 0)
|
|
102
|
+
? Math.floor(value)
|
|
103
|
+
: defaultValue;
|
|
104
|
+
}
|
|
105
|
+
|
|
100
106
|
// #endregion
|
|
101
107
|
|
|
102
108
|
// #region Variables
|
|
@@ -141,9 +141,9 @@ function equalArray(first: unknown[], second: unknown[], options: Options): bool
|
|
|
141
141
|
|
|
142
142
|
let offset = 0;
|
|
143
143
|
|
|
144
|
-
if (length >=
|
|
145
|
-
offset = Math.round(length /
|
|
146
|
-
offset = offset >
|
|
144
|
+
if (length >= EQUAL_ARRAY_THRESHOLD) {
|
|
145
|
+
offset = Math.round(length / EQUAL_ARRAY_PEEK_PERCENTAGE);
|
|
146
|
+
offset = offset > EQUAL_ARRAY_THRESHOLD ? EQUAL_ARRAY_THRESHOLD : offset;
|
|
147
147
|
|
|
148
148
|
for (let index = 0; index < offset; index += 1) {
|
|
149
149
|
if (
|
|
@@ -438,9 +438,9 @@ export function registerEqualizer<Instance>(
|
|
|
438
438
|
|
|
439
439
|
// #region Variables
|
|
440
440
|
|
|
441
|
-
const
|
|
441
|
+
const EQUAL_ARRAY_PEEK_PERCENTAGE = 10;
|
|
442
442
|
|
|
443
|
-
const
|
|
443
|
+
const EQUAL_ARRAY_THRESHOLD = 100;
|
|
444
444
|
|
|
445
445
|
const ERROR_PROPERTIES: string[] = ['name', 'message'];
|
|
446
446
|
|
package/src/models.ts
CHANGED
|
@@ -19,7 +19,7 @@ export type AsyncCancelableCallback<Callback extends GenericAsyncCallback | Gene
|
|
|
19
19
|
};
|
|
20
20
|
|
|
21
21
|
/**
|
|
22
|
-
* For
|
|
22
|
+
* For matching any `void`, `Date`, primitive, or `RegExp` values
|
|
23
23
|
*
|
|
24
24
|
* (Thanks, type-fest!)
|
|
25
25
|
*/
|
package/src/promise/helpers.ts
CHANGED
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import {getNumberOrDefault} from '../internal/number';
|
|
1
2
|
import type {RequiredKeys} from '../models';
|
|
2
3
|
import {error, ok} from '../result/misc';
|
|
3
4
|
import type {Result} from '../result/models';
|
|
@@ -16,14 +17,10 @@ import {
|
|
|
16
17
|
|
|
17
18
|
// #region Functions
|
|
18
19
|
|
|
19
|
-
function getNumberOrDefault(value: unknown): number {
|
|
20
|
-
return typeof value === 'number' && value > 0 ? value : 0;
|
|
21
|
-
}
|
|
22
|
-
|
|
23
20
|
export function getPromiseOptions(input: unknown): RequiredKeys<PromiseOptions, 'time'> {
|
|
24
21
|
if (typeof input === 'number') {
|
|
25
22
|
return {
|
|
26
|
-
time: getNumberOrDefault(input),
|
|
23
|
+
time: getNumberOrDefault(input, 0),
|
|
27
24
|
};
|
|
28
25
|
}
|
|
29
26
|
|
|
@@ -35,7 +32,7 @@ export function getPromiseOptions(input: unknown): RequiredKeys<PromiseOptions,
|
|
|
35
32
|
|
|
36
33
|
return {
|
|
37
34
|
signal: options.signal instanceof AbortSignal ? options.signal : undefined,
|
|
38
|
-
time: getNumberOrDefault(options.time),
|
|
35
|
+
time: getNumberOrDefault(options.time, 0),
|
|
39
36
|
};
|
|
40
37
|
}
|
|
41
38
|
|
package/src/queue.ts
CHANGED
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import {getNumberOrDefault} from './internal/number';
|
|
1
2
|
import type {GenericAsyncCallback, GenericCallback} from './models';
|
|
2
3
|
|
|
3
4
|
// #region Types
|
|
@@ -471,13 +472,13 @@ class Queue<CallbackParameters extends Parameters<GenericAsyncCallback>, Callbac
|
|
|
471
472
|
const paused = item;
|
|
472
473
|
|
|
473
474
|
this.#handled.push(() => {
|
|
474
|
-
|
|
475
|
+
handleQueuedResult(paused, error, result, this.#items.length === 0);
|
|
475
476
|
});
|
|
476
477
|
|
|
477
478
|
break;
|
|
478
479
|
}
|
|
479
480
|
|
|
480
|
-
|
|
481
|
+
handleQueuedResult(item, error, result, this.#items.length === 0);
|
|
481
482
|
|
|
482
483
|
item = this.#items.shift();
|
|
483
484
|
}
|
|
@@ -554,21 +555,20 @@ function getBooleanOrDefault(value: unknown, defaultValue: boolean): boolean {
|
|
|
554
555
|
return typeof value === 'boolean' ? value : defaultValue;
|
|
555
556
|
}
|
|
556
557
|
|
|
557
|
-
function getNumberOrDefault(value: unknown, defaultValue: number): number {
|
|
558
|
-
return typeof value === 'number' && value > 0 ? Math.floor(value) : defaultValue;
|
|
559
|
-
}
|
|
560
|
-
|
|
561
558
|
function getOptions(input?: QueueOptions): Required<QueueOptions> {
|
|
562
559
|
const options = typeof input === 'object' && input != null ? input : {};
|
|
563
560
|
|
|
564
561
|
return {
|
|
565
562
|
autostart: getBooleanOrDefault(options.autostart, true),
|
|
566
|
-
concurrency: getNumberOrDefault(options.concurrency, 1),
|
|
563
|
+
concurrency: getNumberOrDefault(options.concurrency, 1, 1),
|
|
567
564
|
maximum: getNumberOrDefault(options.maximum, 0),
|
|
568
565
|
};
|
|
569
566
|
}
|
|
570
567
|
|
|
571
|
-
function
|
|
568
|
+
function handleQueuedResult<
|
|
569
|
+
CallbackParameters extends Parameters<GenericAsyncCallback>,
|
|
570
|
+
CallbackResult,
|
|
571
|
+
>(
|
|
572
572
|
item: QueuedItem<CallbackParameters, CallbackResult>,
|
|
573
573
|
error: boolean,
|
|
574
574
|
result: unknown,
|
|
@@ -676,11 +676,11 @@ const STATUS_PAUSED: StatusKey = 'paused';
|
|
|
676
676
|
|
|
677
677
|
export {
|
|
678
678
|
type KeyedQueue,
|
|
679
|
-
type QueueError,
|
|
680
679
|
type Queue,
|
|
681
680
|
type Queued,
|
|
682
|
-
type QueueOptions,
|
|
683
681
|
type QueuedResult,
|
|
682
|
+
type QueueError,
|
|
683
|
+
type QueueOptions,
|
|
684
684
|
};
|
|
685
685
|
|
|
686
686
|
// #endregion
|
package/src/string/fuzzy.ts
CHANGED
|
@@ -184,7 +184,7 @@ function getFuzzyOptions<Item>(
|
|
|
184
184
|
return options as RequiredKeys<FuzzyOptions, 'tolerance'>;
|
|
185
185
|
}
|
|
186
186
|
|
|
187
|
-
function
|
|
187
|
+
function getFuzzyState<Item>(items: Item[], input: unknown): FuzzyState<Item> {
|
|
188
188
|
const handler = getHandler(input);
|
|
189
189
|
const options = getFuzzyOptions(input);
|
|
190
190
|
|
|
@@ -237,7 +237,7 @@ export function fuzzy(items: unknown[], configuration?: unknown): Fuzzy<unknown>
|
|
|
237
237
|
throw new TypeError(MESSAGE_ARRAY);
|
|
238
238
|
}
|
|
239
239
|
|
|
240
|
-
return new Fuzzy(
|
|
240
|
+
return new Fuzzy(getFuzzyState(items, configuration));
|
|
241
241
|
}
|
|
242
242
|
|
|
243
243
|
fuzzy.match = fuzzyMatch;
|