@leyyo/common 1.3.17 → 1.3.19
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.d.ts +3 -3
- package/dist/base/index.js +3 -3
- package/dist/base/index.types.d.ts +3 -70
- package/dist/base/index.types.js +0 -32
- package/dist/base/leyyo.d.ts +0 -3
- package/dist/base/leyyo.js +12 -23
- package/dist/class/index.d.ts +2 -2
- package/dist/class/index.js +2 -2
- package/dist/class/index.types.d.ts +0 -20
- package/dist/class/list.d.ts +0 -6
- package/dist/class/list.js +0 -6
- package/dist/class/logger.instance.d.ts +8 -13
- package/dist/class/logger.instance.js +13 -27
- package/dist/common/deploy.common.d.ts +0 -16
- package/dist/common/deploy.common.js +4 -21
- package/dist/common/enum.pool.d.ts +5 -13
- package/dist/common/enum.pool.js +16 -17
- package/dist/common/error.common.d.ts +0 -30
- package/dist/common/error.common.js +33 -69
- package/dist/common/error.pool.d.ts +1 -10
- package/dist/common/error.pool.js +2 -13
- package/dist/common/event.common.d.ts +0 -8
- package/dist/common/event.common.js +15 -25
- package/dist/common/index.d.ts +11 -11
- package/dist/common/index.js +11 -11
- package/dist/common/index.types.d.ts +12 -435
- package/dist/common/index.types.js +0 -1
- package/dist/common/inert.d.ts +1 -49
- package/dist/common/inert.js +35 -64
- package/dist/common/lifecycle.common.d.ts +0 -14
- package/dist/common/lifecycle.common.js +13 -29
- package/dist/common/literal.pool.d.ts +1 -12
- package/dist/common/literal.pool.js +3 -18
- package/dist/common/log.common.d.ts +0 -54
- package/dist/common/log.common.js +62 -147
- package/dist/common/repo.common.d.ts +0 -188
- package/dist/common/repo.common.js +23 -239
- package/dist/const/index.d.ts +8 -12
- package/dist/const/index.js +28 -33
- package/dist/enum/index.d.ts +1 -1
- package/dist/enum/index.js +1 -1
- package/dist/enum/log-level.d.ts +1 -4
- package/dist/enum/log-level.js +1 -1
- package/dist/error/caused.error.d.ts +0 -10
- package/dist/error/caused.error.js +0 -10
- package/dist/error/developer.error.d.ts +4 -17
- package/dist/error/developer.error.js +11 -33
- package/dist/error/http.error.d.ts +0 -13
- package/dist/error/http.error.js +1 -8
- package/dist/error/index.d.ts +7 -7
- package/dist/error/index.js +7 -7
- package/dist/error/index.types.d.ts +1 -150
- package/dist/error/invalid-value.error.d.ts +0 -3
- package/dist/error/invalid-value.error.js +1 -4
- package/dist/error/leyyo.error.d.ts +2 -35
- package/dist/error/leyyo.error.js +26 -58
- package/dist/error/multiple.error.d.ts +0 -6
- package/dist/error/multiple.error.js +2 -9
- package/dist/function/define-loader.d.ts +0 -6
- package/dist/function/define-loader.js +0 -6
- package/dist/function/delay.d.ts +0 -8
- package/dist/function/delay.js +0 -9
- package/dist/function/delete-prop.d.ts +0 -21
- package/dist/function/delete-prop.js +6 -28
- package/dist/function/empty-fn.d.ts +0 -6
- package/dist/function/empty-fn.js +1 -9
- package/dist/function/extended-type.d.ts +0 -6
- package/dist/function/extended-type.js +18 -24
- package/dist/function/get-fqn.d.ts +0 -6
- package/dist/function/get-fqn.js +2 -8
- package/dist/function/get-prop.d.ts +0 -21
- package/dist/function/get-prop.js +5 -26
- package/dist/function/get-stat.d.ts +0 -20
- package/dist/function/get-stat.js +7 -2
- package/dist/function/has-fqn.d.ts +0 -6
- package/dist/function/has-fqn.js +2 -8
- package/dist/function/index.d.ts +40 -40
- package/dist/function/index.js +40 -40
- package/dist/function/index.types.d.ts +1 -1
- package/dist/function/is-anonymous-name.js +1 -1
- package/dist/function/is-class.d.ts +0 -6
- package/dist/function/is-class.js +2 -20
- package/dist/function/is-empty.d.ts +0 -11
- package/dist/function/is-empty.js +1 -12
- package/dist/function/is-filled-arr.d.ts +0 -9
- package/dist/function/is-filled-arr.js +0 -9
- package/dist/function/is-filled-obj.d.ts +0 -9
- package/dist/function/is-filled-obj.js +0 -9
- package/dist/function/is-obj.d.ts +0 -8
- package/dist/function/is-obj.js +1 -9
- package/dist/function/is-test.d.ts +0 -8
- package/dist/function/is-test.js +3 -19
- package/dist/function/is-text.d.ts +0 -10
- package/dist/function/is-text.js +1 -11
- package/dist/function/jitter-interval.d.ts +0 -9
- package/dist/function/jitter-interval.js +2 -18
- package/dist/function/load-config.d.ts +0 -19
- package/dist/function/load-config.js +10 -61
- package/dist/function/on-fqn-set.js +3 -3
- package/dist/function/one-or-more.d.ts +0 -6
- package/dist/function/one-or-more.js +0 -7
- package/dist/function/opt-add.d.ts +0 -8
- package/dist/function/opt-add.js +2 -10
- package/dist/function/opt-append.d.ts +0 -7
- package/dist/function/opt-append.js +0 -7
- package/dist/function/opt-check.d.ts +0 -6
- package/dist/function/opt-check.js +2 -9
- package/dist/function/opt-clone.d.ts +0 -6
- package/dist/function/opt-clone.js +0 -7
- package/dist/function/opt-field.d.ts +0 -8
- package/dist/function/opt-field.js +6 -14
- package/dist/function/opt-fn.d.ts +0 -6
- package/dist/function/opt-fn.js +0 -7
- package/dist/function/random-test-no.d.ts +0 -5
- package/dist/function/random-test-no.js +0 -5
- package/dist/function/remove-fqn.d.ts +0 -8
- package/dist/function/remove-fqn.js +3 -12
- package/dist/function/run-exporter.d.ts +0 -5
- package/dist/function/run-exporter.js +3 -17
- package/dist/function/secure-clone.js +3 -3
- package/dist/function/secure-json.d.ts +0 -35
- package/dist/function/secure-json.js +12 -54
- package/dist/function/set-anonymous-fqn.js +4 -5
- package/dist/function/set-anonymous-name.js +14 -14
- package/dist/function/set-fqn.d.ts +0 -7
- package/dist/function/set-fqn.js +8 -15
- package/dist/function/set-prop.d.ts +0 -24
- package/dist/function/set-prop.js +6 -30
- package/dist/function/stamp-loader.d.ts +0 -6
- package/dist/function/stamp-loader.js +1 -7
- package/dist/function/test-case.d.ts +0 -7
- package/dist/function/test-case.js +3 -10
- package/dist/function/test-name.d.ts +0 -7
- package/dist/function/test-name.js +2 -9
- package/dist/function/trigger-fqn.js +2 -3
- package/dist/index.d.ts +10 -10
- package/dist/index.foretell.js +7 -10
- package/dist/index.js +10 -11
- package/dist/index.loader.js +1 -8
- package/dist/init/index.js +5 -7
- package/dist/sys/index.d.ts +2 -2
- package/dist/sys/index.js +2 -2
- package/dist/sys/leyyo-storage.d.ts +0 -7
- package/dist/sys/leyyo-storage.js +5 -28
- package/dist/sys/package-json.js +5 -5
- package/package.json +16 -31
|
@@ -1,12 +1,3 @@
|
|
|
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
|
-
* */
|
|
10
1
|
export function isFilledArr(arr) {
|
|
11
2
|
return Array.isArray(arr) && arr.length > 0;
|
|
12
3
|
}
|
|
@@ -1,13 +1,4 @@
|
|
|
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
|
-
* */
|
|
11
2
|
export function isFilledObj(obj) {
|
|
12
3
|
return isObj(obj) && Object.keys(obj).length > 0;
|
|
13
4
|
}
|
package/dist/function/is-obj.js
CHANGED
|
@@ -1,11 +1,3 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Is bare object?
|
|
3
|
-
* Means:
|
|
4
|
-
* - `constructor === "Object"`
|
|
5
|
-
*
|
|
6
|
-
* @param {any} obj - given value
|
|
7
|
-
* @return {boolean} - is bare object?
|
|
8
|
-
* */
|
|
9
1
|
export function isObj(obj) {
|
|
10
|
-
return obj && typeof obj ===
|
|
2
|
+
return obj && typeof obj === "object" && !Array.isArray(obj);
|
|
11
3
|
}
|
package/dist/function/is-test.js
CHANGED
|
@@ -1,32 +1,16 @@
|
|
|
1
|
-
// noinspection JSUnusedGlobalSymbols
|
|
2
|
-
// region properties
|
|
3
|
-
/**
|
|
4
|
-
* Is test?
|
|
5
|
-
* */
|
|
6
1
|
let _isTest;
|
|
7
|
-
// endregion properties
|
|
8
|
-
/**
|
|
9
|
-
* Initialize test
|
|
10
|
-
* */
|
|
11
2
|
export function initTest() {
|
|
12
3
|
_isTest = true;
|
|
13
4
|
if (global) {
|
|
14
5
|
if (!global.leyyo_is_testing) {
|
|
15
6
|
global.leyyo_is_testing = true;
|
|
16
|
-
[
|
|
17
|
-
global.console[name] = () => {
|
|
18
|
-
};
|
|
19
|
-
console[name] = () => {
|
|
20
|
-
};
|
|
7
|
+
["log", "warn", "info", "debug", "trace", "error", "fatal"].forEach((name) => {
|
|
8
|
+
global.console[name] = () => { };
|
|
9
|
+
console[name] = () => { };
|
|
21
10
|
});
|
|
22
11
|
}
|
|
23
12
|
}
|
|
24
13
|
}
|
|
25
|
-
/**
|
|
26
|
-
* Is test?
|
|
27
|
-
*
|
|
28
|
-
* @return {boolean}
|
|
29
|
-
* */
|
|
30
14
|
export function isTest() {
|
|
31
15
|
return _isTest;
|
|
32
16
|
}
|
package/dist/function/is-text.js
CHANGED
|
@@ -1,15 +1,5 @@
|
|
|
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
|
-
* */
|
|
11
1
|
export function isText(str) {
|
|
12
|
-
if (typeof str !==
|
|
2
|
+
if (typeof str !== "string") {
|
|
13
3
|
return false;
|
|
14
4
|
}
|
|
15
5
|
const val = str.trim();
|
|
@@ -1,10 +1 @@
|
|
|
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
|
-
* */
|
|
10
1
|
export declare function jitterInterval(tryCount: number, baseDelay: number, maxDelay: number, maxTryCount?: number): number;
|
|
@@ -1,15 +1,5 @@
|
|
|
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
|
-
* */
|
|
11
1
|
export function jitterInterval(tryCount, baseDelay, maxDelay, maxTryCount) {
|
|
12
|
-
if ([tryCount, baseDelay, maxDelay].some(v => !isValid(v))) {
|
|
2
|
+
if ([tryCount, baseDelay, maxDelay].some((v) => !isValid(v))) {
|
|
13
3
|
return undefined;
|
|
14
4
|
}
|
|
15
5
|
if (isValid(maxTryCount) && tryCount >= maxTryCount) {
|
|
@@ -19,12 +9,6 @@ export function jitterInterval(tryCount, baseDelay, maxDelay, maxTryCount) {
|
|
|
19
9
|
const result = Math.floor(exp / 2 + Math.random() * (exp / 2));
|
|
20
10
|
return Number.isSafeInteger(result) ? result : undefined;
|
|
21
11
|
}
|
|
22
|
-
/**
|
|
23
|
-
* Check value is expected interval value
|
|
24
|
-
*
|
|
25
|
-
* @param {any} value - given value, possible number
|
|
26
|
-
* @return {boolean} - is it expected?
|
|
27
|
-
* */
|
|
28
12
|
function isValid(value) {
|
|
29
|
-
return typeof value ===
|
|
13
|
+
return (typeof value === "number" && value > 0 && Number.isInteger(value) && Number.isSafeInteger(value));
|
|
30
14
|
}
|
|
@@ -1,22 +1,3 @@
|
|
|
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
|
-
* */
|
|
22
3
|
export declare function loadConfig(url: string): LeyyoConfig;
|
|
@@ -2,39 +2,20 @@ import * as fs from "node:fs";
|
|
|
2
2
|
import path from "node:path";
|
|
3
3
|
import { dirname } from "path";
|
|
4
4
|
import { fileURLToPath } from "url";
|
|
5
|
-
import * as yaml from
|
|
5
|
+
import * as yaml from "js-yaml";
|
|
6
6
|
import { isObj } from "./is-obj.js";
|
|
7
7
|
import { getRootStorage } from "../sys/index.js";
|
|
8
8
|
import { isText } from "./is-text.js";
|
|
9
9
|
import { isEmpty } from "./is-empty.js";
|
|
10
10
|
import { secureJson, secureObject } from "./secure-json.js";
|
|
11
|
-
const _NAME =
|
|
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
|
-
* */
|
|
32
13
|
export function loadConfig(url) {
|
|
33
14
|
try {
|
|
34
15
|
const __dirname = dirname(dirname(fileURLToPath(url)));
|
|
35
|
-
const yamlPath = path.normalize(__dirname +
|
|
16
|
+
const yamlPath = path.normalize(__dirname + "/.leyyo.yaml");
|
|
36
17
|
if (fs.existsSync(yamlPath)) {
|
|
37
|
-
const input = fs.readFileSync(yamlPath,
|
|
18
|
+
const input = fs.readFileSync(yamlPath, "utf8");
|
|
38
19
|
const data = yaml.load(input);
|
|
39
20
|
if (isObj(data)) {
|
|
40
21
|
for (const [k, v] of Object.entries(data)) {
|
|
@@ -49,45 +30,33 @@ export function loadConfig(url) {
|
|
|
49
30
|
return undefined;
|
|
50
31
|
}
|
|
51
32
|
}
|
|
52
|
-
/**
|
|
53
|
-
* Get key behaviour
|
|
54
|
-
* @param {string} keyFull - key
|
|
55
|
-
* @return {Array} - tuple as `[behaviour, key]`
|
|
56
|
-
* */
|
|
57
33
|
function _behaviour(keyFull) {
|
|
58
34
|
if (!isText(keyFull)) {
|
|
59
35
|
return [undefined, undefined];
|
|
60
36
|
}
|
|
61
|
-
if (keyFull.endsWith(
|
|
37
|
+
if (keyFull.endsWith("!")) {
|
|
62
38
|
keyFull = keyFull.substring(keyFull.length - 1).trim();
|
|
63
39
|
if (!isText(keyFull)) {
|
|
64
40
|
return [undefined, undefined];
|
|
65
41
|
}
|
|
66
|
-
return [
|
|
42
|
+
return ["override", keyFull];
|
|
67
43
|
}
|
|
68
|
-
else if (keyFull.endsWith(
|
|
44
|
+
else if (keyFull.endsWith("?")) {
|
|
69
45
|
keyFull = keyFull.substring(keyFull.length - 1).trim();
|
|
70
46
|
if (!isText(keyFull)) {
|
|
71
47
|
return [undefined, undefined];
|
|
72
48
|
}
|
|
73
|
-
return [
|
|
49
|
+
return ["merge", keyFull];
|
|
74
50
|
}
|
|
75
51
|
return [undefined, keyFull];
|
|
76
52
|
}
|
|
77
|
-
/**
|
|
78
|
-
* Merge array
|
|
79
|
-
*
|
|
80
|
-
* @param {Array} source
|
|
81
|
-
* @param {string} key
|
|
82
|
-
* @param {Array} value
|
|
83
|
-
* */
|
|
84
53
|
function _array(source, key, value) {
|
|
85
54
|
value.forEach((item, index) => {
|
|
86
55
|
if (isEmpty(item)) {
|
|
87
56
|
console.warn(`[leyyoConfig] value empty at (${key}#${index})`);
|
|
88
57
|
return;
|
|
89
58
|
}
|
|
90
|
-
const clonedSource = source.map(item => JSON.stringify(item));
|
|
59
|
+
const clonedSource = source.map((item) => JSON.stringify(item));
|
|
91
60
|
switch (typeof item) {
|
|
92
61
|
case "string":
|
|
93
62
|
case "number":
|
|
@@ -110,13 +79,6 @@ function _array(source, key, value) {
|
|
|
110
79
|
}
|
|
111
80
|
});
|
|
112
81
|
}
|
|
113
|
-
/**
|
|
114
|
-
* Merge object
|
|
115
|
-
*
|
|
116
|
-
* @param {object} source
|
|
117
|
-
* @param {string} keyFull - key
|
|
118
|
-
* @param {any} value
|
|
119
|
-
* */
|
|
120
82
|
function _object(source, keyFull, value) {
|
|
121
83
|
if (isEmpty(value)) {
|
|
122
84
|
return;
|
|
@@ -129,7 +91,6 @@ function _object(source, keyFull, value) {
|
|
|
129
91
|
if (!source) {
|
|
130
92
|
source = {};
|
|
131
93
|
}
|
|
132
|
-
// old is empty
|
|
133
94
|
if (isEmpty(source[key])) {
|
|
134
95
|
switch (typeof value) {
|
|
135
96
|
case "string":
|
|
@@ -157,7 +118,7 @@ function _object(source, keyFull, value) {
|
|
|
157
118
|
case "override":
|
|
158
119
|
source[key] = value;
|
|
159
120
|
break;
|
|
160
|
-
default:
|
|
121
|
+
default:
|
|
161
122
|
if (isEmpty(source[key])) {
|
|
162
123
|
source[key] = value;
|
|
163
124
|
}
|
|
@@ -165,9 +126,7 @@ function _object(source, keyFull, value) {
|
|
|
165
126
|
}
|
|
166
127
|
break;
|
|
167
128
|
case "object":
|
|
168
|
-
// new is an array
|
|
169
129
|
if (Array.isArray(value)) {
|
|
170
|
-
// old is an array (BOTH)
|
|
171
130
|
if (Array.isArray(source[key])) {
|
|
172
131
|
switch (behaviour) {
|
|
173
132
|
case "override":
|
|
@@ -177,44 +136,35 @@ function _object(source, keyFull, value) {
|
|
|
177
136
|
_array(source[key], key, value);
|
|
178
137
|
break;
|
|
179
138
|
default:
|
|
180
|
-
// old exists, ignore
|
|
181
139
|
break;
|
|
182
140
|
}
|
|
183
141
|
}
|
|
184
|
-
// CONFLICT: old is not array
|
|
185
142
|
else {
|
|
186
143
|
switch (behaviour) {
|
|
187
144
|
case "override":
|
|
188
145
|
source[key] = secureObject(value);
|
|
189
146
|
break;
|
|
190
147
|
case "merge":
|
|
191
|
-
// old is different, conflict
|
|
192
148
|
console.warn(`[leyyoConfig] type is conflicted at (${key})`);
|
|
193
149
|
break;
|
|
194
150
|
default:
|
|
195
|
-
// old exists, ignore
|
|
196
151
|
break;
|
|
197
152
|
}
|
|
198
153
|
}
|
|
199
154
|
}
|
|
200
|
-
// new is an object
|
|
201
155
|
else {
|
|
202
|
-
// CONFLICT: old is not object
|
|
203
156
|
if (Array.isArray(source[key])) {
|
|
204
157
|
switch (behaviour) {
|
|
205
158
|
case "override":
|
|
206
159
|
source[key] = value;
|
|
207
160
|
break;
|
|
208
161
|
case "merge":
|
|
209
|
-
// old is different, conflict
|
|
210
162
|
console.warn(`[leyyoConfig] type is conflicted at (${key})`);
|
|
211
163
|
break;
|
|
212
164
|
default:
|
|
213
|
-
// old exists, ignore
|
|
214
165
|
break;
|
|
215
166
|
}
|
|
216
167
|
}
|
|
217
|
-
// old is an object (BOTH)
|
|
218
168
|
else {
|
|
219
169
|
switch (behaviour) {
|
|
220
170
|
case "override":
|
|
@@ -226,7 +176,6 @@ function _object(source, keyFull, value) {
|
|
|
226
176
|
}
|
|
227
177
|
break;
|
|
228
178
|
default:
|
|
229
|
-
// old exists, ignore
|
|
230
179
|
break;
|
|
231
180
|
}
|
|
232
181
|
}
|
|
@@ -3,13 +3,13 @@ export function onFqnSet(target, callback) {
|
|
|
3
3
|
if (!target) {
|
|
4
4
|
return false;
|
|
5
5
|
}
|
|
6
|
-
if (typeof callback !==
|
|
6
|
+
if (typeof callback !== "function") {
|
|
7
7
|
return false;
|
|
8
8
|
}
|
|
9
|
-
if (typeof target ===
|
|
9
|
+
if (typeof target === "function") {
|
|
10
10
|
return _item(target, callback);
|
|
11
11
|
}
|
|
12
|
-
else if (typeof target ===
|
|
12
|
+
else if (typeof target === "object") {
|
|
13
13
|
if (Array.isArray(target)) {
|
|
14
14
|
if (target[KEY_LITERAL_NAME]) {
|
|
15
15
|
return _item(target, callback);
|
|
@@ -1,8 +1,2 @@
|
|
|
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
|
-
* */
|
|
8
2
|
export declare function oneOrMore<T = unknown>(value: OneOrMore<T>): Array<T> | undefined;
|
|
@@ -1,10 +1,3 @@
|
|
|
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
|
-
* */
|
|
8
1
|
export function oneOrMore(value) {
|
|
9
2
|
if (Array.isArray(value)) {
|
|
10
3
|
return value;
|
|
@@ -1,10 +1,2 @@
|
|
|
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
|
-
* */
|
|
10
2
|
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,19 +1,11 @@
|
|
|
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
|
-
* */
|
|
11
3
|
export function optAdd(options, key, value) {
|
|
12
4
|
const o = (isObj(options) ? options : {});
|
|
13
|
-
if (value === undefined || typeof key !==
|
|
5
|
+
if (value === undefined || typeof key !== "string") {
|
|
14
6
|
return o;
|
|
15
7
|
}
|
|
16
|
-
if (key ===
|
|
8
|
+
if (key === "field") {
|
|
17
9
|
return optField(o, value);
|
|
18
10
|
}
|
|
19
11
|
if (o[key] === undefined) {
|
|
@@ -1,9 +1,2 @@
|
|
|
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
|
-
* */
|
|
9
2
|
export declare function optAppend<O extends Opt = Opt>(options: O | Opt, appended: O | Opt): O;
|
|
@@ -1,12 +1,5 @@
|
|
|
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
|
-
* */
|
|
10
3
|
export function optAppend(options, appended) {
|
|
11
4
|
const o = (isObj(options) ? options : {});
|
|
12
5
|
if (!isObj(appended)) {
|
|
@@ -1,8 +1,2 @@
|
|
|
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
|
-
* */
|
|
8
2
|
export declare function optCheck<O extends Opt = Opt>(options: O | OptFn<O> | Opt): O;
|
|
@@ -1,18 +1,11 @@
|
|
|
1
|
-
// noinspection JSUnusedGlobalSymbols
|
|
2
1
|
import { $$get_leyyo_fn } from "./leyyo-fn.js";
|
|
3
2
|
import { isObj } from "./is-obj.js";
|
|
4
3
|
import { FQN } from "../internal.js";
|
|
5
4
|
let _leyyo;
|
|
6
5
|
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
|
-
* */
|
|
13
6
|
export function optCheck(options) {
|
|
14
7
|
let o = options;
|
|
15
|
-
if (typeof options ===
|
|
8
|
+
if (typeof options === "function") {
|
|
16
9
|
try {
|
|
17
10
|
o = options();
|
|
18
11
|
}
|
|
@@ -21,7 +14,7 @@ export function optCheck(options) {
|
|
|
21
14
|
if (!_leyyo) {
|
|
22
15
|
_leyyo = $$get_leyyo_fn();
|
|
23
16
|
}
|
|
24
|
-
new _leyyo.developerError(
|
|
17
|
+
new _leyyo.developerError("Raised callback run", "optCheck#01", where).log(e);
|
|
25
18
|
}
|
|
26
19
|
}
|
|
27
20
|
else if (!isObj(options)) {
|
|
@@ -1,12 +1,5 @@
|
|
|
1
|
-
// noinspection JSUnusedGlobalSymbols
|
|
2
1
|
import { isObj } from "./is-obj.js";
|
|
3
2
|
import { secureClone } from "./secure-clone.js";
|
|
4
|
-
/**
|
|
5
|
-
* Clone existing option
|
|
6
|
-
*
|
|
7
|
-
* @param {Opt} options - source options
|
|
8
|
-
* @return {Opt} - cloned options
|
|
9
|
-
* */
|
|
10
3
|
export function optClone(options) {
|
|
11
4
|
return (isObj(options) ? secureClone(options) : {});
|
|
12
5
|
}
|
|
@@ -1,11 +1,3 @@
|
|
|
1
1
|
import { Opt } from "./index.types.js";
|
|
2
2
|
import { KeyValue } from "../base/index.js";
|
|
3
|
-
/**
|
|
4
|
-
* Add field into options
|
|
5
|
-
* Note: field could not be multiple in option
|
|
6
|
-
*
|
|
7
|
-
* @param {Opt} options - source options
|
|
8
|
-
* @param {KeyValue} field - value
|
|
9
|
-
* @return {Opt} - added options
|
|
10
|
-
* */
|
|
11
3
|
export declare function optField<O extends Opt = Opt>(options: O | Opt, field: KeyValue): O;
|
|
@@ -1,31 +1,23 @@
|
|
|
1
1
|
import { isObj } from "./is-obj.js";
|
|
2
|
-
/**
|
|
3
|
-
* Add field into options
|
|
4
|
-
* Note: field could not be multiple in option
|
|
5
|
-
*
|
|
6
|
-
* @param {Opt} options - source options
|
|
7
|
-
* @param {KeyValue} field - value
|
|
8
|
-
* @return {Opt} - added options
|
|
9
|
-
* */
|
|
10
2
|
export function optField(options, field) {
|
|
11
3
|
const o = (isObj(options) ? options : {});
|
|
12
4
|
const t = typeof field;
|
|
13
|
-
if (![
|
|
5
|
+
if (!["string", "number"].includes(t)) {
|
|
14
6
|
return o;
|
|
15
7
|
}
|
|
16
8
|
if (o.field !== undefined) {
|
|
17
|
-
if (typeof o.field !==
|
|
18
|
-
o.field =
|
|
9
|
+
if (typeof o.field !== "string") {
|
|
10
|
+
o.field = "";
|
|
19
11
|
}
|
|
20
12
|
}
|
|
21
13
|
else {
|
|
22
|
-
o.field =
|
|
14
|
+
o.field = "";
|
|
23
15
|
}
|
|
24
16
|
if (!o.field) {
|
|
25
|
-
o.field =
|
|
17
|
+
o.field = t === "string" ? field : `$.[${field}]`;
|
|
26
18
|
}
|
|
27
19
|
else {
|
|
28
|
-
o.field +=
|
|
20
|
+
o.field += t === "string" ? `.${field}` : `[${field}]`;
|
|
29
21
|
}
|
|
30
22
|
return o;
|
|
31
23
|
}
|
|
@@ -1,8 +1,2 @@
|
|
|
1
1
|
import { Opt } from "./index.types.js";
|
|
2
|
-
/**
|
|
3
|
-
* It's used to easy arrow function usage for lazy evaluation of options
|
|
4
|
-
*
|
|
5
|
-
* @param {Opt} options - options
|
|
6
|
-
* @return {Opt} - options
|
|
7
|
-
* */
|
|
8
2
|
export declare function optFn<O extends Opt = Opt>(options: O | Opt): O;
|
package/dist/function/opt-fn.js
CHANGED
|
@@ -1,11 +1,4 @@
|
|
|
1
1
|
import { isObj } from "./is-obj.js";
|
|
2
|
-
// noinspection JSUnusedGlobalSymbols
|
|
3
|
-
/**
|
|
4
|
-
* It's used to easy arrow function usage for lazy evaluation of options
|
|
5
|
-
*
|
|
6
|
-
* @param {Opt} options - options
|
|
7
|
-
* @return {Opt} - options
|
|
8
|
-
* */
|
|
9
2
|
export function optFn(options) {
|
|
10
3
|
return (isObj(options) ? options : {});
|
|
11
4
|
}
|