@oscarpalmer/atoms 0.216.0 → 0.218.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/insert.mjs +1 -1
- package/dist/array/slice.mjs +27 -14
- package/dist/array/sort.mjs +2 -1
- package/dist/array/swap.d.mts +2 -1
- package/dist/color/constants.d.mts +2 -1
- package/dist/color/misc/get.mjs +3 -1
- package/dist/color/space/hex.mjs +1 -1
- package/dist/color/space/rgb.d.mts +1 -0
- package/dist/function/index.mjs +1 -2
- package/dist/function/retry.d.mts +1 -1
- package/dist/function/retry.mjs +5 -2
- package/dist/herald.mjs +1 -2
- package/dist/index.d.mts +335 -113
- package/dist/index.mjs +483 -241
- package/dist/internal/array/find.mjs +57 -34
- package/dist/internal/array/insert.mjs +1 -1
- package/dist/internal/array/match.mjs +21 -17
- package/dist/internal/array/sets.mjs +7 -1
- package/dist/internal/math/aggregate.mjs +4 -1
- package/dist/internal/number.d.mts +1 -1
- package/dist/internal/number.mjs +4 -2
- package/dist/internal/plan/index.d.mts +7 -0
- package/dist/internal/plan/index.mjs +18 -0
- package/dist/{plan/generate.d.mts → internal/plan/plan.generate.d.mts} +2 -2
- package/dist/{plan/generate.mjs → internal/plan/plan.generate.mjs} +7 -7
- package/dist/internal/random.d.mts +6 -0
- package/dist/internal/random.mjs +13 -2
- package/dist/internal/result/attempt.mjs +4 -4
- package/dist/internal/string/misc.mjs +2 -1
- package/dist/internal/subscription.mjs +1 -1
- package/dist/internal/value/equal.mjs +2 -1
- package/dist/internal/value/partial.mjs +3 -1
- package/dist/models/color.model.d.mts +2 -1
- package/dist/models/function/once.model.d.mts +2 -1
- package/dist/models/index.d.mts +2 -1
- package/dist/models/plan.model.d.mts +160 -29
- package/dist/models/plan.model.mjs +15 -5
- package/dist/models/queue.model.d.mts +2 -1
- package/dist/models/result.model.d.mts +2 -1
- package/dist/models/string/string.fuzzy.model.d.mts +1 -1
- package/dist/models/string/string.misc.model.mjs +1 -1
- package/dist/models/value/value.equal.model.d.mts +2 -1
- package/dist/models/value/value.merge.model.d.mts +3 -2
- package/dist/models/value/value.misc.model.d.mts +2 -1
- package/dist/number.mjs +1 -2
- package/dist/plan/index.d.mts +1 -4
- package/dist/plan/index.mjs +14 -15
- package/dist/plan/is.d.mts +59 -3
- package/dist/plan/is.mjs +82 -10
- package/dist/plan/misc.d.mts +51 -3
- package/dist/plan/misc.mjs +47 -30
- package/dist/plan/models.d.mts +2 -2
- package/dist/plan/result.d.mts +15 -3
- package/dist/plan/result.mjs +5 -11
- package/dist/plan/run.d.mts +1 -3
- package/dist/plan/run.mjs +5 -11
- package/dist/plan/use.d.mts +36 -0
- package/dist/plan/use.mjs +69 -0
- package/dist/promise/index.d.mts +6 -4
- package/dist/promise/index.mjs +4 -4
- package/dist/promise/misc.mjs +5 -2
- package/dist/promise/models.mjs +1 -2
- package/dist/promise/timed.mjs +2 -2
- package/dist/queue.mjs +4 -5
- package/dist/random.d.mts +2 -2
- package/dist/random.mjs +3 -3
- package/dist/result/index.mjs +1 -2
- package/dist/result/match.mjs +2 -2
- package/dist/result/misc.mjs +3 -10
- package/dist/result/work/pipe.d.mts +26 -23
- package/dist/result/work/pipe.mjs +7 -3
- package/dist/string/fuzzy.mjs +1 -1
- package/dist/string/index.mjs +1 -1
- package/dist/subscription.mjs +1 -2
- package/dist/value/clone.mjs +1 -1
- package/dist/value/merge.mjs +17 -4
- package/package.json +8 -10
package/dist/array/insert.mjs
CHANGED
|
@@ -2,7 +2,7 @@ import { ARRAY_INSERT_TYPE_INSERT } from "../models/array/array.misc.model.mjs";
|
|
|
2
2
|
import { insertValues } from "../internal/array/insert.mjs";
|
|
3
3
|
//#region src/array/insert.ts
|
|
4
4
|
function insert(array, indexOrItems, items) {
|
|
5
|
-
return insertValues(ARRAY_INSERT_TYPE_INSERT, array, items
|
|
5
|
+
return insertValues(ARRAY_INSERT_TYPE_INSERT, array, items ?? indexOrItems, typeof indexOrItems === "number" ? indexOrItems : array?.length, 0);
|
|
6
6
|
}
|
|
7
7
|
//#endregion
|
|
8
8
|
export { insert };
|
package/dist/array/slice.mjs
CHANGED
|
@@ -8,34 +8,47 @@ function extract(type, array, first, second) {
|
|
|
8
8
|
if (!Array.isArray(array)) return [];
|
|
9
9
|
const { length } = array;
|
|
10
10
|
if (length === 0) return [];
|
|
11
|
-
const
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
}
|
|
18
|
-
const callbacks = second == null ? getArrayCallbacks(first) : getArrayCallbacks(void 0, void 0, first);
|
|
11
|
+
const take = type === ARRAY_SLICE_TAKE;
|
|
12
|
+
return typeof first === "number" ? getSlice(array, length, first, take) : extractSlice(array, length, first, second, take);
|
|
13
|
+
}
|
|
14
|
+
function extractSlice(array, length, first, second, take) {
|
|
15
|
+
const callbacks = getCallbacks(first, second);
|
|
16
|
+
if (callbacks?.bool == null && callbacks?.value == null) return take ? array.slice() : [];
|
|
19
17
|
const isBoolean = callbacks?.bool != null;
|
|
20
|
-
if (callbacks?.bool == null && callbacks?.value == null) return isTake ? array.slice() : [];
|
|
21
18
|
const extracted = [];
|
|
22
19
|
let push = false;
|
|
23
20
|
for (let index = 0; index < length; index += 1) {
|
|
24
21
|
const item = array[index];
|
|
25
|
-
const matches =
|
|
26
|
-
|
|
27
|
-
|
|
22
|
+
const matches = isMatch(item, index, array, callbacks, second, isBoolean);
|
|
23
|
+
const reached = isBoolean ? !matches : matches;
|
|
24
|
+
if (take && reached) break;
|
|
25
|
+
if (push || take) {
|
|
28
26
|
extracted.push(item);
|
|
29
27
|
continue;
|
|
30
28
|
}
|
|
31
|
-
if (
|
|
32
|
-
else if (isBoolean ? !matches : matches) {
|
|
29
|
+
if (reached) {
|
|
33
30
|
push = true;
|
|
34
31
|
if (isBoolean) extracted.push(item);
|
|
35
32
|
}
|
|
36
33
|
}
|
|
37
34
|
return extracted;
|
|
38
35
|
}
|
|
36
|
+
function getCallbacks(first, second) {
|
|
37
|
+
let callbacks;
|
|
38
|
+
if (second == null) callbacks = getArrayCallbacks(first);
|
|
39
|
+
else callbacks = getArrayCallbacks(void 0, void 0, first);
|
|
40
|
+
return callbacks;
|
|
41
|
+
}
|
|
42
|
+
function getSlice(array, length, amount, take) {
|
|
43
|
+
if (Math.abs(amount) >= length) return take ? array.slice() : [];
|
|
44
|
+
if (amount === 0) return take ? [] : array.slice();
|
|
45
|
+
if (take) return amount >= 0 ? array.slice(0, amount) : array.slice(length + amount);
|
|
46
|
+
return amount >= 0 ? array.slice(amount) : array.slice(0, length + amount);
|
|
47
|
+
}
|
|
48
|
+
function isMatch(item, index, array, callbacks, second, isBoolean) {
|
|
49
|
+
if (isBoolean) return callbacks.bool(item, index, array);
|
|
50
|
+
return Object.is(callbacks.value(item, index, array), second);
|
|
51
|
+
}
|
|
39
52
|
function slice(array, first, second) {
|
|
40
53
|
if (!Array.isArray(array) || array.length === 0) return [];
|
|
41
54
|
const firstIsNumber = typeof first === "number";
|
package/dist/array/sort.mjs
CHANGED
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import { isPlainObject } from "../internal/is.mjs";
|
|
2
2
|
import { floor, round } from "../internal/math/misc.mjs";
|
|
3
|
+
import { min } from "../internal/math/aggregate.mjs";
|
|
3
4
|
import { compare } from "../internal/value/compare.mjs";
|
|
4
5
|
import { SORTER_SYMBOL, SORT_DIRECTION_ASCENDING, SORT_DIRECTION_DESCENDING, arrayModifiers } from "../models/array/array.sort.model.mjs";
|
|
5
6
|
//#region src/array/sort.ts
|
|
@@ -106,7 +107,7 @@ function isSortedArray(array) {
|
|
|
106
107
|
let offset = 0;
|
|
107
108
|
if (length >= 100) {
|
|
108
109
|
offset = round(length / 10);
|
|
109
|
-
offset = offset
|
|
110
|
+
offset = min([offset, 100]);
|
|
110
111
|
for (let index = 0; index < offset; index += 1) {
|
|
111
112
|
const [firstItem, firstOffset] = [array[index], array[index + 1]];
|
|
112
113
|
const [secondItem, secondOffset] = [array[length - index - 2], array[length - index - 1]];
|
package/dist/array/swap.d.mts
CHANGED
package/dist/color/misc/get.mjs
CHANGED
|
@@ -5,7 +5,9 @@ import { getColorFromState, getColorState } from "./state.mjs";
|
|
|
5
5
|
import { color } from "../instance.mjs";
|
|
6
6
|
//#region src/color/misc/get.ts
|
|
7
7
|
function getClampedValue(value, minimum, maximum, rounding) {
|
|
8
|
-
|
|
8
|
+
if (typeof value !== "number" || Number.isNaN(value)) return minimum;
|
|
9
|
+
const actual = rounding ?? false ? round(value) : value;
|
|
10
|
+
return clamp(actual, minimum, maximum);
|
|
9
11
|
}
|
|
10
12
|
function getForegroundColor(value, hex) {
|
|
11
13
|
const { blue, green, red } = getColorFromState(getColorState(value), COLOR_TYPE.rgb);
|
package/dist/color/space/hex.mjs
CHANGED
|
@@ -46,7 +46,7 @@ function getHexaColor() {
|
|
|
46
46
|
* @returns Normalized hex color
|
|
47
47
|
*/
|
|
48
48
|
function getNormalizedHex(value, alpha) {
|
|
49
|
-
const includeAlpha = alpha
|
|
49
|
+
const includeAlpha = alpha === true;
|
|
50
50
|
if (!isHexColor(value)) return `${COLOR_DEFAULTS.hexBlack}${includeAlpha ? COLOR_ALPHA.fullHexLong : ""}`;
|
|
51
51
|
const normalized = value.replace(COLOR_EXPRESSION.prefix, "");
|
|
52
52
|
if (normalized.length < COLOR_LENGTHS.hexLong) {
|
|
@@ -52,6 +52,7 @@ export declare function rgbToHsla(rgb: RGBAColor | RGBColor): HSLAColor;
|
|
|
52
52
|
export declare function rgbToHwb(rgb: RGBAColor | RGBColor): HWBColor;
|
|
53
53
|
/**
|
|
54
54
|
* Convert an _RGB(A)_ color to an _HWBA_ color
|
|
55
|
+
|
|
55
56
|
* _If the value is unable to be converted, a black _HWBA_ color will be returned_
|
|
56
57
|
*
|
|
57
58
|
* _Thanks, https://github.com/color-js/color.js/blob/main/src/spaces/hsl.js#L26_
|
package/dist/function/index.mjs
CHANGED
|
@@ -1,2 +1 @@
|
|
|
1
|
-
|
|
2
|
-
export { noop };
|
|
1
|
+
export { noop } from "../internal/function/misc.mjs";
|
|
@@ -20,7 +20,7 @@ declare function asyncRetry<Callback extends GenericAsyncCallback>(callback: Cal
|
|
|
20
20
|
* @param options Retry options
|
|
21
21
|
* @returns Callback result
|
|
22
22
|
*/
|
|
23
|
-
declare function asyncRetry<Callback extends
|
|
23
|
+
declare function asyncRetry<Callback extends GenericAsyncCallback>(callback: Callback, options?: RetryOptions): Promise<ReturnType<Callback>>;
|
|
24
24
|
/**
|
|
25
25
|
* Retry a callback a specified number of times
|
|
26
26
|
*
|
package/dist/function/retry.mjs
CHANGED
|
@@ -18,8 +18,11 @@ async function asyncRetry(callback, options) {
|
|
|
18
18
|
if (typeof callback !== "function") throw new TypeError(RETRY_MESSAGE_EXPECTATION);
|
|
19
19
|
async function handle() {
|
|
20
20
|
const result = await asyncAttempt(async () => callback());
|
|
21
|
-
if (result.ok)
|
|
22
|
-
|
|
21
|
+
if (result.ok) {
|
|
22
|
+
resolver(result.value);
|
|
23
|
+
return;
|
|
24
|
+
}
|
|
25
|
+
if (attempts >= times || !when(result.error)) rejector(new RetryError(RETRY_MESSAGE_FAILED, result.error));
|
|
23
26
|
else {
|
|
24
27
|
attempts += 1;
|
|
25
28
|
limiter.run();
|
package/dist/herald.mjs
CHANGED
|
@@ -1,2 +1 @@
|
|
|
1
|
-
|
|
2
|
-
export { herald, isHerald, isHeraldEvents, isHeraldSubscription };
|
|
1
|
+
export { herald, isHerald, isHeraldEvents, isHeraldSubscription } from "./internal/herald.mjs";
|