@oscarpalmer/atoms 0.193.1 → 0.195.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/difference.mjs +2 -2
- package/dist/array/index.d.mts +2 -2
- package/dist/array/index.mjs +2 -2
- package/dist/array/intersection.mjs +2 -2
- package/dist/array/move.mjs +1 -1
- package/dist/array/slice.mjs +5 -5
- package/dist/array/sort.d.mts +5 -1
- package/dist/array/sort.mjs +4 -2
- package/dist/array/swap.mjs +1 -1
- package/dist/array/union.mjs +2 -2
- package/dist/beacon.d.mts +8 -1
- package/dist/beacon.mjs +52 -60
- package/dist/color/constants.d.mts +1 -1
- package/dist/color/constants.mjs +3 -5
- package/dist/color/instance.mjs +34 -41
- package/dist/color/misc/format.d.mts +3 -2
- package/dist/color/misc/format.mjs +4 -1
- package/dist/color/misc/is.d.mts +9 -1
- package/dist/color/misc/is.mjs +11 -1
- package/dist/color/misc/state.d.mts +6 -6
- package/dist/color/misc/state.mjs +11 -14
- package/dist/color/models.d.mts +23 -68
- package/dist/color/space/hex.mjs +1 -1
- package/dist/color/space/rgb.mjs +1 -1
- package/dist/function/index.d.mts +1 -2
- package/dist/function/index.mjs +1 -2
- package/dist/function/limit.d.mts +0 -6
- package/dist/function/limit.mjs +2 -2
- package/dist/function/once.d.mts +0 -3
- package/dist/function/once.mjs +17 -14
- package/dist/function/retry.d.mts +1 -24
- package/dist/function/retry.mjs +1 -1
- package/dist/herald.d.mts +2 -72
- package/dist/herald.mjs +2 -92
- package/dist/index.d.mts +3332 -3418
- package/dist/index.mjs +1850 -1870
- package/dist/internal/abort.d.mts +10 -0
- package/dist/internal/abort.mjs +14 -0
- package/dist/internal/array/chunk.mjs +2 -2
- package/dist/internal/array/find.mjs +2 -2
- package/dist/{array → internal/array}/get.d.mts +2 -2
- package/dist/{array → internal/array}/get.mjs +2 -2
- package/dist/{array → internal/array}/match.d.mts +2 -2
- package/dist/{array → internal/array}/match.mjs +15 -15
- package/dist/internal/array/sets.d.mts +4 -4
- package/dist/internal/array/sets.mjs +7 -7
- package/dist/internal/defaults.d.mts +5 -0
- package/dist/internal/defaults.mjs +9 -0
- package/dist/{function → internal/function}/assert.d.mts +2 -2
- package/dist/{function → internal/function}/assert.mjs +4 -4
- package/dist/{function → internal/function}/memoize.d.mts +2 -2
- package/dist/{function → internal/function}/memoize.mjs +22 -35
- package/dist/internal/function/timer.mjs +19 -15
- package/dist/{function → internal/function}/work.d.mts +2 -2
- package/dist/{function → internal/function}/work.mjs +15 -13
- package/dist/internal/herald.d.mts +71 -0
- package/dist/internal/herald.mjs +110 -0
- package/dist/internal/number.d.mts +1 -2
- package/dist/internal/number.mjs +8 -11
- package/dist/internal/{result.d.mts → result/misc.d.mts} +42 -3
- package/dist/internal/result/misc.mjs +51 -0
- package/dist/{result → internal/result}/models.d.mts +2 -2
- package/dist/{sized → internal/sized}/map.d.mts +1 -1
- package/dist/{sized → internal/sized}/map.mjs +2 -2
- package/dist/internal/{sized.d.mts → sized/misc.d.mts} +1 -1
- package/dist/internal/sized/misc.mjs +12 -0
- package/dist/{string → internal/string}/case.d.mts +1 -1
- package/dist/{string → internal/string}/case.mjs +22 -22
- package/dist/internal/{string.d.mts → string/misc.d.mts} +1 -1
- package/dist/internal/{string.mjs → string/misc.mjs} +5 -5
- package/dist/internal/subscription.d.mts +24 -8
- package/dist/internal/subscription.mjs +49 -36
- package/dist/internal/value/compare.mjs +1 -1
- package/dist/internal/value/equal.mjs +6 -6
- package/dist/internal/value/has.d.mts +1 -1
- package/dist/internal/value/misc.d.mts +1 -1
- package/dist/internal/value/misc.mjs +16 -16
- package/dist/internal/value/set.mjs +2 -2
- package/dist/is.mjs +2 -2
- package/dist/logger.mjs +15 -39
- package/dist/promise/constants.d.mts +17 -0
- package/dist/promise/constants.mjs +14 -0
- package/dist/promise/delay.mjs +7 -10
- package/dist/promise/helpers.d.mts +1 -1
- package/dist/promise/helpers.mjs +3 -3
- package/dist/promise/index.d.mts +1 -1
- package/dist/promise/index.mjs +14 -17
- package/dist/promise/misc.d.mts +3 -2
- package/dist/promise/misc.mjs +10 -8
- package/dist/promise/models.d.mts +5 -17
- package/dist/promise/models.mjs +4 -13
- package/dist/promise/timed.mjs +9 -10
- package/dist/query.mjs +16 -16
- package/dist/queue.mjs +104 -120
- package/dist/random.mjs +8 -8
- package/dist/result/index.d.mts +1 -4
- package/dist/result/index.mjs +2 -2
- package/dist/result/match.d.mts +1 -4
- package/dist/result/match.mjs +5 -5
- package/dist/result/misc.d.mts +3 -42
- package/dist/result/misc.mjs +4 -30
- package/dist/result/work/flow.d.mts +1 -4
- package/dist/result/work/flow.mjs +6 -6
- package/dist/result/work/pipe.d.mts +1 -4
- package/dist/result/work/pipe.mjs +5 -5
- package/dist/sized/set.mjs +1 -1
- package/dist/string/fuzzy.mjs +25 -20
- package/dist/string/index.d.mts +1 -1
- package/dist/string/index.mjs +8 -8
- package/dist/string/match.mjs +1 -1
- package/dist/string/normalize.mjs +16 -16
- package/dist/string/template.mjs +3 -3
- package/dist/subscription.d.mts +2 -0
- package/dist/subscription.mjs +2 -0
- package/dist/value/clone.mjs +10 -10
- package/dist/value/diff.mjs +1 -1
- package/dist/value/smush.mjs +3 -3
- package/package.json +35 -14
- package/dist/internal/result.mjs +0 -25
- package/dist/internal/sized.mjs +0 -12
- /package/dist/{result → internal/result}/models.mjs +0 -0
|
@@ -59,7 +59,7 @@ function getDefaultColorState() {
|
|
|
59
59
|
origin: COLOR_TYPE.hex
|
|
60
60
|
};
|
|
61
61
|
}
|
|
62
|
-
function setColorValue(color, state,
|
|
62
|
+
function setColorValue(color, state, changes, type, value, alpha) {
|
|
63
63
|
state.hex = void 0;
|
|
64
64
|
state.hsl = void 0;
|
|
65
65
|
state.hwb = void 0;
|
|
@@ -67,36 +67,33 @@ function setColorValue(color, state, subscriptions, type, value, alpha) {
|
|
|
67
67
|
state.origin = type;
|
|
68
68
|
state[type] = value;
|
|
69
69
|
if (alpha != null) state.alpha = getAlpha(alpha, type === COLOR_TYPE.hex);
|
|
70
|
-
for (const type of COLOR_TYPE.all)
|
|
71
|
-
|
|
72
|
-
if (callbacks != null) for (const callback of callbacks.values()) callback(color[type]);
|
|
73
|
-
}
|
|
74
|
-
for (const callback of subscriptions.values.to.any.values()) callback(color);
|
|
70
|
+
for (const type of COLOR_TYPE.all) if (changes.observed(type)) changes.emit(type, color[type]);
|
|
71
|
+
changes.emit(COLOR_TYPE.wildcard, color);
|
|
75
72
|
}
|
|
76
|
-
function setHexColor(color, state,
|
|
73
|
+
function setHexColor(color, state, changes, value, alpha) {
|
|
77
74
|
if (!isHexColor(value) || !alpha && value === state.hex) return;
|
|
78
75
|
const normalized = getNormalizedHex(value, true);
|
|
79
|
-
setColorValue(color, state,
|
|
76
|
+
setColorValue(color, state, changes, COLOR_TYPE.hex, normalized.slice(0, COLOR_LENGTHS.hexLong), alpha ? normalized.slice(COLOR_LENGTHS.hexLong) : void 0);
|
|
80
77
|
}
|
|
81
|
-
function setHSLColor(color, state,
|
|
78
|
+
function setHSLColor(color, state, changes, value, alpha) {
|
|
82
79
|
if (!isHslLike(value)) return;
|
|
83
|
-
setColorValue(color, state,
|
|
80
|
+
setColorValue(color, state, changes, COLOR_TYPE.hsl, {
|
|
84
81
|
hue: getDegrees(value.hue),
|
|
85
82
|
saturation: getPercentage(value.saturation),
|
|
86
83
|
lightness: getPercentage(value.lightness)
|
|
87
84
|
}, alpha ? value.alpha : void 0);
|
|
88
85
|
}
|
|
89
|
-
function setHWBColor(color, state,
|
|
86
|
+
function setHWBColor(color, state, changes, value, alpha) {
|
|
90
87
|
if (!isHwbLike(value)) return;
|
|
91
|
-
setColorValue(color, state,
|
|
88
|
+
setColorValue(color, state, changes, COLOR_TYPE.hwb, {
|
|
92
89
|
hue: getDegrees(value.hue),
|
|
93
90
|
whiteness: getPercentage(value.whiteness),
|
|
94
91
|
blackness: getPercentage(value.blackness)
|
|
95
92
|
}, alpha ? value.alpha : void 0);
|
|
96
93
|
}
|
|
97
|
-
function setRGBColor(color, state,
|
|
94
|
+
function setRGBColor(color, state, changes, value, alpha) {
|
|
98
95
|
if (!isRgbLike(value)) return;
|
|
99
|
-
setColorValue(color, state,
|
|
96
|
+
setColorValue(color, state, changes, COLOR_TYPE.rgb, {
|
|
100
97
|
red: getHexValue(value.red),
|
|
101
98
|
green: getHexValue(value.green),
|
|
102
99
|
blue: getHexValue(value.blue)
|
package/dist/color/models.d.mts
CHANGED
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import { Subscription } from "../internal/subscription.mjs";
|
|
2
|
-
import {
|
|
2
|
+
import { HeraldEvents } from "../internal/herald.mjs";
|
|
3
|
+
import { COLOR_ALPHA } from "./constants.mjs";
|
|
3
4
|
//#region src/color/models.d.ts
|
|
4
5
|
type Alpha = {
|
|
5
6
|
hex: string;
|
|
@@ -9,6 +10,10 @@ type Alpha = {
|
|
|
9
10
|
* A color that is represented in multiple color formats
|
|
10
11
|
*/
|
|
11
12
|
type Color = {
|
|
13
|
+
/**
|
|
14
|
+
*
|
|
15
|
+
*/
|
|
16
|
+
readonly changes: HeraldEvents<ColorChanges>;
|
|
12
17
|
/**
|
|
13
18
|
* Get the alpha channel _(opacity)_ of the color as a percentage between `0` and `100`
|
|
14
19
|
*
|
|
@@ -134,74 +139,12 @@ type Color = {
|
|
|
134
139
|
*/
|
|
135
140
|
set rgba(value: RGBAColor);
|
|
136
141
|
/**
|
|
137
|
-
* Subscribe to
|
|
138
|
-
*
|
|
139
|
-
* @param key Color property to subscribe to
|
|
140
|
-
* @param callback Callback function for changes
|
|
141
|
-
*/
|
|
142
|
-
subscribe(key: 'alpha', callback: (value: number) => void): Subscription;
|
|
143
|
-
/**
|
|
144
|
-
* Subscribe to hex color changes of the color
|
|
145
|
-
*
|
|
146
|
-
* @param key Color type to subscribe to
|
|
147
|
-
* @param callback Callback function for changes
|
|
148
|
-
*/
|
|
149
|
-
subscribe(key: typeof COLOR_TYPE.hex, callback: (value: string) => void): Subscription;
|
|
150
|
-
/**
|
|
151
|
-
* Subscribe to hex color changes of the color with alpha channel _(opacity)_
|
|
152
|
-
*
|
|
153
|
-
* @param key Color type to subscribe to
|
|
154
|
-
* @param callback Callback function for changes
|
|
155
|
-
*/
|
|
156
|
-
subscribe(key: typeof COLOR_TYPE.hexa, callback: (value: string) => void): Subscription;
|
|
157
|
-
/**
|
|
158
|
-
* Subscribe to _HSL_ color changes of the color
|
|
142
|
+
* Subscribe to value changes for the color
|
|
159
143
|
*
|
|
160
|
-
* @param
|
|
161
|
-
* @param
|
|
144
|
+
* @param callback Callback function
|
|
145
|
+
* @param signal Optional abort signal to cancel the subscription
|
|
162
146
|
*/
|
|
163
|
-
subscribe(
|
|
164
|
-
/**
|
|
165
|
-
* Subscribe to _HSL(A)_ color changes of the color
|
|
166
|
-
*
|
|
167
|
-
* @param key Color type to subscribe to
|
|
168
|
-
* @param callback Callback function for changes
|
|
169
|
-
*/
|
|
170
|
-
subscribe(key: typeof COLOR_TYPE.hsla, callback: (value: HSLAColor) => void): Subscription;
|
|
171
|
-
/**
|
|
172
|
-
* Subscribe to _HWB_ color changes of the color
|
|
173
|
-
*
|
|
174
|
-
* @param key Color type to subscribe to
|
|
175
|
-
* @param callback Callback function for changes
|
|
176
|
-
*/
|
|
177
|
-
subscribe(key: typeof COLOR_TYPE.hwb, callback: (value: HWBColor) => void): Subscription;
|
|
178
|
-
/**
|
|
179
|
-
* Subscribe to _HWB(A)_ color changes of the color
|
|
180
|
-
*
|
|
181
|
-
* @param key Color type to subscribe to
|
|
182
|
-
* @param callback Callback function for changes
|
|
183
|
-
*/
|
|
184
|
-
subscribe(key: typeof COLOR_TYPE.hwba, callback: (value: HWBAColor) => void): Subscription;
|
|
185
|
-
/**
|
|
186
|
-
* Subscribe to _RGB_ color changes of the color
|
|
187
|
-
*
|
|
188
|
-
* @param key Color type to subscribe to
|
|
189
|
-
* @param callback Callback function for changes
|
|
190
|
-
*/
|
|
191
|
-
subscribe(key: typeof COLOR_TYPE.rgb, callback: (value: RGBColor) => void): Subscription;
|
|
192
|
-
/**
|
|
193
|
-
* Subscribe to _RGBA_ color changes of the color
|
|
194
|
-
*
|
|
195
|
-
* @param key Color type to subscribe to
|
|
196
|
-
* @param callback Callback function for changes
|
|
197
|
-
*/
|
|
198
|
-
subscribe(key: typeof COLOR_TYPE.rgba, callback: (value: RGBAColor) => void): Subscription;
|
|
199
|
-
/**
|
|
200
|
-
* Subscribe to any color changes of the color
|
|
201
|
-
*
|
|
202
|
-
* @param callback Callback function for changes
|
|
203
|
-
*/
|
|
204
|
-
subscribe(callback: (value: Color) => void): Subscription;
|
|
147
|
+
subscribe(callback: (value: Color) => void, signal?: AbortSignal): Subscription;
|
|
205
148
|
/**
|
|
206
149
|
* Get the color as a hex string
|
|
207
150
|
*
|
|
@@ -243,6 +186,18 @@ type Color = {
|
|
|
243
186
|
*/
|
|
244
187
|
unsubscribe(): void;
|
|
245
188
|
};
|
|
189
|
+
type ColorChanges = {
|
|
190
|
+
'*': (value: Color) => void;
|
|
191
|
+
alpha: (value: number) => void;
|
|
192
|
+
hex: (value: string) => void;
|
|
193
|
+
hexa: (value: string) => void;
|
|
194
|
+
hsl: (value: HSLColor) => void;
|
|
195
|
+
hsla: (value: HSLAColor) => void;
|
|
196
|
+
hwb: (value: HWBColor) => void;
|
|
197
|
+
hwba: (value: HWBAColor) => void;
|
|
198
|
+
rgb: (value: RGBColor) => void;
|
|
199
|
+
rgba: (value: RGBAColor) => void;
|
|
200
|
+
};
|
|
246
201
|
type ColorWithAlpha = {
|
|
247
202
|
/**
|
|
248
203
|
* Alpha channel _(opacity)_ of the color _(in percentage; 0-100)_
|
|
@@ -332,4 +287,4 @@ type ColorValue = string | HSLColor | HWBColor | RGBColor;
|
|
|
332
287
|
*/
|
|
333
288
|
type ColorValueExtended = ColorValue | HSLAColor | HWBAColor | RGBAColor;
|
|
334
289
|
//#endregion
|
|
335
|
-
export { Alpha, Color, ColorProperty, ColorState, ColorType, ColorTypeExtended, ColorValue, ColorValueExtended, HSLAColor, HSLColor, HWBAColor, HWBColor, RGBAColor, RGBColor };
|
|
290
|
+
export { Alpha, Color, ColorChanges, ColorProperty, ColorState, ColorType, ColorTypeExtended, ColorValue, ColorValueExtended, HSLAColor, HSLColor, HWBAColor, HWBColor, RGBAColor, RGBColor };
|
package/dist/color/space/hex.mjs
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { join } from "../../internal/string.mjs";
|
|
1
|
+
import { join } from "../../internal/string/misc.mjs";
|
|
2
2
|
import { COLOR_ALPHA, COLOR_DEFAULTS, COLOR_EXPRESSION, COLOR_LENGTHS, COLOR_MAX, COLOR_TYPE } from "../constants.mjs";
|
|
3
3
|
import { getHexValue, getPercentage } from "../misc/get.mjs";
|
|
4
4
|
import { isHexColor } from "../misc/is.mjs";
|
package/dist/color/space/rgb.mjs
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { join } from "../../internal/string.mjs";
|
|
1
|
+
import { join } from "../../internal/string/misc.mjs";
|
|
2
2
|
import { COLOR_DEFAULTS, COLOR_MAX, COLOR_TYPE } from "../constants.mjs";
|
|
3
3
|
import { getAlpha, getAlphaValue } from "../misc/alpha.mjs";
|
|
4
4
|
import { getHexValue } from "../misc/get.mjs";
|
package/dist/function/index.mjs
CHANGED
|
@@ -36,9 +36,6 @@ declare function asyncThrottle<Callback extends GenericAsyncCallback | GenericCa
|
|
|
36
36
|
* @returns Debounced callback handler with a `cancel` method
|
|
37
37
|
*/
|
|
38
38
|
declare function debounce<Callback extends GenericCallback>(callback: Callback, time?: number): CancelableCallback<Callback>;
|
|
39
|
-
declare namespace debounce {
|
|
40
|
-
var async: typeof asyncDebounce;
|
|
41
|
-
}
|
|
42
39
|
/**
|
|
43
40
|
* Throttle a function, ensuring it is only called once every `time` milliseconds
|
|
44
41
|
*
|
|
@@ -47,8 +44,5 @@ declare namespace debounce {
|
|
|
47
44
|
* @returns Throttled callback handler with a `cancel` method
|
|
48
45
|
*/
|
|
49
46
|
declare function throttle<Callback extends GenericCallback>(callback: Callback, time?: number): CancelableCallback<Callback>;
|
|
50
|
-
declare namespace throttle {
|
|
51
|
-
var async: typeof asyncThrottle;
|
|
52
|
-
}
|
|
53
47
|
//#endregion
|
|
54
48
|
export { asyncDebounce, asyncThrottle, debounce, throttle };
|
package/dist/function/limit.mjs
CHANGED
|
@@ -42,7 +42,6 @@ function asyncThrottle(callback, time) {
|
|
|
42
42
|
function debounce(callback, time) {
|
|
43
43
|
return getTimer(TIMER_DEBOUNCE, callback, time);
|
|
44
44
|
}
|
|
45
|
-
debounce.async = asyncDebounce;
|
|
46
45
|
/**
|
|
47
46
|
* Throttle a function, ensuring it is only called once every `time` milliseconds
|
|
48
47
|
*
|
|
@@ -53,6 +52,7 @@ debounce.async = asyncDebounce;
|
|
|
53
52
|
function throttle(callback, time) {
|
|
54
53
|
return getTimer(TIMER_THROTTLE, callback, time);
|
|
55
54
|
}
|
|
56
|
-
|
|
55
|
+
Object.defineProperty(debounce, "async", { value: asyncDebounce });
|
|
56
|
+
Object.defineProperty(throttle, "async", { value: asyncThrottle });
|
|
57
57
|
//#endregion
|
|
58
58
|
export { asyncDebounce, asyncThrottle, debounce, throttle };
|
package/dist/function/once.d.mts
CHANGED
|
@@ -16,8 +16,5 @@ declare function asyncOnce<Callback extends GenericAsyncCallback>(callback: Call
|
|
|
16
16
|
* @returns _Once_ callback
|
|
17
17
|
*/
|
|
18
18
|
declare function once<Callback extends GenericCallback>(callback: Callback): OnceCallback<Callback>;
|
|
19
|
-
declare namespace once {
|
|
20
|
-
var async: typeof asyncOnce;
|
|
21
|
-
}
|
|
22
19
|
//#endregion
|
|
23
20
|
export { asyncOnce, once };
|
package/dist/function/once.mjs
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { assert } from "
|
|
1
|
+
import { assert } from "../internal/function/assert.mjs";
|
|
2
2
|
//#region src/function/once.ts
|
|
3
3
|
/**
|
|
4
4
|
* Create an asynchronous function that can only be called once, rejecting or resolving the same result on subsequent calls
|
|
@@ -45,6 +45,7 @@ function asyncOnce(callback) {
|
|
|
45
45
|
enumerable: true,
|
|
46
46
|
get: () => state.called
|
|
47
47
|
},
|
|
48
|
+
clear: { value: () => clearState(state) },
|
|
48
49
|
cleared: {
|
|
49
50
|
enumerable: true,
|
|
50
51
|
get: () => state.cleared
|
|
@@ -58,13 +59,13 @@ function asyncOnce(callback) {
|
|
|
58
59
|
get: () => state.finished
|
|
59
60
|
}
|
|
60
61
|
});
|
|
61
|
-
fn.clear = () => {
|
|
62
|
-
if (!state.called || !state.finished || state.cleared) return;
|
|
63
|
-
state.cleared = true;
|
|
64
|
-
state.value = void 0;
|
|
65
|
-
};
|
|
66
62
|
return fn;
|
|
67
63
|
}
|
|
64
|
+
function clearState(state) {
|
|
65
|
+
if (!state.called || state.cleared) return;
|
|
66
|
+
state.cleared = true;
|
|
67
|
+
state.value = void 0;
|
|
68
|
+
}
|
|
68
69
|
function handleOnceResult(state, value, error) {
|
|
69
70
|
state.error = error;
|
|
70
71
|
state.finished = true;
|
|
@@ -98,18 +99,20 @@ function once(callback) {
|
|
|
98
99
|
return state.value;
|
|
99
100
|
};
|
|
100
101
|
Object.defineProperties(fn, {
|
|
101
|
-
called: {
|
|
102
|
-
|
|
102
|
+
called: {
|
|
103
|
+
enumerable: true,
|
|
104
|
+
get: () => state.called
|
|
105
|
+
},
|
|
106
|
+
clear: { value: () => clearState(state) },
|
|
107
|
+
cleared: {
|
|
108
|
+
enumerable: true,
|
|
109
|
+
get: () => state.cleared
|
|
110
|
+
}
|
|
103
111
|
});
|
|
104
|
-
fn.clear = () => {
|
|
105
|
-
if (!state.called || state.cleared) return;
|
|
106
|
-
state.cleared = true;
|
|
107
|
-
state.value = void 0;
|
|
108
|
-
};
|
|
109
112
|
return fn;
|
|
110
113
|
}
|
|
111
|
-
once.async = asyncOnce;
|
|
112
114
|
const ONCE_MESSAGE_CLEARED = "Once has been cleared";
|
|
113
115
|
const ONCE_MESSAGE_EXPECTATION = "Once expected a function";
|
|
116
|
+
Object.defineProperty(once, "async", { value: asyncOnce });
|
|
114
117
|
//#endregion
|
|
115
118
|
export { asyncOnce, once };
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { GenericCallback } from "../models.mjs";
|
|
2
2
|
//#region src/function/retry.d.ts
|
|
3
3
|
/**
|
|
4
4
|
* An error thrown when a retry fails
|
|
@@ -12,26 +12,6 @@ type RetryOptions = {
|
|
|
12
12
|
times?: number;
|
|
13
13
|
when?: (error: unknown) => boolean;
|
|
14
14
|
};
|
|
15
|
-
/**
|
|
16
|
-
* Retry a callback a specified number of times, with a delay between attempts
|
|
17
|
-
*
|
|
18
|
-
* _Available as `asyncRetry` and `retry.async`_
|
|
19
|
-
*
|
|
20
|
-
* @param callback Callback to retry
|
|
21
|
-
* @param options Retry options
|
|
22
|
-
* @returns Callback result
|
|
23
|
-
*/
|
|
24
|
-
declare function asyncRetry<Callback extends GenericAsyncCallback>(callback: Callback, options?: RetryOptions): Promise<Awaited<ReturnType<Callback>>>;
|
|
25
|
-
/**
|
|
26
|
-
* Retry a callback a specified number of times, with a delay between attempts
|
|
27
|
-
*
|
|
28
|
-
* _Available as `asyncRetry` and `retry.async`_
|
|
29
|
-
*
|
|
30
|
-
* @param callback Callback to retry
|
|
31
|
-
* @param options Retry options
|
|
32
|
-
* @returns Callback result
|
|
33
|
-
*/
|
|
34
|
-
declare function asyncRetry<Callback extends GenericCallback>(callback: Callback, options?: RetryOptions): Promise<ReturnType<Callback>>;
|
|
35
15
|
/**
|
|
36
16
|
* Retry a callback a specified number of times
|
|
37
17
|
*
|
|
@@ -40,8 +20,5 @@ declare function asyncRetry<Callback extends GenericCallback>(callback: Callback
|
|
|
40
20
|
* @returns Callback result
|
|
41
21
|
*/
|
|
42
22
|
declare function retry<Callback extends GenericCallback>(callback: Callback, options?: Omit<RetryOptions, 'delay'>): ReturnType<Callback>;
|
|
43
|
-
declare namespace retry {
|
|
44
|
-
var async: typeof asyncRetry;
|
|
45
|
-
}
|
|
46
23
|
//#endregion
|
|
47
24
|
export { RetryError, RetryOptions, retry };
|
package/dist/function/retry.mjs
CHANGED
|
@@ -78,12 +78,12 @@ function retry(callback, options) {
|
|
|
78
78
|
}
|
|
79
79
|
throw new RetryError(RETRY_MESSAGE_FAILED, last);
|
|
80
80
|
}
|
|
81
|
-
retry.async = asyncRetry;
|
|
82
81
|
function shouldRetry() {
|
|
83
82
|
return true;
|
|
84
83
|
}
|
|
85
84
|
const RETRY_ERROR_NAME = "RetryError";
|
|
86
85
|
const RETRY_MESSAGE_EXPECTATION = "Retry expected a function";
|
|
87
86
|
const RETRY_MESSAGE_FAILED = "Retry failed";
|
|
87
|
+
Object.defineProperty(retry, "async", { value: asyncRetry });
|
|
88
88
|
//#endregion
|
|
89
89
|
export { RetryError, retry };
|
package/dist/herald.d.mts
CHANGED
|
@@ -1,72 +1,2 @@
|
|
|
1
|
-
import {
|
|
2
|
-
|
|
3
|
-
type Events<Map extends Record<string, GenericCallback>> = {
|
|
4
|
-
/**
|
|
5
|
-
* Subscribe to an event with a callback
|
|
6
|
-
*
|
|
7
|
-
* @param event Event name
|
|
8
|
-
* @param callback Callback function
|
|
9
|
-
* @returns Unsubscriber function
|
|
10
|
-
*/
|
|
11
|
-
subscribe<Event extends keyof Map>(event: Event, callback: Map[Event]): Unsubscriber;
|
|
12
|
-
/**
|
|
13
|
-
* Unsubscribe from an event with a callback _(or all callbacks, if no callback is provided)_
|
|
14
|
-
*
|
|
15
|
-
* @param event Event name
|
|
16
|
-
* @param callback Callback function
|
|
17
|
-
* @returns Unsubscriber function
|
|
18
|
-
*/
|
|
19
|
-
unsubscribe<Event extends keyof Map>(event: Event, callback?: Map[Event]): void;
|
|
20
|
-
};
|
|
21
|
-
type Herald<Map extends Record<string, GenericCallback>> = {
|
|
22
|
-
readonly events: Events<Map>;
|
|
23
|
-
/**
|
|
24
|
-
* Remove all event subscribers
|
|
25
|
-
*/
|
|
26
|
-
clear(): void;
|
|
27
|
-
/**
|
|
28
|
-
* Emit an event with parameters
|
|
29
|
-
*
|
|
30
|
-
* @param event Event name
|
|
31
|
-
* @param parameters Event parameters
|
|
32
|
-
*/
|
|
33
|
-
emit<Event extends keyof Map>(event: Event, ...parameters: Parameters<Map[Event]>): void;
|
|
34
|
-
/**
|
|
35
|
-
* Subscribe to an event with a callback
|
|
36
|
-
*
|
|
37
|
-
* @param event Event name
|
|
38
|
-
* @param callback Callback function
|
|
39
|
-
* @returns Unsubscriber function
|
|
40
|
-
*/
|
|
41
|
-
subscribe<Event extends keyof Map>(event: Event, callback: Map[Event]): Unsubscriber;
|
|
42
|
-
/**
|
|
43
|
-
* Unsubscribe from an event with a callback _(or all callbacks, if no callback is provided)_
|
|
44
|
-
*
|
|
45
|
-
* @param event Event name
|
|
46
|
-
* @param callback Callback function
|
|
47
|
-
*/
|
|
48
|
-
unsubscribe<Event extends keyof Map>(event: Event, callback?: Map[Event]): void;
|
|
49
|
-
};
|
|
50
|
-
/**
|
|
51
|
-
* Create a _Herald_ for announcing named events
|
|
52
|
-
*
|
|
53
|
-
* @param names Event names
|
|
54
|
-
* @returns _Herald_ instance
|
|
55
|
-
*/
|
|
56
|
-
declare function herald<Events extends Record<string, GenericCallback>>(names: (keyof Events)[]): Herald<Events>;
|
|
57
|
-
/**
|
|
58
|
-
* Is the value events for a herald?
|
|
59
|
-
*
|
|
60
|
-
* @param value Value to check
|
|
61
|
-
* @returns `true` if the value is events for a herald, otherwise `false`
|
|
62
|
-
*/
|
|
63
|
-
declare function isEvents<Map extends Record<string, GenericCallback> = Record<string, GenericCallback>>(value: unknown): value is Events<Map>;
|
|
64
|
-
/**
|
|
65
|
-
* Is the value a herald?
|
|
66
|
-
*
|
|
67
|
-
* @param value Value to check
|
|
68
|
-
* @returns `true` if the value is a herald, otherwise `false`
|
|
69
|
-
*/
|
|
70
|
-
declare function isHerald<Events extends Record<string, GenericCallback> = Record<string, GenericCallback>>(value: unknown): value is Herald<Events>;
|
|
71
|
-
//#endregion
|
|
72
|
-
export { Events, Herald, herald, isEvents, isHerald };
|
|
1
|
+
import { herald, isHerald, isHeraldEvents, isHeraldSubscription } from "./internal/herald.mjs";
|
|
2
|
+
export { herald, isHerald, isHeraldEvents, isHeraldSubscription };
|
package/dist/herald.mjs
CHANGED
|
@@ -1,92 +1,2 @@
|
|
|
1
|
-
import {
|
|
2
|
-
|
|
3
|
-
function getEvents(herald) {
|
|
4
|
-
const events = {
|
|
5
|
-
subscribe: (event, callback) => herald.subscribe(event, callback),
|
|
6
|
-
unsubscribe: (event, callback) => herald.unsubscribe(event, callback)
|
|
7
|
-
};
|
|
8
|
-
Object.defineProperty(events, KEY_HERALD, {
|
|
9
|
-
enumerable: false,
|
|
10
|
-
value: NAME_EVENTS
|
|
11
|
-
});
|
|
12
|
-
return Object.freeze(events);
|
|
13
|
-
}
|
|
14
|
-
/**
|
|
15
|
-
* Create a _Herald_ for announcing named events
|
|
16
|
-
*
|
|
17
|
-
* @param names Event names
|
|
18
|
-
* @returns _Herald_ instance
|
|
19
|
-
*/
|
|
20
|
-
function herald(names) {
|
|
21
|
-
if (!Array.isArray(names) || names.length === 0 || !names.every((name) => typeof name === "string")) throw new Error(MESSAGE);
|
|
22
|
-
const set = new Set(names);
|
|
23
|
-
const subscribers = /* @__PURE__ */ new Map();
|
|
24
|
-
const instance = {
|
|
25
|
-
clear() {
|
|
26
|
-
subscribers.clear();
|
|
27
|
-
},
|
|
28
|
-
emit(event, ...parameters) {
|
|
29
|
-
const callbacks = subscribers.get(event);
|
|
30
|
-
if (callbacks == null) return;
|
|
31
|
-
for (const callback of callbacks) callback(...parameters);
|
|
32
|
-
},
|
|
33
|
-
subscribe(event, callback) {
|
|
34
|
-
if (!set.has(event) || typeof callback !== "function") return noop;
|
|
35
|
-
let eventSubscribers = subscribers.get(event);
|
|
36
|
-
if (eventSubscribers == null) {
|
|
37
|
-
eventSubscribers = /* @__PURE__ */ new Set();
|
|
38
|
-
subscribers.set(event, eventSubscribers);
|
|
39
|
-
}
|
|
40
|
-
eventSubscribers.add(callback);
|
|
41
|
-
return () => {
|
|
42
|
-
eventSubscribers?.delete(callback);
|
|
43
|
-
};
|
|
44
|
-
},
|
|
45
|
-
unsubscribe(event, callback) {
|
|
46
|
-
if (!set.has(event) || (callback != null ? typeof callback !== "function" : false)) return;
|
|
47
|
-
const eventSubscribers = subscribers.get(event);
|
|
48
|
-
if (eventSubscribers == null) return;
|
|
49
|
-
if (callback == null) eventSubscribers.clear();
|
|
50
|
-
else eventSubscribers.delete(callback);
|
|
51
|
-
if (callback == null || eventSubscribers.size === 0) subscribers.delete(event);
|
|
52
|
-
}
|
|
53
|
-
};
|
|
54
|
-
Object.defineProperties(instance, {
|
|
55
|
-
[KEY_HERALD]: {
|
|
56
|
-
enumerable: false,
|
|
57
|
-
value: NAME_HERALD
|
|
58
|
-
},
|
|
59
|
-
events: {
|
|
60
|
-
enumerable: true,
|
|
61
|
-
value: getEvents(instance)
|
|
62
|
-
}
|
|
63
|
-
});
|
|
64
|
-
return Object.freeze(instance);
|
|
65
|
-
}
|
|
66
|
-
/**
|
|
67
|
-
* Is the value events for a herald?
|
|
68
|
-
*
|
|
69
|
-
* @param value Value to check
|
|
70
|
-
* @returns `true` if the value is events for a herald, otherwise `false`
|
|
71
|
-
*/
|
|
72
|
-
function isEvents(value) {
|
|
73
|
-
return isHeraldInstance(NAME_EVENTS, value);
|
|
74
|
-
}
|
|
75
|
-
/**
|
|
76
|
-
* Is the value a herald?
|
|
77
|
-
*
|
|
78
|
-
* @param value Value to check
|
|
79
|
-
* @returns `true` if the value is a herald, otherwise `false`
|
|
80
|
-
*/
|
|
81
|
-
function isHerald(value) {
|
|
82
|
-
return isHeraldInstance(NAME_HERALD, value);
|
|
83
|
-
}
|
|
84
|
-
function isHeraldInstance(name, value) {
|
|
85
|
-
return typeof value === "object" && value != null && KEY_HERALD in value && value[KEY_HERALD] === name;
|
|
86
|
-
}
|
|
87
|
-
const KEY_HERALD = "$herald";
|
|
88
|
-
const MESSAGE = "Herald requires an array of event names.";
|
|
89
|
-
const NAME_EVENTS = "events";
|
|
90
|
-
const NAME_HERALD = "herald";
|
|
91
|
-
//#endregion
|
|
92
|
-
export { herald, isEvents, isHerald };
|
|
1
|
+
import { herald, isHerald, isHeraldEvents, isHeraldSubscription } from "./internal/herald.mjs";
|
|
2
|
+
export { herald, isHerald, isHeraldEvents, isHeraldSubscription };
|