@oscarpalmer/atoms 0.193.0 → 0.194.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/intersection.mjs +2 -2
- package/dist/array/match.mjs +13 -13
- 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/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/function/assert.mjs +2 -2
- package/dist/function/limit.d.mts +0 -6
- package/dist/function/limit.mjs +2 -2
- package/dist/function/memoize.mjs +19 -32
- package/dist/function/once.d.mts +0 -3
- package/dist/function/once.mjs +16 -13
- package/dist/function/retry.d.mts +1 -24
- package/dist/function/retry.mjs +1 -1
- package/dist/function/work.mjs +13 -11
- package/dist/herald.d.mts +30 -31
- package/dist/herald.mjs +74 -56
- package/dist/index.d.mts +100 -185
- package/dist/index.mjs +680 -702
- 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/internal/array/sets.d.mts +4 -4
- package/dist/internal/array/sets.mjs +7 -7
- package/dist/internal/function/timer.mjs +19 -15
- package/dist/internal/number.mjs +7 -7
- package/dist/internal/result.mjs +3 -3
- package/dist/internal/sized.mjs +4 -4
- package/dist/internal/string.mjs +4 -4
- package/dist/internal/subscription.d.mts +24 -8
- package/dist/internal/subscription.mjs +49 -36
- package/dist/internal/value/equal.mjs +6 -6
- package/dist/internal/value/misc.mjs +14 -14
- package/dist/internal/value/set.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.mjs +1 -1
- package/dist/promise/index.mjs +14 -17
- package/dist/promise/misc.d.mts +2 -1
- package/dist/promise/misc.mjs +8 -7
- package/dist/promise/models.d.mts +4 -16
- package/dist/promise/models.mjs +4 -13
- package/dist/promise/timed.mjs +9 -10
- package/dist/query.mjs +15 -15
- package/dist/queue.mjs +103 -116
- package/dist/random.mjs +7 -7
- package/dist/result/index.d.mts +0 -3
- package/dist/result/index.mjs +1 -1
- package/dist/result/match.d.mts +0 -3
- package/dist/result/match.mjs +4 -4
- package/dist/result/misc.mjs +2 -2
- package/dist/result/work/flow.d.mts +0 -3
- package/dist/result/work/flow.mjs +5 -5
- package/dist/result/work/pipe.d.mts +0 -3
- package/dist/result/work/pipe.mjs +3 -3
- package/dist/string/case.mjs +20 -20
- package/dist/string/fuzzy.mjs +23 -18
- package/dist/string/index.mjs +7 -7
- package/dist/string/normalize.mjs +14 -14
- package/dist/string/template.mjs +2 -2
- package/dist/value/clone.mjs +10 -10
- package/dist/value/smush.mjs +2 -2
- package/package.json +13 -5
- package/src/array/difference.ts +0 -73
- package/src/array/exists.ts +0 -93
- package/src/array/filter.ts +0 -182
- package/src/array/find.ts +0 -183
- package/src/array/first.ts +0 -196
- package/src/array/flatten.ts +0 -20
- package/src/array/from.ts +0 -129
- package/src/array/get.ts +0 -131
- package/src/array/group-by.ts +0 -369
- package/src/array/index.ts +0 -26
- package/src/array/insert.ts +0 -52
- package/src/array/intersection.ts +0 -72
- package/src/array/last.ts +0 -194
- package/src/array/match.ts +0 -436
- package/src/array/move.ts +0 -315
- package/src/array/partition.ts +0 -91
- package/src/array/push.ts +0 -23
- package/src/array/reverse.ts +0 -33
- package/src/array/select.ts +0 -260
- package/src/array/single.ts +0 -93
- package/src/array/slice.ts +0 -335
- package/src/array/sort.ts +0 -607
- package/src/array/splice.ts +0 -106
- package/src/array/swap.ts +0 -322
- package/src/array/to-map.ts +0 -371
- package/src/array/to-record.ts +0 -351
- package/src/array/to-set.ts +0 -80
- package/src/array/toggle.ts +0 -79
- package/src/array/union.ts +0 -72
- package/src/array/unique.ts +0 -67
- package/src/array/update.ts +0 -75
- package/src/beacon.ts +0 -378
- package/src/color/constants.ts +0 -137
- package/src/color/index.ts +0 -83
- package/src/color/instance.ts +0 -162
- package/src/color/misc/alpha.ts +0 -56
- package/src/color/misc/format.ts +0 -29
- package/src/color/misc/get.ts +0 -210
- package/src/color/misc/is.ts +0 -221
- package/src/color/misc/state.ts +0 -243
- package/src/color/models.ts +0 -389
- package/src/color/space/hex.ts +0 -184
- package/src/color/space/hsl.ts +0 -174
- package/src/color/space/hwb.ts +0 -153
- package/src/color/space/rgb.ts +0 -240
- package/src/function/assert.ts +0 -174
- package/src/function/index.ts +0 -2
- package/src/function/limit.ts +0 -83
- package/src/function/memoize.ts +0 -202
- package/src/function/once.ts +0 -200
- package/src/function/retry.ts +0 -175
- package/src/function/work.ts +0 -1007
- package/src/herald.ts +0 -216
- package/src/index.ts +0 -68
- package/src/internal/array/callbacks.ts +0 -46
- package/src/internal/array/chunk.ts +0 -51
- package/src/internal/array/compact.ts +0 -56
- package/src/internal/array/find.ts +0 -200
- package/src/internal/array/group.ts +0 -42
- package/src/internal/array/index-of.ts +0 -182
- package/src/internal/array/insert.ts +0 -80
- package/src/internal/array/overlap.ts +0 -35
- package/src/internal/array/sets.ts +0 -74
- package/src/internal/array/shuffle.ts +0 -33
- package/src/internal/array/update.ts +0 -52
- package/src/internal/function/misc.ts +0 -8
- package/src/internal/function/timer.ts +0 -168
- package/src/internal/is.ts +0 -244
- package/src/internal/math/aggregate.ts +0 -164
- package/src/internal/math/misc.ts +0 -28
- package/src/internal/number.ts +0 -129
- package/src/internal/random.ts +0 -49
- package/src/internal/result.ts +0 -92
- package/src/internal/sized.ts +0 -25
- package/src/internal/string.ts +0 -128
- package/src/internal/subscription.ts +0 -264
- package/src/internal/value/compare.ts +0 -170
- package/src/internal/value/equal.ts +0 -465
- package/src/internal/value/get.ts +0 -57
- package/src/internal/value/handlers.ts +0 -95
- package/src/internal/value/has.ts +0 -118
- package/src/internal/value/misc.ts +0 -125
- package/src/internal/value/partial.ts +0 -46
- package/src/internal/value/set.ts +0 -132
- package/src/is.ts +0 -182
- package/src/logger.ts +0 -230
- package/src/math.ts +0 -281
- package/src/models.ts +0 -286
- package/src/number.ts +0 -1
- package/src/promise/delay.ts +0 -62
- package/src/promise/helpers.ts +0 -96
- package/src/promise/index.ts +0 -300
- package/src/promise/misc.ts +0 -96
- package/src/promise/models.ts +0 -195
- package/src/promise/timed.ts +0 -91
- package/src/query.ts +0 -147
- package/src/queue.ts +0 -814
- package/src/random.ts +0 -125
- package/src/result/index.ts +0 -105
- package/src/result/match.ts +0 -124
- package/src/result/misc.ts +0 -129
- package/src/result/models.ts +0 -83
- package/src/result/work/flow.ts +0 -488
- package/src/result/work/pipe.ts +0 -496
- package/src/sized/map.ts +0 -110
- package/src/sized/set.ts +0 -107
- package/src/string/case.ts +0 -236
- package/src/string/fuzzy.ts +0 -444
- package/src/string/index.ts +0 -199
- package/src/string/match.ts +0 -80
- package/src/string/normalize.ts +0 -205
- package/src/string/template.ts +0 -161
- package/src/value/clone.ts +0 -319
- package/src/value/collection.ts +0 -63
- package/src/value/diff.ts +0 -232
- package/src/value/freeze.ts +0 -322
- package/src/value/handle.ts +0 -3
- package/src/value/index.ts +0 -5
- package/src/value/merge.ts +0 -278
- package/src/value/omit.ts +0 -20
- package/src/value/pick.ts +0 -20
- package/src/value/shake.ts +0 -45
- package/src/value/smush.ts +0 -89
- package/src/value/transform.ts +0 -153
- package/src/value/unsmush.ts +0 -84
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 "../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/function/assert.mjs
CHANGED
|
@@ -40,7 +40,7 @@ function assertCondition(condition, message, error) {
|
|
|
40
40
|
* @param error Error constructor _(defaults to `Error`)_
|
|
41
41
|
*/
|
|
42
42
|
function assertDefined(value, message, error) {
|
|
43
|
-
assert(() => value != null, message ??
|
|
43
|
+
assert(() => value != null, message ?? ASSERT_MESSAGE_VALUE_DEFINED, error);
|
|
44
44
|
}
|
|
45
45
|
/**
|
|
46
46
|
* Creates an _Asserter_ that asserts a value is an instance of a constructor, throwing an error if it is not
|
|
@@ -91,6 +91,6 @@ function assertProperty(path, condition, message, error) {
|
|
|
91
91
|
}, message, error);
|
|
92
92
|
};
|
|
93
93
|
}
|
|
94
|
-
const
|
|
94
|
+
const ASSERT_MESSAGE_VALUE_DEFINED = "Expected value to be defined";
|
|
95
95
|
//#endregion
|
|
96
96
|
export { assert, assertCondition, assertDefined, assertInstanceOf, assertIs, assertProperty };
|
|
@@ -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 };
|
|
@@ -6,7 +6,7 @@ function getMemoizationOptions(input) {
|
|
|
6
6
|
const { cacheKey, cacheSize } = isPlainObject(input) ? input : {};
|
|
7
7
|
return {
|
|
8
8
|
cacheKey: typeof cacheKey === "function" ? cacheKey : void 0,
|
|
9
|
-
cacheSize: typeof cacheSize === "number" && cacheSize > 0 ? cacheSize :
|
|
9
|
+
cacheSize: typeof cacheSize === "number" && cacheSize > 0 ? cacheSize : MEMOIZED_CACHE_SIZE_DEFAULT
|
|
10
10
|
};
|
|
11
11
|
}
|
|
12
12
|
/**
|
|
@@ -17,54 +17,41 @@ function getMemoizationOptions(input) {
|
|
|
17
17
|
* @returns _Memoized_ instance
|
|
18
18
|
*/
|
|
19
19
|
function memoize(callback, options) {
|
|
20
|
-
if (typeof callback !== "function") throw new TypeError(
|
|
21
|
-
const state = {
|
|
20
|
+
if (typeof callback !== "function") throw new TypeError(MEMOIZED_CALLBACK);
|
|
21
|
+
const state = {
|
|
22
|
+
cache: void 0,
|
|
23
|
+
getter: void 0,
|
|
24
|
+
options: getMemoizationOptions(options)
|
|
25
|
+
};
|
|
22
26
|
state.cache = new SizedMap(state.options.cacheSize);
|
|
23
27
|
state.getter = (...parameters) => {
|
|
24
|
-
const key = state.options.cacheKey?.(...parameters) ?? (parameters.length === 1 ? parameters[0] : join(parameters.map(getString),
|
|
28
|
+
const key = state.options.cacheKey?.(...parameters) ?? (parameters.length === 1 ? parameters[0] : join(parameters.map(getString), MEMOIZED_KEY_SEPARATOR));
|
|
25
29
|
if (state.cache.has(key)) return state.cache.get(key);
|
|
26
30
|
const value = callback(...parameters);
|
|
27
|
-
state.cache
|
|
31
|
+
state.cache.set(key, value);
|
|
28
32
|
return value;
|
|
29
33
|
};
|
|
30
34
|
const instance = {
|
|
31
|
-
clear: () =>
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
},
|
|
37
|
-
destroy: () => {
|
|
38
|
-
state.cache?.clear();
|
|
39
|
-
state.cache = void 0;
|
|
40
|
-
state.getter = void 0;
|
|
41
|
-
},
|
|
42
|
-
get: (key) => {
|
|
43
|
-
return state.cache?.get(key);
|
|
44
|
-
},
|
|
45
|
-
has: (key) => {
|
|
46
|
-
return state.cache?.has(key) ?? false;
|
|
47
|
-
},
|
|
48
|
-
run: (...parameters) => {
|
|
49
|
-
if (state.cache == null || state.getter == null) throw new Error(MEMOIZED_ERROR_DESTROYED);
|
|
50
|
-
return state.getter(...parameters);
|
|
51
|
-
}
|
|
35
|
+
clear: () => state.cache.clear(),
|
|
36
|
+
delete: (key) => state.cache.delete(key),
|
|
37
|
+
get: (key) => state.cache.get(key),
|
|
38
|
+
has: (key) => state.cache.has(key),
|
|
39
|
+
run: (...parameters) => state.getter(...parameters)
|
|
52
40
|
};
|
|
53
41
|
Object.defineProperties(instance, {
|
|
54
42
|
maximum: {
|
|
55
43
|
enumerable: true,
|
|
56
|
-
get: () => state.cache
|
|
44
|
+
get: () => state.cache.maximum
|
|
57
45
|
},
|
|
58
46
|
size: {
|
|
59
47
|
enumerable: true,
|
|
60
|
-
get: () => state.cache
|
|
48
|
+
get: () => state.cache.size
|
|
61
49
|
}
|
|
62
50
|
});
|
|
63
51
|
return Object.freeze(instance);
|
|
64
52
|
}
|
|
65
|
-
const
|
|
66
|
-
const
|
|
67
|
-
const
|
|
68
|
-
const SEPARATOR = "_";
|
|
53
|
+
const MEMOIZED_CACHE_SIZE_DEFAULT = 1024;
|
|
54
|
+
const MEMOIZED_CALLBACK = "Memoized requires a callback function";
|
|
55
|
+
const MEMOIZED_KEY_SEPARATOR = "_";
|
|
69
56
|
//#endregion
|
|
70
57
|
export { memoize };
|
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
|
@@ -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/function/work.mjs
CHANGED
|
@@ -15,7 +15,6 @@ function flow(...fns) {
|
|
|
15
15
|
return isOk(value) ? value.value : value;
|
|
16
16
|
}), fns, true);
|
|
17
17
|
}
|
|
18
|
-
flow.async = asyncFlow;
|
|
19
18
|
async function asyncPipe(value, ...pipes) {
|
|
20
19
|
assertPipeFunctions(pipes);
|
|
21
20
|
return asyncWork(value, pipes, false);
|
|
@@ -24,7 +23,6 @@ function pipe(value, ...pipes) {
|
|
|
24
23
|
assertPipeFunctions(pipes);
|
|
25
24
|
return work(value, pipes, false);
|
|
26
25
|
}
|
|
27
|
-
pipe.async = asyncPipe;
|
|
28
26
|
async function asyncWork(initial, functions, flow) {
|
|
29
27
|
const { length } = functions;
|
|
30
28
|
let transformed = unwrapValue(initial);
|
|
@@ -36,10 +34,10 @@ async function asyncWork(initial, functions, flow) {
|
|
|
36
34
|
}
|
|
37
35
|
function unwrapValue(value, flow, nested) {
|
|
38
36
|
if (typeof value === "function") {
|
|
39
|
-
if (nested != null) throw new TypeError(
|
|
37
|
+
if (nested != null) throw new TypeError(WORK_MESSAGE_NESTING);
|
|
40
38
|
return unwrapValue(value(), flow, true);
|
|
41
39
|
}
|
|
42
|
-
if (flow != null && value instanceof Promise) throw new TypeError(flow ?
|
|
40
|
+
if (flow != null && value instanceof Promise) throw new TypeError(flow ? WORK_MESSAGE_FLOW_PROMISE : WORK_MESSAGE_PIPE_PROMISE);
|
|
43
41
|
if (isError(value)) throw value.error;
|
|
44
42
|
return isOk(value) ? value.value : value;
|
|
45
43
|
}
|
|
@@ -52,12 +50,16 @@ function work(initial, functions, flow) {
|
|
|
52
50
|
}
|
|
53
51
|
return transformed;
|
|
54
52
|
}
|
|
55
|
-
const
|
|
56
|
-
const
|
|
57
|
-
const
|
|
58
|
-
const
|
|
59
|
-
const
|
|
60
|
-
const assertFlowFunctions = assert.condition((value) => Array.isArray(value) && value.every((item) => typeof item === "function"),
|
|
61
|
-
const assertPipeFunctions = assert.condition((value) => Array.isArray(value) && value.every((item) => typeof item === "function"),
|
|
53
|
+
const WORK_MESSAGE_FLOW_ARRAY = "Flow expected to receive an array of functions";
|
|
54
|
+
const WORK_MESSAGE_FLOW_PROMISE = "Synchronous Flow received a promise. Use `flow.async` instead.";
|
|
55
|
+
const WORK_MESSAGE_NESTING = "Return values are too deeply nested.";
|
|
56
|
+
const WORK_MESSAGE_PIPE_ARRAY = "Pipe expected to receive an array of functions";
|
|
57
|
+
const WORK_MESSAGE_PIPE_PROMISE = "Synchronous Pipe received a promise. Use `pipe.async` instead.";
|
|
58
|
+
const assertFlowFunctions = assert.condition((value) => Array.isArray(value) && value.every((item) => typeof item === "function"), WORK_MESSAGE_FLOW_ARRAY, TypeError);
|
|
59
|
+
const assertPipeFunctions = assert.condition((value) => Array.isArray(value) && value.every((item) => typeof item === "function"), WORK_MESSAGE_PIPE_ARRAY, TypeError);
|
|
60
|
+
flow.async = asyncFlow;
|
|
61
|
+
pipe.async = asyncPipe;
|
|
62
|
+
Object.defineProperty(flow, "async", { value: asyncFlow });
|
|
63
|
+
Object.defineProperty(pipe, "async", { value: asyncPipe });
|
|
62
64
|
//#endregion
|
|
63
65
|
export { asyncFlow, asyncPipe, flow, pipe };
|
package/dist/herald.d.mts
CHANGED
|
@@ -1,25 +1,8 @@
|
|
|
1
|
-
import { GenericCallback
|
|
1
|
+
import { GenericCallback } from "./models.mjs";
|
|
2
|
+
import { Subscription, SubscriptionProperty } from "./internal/subscription.mjs";
|
|
2
3
|
//#region src/herald.d.ts
|
|
3
|
-
type Events
|
|
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>;
|
|
4
|
+
type Herald<Events extends Record<string, GenericCallback>> = {
|
|
5
|
+
readonly events: HeraldEvents<Events>;
|
|
23
6
|
/**
|
|
24
7
|
* Remove all event subscribers
|
|
25
8
|
*/
|
|
@@ -30,37 +13,46 @@ type Herald<Map extends Record<string, GenericCallback>> = {
|
|
|
30
13
|
* @param event Event name
|
|
31
14
|
* @param parameters Event parameters
|
|
32
15
|
*/
|
|
33
|
-
emit<Event extends keyof
|
|
16
|
+
emit<Event extends keyof Events>(event: Event, ...parameters: Parameters<Events[Event]>): void;
|
|
34
17
|
/**
|
|
35
|
-
*
|
|
18
|
+
* Is the event observed by any subscribers?
|
|
36
19
|
*
|
|
37
20
|
* @param event Event name
|
|
38
|
-
* @
|
|
39
|
-
* @returns Unsubscriber function
|
|
21
|
+
* @returns `true` if the event is observed, otherwise `false`
|
|
40
22
|
*/
|
|
41
|
-
|
|
23
|
+
observed<Event extends keyof Events>(event: Event): boolean;
|
|
42
24
|
/**
|
|
43
|
-
*
|
|
25
|
+
* Subscribe to an event with a callback
|
|
44
26
|
*
|
|
45
27
|
* @param event Event name
|
|
46
28
|
* @param callback Callback function
|
|
29
|
+
* @param signal Optional abort signal to cancel the subscription
|
|
30
|
+
* @returns Subscription instance
|
|
47
31
|
*/
|
|
48
|
-
|
|
32
|
+
subscribe<Event extends keyof Events>(event: Event, callback: Events[Event], signal?: AbortSignal): Subscription;
|
|
33
|
+
};
|
|
34
|
+
type HeraldEvents<Events extends Record<string, GenericCallback>> = { [Key in keyof Events]: Key extends '*' ? never : (callback: Events[Key], signal?: AbortSignal) => void; };
|
|
35
|
+
type HeraldOnCreate<Events extends Record<string, GenericCallback>> = <Event extends keyof Events>(event: Event, callback: Events[Event], subscription: Subscription) => void;
|
|
36
|
+
type HeraldOptions<Events extends Record<string, GenericCallback>> = {
|
|
37
|
+
names: Array<keyof Events>;
|
|
38
|
+
property?: SubscriptionProperty;
|
|
39
|
+
onCreate?: HeraldOnCreate<Events>;
|
|
49
40
|
};
|
|
50
41
|
/**
|
|
51
42
|
* Create a _Herald_ for announcing named events
|
|
52
43
|
*
|
|
53
44
|
* @param names Event names
|
|
45
|
+
* @param property Optional property for subscription identification _(defaults to `$herald`)_
|
|
54
46
|
* @returns _Herald_ instance
|
|
55
47
|
*/
|
|
56
|
-
declare function herald<Events extends Record<string, GenericCallback>>(
|
|
48
|
+
declare function herald<Events extends Record<string, GenericCallback>>(options: HeraldOptions<Events>): Herald<Events>;
|
|
57
49
|
/**
|
|
58
50
|
* Is the value events for a herald?
|
|
59
51
|
*
|
|
60
52
|
* @param value Value to check
|
|
61
53
|
* @returns `true` if the value is events for a herald, otherwise `false`
|
|
62
54
|
*/
|
|
63
|
-
declare function
|
|
55
|
+
declare function isHeraldEvents<Events extends Record<string, GenericCallback> = Record<string, GenericCallback>>(value: unknown): value is HeraldEvents<Events>;
|
|
64
56
|
/**
|
|
65
57
|
* Is the value a herald?
|
|
66
58
|
*
|
|
@@ -68,5 +60,12 @@ declare function isEvents<Map extends Record<string, GenericCallback> = Record<s
|
|
|
68
60
|
* @returns `true` if the value is a herald, otherwise `false`
|
|
69
61
|
*/
|
|
70
62
|
declare function isHerald<Events extends Record<string, GenericCallback> = Record<string, GenericCallback>>(value: unknown): value is Herald<Events>;
|
|
63
|
+
/**
|
|
64
|
+
* Is the value a herald subscription?
|
|
65
|
+
*
|
|
66
|
+
* @param value Value to check
|
|
67
|
+
* @returns `true` if the value is a herald subscription, otherwise `false`
|
|
68
|
+
*/
|
|
69
|
+
declare function isHeraldSubscription(value: unknown): value is Subscription;
|
|
71
70
|
//#endregion
|
|
72
|
-
export {
|
|
71
|
+
export { Herald, HeraldEvents, HeraldOptions, herald, isHerald, isHeraldEvents, isHeraldSubscription };
|