@oscarpalmer/atoms 0.201.0 → 0.203.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/find.d.mts +10 -11
- package/dist/array/first.d.mts +10 -11
- package/dist/array/flatten.d.mts +2 -3
- package/dist/array/from.d.mts +7 -8
- package/dist/array/group-by.d.mts +16 -185
- 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/move.d.mts +9 -10
- 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/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 +41 -33
- package/dist/array/splice.d.mts +5 -6
- package/dist/array/swap.d.mts +8 -9
- package/dist/array/to-map.d.mts +18 -175
- package/dist/array/to-record.d.mts +18 -175
- 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 +90 -65
- 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 +125 -61
- package/dist/color/misc/alpha.d.mts +4 -5
- 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 +3 -4
- package/dist/color/misc/state.d.mts +8 -10
- package/dist/color/misc/state.mjs +22 -20
- package/dist/color/models.d.mts +25 -19
- package/dist/color/space/hex.d.mts +9 -10
- package/dist/color/space/hsl.d.mts +8 -9
- package/dist/color/space/hwb.d.mts +9 -10
- package/dist/color/space/rgb.d.mts +11 -12
- package/dist/function/limit.d.mts +9 -8
- package/dist/function/limit.mjs +5 -5
- package/dist/function/once.d.mts +26 -6
- package/dist/function/once.mjs +135 -76
- package/dist/function/retry.d.mts +5 -6
- package/dist/function/retry.mjs +3 -3
- package/dist/index.d.mts +244 -584
- package/dist/index.mjs +1191 -810
- package/dist/internal/abort.d.mts +3 -4
- 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/group.d.mts +2 -3
- package/dist/internal/array/index-of.d.mts +10 -11
- 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/limit.d.mts +41 -0
- package/dist/internal/function/limit.mjs +110 -0
- package/dist/internal/function/memoize.d.mts +4 -5
- package/dist/internal/function/memoize.mjs +53 -31
- package/dist/internal/function/misc.d.mts +2 -3
- package/dist/internal/function/work.d.mts +53 -54
- package/dist/internal/herald.d.mts +8 -9
- package/dist/internal/herald.mjs +38 -26
- 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 -0
- 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 +14 -15
- package/dist/internal/subscription.mjs +69 -57
- package/dist/internal/value/compare.d.mts +17 -9
- package/dist/internal/value/compare.mjs +7 -7
- package/dist/internal/value/equal.d.mts +34 -15
- package/dist/internal/value/equal.mjs +28 -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 +50 -50
- package/dist/internal/value/has.d.mts +6 -7
- package/dist/internal/value/misc.d.mts +6 -7
- package/dist/internal/value/partial.d.mts +3 -4
- package/dist/internal/value/set.d.mts +4 -5
- package/dist/is.d.mts +13 -13
- package/dist/logger.d.mts +5 -4
- package/dist/logger.mjs +61 -54
- package/dist/math.d.mts +20 -20
- package/dist/models.d.mts +58 -46
- package/dist/promise/constants.d.mts +14 -15
- package/dist/promise/delay.d.mts +3 -4
- package/dist/promise/delay.mjs +4 -4
- package/dist/promise/helpers.d.mts +7 -8
- package/dist/promise/index.d.mts +13 -14
- package/dist/promise/misc.d.mts +6 -6
- package/dist/promise/models.d.mts +16 -17
- package/dist/promise/timed.d.mts +4 -5
- package/dist/promise/timed.mjs +5 -5
- package/dist/query.d.mts +3 -4
- package/dist/queue.d.mts +14 -15
- package/dist/queue.mjs +185 -129
- package/dist/random.d.mts +8 -8
- package/dist/result/index.d.mts +8 -9
- package/dist/result/match.d.mts +6 -7
- package/dist/result/misc.d.mts +3 -3
- package/dist/result/work/flow.d.mts +28 -29
- package/dist/result/work/pipe.d.mts +24 -25
- package/dist/sized/set.d.mts +2 -3
- package/dist/string/fuzzy.d.mts +21 -12
- package/dist/string/fuzzy.mjs +77 -49
- 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 -4
- package/dist/string/template.d.mts +9 -9
- package/dist/string/template.mjs +11 -4
- package/dist/value/clone.d.mts +21 -13
- package/dist/value/clone.mjs +22 -20
- 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 -1
- package/dist/value/merge.d.mts +13 -14
- package/dist/value/merge.mjs +21 -5
- 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 -7
- package/dist/value/unsmush.d.mts +3 -4
- package/package.json +1 -1
- package/dist/internal/function/timer.d.mts +0 -10
- package/dist/internal/function/timer.mjs +0 -87
|
@@ -1,6 +1,17 @@
|
|
|
1
1
|
import { isNonPlainObject, isPlainObject, isPrimitive, isTypedArray } from "../is.mjs";
|
|
2
|
-
import {
|
|
2
|
+
import { createCompareHandler } from "./handlers.mjs";
|
|
3
3
|
//#region src/internal/value/equal.ts
|
|
4
|
+
function Equalizer(options) {
|
|
5
|
+
Object.defineProperty(this, EQUAL_SYMBOL, { value: options });
|
|
6
|
+
}
|
|
7
|
+
Object.defineProperties(Equalizer.prototype, {
|
|
8
|
+
compare: { value: compare },
|
|
9
|
+
deregister: { value: deregisterEqualizer },
|
|
10
|
+
register: { value: registerEqualizer }
|
|
11
|
+
});
|
|
12
|
+
function compare(first, second) {
|
|
13
|
+
return equalValue(first, second, this[EQUAL_SYMBOL]);
|
|
14
|
+
}
|
|
4
15
|
function createEqualOptions(input) {
|
|
5
16
|
const options = {
|
|
6
17
|
ignoreCase: false,
|
|
@@ -35,7 +46,7 @@ function createEqualOptions(input) {
|
|
|
35
46
|
* @param constructor Class constructor
|
|
36
47
|
*/
|
|
37
48
|
function deregisterEqualizer(constructor) {
|
|
38
|
-
|
|
49
|
+
equalHandler.base.deregister(constructor);
|
|
39
50
|
}
|
|
40
51
|
function filterKey(key, options) {
|
|
41
52
|
if (typeof key !== "string") return true;
|
|
@@ -46,10 +57,6 @@ function filterKey(key, options) {
|
|
|
46
57
|
function equal(first, second, options) {
|
|
47
58
|
return equalValue(first, second, createEqualOptions(options));
|
|
48
59
|
}
|
|
49
|
-
equal.handlers = createCompareHandlers(equal, { callback: Object.is });
|
|
50
|
-
equal.deregister = deregisterEqualizer;
|
|
51
|
-
equal.initialize = initializeEqualizer;
|
|
52
|
-
equal.register = registerEqualizer;
|
|
53
60
|
function equalArray(first, second, options) {
|
|
54
61
|
const { length } = first;
|
|
55
62
|
if (length !== second.length) return false;
|
|
@@ -138,7 +145,7 @@ function equalValue(first, second, options) {
|
|
|
138
145
|
case Array.isArray(first) && Array.isArray(second): return equalArray(first, second, options);
|
|
139
146
|
case isPlainObject(first) && isPlainObject(second): return equalPlainObject(first, second, options);
|
|
140
147
|
case isTypedArray(first) && isTypedArray(second): return equalTypedArray(first, second);
|
|
141
|
-
default: return
|
|
148
|
+
default: return equalHandler.handle(first, second, options);
|
|
142
149
|
}
|
|
143
150
|
}
|
|
144
151
|
/**
|
|
@@ -150,11 +157,7 @@ function equalValue(first, second, options) {
|
|
|
150
157
|
* @returns Equalizer function
|
|
151
158
|
*/
|
|
152
159
|
function initializeEqualizer(options) {
|
|
153
|
-
|
|
154
|
-
const equalizer = (first, second) => equalValue(first, second, actual);
|
|
155
|
-
equalizer.deregister = deregisterEqualizer;
|
|
156
|
-
equalizer.register = registerEqualizer;
|
|
157
|
-
return equalizer;
|
|
160
|
+
return new Equalizer(createEqualOptions(options));
|
|
158
161
|
}
|
|
159
162
|
/**
|
|
160
163
|
* Register a equality comparison function for a specific class
|
|
@@ -165,12 +168,24 @@ function initializeEqualizer(options) {
|
|
|
165
168
|
* @param handler Comparison function
|
|
166
169
|
*/
|
|
167
170
|
function registerEqualizer(constructor, handler) {
|
|
168
|
-
|
|
171
|
+
equalHandler.base.register(constructor, handler);
|
|
169
172
|
}
|
|
170
173
|
const EQUAL_ARRAY_PEEK_PERCENTAGE = 10;
|
|
171
174
|
const EQUAL_ARRAY_THRESHOLD = 100;
|
|
172
175
|
const EQUAL_ERROR_PROPERTIES = ["name", "message"];
|
|
173
176
|
const EQUAL_EXPRESSION_PROPERTIES = ["source", "flags"];
|
|
174
177
|
const EQUAL_MINIMUM_LENGTH_FOR_SET = 16;
|
|
178
|
+
const EQUAL_SYMBOL = Symbol("equal");
|
|
179
|
+
const equalHandler = createCompareHandler(equal, { callback: Object.is });
|
|
180
|
+
equal.deregister = deregisterEqualizer;
|
|
181
|
+
equal.handler = equalHandler;
|
|
182
|
+
equal.initialize = initializeEqualizer;
|
|
183
|
+
equal.register = registerEqualizer;
|
|
184
|
+
Object.defineProperties(equal, {
|
|
185
|
+
deregister: { value: deregisterEqualizer },
|
|
186
|
+
handler: { value: equalHandler },
|
|
187
|
+
initialize: { value: initializeEqualizer },
|
|
188
|
+
register: { value: registerEqualizer }
|
|
189
|
+
});
|
|
175
190
|
//#endregion
|
|
176
191
|
export { deregisterEqualizer, equal, initializeEqualizer, registerEqualizer };
|
|
@@ -17,7 +17,7 @@ import { NestedKeys, NestedValue, PlainObject } from "../../models.mjs";
|
|
|
17
17
|
* getValue(data, 'foo.nope'); // => undefined
|
|
18
18
|
* ```
|
|
19
19
|
*/
|
|
20
|
-
declare function getValue<Data extends PlainObject, Path extends NestedKeys<Data>>(data: Data, path: Path): NestedValue<Data, Path>;
|
|
20
|
+
export declare function getValue<Data extends PlainObject, Path extends NestedKeys<Data>>(data: Data, path: Path): NestedValue<Data, Path>;
|
|
21
21
|
/**
|
|
22
22
|
* Get the value from an object using an unknown path
|
|
23
23
|
*
|
|
@@ -36,6 +36,5 @@ declare function getValue<Data extends PlainObject, Path extends NestedKeys<Data
|
|
|
36
36
|
* getValue(data, 'foo.nope'); // => undefined
|
|
37
37
|
* ```
|
|
38
38
|
*/
|
|
39
|
-
declare function getValue<Data extends PlainObject>(data: Data, path: string, ignoreCase?: boolean): unknown;
|
|
40
|
-
//#endregion
|
|
41
|
-
export { getValue };
|
|
39
|
+
export declare function getValue<Data extends PlainObject>(data: Data, path: string, ignoreCase?: boolean): unknown;
|
|
40
|
+
//#endregion
|
|
@@ -1,18 +1,28 @@
|
|
|
1
1
|
import { Constructor, GenericCallback } from "../../models.mjs";
|
|
2
2
|
//#region src/internal/value/handlers.d.ts
|
|
3
|
-
type
|
|
3
|
+
type BaseHandler = {
|
|
4
|
+
handlers: WeakMap<Constructor, string | GenericCallback>;
|
|
5
|
+
options: BaseHandlerOptions;
|
|
6
|
+
owner: GenericCallback;
|
|
7
|
+
deregister: (constructor: Constructor) => void;
|
|
8
|
+
get: (first: unknown, second: unknown) => string | GenericCallback | undefined;
|
|
9
|
+
register: (constructor: Constructor, handler?: string | GenericCallback) => void;
|
|
10
|
+
};
|
|
11
|
+
type BaseHandlerOptions = {
|
|
4
12
|
callback: GenericCallback;
|
|
5
13
|
method?: string;
|
|
6
14
|
};
|
|
7
|
-
|
|
8
|
-
|
|
15
|
+
type CompareHandler<Value> = {
|
|
16
|
+
base: BaseHandler;
|
|
9
17
|
handle(first: unknown, second: unknown, ...parameters: unknown[]): Value;
|
|
10
|
-
register(constructor: Constructor, handler?: string | GenericCallback): void;
|
|
11
18
|
};
|
|
12
|
-
|
|
13
|
-
|
|
19
|
+
type ValueHandler = {
|
|
20
|
+
base: BaseHandler;
|
|
14
21
|
handle(value: unknown, ...parameters: unknown[]): unknown;
|
|
15
|
-
register(constructor: Constructor, handler?: string | GenericCallback): void;
|
|
16
22
|
};
|
|
17
|
-
|
|
18
|
-
|
|
23
|
+
declare function BaseHandler(this: any, owner: GenericCallback, options: BaseHandlerOptions): void;
|
|
24
|
+
declare function CompareHandler(this: any, base: BaseHandler): void;
|
|
25
|
+
declare function ValueHandler(this: any, value: BaseHandler): void;
|
|
26
|
+
export declare function createCompareHandler<Value>(owner: GenericCallback, options: BaseHandlerOptions): CompareHandler<Value>;
|
|
27
|
+
export declare function createValueHandler(owner: GenericCallback, options: BaseHandlerOptions): ValueHandler;
|
|
28
|
+
//#endregion
|
|
@@ -1,57 +1,57 @@
|
|
|
1
1
|
import { isNonConstructor } from "../is.mjs";
|
|
2
2
|
//#region src/internal/value/handlers.ts
|
|
3
|
-
function
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
return
|
|
40
|
-
deregister(constructor) {
|
|
41
|
-
handlers.deregister(constructor);
|
|
42
|
-
},
|
|
43
|
-
handle(value, ...parameters) {
|
|
44
|
-
const handler = handlers.get(value, value);
|
|
45
|
-
if (handler == null) return options.callback(value, ...parameters);
|
|
46
|
-
return typeof handler === "function" ? handler(value) : value[handler]();
|
|
47
|
-
},
|
|
48
|
-
register(constructor, handler) {
|
|
49
|
-
handlers.register(constructor, handler);
|
|
50
|
-
}
|
|
51
|
-
};
|
|
3
|
+
function BaseHandler(owner, options) {
|
|
4
|
+
this.handlers = /* @__PURE__ */ new WeakMap();
|
|
5
|
+
this.owner = owner;
|
|
6
|
+
this.options = options;
|
|
7
|
+
}
|
|
8
|
+
Object.defineProperties(BaseHandler.prototype, {
|
|
9
|
+
deregister: { value: deregisterHandler },
|
|
10
|
+
get: { value: getHandler },
|
|
11
|
+
register: { value: registerHandler }
|
|
12
|
+
});
|
|
13
|
+
function CompareHandler(base) {
|
|
14
|
+
this.base = base;
|
|
15
|
+
}
|
|
16
|
+
Object.defineProperties(CompareHandler.prototype, { handle: { value: handleComparison } });
|
|
17
|
+
function ValueHandler(value) {
|
|
18
|
+
this.base = value;
|
|
19
|
+
}
|
|
20
|
+
Object.defineProperties(ValueHandler.prototype, { handle: { value: handleValue } });
|
|
21
|
+
function createBaseHandler(owner, options) {
|
|
22
|
+
return new BaseHandler(owner, options);
|
|
23
|
+
}
|
|
24
|
+
function createCompareHandler(owner, options) {
|
|
25
|
+
return new CompareHandler(createBaseHandler(owner, options));
|
|
26
|
+
}
|
|
27
|
+
function createValueHandler(owner, options) {
|
|
28
|
+
return new ValueHandler(createBaseHandler(owner, options));
|
|
29
|
+
}
|
|
30
|
+
function deregisterHandler(value) {
|
|
31
|
+
this.handlers.delete(value);
|
|
32
|
+
}
|
|
33
|
+
function getHandler(first, second) {
|
|
34
|
+
if (isConstructable(first) && isConstructable(second) && first.constructor === second.constructor) return this.handlers.get(first.constructor);
|
|
35
|
+
}
|
|
36
|
+
function handleComparison(first, second, ...parameters) {
|
|
37
|
+
const handler = this.base.get(first, second);
|
|
38
|
+
if (handler == null) return this.base.options.callback(first, second, ...parameters);
|
|
39
|
+
return typeof handler === "function" ? handler(first, second) : first[handler](second);
|
|
52
40
|
}
|
|
53
41
|
function isConstructable(value) {
|
|
54
42
|
return typeof value === "object" && value !== null;
|
|
55
43
|
}
|
|
44
|
+
function registerHandler(constructor, handler) {
|
|
45
|
+
if (isNonConstructor(constructor) || handler === this.owner) return;
|
|
46
|
+
let actual = handler ?? this.options.method;
|
|
47
|
+
if (typeof actual !== "function" && typeof actual !== "string") return;
|
|
48
|
+
if (typeof actual === "string") actual = typeof constructor.prototype[actual] === "function" ? actual : void 0;
|
|
49
|
+
if (actual != null) this.handlers.set(constructor, actual);
|
|
50
|
+
}
|
|
51
|
+
function handleValue(value, ...parameters) {
|
|
52
|
+
const handler = this.base.get(value, value);
|
|
53
|
+
if (handler == null) return this.base.options.callback(value, ...parameters);
|
|
54
|
+
return typeof handler === "function" ? handler(value) : value[handler]();
|
|
55
|
+
}
|
|
56
56
|
//#endregion
|
|
57
|
-
export {
|
|
57
|
+
export { createCompareHandler, createValueHandler };
|
|
@@ -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
|
|
@@ -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<unknown, string>;
|
|
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<unknown, string>;
|
|
7
|
+
export declare function handleValue(data: object, path: string, value: unknown, get: false, ignoreCase: boolean): void;
|
|
8
|
+
//#endregion
|
|
@@ -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
|
|
@@ -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
|
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,46 +1,73 @@
|
|
|
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
|
+
for (const method of methods) {
|
|
9
|
+
const bound = console[method].bind(console);
|
|
10
|
+
Object.defineProperty(this, method, {
|
|
11
|
+
enumerable: true,
|
|
12
|
+
get() {
|
|
13
|
+
return enabled ? bound : noop;
|
|
14
|
+
}
|
|
15
|
+
});
|
|
16
|
+
}
|
|
17
|
+
}
|
|
18
|
+
Lumberjack.prototype[LOGGER_PROPERTY] = LOGGER_NAME;
|
|
19
|
+
Object.defineProperties(Lumberjack.prototype, {
|
|
20
|
+
enabled: {
|
|
21
|
+
enumerable: true,
|
|
22
|
+
get: () => enabled,
|
|
23
|
+
set: (value) => {
|
|
24
|
+
enabled = typeof value === "boolean" ? value : enabled;
|
|
25
|
+
}
|
|
26
|
+
},
|
|
27
|
+
time: { value: (label) => new TimeLogger(getString(label)) }
|
|
28
|
+
});
|
|
29
|
+
function TimeLogger(label) {
|
|
30
|
+
Object.defineProperty(this, LOGGER_SYMBOL, { value: {
|
|
31
|
+
label,
|
|
32
|
+
started: enabled,
|
|
33
|
+
stopped: false
|
|
34
|
+
} });
|
|
35
|
+
this[LOGGER_SYMBOL].isActive = () => {
|
|
36
|
+
return this[LOGGER_SYMBOL].started && !this[LOGGER_SYMBOL].stopped && enabled;
|
|
37
|
+
};
|
|
38
|
+
if (this[LOGGER_SYMBOL].started) console.time(label);
|
|
39
|
+
}
|
|
40
|
+
TimeLogger.prototype[LOGGER_PROPERTY] = LOGGER_NAME_TIMED;
|
|
41
|
+
Object.defineProperties(TimeLogger.prototype, {
|
|
42
|
+
active: {
|
|
43
|
+
enumerable: true,
|
|
44
|
+
get() {
|
|
45
|
+
return this[LOGGER_SYMBOL].isActive();
|
|
46
|
+
}
|
|
47
|
+
},
|
|
48
|
+
log: { get() {
|
|
49
|
+
const state = this[LOGGER_SYMBOL];
|
|
50
|
+
return state.isActive() ? console.timeLog.bind(console, state.label) : noop;
|
|
51
|
+
} },
|
|
52
|
+
stop: { get() {
|
|
53
|
+
const state = this[LOGGER_SYMBOL];
|
|
54
|
+
if (state.isActive()) {
|
|
55
|
+
state.stopped = true;
|
|
56
|
+
return console.timeEnd.bind(console, state.label);
|
|
57
|
+
}
|
|
58
|
+
return noop;
|
|
59
|
+
} }
|
|
60
|
+
});
|
|
4
61
|
function isLogger(value) {
|
|
5
62
|
return isLoggerInstance(LOGGER_NAME, value);
|
|
6
63
|
}
|
|
7
64
|
function isLoggerInstance(name, value) {
|
|
8
65
|
return typeof value === "object" && value !== null && value[LOGGER_PROPERTY] === name;
|
|
9
66
|
}
|
|
10
|
-
function
|
|
67
|
+
function isTimeLogger(value) {
|
|
11
68
|
return isLoggerInstance(LOGGER_NAME_TIMED, value);
|
|
12
69
|
}
|
|
13
|
-
|
|
14
|
-
function stop() {
|
|
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);
|
|
40
|
-
}
|
|
41
|
-
const LOGGER_NAME = "Logger";
|
|
42
|
-
const LOGGER_NAME_TIMED = "TimedLogger";
|
|
43
|
-
const LOGGER_PROPERTY = "$logger";
|
|
70
|
+
const LOGGER_SYMBOL = Symbol(LOGGER_PROPERTY);
|
|
44
71
|
const methods = [
|
|
45
72
|
"debug",
|
|
46
73
|
"dir",
|
|
@@ -56,27 +83,7 @@ const methods = [
|
|
|
56
83
|
*
|
|
57
84
|
* _(Logging can be enabled or disabled by setting the `enabled` property)_
|
|
58
85
|
*/
|
|
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
|
-
})();
|
|
86
|
+
const Logger = new Lumberjack();
|
|
80
87
|
let enabled = true;
|
|
81
88
|
//#endregion
|
|
82
|
-
export { Logger, isLogger,
|
|
89
|
+
export { Logger, isLogger, isTimeLogger };
|