@oscarpalmer/atoms 0.184.1 → 0.185.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/index.d.mts +2 -2
- package/dist/array/index.mjs +2 -2
- package/dist/array/{position.d.mts → match.d.mts} +9 -6
- package/dist/array/{position.mjs → match.mjs} +16 -16
- package/dist/array/move.mjs +1 -1
- package/dist/array/single.mjs +2 -2
- package/dist/array/sort.d.mts +9 -4
- package/dist/array/sort.mjs +6 -6
- package/dist/array/swap.mjs +1 -1
- package/dist/beacon.d.mts +12 -0
- package/dist/beacon.mjs +9 -0
- package/dist/color/instance.d.mts +8 -0
- package/dist/color/instance.mjs +5 -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/color/models.d.mts +30 -0
- package/dist/function/assert.d.mts +29 -8
- package/dist/function/assert.mjs +29 -8
- package/dist/function/memoize.d.mts +3 -0
- package/dist/function/memoize.mjs +3 -0
- package/dist/function/once.mjs +9 -9
- package/dist/function/retry.d.mts +3 -0
- package/dist/function/retry.mjs +11 -8
- package/dist/function/work.mjs +1 -1
- package/dist/index.d.mts +272 -160
- package/dist/index.mjs +279 -216
- package/dist/internal/number.d.mts +2 -1
- package/dist/internal/number.mjs +4 -1
- package/dist/internal/value/compare.d.mts +2 -1
- package/dist/internal/value/equal.d.mts +5 -0
- package/dist/internal/value/equal.mjs +5 -5
- package/dist/internal/value/get.d.mts +2 -2
- package/dist/internal/value/has.d.mts +3 -3
- package/dist/internal/value/has.mjs +1 -1
- package/dist/internal/value/misc.d.mts +2 -2
- package/dist/internal/value/misc.mjs +10 -4
- package/dist/logger.d.mts +11 -0
- package/dist/logger.mjs +11 -0
- package/dist/models.d.mts +1 -1
- package/dist/promise/helpers.mjs +3 -5
- package/dist/promise/index.d.mts +0 -6
- package/dist/promise/models.d.mts +36 -0
- package/dist/promise/models.mjs +6 -0
- package/dist/queue.d.mts +13 -1
- package/dist/queue.mjs +14 -7
- package/dist/result/index.d.mts +0 -8
- package/dist/result/index.mjs +0 -8
- package/dist/result/match.d.mts +4 -4
- package/dist/result/work/flow.d.mts +12 -36
- package/dist/result/work/pipe.d.mts +11 -33
- package/dist/sized/set.d.mts +3 -2
- package/dist/sized/set.mjs +3 -2
- package/dist/string/fuzzy.mjs +2 -2
- package/dist/value/handle.mjs +1 -1
- package/dist/value/merge.d.mts +0 -1
- package/dist/value/merge.mjs +0 -1
- package/dist/value/shake.d.mts +3 -0
- package/dist/value/smush.d.mts +3 -0
- package/dist/value/transform.d.mts +9 -0
- package/dist/value/unsmush.d.mts +3 -0
- package/package.json +3 -3
- package/src/array/difference.ts +4 -0
- package/src/array/from.ts +4 -0
- package/src/array/index.ts +1 -1
- package/src/array/intersection.ts +4 -0
- package/src/array/{position.ts → match.ts} +28 -25
- package/src/array/move.ts +5 -1
- package/src/array/reverse.ts +4 -0
- package/src/array/select.ts +2 -0
- package/src/array/single.ts +2 -2
- package/src/array/sort.ts +14 -9
- package/src/array/swap.ts +5 -1
- package/src/array/toggle.ts +4 -0
- package/src/array/union.ts +4 -0
- package/src/beacon.ts +12 -0
- package/src/color/index.ts +0 -3
- package/src/color/instance.ts +11 -3
- package/src/color/misc/get.ts +8 -8
- package/src/color/misc/state.ts +1 -1
- package/src/color/models.ts +30 -0
- package/src/function/assert.ts +66 -7
- package/src/function/memoize.ts +3 -0
- package/src/function/once.ts +13 -9
- package/src/function/retry.ts +11 -8
- package/src/internal/number.ts +6 -0
- package/src/internal/value/compare.ts +2 -1
- package/src/internal/value/equal.ts +10 -5
- package/src/internal/value/get.ts +2 -2
- package/src/internal/value/has.ts +6 -6
- package/src/internal/value/misc.ts +24 -13
- package/src/logger.ts +11 -0
- package/src/models.ts +1 -1
- package/src/promise/helpers.ts +3 -6
- package/src/promise/index.ts +0 -6
- package/src/promise/models.ts +36 -0
- package/src/queue.ts +23 -11
- package/src/result/index.ts +0 -8
- package/src/result/match.ts +4 -4
- package/src/result/work/flow.ts +12 -36
- package/src/result/work/pipe.ts +11 -33
- package/src/sized/set.ts +4 -3
- package/src/string/fuzzy.ts +2 -2
- package/src/value/merge.ts +0 -1
- package/src/value/shake.ts +3 -0
- package/src/value/smush.ts +3 -0
- package/src/value/transform.ts +9 -0
- package/src/value/unsmush.ts +3 -0
|
@@ -1,6 +1,9 @@
|
|
|
1
1
|
import { GenericCallback } from "../models.mjs";
|
|
2
2
|
|
|
3
3
|
//#region src/function/memoize.d.ts
|
|
4
|
+
/**
|
|
5
|
+
* A memoized function, caching and retrieving results based on the its parameters _(or a custom cache key)_
|
|
6
|
+
*/
|
|
4
7
|
declare class Memoized<Callback extends GenericCallback> {
|
|
5
8
|
#private;
|
|
6
9
|
/**
|
|
@@ -2,6 +2,9 @@ import { isPlainObject } from "../internal/is.mjs";
|
|
|
2
2
|
import { getString, join } from "../internal/string.mjs";
|
|
3
3
|
import { SizedMap } from "../sized/map.mjs";
|
|
4
4
|
//#region src/function/memoize.ts
|
|
5
|
+
/**
|
|
6
|
+
* A memoized function, caching and retrieving results based on the its parameters _(or a custom cache key)_
|
|
7
|
+
*/
|
|
5
8
|
var Memoized = class {
|
|
6
9
|
#state;
|
|
7
10
|
/**
|
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 };
|
|
@@ -1,6 +1,9 @@
|
|
|
1
1
|
import { GenericAsyncCallback, GenericCallback } from "../models.mjs";
|
|
2
2
|
|
|
3
3
|
//#region src/function/retry.d.ts
|
|
4
|
+
/**
|
|
5
|
+
* An error thrown when a retry fails
|
|
6
|
+
*/
|
|
4
7
|
declare class RetryError extends Error {
|
|
5
8
|
readonly original: unknown;
|
|
6
9
|
constructor(message: string, original: unknown);
|
package/dist/function/retry.mjs
CHANGED
|
@@ -1,11 +1,14 @@
|
|
|
1
1
|
import { isPlainObject } from "../internal/is.mjs";
|
|
2
2
|
import { TIMER_WAIT, getTimer } from "../internal/function/timer.mjs";
|
|
3
3
|
//#region src/function/retry.ts
|
|
4
|
+
/**
|
|
5
|
+
* An error thrown when a retry fails
|
|
6
|
+
*/
|
|
4
7
|
var RetryError = class extends Error {
|
|
5
8
|
constructor(message, original) {
|
|
6
9
|
super(message);
|
|
7
10
|
this.original = original;
|
|
8
|
-
this.name =
|
|
11
|
+
this.name = RETRY_ERROR_NAME;
|
|
9
12
|
}
|
|
10
13
|
};
|
|
11
14
|
/**
|
|
@@ -17,13 +20,13 @@ var RetryError = class extends Error {
|
|
|
17
20
|
* @returns Callback result
|
|
18
21
|
*/
|
|
19
22
|
async function asyncRetry(callback, options) {
|
|
20
|
-
if (typeof callback !== "function") throw new TypeError(
|
|
23
|
+
if (typeof callback !== "function") throw new TypeError(RETRY_MESSAGE_EXPECTATION);
|
|
21
24
|
async function handle() {
|
|
22
25
|
try {
|
|
23
26
|
const result = await callback();
|
|
24
27
|
resolver(result);
|
|
25
28
|
} catch (error) {
|
|
26
|
-
if (attempts >= times || !when(error)) rejector(new RetryError(
|
|
29
|
+
if (attempts >= times || !when(error)) rejector(new RetryError(RETRY_MESSAGE_FAILED, error));
|
|
27
30
|
else {
|
|
28
31
|
attempts += 1;
|
|
29
32
|
timer();
|
|
@@ -59,7 +62,7 @@ function getRetryOptions(input) {
|
|
|
59
62
|
* @returns Callback result
|
|
60
63
|
*/
|
|
61
64
|
function retry(callback, options) {
|
|
62
|
-
if (typeof callback !== "function") throw new TypeError(
|
|
65
|
+
if (typeof callback !== "function") throw new TypeError(RETRY_MESSAGE_EXPECTATION);
|
|
63
66
|
const { times, when } = getRetryOptions(options);
|
|
64
67
|
let last;
|
|
65
68
|
for (let index = 0; index <= times; index += 1) try {
|
|
@@ -70,14 +73,14 @@ function retry(callback, options) {
|
|
|
70
73
|
break;
|
|
71
74
|
}
|
|
72
75
|
}
|
|
73
|
-
throw new RetryError(
|
|
76
|
+
throw new RetryError(RETRY_MESSAGE_FAILED, last);
|
|
74
77
|
}
|
|
75
78
|
retry.async = asyncRetry;
|
|
76
79
|
function shouldRetry() {
|
|
77
80
|
return true;
|
|
78
81
|
}
|
|
79
|
-
const
|
|
80
|
-
const
|
|
81
|
-
const
|
|
82
|
+
const RETRY_ERROR_NAME = "RetryError";
|
|
83
|
+
const RETRY_MESSAGE_EXPECTATION = "Retry expected a function";
|
|
84
|
+
const RETRY_MESSAGE_FAILED = "Retry failed";
|
|
82
85
|
//#endregion
|
|
83
86
|
export { RetryError, retry };
|