@oscarpalmer/atoms 0.189.0 → 0.190.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/beacon.d.mts +51 -31
- package/dist/beacon.mjs +163 -141
- package/dist/color/index.d.mts +1 -2
- package/dist/color/index.mjs +2 -2
- package/dist/color/instance.d.mts +3 -167
- package/dist/color/instance.mjs +58 -217
- package/dist/color/misc/get.d.mts +1 -2
- package/dist/color/misc/get.mjs +3 -3
- package/dist/color/misc/index.d.mts +4 -4
- package/dist/color/misc/index.mjs +9 -9
- package/dist/color/misc/is.d.mts +1 -2
- package/dist/color/misc/is.mjs +5 -2
- package/dist/color/models.d.mts +158 -2
- package/dist/function/memoize.d.mts +3 -9
- package/dist/function/memoize.mjs +43 -90
- package/dist/function/once.mjs +16 -4
- package/dist/herald.d.mts +19 -15
- package/dist/herald.mjs +79 -89
- package/dist/index.d.mts +173 -162
- package/dist/index.mjs +754 -996
- package/dist/internal/result.d.mts +6 -6
- package/dist/internal/result.mjs +1 -1
- package/dist/internal/value/has.d.mts +2 -2
- package/dist/logger.d.mts +7 -7
- package/dist/logger.mjs +72 -51
- package/dist/promise/helpers.d.mts +2 -2
- package/dist/promise/helpers.mjs +2 -2
- package/dist/queue.d.mts +24 -12
- package/dist/queue.mjs +288 -346
- package/dist/string/fuzzy.d.mts +4 -13
- package/dist/string/fuzzy.mjs +15 -41
- package/package.json +2 -2
- package/src/beacon.ts +262 -160
- package/src/color/index.ts +8 -8
- package/src/color/instance.ts +82 -258
- package/src/color/misc/get.ts +4 -4
- package/src/color/misc/index.ts +10 -11
- package/src/color/misc/is.ts +4 -1
- package/src/color/models.ts +180 -2
- package/src/function/memoize.ts +74 -65
- package/src/function/once.ts +4 -0
- package/src/herald.ts +136 -94
- package/src/internal/result.ts +6 -6
- package/src/internal/value/has.ts +2 -2
- package/src/logger.ts +93 -42
- package/src/promise/helpers.ts +2 -2
- package/src/queue.ts +480 -375
- package/src/string/fuzzy.ts +36 -31
|
@@ -4,42 +4,42 @@ import { Err, ExtendedErr, Ok, Result } from "../result/models.mjs";
|
|
|
4
4
|
* Is the _Result_ an extended error?
|
|
5
5
|
*
|
|
6
6
|
* @param result _Result_ to check
|
|
7
|
-
* @returns `true` if the _Result_ is an extended error, `false`
|
|
7
|
+
* @returns `true` if the _Result_ is an extended error, otherwise `false`
|
|
8
8
|
*/
|
|
9
9
|
declare function isError<Value, E = Error>(result: ExtendedErr<E> | Result<Value, E>, extended: true): result is ExtendedErr<E>;
|
|
10
10
|
/**
|
|
11
11
|
* Is the _Result_ an error?
|
|
12
12
|
*
|
|
13
13
|
* @param result _Result_ to check
|
|
14
|
-
* @returns `true` if the _Result_ is an error, `false`
|
|
14
|
+
* @returns `true` if the _Result_ is an error, otherwise `false`
|
|
15
15
|
*/
|
|
16
16
|
declare function isError<Value, E = Error>(result: Result<Value, E>): result is Err<E>;
|
|
17
17
|
/**
|
|
18
18
|
* Is the value an error?
|
|
19
19
|
*
|
|
20
20
|
* @param value Value to check
|
|
21
|
-
* @returns `true` if the value is an error, `false`
|
|
21
|
+
* @returns `true` if the value is an error, otherwise `false`
|
|
22
22
|
*/
|
|
23
23
|
declare function isError(value: unknown): value is Err<unknown> | ExtendedErr<unknown>;
|
|
24
24
|
/**
|
|
25
25
|
* Is the _Result_ ok?
|
|
26
26
|
*
|
|
27
27
|
* @param value _Result_ to check
|
|
28
|
-
* @returns `true` if the _Result_ is ok, `false`
|
|
28
|
+
* @returns `true` if the _Result_ is ok, otherwise `false`
|
|
29
29
|
*/
|
|
30
30
|
declare function isOk<Value, E = Error>(value: Result<Value, E>): value is Ok<Value>;
|
|
31
31
|
/**
|
|
32
32
|
* Is the value ok?
|
|
33
33
|
*
|
|
34
34
|
* @param value Value to check
|
|
35
|
-
* @returns `true` if the value is ok, `false`
|
|
35
|
+
* @returns `true` if the value is ok, otherwise `false`
|
|
36
36
|
*/
|
|
37
37
|
declare function isOk(value: unknown): value is Ok<unknown>;
|
|
38
38
|
/**
|
|
39
39
|
* Is the value a _Result_?
|
|
40
40
|
*
|
|
41
41
|
* @param value Value to check
|
|
42
|
-
* @returns `true` if the value is a _Result_, `false`
|
|
42
|
+
* @returns `true` if the value is a _Result_, otherwise `false`
|
|
43
43
|
*/
|
|
44
44
|
declare function isResult(value: unknown): value is ExtendedErr<unknown> | Result<unknown, unknown>;
|
|
45
45
|
//#endregion
|
package/dist/internal/result.mjs
CHANGED
|
@@ -10,7 +10,7 @@ function isOk(value) {
|
|
|
10
10
|
* Is the value a _Result_?
|
|
11
11
|
*
|
|
12
12
|
* @param value Value to check
|
|
13
|
-
* @returns `true` if the value is a _Result_, `false`
|
|
13
|
+
* @returns `true` if the value is a _Result_, otherwise `false`
|
|
14
14
|
*/
|
|
15
15
|
function isResult(value) {
|
|
16
16
|
return isResultValue(value, true) || isResultValue(value, false);
|
|
@@ -6,7 +6,7 @@ import { Result } from "../../result/models.mjs";
|
|
|
6
6
|
*
|
|
7
7
|
* @param data Object to check in
|
|
8
8
|
* @param path Path for property, e.g., `foo.bar.baz`
|
|
9
|
-
* @returns `true` if the property exists, `false`
|
|
9
|
+
* @returns `true` if the property exists, otherwise `false`
|
|
10
10
|
*
|
|
11
11
|
* @example
|
|
12
12
|
* ```typescript
|
|
@@ -25,7 +25,7 @@ declare function hasValue<Data extends PlainObject, Path extends NestedKeys<Data
|
|
|
25
25
|
* @param data Object to check in
|
|
26
26
|
* @param path Path for property, e.g., `foo.bar.baz`
|
|
27
27
|
* @param ignoreCase If `true`, the path matching is case-insensitive
|
|
28
|
-
* @returns `true` if the property exists, `false`
|
|
28
|
+
* @returns `true` if the property exists, otherwise `false`
|
|
29
29
|
*
|
|
30
30
|
* @example
|
|
31
31
|
* ```typescript
|
package/dist/logger.d.mts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
//#region src/logger.d.ts
|
|
2
|
-
type
|
|
2
|
+
type Logger = {
|
|
3
3
|
/**
|
|
4
4
|
* Log any number of values at the "debug" log level
|
|
5
5
|
*/
|
|
@@ -51,8 +51,7 @@ type LoggerInstance = {
|
|
|
51
51
|
/**
|
|
52
52
|
* A named timer that can be used to log durations to the console
|
|
53
53
|
*/
|
|
54
|
-
|
|
55
|
-
#private;
|
|
54
|
+
type TimedLogger = {
|
|
56
55
|
/**
|
|
57
56
|
* Is the timer active? _(i.e. has it been started and not stopped, and is logging enabled?)_
|
|
58
57
|
*/
|
|
@@ -67,13 +66,14 @@ declare class TimedLogger {
|
|
|
67
66
|
* _(Will always log the total duration, even if logging is disabled)_
|
|
68
67
|
*/
|
|
69
68
|
get stop(): () => void;
|
|
70
|
-
|
|
71
|
-
|
|
69
|
+
};
|
|
70
|
+
declare function isLogger(value: unknown): value is Logger;
|
|
71
|
+
declare function isTimedLogger(value: unknown): value is TimedLogger;
|
|
72
72
|
/**
|
|
73
73
|
* A logger that can be used to log messages to the console
|
|
74
74
|
*
|
|
75
75
|
* _(Logging can be enabled or disabled by setting the `enabled` property)_
|
|
76
76
|
*/
|
|
77
|
-
declare const Logger:
|
|
77
|
+
declare const Logger: Logger;
|
|
78
78
|
//#endregion
|
|
79
|
-
export { Logger, type TimedLogger };
|
|
79
|
+
export { Logger, type TimedLogger, isLogger, isTimedLogger };
|
package/dist/logger.mjs
CHANGED
|
@@ -1,50 +1,60 @@
|
|
|
1
1
|
import { noop } from "./internal/function/misc.mjs";
|
|
2
2
|
//#region src/logger.ts
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
get log() {
|
|
20
|
-
return this.active ? this.#logger : noop;
|
|
21
|
-
}
|
|
22
|
-
/**
|
|
23
|
-
* Stop the timer and logs the total duration
|
|
24
|
-
*
|
|
25
|
-
* _(Will always log the total duration, even if logging is disabled)_
|
|
26
|
-
*/
|
|
27
|
-
get stop() {
|
|
28
|
-
return this.active ? this.#stopTimer() : noop;
|
|
29
|
-
}
|
|
30
|
-
constructor(label) {
|
|
31
|
-
this.#logger = console.timeLog.bind(console, label);
|
|
32
|
-
this.#stopper = console.timeEnd.bind(console, label);
|
|
33
|
-
this.#state = {
|
|
34
|
-
label,
|
|
35
|
-
started: enabled,
|
|
36
|
-
stopped: false
|
|
37
|
-
};
|
|
38
|
-
if (this.#state.started) console.time(label);
|
|
39
|
-
}
|
|
40
|
-
#stopTimer() {
|
|
41
|
-
const stopper = this.#stopper;
|
|
42
|
-
this.#state.stopped = true;
|
|
43
|
-
this.#logger = void 0;
|
|
44
|
-
this.#stopper = void 0;
|
|
45
|
-
return stopper;
|
|
3
|
+
function isLogger(value) {
|
|
4
|
+
return isLoggerInstance(NAME_LOGGER, value);
|
|
5
|
+
}
|
|
6
|
+
function isLoggerInstance(name, value) {
|
|
7
|
+
return typeof value === "object" && value !== null && value[KEY_LOGGER] === name;
|
|
8
|
+
}
|
|
9
|
+
function isTimedLogger(value) {
|
|
10
|
+
return isLoggerInstance(NAME_TIMED, value);
|
|
11
|
+
}
|
|
12
|
+
function timedLogger(label) {
|
|
13
|
+
function stop() {
|
|
14
|
+
const fn = stopper;
|
|
15
|
+
state.stopped = true;
|
|
16
|
+
logger = void 0;
|
|
17
|
+
stopper = void 0;
|
|
18
|
+
return fn;
|
|
46
19
|
}
|
|
47
|
-
|
|
20
|
+
let logger = console.timeLog.bind(console, label);
|
|
21
|
+
let stopper = console.timeEnd.bind(console, label);
|
|
22
|
+
const state = {
|
|
23
|
+
label,
|
|
24
|
+
started: enabled,
|
|
25
|
+
stopped: false
|
|
26
|
+
};
|
|
27
|
+
const instance = {};
|
|
28
|
+
Object.defineProperties(instance, {
|
|
29
|
+
[KEY_LOGGER]: {
|
|
30
|
+
enumerable: false,
|
|
31
|
+
value: NAME_TIMED
|
|
32
|
+
},
|
|
33
|
+
active: {
|
|
34
|
+
enumerable: true,
|
|
35
|
+
get() {
|
|
36
|
+
return state.started && !state.stopped && enabled;
|
|
37
|
+
}
|
|
38
|
+
},
|
|
39
|
+
log: {
|
|
40
|
+
enumerable: true,
|
|
41
|
+
get() {
|
|
42
|
+
return this.active ? logger : noop;
|
|
43
|
+
}
|
|
44
|
+
},
|
|
45
|
+
stop: {
|
|
46
|
+
enumerable: true,
|
|
47
|
+
get() {
|
|
48
|
+
return instance.active ? stop() : noop;
|
|
49
|
+
}
|
|
50
|
+
}
|
|
51
|
+
});
|
|
52
|
+
if (state.started) console.time(label);
|
|
53
|
+
return Object.freeze(instance);
|
|
54
|
+
}
|
|
55
|
+
const KEY_LOGGER = "$logger";
|
|
56
|
+
const NAME_LOGGER = "Logger";
|
|
57
|
+
const NAME_TIMED = "TimedLogger";
|
|
48
58
|
const methods = [
|
|
49
59
|
"debug",
|
|
50
60
|
"dir",
|
|
@@ -63,7 +73,12 @@ const methods = [
|
|
|
63
73
|
const Logger = (() => {
|
|
64
74
|
const instance = {};
|
|
65
75
|
Object.defineProperties(instance, {
|
|
76
|
+
[KEY_LOGGER]: {
|
|
77
|
+
enumerable: false,
|
|
78
|
+
value: NAME_LOGGER
|
|
79
|
+
},
|
|
66
80
|
enabled: {
|
|
81
|
+
enumerable: true,
|
|
67
82
|
get() {
|
|
68
83
|
return enabled;
|
|
69
84
|
},
|
|
@@ -71,15 +86,21 @@ const Logger = (() => {
|
|
|
71
86
|
enabled = typeof value === "boolean" ? value : enabled;
|
|
72
87
|
}
|
|
73
88
|
},
|
|
74
|
-
time: {
|
|
75
|
-
|
|
76
|
-
|
|
89
|
+
time: {
|
|
90
|
+
enumerable: true,
|
|
91
|
+
value(label) {
|
|
92
|
+
return timedLogger(label);
|
|
93
|
+
}
|
|
94
|
+
}
|
|
95
|
+
});
|
|
96
|
+
for (const method of methods) Object.defineProperty(instance, method, {
|
|
97
|
+
enumerable: true,
|
|
98
|
+
get() {
|
|
99
|
+
return enabled ? console[method].bind(console) : noop;
|
|
100
|
+
}
|
|
77
101
|
});
|
|
78
|
-
for (const method of methods) Object.defineProperty(instance, method, { get() {
|
|
79
|
-
return enabled ? console[method].bind(console) : noop;
|
|
80
|
-
} });
|
|
81
102
|
return Object.freeze(instance);
|
|
82
103
|
})();
|
|
83
104
|
let enabled = true;
|
|
84
105
|
//#endregion
|
|
85
|
-
export { Logger };
|
|
106
|
+
export { Logger, isLogger, isTimedLogger };
|
|
@@ -10,14 +10,14 @@ declare function getStrategyOrDefault(value: unknown): PromiseStrategy;
|
|
|
10
10
|
* Is the value a fulfilled _Promise_ result?
|
|
11
11
|
*
|
|
12
12
|
* @param value Value to check
|
|
13
|
-
* @returns `true` if the value is a fulfilled _Promise_ result, `false`
|
|
13
|
+
* @returns `true` if the value is a fulfilled _Promise_ result, otherwise `false`
|
|
14
14
|
*/
|
|
15
15
|
declare function isFulfilled<Value>(value: unknown): value is FulfilledPromise<Value>;
|
|
16
16
|
/**
|
|
17
17
|
* Is the value a rejected _Promise_ result?
|
|
18
18
|
*
|
|
19
19
|
* @param value Value to check
|
|
20
|
-
* @returns `true` if the value is a rejected _Promise_ result, `false`
|
|
20
|
+
* @returns `true` if the value is a rejected _Promise_ result, otherwise `false`
|
|
21
21
|
*/
|
|
22
22
|
declare function isRejected(value: unknown): value is RejectedPromise;
|
|
23
23
|
//#endregion
|
package/dist/promise/helpers.mjs
CHANGED
|
@@ -36,7 +36,7 @@ function getStrategyOrDefault(value) {
|
|
|
36
36
|
* Is the value a fulfilled _Promise_ result?
|
|
37
37
|
*
|
|
38
38
|
* @param value Value to check
|
|
39
|
-
* @returns `true` if the value is a fulfilled _Promise_ result, `false`
|
|
39
|
+
* @returns `true` if the value is a fulfilled _Promise_ result, otherwise `false`
|
|
40
40
|
*/
|
|
41
41
|
function isFulfilled(value) {
|
|
42
42
|
return isType(value, PROMISE_TYPE_FULFILLED);
|
|
@@ -45,7 +45,7 @@ function isFulfilled(value) {
|
|
|
45
45
|
* Is the value a rejected _Promise_ result?
|
|
46
46
|
*
|
|
47
47
|
* @param value Value to check
|
|
48
|
-
* @returns `true` if the value is a rejected _Promise_ result, `false`
|
|
48
|
+
* @returns `true` if the value is a rejected _Promise_ result, otherwise `false`
|
|
49
49
|
*/
|
|
50
50
|
function isRejected(value) {
|
|
51
51
|
return isType(value, PROMISE_TYPE_REJECTED);
|
package/dist/queue.d.mts
CHANGED
|
@@ -3,8 +3,7 @@ import { GenericAsyncCallback, GenericCallback } from "./models.mjs";
|
|
|
3
3
|
/**
|
|
4
4
|
* A queue that can be used to manage (a)synchronous tasks with a specific key
|
|
5
5
|
*/
|
|
6
|
-
|
|
7
|
-
#private;
|
|
6
|
+
type KeyedQueue<CallbackParameters extends Parameters<GenericAsyncCallback>, CallbackResult> = {
|
|
8
7
|
/**
|
|
9
8
|
* Get keys of all active queues
|
|
10
9
|
*/
|
|
@@ -45,7 +44,6 @@ declare class KeyedQueue<CallbackParameters extends Parameters<GenericAsyncCallb
|
|
|
45
44
|
* Number of queues
|
|
46
45
|
*/
|
|
47
46
|
get queues(): number;
|
|
48
|
-
constructor(callback: GenericAsyncCallback, options: Required<QueueOptions>);
|
|
49
47
|
/**
|
|
50
48
|
* Queue an item for a specific key
|
|
51
49
|
*
|
|
@@ -99,12 +97,11 @@ declare class KeyedQueue<CallbackParameters extends Parameters<GenericAsyncCallb
|
|
|
99
97
|
* @param key Optional key to resume the queue for
|
|
100
98
|
*/
|
|
101
99
|
resume(key?: string): void;
|
|
102
|
-
}
|
|
100
|
+
};
|
|
103
101
|
/**
|
|
104
102
|
* A queue that can be used to manage (a)synchronous tasks
|
|
105
103
|
*/
|
|
106
|
-
|
|
107
|
-
#private;
|
|
104
|
+
type Queue<CallbackParameters extends Parameters<GenericAsyncCallback>, CallbackResult> = {
|
|
108
105
|
/**
|
|
109
106
|
* Is the queue active?
|
|
110
107
|
*/
|
|
@@ -137,7 +134,6 @@ declare class Queue<CallbackParameters extends Parameters<GenericAsyncCallback>,
|
|
|
137
134
|
* Number of items in the queue
|
|
138
135
|
*/
|
|
139
136
|
get size(): number;
|
|
140
|
-
constructor(callback: GenericAsyncCallback, options: Required<QueueOptions>, key?: string);
|
|
141
137
|
/**
|
|
142
138
|
* Add an item to the queue
|
|
143
139
|
*
|
|
@@ -167,7 +163,7 @@ declare class Queue<CallbackParameters extends Parameters<GenericAsyncCallback>,
|
|
|
167
163
|
* Resume the queue
|
|
168
164
|
*/
|
|
169
165
|
resume(): void;
|
|
170
|
-
}
|
|
166
|
+
};
|
|
171
167
|
/**
|
|
172
168
|
* An error thrown by the Queue when an operation fails
|
|
173
169
|
*/
|
|
@@ -209,10 +205,26 @@ type QueuedResult<Value> = {
|
|
|
209
205
|
/**
|
|
210
206
|
* Result for the queued promise
|
|
211
207
|
*/
|
|
212
|
-
value: Value;
|
|
208
|
+
value: Value extends Promise<infer Result> ? Result : Value;
|
|
213
209
|
};
|
|
214
210
|
type Tail<Values extends any[]> = Values extends [infer _, ...infer Rest] ? Rest : never;
|
|
215
|
-
|
|
211
|
+
/**
|
|
212
|
+
* Is the value keyed queue?
|
|
213
|
+
*
|
|
214
|
+
* @param value Value to check
|
|
215
|
+
* @returns `true` if the value is a keyed queue, otherwise `false`
|
|
216
|
+
*/
|
|
217
|
+
declare function isKeyedQueue(value: unknown): value is KeyedQueue<unknown[], unknown>;
|
|
218
|
+
/**
|
|
219
|
+
* Is the value a queue?
|
|
220
|
+
*
|
|
221
|
+
* @param value Value to check
|
|
222
|
+
* @returns `true` if the value is a queue, otherwise `false`
|
|
223
|
+
*/
|
|
224
|
+
declare function isQueue(value: unknown): value is Queue<unknown[], unknown>;
|
|
225
|
+
declare function isQueueInstance<Instance>(name: string, value: unknown): value is Instance;
|
|
226
|
+
declare function keyedQueue<Callback extends (key: string, ...parameters: any[]) => Promise<void>>(callback: Callback, options?: QueueOptions): KeyedQueue<Parameters<Callback>, Awaited<ReturnType<Callback>>>;
|
|
227
|
+
declare function keyedQueue<Callback extends (key: string, ...parameters: any[]) => void>(callback: Callback, options?: QueueOptions): KeyedQueue<Parameters<Callback>, ReturnType<Callback>>;
|
|
216
228
|
/**
|
|
217
229
|
* Create a queue for an asynchronous callback function
|
|
218
230
|
*
|
|
@@ -220,7 +232,7 @@ declare function keyedQueue<Callback extends GenericAsyncCallback>(callback: Cal
|
|
|
220
232
|
* @param options Queue options
|
|
221
233
|
* @returns Queue instance
|
|
222
234
|
*/
|
|
223
|
-
declare function queue<Callback extends (
|
|
235
|
+
declare function queue<Callback extends GenericAsyncCallback>(callback: Callback, options?: QueueOptions): Queue<Parameters<Callback>, Awaited<ReturnType<Callback>>>;
|
|
224
236
|
/**
|
|
225
237
|
* Create a queue for a synchronous callback function
|
|
226
238
|
*
|
|
@@ -233,4 +245,4 @@ declare namespace queue {
|
|
|
233
245
|
var keyed: typeof keyedQueue;
|
|
234
246
|
}
|
|
235
247
|
//#endregion
|
|
236
|
-
export {
|
|
248
|
+
export { KeyedQueue, Queue, QueueError, QueueOptions, Queued, QueuedResult, isKeyedQueue, isQueue, isQueueInstance, keyedQueue, queue };
|