@oscarpalmer/atoms 0.202.0 → 0.204.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 +4 -5
- package/dist/array/exists.d.mts +5 -6
- package/dist/array/filter.d.mts +10 -11
- package/dist/array/filter.mjs +0 -1
- package/dist/array/find.d.mts +10 -11
- package/dist/array/find.mjs +0 -1
- package/dist/array/first.d.mts +10 -11
- package/dist/array/first.mjs +0 -1
- package/dist/array/flatten.d.mts +2 -3
- package/dist/array/from.d.mts +7 -8
- package/dist/array/group-by.d.mts +7 -8
- package/dist/array/group-by.mjs +0 -1
- package/dist/array/insert.d.mts +3 -4
- package/dist/array/intersection.d.mts +4 -5
- package/dist/array/last.d.mts +10 -11
- package/dist/array/last.mjs +0 -1
- package/dist/array/move.d.mts +9 -10
- package/dist/array/move.mjs +0 -4
- package/dist/array/partition.d.mts +5 -6
- package/dist/array/push.d.mts +2 -3
- package/dist/array/reverse.d.mts +2 -3
- package/dist/array/select.d.mts +11 -12
- package/dist/array/select.mjs +0 -1
- package/dist/array/single.d.mts +4 -5
- package/dist/array/slice.d.mts +12 -13
- package/dist/array/sort.d.mts +31 -32
- package/dist/array/sort.mjs +38 -39
- package/dist/array/splice.d.mts +5 -6
- package/dist/array/swap.d.mts +8 -9
- package/dist/array/swap.mjs +0 -1
- package/dist/array/to-map.d.mts +7 -8
- package/dist/array/to-map.mjs +0 -1
- package/dist/array/to-record.d.mts +7 -8
- package/dist/array/to-record.mjs +0 -1
- package/dist/array/to-set.d.mts +4 -5
- package/dist/array/toggle.d.mts +4 -5
- package/dist/array/union.d.mts +4 -5
- package/dist/array/unique.d.mts +4 -5
- package/dist/array/update.d.mts +4 -5
- package/dist/beacon.d.mts +8 -9
- package/dist/beacon.mjs +96 -71
- package/dist/color/constants.d.mts +14 -13
- package/dist/color/constants.mjs +9 -2
- package/dist/color/index.d.mts +2 -2
- package/dist/color/instance.d.mts +3 -3
- package/dist/color/instance.mjs +91 -69
- package/dist/color/misc/alpha.d.mts +7 -6
- package/dist/color/misc/alpha.mjs +8 -2
- package/dist/color/misc/format.d.mts +6 -7
- package/dist/color/misc/format.mjs +15 -12
- package/dist/color/misc/get.d.mts +14 -15
- package/dist/color/misc/is.d.mts +16 -17
- package/dist/color/misc/is.mjs +7 -7
- package/dist/color/misc/state.d.mts +33 -10
- package/dist/color/misc/state.mjs +28 -48
- package/dist/color/models.d.mts +25 -19
- package/dist/color/space/hex.d.mts +14 -11
- package/dist/color/space/hex.mjs +21 -2
- package/dist/color/space/hsl.d.mts +13 -10
- package/dist/color/space/hsl.mjs +25 -4
- package/dist/color/space/hwb.d.mts +14 -11
- package/dist/color/space/hwb.mjs +24 -3
- package/dist/color/space/rgb.d.mts +16 -13
- package/dist/color/space/rgb.mjs +41 -20
- package/dist/function/limit.d.mts +9 -8
- package/dist/function/limit.mjs +5 -7
- package/dist/function/once.d.mts +26 -6
- package/dist/function/once.mjs +129 -76
- package/dist/function/retry.d.mts +5 -6
- package/dist/function/retry.mjs +3 -4
- package/dist/index.d.mts +184 -60
- package/dist/index.mjs +1292 -970
- package/dist/internal/aborter.d.mts +9 -0
- package/dist/internal/{abort.mjs → aborter.mjs} +1 -1
- package/dist/internal/array/callbacks.d.mts +4 -5
- package/dist/internal/array/chunk.d.mts +2 -3
- package/dist/internal/array/compact.d.mts +3 -4
- package/dist/internal/array/find.d.mts +10 -11
- package/dist/internal/array/get.d.mts +7 -8
- package/dist/internal/array/get.mjs +3 -2
- package/dist/internal/array/group.d.mts +2 -3
- package/dist/internal/array/index-of.d.mts +10 -11
- package/dist/internal/array/index-of.mjs +0 -1
- package/dist/internal/array/insert.d.mts +5 -6
- package/dist/internal/array/match.d.mts +17 -18
- package/dist/internal/array/overlap.d.mts +2 -3
- package/dist/internal/array/sets.d.mts +5 -6
- package/dist/internal/array/shuffle.d.mts +2 -3
- package/dist/internal/array/update.d.mts +2 -3
- package/dist/internal/defaults.d.mts +3 -4
- package/dist/internal/function/assert.d.mts +10 -11
- package/dist/internal/function/assert.mjs +0 -7
- package/dist/internal/function/limit.d.mts +41 -0
- package/dist/internal/function/limit.mjs +106 -0
- package/dist/internal/function/memoize.d.mts +4 -5
- package/dist/internal/function/memoize.mjs +55 -31
- package/dist/internal/function/misc.d.mts +2 -3
- package/dist/internal/function/work.d.mts +53 -54
- package/dist/internal/function/work.mjs +0 -2
- package/dist/internal/herald.d.mts +8 -9
- package/dist/internal/herald.mjs +38 -27
- package/dist/internal/is.d.mts +19 -20
- package/dist/internal/math/aggregate.d.mts +14 -15
- package/dist/internal/math/misc.d.mts +3 -4
- package/dist/internal/number.d.mts +4 -5
- package/dist/internal/random.d.mts +3 -4
- package/dist/internal/result/misc.d.mts +29 -14
- package/dist/internal/result/misc.mjs +4 -3
- package/dist/internal/result/models.d.mts +9 -10
- package/dist/internal/sized/map.d.mts +2 -3
- package/dist/internal/sized/misc.d.mts +2 -3
- package/dist/internal/string/case.d.mts +9 -10
- package/dist/internal/string/misc.d.mts +8 -9
- package/dist/internal/subscription.d.mts +10 -11
- package/dist/internal/subscription.mjs +72 -58
- package/dist/internal/value/compare.d.mts +17 -9
- package/dist/internal/value/compare.mjs +6 -11
- package/dist/internal/value/equal.d.mts +34 -15
- package/dist/internal/value/equal.mjs +20 -13
- package/dist/internal/value/get.d.mts +3 -4
- package/dist/internal/value/handlers.d.mts +19 -9
- package/dist/internal/value/handlers.mjs +48 -50
- package/dist/internal/value/has.d.mts +6 -7
- package/dist/internal/value/has.mjs +0 -1
- package/dist/internal/value/misc.d.mts +6 -7
- package/dist/internal/value/misc.mjs +4 -3
- package/dist/internal/value/partial.d.mts +3 -4
- package/dist/internal/value/partial.mjs +2 -1
- package/dist/internal/value/set.d.mts +4 -5
- package/dist/internal/value/set.mjs +2 -1
- package/dist/is.d.mts +13 -13
- package/dist/logger.d.mts +5 -4
- package/dist/logger.mjs +72 -64
- package/dist/math.d.mts +20 -20
- package/dist/models.d.mts +45 -49
- package/dist/promise/constants.d.mts +14 -15
- package/dist/promise/delay.d.mts +3 -4
- package/dist/promise/delay.mjs +5 -5
- package/dist/promise/helpers.d.mts +7 -8
- package/dist/promise/helpers.mjs +4 -3
- package/dist/promise/index.d.mts +13 -14
- package/dist/promise/index.mjs +1 -2
- package/dist/promise/misc.d.mts +7 -7
- package/dist/promise/models.d.mts +17 -18
- package/dist/promise/timed.d.mts +4 -5
- package/dist/promise/timed.mjs +6 -6
- package/dist/query.d.mts +3 -4
- package/dist/queue.d.mts +14 -15
- package/dist/queue.mjs +198 -136
- package/dist/random.d.mts +8 -8
- package/dist/result/index.d.mts +8 -9
- package/dist/result/index.mjs +0 -1
- package/dist/result/match.d.mts +6 -7
- package/dist/result/match.mjs +0 -1
- package/dist/result/misc.d.mts +3 -3
- package/dist/result/work/flow.d.mts +28 -29
- package/dist/result/work/flow.mjs +0 -1
- package/dist/result/work/pipe.d.mts +24 -25
- package/dist/result/work/pipe.mjs +0 -1
- package/dist/sized/set.d.mts +2 -3
- package/dist/string/fuzzy.d.mts +21 -12
- package/dist/string/fuzzy.mjs +77 -52
- package/dist/string/index.d.mts +8 -8
- package/dist/string/match.d.mts +4 -5
- package/dist/string/normalize.d.mts +8 -9
- package/dist/string/normalize.mjs +9 -5
- package/dist/string/template.d.mts +9 -9
- package/dist/string/template.mjs +11 -5
- package/dist/value/clone.d.mts +21 -13
- package/dist/value/clone.mjs +19 -25
- package/dist/value/collection.d.mts +4 -5
- package/dist/value/diff.d.mts +5 -6
- package/dist/value/freeze.d.mts +18 -19
- package/dist/value/freeze.mjs +1 -5
- package/dist/value/merge.d.mts +13 -14
- package/dist/value/merge.mjs +21 -7
- package/dist/value/omit.d.mts +2 -3
- package/dist/value/pick.d.mts +2 -3
- package/dist/value/shake.d.mts +3 -4
- package/dist/value/smush.d.mts +3 -4
- package/dist/value/transform.d.mts +15 -10
- package/dist/value/transform.mjs +12 -8
- package/dist/value/unsmush.d.mts +3 -4
- package/package.json +2 -2
- package/dist/internal/abort.d.mts +0 -10
- package/dist/internal/function/timer.d.mts +0 -10
- package/dist/internal/function/timer.mjs +0 -87
|
@@ -18,7 +18,7 @@ import { Result } from "../result/models.mjs";
|
|
|
18
18
|
* hasValue(data, 'foo.nope'); // => false
|
|
19
19
|
* ```
|
|
20
20
|
*/
|
|
21
|
-
declare function hasValue<Data extends PlainObject, Path extends NestedKeys<Data>>(data: Data, path: Path): boolean;
|
|
21
|
+
export declare function hasValue<Data extends PlainObject, Path extends NestedKeys<Data>>(data: Data, path: Path): boolean;
|
|
22
22
|
/**
|
|
23
23
|
* Check if a property is defined in an object
|
|
24
24
|
*
|
|
@@ -37,8 +37,8 @@ declare function hasValue<Data extends PlainObject, Path extends NestedKeys<Data
|
|
|
37
37
|
* hasValue(data, 'foo.nope'); // => false
|
|
38
38
|
* ```
|
|
39
39
|
*/
|
|
40
|
-
declare function hasValue<Data extends PlainObject>(data: Data, path: string, ignoreCase?: boolean): boolean;
|
|
41
|
-
declare namespace hasValue {
|
|
40
|
+
export declare function hasValue<Data extends PlainObject>(data: Data, path: string, ignoreCase?: boolean): boolean;
|
|
41
|
+
export declare namespace hasValue {
|
|
42
42
|
var get: typeof hasValueResult;
|
|
43
43
|
}
|
|
44
44
|
/**
|
|
@@ -61,7 +61,7 @@ declare namespace hasValue {
|
|
|
61
61
|
* hasValueResult(data, 'foo.nope'); // => {ok: false, error: 'Expected property to exist in object'}
|
|
62
62
|
* ```
|
|
63
63
|
*/
|
|
64
|
-
declare function hasValueResult<Data extends PlainObject, Path extends NestedKeys<Data>>(data: Data, path: Path): Result<NestedValue<Data, ToString<Path>>, string>;
|
|
64
|
+
export declare function hasValueResult<Data extends PlainObject, Path extends NestedKeys<Data>>(data: Data, path: Path): Result<NestedValue<Data, ToString<Path>>, string>;
|
|
65
65
|
/**
|
|
66
66
|
* Check if a property is defined in an object, and get its value if it is
|
|
67
67
|
*
|
|
@@ -82,6 +82,5 @@ declare function hasValueResult<Data extends PlainObject, Path extends NestedKey
|
|
|
82
82
|
* hasValueResult(data, 'foo.nope'); // => {ok: false, error: 'Expected property to exist in object'}
|
|
83
83
|
* ```
|
|
84
84
|
*/
|
|
85
|
-
declare function hasValueResult<Data extends PlainObject>(data: Data, path: string, ignoreCase?: boolean): Result<unknown, string>;
|
|
86
|
-
//#endregion
|
|
87
|
-
export { hasValue, hasValueResult };
|
|
85
|
+
export declare function hasValueResult<Data extends PlainObject>(data: Data, path: string, ignoreCase?: boolean): Result<unknown, string>;
|
|
86
|
+
//#endregion
|
|
@@ -7,6 +7,5 @@ function hasValueResult(data, path, ignoreCase) {
|
|
|
7
7
|
return getNestedValue(data, path, ignoreCase === true);
|
|
8
8
|
}
|
|
9
9
|
hasValue.get = hasValueResult;
|
|
10
|
-
Object.defineProperty(hasValue, "get", { value: hasValueResult });
|
|
11
10
|
//#endregion
|
|
12
11
|
export { hasValue, hasValueResult };
|
|
@@ -1,9 +1,8 @@
|
|
|
1
1
|
import { Result } from "../result/models.mjs";
|
|
2
2
|
//#region src/internal/value/misc.d.ts
|
|
3
|
-
declare function findKey(needle: string, haystack: object): string;
|
|
4
|
-
declare function getNestedValue(data: object, path: string, ignoreCase: boolean): Result<unknown, string>;
|
|
5
|
-
declare function getPaths(path: string, lowercase: boolean): string | string[];
|
|
6
|
-
declare function handleValue(data: object, path: string, value: unknown, get: true, ignoreCase: boolean): Result<
|
|
7
|
-
declare function handleValue(data: object, path: string, value: unknown, get: false, ignoreCase: boolean): void;
|
|
8
|
-
//#endregion
|
|
9
|
-
export { findKey, getNestedValue, getPaths, handleValue };
|
|
3
|
+
export declare function findKey(needle: string, haystack: object): string;
|
|
4
|
+
export declare function getNestedValue(data: object, path: string, ignoreCase: boolean): Result<unknown, string>;
|
|
5
|
+
export declare function getPaths(path: string, lowercase: boolean): string | string[];
|
|
6
|
+
export declare function handleValue(data: object, path: string, value: unknown, get: true, ignoreCase: boolean): Result<object, string>;
|
|
7
|
+
export declare function handleValue(data: object, path: string, value: unknown, get: false, ignoreCase: boolean): void;
|
|
8
|
+
//#endregion
|
|
@@ -30,9 +30,10 @@ function getPaths(path, lowercase) {
|
|
|
30
30
|
function handleValue(data, path, value, get, ignoreCase) {
|
|
31
31
|
if (typeof data === "object" && data !== null) {
|
|
32
32
|
if (ignoreKey(path)) return error(MISC_NESTED_MESSAGE_UNSAFE);
|
|
33
|
-
const
|
|
34
|
-
|
|
35
|
-
|
|
33
|
+
const dataObject = data;
|
|
34
|
+
const key = ignoreCase ? findKey(path, dataObject) : path;
|
|
35
|
+
if (get) return key in dataObject ? ok(dataObject[key]) : error(MISC_NESTED_MESSAGE_MISSING);
|
|
36
|
+
dataObject[key] = typeof value === "function" ? value(dataObject[key]) : value;
|
|
36
37
|
}
|
|
37
38
|
if (get) return error(MISC_NESTED_MESSAGE_MISSING);
|
|
38
39
|
}
|
|
@@ -1,5 +1,4 @@
|
|
|
1
1
|
//#region src/internal/value/partial.d.ts
|
|
2
|
-
declare function partial<Value extends object, ValueKey extends keyof Value>(value: unknown, keys: ValueKey[], omit: true): Omit<Value, ValueKey>;
|
|
3
|
-
declare function partial<Value extends object, ValueKey extends keyof Value>(value: unknown, keys: ValueKey[], omit: false): Pick<Value, ValueKey>;
|
|
4
|
-
//#endregion
|
|
5
|
-
export { partial };
|
|
2
|
+
export declare function partial<Value extends object, ValueKey extends keyof Value>(value: unknown, keys: ValueKey[], omit: true): Omit<Value, ValueKey>;
|
|
3
|
+
export declare function partial<Value extends object, ValueKey extends keyof Value>(value: unknown, keys: ValueKey[], omit: false): Pick<Value, ValueKey>;
|
|
4
|
+
//#endregion
|
|
@@ -1,6 +1,7 @@
|
|
|
1
|
+
import { isPlainObject } from "../is.mjs";
|
|
1
2
|
//#region src/internal/value/partial.ts
|
|
2
3
|
function partial(value, providedKeys, omit) {
|
|
3
|
-
if (
|
|
4
|
+
if (!isPlainObject(value)) return {};
|
|
4
5
|
const keys = omit ? Object.keys(value) : Array.isArray(providedKeys) ? providedKeys : [];
|
|
5
6
|
const { length } = keys;
|
|
6
7
|
if (length === 0) return omit ? value : {};
|
|
@@ -15,7 +15,7 @@ import { NestedKeys, NestedValue, PlainObject } from "../../models.mjs";
|
|
|
15
15
|
* setValue(data, 'foo.bar.baz', (current) => current + 1); // => {foo: {bar: {baz: 43}}}
|
|
16
16
|
* ```
|
|
17
17
|
*/
|
|
18
|
-
declare function setValue<Data extends PlainObject, Path extends NestedKeys<Data>>(data: Data, path: Path, updater: (current: NestedValue<Data, Path>) => NestedValue<Data, Path>): Data;
|
|
18
|
+
export declare function setValue<Data extends PlainObject, Path extends NestedKeys<Data>>(data: Data, path: Path, updater: (current: NestedValue<Data, Path>) => NestedValue<Data, Path>): Data;
|
|
19
19
|
/**
|
|
20
20
|
* Set the value in an object using a known path
|
|
21
21
|
*
|
|
@@ -31,7 +31,7 @@ declare function setValue<Data extends PlainObject, Path extends NestedKeys<Data
|
|
|
31
31
|
* setValue(data, 'foo.bar.baz', 99); // => {foo: {bar: {baz: 99}}}
|
|
32
32
|
* ```
|
|
33
33
|
*/
|
|
34
|
-
declare function setValue<Data extends PlainObject, Path extends NestedKeys<Data>>(data: Data, path: Path, value: NestedValue<Data, Path>): Data;
|
|
34
|
+
export declare function setValue<Data extends PlainObject, Path extends NestedKeys<Data>>(data: Data, path: Path, value: NestedValue<Data, Path>): Data;
|
|
35
35
|
/**
|
|
36
36
|
* Set the value in an object using an unknown path
|
|
37
37
|
*
|
|
@@ -48,6 +48,5 @@ declare function setValue<Data extends PlainObject, Path extends NestedKeys<Data
|
|
|
48
48
|
* setValue(data, 'Foo.Bar.Baz', 99, true); // => {foo: {bar: {baz: 99}}}
|
|
49
49
|
* ```
|
|
50
50
|
*/
|
|
51
|
-
declare function setValue<Data extends PlainObject>(data: Data, path: string, value: unknown, ignoreCase?: boolean): Data;
|
|
52
|
-
//#endregion
|
|
53
|
-
export { setValue };
|
|
51
|
+
export declare function setValue<Data extends PlainObject>(data: Data, path: string, value: unknown, ignoreCase?: boolean): Data;
|
|
52
|
+
//#endregion
|
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import { unwrap } from "../result/misc.mjs";
|
|
1
2
|
import { getPaths, handleValue } from "./misc.mjs";
|
|
2
3
|
//#region src/internal/value/set.ts
|
|
3
4
|
function setValue(data, path, value, ignoreCase) {
|
|
@@ -17,7 +18,7 @@ function setValue(data, path, value, ignoreCase) {
|
|
|
17
18
|
handleValue(target, currentPath, value, false, shouldIgnoreCase);
|
|
18
19
|
break;
|
|
19
20
|
}
|
|
20
|
-
let next = handleValue(target, currentPath, null, true, shouldIgnoreCase)
|
|
21
|
+
let next = unwrap(handleValue(target, currentPath, null, true, shouldIgnoreCase), void 0);
|
|
21
22
|
if (typeof next !== "object" || next === null) {
|
|
22
23
|
const nextPath = paths[index + 1];
|
|
23
24
|
if (SET_EXPRESSION_INDEX.test(nextPath)) next = Array.from({ length: Number(nextPath) + 1 }, () => void 0);
|
package/dist/is.d.mts
CHANGED
|
@@ -6,83 +6,83 @@ import { isArrayOrPlainObject, isConstructor, isInstanceOf, isKey, isNonArrayOrP
|
|
|
6
6
|
* @param value Value to check
|
|
7
7
|
* @returns `true` if the value is considered empty, otherwise `false`
|
|
8
8
|
*/
|
|
9
|
-
declare function isEmpty(value: unknown): boolean;
|
|
9
|
+
export declare function isEmpty(value: unknown): boolean;
|
|
10
10
|
/**
|
|
11
11
|
* Is the value not empty, or holding non-empty values?
|
|
12
12
|
*
|
|
13
13
|
* @param value Value to check
|
|
14
14
|
* @returns `true` if the value is not considered empty, otherwise `false`
|
|
15
15
|
*/
|
|
16
|
-
declare function isNonEmpty(value: unknown): boolean;
|
|
16
|
+
export declare function isNonEmpty(value: unknown): boolean;
|
|
17
17
|
/**
|
|
18
18
|
* Is the value not `undefined` or `null`?
|
|
19
19
|
*
|
|
20
20
|
* @param value Value to check
|
|
21
21
|
* @returns `true` if the value is not `undefined` or `null`, otherwise `false`
|
|
22
22
|
*/
|
|
23
|
-
declare function isNonNullable<Value>(value: Value): value is Exclude<Value, undefined | null>;
|
|
23
|
+
export declare function isNonNullable<Value>(value: Value): value is Exclude<Value, undefined | null>;
|
|
24
24
|
/**
|
|
25
25
|
* Is the value not `undefined`, `null`, or stringified as an empty _(no whitespace)_ string?
|
|
26
26
|
*
|
|
27
27
|
* @param value Value to check
|
|
28
28
|
* @returns `true` if the value is not `undefined`, `null`, or matches an empty string, otherwise `false`
|
|
29
29
|
*/
|
|
30
|
-
declare function isNonNullableOrEmpty<Value>(value: Value): value is Exclude<Value, undefined | null | ''>;
|
|
30
|
+
export declare function isNonNullableOrEmpty<Value>(value: Value): value is Exclude<Value, undefined | null | ''>;
|
|
31
31
|
/**
|
|
32
32
|
* Is the value not `undefined`, `null`, or stringified as a whitespace-only string?
|
|
33
33
|
*
|
|
34
34
|
* @param value Value to check
|
|
35
35
|
* @returns `true` if the value is not `undefined`, `null`, or matches a whitespace-only string, otherwise `false`
|
|
36
36
|
*/
|
|
37
|
-
declare function isNonNullableOrWhitespace<Value>(value: Value): value is Exclude<Value, undefined | null | ''>;
|
|
37
|
+
export declare function isNonNullableOrWhitespace<Value>(value: Value): value is Exclude<Value, undefined | null | ''>;
|
|
38
38
|
/**
|
|
39
39
|
* Is the value not a number or a number-like string?
|
|
40
40
|
*
|
|
41
41
|
* @param value Value to check
|
|
42
42
|
* @returns `true` if the value is not a number or a number-like string, otherwise `false`
|
|
43
43
|
*/
|
|
44
|
-
declare function isNonNumerical<Value>(value: Value): value is Exclude<Value, number | `${number}`>;
|
|
44
|
+
export declare function isNonNumerical<Value>(value: Value): value is Exclude<Value, number | `${number}`>;
|
|
45
45
|
/**
|
|
46
46
|
* Is the value not an object _(or function)_?
|
|
47
47
|
*
|
|
48
48
|
* @param value Value to check
|
|
49
49
|
* @returns `true` if the value is not an object, otherwise `false`
|
|
50
50
|
*/
|
|
51
|
-
declare function isNonObject<Value>(value: Value): value is Exclude<Value, object>;
|
|
51
|
+
export declare function isNonObject<Value>(value: Value): value is Exclude<Value, object>;
|
|
52
52
|
/**
|
|
53
53
|
* Is the value `undefined` or `null`?
|
|
54
54
|
*
|
|
55
55
|
* @param value Value to check
|
|
56
56
|
* @returns `true` if the value is `undefined` or `null`, otherwise `false`
|
|
57
57
|
*/
|
|
58
|
-
declare function isNullable(value: unknown): value is undefined | null;
|
|
58
|
+
export declare function isNullable(value: unknown): value is undefined | null;
|
|
59
59
|
/**
|
|
60
60
|
* Is the value `undefined`, `null`, or stringified as an empty _(no whitespace)_ string?
|
|
61
61
|
*
|
|
62
62
|
* @param value Value to check
|
|
63
63
|
* @returns `true` if the value is nullable or matches an empty string, otherwise `false`
|
|
64
64
|
*/
|
|
65
|
-
declare function isNullableOrEmpty(value: unknown): value is undefined | null | '';
|
|
65
|
+
export declare function isNullableOrEmpty(value: unknown): value is undefined | null | '';
|
|
66
66
|
/**
|
|
67
67
|
* Is the value `undefined`, `null`, or stringified as a whitespace-only string?
|
|
68
68
|
*
|
|
69
69
|
* @param value Value to check
|
|
70
70
|
* @returns `true` if the value is nullable or matches a whitespace-only string, otherwise `false`
|
|
71
71
|
*/
|
|
72
|
-
declare function isNullableOrWhitespace(value: unknown): value is undefined | null | '';
|
|
72
|
+
export declare function isNullableOrWhitespace(value: unknown): value is undefined | null | '';
|
|
73
73
|
/**
|
|
74
74
|
* Is the value a number or a number-like string?
|
|
75
75
|
*
|
|
76
76
|
* @param value Value to check
|
|
77
77
|
* @returns `true` if the value is a number or a number-like string, otherwise `false`
|
|
78
78
|
*/
|
|
79
|
-
declare function isNumerical(value: unknown): value is number | `${number}`;
|
|
79
|
+
export declare function isNumerical(value: unknown): value is number | `${number}`;
|
|
80
80
|
/**
|
|
81
81
|
* Is the value an object _(or function)_?
|
|
82
82
|
*
|
|
83
83
|
* @param value Value to check
|
|
84
84
|
* @returns `true` if the value matches, otherwise `false`
|
|
85
85
|
*/
|
|
86
|
-
declare function isObject(value: unknown): value is object;
|
|
86
|
+
export declare function isObject(value: unknown): value is object;
|
|
87
87
|
//#endregion
|
|
88
|
-
export { isArrayOrPlainObject, isConstructor,
|
|
88
|
+
export { isArrayOrPlainObject, isConstructor, isInstanceOf, isKey, isNonArrayOrPlainObject, isNonConstructor, isNonInstanceOf, isNonKey, isNonNumber, isNonPlainObject, isNonPrimitive, isNonTypedArray, isNumber, isPlainObject, isPrimitive, isTypedArray };
|
package/dist/logger.d.mts
CHANGED
|
@@ -46,12 +46,12 @@ type Logger = {
|
|
|
46
46
|
* @param label Label for the logger
|
|
47
47
|
* @returns _TimedLogger_ instance
|
|
48
48
|
*/
|
|
49
|
-
time(label: string):
|
|
49
|
+
time(label: string): TimeLogger;
|
|
50
50
|
};
|
|
51
51
|
/**
|
|
52
52
|
* A named timer that can be used to log durations to the console
|
|
53
53
|
*/
|
|
54
|
-
type
|
|
54
|
+
type TimeLogger = {
|
|
55
55
|
/**
|
|
56
56
|
* Is the timer active? _(i.e. has it been started and not stopped, and is logging enabled?)_
|
|
57
57
|
*/
|
|
@@ -67,8 +67,9 @@ type TimedLogger = {
|
|
|
67
67
|
*/
|
|
68
68
|
get stop(): () => void;
|
|
69
69
|
};
|
|
70
|
+
declare function TimeLogger(this: any, label: string): void;
|
|
70
71
|
declare function isLogger(value: unknown): value is Logger;
|
|
71
|
-
declare function
|
|
72
|
+
declare function isTimeLogger(value: unknown): value is TimeLogger;
|
|
72
73
|
/**
|
|
73
74
|
* A logger that can be used to log messages to the console
|
|
74
75
|
*
|
|
@@ -76,4 +77,4 @@ declare function isTimedLogger(value: unknown): value is TimedLogger;
|
|
|
76
77
|
*/
|
|
77
78
|
declare const Logger: Logger;
|
|
78
79
|
//#endregion
|
|
79
|
-
export { Logger, type
|
|
80
|
+
export { Logger, type TimeLogger, isLogger, isTimeLogger };
|
package/dist/logger.mjs
CHANGED
|
@@ -1,82 +1,90 @@
|
|
|
1
1
|
import { noop } from "./internal/function/misc.mjs";
|
|
2
2
|
import { getString } from "./internal/string/misc.mjs";
|
|
3
3
|
//#region src/logger.ts
|
|
4
|
+
const LOGGER_NAME = "Logger";
|
|
5
|
+
const LOGGER_NAME_TIMED = "TimedLogger";
|
|
6
|
+
const LOGGER_PROPERTY = "$logger";
|
|
7
|
+
function Lumberjack() {}
|
|
8
|
+
Lumberjack.prototype[LOGGER_PROPERTY] = LOGGER_NAME;
|
|
9
|
+
Lumberjack.prototype.time = getTimeLogger;
|
|
10
|
+
Object.defineProperties(Lumberjack.prototype, {
|
|
11
|
+
debug: { get: getLoggerCallback.bind("debug") },
|
|
12
|
+
dir: { get: getLoggerCallback.bind("dir") },
|
|
13
|
+
error: { get: getLoggerCallback.bind("error") },
|
|
14
|
+
enabled: {
|
|
15
|
+
enumerable: true,
|
|
16
|
+
get: getLoggerEnabled,
|
|
17
|
+
set: setLoggerEnabled
|
|
18
|
+
},
|
|
19
|
+
info: { get: getLoggerCallback.bind("info") },
|
|
20
|
+
log: { get: getLoggerCallback.bind("log") },
|
|
21
|
+
table: { get: getLoggerCallback.bind("table") },
|
|
22
|
+
trace: { get: getLoggerCallback.bind("trace") },
|
|
23
|
+
warn: { get: getLoggerCallback.bind("warn") }
|
|
24
|
+
});
|
|
25
|
+
function TimeLogger(label) {
|
|
26
|
+
this[LOGGER_SYMBOL] = {
|
|
27
|
+
label,
|
|
28
|
+
started: enabled,
|
|
29
|
+
stopped: false
|
|
30
|
+
};
|
|
31
|
+
this[LOGGER_SYMBOL].isActive = () => {
|
|
32
|
+
return enabled && this[LOGGER_SYMBOL].started && !this[LOGGER_SYMBOL].stopped;
|
|
33
|
+
};
|
|
34
|
+
if (this[LOGGER_SYMBOL].started) console.time(label);
|
|
35
|
+
}
|
|
36
|
+
TimeLogger.prototype[LOGGER_PROPERTY] = LOGGER_NAME_TIMED;
|
|
37
|
+
Object.defineProperties(TimeLogger.prototype, {
|
|
38
|
+
active: {
|
|
39
|
+
enumerable: true,
|
|
40
|
+
get: getTimeLoggerActive
|
|
41
|
+
},
|
|
42
|
+
log: { get: getTimerLoggerLog },
|
|
43
|
+
stop: { get: getTimeLoggerStop }
|
|
44
|
+
});
|
|
45
|
+
function getLoggerCallback() {
|
|
46
|
+
return enabled ? console[this].bind(console) : noop;
|
|
47
|
+
}
|
|
48
|
+
function getLoggerEnabled() {
|
|
49
|
+
return enabled;
|
|
50
|
+
}
|
|
51
|
+
function getTimeLogger(label) {
|
|
52
|
+
return new TimeLogger(getString(label));
|
|
53
|
+
}
|
|
54
|
+
function getTimeLoggerActive() {
|
|
55
|
+
return this[LOGGER_SYMBOL].isActive();
|
|
56
|
+
}
|
|
57
|
+
function getTimerLoggerLog() {
|
|
58
|
+
const state = this[LOGGER_SYMBOL];
|
|
59
|
+
return state.isActive() ? console.timeLog.bind(console, state.label) : noop;
|
|
60
|
+
}
|
|
61
|
+
function getTimeLoggerStop() {
|
|
62
|
+
const state = this[LOGGER_SYMBOL];
|
|
63
|
+
if (state.isActive()) {
|
|
64
|
+
state.stopped = true;
|
|
65
|
+
return console.timeEnd.bind(console, state.label);
|
|
66
|
+
}
|
|
67
|
+
return noop;
|
|
68
|
+
}
|
|
4
69
|
function isLogger(value) {
|
|
5
70
|
return isLoggerInstance(LOGGER_NAME, value);
|
|
6
71
|
}
|
|
7
72
|
function isLoggerInstance(name, value) {
|
|
8
|
-
return typeof value === "object" && value !== null && value[LOGGER_PROPERTY] === name;
|
|
73
|
+
return typeof value === "object" && value !== null && LOGGER_PROPERTY in value && value[LOGGER_PROPERTY] === name;
|
|
9
74
|
}
|
|
10
|
-
function
|
|
75
|
+
function isTimeLogger(value) {
|
|
11
76
|
return isLoggerInstance(LOGGER_NAME_TIMED, value);
|
|
12
77
|
}
|
|
13
|
-
function
|
|
14
|
-
|
|
15
|
-
const fn = stopper;
|
|
16
|
-
state.stopped = true;
|
|
17
|
-
logger = void 0;
|
|
18
|
-
stopper = void 0;
|
|
19
|
-
return fn;
|
|
20
|
-
}
|
|
21
|
-
let logger = console.timeLog.bind(console, label);
|
|
22
|
-
let stopper = console.timeEnd.bind(console, label);
|
|
23
|
-
const state = {
|
|
24
|
-
label,
|
|
25
|
-
started: enabled,
|
|
26
|
-
stopped: false
|
|
27
|
-
};
|
|
28
|
-
const instance = {};
|
|
29
|
-
Object.defineProperties(instance, {
|
|
30
|
-
[LOGGER_PROPERTY]: { value: LOGGER_NAME_TIMED },
|
|
31
|
-
active: {
|
|
32
|
-
enumerable: true,
|
|
33
|
-
get: () => state.started && !state.stopped && enabled
|
|
34
|
-
},
|
|
35
|
-
log: { get: () => instance.active ? logger : noop },
|
|
36
|
-
stop: { get: () => instance.active ? stop() : noop }
|
|
37
|
-
});
|
|
38
|
-
if (state.started) console.time(label);
|
|
39
|
-
return Object.freeze(instance);
|
|
78
|
+
function setLoggerEnabled(value) {
|
|
79
|
+
enabled = typeof value === "boolean" ? value : enabled;
|
|
40
80
|
}
|
|
41
|
-
const
|
|
42
|
-
const LOGGER_NAME_TIMED = "TimedLogger";
|
|
43
|
-
const LOGGER_PROPERTY = "$logger";
|
|
44
|
-
const methods = [
|
|
45
|
-
"debug",
|
|
46
|
-
"dir",
|
|
47
|
-
"error",
|
|
48
|
-
"info",
|
|
49
|
-
"log",
|
|
50
|
-
"table",
|
|
51
|
-
"trace",
|
|
52
|
-
"warn"
|
|
53
|
-
];
|
|
81
|
+
const LOGGER_SYMBOL = Symbol(LOGGER_PROPERTY);
|
|
54
82
|
/**
|
|
55
83
|
* A logger that can be used to log messages to the console
|
|
56
84
|
*
|
|
57
85
|
* _(Logging can be enabled or disabled by setting the `enabled` property)_
|
|
58
86
|
*/
|
|
59
|
-
const Logger = (
|
|
60
|
-
const instance = {};
|
|
61
|
-
Object.defineProperties(instance, {
|
|
62
|
-
[LOGGER_PROPERTY]: { value: LOGGER_NAME },
|
|
63
|
-
enabled: {
|
|
64
|
-
enumerable: true,
|
|
65
|
-
get: () => enabled,
|
|
66
|
-
set: (value) => {
|
|
67
|
-
enabled = typeof value === "boolean" ? value : enabled;
|
|
68
|
-
}
|
|
69
|
-
},
|
|
70
|
-
time: { value: (label) => timedLogger(getString(label)) }
|
|
71
|
-
});
|
|
72
|
-
for (const method of methods) Object.defineProperty(instance, method, {
|
|
73
|
-
enumerable: true,
|
|
74
|
-
get() {
|
|
75
|
-
return enabled ? console[method].bind(console) : noop;
|
|
76
|
-
}
|
|
77
|
-
});
|
|
78
|
-
return Object.freeze(instance);
|
|
79
|
-
})();
|
|
87
|
+
const Logger = new Lumberjack();
|
|
80
88
|
let enabled = true;
|
|
81
89
|
//#endregion
|
|
82
|
-
export { Logger, isLogger,
|
|
90
|
+
export { Logger, isLogger, isTimeLogger };
|
package/dist/math.d.mts
CHANGED
|
@@ -9,7 +9,7 @@ import { round } from "./internal/math/misc.mjs";
|
|
|
9
9
|
* @param callback Callback to get an item's value
|
|
10
10
|
* @returns Average value, or `Number.NaN` if no average can be calculated
|
|
11
11
|
*/
|
|
12
|
-
declare function average<Item>(items: Item[], callback: (item: Item, index: number, array: Item[]) => number): number;
|
|
12
|
+
export declare function average<Item>(items: Item[], callback: (item: Item, index: number, array: Item[]) => number): number;
|
|
13
13
|
/**
|
|
14
14
|
* Get the average value from a list of items
|
|
15
15
|
*
|
|
@@ -17,14 +17,14 @@ declare function average<Item>(items: Item[], callback: (item: Item, index: numb
|
|
|
17
17
|
* @param key Key to use for value
|
|
18
18
|
* @returns Average value, or `Number.NaN` if no average can be calculated
|
|
19
19
|
*/
|
|
20
|
-
declare function average<Item extends PlainObject>(items: Item[], key: keyof NumericalValues<Item>): number;
|
|
20
|
+
export declare function average<Item extends PlainObject>(items: Item[], key: keyof NumericalValues<Item>): number;
|
|
21
21
|
/**
|
|
22
22
|
* Get the average value from a list of numbers
|
|
23
23
|
*
|
|
24
24
|
* @param numbers List of numbers
|
|
25
25
|
* @returns Average value, or `Number.NaN` if no average can be calculated
|
|
26
26
|
*/
|
|
27
|
-
declare function average(numbers: number[]): number;
|
|
27
|
+
export declare function average(numbers: number[]): number;
|
|
28
28
|
/**
|
|
29
29
|
* Round a number up
|
|
30
30
|
*
|
|
@@ -32,7 +32,7 @@ declare function average(numbers: number[]): number;
|
|
|
32
32
|
* @param decimals Number of decimal places to round to _(defaults to `0`)_
|
|
33
33
|
* @returns Rounded number, or `Number.NaN` if the value if unable to be rounded
|
|
34
34
|
*/
|
|
35
|
-
declare function ceil(value: number, decimals?: number): number;
|
|
35
|
+
export declare function ceil(value: number, decimals?: number): number;
|
|
36
36
|
/**
|
|
37
37
|
* Count the number of items in an array that match a specific value
|
|
38
38
|
*
|
|
@@ -41,7 +41,7 @@ declare function ceil(value: number, decimals?: number): number;
|
|
|
41
41
|
* @param value Value to match and count
|
|
42
42
|
* @returns Number of items that match the condition, or `Number.NaN` if no count can be calculated
|
|
43
43
|
*/
|
|
44
|
-
declare function count<Item>(array: Item[], callback: (item: Item, index: number, array: Item[]) => unknown, value: unknown): number;
|
|
44
|
+
export declare function count<Item>(array: Item[], callback: (item: Item, index: number, array: Item[]) => unknown, value: unknown): number;
|
|
45
45
|
/**
|
|
46
46
|
* Count the number of items in an array that have a specific value
|
|
47
47
|
*
|
|
@@ -50,14 +50,14 @@ declare function count<Item>(array: Item[], callback: (item: Item, index: number
|
|
|
50
50
|
* @param value Value to match and count
|
|
51
51
|
* @returns Number of items with the specified key value, or `Number.NaN` if no count can be calculated
|
|
52
52
|
*/
|
|
53
|
-
declare function count<Item extends PlainObject, ItemKey extends keyof Item>(array: Item[], key: ItemKey, value: Item[ItemKey]): number;
|
|
53
|
+
export declare function count<Item extends PlainObject, ItemKey extends keyof Item>(array: Item[], key: ItemKey, value: Item[ItemKey]): number;
|
|
54
54
|
/**
|
|
55
55
|
* Count the number of items in an array
|
|
56
56
|
*
|
|
57
57
|
* @param values Array to count for
|
|
58
58
|
* @returns Number of items, or `Number.NaN` if no count can be calculated
|
|
59
59
|
*/
|
|
60
|
-
declare function count(values: unknown[]): number;
|
|
60
|
+
export declare function count(values: unknown[]): number;
|
|
61
61
|
/**
|
|
62
62
|
* Round a number down
|
|
63
63
|
*
|
|
@@ -65,7 +65,7 @@ declare function count(values: unknown[]): number;
|
|
|
65
65
|
* @param decimals Number of decimal places to round to _(defaults to `0`)_
|
|
66
66
|
* @returns Rounded number, or `Number.NaN` if the value if unable to be rounded
|
|
67
67
|
*/
|
|
68
|
-
declare function floor(value: number, decimals?: number): number;
|
|
68
|
+
export declare function floor(value: number, decimals?: number): number;
|
|
69
69
|
/**
|
|
70
70
|
* Get the median value from a list of items
|
|
71
71
|
*
|
|
@@ -73,7 +73,7 @@ declare function floor(value: number, decimals?: number): number;
|
|
|
73
73
|
* @param callback Callback to get an item's value
|
|
74
74
|
* @returns Median value, or `Number.NaN` if no median can be calculated
|
|
75
75
|
*/
|
|
76
|
-
declare function median<Item>(array: Item[], callback: (item: Item, index: number, array: Item[]) => number): number;
|
|
76
|
+
export declare function median<Item>(array: Item[], callback: (item: Item, index: number, array: Item[]) => number): number;
|
|
77
77
|
/**
|
|
78
78
|
* Get the median value from a list of items
|
|
79
79
|
*
|
|
@@ -81,14 +81,14 @@ declare function median<Item>(array: Item[], callback: (item: Item, index: numbe
|
|
|
81
81
|
* @param key Key to use for value
|
|
82
82
|
* @returns Median value, or `Number.NaN` if no median can be calculated
|
|
83
83
|
*/
|
|
84
|
-
declare function median<Item extends PlainObject>(array: Item[], key: keyof NumericalValues<Item>): number;
|
|
84
|
+
export declare function median<Item extends PlainObject>(array: Item[], key: keyof NumericalValues<Item>): number;
|
|
85
85
|
/**
|
|
86
86
|
* Get the median value from a list of numbers
|
|
87
87
|
*
|
|
88
88
|
* @param array List of numbers
|
|
89
89
|
* @returns Median value, or `Number.NaN` if no median can be calculated
|
|
90
90
|
*/
|
|
91
|
-
declare function median(array: number[]): number;
|
|
91
|
+
export declare function median(array: number[]): number;
|
|
92
92
|
/**
|
|
93
93
|
* Get the minimum value from a list of items
|
|
94
94
|
*
|
|
@@ -97,7 +97,7 @@ declare function median(array: number[]): number;
|
|
|
97
97
|
* @param first Return only the first item with the minimum value
|
|
98
98
|
* @returns First item with the minimum value, or `undefined` if no minimum can be found
|
|
99
99
|
*/
|
|
100
|
-
declare function min<Item>(items: Item[], callback: (item: Item, index: number, array: Item[]) => number, first: true): Item | undefined;
|
|
100
|
+
export declare function min<Item>(items: Item[], callback: (item: Item, index: number, array: Item[]) => number, first: true): Item | undefined;
|
|
101
101
|
/**
|
|
102
102
|
* Get the minimum value from a list of items
|
|
103
103
|
*
|
|
@@ -106,7 +106,7 @@ declare function min<Item>(items: Item[], callback: (item: Item, index: number,
|
|
|
106
106
|
* @param first Return only the first item with the minimum value
|
|
107
107
|
* @returns First item with the minimum value, or `undefined` if no minimum can be found
|
|
108
108
|
*/
|
|
109
|
-
declare function min<Item extends PlainObject>(items: Item[], key: keyof NumericalValues<Item>, first: true): Item | undefined;
|
|
109
|
+
export declare function min<Item extends PlainObject>(items: Item[], key: keyof NumericalValues<Item>, first: true): Item | undefined;
|
|
110
110
|
/**
|
|
111
111
|
* Get the minimum value from a list of items
|
|
112
112
|
*
|
|
@@ -114,7 +114,7 @@ declare function min<Item extends PlainObject>(items: Item[], key: keyof Numeric
|
|
|
114
114
|
* @param callback Callback to get an item's value
|
|
115
115
|
* @returns Items with the minimum value
|
|
116
116
|
*/
|
|
117
|
-
declare function min<Item>(items: Item[], callback: (item: Item, index: number, array: Item[]) => number): Item[];
|
|
117
|
+
export declare function min<Item>(items: Item[], callback: (item: Item, index: number, array: Item[]) => number): Item[];
|
|
118
118
|
/**
|
|
119
119
|
* Get the minimum value from a list of items
|
|
120
120
|
*
|
|
@@ -122,14 +122,14 @@ declare function min<Item>(items: Item[], callback: (item: Item, index: number,
|
|
|
122
122
|
* @param key Key to use for value
|
|
123
123
|
* @returns Items with the minimum value
|
|
124
124
|
*/
|
|
125
|
-
declare function min<Item extends PlainObject>(items: Item[], key: keyof NumericalValues<Item>): Item[];
|
|
125
|
+
export declare function min<Item extends PlainObject>(items: Item[], key: keyof NumericalValues<Item>): Item[];
|
|
126
126
|
/**
|
|
127
127
|
* Get the minimum value from a list of numbers
|
|
128
128
|
*
|
|
129
129
|
* @param values List of numbers
|
|
130
130
|
* @returns Minimum value, or `Number.NaN` if no minimum can be found
|
|
131
131
|
*/
|
|
132
|
-
declare function min(values: number[]): number;
|
|
132
|
+
export declare function min(values: number[]): number;
|
|
133
133
|
/**
|
|
134
134
|
* Get the sum of a list of items
|
|
135
135
|
*
|
|
@@ -137,7 +137,7 @@ declare function min(values: number[]): number;
|
|
|
137
137
|
* @param callback Callback to get an item's value
|
|
138
138
|
* @returns Sum of the values, or `Number.NaN` if no sum can be calculated
|
|
139
139
|
*/
|
|
140
|
-
declare function sum<Item>(items: Item[], callback: (item: Item, index: number, array: Item[]) => number): number;
|
|
140
|
+
export declare function sum<Item>(items: Item[], callback: (item: Item, index: number, array: Item[]) => number): number;
|
|
141
141
|
/**
|
|
142
142
|
* Get the sum of a list of items
|
|
143
143
|
*
|
|
@@ -145,13 +145,13 @@ declare function sum<Item>(items: Item[], callback: (item: Item, index: number,
|
|
|
145
145
|
* @param key Key to use for value
|
|
146
146
|
* @returns Sum of the values, or `Number.NaN` if no sum can be calculated
|
|
147
147
|
*/
|
|
148
|
-
declare function sum<Item extends PlainObject>(items: Item[], key: keyof NumericalValues<Item>): number;
|
|
148
|
+
export declare function sum<Item extends PlainObject>(items: Item[], key: keyof NumericalValues<Item>): number;
|
|
149
149
|
/**
|
|
150
150
|
* Get the sum of a list of numbers
|
|
151
151
|
*
|
|
152
152
|
* @param values List of numbers
|
|
153
153
|
* @returns Sum of the numbers, or `Number.NaN` if no sum can be calculated
|
|
154
154
|
*/
|
|
155
|
-
declare function sum(values: number[]): number;
|
|
155
|
+
export declare function sum(values: number[]): number;
|
|
156
156
|
//#endregion
|
|
157
|
-
export {
|
|
157
|
+
export { max, round };
|