@oscarpalmer/atoms 0.198.0 → 0.200.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/flatten.d.mts +1 -1
- package/dist/array/from.d.mts +1 -1
- package/dist/array/group-by.d.mts +2 -2
- package/dist/array/sort.d.mts +4 -0
- package/dist/array/to-map.d.mts +2 -2
- package/dist/array/to-record.d.mts +2 -2
- package/dist/beacon.mjs +46 -43
- package/dist/color/instance.mjs +14 -10
- package/dist/function/retry.mjs +6 -8
- package/dist/index.d.mts +153 -53
- package/dist/index.mjs +347 -259
- package/dist/internal/array/compact.d.mts +2 -2
- package/dist/internal/array/find.d.mts +2 -2
- package/dist/internal/array/find.mjs +11 -11
- package/dist/internal/function/memoize.mjs +4 -3
- package/dist/internal/function/timer.mjs +3 -5
- package/dist/internal/herald.mjs +26 -23
- package/dist/internal/subscription.d.mts +72 -16
- package/dist/internal/subscription.mjs +94 -29
- package/dist/internal/value/compare.mjs +2 -2
- package/dist/internal/value/equal.mjs +30 -30
- package/dist/internal/value/handlers.d.mts +3 -3
- package/dist/internal/value/handlers.mjs +6 -6
- package/dist/promise/constants.d.mts +3 -1
- package/dist/promise/constants.mjs +3 -1
- package/dist/promise/delay.mjs +2 -2
- package/dist/promise/helpers.d.mts +4 -5
- package/dist/promise/helpers.mjs +13 -5
- package/dist/promise/index.d.mts +34 -36
- package/dist/promise/index.mjs +28 -23
- package/dist/promise/misc.mjs +2 -2
- package/dist/promise/models.d.mts +7 -6
- package/dist/promise/timed.mjs +2 -2
- package/dist/queue.d.mts +4 -0
- package/dist/queue.mjs +3 -3
- package/dist/string/fuzzy.d.mts +2 -0
- package/dist/string/fuzzy.mjs +20 -18
- package/dist/string/normalize.mjs +12 -12
- package/dist/string/template.mjs +8 -8
- package/dist/subscription.d.mts +2 -2
- package/dist/subscription.mjs +2 -2
- package/dist/value/clone.mjs +13 -13
- package/dist/value/freeze.d.mts +2 -0
- package/dist/value/freeze.mjs +2 -0
- package/dist/value/merge.d.mts +1 -1
- package/dist/value/merge.mjs +7 -6
- package/package.json +4 -4
- package/plugin/index.js +1 -1
package/dist/array/flatten.d.mts
CHANGED
|
@@ -11,6 +11,6 @@ import { NestedArray } from "../models.mjs";
|
|
|
11
11
|
* flatten([1, [2, [3, 4], 5], 6]); // => [1, 2, 3, 4, 5, 6]
|
|
12
12
|
* ```
|
|
13
13
|
*/
|
|
14
|
-
declare function flatten<Item>(array: Item[]): NestedArray<Item
|
|
14
|
+
declare function flatten<Item>(array: Item[]): Array<NestedArray<Item>>;
|
|
15
15
|
//#endregion
|
|
16
16
|
export { flatten };
|
package/dist/array/from.d.mts
CHANGED
|
@@ -62,7 +62,7 @@ declare function times(length: number): number[];
|
|
|
62
62
|
* times(5, index => index * 2); // => [0, 2, 4, 6, 8]
|
|
63
63
|
* ```
|
|
64
64
|
*/
|
|
65
|
-
declare function times<Callback extends (index: number) => unknown>(length: number, callback: Callback): ReturnType<Callback
|
|
65
|
+
declare function times<Callback extends (index: number) => unknown>(length: number, callback: Callback): Array<ReturnType<Callback>>;
|
|
66
66
|
/**
|
|
67
67
|
* Get an array with a specified length, filled with a specified value
|
|
68
68
|
*
|
|
@@ -155,7 +155,7 @@ declare namespace groupBy {
|
|
|
155
155
|
* // }
|
|
156
156
|
* ```
|
|
157
157
|
*/
|
|
158
|
-
declare function groupArraysBy<Item, KeyCallback extends (item: Item, index: number, array: Item[]) => Key, ValueCallback extends (item: Item, index: number, array: Item[]) => unknown>(array: Item[], key: KeyCallback, value: ValueCallback): Record<ReturnType<KeyCallback>, ReturnType<ValueCallback
|
|
158
|
+
declare function groupArraysBy<Item, KeyCallback extends (item: Item, index: number, array: Item[]) => Key, ValueCallback extends (item: Item, index: number, array: Item[]) => unknown>(array: Item[], key: KeyCallback, value: ValueCallback): Record<ReturnType<KeyCallback>, Array<ReturnType<ValueCallback>>>;
|
|
159
159
|
/**
|
|
160
160
|
* Create a record from an array of items using a specific key and value, grouping values into arrays
|
|
161
161
|
*
|
|
@@ -201,7 +201,7 @@ declare function groupArraysBy<Item extends PlainObject, KeyCallback extends (it
|
|
|
201
201
|
* // }
|
|
202
202
|
* ```
|
|
203
203
|
*/
|
|
204
|
-
declare function groupArraysBy<Item extends PlainObject, ItemKey extends keyof Item, ValueCallback extends (item: Item, index: number, array: Item[]) => unknown>(array: Item[], key: ItemKey, value: ValueCallback): Simplify<Record<KeyedValue<Item, ItemKey>, ReturnType<ValueCallback
|
|
204
|
+
declare function groupArraysBy<Item extends PlainObject, ItemKey extends keyof Item, ValueCallback extends (item: Item, index: number, array: Item[]) => unknown>(array: Item[], key: ItemKey, value: ValueCallback): Simplify<Record<KeyedValue<Item, ItemKey>, Array<ReturnType<ValueCallback>>>>;
|
|
205
205
|
/**
|
|
206
206
|
* Create a record from an array of items using a specific key and value, grouping values into arrays
|
|
207
207
|
*
|
package/dist/array/sort.d.mts
CHANGED
|
@@ -172,6 +172,8 @@ declare function initializeSorter<Item>(descending?: boolean): Sorter<Item>;
|
|
|
172
172
|
/**
|
|
173
173
|
* Is the array sorted according to the sorters _(and the optional default direction)_?
|
|
174
174
|
*
|
|
175
|
+
* _Available as `isSorted` and `sort.is`_
|
|
176
|
+
*
|
|
175
177
|
* @param array Array to check
|
|
176
178
|
* @param sorters Sorters to determine sorting
|
|
177
179
|
* @param descending Sorted in descending order? _(defaults to `false`; overridden by individual sorters)_
|
|
@@ -181,6 +183,8 @@ declare function isSorted<Item>(array: Item[], sorters: Array<ArraySorter<Item>>
|
|
|
181
183
|
/**
|
|
182
184
|
* Is the array sorted according to the sorter _(and the optional default direction)_?
|
|
183
185
|
*
|
|
186
|
+
* _Available as `isSorted` and `sort.is`_
|
|
187
|
+
*
|
|
184
188
|
* @param array Array to check
|
|
185
189
|
* @param sorter Sorter to determine sorting
|
|
186
190
|
* @param descending Sorted in descending order? _(defaults to `false`; overridden by individual sorters)_
|
package/dist/array/to-map.d.mts
CHANGED
|
@@ -152,7 +152,7 @@ declare namespace toMap {
|
|
|
152
152
|
* ); // => Map { 10 => [1, 3], 20 => [2] }
|
|
153
153
|
* ```
|
|
154
154
|
*/
|
|
155
|
-
declare function toMapArrays<Item, KeyCallback extends (item: Item, index: number, array: Item[]) => Key, ValueCallback extends (item: Item, index: number, array: Item[]) => unknown>(array: Item[], key: KeyCallback, value: ValueCallback): Map<ReturnType<KeyCallback>, ReturnType<ValueCallback
|
|
155
|
+
declare function toMapArrays<Item, KeyCallback extends (item: Item, index: number, array: Item[]) => Key, ValueCallback extends (item: Item, index: number, array: Item[]) => unknown>(array: Item[], key: KeyCallback, value: ValueCallback): Map<ReturnType<KeyCallback>, Array<ReturnType<ValueCallback>>>;
|
|
156
156
|
/**
|
|
157
157
|
* Create a _Map_ from an array of items using a callback and value, grouping values into arrays
|
|
158
158
|
*
|
|
@@ -192,7 +192,7 @@ declare function toMapArrays<Item extends PlainObject, KeyCallback extends (item
|
|
|
192
192
|
* ); // => Map { 10 => [1, 3], 20 => [2] }
|
|
193
193
|
* ```
|
|
194
194
|
*/
|
|
195
|
-
declare function toMapArrays<Item extends PlainObject, ItemKey extends keyof Item, ValueCallback extends (item: Item, index: number, array: Item[]) => unknown>(array: Item[], key: ItemKey, value: ValueCallback): Map<Item[ItemKey], ReturnType<ValueCallback
|
|
195
|
+
declare function toMapArrays<Item extends PlainObject, ItemKey extends keyof Item, ValueCallback extends (item: Item, index: number, array: Item[]) => unknown>(array: Item[], key: ItemKey, value: ValueCallback): Map<Item[ItemKey], Array<ReturnType<ValueCallback>>>;
|
|
196
196
|
/**
|
|
197
197
|
* Create a _Map_ from an array of items using a key and value, grouping values into arrays
|
|
198
198
|
*
|
|
@@ -152,7 +152,7 @@ declare namespace toRecord {
|
|
|
152
152
|
* ); // => { 10: [1, 3], 20: [2] }
|
|
153
153
|
* ```
|
|
154
154
|
*/
|
|
155
|
-
declare function toRecordArrays<Item, KeyCallback extends (item: Item, index: number, array: Item[]) => Key, ValueCallback extends (item: Item, index: number, array: Item[]) => unknown>(array: Item[], key: KeyCallback, value: ValueCallback): Record<ReturnType<KeyCallback>, ReturnType<ValueCallback
|
|
155
|
+
declare function toRecordArrays<Item, KeyCallback extends (item: Item, index: number, array: Item[]) => Key, ValueCallback extends (item: Item, index: number, array: Item[]) => unknown>(array: Item[], key: KeyCallback, value: ValueCallback): Record<ReturnType<KeyCallback>, Array<ReturnType<ValueCallback>>>;
|
|
156
156
|
/**
|
|
157
157
|
* Create a record from an array of items using a callback and value, grouping values into arrays
|
|
158
158
|
*
|
|
@@ -192,7 +192,7 @@ declare function toRecordArrays<Item extends PlainObject, Callback extends (item
|
|
|
192
192
|
* ); // => { 10: [1, 3], 20: [2] }
|
|
193
193
|
* ```
|
|
194
194
|
*/
|
|
195
|
-
declare function toRecordArrays<Item extends PlainObject, ItemKey extends keyof Item, Callback extends (item: Item, index: number, array: Item[]) => unknown>(array: Item[], key: ItemKey, callback: Callback): Simplify<Record<KeyedValue<Item, ItemKey>, ReturnType<Callback
|
|
195
|
+
declare function toRecordArrays<Item extends PlainObject, ItemKey extends keyof Item, Callback extends (item: Item, index: number, array: Item[]) => unknown>(array: Item[], key: ItemKey, callback: Callback): Simplify<Record<KeyedValue<Item, ItemKey>, Array<ReturnType<Callback>>>>;
|
|
196
196
|
/**
|
|
197
197
|
* Create a record from an array of items using a key and value, grouping values into arrays
|
|
198
198
|
*
|
package/dist/beacon.mjs
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { noop } from "./internal/function/misc.mjs";
|
|
2
2
|
import { isPlainObject } from "./internal/is.mjs";
|
|
3
|
-
import {
|
|
3
|
+
import { SUBSCRIPTION_NAME, isSubscription, subscriptions } from "./internal/subscription.mjs";
|
|
4
4
|
//#region src/beacon.ts
|
|
5
5
|
/**
|
|
6
6
|
* Create a new beacon
|
|
@@ -14,8 +14,8 @@ function beacon(value, options) {
|
|
|
14
14
|
value,
|
|
15
15
|
active: true,
|
|
16
16
|
observable: void 0,
|
|
17
|
-
options:
|
|
18
|
-
subscriptions:
|
|
17
|
+
options: createBeaconOptions(options),
|
|
18
|
+
subscriptions: subscriptions({ property: beaconSubscription })
|
|
19
19
|
};
|
|
20
20
|
const instance = {
|
|
21
21
|
deactivate: () => finishBeacon(state, false),
|
|
@@ -40,28 +40,32 @@ function beacon(value, options) {
|
|
|
40
40
|
});
|
|
41
41
|
return Object.freeze(instance);
|
|
42
42
|
}
|
|
43
|
-
function
|
|
44
|
-
if (!state.active) return;
|
|
45
|
-
state.active = false;
|
|
46
|
-
for (const [, observer] of state.subscriptions.state.values.to.any) if (emit) observer.complete?.();
|
|
47
|
-
state.subscriptions.clear();
|
|
48
|
-
state.observable?.deactivate();
|
|
49
|
-
state.observable = void 0;
|
|
50
|
-
}
|
|
51
|
-
function getBeaconOptions(input) {
|
|
43
|
+
function createBeaconOptions(input) {
|
|
52
44
|
const options = isPlainObject(input) ? input : {};
|
|
53
45
|
options.equal = typeof options.equal === "function" ? options.equal : Object.is;
|
|
54
46
|
return options;
|
|
55
47
|
}
|
|
56
|
-
function
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
}
|
|
61
|
-
|
|
62
|
-
|
|
48
|
+
function createObservable(beacon) {
|
|
49
|
+
const state = {
|
|
50
|
+
beacon,
|
|
51
|
+
active: beacon.active
|
|
52
|
+
};
|
|
53
|
+
const instance = {
|
|
54
|
+
deactivate: () => {
|
|
55
|
+
state.active = false;
|
|
56
|
+
},
|
|
57
|
+
subscribe: (first, second, third) => subscribeToObservable(state, first, second, third)
|
|
58
|
+
};
|
|
59
|
+
Object.defineProperties(instance, {
|
|
60
|
+
[BEACON_PROPERTY]: { value: BEACON_OBSERVABLE },
|
|
61
|
+
active: {
|
|
62
|
+
enumerable: true,
|
|
63
|
+
get: () => beacon.active && state.active
|
|
64
|
+
}
|
|
65
|
+
});
|
|
66
|
+
return Object.freeze(instance);
|
|
63
67
|
}
|
|
64
|
-
function
|
|
68
|
+
function createObserver(first, second, third) {
|
|
65
69
|
let observer = { next: noop };
|
|
66
70
|
if (typeof first === "function") observer = {
|
|
67
71
|
error: getObservableCallback(second),
|
|
@@ -75,6 +79,22 @@ function getObserver(first, second, third) {
|
|
|
75
79
|
}
|
|
76
80
|
return observer;
|
|
77
81
|
}
|
|
82
|
+
function finishBeacon(state, emit) {
|
|
83
|
+
if (!state.active) return;
|
|
84
|
+
state.active = false;
|
|
85
|
+
for (const [, observer] of state.subscriptions.values.to.any) if (emit) observer.complete?.();
|
|
86
|
+
state.subscriptions.clear();
|
|
87
|
+
state.observable?.deactivate();
|
|
88
|
+
state.observable = void 0;
|
|
89
|
+
}
|
|
90
|
+
function getObservable(state) {
|
|
91
|
+
if (!state.active) throw new Error(BEACON_MESSAGE_RETRIEVE);
|
|
92
|
+
state.observable ??= createObservable(state);
|
|
93
|
+
return state.observable;
|
|
94
|
+
}
|
|
95
|
+
function getObservableCallback(value) {
|
|
96
|
+
return typeof value === "function" ? value : noop;
|
|
97
|
+
}
|
|
78
98
|
/**
|
|
79
99
|
* Is the value a beacon?
|
|
80
100
|
*
|
|
@@ -105,29 +125,9 @@ function isBeaconSubscription(value) {
|
|
|
105
125
|
function isObservable(value) {
|
|
106
126
|
return isBeaconInstance(BEACON_OBSERVABLE, value);
|
|
107
127
|
}
|
|
108
|
-
function observeBeacon(beacon) {
|
|
109
|
-
const state = {
|
|
110
|
-
beacon,
|
|
111
|
-
active: beacon.active
|
|
112
|
-
};
|
|
113
|
-
const instance = {
|
|
114
|
-
deactivate: () => {
|
|
115
|
-
state.active = false;
|
|
116
|
-
},
|
|
117
|
-
subscribe: (first, second, third) => subscribeToObservable(state, first, second, third)
|
|
118
|
-
};
|
|
119
|
-
Object.defineProperties(instance, {
|
|
120
|
-
[BEACON_PROPERTY]: { value: BEACON_OBSERVABLE },
|
|
121
|
-
active: {
|
|
122
|
-
enumerable: true,
|
|
123
|
-
get: () => beacon.active && state.active
|
|
124
|
-
}
|
|
125
|
-
});
|
|
126
|
-
return Object.freeze(instance);
|
|
127
|
-
}
|
|
128
128
|
function subscribeToObservable(state, first, second, third) {
|
|
129
129
|
if (!state.beacon.active || !state.active) throw new Error(BEACON_MESSAGE_SUBSCRIBE);
|
|
130
|
-
const observer =
|
|
130
|
+
const observer = createObserver(first, second, third);
|
|
131
131
|
const [subscription] = state.beacon.subscriptions.create({
|
|
132
132
|
isActive: () => state.beacon.active && state.active,
|
|
133
133
|
value: observer
|
|
@@ -141,7 +141,7 @@ function updateBeacon(type, state, value, finish) {
|
|
|
141
141
|
if (state.options.equal(state.value, value)) return;
|
|
142
142
|
state.value = value;
|
|
143
143
|
}
|
|
144
|
-
for (const [, observer] of state.subscriptions.
|
|
144
|
+
for (const [, observer] of state.subscriptions.values.to.any) observer[type]?.(value);
|
|
145
145
|
if (finish === true) finishBeacon(state, true);
|
|
146
146
|
}
|
|
147
147
|
const BEACON_MESSAGE_RETRIEVE = "Cannot retrieve observable from a closed beacon";
|
|
@@ -151,6 +151,9 @@ const BEACON_NAME = "beacon";
|
|
|
151
151
|
const BEACON_OBSERVABLE = "observable";
|
|
152
152
|
const BEACON_TYPE_ERROR = "error";
|
|
153
153
|
const BEACON_TYPE_NEXT = "next";
|
|
154
|
-
const beaconSubscription = {
|
|
154
|
+
const beaconSubscription = {
|
|
155
|
+
key: BEACON_PROPERTY,
|
|
156
|
+
value: SUBSCRIPTION_NAME
|
|
157
|
+
};
|
|
155
158
|
//#endregion
|
|
156
159
|
export { beacon, isBeacon, isBeaconSubscription, isObservable };
|
package/dist/color/instance.mjs
CHANGED
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import { SUBSCRIPTION_NAME } from "../internal/subscription.mjs";
|
|
1
2
|
import { herald } from "../internal/herald.mjs";
|
|
2
3
|
import { COLOR_PROPERTY, COLOR_TYPE } from "./constants.mjs";
|
|
3
4
|
import { getAlpha } from "./misc/alpha.mjs";
|
|
@@ -31,22 +32,22 @@ function color(value) {
|
|
|
31
32
|
enumerable: true,
|
|
32
33
|
value: changes.events
|
|
33
34
|
},
|
|
34
|
-
hex:
|
|
35
|
-
hexa:
|
|
36
|
-
hsl:
|
|
37
|
-
hsla:
|
|
38
|
-
hwb:
|
|
39
|
-
hwba:
|
|
35
|
+
hex: createColorProperty(COLOR_TYPE.hex, instance, state, changes, false),
|
|
36
|
+
hexa: createColorProperty(COLOR_TYPE.hex, instance, state, changes, true),
|
|
37
|
+
hsl: createColorProperty(COLOR_TYPE.hsl, instance, state, changes, false),
|
|
38
|
+
hsla: createColorProperty(COLOR_TYPE.hsl, instance, state, changes, true),
|
|
39
|
+
hwb: createColorProperty(COLOR_TYPE.hwb, instance, state, changes, false),
|
|
40
|
+
hwba: createColorProperty(COLOR_TYPE.hwb, instance, state, changes, true),
|
|
40
41
|
origin: {
|
|
41
42
|
enumerable: true,
|
|
42
43
|
get: () => state.origin
|
|
43
44
|
},
|
|
44
|
-
rgb:
|
|
45
|
-
rgba:
|
|
45
|
+
rgb: createColorProperty(COLOR_TYPE.rgb, instance, state, changes, false),
|
|
46
|
+
rgba: createColorProperty(COLOR_TYPE.rgb, instance, state, changes, true)
|
|
46
47
|
});
|
|
47
48
|
return Object.freeze(instance);
|
|
48
49
|
}
|
|
49
|
-
function
|
|
50
|
+
function createColorProperty(space, color, state, changes, alpha) {
|
|
50
51
|
const setValue = setters[space];
|
|
51
52
|
return {
|
|
52
53
|
enumerable: true,
|
|
@@ -71,7 +72,10 @@ function onCreateSubscription(instance, event, callback) {
|
|
|
71
72
|
function setAlphaValue(state, value) {
|
|
72
73
|
if (typeof value === "number" && !Number.isNaN(value)) state.alpha = getAlpha(value, false);
|
|
73
74
|
}
|
|
74
|
-
const colorSubscription = {
|
|
75
|
+
const colorSubscription = {
|
|
76
|
+
key: COLOR_PROPERTY.name,
|
|
77
|
+
value: SUBSCRIPTION_NAME
|
|
78
|
+
};
|
|
75
79
|
const setters = {
|
|
76
80
|
hex: setHexColor,
|
|
77
81
|
hsl: setHSLColor,
|
package/dist/function/retry.mjs
CHANGED
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import { isPlainObject } from "../internal/is.mjs";
|
|
2
|
+
import { getNumberOrDefault } from "../internal/defaults.mjs";
|
|
2
3
|
import { TIMER_WAIT, getTimer } from "../internal/function/timer.mjs";
|
|
3
4
|
//#region src/function/retry.ts
|
|
4
5
|
/**
|
|
@@ -35,7 +36,7 @@ async function asyncRetry(callback, options) {
|
|
|
35
36
|
}
|
|
36
37
|
}
|
|
37
38
|
}
|
|
38
|
-
const { delay, times, when } =
|
|
39
|
+
const { delay, times, when } = createRetryOptions(options);
|
|
39
40
|
const timer = getTimer(TIMER_WAIT, handle, delay);
|
|
40
41
|
let attempts = 0;
|
|
41
42
|
let rejector;
|
|
@@ -46,14 +47,11 @@ async function asyncRetry(callback, options) {
|
|
|
46
47
|
handle();
|
|
47
48
|
});
|
|
48
49
|
}
|
|
49
|
-
function
|
|
50
|
-
return typeof value === "number" && value > 0 ? value : 0;
|
|
51
|
-
}
|
|
52
|
-
function getRetryOptions(input) {
|
|
50
|
+
function createRetryOptions(input) {
|
|
53
51
|
const options = isPlainObject(input) ? input : {};
|
|
54
52
|
return {
|
|
55
|
-
delay:
|
|
56
|
-
times:
|
|
53
|
+
delay: getNumberOrDefault(options.delay, 0),
|
|
54
|
+
times: getNumberOrDefault(options.times, 0),
|
|
57
55
|
when: typeof options.when === "function" ? options.when : shouldRetry
|
|
58
56
|
};
|
|
59
57
|
}
|
|
@@ -66,7 +64,7 @@ function getRetryOptions(input) {
|
|
|
66
64
|
*/
|
|
67
65
|
function retry(callback, options) {
|
|
68
66
|
if (typeof callback !== "function") throw new TypeError(RETRY_MESSAGE_EXPECTATION);
|
|
69
|
-
const { times, when } =
|
|
67
|
+
const { times, when } = createRetryOptions(options);
|
|
70
68
|
let last;
|
|
71
69
|
for (let index = 0; index <= times; index += 1) try {
|
|
72
70
|
return callback();
|