@leyyo/common 1.3.19 → 1.3.21
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/base/index.types.d.ts +67 -0
- package/dist/base/index.types.js +32 -0
- package/dist/base/leyyo.d.ts +3 -0
- package/dist/base/leyyo.js +18 -7
- package/dist/class/index.types.d.ts +20 -0
- package/dist/class/list.d.ts +6 -0
- package/dist/class/list.js +6 -0
- package/dist/class/logger.instance.d.ts +5 -0
- package/dist/class/logger.instance.js +13 -0
- package/dist/common/deploy.common.d.ts +16 -0
- package/dist/common/deploy.common.js +17 -0
- package/dist/common/enum.pool.d.ts +10 -0
- package/dist/common/enum.pool.js +14 -0
- package/dist/common/error.common.d.ts +30 -0
- package/dist/common/error.common.js +40 -0
- package/dist/common/error.pool.d.ts +9 -0
- package/dist/common/error.pool.js +10 -0
- package/dist/common/event.common.d.ts +8 -0
- package/dist/common/event.common.js +16 -3
- package/dist/common/index.types.d.ts +432 -0
- package/dist/common/index.types.js +1 -0
- package/dist/common/inert.d.ts +48 -0
- package/dist/common/inert.js +29 -0
- package/dist/common/lifecycle.common.d.ts +14 -0
- package/dist/common/lifecycle.common.js +16 -0
- package/dist/common/literal.pool.d.ts +11 -0
- package/dist/common/literal.pool.js +15 -0
- package/dist/common/log.common.d.ts +54 -0
- package/dist/common/log.common.js +96 -6
- package/dist/common/repo.common.d.ts +188 -0
- package/dist/common/repo.common.js +211 -0
- package/dist/const/index.d.ts +6 -0
- package/dist/const/index.js +7 -0
- package/dist/enum/log-level.d.ts +3 -0
- package/dist/error/caused.error.d.ts +10 -0
- package/dist/error/caused.error.js +10 -0
- package/dist/error/developer.error.d.ts +8 -0
- package/dist/error/developer.error.js +10 -0
- package/dist/error/http.error.d.ts +13 -0
- package/dist/error/http.error.js +7 -0
- package/dist/error/index.types.d.ts +149 -0
- package/dist/error/invalid-value.error.d.ts +3 -0
- package/dist/error/invalid-value.error.js +3 -0
- package/dist/error/leyyo.error.d.ts +33 -0
- package/dist/error/leyyo.error.js +36 -0
- package/dist/error/multiple.error.d.ts +6 -0
- package/dist/error/multiple.error.js +7 -0
- package/dist/function/define-loader.d.ts +6 -0
- package/dist/function/define-loader.js +6 -0
- package/dist/function/delay.d.ts +8 -0
- package/dist/function/delay.js +9 -0
- package/dist/function/delete-prop.d.ts +21 -0
- package/dist/function/delete-prop.js +22 -0
- package/dist/function/empty-fn.d.ts +6 -0
- package/dist/function/empty-fn.js +7 -0
- package/dist/function/extended-type.d.ts +6 -0
- package/dist/function/extended-type.js +7 -0
- package/dist/function/get-fqn.d.ts +6 -0
- package/dist/function/get-fqn.js +7 -0
- package/dist/function/get-prop.d.ts +21 -0
- package/dist/function/get-prop.js +21 -0
- package/dist/function/get-stat.d.ts +20 -0
- package/dist/function/has-fqn.d.ts +6 -0
- package/dist/function/has-fqn.js +7 -0
- package/dist/function/index.d.ts +1 -0
- package/dist/function/index.js +1 -0
- package/dist/function/is-class.d.ts +6 -0
- package/dist/function/is-class.js +18 -0
- package/dist/function/is-empty.d.ts +11 -0
- package/dist/function/is-empty.js +11 -0
- package/dist/function/is-filled-arr.d.ts +9 -0
- package/dist/function/is-filled-arr.js +9 -0
- package/dist/function/is-filled-obj.d.ts +9 -0
- package/dist/function/is-filled-obj.js +9 -0
- package/dist/function/is-obj.d.ts +8 -0
- package/dist/function/is-obj.js +8 -0
- package/dist/function/is-test.d.ts +8 -0
- package/dist/function/is-test.js +14 -0
- package/dist/function/is-text.d.ts +10 -0
- package/dist/function/is-text.js +10 -0
- package/dist/function/jitter-interval.d.ts +9 -0
- package/dist/function/jitter-interval.js +16 -0
- package/dist/function/load-config.d.ts +19 -0
- package/dist/function/load-config.js +52 -1
- package/dist/function/on-fqn-set.js +1 -0
- package/dist/function/one-or-more.d.ts +6 -0
- package/dist/function/one-or-more.js +7 -0
- package/dist/function/opt-add.d.ts +8 -0
- package/dist/function/opt-add.js +8 -0
- package/dist/function/opt-append.d.ts +7 -0
- package/dist/function/opt-append.js +7 -0
- package/dist/function/opt-check.d.ts +6 -0
- package/dist/function/opt-check.js +7 -0
- package/dist/function/opt-clone.d.ts +6 -0
- package/dist/function/opt-clone.js +7 -0
- package/dist/function/opt-field.d.ts +8 -0
- package/dist/function/opt-field.js +8 -0
- package/dist/function/opt-fn.d.ts +6 -0
- package/dist/function/opt-fn.js +7 -0
- package/dist/function/random-test-no.d.ts +5 -0
- package/dist/function/random-test-no.js +5 -0
- package/dist/function/remove-fqn.d.ts +8 -0
- package/dist/function/remove-fqn.js +11 -1
- package/dist/function/run-exporter.d.ts +5 -0
- package/dist/function/run-exporter.js +14 -0
- package/dist/function/secure-json.d.ts +35 -0
- package/dist/function/secure-json.js +44 -0
- package/dist/function/set-anonymous-fqn.js +2 -0
- package/dist/function/set-fqn.d.ts +7 -0
- package/dist/function/set-fqn.js +8 -0
- package/dist/function/set-prop.d.ts +24 -0
- package/dist/function/set-prop.js +24 -0
- package/dist/function/stamp-loader.d.ts +6 -0
- package/dist/function/stamp-loader.js +6 -0
- package/dist/function/test-case.d.ts +7 -0
- package/dist/function/test-case.js +7 -0
- package/dist/function/test-name.d.ts +7 -0
- package/dist/function/test-name.js +7 -0
- package/dist/function/times.d.ts +6 -0
- package/dist/function/times.js +12 -0
- package/dist/function/trigger-fqn.js +1 -0
- package/dist/index.foretell.js +3 -0
- package/dist/index.js +1 -0
- package/dist/index.loader.js +8 -1
- package/dist/sys/leyyo-storage.d.ts +7 -0
- package/dist/sys/leyyo-storage.js +23 -0
- package/package.json +1 -1
|
@@ -3,18 +3,39 @@ import { testCase } from "./test-case.js";
|
|
|
3
3
|
import { $$get_leyyo_fn } from "./leyyo-fn.js";
|
|
4
4
|
const where = `${FQN}.GetProp`;
|
|
5
5
|
let _leyyo;
|
|
6
|
+
/**
|
|
7
|
+
* Get target property
|
|
8
|
+
*
|
|
9
|
+
* @param {any} target - target
|
|
10
|
+
* @param {string} key - key
|
|
11
|
+
* @return {any}
|
|
12
|
+
* */
|
|
6
13
|
export function getKey(target, key) {
|
|
7
14
|
if (typeof key !== "string") {
|
|
8
15
|
return undefined;
|
|
9
16
|
}
|
|
10
17
|
return getProp(target, key);
|
|
11
18
|
}
|
|
19
|
+
/**
|
|
20
|
+
* Get target hidden property
|
|
21
|
+
*
|
|
22
|
+
* @param {any} target - target
|
|
23
|
+
* @param {symbol} key - hidden key
|
|
24
|
+
* @return {any}
|
|
25
|
+
* */
|
|
12
26
|
export function getSymbol(target, key) {
|
|
13
27
|
if (typeof key !== "symbol") {
|
|
14
28
|
return undefined;
|
|
15
29
|
}
|
|
16
30
|
return getProp(target, key);
|
|
17
31
|
}
|
|
32
|
+
/**
|
|
33
|
+
* Get target property
|
|
34
|
+
*
|
|
35
|
+
* @param {any} target - target
|
|
36
|
+
* @param {(symbol|string)} key - key
|
|
37
|
+
* @return {any}
|
|
38
|
+
* */
|
|
18
39
|
export function getProp(target, key) {
|
|
19
40
|
if (!["symbol", "string"].includes(typeof key)) {
|
|
20
41
|
return undefined;
|
|
@@ -39,20 +39,40 @@ export interface StatisticsOs {
|
|
|
39
39
|
cpu: Array<StatisticsCpuInfo>;
|
|
40
40
|
}
|
|
41
41
|
export interface StatisticsMemory {
|
|
42
|
+
/**
|
|
43
|
+
* Resident Set Size, is the amount of space occupied in the main memory device (that is a subset of the total allocated memory) for the
|
|
44
|
+
* process, including all C++ and JavaScript objects and code.
|
|
45
|
+
*/
|
|
42
46
|
rss: number;
|
|
47
|
+
/**
|
|
48
|
+
* Refers to V8's memory usage.
|
|
49
|
+
*/
|
|
43
50
|
heapTotal: number;
|
|
51
|
+
/**
|
|
52
|
+
* Refers to V8's memory usage.
|
|
53
|
+
*/
|
|
44
54
|
heapUsed: number;
|
|
45
55
|
external: number;
|
|
56
|
+
/**
|
|
57
|
+
* Refers to memory allocated for `ArrayBuffer`s and `SharedArrayBuffer`s, including all Node.js Buffers. This is also included
|
|
58
|
+
* in the external value. When Node.js is used as an embedded library, this value may be `0` because allocations for `ArrayBuffer`s
|
|
59
|
+
* may not be tracked in that case.
|
|
60
|
+
*/
|
|
46
61
|
arrayBuffers: number;
|
|
47
62
|
}
|
|
48
63
|
export interface StatisticsCpuInfo {
|
|
49
64
|
model: string;
|
|
50
65
|
speed: number;
|
|
51
66
|
times: {
|
|
67
|
+
/** The number of milliseconds the CPU has spent in user mode. */
|
|
52
68
|
user: number;
|
|
69
|
+
/** The number of milliseconds the CPU has spent in nice mode. */
|
|
53
70
|
nice: number;
|
|
71
|
+
/** The number of milliseconds the CPU has spent in sys mode. */
|
|
54
72
|
sys: number;
|
|
73
|
+
/** The number of milliseconds the CPU has spent in idle mode. */
|
|
55
74
|
idle: number;
|
|
75
|
+
/** The number of milliseconds the CPU has spent in irq mode. */
|
|
56
76
|
irq: number;
|
|
57
77
|
};
|
|
58
78
|
}
|
|
@@ -1,2 +1,8 @@
|
|
|
1
1
|
import { FqnTarget } from "./index.types.js";
|
|
2
|
+
/**
|
|
3
|
+
* Get fqn name
|
|
4
|
+
*
|
|
5
|
+
* @param {FqnTarget} target - target (function, class, instance, enum, literal)
|
|
6
|
+
* @return {string} - fully qualified name
|
|
7
|
+
* */
|
|
2
8
|
export declare function hasFqn(target: FqnTarget): boolean;
|
package/dist/function/has-fqn.js
CHANGED
|
@@ -1,9 +1,16 @@
|
|
|
1
1
|
import { KEY_ENUM_NAME, KEY_FQN_NAME, KEY_LITERAL_NAME } from "../const/index.js";
|
|
2
|
+
/**
|
|
3
|
+
* Get fqn name
|
|
4
|
+
*
|
|
5
|
+
* @param {FqnTarget} target - target (function, class, instance, enum, literal)
|
|
6
|
+
* @return {string} - fully qualified name
|
|
7
|
+
* */
|
|
2
8
|
export function hasFqn(target) {
|
|
3
9
|
if (!target) {
|
|
4
10
|
return false;
|
|
5
11
|
}
|
|
6
12
|
if (typeof target === "function") {
|
|
13
|
+
// function, class
|
|
7
14
|
return !!target[KEY_FQN_NAME];
|
|
8
15
|
}
|
|
9
16
|
else if (typeof target === "object") {
|
package/dist/function/index.d.ts
CHANGED
package/dist/function/index.js
CHANGED
|
@@ -1,3 +1,9 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Is class?
|
|
3
|
+
*
|
|
4
|
+
* @param {any} fn - given value
|
|
5
|
+
* @return {boolean} - is class?
|
|
6
|
+
* */
|
|
1
7
|
export function isClass(fn) {
|
|
2
8
|
if (typeof fn !== "function") {
|
|
3
9
|
return false;
|
|
@@ -8,4 +14,16 @@ export function isClass(fn) {
|
|
|
8
14
|
catch (e) {
|
|
9
15
|
return false;
|
|
10
16
|
}
|
|
17
|
+
// // Class constructor is also a function
|
|
18
|
+
// if ( !(fn && fn.constructor === Function) || (fn as Fnc).prototype === undefined) {
|
|
19
|
+
// return false;
|
|
20
|
+
// }
|
|
21
|
+
//
|
|
22
|
+
// // This is a class that extends other class
|
|
23
|
+
// if (Function.prototype !== Object.getPrototypeOf(fn)) {
|
|
24
|
+
// return true;
|
|
25
|
+
// }
|
|
26
|
+
//
|
|
27
|
+
// // Usually a function will only have 'constructor' in the prototype
|
|
28
|
+
// return Object.getOwnPropertyNames((fn as Fnc).prototype).length > 1;
|
|
11
29
|
}
|
|
@@ -1 +1,12 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Is empty?
|
|
3
|
+
* Means:
|
|
4
|
+
* - `not null`
|
|
5
|
+
* - `not undefined`
|
|
6
|
+
* - `not empty string`
|
|
7
|
+
*
|
|
8
|
+
* @param {any} value - given value
|
|
9
|
+
* @param {boolean?} notSpace - yes: ignore empty string
|
|
10
|
+
* @return {boolean} - is empty?
|
|
11
|
+
* */
|
|
1
12
|
export declare function isEmpty(value: unknown, notSpace?: boolean): boolean;
|
|
@@ -1,4 +1,15 @@
|
|
|
1
1
|
import { EMPTY_VALUES } from "../const/index.js";
|
|
2
|
+
/**
|
|
3
|
+
* Is empty?
|
|
4
|
+
* Means:
|
|
5
|
+
* - `not null`
|
|
6
|
+
* - `not undefined`
|
|
7
|
+
* - `not empty string`
|
|
8
|
+
*
|
|
9
|
+
* @param {any} value - given value
|
|
10
|
+
* @param {boolean?} notSpace - yes: ignore empty string
|
|
11
|
+
* @return {boolean} - is empty?
|
|
12
|
+
* */
|
|
2
13
|
export function isEmpty(value, notSpace) {
|
|
3
14
|
if (notSpace) {
|
|
4
15
|
return EMPTY_VALUES.includes(value);
|
|
@@ -1,3 +1,12 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Is filled array?
|
|
3
|
+
* Means
|
|
4
|
+
* - `constructor === "Array"`
|
|
5
|
+
* - `arr.length > 0`
|
|
6
|
+
*
|
|
7
|
+
* @param {any} arr - given value
|
|
8
|
+
* @return {boolean} - is filled array?
|
|
9
|
+
* */
|
|
1
10
|
export function isFilledArr(arr) {
|
|
2
11
|
return Array.isArray(arr) && arr.length > 0;
|
|
3
12
|
}
|
|
@@ -1,4 +1,13 @@
|
|
|
1
1
|
import { isObj } from "./is-obj.js";
|
|
2
|
+
/**
|
|
3
|
+
* Is filled object?
|
|
4
|
+
* Means:
|
|
5
|
+
* - `constructor === "Object"`
|
|
6
|
+
* - `obj.keys.length > 0`
|
|
7
|
+
*
|
|
8
|
+
* @param {any} obj - given value
|
|
9
|
+
* @return {boolean} - is filled object?
|
|
10
|
+
* */
|
|
2
11
|
export function isFilledObj(obj) {
|
|
3
12
|
return isObj(obj) && Object.keys(obj).length > 0;
|
|
4
13
|
}
|
package/dist/function/is-obj.js
CHANGED
package/dist/function/is-test.js
CHANGED
|
@@ -1,4 +1,13 @@
|
|
|
1
|
+
// noinspection JSUnusedGlobalSymbols
|
|
2
|
+
// region properties
|
|
3
|
+
/**
|
|
4
|
+
* Is test?
|
|
5
|
+
* */
|
|
1
6
|
let _isTest;
|
|
7
|
+
// endregion properties
|
|
8
|
+
/**
|
|
9
|
+
* Initialize test
|
|
10
|
+
* */
|
|
2
11
|
export function initTest() {
|
|
3
12
|
_isTest = true;
|
|
4
13
|
if (global) {
|
|
@@ -11,6 +20,11 @@ export function initTest() {
|
|
|
11
20
|
}
|
|
12
21
|
}
|
|
13
22
|
}
|
|
23
|
+
/**
|
|
24
|
+
* Is test?
|
|
25
|
+
*
|
|
26
|
+
* @return {boolean}
|
|
27
|
+
* */
|
|
14
28
|
export function isTest() {
|
|
15
29
|
return _isTest;
|
|
16
30
|
}
|
package/dist/function/is-text.js
CHANGED
|
@@ -1,3 +1,13 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Is text?
|
|
3
|
+
* Means:
|
|
4
|
+
* - `typeof === "string"`
|
|
5
|
+
* - `not empty string`
|
|
6
|
+
* - `not starts/ends with space`
|
|
7
|
+
*
|
|
8
|
+
* @param {any} str - given value
|
|
9
|
+
* @return {boolean} - is text?
|
|
10
|
+
* */
|
|
1
11
|
export function isText(str) {
|
|
2
12
|
if (typeof str !== "string") {
|
|
3
13
|
return false;
|
|
@@ -1 +1,10 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Generate next delay time with exponential & randomized manner
|
|
3
|
+
*
|
|
4
|
+
* @param {number} tryCount - try count
|
|
5
|
+
* @param {number} baseDelay - starting delay interval
|
|
6
|
+
* @param {number} maxDelay - maximum delay interval
|
|
7
|
+
* @param {number} maxTryCount - max try count, if `tryCount` excess it, it returns undefined
|
|
8
|
+
* @return {number} - next interval time if (maxTryCount && `tryCount` >= `maxTryCount`)
|
|
9
|
+
* */
|
|
1
10
|
export declare function jitterInterval(tryCount: number, baseDelay: number, maxDelay: number, maxTryCount?: number): number;
|
|
@@ -1,3 +1,13 @@
|
|
|
1
|
+
// noinspection JSUnusedGlobalSymbols
|
|
2
|
+
/**
|
|
3
|
+
* Generate next delay time with exponential & randomized manner
|
|
4
|
+
*
|
|
5
|
+
* @param {number} tryCount - try count
|
|
6
|
+
* @param {number} baseDelay - starting delay interval
|
|
7
|
+
* @param {number} maxDelay - maximum delay interval
|
|
8
|
+
* @param {number} maxTryCount - max try count, if `tryCount` excess it, it returns undefined
|
|
9
|
+
* @return {number} - next interval time if (maxTryCount && `tryCount` >= `maxTryCount`)
|
|
10
|
+
* */
|
|
1
11
|
export function jitterInterval(tryCount, baseDelay, maxDelay, maxTryCount) {
|
|
2
12
|
if ([tryCount, baseDelay, maxDelay].some((v) => !isValid(v))) {
|
|
3
13
|
return undefined;
|
|
@@ -9,6 +19,12 @@ export function jitterInterval(tryCount, baseDelay, maxDelay, maxTryCount) {
|
|
|
9
19
|
const result = Math.floor(exp / 2 + Math.random() * (exp / 2));
|
|
10
20
|
return Number.isSafeInteger(result) ? result : undefined;
|
|
11
21
|
}
|
|
22
|
+
/**
|
|
23
|
+
* Check value is expected interval value
|
|
24
|
+
*
|
|
25
|
+
* @param {any} value - given value, possible number
|
|
26
|
+
* @return {boolean} - is it expected?
|
|
27
|
+
* */
|
|
12
28
|
function isValid(value) {
|
|
13
29
|
return (typeof value === "number" && value > 0 && Number.isInteger(value) && Number.isSafeInteger(value));
|
|
14
30
|
}
|
|
@@ -1,3 +1,22 @@
|
|
|
1
1
|
import { LeyyoConfig } from "./index.types.js";
|
|
2
2
|
export declare const leyyoConfig: LeyyoConfig;
|
|
3
|
+
/**
|
|
4
|
+
* Load config from `.leyyo.yaml` file
|
|
5
|
+
*
|
|
6
|
+
* `OBJECT` postfixes:
|
|
7
|
+
* - !: only override (`don't merge`)
|
|
8
|
+
* - ?: only merge (`don't override`)
|
|
9
|
+
* - <empty>: only set if key is absent
|
|
10
|
+
*
|
|
11
|
+
* `ARRAY` postfixes:
|
|
12
|
+
* - !: only override (`don't merge`)
|
|
13
|
+
* - ?: only merge (`don't override`)
|
|
14
|
+
* - <empty>: only set if key is absent
|
|
15
|
+
*
|
|
16
|
+
* Generics:
|
|
17
|
+
* - `C`- config model
|
|
18
|
+
*
|
|
19
|
+
* @param {string} url
|
|
20
|
+
* @return {LeyyoConfig}
|
|
21
|
+
* */
|
|
3
22
|
export declare function loadConfig(url: string): LeyyoConfig;
|
|
@@ -10,6 +10,25 @@ import { isEmpty } from "./is-empty.js";
|
|
|
10
10
|
import { secureJson, secureObject } from "./secure-json.js";
|
|
11
11
|
const _NAME = "$$leyyo.config";
|
|
12
12
|
export const leyyoConfig = getRootStorage(_NAME, {});
|
|
13
|
+
/**
|
|
14
|
+
* Load config from `.leyyo.yaml` file
|
|
15
|
+
*
|
|
16
|
+
* `OBJECT` postfixes:
|
|
17
|
+
* - !: only override (`don't merge`)
|
|
18
|
+
* - ?: only merge (`don't override`)
|
|
19
|
+
* - <empty>: only set if key is absent
|
|
20
|
+
*
|
|
21
|
+
* `ARRAY` postfixes:
|
|
22
|
+
* - !: only override (`don't merge`)
|
|
23
|
+
* - ?: only merge (`don't override`)
|
|
24
|
+
* - <empty>: only set if key is absent
|
|
25
|
+
*
|
|
26
|
+
* Generics:
|
|
27
|
+
* - `C`- config model
|
|
28
|
+
*
|
|
29
|
+
* @param {string} url
|
|
30
|
+
* @return {LeyyoConfig}
|
|
31
|
+
* */
|
|
13
32
|
export function loadConfig(url) {
|
|
14
33
|
try {
|
|
15
34
|
const __dirname = dirname(dirname(fileURLToPath(url)));
|
|
@@ -30,6 +49,11 @@ export function loadConfig(url) {
|
|
|
30
49
|
return undefined;
|
|
31
50
|
}
|
|
32
51
|
}
|
|
52
|
+
/**
|
|
53
|
+
* Get key behaviour
|
|
54
|
+
* @param {string} keyFull - key
|
|
55
|
+
* @return {Array} - tuple as `[behaviour, key]`
|
|
56
|
+
* */
|
|
33
57
|
function _behaviour(keyFull) {
|
|
34
58
|
if (!isText(keyFull)) {
|
|
35
59
|
return [undefined, undefined];
|
|
@@ -50,6 +74,13 @@ function _behaviour(keyFull) {
|
|
|
50
74
|
}
|
|
51
75
|
return [undefined, keyFull];
|
|
52
76
|
}
|
|
77
|
+
/**
|
|
78
|
+
* Merge array
|
|
79
|
+
*
|
|
80
|
+
* @param {Array} source
|
|
81
|
+
* @param {string} key
|
|
82
|
+
* @param {Array} value
|
|
83
|
+
* */
|
|
53
84
|
function _array(source, key, value) {
|
|
54
85
|
value.forEach((item, index) => {
|
|
55
86
|
if (isEmpty(item)) {
|
|
@@ -79,6 +110,13 @@ function _array(source, key, value) {
|
|
|
79
110
|
}
|
|
80
111
|
});
|
|
81
112
|
}
|
|
113
|
+
/**
|
|
114
|
+
* Merge object
|
|
115
|
+
*
|
|
116
|
+
* @param {object} source
|
|
117
|
+
* @param {string} keyFull - key
|
|
118
|
+
* @param {any} value
|
|
119
|
+
* */
|
|
82
120
|
function _object(source, keyFull, value) {
|
|
83
121
|
if (isEmpty(value)) {
|
|
84
122
|
return;
|
|
@@ -91,6 +129,7 @@ function _object(source, keyFull, value) {
|
|
|
91
129
|
if (!source) {
|
|
92
130
|
source = {};
|
|
93
131
|
}
|
|
132
|
+
// old is empty
|
|
94
133
|
if (isEmpty(source[key])) {
|
|
95
134
|
switch (typeof value) {
|
|
96
135
|
case "string":
|
|
@@ -118,7 +157,7 @@ function _object(source, keyFull, value) {
|
|
|
118
157
|
case "override":
|
|
119
158
|
source[key] = value;
|
|
120
159
|
break;
|
|
121
|
-
default:
|
|
160
|
+
default: // merge
|
|
122
161
|
if (isEmpty(source[key])) {
|
|
123
162
|
source[key] = value;
|
|
124
163
|
}
|
|
@@ -126,7 +165,9 @@ function _object(source, keyFull, value) {
|
|
|
126
165
|
}
|
|
127
166
|
break;
|
|
128
167
|
case "object":
|
|
168
|
+
// new is an array
|
|
129
169
|
if (Array.isArray(value)) {
|
|
170
|
+
// old is an array (BOTH)
|
|
130
171
|
if (Array.isArray(source[key])) {
|
|
131
172
|
switch (behaviour) {
|
|
132
173
|
case "override":
|
|
@@ -136,35 +177,44 @@ function _object(source, keyFull, value) {
|
|
|
136
177
|
_array(source[key], key, value);
|
|
137
178
|
break;
|
|
138
179
|
default:
|
|
180
|
+
// old exists, ignore
|
|
139
181
|
break;
|
|
140
182
|
}
|
|
141
183
|
}
|
|
184
|
+
// CONFLICT: old is not array
|
|
142
185
|
else {
|
|
143
186
|
switch (behaviour) {
|
|
144
187
|
case "override":
|
|
145
188
|
source[key] = secureObject(value);
|
|
146
189
|
break;
|
|
147
190
|
case "merge":
|
|
191
|
+
// old is different, conflict
|
|
148
192
|
console.warn(`[leyyoConfig] type is conflicted at (${key})`);
|
|
149
193
|
break;
|
|
150
194
|
default:
|
|
195
|
+
// old exists, ignore
|
|
151
196
|
break;
|
|
152
197
|
}
|
|
153
198
|
}
|
|
154
199
|
}
|
|
200
|
+
// new is an object
|
|
155
201
|
else {
|
|
202
|
+
// CONFLICT: old is not object
|
|
156
203
|
if (Array.isArray(source[key])) {
|
|
157
204
|
switch (behaviour) {
|
|
158
205
|
case "override":
|
|
159
206
|
source[key] = value;
|
|
160
207
|
break;
|
|
161
208
|
case "merge":
|
|
209
|
+
// old is different, conflict
|
|
162
210
|
console.warn(`[leyyoConfig] type is conflicted at (${key})`);
|
|
163
211
|
break;
|
|
164
212
|
default:
|
|
213
|
+
// old exists, ignore
|
|
165
214
|
break;
|
|
166
215
|
}
|
|
167
216
|
}
|
|
217
|
+
// old is an object (BOTH)
|
|
168
218
|
else {
|
|
169
219
|
switch (behaviour) {
|
|
170
220
|
case "override":
|
|
@@ -176,6 +226,7 @@ function _object(source, keyFull, value) {
|
|
|
176
226
|
}
|
|
177
227
|
break;
|
|
178
228
|
default:
|
|
229
|
+
// old exists, ignore
|
|
179
230
|
break;
|
|
180
231
|
}
|
|
181
232
|
}
|
|
@@ -1,2 +1,8 @@
|
|
|
1
1
|
import { OneOrMore } from "../base/index.js";
|
|
2
|
+
/**
|
|
3
|
+
* Return array value from one or more type
|
|
4
|
+
*
|
|
5
|
+
* @param {OneOrMore} value - it can be one value or array value
|
|
6
|
+
* @return {Array}
|
|
7
|
+
* */
|
|
2
8
|
export declare function oneOrMore<T = unknown>(value: OneOrMore<T>): Array<T> | undefined;
|
|
@@ -1,3 +1,10 @@
|
|
|
1
|
+
// noinspection JSUnusedGlobalSymbols
|
|
2
|
+
/**
|
|
3
|
+
* Return array value from one or more type
|
|
4
|
+
*
|
|
5
|
+
* @param {OneOrMore} value - it can be one value or array value
|
|
6
|
+
* @return {Array}
|
|
7
|
+
* */
|
|
1
8
|
export function oneOrMore(value) {
|
|
2
9
|
if (Array.isArray(value)) {
|
|
3
10
|
return value;
|
|
@@ -1,2 +1,10 @@
|
|
|
1
1
|
import { Opt } from "./index.types.js";
|
|
2
|
+
/**
|
|
3
|
+
* Add key=value into options
|
|
4
|
+
*
|
|
5
|
+
* @param {Opt} options - source options
|
|
6
|
+
* @param {string} key - key
|
|
7
|
+
* @param {any} value - value
|
|
8
|
+
* @return {Opt} - added options
|
|
9
|
+
* */
|
|
2
10
|
export declare function optAdd<O extends Opt = Opt>(options: O | Opt, key: keyof O | string, value: unknown): O;
|
package/dist/function/opt-add.js
CHANGED
|
@@ -1,5 +1,13 @@
|
|
|
1
1
|
import { optField } from "./opt-field.js";
|
|
2
2
|
import { isObj } from "./is-obj.js";
|
|
3
|
+
/**
|
|
4
|
+
* Add key=value into options
|
|
5
|
+
*
|
|
6
|
+
* @param {Opt} options - source options
|
|
7
|
+
* @param {string} key - key
|
|
8
|
+
* @param {any} value - value
|
|
9
|
+
* @return {Opt} - added options
|
|
10
|
+
* */
|
|
3
11
|
export function optAdd(options, key, value) {
|
|
4
12
|
const o = (isObj(options) ? options : {});
|
|
5
13
|
if (value === undefined || typeof key !== "string") {
|
|
@@ -1,2 +1,9 @@
|
|
|
1
1
|
import { Opt } from "./index.types.js";
|
|
2
|
+
/**
|
|
3
|
+
* Merge two options
|
|
4
|
+
*
|
|
5
|
+
* @param {Opt} options - source options
|
|
6
|
+
* @param {Opt} appended - appended options
|
|
7
|
+
* @return {Opt} - merged options
|
|
8
|
+
* */
|
|
2
9
|
export declare function optAppend<O extends Opt = Opt>(options: O | Opt, appended: O | Opt): O;
|
|
@@ -1,5 +1,12 @@
|
|
|
1
1
|
import { isObj } from "./is-obj.js";
|
|
2
2
|
import { optAdd } from "./opt-add.js";
|
|
3
|
+
/**
|
|
4
|
+
* Merge two options
|
|
5
|
+
*
|
|
6
|
+
* @param {Opt} options - source options
|
|
7
|
+
* @param {Opt} appended - appended options
|
|
8
|
+
* @return {Opt} - merged options
|
|
9
|
+
* */
|
|
3
10
|
export function optAppend(options, appended) {
|
|
4
11
|
const o = (isObj(options) ? options : {});
|
|
5
12
|
if (!isObj(appended)) {
|
|
@@ -1,2 +1,8 @@
|
|
|
1
1
|
import { Opt, OptFn } from "./index.types.js";
|
|
2
|
+
/**
|
|
3
|
+
* Check option, if it's invalid, create empty options
|
|
4
|
+
*
|
|
5
|
+
* @param {(Opt|OptFn)} options - options or options callback
|
|
6
|
+
* @return {Opt} - checked options
|
|
7
|
+
* */
|
|
2
8
|
export declare function optCheck<O extends Opt = Opt>(options: O | OptFn<O> | Opt): O;
|
|
@@ -1,8 +1,15 @@
|
|
|
1
|
+
// noinspection JSUnusedGlobalSymbols
|
|
1
2
|
import { $$get_leyyo_fn } from "./leyyo-fn.js";
|
|
2
3
|
import { isObj } from "./is-obj.js";
|
|
3
4
|
import { FQN } from "../internal.js";
|
|
4
5
|
let _leyyo;
|
|
5
6
|
const where = `${FQN}.optCheck`;
|
|
7
|
+
/**
|
|
8
|
+
* Check option, if it's invalid, create empty options
|
|
9
|
+
*
|
|
10
|
+
* @param {(Opt|OptFn)} options - options or options callback
|
|
11
|
+
* @return {Opt} - checked options
|
|
12
|
+
* */
|
|
6
13
|
export function optCheck(options) {
|
|
7
14
|
let o = options;
|
|
8
15
|
if (typeof options === "function") {
|
|
@@ -1,5 +1,12 @@
|
|
|
1
|
+
// noinspection JSUnusedGlobalSymbols
|
|
1
2
|
import { isObj } from "./is-obj.js";
|
|
2
3
|
import { secureClone } from "./secure-clone.js";
|
|
4
|
+
/**
|
|
5
|
+
* Clone existing option
|
|
6
|
+
*
|
|
7
|
+
* @param {Opt} options - source options
|
|
8
|
+
* @return {Opt} - cloned options
|
|
9
|
+
* */
|
|
3
10
|
export function optClone(options) {
|
|
4
11
|
return (isObj(options) ? secureClone(options) : {});
|
|
5
12
|
}
|