@oscarpalmer/atoms 0.197.0 → 0.199.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/beacon.mjs +46 -43
- package/dist/color/instance.mjs +14 -10
- package/dist/function/retry.mjs +6 -8
- package/dist/index.d.mts +826 -710
- package/dist/index.mjs +381 -295
- package/dist/internal/array/find.d.mts +2 -2
- package/dist/internal/array/find.mjs +11 -11
- package/dist/internal/function/memoize.mjs +4 -3
- package/dist/internal/function/timer.mjs +3 -5
- package/dist/internal/herald.mjs +26 -23
- package/dist/internal/subscription.d.mts +72 -16
- package/dist/internal/subscription.mjs +94 -29
- package/dist/internal/value/compare.mjs +2 -2
- package/dist/internal/value/equal.mjs +30 -30
- package/dist/internal/value/handlers.d.mts +3 -3
- package/dist/internal/value/handlers.mjs +6 -6
- package/dist/promise/delay.mjs +2 -2
- package/dist/promise/helpers.d.mts +3 -3
- package/dist/promise/helpers.mjs +4 -4
- package/dist/promise/index.mjs +3 -3
- package/dist/promise/timed.mjs +2 -2
- package/dist/queue.mjs +3 -3
- package/dist/string/fuzzy.mjs +18 -18
- package/dist/string/normalize.mjs +12 -12
- package/dist/string/template.mjs +8 -8
- package/dist/subscription.d.mts +2 -2
- package/dist/subscription.mjs +2 -2
- package/dist/value/clone.d.mts +40 -13
- package/dist/value/clone.mjs +89 -72
- package/dist/value/merge.mjs +5 -5
- package/package.json +3 -2
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { isNonConstructor } from "../is.mjs";
|
|
2
2
|
//#region src/internal/value/handlers.ts
|
|
3
|
-
function
|
|
4
|
-
const handlers =
|
|
3
|
+
function createCompareHandlers(owner, options) {
|
|
4
|
+
const handlers = createHandlers(owner, options);
|
|
5
5
|
return {
|
|
6
6
|
deregister(constructor) {
|
|
7
7
|
handlers.deregister(constructor);
|
|
@@ -16,7 +16,7 @@ function getCompareHandlers(owner, options) {
|
|
|
16
16
|
}
|
|
17
17
|
};
|
|
18
18
|
}
|
|
19
|
-
function
|
|
19
|
+
function createHandlers(owner, options) {
|
|
20
20
|
const handlers = /* @__PURE__ */ new WeakMap();
|
|
21
21
|
return {
|
|
22
22
|
deregister(constructor) {
|
|
@@ -34,8 +34,8 @@ function getHandlers(owner, options) {
|
|
|
34
34
|
}
|
|
35
35
|
};
|
|
36
36
|
}
|
|
37
|
-
function
|
|
38
|
-
const handlers =
|
|
37
|
+
function createSelfHandlers(owner, options) {
|
|
38
|
+
const handlers = createHandlers(owner, options);
|
|
39
39
|
return {
|
|
40
40
|
deregister(constructor) {
|
|
41
41
|
handlers.deregister(constructor);
|
|
@@ -54,4 +54,4 @@ function isConstructable(value) {
|
|
|
54
54
|
return typeof value === "object" && value !== null;
|
|
55
55
|
}
|
|
56
56
|
//#endregion
|
|
57
|
-
export {
|
|
57
|
+
export { createCompareHandlers, createSelfHandlers };
|
package/dist/promise/delay.mjs
CHANGED
|
@@ -1,10 +1,10 @@
|
|
|
1
1
|
import { createAborter } from "../internal/abort.mjs";
|
|
2
2
|
import { TIMER_WAIT, getTimer } from "../internal/function/timer.mjs";
|
|
3
|
-
import {
|
|
3
|
+
import { createPromiseOptions } from "./helpers.mjs";
|
|
4
4
|
import { settlePromise } from "./misc.mjs";
|
|
5
5
|
//#region src/promise/delay.ts
|
|
6
6
|
function delay(options) {
|
|
7
|
-
const { signal, time } =
|
|
7
|
+
const { signal, time } = createPromiseOptions(options);
|
|
8
8
|
if (signal?.aborted ?? false) return Promise.reject(signal?.reason);
|
|
9
9
|
const aborter = createAborter(signal, () => {
|
|
10
10
|
timer.cancel();
|
|
@@ -2,8 +2,8 @@ import { RequiredKeys } from "../models.mjs";
|
|
|
2
2
|
import { Result } from "../internal/result/models.mjs";
|
|
3
3
|
import { FulfilledPromise, PromiseOptions, PromiseStrategy, PromisesOptions, PromisesValue, RejectedPromise } from "./models.mjs";
|
|
4
4
|
//#region src/promise/helpers.d.ts
|
|
5
|
-
declare function
|
|
6
|
-
declare function
|
|
5
|
+
declare function createPromiseOptions(input: unknown): RequiredKeys<PromiseOptions, 'time'>;
|
|
6
|
+
declare function createPromisesOptions(input: unknown): RequiredKeys<PromisesOptions, 'strategy'>;
|
|
7
7
|
declare function getResultsFromPromises<Value>(promised: PromisesValue<Value>[]): Result<Value>[];
|
|
8
8
|
declare function getStrategyOrDefault(value: unknown): PromiseStrategy;
|
|
9
9
|
/**
|
|
@@ -21,4 +21,4 @@ declare function isFulfilled<Value>(value: unknown): value is FulfilledPromise<V
|
|
|
21
21
|
*/
|
|
22
22
|
declare function isRejected(value: unknown): value is RejectedPromise;
|
|
23
23
|
//#endregion
|
|
24
|
-
export {
|
|
24
|
+
export { createPromiseOptions, createPromisesOptions, getResultsFromPromises, getStrategyOrDefault, isFulfilled, isRejected };
|
package/dist/promise/helpers.mjs
CHANGED
|
@@ -1,8 +1,8 @@
|
|
|
1
|
-
import { error, ok } from "../internal/result/misc.mjs";
|
|
2
1
|
import { getNumberOrDefault } from "../internal/defaults.mjs";
|
|
2
|
+
import { error, ok } from "../internal/result/misc.mjs";
|
|
3
3
|
import { PROMISE_STRATEGY_ALL, PROMISE_STRATEGY_DEFAULT, PROMISE_TYPE_FULFILLED, PROMISE_TYPE_REJECTED } from "./constants.mjs";
|
|
4
4
|
//#region src/promise/helpers.ts
|
|
5
|
-
function
|
|
5
|
+
function createPromiseOptions(input) {
|
|
6
6
|
if (typeof input === "number") return { time: getNumberOrDefault(input, 0) };
|
|
7
7
|
if (input instanceof AbortSignal) return {
|
|
8
8
|
signal: input,
|
|
@@ -14,7 +14,7 @@ function getPromiseOptions(input) {
|
|
|
14
14
|
time: getNumberOrDefault(options.time, 0)
|
|
15
15
|
};
|
|
16
16
|
}
|
|
17
|
-
function
|
|
17
|
+
function createPromisesOptions(input) {
|
|
18
18
|
if (typeof input === "string") return { strategy: getStrategyOrDefault(input) };
|
|
19
19
|
if (input instanceof AbortSignal) return {
|
|
20
20
|
signal: input,
|
|
@@ -54,4 +54,4 @@ function isType(value, type) {
|
|
|
54
54
|
return typeof value === "object" && value !== null && value.status === type;
|
|
55
55
|
}
|
|
56
56
|
//#endregion
|
|
57
|
-
export {
|
|
57
|
+
export { createPromiseOptions, createPromisesOptions, getResultsFromPromises, getStrategyOrDefault, isFulfilled, isRejected };
|
package/dist/promise/index.mjs
CHANGED
|
@@ -1,13 +1,13 @@
|
|
|
1
1
|
import { createAborter } from "../internal/abort.mjs";
|
|
2
2
|
import { PROMISE_MESSAGE_EXPECTATION_ATTEMPT, PROMISE_STRATEGY_DEFAULT, PROMISE_TYPE_FULFILLED, PROMISE_TYPE_REJECTED } from "./constants.mjs";
|
|
3
|
-
import {
|
|
3
|
+
import { createPromiseOptions, createPromisesOptions, getResultsFromPromises } from "./helpers.mjs";
|
|
4
4
|
import { handleResult, settlePromise } from "./misc.mjs";
|
|
5
5
|
import { getTimedPromise } from "./timed.mjs";
|
|
6
6
|
//#region src/promise/index.ts
|
|
7
7
|
async function attemptPromise(value, options) {
|
|
8
8
|
const isFunction = typeof value === "function";
|
|
9
9
|
if (!isFunction && !(value instanceof Promise)) return Promise.reject(new TypeError(PROMISE_MESSAGE_EXPECTATION_ATTEMPT));
|
|
10
|
-
const { signal, time } =
|
|
10
|
+
const { signal, time } = createPromiseOptions(options);
|
|
11
11
|
if (signal?.aborted ?? false) return Promise.reject(signal?.reason);
|
|
12
12
|
const aborter = createAborter(signal, () => {
|
|
13
13
|
rejector(signal?.reason);
|
|
@@ -29,7 +29,7 @@ async function attemptPromise(value, options) {
|
|
|
29
29
|
return time > 0 ? getTimedPromise(promise, time, signal) : promise;
|
|
30
30
|
}
|
|
31
31
|
async function promises(items, options) {
|
|
32
|
-
const { signal, strategy } =
|
|
32
|
+
const { signal, strategy } = createPromisesOptions(options);
|
|
33
33
|
if (signal?.aborted ?? false) return Promise.reject(signal?.reason);
|
|
34
34
|
if (!Array.isArray(items)) return Promise.resolve([]);
|
|
35
35
|
const actual = items.map((item) => typeof item === "function" ? item() : item).filter((item) => item instanceof Promise);
|
package/dist/promise/timed.mjs
CHANGED
|
@@ -2,7 +2,7 @@ import { createAborter } from "../internal/abort.mjs";
|
|
|
2
2
|
import { TIMER_WAIT, getTimer } from "../internal/function/timer.mjs";
|
|
3
3
|
import { PROMISE_MESSAGE_EXPECTATION_TIMED } from "./constants.mjs";
|
|
4
4
|
import { PromiseTimeoutError } from "./models.mjs";
|
|
5
|
-
import {
|
|
5
|
+
import { createPromiseOptions } from "./helpers.mjs";
|
|
6
6
|
import { settlePromise } from "./misc.mjs";
|
|
7
7
|
//#region src/promise/timed.ts
|
|
8
8
|
async function getTimedPromise(promise, time, signal) {
|
|
@@ -24,7 +24,7 @@ async function getTimedPromise(promise, time, signal) {
|
|
|
24
24
|
}
|
|
25
25
|
async function timed(promise, options) {
|
|
26
26
|
if (!(promise instanceof Promise)) return Promise.reject(new TypeError(PROMISE_MESSAGE_EXPECTATION_TIMED));
|
|
27
|
-
const { signal, time } =
|
|
27
|
+
const { signal, time } = createPromiseOptions(options);
|
|
28
28
|
if (signal?.aborted ?? false) return Promise.reject(signal?.reason);
|
|
29
29
|
return time > 0 ? getTimedPromise(promise, time, signal) : promise;
|
|
30
30
|
}
|
package/dist/queue.mjs
CHANGED
|
@@ -54,7 +54,7 @@ function createQueue(callback, options, key) {
|
|
|
54
54
|
handled: [],
|
|
55
55
|
id: 0,
|
|
56
56
|
items: [],
|
|
57
|
-
options:
|
|
57
|
+
options: createQueueOptions(options),
|
|
58
58
|
paused: !getBooleanOrDefault(options?.autostart, true),
|
|
59
59
|
runners: 0
|
|
60
60
|
};
|
|
@@ -104,7 +104,7 @@ function createQueue(callback, options, key) {
|
|
|
104
104
|
});
|
|
105
105
|
return Object.freeze(instance);
|
|
106
106
|
}
|
|
107
|
-
function
|
|
107
|
+
function createQueueOptions(input) {
|
|
108
108
|
const options = typeof input === "object" && input != null ? input : {};
|
|
109
109
|
return {
|
|
110
110
|
autostart: getBooleanOrDefault(options.autostart, true),
|
|
@@ -182,7 +182,7 @@ function keyedQueue(callback, options) {
|
|
|
182
182
|
if (typeof callback !== "function") throw new TypeError(QUEUE_MESSAGE_CALLBACK);
|
|
183
183
|
const state = {
|
|
184
184
|
callback,
|
|
185
|
-
options:
|
|
185
|
+
options: createQueueOptions(options),
|
|
186
186
|
queues: /* @__PURE__ */ new Map()
|
|
187
187
|
};
|
|
188
188
|
const instance = {
|
package/dist/string/fuzzy.mjs
CHANGED
|
@@ -3,20 +3,7 @@ import { getString } from "../internal/string/misc.mjs";
|
|
|
3
3
|
import { lowerCase } from "../internal/string/case.mjs";
|
|
4
4
|
import { includes } from "./match.mjs";
|
|
5
5
|
//#region src/string/fuzzy.ts
|
|
6
|
-
function
|
|
7
|
-
if (input == null || input === getString) return getString;
|
|
8
|
-
switch (typeof input) {
|
|
9
|
-
case "function": return input;
|
|
10
|
-
case "string": return (item) => item[input];
|
|
11
|
-
default:
|
|
12
|
-
if (isPlainObject(input)) return getHandler(input.key ?? input.handler);
|
|
13
|
-
throw new TypeError(FUZZY_MESSAGE_HANDLER);
|
|
14
|
-
}
|
|
15
|
-
}
|
|
16
|
-
function getFuzzyItems(items) {
|
|
17
|
-
return items.sort((first, second) => first.haystack.localeCompare(second.haystack)).map(({ item }) => item);
|
|
18
|
-
}
|
|
19
|
-
function getFuzzyOptions(input, state) {
|
|
6
|
+
function createFuzzyOptions(input, state) {
|
|
20
7
|
const options = isPlainObject(input) ? input : {};
|
|
21
8
|
const limit = typeof input === "number" ? input : options.limit;
|
|
22
9
|
if (typeof limit === "number" && !Number.isNaN(limit) && limit >= 1) options.limit = Math.floor(limit);
|
|
@@ -24,9 +11,9 @@ function getFuzzyOptions(input, state) {
|
|
|
24
11
|
options.tolerance = getTolerance(options.tolerance, state);
|
|
25
12
|
return options;
|
|
26
13
|
}
|
|
27
|
-
function
|
|
14
|
+
function createFuzzyState(items, input) {
|
|
28
15
|
const handler = getHandler(input);
|
|
29
|
-
const options =
|
|
16
|
+
const options = createFuzzyOptions(input);
|
|
30
17
|
return {
|
|
31
18
|
handler,
|
|
32
19
|
items: items.slice(),
|
|
@@ -35,14 +22,27 @@ function getFuzzyState(items, input) {
|
|
|
35
22
|
tolerance: options.tolerance
|
|
36
23
|
};
|
|
37
24
|
}
|
|
25
|
+
function getHandler(input) {
|
|
26
|
+
if (input == null || input === getString) return getString;
|
|
27
|
+
switch (typeof input) {
|
|
28
|
+
case "function": return input;
|
|
29
|
+
case "string": return (item) => item[input];
|
|
30
|
+
default:
|
|
31
|
+
if (isPlainObject(input)) return getHandler(input.key ?? input.handler);
|
|
32
|
+
throw new TypeError(FUZZY_MESSAGE_HANDLER);
|
|
33
|
+
}
|
|
34
|
+
}
|
|
35
|
+
function getFuzzyItems(items) {
|
|
36
|
+
return items.sort((first, second) => first.haystack.localeCompare(second.haystack)).map(({ item }) => item);
|
|
37
|
+
}
|
|
38
38
|
function getTolerance(input, state) {
|
|
39
39
|
if (typeof input === "number" && !Number.isNaN(input)) return input < 0 ? 0 : Math.floor(input);
|
|
40
40
|
return state?.tolerance ?? FUZZY_PROXIMITY_THRESHOLD;
|
|
41
41
|
}
|
|
42
42
|
function fuzzy(items, configuration) {
|
|
43
43
|
if (!Array.isArray(items)) throw new TypeError(FUZZY_MESSAGE_ARRAY);
|
|
44
|
-
const state =
|
|
45
|
-
const instance = { search: (value, options) => search(state.items, state.strings, value, options == null ? state :
|
|
44
|
+
const state = createFuzzyState(items, configuration);
|
|
45
|
+
const instance = { search: (value, options) => search(state.items, state.strings, value, options == null ? state : createFuzzyOptions(options, state)) };
|
|
46
46
|
Object.defineProperties(instance, {
|
|
47
47
|
items: {
|
|
48
48
|
enumerable: true,
|
|
@@ -2,6 +2,16 @@ import { isPlainObject } from "../internal/is.mjs";
|
|
|
2
2
|
import { memoize } from "../internal/function/memoize.mjs";
|
|
3
3
|
import { lowerCase } from "../internal/string/case.mjs";
|
|
4
4
|
//#region src/string/normalize.ts
|
|
5
|
+
function createNormalizeOptions(input) {
|
|
6
|
+
const options = isPlainObject(input) ? input : {};
|
|
7
|
+
return {
|
|
8
|
+
deburr: options.deburr !== false,
|
|
9
|
+
lowerCase: options.lowerCase !== false,
|
|
10
|
+
special: options.special === true,
|
|
11
|
+
trim: options.trim !== false,
|
|
12
|
+
whitespace: options.whitespace !== false
|
|
13
|
+
};
|
|
14
|
+
}
|
|
5
15
|
/**
|
|
6
16
|
* Deburr a string, removing diacritical marks
|
|
7
17
|
*
|
|
@@ -17,16 +27,6 @@ function deburr(value) {
|
|
|
17
27
|
});
|
|
18
28
|
return deburrMemoizer.run(value);
|
|
19
29
|
}
|
|
20
|
-
function getNormalizeOptions(input) {
|
|
21
|
-
const options = isPlainObject(input) ? input : {};
|
|
22
|
-
return {
|
|
23
|
-
deburr: options.deburr !== false,
|
|
24
|
-
lowerCase: options.lowerCase !== false,
|
|
25
|
-
special: options.special === true,
|
|
26
|
-
trim: options.trim !== false,
|
|
27
|
-
whitespace: options.whitespace !== false
|
|
28
|
-
};
|
|
29
|
-
}
|
|
30
30
|
/**
|
|
31
31
|
* Initialize a string normalizer
|
|
32
32
|
*
|
|
@@ -36,7 +36,7 @@ function getNormalizeOptions(input) {
|
|
|
36
36
|
* @returns Normalizer function
|
|
37
37
|
*/
|
|
38
38
|
function initializeNormalizer(options) {
|
|
39
|
-
const normalization =
|
|
39
|
+
const normalization = createNormalizeOptions(options);
|
|
40
40
|
return (value) => normalizeString(value, normalization);
|
|
41
41
|
}
|
|
42
42
|
/**
|
|
@@ -49,7 +49,7 @@ function initializeNormalizer(options) {
|
|
|
49
49
|
* @returns Normalized string
|
|
50
50
|
*/
|
|
51
51
|
function normalize(value, options) {
|
|
52
|
-
return normalizeString(value,
|
|
52
|
+
return normalizeString(value, createNormalizeOptions(options));
|
|
53
53
|
}
|
|
54
54
|
function normalizeString(value, options) {
|
|
55
55
|
if (typeof value !== "string") return "";
|
package/dist/string/template.mjs
CHANGED
|
@@ -2,18 +2,18 @@ import { isPlainObject, isTemplateStringsArray } from "../internal/is.mjs";
|
|
|
2
2
|
import { getString, interpolate } from "../internal/string/misc.mjs";
|
|
3
3
|
import { getValue } from "../internal/value/get.mjs";
|
|
4
4
|
//#region src/string/template.ts
|
|
5
|
-
function
|
|
6
|
-
return (variables, options) => {
|
|
7
|
-
return template(interpolate(strings, values), variables, options);
|
|
8
|
-
};
|
|
9
|
-
}
|
|
10
|
-
function getTemplateOptions(input) {
|
|
5
|
+
function createTemplateOptions(input) {
|
|
11
6
|
const options = isPlainObject(input) ? input : {};
|
|
12
7
|
return {
|
|
13
8
|
ignoreCase: options.ignoreCase === true,
|
|
14
9
|
pattern: options.pattern instanceof RegExp ? options.pattern : TEMPLATE_EXPRESSION_VARIABLE
|
|
15
10
|
};
|
|
16
11
|
}
|
|
12
|
+
function getRenderer(strings, values) {
|
|
13
|
+
return (variables, options) => {
|
|
14
|
+
return template(interpolate(strings, values), variables, options);
|
|
15
|
+
};
|
|
16
|
+
}
|
|
17
17
|
function handleTemplate(value, pattern, ignoreCase, variables) {
|
|
18
18
|
if (typeof value !== "string") return "";
|
|
19
19
|
if (typeof variables !== "object" || variables === null || Object.keys(variables).length === 0) return value;
|
|
@@ -35,14 +35,14 @@ function handleTemplate(value, pattern, ignoreCase, variables) {
|
|
|
35
35
|
* @returns _Templater_ function
|
|
36
36
|
*/
|
|
37
37
|
function initializeTemplater(options) {
|
|
38
|
-
const { ignoreCase, pattern } =
|
|
38
|
+
const { ignoreCase, pattern } = createTemplateOptions(options);
|
|
39
39
|
return ((value, ...parameters) => {
|
|
40
40
|
return isTemplateStringsArray(value) ? (variables) => handleTemplate(interpolate(value, parameters), pattern, ignoreCase, variables) : handleTemplate(value, pattern, ignoreCase, parameters[0]);
|
|
41
41
|
});
|
|
42
42
|
}
|
|
43
43
|
function template(value, ...parameters) {
|
|
44
44
|
if (isTemplateStringsArray(value)) return getRenderer(value, parameters);
|
|
45
|
-
const { ignoreCase, pattern } =
|
|
45
|
+
const { ignoreCase, pattern } = createTemplateOptions(parameters[1]);
|
|
46
46
|
return handleTemplate(value, pattern, ignoreCase, parameters[0]);
|
|
47
47
|
}
|
|
48
48
|
const TEMPLATE_EXPRESSION_VARIABLE = /{{([\s\S]+?)}}/g;
|
package/dist/subscription.d.mts
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
import { Subscription, isSubscription } from "./internal/subscription.mjs";
|
|
2
|
-
export { type Subscription, isSubscription };
|
|
1
|
+
import { Subscription, SubscriptionParameters, SubscriptionProperty, Subscriptions, SubscriptionsParameters, isSubscription, isSubscriptions, subscriptions } from "./internal/subscription.mjs";
|
|
2
|
+
export { type Subscription, type SubscriptionParameters, type SubscriptionProperty, type Subscriptions, type SubscriptionsParameters, isSubscription, isSubscriptions, subscriptions };
|
package/dist/subscription.mjs
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
import { isSubscription } from "./internal/subscription.mjs";
|
|
2
|
-
export { isSubscription };
|
|
1
|
+
import { isSubscription, isSubscriptions, subscriptions } from "./internal/subscription.mjs";
|
|
2
|
+
export { isSubscription, isSubscriptions, subscriptions };
|
package/dist/value/clone.d.mts
CHANGED
|
@@ -9,19 +9,36 @@ type CloneOptions = {
|
|
|
9
9
|
* Copy symbols instead of returning `Symbol(description)`? _(defaults to `false`)_
|
|
10
10
|
*/
|
|
11
11
|
copySymbols?: boolean;
|
|
12
|
-
/**
|
|
13
|
-
* Clone only the value itself, without cloning nested values? _(defaults to `false`)_
|
|
14
|
-
*/
|
|
15
|
-
flat?: boolean;
|
|
16
12
|
};
|
|
17
13
|
/**
|
|
18
|
-
*
|
|
19
|
-
*
|
|
20
|
-
* @param value Value to clone
|
|
21
|
-
* @param flat Clone only the value itself, without cloning nested values
|
|
22
|
-
* @returns Cloned value
|
|
14
|
+
* A cloning function with predefined options
|
|
23
15
|
*/
|
|
24
|
-
|
|
16
|
+
type Cloner = {
|
|
17
|
+
/**
|
|
18
|
+
* Clone any kind of value
|
|
19
|
+
*
|
|
20
|
+
* @param value Value to clone
|
|
21
|
+
* @returns Cloned value
|
|
22
|
+
*/
|
|
23
|
+
<Value>(value: Value): Value;
|
|
24
|
+
/**
|
|
25
|
+
* Deregister a clone handler for a specific class
|
|
26
|
+
*
|
|
27
|
+
* _Available as `deregisterCloner` and `template.deregister`_
|
|
28
|
+
*
|
|
29
|
+
* @param constructor Class constructor
|
|
30
|
+
*/
|
|
31
|
+
deregister: typeof deregisterCloner;
|
|
32
|
+
/**
|
|
33
|
+
* Register a clone handler for a specific class
|
|
34
|
+
*
|
|
35
|
+
* _Available as `registerCloner` and `template.register`_
|
|
36
|
+
*
|
|
37
|
+
* @param constructor Class constructor
|
|
38
|
+
* @param handler Method name or clone function _(defaults to method name `clone`)_
|
|
39
|
+
*/
|
|
40
|
+
register: typeof registerCloner;
|
|
41
|
+
};
|
|
25
42
|
/**
|
|
26
43
|
* Clone any kind of value _(deeply, if needed)_
|
|
27
44
|
*
|
|
@@ -31,18 +48,19 @@ declare function clone<Value>(value: Value, flat: true): Value;
|
|
|
31
48
|
*/
|
|
32
49
|
declare function clone<Value>(value: Value, options?: CloneOptions): Value;
|
|
33
50
|
declare namespace clone {
|
|
51
|
+
var deregister: typeof deregisterCloner;
|
|
34
52
|
var handlers: {
|
|
35
53
|
deregister(constructor: Constructor): void;
|
|
36
54
|
handle(value: unknown, ...parameters: unknown[]): unknown;
|
|
37
55
|
register(constructor: Constructor, handler?: string | GenericCallback): void;
|
|
38
56
|
};
|
|
39
|
-
var
|
|
57
|
+
var initialize: typeof initializeCloner;
|
|
40
58
|
var register: typeof registerCloner;
|
|
41
59
|
}
|
|
42
60
|
/**
|
|
43
61
|
* Copy any kind of value
|
|
44
62
|
*
|
|
45
|
-
* -
|
|
63
|
+
* - Copies the value shallowly _(if possible)_, without copying or cloning nested values
|
|
46
64
|
* - To copy a value deeply, use `clone` instead
|
|
47
65
|
*
|
|
48
66
|
* @param value Value to copy
|
|
@@ -57,6 +75,15 @@ declare function copy<Value>(value: Value): Value;
|
|
|
57
75
|
* @param constructor Class constructor
|
|
58
76
|
*/
|
|
59
77
|
declare function deregisterCloner<Instance>(constructor: Constructor<Instance>): void;
|
|
78
|
+
/**
|
|
79
|
+
* Create a cloner with predefined options
|
|
80
|
+
*
|
|
81
|
+
* _Available as `initializeCloner` and `clone.initialize`_
|
|
82
|
+
*
|
|
83
|
+
* @param options Clone options
|
|
84
|
+
* @returns Cloner function
|
|
85
|
+
*/
|
|
86
|
+
declare function initializeCloner(options?: CloneOptions): Cloner;
|
|
60
87
|
/**
|
|
61
88
|
* Register a clone handler for a specific class
|
|
62
89
|
*
|
|
@@ -67,4 +94,4 @@ declare function deregisterCloner<Instance>(constructor: Constructor<Instance>):
|
|
|
67
94
|
*/
|
|
68
95
|
declare function registerCloner<Instance>(constructor: Constructor<Instance>, handler?: string | ((value: Instance) => Instance)): void;
|
|
69
96
|
//#endregion
|
|
70
|
-
export { CloneOptions, clone, copy, deregisterCloner, registerCloner };
|
|
97
|
+
export { CloneOptions, Cloner, clone, copy, deregisterCloner, initializeCloner, registerCloner };
|