@oscarpalmer/atoms 0.213.0 → 0.214.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.d.mts +1 -1
- package/dist/array/difference.mjs +3 -2
- package/dist/array/exists.d.mts +1 -1
- package/dist/array/exists.mjs +3 -2
- package/dist/array/filter.d.mts +1 -1
- package/dist/array/filter.mjs +1 -0
- package/dist/array/find.d.mts +1 -1
- package/dist/array/find.mjs +4 -3
- package/dist/array/first.d.mts +1 -1
- package/dist/array/flatten.d.mts +1 -1
- package/dist/array/group-by.d.mts +1 -1
- package/dist/array/index.d.mts +2 -2
- package/dist/array/insert.mjs +3 -2
- package/dist/array/intersection.mjs +3 -2
- package/dist/array/last.d.mts +1 -1
- package/dist/array/move.d.mts +1 -1
- package/dist/array/partition.d.mts +1 -1
- package/dist/array/partition.mjs +1 -0
- package/dist/array/push.mjs +3 -2
- package/dist/array/select.d.mts +10 -12
- package/dist/array/select.mjs +1 -0
- package/dist/array/single.d.mts +1 -1
- package/dist/array/single.mjs +1 -0
- package/dist/array/slice.d.mts +1 -1
- package/dist/array/slice.mjs +4 -5
- package/dist/array/sort.d.mts +4 -103
- package/dist/array/sort.mjs +6 -14
- package/dist/array/splice.mjs +3 -2
- package/dist/array/swap.d.mts +1 -1
- package/dist/array/to-map.d.mts +1 -1
- package/dist/array/to-record.d.mts +1 -1
- package/dist/array/to-set.d.mts +1 -1
- package/dist/array/toggle.d.mts +1 -1
- package/dist/array/union.mjs +3 -2
- package/dist/array/unique.d.mts +1 -1
- package/dist/array/unique.mjs +3 -2
- package/dist/array/update.d.mts +1 -1
- package/dist/beacon.d.mts +6 -92
- package/dist/beacon.mjs +6 -16
- package/dist/color/constants.d.mts +2 -2
- package/dist/color/constants.mjs +1 -1
- package/dist/color/index.d.mts +1 -1
- package/dist/color/instance.d.mts +1 -1
- package/dist/color/misc/alpha.d.mts +1 -1
- package/dist/color/misc/format.d.mts +1 -1
- package/dist/color/misc/get.d.mts +1 -1
- package/dist/color/misc/is.d.mts +2 -2
- package/dist/color/misc/is.mjs +1 -0
- package/dist/color/misc/state.d.mts +1 -1
- package/dist/color/space/hex.d.mts +1 -1
- package/dist/color/space/hsl.d.mts +1 -1
- package/dist/color/space/hwb.d.mts +1 -1
- package/dist/color/space/rgb.d.mts +1 -1
- package/dist/function/limit.d.mts +2 -2
- package/dist/function/limit.mjs +2 -1
- package/dist/function/once.d.mts +7 -3
- package/dist/function/once.mjs +5 -10
- package/dist/function/retry.d.mts +4 -14
- package/dist/function/retry.mjs +3 -15
- package/dist/herald.d.mts +2 -2
- package/dist/index.d.mts +425 -318
- package/dist/index.mjs +454 -408
- package/dist/internal/aborter.d.mts +1 -6
- package/dist/internal/aborter.mjs +3 -4
- package/dist/internal/array/callbacks.d.mts +3 -7
- package/dist/internal/array/chunk.mjs +2 -2
- package/dist/internal/array/find.d.mts +5 -23
- package/dist/internal/array/find.mjs +5 -9
- package/dist/internal/array/get.d.mts +1 -1
- package/dist/internal/array/group.d.mts +1 -1
- package/dist/internal/array/index-of.d.mts +1 -1
- package/dist/internal/array/index-of.mjs +4 -3
- package/dist/internal/array/insert.d.mts +2 -5
- package/dist/internal/array/insert.mjs +2 -4
- package/dist/internal/array/match.d.mts +2 -5
- package/dist/internal/array/match.mjs +10 -20
- package/dist/internal/array/overlap.d.mts +2 -10
- package/dist/internal/array/sets.d.mts +2 -5
- package/dist/internal/array/sets.mjs +5 -7
- package/dist/internal/function/assert.d.mts +5 -12
- package/dist/internal/function/assert.mjs +2 -2
- package/dist/internal/function/limit.d.mts +2 -37
- package/dist/internal/function/limit.mjs +4 -15
- package/dist/internal/function/memoize.d.mts +5 -70
- package/dist/internal/function/memoize.mjs +2 -5
- package/dist/internal/function/work.d.mts +16 -22
- package/dist/internal/function/work.mjs +1 -8
- package/dist/internal/herald.d.mts +3 -3
- package/dist/internal/herald.mjs +2 -1
- package/dist/internal/is.d.mts +1 -1
- package/dist/internal/math/aggregate.d.mts +2 -14
- package/dist/internal/math/aggregate.mjs +2 -5
- package/dist/internal/number.mjs +4 -7
- package/dist/internal/result/attempt.d.mts +1 -1
- package/dist/internal/result/misc.d.mts +1 -1
- package/dist/internal/string/case.mjs +6 -16
- package/dist/internal/string/misc.mjs +1 -2
- package/dist/internal/subscription.d.mts +1 -100
- package/dist/internal/subscription.mjs +3 -9
- package/dist/internal/value/compare.d.mts +4 -4
- package/dist/internal/value/compare.mjs +1 -1
- package/dist/internal/value/equal.d.mts +6 -57
- package/dist/internal/value/equal.mjs +5 -10
- package/dist/internal/value/get.d.mts +1 -1
- package/dist/internal/value/handlers.d.mts +2 -21
- package/dist/internal/value/has.d.mts +2 -2
- package/dist/internal/value/misc.d.mts +1 -1
- package/dist/internal/value/misc.mjs +8 -14
- package/dist/internal/value/set.d.mts +1 -1
- package/dist/internal/value/set.mjs +2 -2
- package/dist/is.mjs +3 -3
- package/dist/logger.d.mts +3 -70
- package/dist/logger.mjs +2 -5
- package/dist/math.d.mts +1 -1
- package/dist/math.mjs +2 -1
- package/dist/models/aborter.model.d.mts +12 -0
- package/dist/models/aborter.model.mjs +5 -0
- package/dist/models/array/array.find.model.d.mts +22 -0
- package/dist/models/array/array.find.model.mjs +8 -0
- package/dist/models/array/array.match.model.d.mts +14 -0
- package/dist/models/array/array.match.model.mjs +14 -0
- package/dist/models/array/array.misc.model.d.mts +36 -0
- package/dist/models/array/array.misc.model.mjs +12 -0
- package/dist/models/array/array.sort.model.d.mts +122 -0
- package/dist/models/array/array.sort.model.mjs +12 -0
- package/dist/models/beacon.model.d.mts +119 -0
- package/dist/models/beacon.model.mjs +16 -0
- package/dist/{color/models.d.mts → models/color.model.d.mts} +4 -4
- package/dist/models/function/assert.model.d.mts +13 -0
- package/dist/models/function/assert.model.mjs +4 -0
- package/dist/models/function/limiter.model.d.mts +71 -0
- package/dist/models/function/limiter.model.mjs +15 -0
- package/dist/models/function/memoize.model.d.mts +88 -0
- package/dist/models/function/memoize.model.mjs +7 -0
- package/dist/models/function/once.model.d.mts +76 -0
- package/dist/models/function/once.model.mjs +9 -0
- package/dist/models/function/retry.model.d.mts +17 -0
- package/dist/models/function/retry.model.mjs +17 -0
- package/dist/models/function/work.model.d.mts +20 -0
- package/dist/models/function/work.model.mjs +11 -0
- package/dist/{internal/models → models}/herald.model.d.mts +3 -3
- package/dist/{internal/models → models}/herald.model.mjs +2 -2
- package/dist/{models.d.mts → models/index.d.mts} +5 -47
- package/dist/models/logger.model.d.mts +83 -0
- package/dist/models/logger.model.mjs +7 -0
- package/dist/models/math.model.d.mts +16 -0
- package/dist/models/math.model.mjs +7 -0
- package/dist/models/misc.model.d.mts +10 -0
- package/dist/models/misc.model.mjs +11 -0
- package/dist/{internal/models → models}/plan.model.d.mts +3 -3
- package/dist/{internal/models → models}/plan.model.mjs +1 -1
- package/dist/models/promise.model.d.mts +119 -0
- package/dist/models/promise.model.mjs +47 -0
- package/dist/models/query.model.d.mts +9 -0
- package/dist/models/query.model.mjs +14 -0
- package/dist/models/queue.model.d.mts +251 -0
- package/dist/models/queue.model.mjs +29 -0
- package/dist/models/random.model.d.mts +6 -0
- package/dist/models/random.model.mjs +7 -0
- package/dist/{internal/models → models}/result.model.d.mts +10 -2
- package/dist/models/string/string.case.model.d.mts +19 -0
- package/dist/models/string/string.case.model.mjs +14 -0
- package/dist/models/string/string.fuzzy.model.d.mts +108 -0
- package/dist/models/string/string.fuzzy.model.mjs +9 -0
- package/dist/models/string/string.misc.model.d.mts +13 -0
- package/dist/models/string/string.misc.model.mjs +13 -0
- package/dist/models/string/string.normalize.model.d.mts +85 -0
- package/dist/models/string/string.normalize.model.mjs +43 -0
- package/dist/models/string/string.template.model.d.mts +50 -0
- package/dist/models/string/string.template.model.mjs +5 -0
- package/dist/models/subscription.model.d.mts +127 -0
- package/dist/models/subscription.model.mjs +10 -0
- package/dist/models/value/value.clone.model.d.mts +56 -0
- package/dist/models/value/value.clone.model.mjs +24 -0
- package/dist/models/value/value.diff.model.d.mts +61 -0
- package/dist/models/value/value.diff.model.mjs +6 -0
- package/dist/models/value/value.equal.model.d.mts +76 -0
- package/dist/models/value/value.equal.model.mjs +9 -0
- package/dist/models/value/value.handler.model.d.mts +27 -0
- package/dist/models/value/value.handler.model.mjs +1 -0
- package/dist/models/value/value.merge.model.d.mts +82 -0
- package/dist/models/value/value.merge.model.mjs +5 -0
- package/dist/models/value/value.misc.model.d.mts +33 -0
- package/dist/models/value/value.misc.model.mjs +12 -0
- package/dist/models/value/value.transform.model.d.mts +28 -0
- package/dist/models/value/value.transform.model.mjs +4 -0
- package/dist/plan/generate.d.mts +3 -2
- package/dist/plan/generate.mjs +11 -7
- package/dist/plan/index.d.mts +1 -1
- package/dist/plan/index.mjs +1 -1
- package/dist/plan/is.d.mts +1 -1
- package/dist/plan/is.mjs +1 -1
- package/dist/plan/misc.d.mts +1 -1
- package/dist/plan/models.d.mts +1 -1
- package/dist/plan/result.d.mts +2 -2
- package/dist/plan/result.mjs +3 -3
- package/dist/plan/run.d.mts +1 -1
- package/dist/plan/run.mjs +3 -3
- package/dist/promise/delay.d.mts +1 -1
- package/dist/promise/delay.mjs +2 -1
- package/dist/promise/helpers.d.mts +2 -2
- package/dist/promise/helpers.mjs +6 -6
- package/dist/promise/index.d.mts +2 -2
- package/dist/promise/index.mjs +1 -1
- package/dist/promise/misc.d.mts +3 -3
- package/dist/promise/misc.mjs +7 -4
- package/dist/promise/models.d.mts +2 -106
- package/dist/promise/models.mjs +1 -35
- package/dist/promise/timed.d.mts +2 -2
- package/dist/promise/timed.mjs +3 -3
- package/dist/query.d.mts +1 -1
- package/dist/query.mjs +5 -15
- package/dist/queue.d.mts +6 -200
- package/dist/queue.mjs +9 -34
- package/dist/random.mjs +2 -5
- package/dist/result/match.d.mts +1 -1
- package/dist/result/match.mjs +27 -15
- package/dist/result/misc.d.mts +1 -1
- package/dist/result/work/flow.d.mts +13 -21
- package/dist/result/work/pipe.d.mts +2 -2
- package/dist/string/fuzzy.d.mts +5 -87
- package/dist/string/fuzzy.mjs +6 -11
- package/dist/string/index.mjs +6 -8
- package/dist/string/match.mjs +4 -6
- package/dist/string/normalize.d.mts +4 -40
- package/dist/string/normalize.mjs +9 -48
- package/dist/string/template.d.mts +5 -43
- package/dist/string/template.mjs +1 -2
- package/dist/subscription.d.mts +2 -1
- package/dist/value/clone.d.mts +6 -42
- package/dist/value/clone.mjs +10 -30
- package/dist/value/collection.mjs +2 -0
- package/dist/value/diff.d.mts +3 -44
- package/dist/value/diff.mjs +1 -3
- package/dist/value/freeze.d.mts +1 -5
- package/dist/value/index.d.mts +4 -3
- package/dist/value/merge.d.mts +6 -64
- package/dist/value/merge.mjs +8 -8
- package/dist/value/omit.d.mts +1 -1
- package/dist/value/pick.d.mts +1 -1
- package/dist/value/shake.d.mts +4 -6
- package/dist/value/smush.d.mts +4 -6
- package/dist/value/smush.mjs +2 -2
- package/dist/value/transform.d.mts +6 -22
- package/dist/value/transform.mjs +1 -1
- package/dist/value/unsmush.d.mts +4 -10
- package/package.json +12 -4
- package/dist/promise/constants.d.mts +0 -17
- package/dist/promise/constants.mjs +0 -15
- /package/dist/{color/models.mjs → models/color.model.mjs} +0 -0
- /package/dist/{internal/models/result.model.mjs → models/index.mjs} +0 -0
- /package/dist/{models.mjs → models/result.model.mjs} +0 -0
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import { NestedKeys, NestedValue, PlainObject, ToString } from "../../models.mjs";
|
|
2
|
-
import { Result } from "
|
|
1
|
+
import { NestedKeys, NestedValue, PlainObject, ToString } from "../../models/index.mjs";
|
|
2
|
+
import { Result } from "../../models/result.model.mjs";
|
|
3
3
|
//#region src/internal/value/has.d.ts
|
|
4
4
|
/**
|
|
5
5
|
* Check if a property is defined in an object
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { Result } from "
|
|
1
|
+
import { Result } from "../../models/result.model.mjs";
|
|
2
2
|
//#region src/internal/value/misc.d.ts
|
|
3
3
|
export declare function findKey(needle: string, haystack: object): string;
|
|
4
4
|
export declare function getNestedValue(data: object, path: string, ignoreCase: boolean): Result<unknown, string>;
|
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import { VALUE_MISC_EXPRESSION_BRACKET, VALUE_MISC_EXPRESSION_DOTS, VALUE_MISC_EXPRESSION_NESTED, VALUE_MISC_NESTED_MESSAGE_INPUT, VALUE_MISC_NESTED_MESSAGE_MISSING, VALUE_MISC_NESTED_MESSAGE_PATH, VALUE_MISC_NESTED_MESSAGE_UNSAFE } from "../../models/value/value.misc.model.mjs";
|
|
1
2
|
import { error, ok } from "../result/misc.mjs";
|
|
2
3
|
import { ignoreKey } from "../string/misc.mjs";
|
|
3
4
|
//#region src/internal/value/misc.ts
|
|
@@ -7,8 +8,8 @@ function findKey(needle, haystack) {
|
|
|
7
8
|
return index > -1 ? keys[index] : needle;
|
|
8
9
|
}
|
|
9
10
|
function getNestedValue(data, path, ignoreCase) {
|
|
10
|
-
if (typeof data !== "object" || data === null) return error(
|
|
11
|
-
if (typeof path !== "string" || path.trim().length === 0) return error(
|
|
11
|
+
if (typeof data !== "object" || data === null) return error(VALUE_MISC_NESTED_MESSAGE_INPUT);
|
|
12
|
+
if (typeof path !== "string" || path.trim().length === 0) return error(VALUE_MISC_NESTED_MESSAGE_PATH);
|
|
12
13
|
const shouldIgnoreCase = ignoreCase === true;
|
|
13
14
|
const paths = getPaths(path, shouldIgnoreCase);
|
|
14
15
|
if (typeof paths === "string") return handleValue(data, paths, null, true, shouldIgnoreCase);
|
|
@@ -24,25 +25,18 @@ function getNestedValue(data, path, ignoreCase) {
|
|
|
24
25
|
}
|
|
25
26
|
function getPaths(path, lowercase) {
|
|
26
27
|
const normalized = lowercase ? path.toLowerCase() : path;
|
|
27
|
-
if (!
|
|
28
|
-
return normalized.replace(
|
|
28
|
+
if (!VALUE_MISC_EXPRESSION_NESTED.test(normalized)) return normalized;
|
|
29
|
+
return normalized.replace(VALUE_MISC_EXPRESSION_BRACKET, ".$1").replace(VALUE_MISC_EXPRESSION_DOTS, "").split(".");
|
|
29
30
|
}
|
|
30
31
|
function handleValue(data, path, value, get, ignoreCase) {
|
|
31
32
|
if (typeof data === "object" && data !== null) {
|
|
32
|
-
if (ignoreKey(path)) return error(
|
|
33
|
+
if (ignoreKey(path)) return error(VALUE_MISC_NESTED_MESSAGE_UNSAFE);
|
|
33
34
|
const dataObject = data;
|
|
34
35
|
const key = ignoreCase ? findKey(path, dataObject) : path;
|
|
35
|
-
if (get) return key in dataObject ? ok(dataObject[key]) : error(
|
|
36
|
+
if (get) return key in dataObject ? ok(dataObject[key]) : error(VALUE_MISC_NESTED_MESSAGE_MISSING);
|
|
36
37
|
dataObject[key] = typeof value === "function" ? value(dataObject[key]) : value;
|
|
37
38
|
}
|
|
38
|
-
if (get) return error(
|
|
39
|
+
if (get) return error(VALUE_MISC_NESTED_MESSAGE_MISSING);
|
|
39
40
|
}
|
|
40
|
-
const MISC_EXPRESSION_BRACKET = /\[(\w+)\]/g;
|
|
41
|
-
const MISC_EXPRESSION_DOTS = /^\.|\.$/g;
|
|
42
|
-
const MISC_EXPRESSION_NESTED = /\.|\[\w+\]/;
|
|
43
|
-
const MISC_NESTED_MESSAGE_INPUT = "Expected data to be an object";
|
|
44
|
-
const MISC_NESTED_MESSAGE_MISSING = "Expected property to exist in object";
|
|
45
|
-
const MISC_NESTED_MESSAGE_PATH = "Expected path to be a string";
|
|
46
|
-
const MISC_NESTED_MESSAGE_UNSAFE = "Access to this property is not allowed";
|
|
47
41
|
//#endregion
|
|
48
42
|
export { findKey, getNestedValue, getPaths, handleValue };
|
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import { unwrap } from "../result/misc.mjs";
|
|
2
2
|
import { getPaths, handleValue } from "./misc.mjs";
|
|
3
|
+
import { EXPRESSION_INTEGER } from "../../models/misc.model.mjs";
|
|
3
4
|
//#region src/internal/value/set.ts
|
|
4
5
|
function setValue(data, path, value, ignoreCase) {
|
|
5
6
|
if (typeof data !== "object" || data === null || typeof path !== "string" || path.trim().length === 0) return data;
|
|
@@ -21,7 +22,7 @@ function setValue(data, path, value, ignoreCase) {
|
|
|
21
22
|
let next = unwrap(handleValue(target, currentPath, null, true, shouldIgnoreCase), void 0);
|
|
22
23
|
if (typeof next !== "object" || next === null) {
|
|
23
24
|
const nextPath = paths[index + 1];
|
|
24
|
-
if (
|
|
25
|
+
if (EXPRESSION_INTEGER.test(nextPath)) next = Array.from({ length: +nextPath + 1 }, () => void 0);
|
|
25
26
|
else next = {};
|
|
26
27
|
target[currentPath] = next;
|
|
27
28
|
}
|
|
@@ -29,6 +30,5 @@ function setValue(data, path, value, ignoreCase) {
|
|
|
29
30
|
}
|
|
30
31
|
return data;
|
|
31
32
|
}
|
|
32
|
-
const SET_EXPRESSION_INDEX = /^\d+$/;
|
|
33
33
|
//#endregion
|
|
34
34
|
export { setValue };
|
package/dist/is.mjs
CHANGED
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import { isArrayOrPlainObject, isConstructor, isInstanceOf, isKey, isNonArrayOrPlainObject, isNonConstructor, isNonInstanceOf, isNonKey, isNonNumber, isNonPlainObject, isNonPrimitive, isNonTemplateStringsArray, isNonTypedArray, isNumber, isPlainObject, isPrimitive, isTemplateStringsArray, isTypedArray } from "./internal/is.mjs";
|
|
2
2
|
import { getArray } from "./internal/array/get.mjs";
|
|
3
3
|
import { getString } from "./internal/string/misc.mjs";
|
|
4
|
+
import { EXPRESSION_WHITESPACE_ONLY } from "./models/misc.model.mjs";
|
|
4
5
|
//#region src/is.ts
|
|
5
6
|
/**
|
|
6
7
|
* Is the value empty, or only containing `null` or `undefined` values?
|
|
@@ -53,7 +54,7 @@ function isNonNullableOrEmpty(value) {
|
|
|
53
54
|
* @returns `true` if the value is not `undefined`, `null`, or matches a whitespace-only string, otherwise `false`
|
|
54
55
|
*/
|
|
55
56
|
function isNonNullableOrWhitespace(value) {
|
|
56
|
-
return value != null && !
|
|
57
|
+
return value != null && !EXPRESSION_WHITESPACE_ONLY.test(getString(value));
|
|
57
58
|
}
|
|
58
59
|
/**
|
|
59
60
|
* Is the value not a number or a number-like string?
|
|
@@ -98,7 +99,7 @@ function isNullableOrEmpty(value) {
|
|
|
98
99
|
* @returns `true` if the value is nullable or matches a whitespace-only string, otherwise `false`
|
|
99
100
|
*/
|
|
100
101
|
function isNullableOrWhitespace(value) {
|
|
101
|
-
return value == null ||
|
|
102
|
+
return value == null || EXPRESSION_WHITESPACE_ONLY.test(getString(value));
|
|
102
103
|
}
|
|
103
104
|
/**
|
|
104
105
|
* Is the value a number or a number-like string?
|
|
@@ -118,6 +119,5 @@ function isNumerical(value) {
|
|
|
118
119
|
function isObject(value) {
|
|
119
120
|
return typeof value === "object" && value !== null || typeof value === "function";
|
|
120
121
|
}
|
|
121
|
-
const EXPRESSION_WHITESPACE = /^\s*$/;
|
|
122
122
|
//#endregion
|
|
123
123
|
export { isArrayOrPlainObject, isConstructor, isEmpty, isInstanceOf, isKey, isNonArrayOrPlainObject, isNonConstructor, isNonEmpty, isNonInstanceOf, isNonKey, isNonNullable, isNonNullableOrEmpty, isNonNullableOrWhitespace, isNonNumber, isNonNumerical, isNonObject, isNonPlainObject, isNonPrimitive, isNonTemplateStringsArray, isNonTypedArray, isNullable, isNullableOrEmpty, isNullableOrWhitespace, isNumber, isNumerical, isObject, isPlainObject, isPrimitive, isTemplateStringsArray, isTypedArray };
|
package/dist/logger.d.mts
CHANGED
|
@@ -1,80 +1,13 @@
|
|
|
1
|
+
import { Lumberjack, TimeLogger } from "./models/logger.model.mjs";
|
|
1
2
|
//#region src/logger.d.ts
|
|
2
|
-
type Logger = {
|
|
3
|
-
/**
|
|
4
|
-
* Log any number of values at the "debug" log level
|
|
5
|
-
*/
|
|
6
|
-
get debug(): typeof console.debug;
|
|
7
|
-
/**
|
|
8
|
-
* Log the value and shows all its properties
|
|
9
|
-
*/
|
|
10
|
-
get dir(): typeof console.dir;
|
|
11
|
-
/**
|
|
12
|
-
* Is logging to the console enabled? _(defaults to `true`)_
|
|
13
|
-
*/
|
|
14
|
-
get enabled(): boolean;
|
|
15
|
-
/**
|
|
16
|
-
* Enable or disable logging to the console
|
|
17
|
-
*/
|
|
18
|
-
set enabled(value: boolean);
|
|
19
|
-
/**
|
|
20
|
-
* Log any number of values at the "error" log level
|
|
21
|
-
*/
|
|
22
|
-
get error(): typeof console.error;
|
|
23
|
-
/**
|
|
24
|
-
* Log any number of values at the "info" log level
|
|
25
|
-
*/
|
|
26
|
-
get info(): typeof console.info;
|
|
27
|
-
/**
|
|
28
|
-
* Log any number of values at the "log" log level
|
|
29
|
-
*/
|
|
30
|
-
get log(): typeof console.log;
|
|
31
|
-
/**
|
|
32
|
-
* Log data as a table, with optional properties to use as columns
|
|
33
|
-
*/
|
|
34
|
-
get table(): typeof console.table;
|
|
35
|
-
/**
|
|
36
|
-
* Log any number of values together with a trace from where it was called
|
|
37
|
-
*/
|
|
38
|
-
get trace(): typeof console.trace;
|
|
39
|
-
/**
|
|
40
|
-
* Log any number of values at the "warn" log level
|
|
41
|
-
*/
|
|
42
|
-
get warn(): typeof console.warn;
|
|
43
|
-
/**
|
|
44
|
-
* Start a timed logger with a label
|
|
45
|
-
*
|
|
46
|
-
* @param label Label for the logger
|
|
47
|
-
* @returns _TimedLogger_ instance
|
|
48
|
-
*/
|
|
49
|
-
time(label: string): TimeLogger;
|
|
50
|
-
};
|
|
51
|
-
/**
|
|
52
|
-
* A named timer that can be used to log durations to the console
|
|
53
|
-
*/
|
|
54
|
-
type TimeLogger = {
|
|
55
|
-
/**
|
|
56
|
-
* Is the timer active? _(i.e. has it been started and not stopped, and is logging enabled?)_
|
|
57
|
-
*/
|
|
58
|
-
get active(): boolean;
|
|
59
|
-
/**
|
|
60
|
-
* Log the current duration of the timer _(ignored if logging is disabled)_
|
|
61
|
-
*/
|
|
62
|
-
get log(): () => void;
|
|
63
|
-
/**
|
|
64
|
-
* Stop the timer and logs the total duration
|
|
65
|
-
*
|
|
66
|
-
* _(Will always log the total duration, even if logging is disabled)_
|
|
67
|
-
*/
|
|
68
|
-
get stop(): () => void;
|
|
69
|
-
};
|
|
70
3
|
declare function TimeLogger(this: any, label: string): void;
|
|
71
|
-
declare function isLogger(value: unknown): value is
|
|
4
|
+
declare function isLogger(value: unknown): value is Lumberjack;
|
|
72
5
|
declare function isTimeLogger(value: unknown): value is TimeLogger;
|
|
73
6
|
/**
|
|
74
7
|
* A logger that can be used to log messages to the console
|
|
75
8
|
*
|
|
76
9
|
* _(Logging can be enabled or disabled by setting the `enabled` property)_
|
|
77
10
|
*/
|
|
78
|
-
declare const Logger:
|
|
11
|
+
declare const Logger: Lumberjack;
|
|
79
12
|
//#endregion
|
|
80
13
|
export { Logger, type TimeLogger, isLogger, isTimeLogger };
|
package/dist/logger.mjs
CHANGED
|
@@ -1,9 +1,7 @@
|
|
|
1
1
|
import { noop } from "./internal/function/misc.mjs";
|
|
2
2
|
import { getString } from "./internal/string/misc.mjs";
|
|
3
|
+
import { LOGGER_NAME, LOGGER_NAME_TIMED, LOGGER_PROPERTY, LOGGER_SYMBOL } from "./models/logger.model.mjs";
|
|
3
4
|
//#region src/logger.ts
|
|
4
|
-
const LOGGER_NAME = "Logger";
|
|
5
|
-
const LOGGER_NAME_TIMED = "TimedLogger";
|
|
6
|
-
const LOGGER_PROPERTY = "$logger";
|
|
7
5
|
function Lumberjack() {}
|
|
8
6
|
Lumberjack.prototype[LOGGER_PROPERTY] = LOGGER_NAME;
|
|
9
7
|
Lumberjack.prototype.time = getTimeLogger;
|
|
@@ -70,7 +68,7 @@ function isLogger(value) {
|
|
|
70
68
|
return isLoggerInstance(LOGGER_NAME, value);
|
|
71
69
|
}
|
|
72
70
|
function isLoggerInstance(name, value) {
|
|
73
|
-
return typeof value === "object" && value !== null &&
|
|
71
|
+
return typeof value === "object" && value !== null && "$logger" in value && value["$logger"] === name;
|
|
74
72
|
}
|
|
75
73
|
function isTimeLogger(value) {
|
|
76
74
|
return isLoggerInstance(LOGGER_NAME_TIMED, value);
|
|
@@ -78,7 +76,6 @@ function isTimeLogger(value) {
|
|
|
78
76
|
function setLoggerEnabled(value) {
|
|
79
77
|
enabled = typeof value === "boolean" ? value : enabled;
|
|
80
78
|
}
|
|
81
|
-
const LOGGER_SYMBOL = Symbol(LOGGER_PROPERTY);
|
|
82
79
|
/**
|
|
83
80
|
* A logger that can be used to log messages to the console
|
|
84
81
|
*
|
package/dist/math.d.mts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { NumericalValues, PlainObject } from "./models.mjs";
|
|
1
|
+
import { NumericalValues, PlainObject } from "./models/index.mjs";
|
|
2
2
|
import { max, min } from "./internal/math/aggregate.mjs";
|
|
3
3
|
import { floor, round } from "./internal/math/misc.mjs";
|
|
4
4
|
//#region src/math.d.ts
|
package/dist/math.mjs
CHANGED
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import { isNumber } from "./internal/is.mjs";
|
|
2
2
|
import { floor, round, roundNumber } from "./internal/math/misc.mjs";
|
|
3
|
-
import { AGGREGATION_AVERAGE
|
|
3
|
+
import { AGGREGATION_AVERAGE } from "./models/math.model.mjs";
|
|
4
|
+
import { aggregate, getAggregateCallback, getAggregated, max, min } from "./internal/math/aggregate.mjs";
|
|
4
5
|
//#region src/math.ts
|
|
5
6
|
function average(array, key) {
|
|
6
7
|
const aggregated = aggregate(AGGREGATION_AVERAGE, array, key);
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import { GenericCallback } from "./index.mjs";
|
|
2
|
+
//#region src/models/aborter.model.d.ts
|
|
3
|
+
export type Aborter = {
|
|
4
|
+
callback: GenericCallback;
|
|
5
|
+
cancel(): void;
|
|
6
|
+
signal: AbortSignal;
|
|
7
|
+
};
|
|
8
|
+
export declare const ABORTER_EVENT = "abort";
|
|
9
|
+
export declare const ABORTER_OPTIONS: {
|
|
10
|
+
once: boolean;
|
|
11
|
+
};
|
|
12
|
+
//#endregion
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
//#region src/models/array/array.find.model.d.ts
|
|
2
|
+
export type ArrayFindMapper = {
|
|
3
|
+
callback: unknown;
|
|
4
|
+
reverse: boolean;
|
|
5
|
+
};
|
|
6
|
+
export type ArrayFindValueType = "index" | "item";
|
|
7
|
+
export type ArrayFindValuesResult = {
|
|
8
|
+
matched: unknown[];
|
|
9
|
+
notMatched: unknown[];
|
|
10
|
+
};
|
|
11
|
+
export type ArrayFindValuesType = "all" | "unique";
|
|
12
|
+
export type ArrayParameters = {
|
|
13
|
+
bool?: unknown;
|
|
14
|
+
key?: unknown;
|
|
15
|
+
value?: unknown;
|
|
16
|
+
};
|
|
17
|
+
export declare const ARRAY_FIND_VALUE_INDEX = "index";
|
|
18
|
+
export declare const ARRAY_FIND_VALUE_ITEM = "item";
|
|
19
|
+
export declare const ARRAY_FIND_VALUES_ALL: ArrayFindValuesType;
|
|
20
|
+
export declare const ARRAY_FIND_VALUES_UNIQUE: ArrayFindValuesType;
|
|
21
|
+
export declare const ARRAY_FIND_UNIQUE_THRESHOLD = 100;
|
|
22
|
+
//#endregion
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
//#region src/models/array/array.find.model.ts
|
|
2
|
+
const ARRAY_FIND_VALUE_INDEX = "index";
|
|
3
|
+
const ARRAY_FIND_VALUE_ITEM = "item";
|
|
4
|
+
const ARRAY_FIND_VALUES_ALL = "all";
|
|
5
|
+
const ARRAY_FIND_VALUES_UNIQUE = "unique";
|
|
6
|
+
const ARRAY_FIND_UNIQUE_THRESHOLD = 100;
|
|
7
|
+
//#endregion
|
|
8
|
+
export { ARRAY_FIND_UNIQUE_THRESHOLD, ARRAY_FIND_VALUES_ALL, ARRAY_FIND_VALUES_UNIQUE, ARRAY_FIND_VALUE_INDEX, ARRAY_FIND_VALUE_ITEM };
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
import { ArrayComparison } from "./array.misc.model.mjs";
|
|
2
|
+
//#region src/models/array/array.match.model.d.ts
|
|
3
|
+
export declare const ARRAY_MATCH_COMPARISON_END: ArrayComparison;
|
|
4
|
+
export declare const ARRAY_MATCH_COMPARISON_INSIDE: ArrayComparison;
|
|
5
|
+
export declare const ARRAY_MATCH_COMPARISON_INVALID: ArrayComparison;
|
|
6
|
+
export declare const ARRAY_MATCH_COMPARISON_OUTSIDE: ArrayComparison;
|
|
7
|
+
export declare const ARRAY_MATCH_COMPARISON_SAME: ArrayComparison;
|
|
8
|
+
export declare const ARRAY_MATCH_COMPARISON_START: ArrayComparison;
|
|
9
|
+
export declare const arrayMatchEndings: Set<ArrayComparison>;
|
|
10
|
+
export declare const arrayMatchInvalid: readonly [-1, ArrayComparison];
|
|
11
|
+
export declare const arrayMatchOutside: readonly [-1, ArrayComparison];
|
|
12
|
+
export declare const arrayMatchOutsides: Set<ArrayComparison>;
|
|
13
|
+
export declare const arrayMatchStarts: Set<ArrayComparison>;
|
|
14
|
+
//#endregion
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
//#region src/models/array/array.match.model.ts
|
|
2
|
+
const ARRAY_MATCH_COMPARISON_END = "end";
|
|
3
|
+
const ARRAY_MATCH_COMPARISON_INSIDE = "inside";
|
|
4
|
+
const ARRAY_MATCH_COMPARISON_INVALID = "invalid";
|
|
5
|
+
const ARRAY_MATCH_COMPARISON_OUTSIDE = "outside";
|
|
6
|
+
const ARRAY_MATCH_COMPARISON_SAME = "same";
|
|
7
|
+
const ARRAY_MATCH_COMPARISON_START = "start";
|
|
8
|
+
const arrayMatchEndings = /* @__PURE__ */ new Set(["end", ARRAY_MATCH_COMPARISON_SAME]);
|
|
9
|
+
const arrayMatchInvalid = [-1, ARRAY_MATCH_COMPARISON_INVALID];
|
|
10
|
+
const arrayMatchOutside = [-1, ARRAY_MATCH_COMPARISON_OUTSIDE];
|
|
11
|
+
const arrayMatchOutsides = /* @__PURE__ */ new Set([ARRAY_MATCH_COMPARISON_INVALID, ARRAY_MATCH_COMPARISON_OUTSIDE]);
|
|
12
|
+
const arrayMatchStarts = /* @__PURE__ */ new Set([ARRAY_MATCH_COMPARISON_START, ARRAY_MATCH_COMPARISON_SAME]);
|
|
13
|
+
//#endregion
|
|
14
|
+
export { ARRAY_MATCH_COMPARISON_END, ARRAY_MATCH_COMPARISON_INSIDE, ARRAY_MATCH_COMPARISON_INVALID, ARRAY_MATCH_COMPARISON_OUTSIDE, ARRAY_MATCH_COMPARISON_SAME, ARRAY_MATCH_COMPARISON_START, arrayMatchEndings, arrayMatchInvalid, arrayMatchOutside, arrayMatchOutsides, arrayMatchStarts };
|
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
import { GenericCallback, PlainObject } from "../index.mjs";
|
|
2
|
+
//#region src/models/array/array.misc.model.d.ts
|
|
3
|
+
export type ArrayCompareSetsType = "difference" | "intersection" | "union";
|
|
4
|
+
/**
|
|
5
|
+
* Comparison of an array within another array
|
|
6
|
+
*/
|
|
7
|
+
export type ArrayComparison = "end" | "inside" | "invalid" | "outside" | "same" | "start";
|
|
8
|
+
export type ArrayExtractType = "drop" | "take";
|
|
9
|
+
export type ArrayGetCallbacks = {
|
|
10
|
+
bool?: GenericCallback;
|
|
11
|
+
keyed?: GenericCallback;
|
|
12
|
+
value?: GenericCallback;
|
|
13
|
+
};
|
|
14
|
+
export type ArrayInsertType = "insert" | "push" | "splice";
|
|
15
|
+
export type ArrayOverlapItem = {
|
|
16
|
+
array: unknown[];
|
|
17
|
+
index: number;
|
|
18
|
+
};
|
|
19
|
+
export type ArrayMapKeyOrCallback<Item> = ((item: Item, index: number, array: Item[]) => unknown) | (Item extends PlainObject ? keyof Item : never);
|
|
20
|
+
export type ArrayMapped<Item, Map extends ArrayMapKeyOrCallback<Item>> = Map extends ((item: Item, index: number, array: Item[]) => unknown) ? ReturnType<Map> : Map extends keyof Item ? Item[Map] : never;
|
|
21
|
+
export type ArrayObjectKeysOf<Item> = { [Key in keyof Item]: Item[Key] extends PlainObject ? Key : never; }[keyof Item];
|
|
22
|
+
export type ArrayOverlapResult = {
|
|
23
|
+
first: ArrayOverlapItem;
|
|
24
|
+
second: ArrayOverlapItem;
|
|
25
|
+
overlap: boolean;
|
|
26
|
+
};
|
|
27
|
+
export declare const ARRAY_CHUNK_MAX_SIZE = 5e3;
|
|
28
|
+
export declare const ARRAY_INSERT_TYPE_INSERT: ArrayInsertType;
|
|
29
|
+
export declare const ARRAY_INSERT_TYPE_PUSH: ArrayInsertType;
|
|
30
|
+
export declare const ARRAY_INSERT_TYPE_SPLICE: ArrayInsertType;
|
|
31
|
+
export declare const ARRAY_SETS_COMPARE_DIFFERENCE: ArrayCompareSetsType;
|
|
32
|
+
export declare const ARRAY_SETS_COMPARE_INTERSECTION: ArrayCompareSetsType;
|
|
33
|
+
export declare const ARRAY_SETS_COMPARE_UNION: ArrayCompareSetsType;
|
|
34
|
+
export declare const ARRAY_SLICE_DROP: ArrayExtractType;
|
|
35
|
+
export declare const ARRAY_SLICE_TAKE: ArrayExtractType;
|
|
36
|
+
//#endregion
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
//#region src/models/array/array.misc.model.ts
|
|
2
|
+
const ARRAY_CHUNK_MAX_SIZE = 5e3;
|
|
3
|
+
const ARRAY_INSERT_TYPE_INSERT = "insert";
|
|
4
|
+
const ARRAY_INSERT_TYPE_PUSH = "push";
|
|
5
|
+
const ARRAY_INSERT_TYPE_SPLICE = "splice";
|
|
6
|
+
const ARRAY_SETS_COMPARE_DIFFERENCE = "difference";
|
|
7
|
+
const ARRAY_SETS_COMPARE_INTERSECTION = "intersection";
|
|
8
|
+
const ARRAY_SETS_COMPARE_UNION = "union";
|
|
9
|
+
const ARRAY_SLICE_DROP = "drop";
|
|
10
|
+
const ARRAY_SLICE_TAKE = "take";
|
|
11
|
+
//#endregion
|
|
12
|
+
export { ARRAY_CHUNK_MAX_SIZE, ARRAY_INSERT_TYPE_INSERT, ARRAY_INSERT_TYPE_PUSH, ARRAY_INSERT_TYPE_SPLICE, ARRAY_SETS_COMPARE_DIFFERENCE, ARRAY_SETS_COMPARE_INTERSECTION, ARRAY_SETS_COMPARE_UNION, ARRAY_SLICE_DROP, ARRAY_SLICE_TAKE };
|
|
@@ -0,0 +1,122 @@
|
|
|
1
|
+
import { PlainObject, Primitive } from "../index.mjs";
|
|
2
|
+
//#region src/models/array/array.sort.model.d.ts
|
|
3
|
+
/**
|
|
4
|
+
* Sorting information for arrays _(using a comparison callback)_
|
|
5
|
+
*/
|
|
6
|
+
export type ArrayComparisonSorter<Item> = {
|
|
7
|
+
/**
|
|
8
|
+
* Callback to use when comparing items and values
|
|
9
|
+
*/
|
|
10
|
+
comparison: ComparisonSorter<Item>;
|
|
11
|
+
/**
|
|
12
|
+
* Direction to sort by
|
|
13
|
+
*/
|
|
14
|
+
direction?: SortDirection;
|
|
15
|
+
};
|
|
16
|
+
/**
|
|
17
|
+
* Sorting information for arrays _(using a key)_
|
|
18
|
+
*/
|
|
19
|
+
export type ArrayKeySorter<Item extends PlainObject, ItemKey extends keyof Item> = {
|
|
20
|
+
/**
|
|
21
|
+
* Comparator to use when comparing items and values
|
|
22
|
+
*/
|
|
23
|
+
compare?: CompareCallback<Item, Item[ItemKey]>;
|
|
24
|
+
/**
|
|
25
|
+
* Direction to sort by
|
|
26
|
+
*/
|
|
27
|
+
direction?: SortDirection;
|
|
28
|
+
/**
|
|
29
|
+
* Key to sort by
|
|
30
|
+
*/
|
|
31
|
+
key: ItemKey;
|
|
32
|
+
};
|
|
33
|
+
/**
|
|
34
|
+
* Sorters based on keys in an object
|
|
35
|
+
*/
|
|
36
|
+
export type ArrayKeySorters<Item extends PlainObject> = { [ItemKey in keyof Item]: ArrayKeySorter<Item, ItemKey>; }[keyof Item];
|
|
37
|
+
/**
|
|
38
|
+
* Sorter to use for sorting
|
|
39
|
+
*/
|
|
40
|
+
export type ArraySorter<Item> = Item extends PlainObject ? keyof Item | ArrayComparisonSorter<Item> | ArrayKeySorters<Item> | ArrayValueSorter<Item> | ComparisonSorter<Item> : ArrayComparisonSorter<Item> | ArrayValueSorter<Item> | ComparisonSorter<Item>;
|
|
41
|
+
/**
|
|
42
|
+
* Sorters to use for sorting
|
|
43
|
+
*/
|
|
44
|
+
export type ArraySorters<Item> = Array<ArraySorter<Item>>;
|
|
45
|
+
/**
|
|
46
|
+
* Sorting information for arrays _(using a value callback and built-in comparison)_
|
|
47
|
+
*/
|
|
48
|
+
export type ArrayValueSorter<Item> = {
|
|
49
|
+
/**
|
|
50
|
+
* Direction to sort by
|
|
51
|
+
*/
|
|
52
|
+
direction?: SortDirection;
|
|
53
|
+
/**
|
|
54
|
+
* Value to sort by
|
|
55
|
+
*/
|
|
56
|
+
value(item: Item): unknown;
|
|
57
|
+
};
|
|
58
|
+
/**
|
|
59
|
+
* Comparator to use when comparing items and values
|
|
60
|
+
*/
|
|
61
|
+
export type CompareCallback<Item, Value = CompareCallbackValue<Item>> = (first: Item, firstValue: Value, second: Item, secondValue: Value) => number;
|
|
62
|
+
export type CompareCallbackValue<Item> = Item extends Primitive ? Item : unknown;
|
|
63
|
+
/**
|
|
64
|
+
* Callback to use when comparing items and values
|
|
65
|
+
*/
|
|
66
|
+
export type ComparisonSorter<Item> = (first: Item, second: Item) => number;
|
|
67
|
+
export type InternalSorter = {
|
|
68
|
+
[SORTER_SYMBOL]: SortHandler[];
|
|
69
|
+
};
|
|
70
|
+
/**
|
|
71
|
+
* Direction to sort by
|
|
72
|
+
*/
|
|
73
|
+
export type SortDirection = "ascending" | "descending";
|
|
74
|
+
export type SortHandler = {
|
|
75
|
+
comparison?: SortHandlerComparison;
|
|
76
|
+
get: boolean;
|
|
77
|
+
identifier: string;
|
|
78
|
+
modifier: number;
|
|
79
|
+
value?: Function;
|
|
80
|
+
};
|
|
81
|
+
export type SortHandlerComparison = {
|
|
82
|
+
complex?: Function;
|
|
83
|
+
simple?: Function;
|
|
84
|
+
};
|
|
85
|
+
/**
|
|
86
|
+
* Sorter for an array with predefined sorters
|
|
87
|
+
*
|
|
88
|
+
* Can be used to sort an array, get the predicted index for an item, and check if an array is sorted
|
|
89
|
+
*/
|
|
90
|
+
export type Sorter<Item> = {
|
|
91
|
+
/**
|
|
92
|
+
* Get the index for an item _(to be inserted into an array of items)_
|
|
93
|
+
*
|
|
94
|
+
* _(If the array is not sorted, it will be treated as sorted, and the result may be inaccurate)_
|
|
95
|
+
*
|
|
96
|
+
* @param array Array to get the index from
|
|
97
|
+
* @param item Item to get the index for
|
|
98
|
+
* @returns Index for item
|
|
99
|
+
*/
|
|
100
|
+
index(array: Item[], item: Item): number;
|
|
101
|
+
/**
|
|
102
|
+
* Is the array sorted?
|
|
103
|
+
*
|
|
104
|
+
* @param array Array to check
|
|
105
|
+
* @returns `true` if sorted, otherwise `false`
|
|
106
|
+
*/
|
|
107
|
+
is(array: Item[]): boolean;
|
|
108
|
+
/**
|
|
109
|
+
* Sort an array of items
|
|
110
|
+
*
|
|
111
|
+
* @param array Array to sort
|
|
112
|
+
* @returns Sorted array
|
|
113
|
+
*/
|
|
114
|
+
sort(array: Item[]): Item[];
|
|
115
|
+
};
|
|
116
|
+
export declare const SORT_PEEK_PERCENTAGE = 10;
|
|
117
|
+
export declare const SORT_THRESHOLD = 100;
|
|
118
|
+
export declare const SORT_DIRECTION_ASCENDING: SortDirection;
|
|
119
|
+
export declare const SORT_DIRECTION_DESCENDING: SortDirection;
|
|
120
|
+
export declare const SORTER_SYMBOL: unique symbol;
|
|
121
|
+
export declare const arrayModifiers: Record<string, number>;
|
|
122
|
+
//#endregion
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
//#region src/models/array/array.sort.model.ts
|
|
2
|
+
const SORT_PEEK_PERCENTAGE = 10;
|
|
3
|
+
const SORT_THRESHOLD = 100;
|
|
4
|
+
const SORT_DIRECTION_ASCENDING = "ascending";
|
|
5
|
+
const SORT_DIRECTION_DESCENDING = "descending";
|
|
6
|
+
const SORTER_SYMBOL = Symbol("sorter");
|
|
7
|
+
const arrayModifiers = {
|
|
8
|
+
[SORT_DIRECTION_ASCENDING]: 1,
|
|
9
|
+
[SORT_DIRECTION_DESCENDING]: -1
|
|
10
|
+
};
|
|
11
|
+
//#endregion
|
|
12
|
+
export { SORTER_SYMBOL, SORT_DIRECTION_ASCENDING, SORT_DIRECTION_DESCENDING, SORT_PEEK_PERCENTAGE, SORT_THRESHOLD, arrayModifiers };
|
|
@@ -0,0 +1,119 @@
|
|
|
1
|
+
import { Subscription, SubscriptionProperty, Subscriptions } from "./subscription.model.mjs";
|
|
2
|
+
//#region src/models/beacon.model.d.ts
|
|
3
|
+
/**
|
|
4
|
+
* A beacon is a lighthouse, holding an observable value that can be subscribed to and emitted from
|
|
5
|
+
*/
|
|
6
|
+
export type Beacon<Value> = {
|
|
7
|
+
/**
|
|
8
|
+
* Is the beacon active?
|
|
9
|
+
*/
|
|
10
|
+
get active(): boolean;
|
|
11
|
+
/**
|
|
12
|
+
* The observable that can be subscribed to
|
|
13
|
+
*/
|
|
14
|
+
get observable(): Observable<Value>;
|
|
15
|
+
/**
|
|
16
|
+
* The current value
|
|
17
|
+
*/
|
|
18
|
+
get value(): Value;
|
|
19
|
+
/**
|
|
20
|
+
* Deactivate the beacon
|
|
21
|
+
*/
|
|
22
|
+
deactivate(): void;
|
|
23
|
+
/**
|
|
24
|
+
* Emit a new value
|
|
25
|
+
*
|
|
26
|
+
* @param value Value to set and emit
|
|
27
|
+
* @param finish Finish the beacon after emitting? _(defaults to `false`)_
|
|
28
|
+
*/
|
|
29
|
+
emit(value: Value, finish?: boolean): void;
|
|
30
|
+
/**
|
|
31
|
+
* Emit an error
|
|
32
|
+
*
|
|
33
|
+
* @param value Error to emit
|
|
34
|
+
* @param finish Finish the beacon after emitting? _(defaults to `false`)_
|
|
35
|
+
*/
|
|
36
|
+
error(value: Error, finish?: boolean): void;
|
|
37
|
+
/**
|
|
38
|
+
* Finish the beacon
|
|
39
|
+
*/
|
|
40
|
+
finish(): void;
|
|
41
|
+
};
|
|
42
|
+
export type BeaconOptions<Value> = {
|
|
43
|
+
/**
|
|
44
|
+
* Method for comparing values for equality
|
|
45
|
+
*
|
|
46
|
+
* @param first First value
|
|
47
|
+
* @param second Second value
|
|
48
|
+
* @returns `true` if the values are equal, otherwise `false`
|
|
49
|
+
* @default Object.is
|
|
50
|
+
*/
|
|
51
|
+
equal?: (first: Value, second: Value) => boolean;
|
|
52
|
+
};
|
|
53
|
+
export type BeaconState<Value> = {
|
|
54
|
+
active: boolean;
|
|
55
|
+
observable?: Observable<Value>;
|
|
56
|
+
options: Required<BeaconOptions<Value>>;
|
|
57
|
+
subscriptions?: Subscriptions<Observer<unknown>>;
|
|
58
|
+
value: Value;
|
|
59
|
+
};
|
|
60
|
+
export type InternalBeacon = {
|
|
61
|
+
[BEACON_SYMBOL]: BeaconState<unknown>;
|
|
62
|
+
} & Beacon<unknown>;
|
|
63
|
+
export type InternalObservable = {
|
|
64
|
+
[BEACON_SYMBOL]: ObservableState<unknown>;
|
|
65
|
+
} & Observable<unknown>;
|
|
66
|
+
export type Observable<Value> = {
|
|
67
|
+
/**
|
|
68
|
+
* Is the observable active?
|
|
69
|
+
*/
|
|
70
|
+
get active(): boolean;
|
|
71
|
+
/**
|
|
72
|
+
* Deactivate the observable
|
|
73
|
+
*/
|
|
74
|
+
deactivate(): void;
|
|
75
|
+
/**
|
|
76
|
+
* Subscribe to value changes
|
|
77
|
+
*
|
|
78
|
+
* @param onNext Callback for when the observable receives a new value
|
|
79
|
+
* @param onError Callback for when the observable receives an error
|
|
80
|
+
* @param onComplete Callback for when the observable is completed
|
|
81
|
+
* @returns Subscription to the observable
|
|
82
|
+
*/
|
|
83
|
+
subscribe(onNext: (value: Value) => void, onError?: (error: Error) => void, onComplete?: () => void): Subscription;
|
|
84
|
+
/**
|
|
85
|
+
* Subscribe to value changes
|
|
86
|
+
*
|
|
87
|
+
* @param observer Observer for changes
|
|
88
|
+
* @returns Subscription to the observable
|
|
89
|
+
*/
|
|
90
|
+
subscribe(observer: Observer<Value>): Subscription;
|
|
91
|
+
};
|
|
92
|
+
export type ObservableState<Value> = {
|
|
93
|
+
active: boolean;
|
|
94
|
+
beacon: BeaconState<Value>;
|
|
95
|
+
};
|
|
96
|
+
export type Observer<Value> = {
|
|
97
|
+
/**
|
|
98
|
+
* Callback for when the observable is completed
|
|
99
|
+
*/
|
|
100
|
+
complete?: () => void;
|
|
101
|
+
/**
|
|
102
|
+
* Callback for when the observable receives an error
|
|
103
|
+
*/
|
|
104
|
+
error?: (error: Error) => void;
|
|
105
|
+
/**
|
|
106
|
+
* Callback for when the observable receives a new value
|
|
107
|
+
*/
|
|
108
|
+
next?: (value: Value) => void;
|
|
109
|
+
};
|
|
110
|
+
export declare const BEACON_MESSAGE_RETRIEVE = "Cannot retrieve observable from a closed beacon";
|
|
111
|
+
export declare const BEACON_MESSAGE_SUBSCRIBE = "Cannot subscribe to a closed observable";
|
|
112
|
+
export declare const BEACON_PROPERTY = "$beacon";
|
|
113
|
+
export declare const BEACON_NAME = "beacon";
|
|
114
|
+
export declare const BEACON_OBSERVABLE = "observable";
|
|
115
|
+
export declare const BEACON_SYMBOL: unique symbol;
|
|
116
|
+
export declare const BEACON_TYPE_ERROR = "error";
|
|
117
|
+
export declare const BEACON_TYPE_NEXT = "next";
|
|
118
|
+
export declare const beaconSubscription: SubscriptionProperty;
|
|
119
|
+
//#endregion
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
import { SUBSCRIPTION_NAME } from "./subscription.model.mjs";
|
|
2
|
+
//#region src/models/beacon.model.ts
|
|
3
|
+
const BEACON_MESSAGE_RETRIEVE = "Cannot retrieve observable from a closed beacon";
|
|
4
|
+
const BEACON_MESSAGE_SUBSCRIBE = "Cannot subscribe to a closed observable";
|
|
5
|
+
const BEACON_PROPERTY = "$beacon";
|
|
6
|
+
const BEACON_NAME = "beacon";
|
|
7
|
+
const BEACON_OBSERVABLE = "observable";
|
|
8
|
+
const BEACON_SYMBOL = Symbol(BEACON_PROPERTY);
|
|
9
|
+
const BEACON_TYPE_ERROR = "error";
|
|
10
|
+
const BEACON_TYPE_NEXT = "next";
|
|
11
|
+
const beaconSubscription = {
|
|
12
|
+
key: BEACON_PROPERTY,
|
|
13
|
+
value: SUBSCRIPTION_NAME
|
|
14
|
+
};
|
|
15
|
+
//#endregion
|
|
16
|
+
export { BEACON_MESSAGE_RETRIEVE, BEACON_MESSAGE_SUBSCRIBE, BEACON_NAME, BEACON_OBSERVABLE, BEACON_PROPERTY, BEACON_SYMBOL, BEACON_TYPE_ERROR, BEACON_TYPE_NEXT, beaconSubscription };
|