@bemedev/decompose 2.0.3 → 2.2.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/lib/constants/index.cjs +9 -14
- package/lib/constants/index.js +3 -3
- package/lib/constants/objects.cjs +10 -9
- package/lib/constants/objects.cjs.map +1 -1
- package/lib/constants/objects.js +9 -7
- package/lib/constants/objects.js.map +1 -1
- package/lib/constants/strings.cjs +9 -8
- package/lib/constants/strings.cjs.map +1 -1
- package/lib/constants/strings.js +8 -6
- package/lib/constants/strings.js.map +1 -1
- package/lib/contexts/assign.cjs +34 -43
- package/lib/contexts/assign.cjs.map +1 -1
- package/lib/contexts/assign.js +33 -41
- package/lib/contexts/assign.js.map +1 -1
- package/lib/contexts/constants.cjs +8 -7
- package/lib/contexts/constants.cjs.map +1 -1
- package/lib/contexts/constants.js +7 -5
- package/lib/contexts/constants.js.map +1 -1
- package/lib/contexts/get.cjs +20 -22
- package/lib/contexts/get.cjs.map +1 -1
- package/lib/contexts/get.js +19 -20
- package/lib/contexts/get.js.map +1 -1
- package/lib/contexts/index.cjs +5 -10
- package/lib/contexts/index.js +3 -3
- package/lib/decompose.cjs +53 -65
- package/lib/decompose.cjs.map +1 -1
- package/lib/decompose.js +52 -63
- package/lib/decompose.js.map +1 -1
- package/lib/decomposeKeys.cjs +27 -33
- package/lib/decomposeKeys.cjs.map +1 -1
- package/lib/decomposeKeys.js +25 -30
- package/lib/decomposeKeys.js.map +1 -1
- package/lib/decomposeSV.cjs +25 -28
- package/lib/decomposeSV.cjs.map +1 -1
- package/lib/decomposeSV.js +22 -24
- package/lib/decomposeSV.js.map +1 -1
- package/lib/flatByKey.cjs +26 -22
- package/lib/flatByKey.cjs.map +1 -1
- package/lib/flatByKey.js +25 -20
- package/lib/flatByKey.js.map +1 -1
- package/lib/helpers.cjs +10 -13
- package/lib/helpers.cjs.map +1 -1
- package/lib/helpers.js +9 -11
- package/lib/helpers.js.map +1 -1
- package/lib/index.cjs +27 -31
- package/lib/index.js +12 -11
- package/lib/recompose.cjs +43 -51
- package/lib/recompose.cjs.map +1 -1
- package/lib/recompose.js +42 -49
- package/lib/recompose.js.map +1 -1
- package/lib/sortMap.cjs +6 -5
- package/lib/sortMap.cjs.map +1 -1
- package/lib/sortMap.js +5 -3
- package/lib/sortMap.js.map +1 -1
- package/lib/types.types.d.ts +8 -9
- package/lib/types.types.d.ts.map +1 -1
- package/package.json +41 -33
- package/lib/constants/index.cjs.map +0 -1
- package/lib/constants/index.js.map +0 -1
- package/lib/contexts/index.cjs.map +0 -1
- package/lib/contexts/index.js.map +0 -1
- package/lib/index.cjs.map +0 -1
- package/lib/index.js.map +0 -1
package/lib/decompose.cjs
CHANGED
|
@@ -1,73 +1,61 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
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
|
-
output.push([`${prev}`, arg]);
|
|
35
|
-
const entries1 = Object.entries(arg);
|
|
36
|
-
entries1.forEach(([key, value]) => {
|
|
37
|
-
const values = ddecompose(value, `${_prev}${key}`, options, false);
|
|
38
|
-
output.push(...values);
|
|
39
|
-
});
|
|
40
|
-
return output;
|
|
1
|
+
Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
|
|
2
|
+
const require_constants_strings = require("./constants/strings.cjs");
|
|
3
|
+
const require_constants_objects = require("./constants/objects.cjs");
|
|
4
|
+
const require_helpers = require("./helpers.cjs");
|
|
5
|
+
//#region src/decompose.ts
|
|
6
|
+
function ddecompose(arg, prev = "", options = require_constants_objects.DEFAULT_DECOMPOSE_OPTIONS, first = true) {
|
|
7
|
+
const { object } = {
|
|
8
|
+
...require_constants_objects.DEFAULT_DECOMPOSE_OPTIONS,
|
|
9
|
+
...options
|
|
10
|
+
};
|
|
11
|
+
const canAddObjectKeys = object === "both" || object === "object";
|
|
12
|
+
const canAddKeys = object === "both" || object === "key";
|
|
13
|
+
const _prev = prev ? prev + require_constants_strings.DELIMITER : "";
|
|
14
|
+
const output = [];
|
|
15
|
+
if (Array.isArray(arg)) {
|
|
16
|
+
if (canAddObjectKeys && !first) output.push([`${prev}`, arg]);
|
|
17
|
+
arg.forEach((item, index) => {
|
|
18
|
+
const values = ddecompose(item, `${_prev}${require_constants_strings.LEFT_BRACKET}${index}${require_constants_strings.RIGHT_BRACKET}`, options, false);
|
|
19
|
+
output.push(...values);
|
|
20
|
+
});
|
|
21
|
+
return output;
|
|
22
|
+
}
|
|
23
|
+
if (require_helpers.isPrimitive(arg)) {
|
|
24
|
+
const isFirst = !prev.includes(require_constants_strings.DELIMITER);
|
|
25
|
+
if (canAddKeys || isFirst) output.push([`${prev}`, arg]);
|
|
26
|
+
return output;
|
|
27
|
+
}
|
|
28
|
+
if (canAddObjectKeys && prev !== "") output.push([`${prev}`, arg]);
|
|
29
|
+
Object.entries(arg).forEach(([key, value]) => {
|
|
30
|
+
const values = ddecompose(value, `${_prev}${key}`, options, false);
|
|
31
|
+
output.push(...values);
|
|
32
|
+
});
|
|
33
|
+
return output;
|
|
41
34
|
}
|
|
42
35
|
const _decompose = (val, options) => {
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
.replace(regexRight, `]`);
|
|
61
|
-
const key = start ? `${sep}${_key}` : _key;
|
|
62
|
-
return [key, value];
|
|
63
|
-
});
|
|
64
|
-
const output = Object.fromEntries(entries2);
|
|
65
|
-
return output;
|
|
36
|
+
const entries1 = ddecompose(val, "", options);
|
|
37
|
+
const { sep, start } = {
|
|
38
|
+
...require_constants_objects.DEFAULT_DECOMPOSE_OPTIONS,
|
|
39
|
+
...options
|
|
40
|
+
};
|
|
41
|
+
if (entries1.length == 0) {
|
|
42
|
+
if (Array.isArray(val)) return [];
|
|
43
|
+
return {};
|
|
44
|
+
}
|
|
45
|
+
const regexDel = new RegExp(require_constants_strings.DELIMITER, "g");
|
|
46
|
+
const regexLeft = new RegExp(require_constants_strings.LEFT_BRACKET, "g");
|
|
47
|
+
const regexRight = new RegExp(require_constants_strings.RIGHT_BRACKET, "g");
|
|
48
|
+
const entries2 = entries1.map(([__key, value]) => {
|
|
49
|
+
const _key = __key.replace(regexDel, sep).replace(regexLeft, `[`).replace(regexRight, `]`);
|
|
50
|
+
return [start ? `${sep}${_key}` : _key, value];
|
|
51
|
+
});
|
|
52
|
+
return Object.fromEntries(entries2);
|
|
66
53
|
};
|
|
67
54
|
/* v8 ignore next 1 */
|
|
68
55
|
const decompose = (val, options) => _decompose(val, options);
|
|
69
56
|
decompose.low = decompose;
|
|
70
57
|
decompose.strict = decompose;
|
|
71
|
-
|
|
58
|
+
//#endregion
|
|
72
59
|
exports.decompose = decompose;
|
|
73
|
-
|
|
60
|
+
|
|
61
|
+
//# sourceMappingURL=decompose.cjs.map
|
package/lib/decompose.cjs.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"decompose.cjs","sources":["../src/decompose.ts"],"sourcesContent":["import { DEFAULT_DECOMPOSE_OPTIONS } from './constants';\nimport {\n DELIMITER,\n LEFT_BRACKET,\n RIGHT_BRACKET,\n} from './constants/strings';\nimport { isPrimitive } from './helpers';\nimport type { Decompose, DecomposeOptions } from './types.types';\n\nfunction ddecompose(\n arg: any,\n prev = '',\n options: DecomposeOptions = DEFAULT_DECOMPOSE_OPTIONS,\n first = true,\n) {\n const { object } = {\n ...DEFAULT_DECOMPOSE_OPTIONS,\n ...options,\n };\n const canAddObjectKeys = object === 'both' || object === 'object';\n const canAddKeys = object === 'both' || object === 'key';\n\n const _prev = prev ? prev + DELIMITER : '';\n const output: [string, any][] = [];\n\n const isArray = Array.isArray(arg);\n if (isArray) {\n if (canAddObjectKeys && !first) output.push([`${prev}`, arg]);\n\n arg.forEach((item, index) => {\n const values = ddecompose(\n item,\n `${_prev}${LEFT_BRACKET}${index}${RIGHT_BRACKET}`,\n options,\n false,\n );\n output.push(...values);\n });\n return output;\n }\n\n const isPrimit = isPrimitive(arg);\n if (isPrimit) {\n const isFirst = !prev.includes(DELIMITER);\n if (canAddKeys || isFirst) output.push([`${prev}`, arg]);\n return output;\n }\n\n if (canAddObjectKeys && prev !== '') output.push([`${prev}`, arg]);\n\n const entries1 = Object.entries(arg);\n entries1.forEach(([key, value]) => {\n const values = ddecompose(value, `${_prev}${key}`, options, false);\n output.push(...values);\n });\n\n return output;\n}\n\ntype Decompose_F = <\n T,\n const O extends DecomposeOptions = typeof DEFAULT_DECOMPOSE_OPTIONS,\n>(\n val: T,\n options?: O,\n) => Decompose<T, O>;\ntype _Decompose_F = (val: any, options?: DecomposeOptions) => any;\n\nexport type Decomposer = Decompose_F & {\n strict: Decompose_F;\n low: _Decompose_F;\n};\n\nconst _decompose: _Decompose_F = (val, options) => {\n const entries1 = ddecompose(val, '', options);\n\n const { sep, start } = {\n ...DEFAULT_DECOMPOSE_OPTIONS,\n ...options,\n };\n if (entries1.length == 0) {\n if (Array.isArray(val)) return [];\n return {};\n }\n\n const regexDel = new RegExp(DELIMITER, 'g');\n const regexLeft = new RegExp(LEFT_BRACKET, 'g');\n const regexRight = new RegExp(RIGHT_BRACKET, 'g');\n const entries2 = entries1.map(([__key, value]) => {\n const _key = __key\n .replace(regexDel, sep)\n .replace(regexLeft, `[`)\n .replace(regexRight, `]`);\n const key = start ? `${sep}${_key}` : _key;\n return [key, value];\n });\n\n const output = Object.fromEntries(entries2);\n return output;\n};\n\n/* v8 ignore next 1 */\nexport const decompose: Decomposer = (val, options) =>\n _decompose(val, options);\ndecompose.low = decompose;\ndecompose.strict = decompose;\n"],"
|
|
1
|
+
{"version":3,"file":"decompose.cjs","names":["DEFAULT_DECOMPOSE_OPTIONS","DELIMITER","LEFT_BRACKET","RIGHT_BRACKET","isPrimitive"],"sources":["../src/decompose.ts"],"sourcesContent":["import { DEFAULT_DECOMPOSE_OPTIONS } from './constants';\nimport {\n DELIMITER,\n LEFT_BRACKET,\n RIGHT_BRACKET,\n} from './constants/strings';\nimport { isPrimitive } from './helpers';\nimport type { Decompose, DecomposeOptions } from './types.types';\n\nfunction ddecompose(\n arg: any,\n prev = '',\n options: DecomposeOptions = DEFAULT_DECOMPOSE_OPTIONS,\n first = true,\n) {\n const { object } = {\n ...DEFAULT_DECOMPOSE_OPTIONS,\n ...options,\n };\n const canAddObjectKeys = object === 'both' || object === 'object';\n const canAddKeys = object === 'both' || object === 'key';\n\n const _prev = prev ? prev + DELIMITER : '';\n const output: [string, any][] = [];\n\n const isArray = Array.isArray(arg);\n if (isArray) {\n if (canAddObjectKeys && !first) output.push([`${prev}`, arg]);\n\n arg.forEach((item, index) => {\n const values = ddecompose(\n item,\n `${_prev}${LEFT_BRACKET}${index}${RIGHT_BRACKET}`,\n options,\n false,\n );\n output.push(...values);\n });\n return output;\n }\n\n const isPrimit = isPrimitive(arg);\n if (isPrimit) {\n const isFirst = !prev.includes(DELIMITER);\n if (canAddKeys || isFirst) output.push([`${prev}`, arg]);\n return output;\n }\n\n if (canAddObjectKeys && prev !== '') output.push([`${prev}`, arg]);\n\n const entries1 = Object.entries(arg);\n entries1.forEach(([key, value]) => {\n const values = ddecompose(value, `${_prev}${key}`, options, false);\n output.push(...values);\n });\n\n return output;\n}\n\ntype Decompose_F = <\n T,\n const O extends DecomposeOptions = typeof DEFAULT_DECOMPOSE_OPTIONS,\n>(\n val: T,\n options?: O,\n) => Decompose<T, O>;\ntype _Decompose_F = (val: any, options?: DecomposeOptions) => any;\n\nexport type Decomposer = Decompose_F & {\n strict: Decompose_F;\n low: _Decompose_F;\n};\n\nconst _decompose: _Decompose_F = (val, options) => {\n const entries1 = ddecompose(val, '', options);\n\n const { sep, start } = {\n ...DEFAULT_DECOMPOSE_OPTIONS,\n ...options,\n };\n if (entries1.length == 0) {\n if (Array.isArray(val)) return [];\n return {};\n }\n\n const regexDel = new RegExp(DELIMITER, 'g');\n const regexLeft = new RegExp(LEFT_BRACKET, 'g');\n const regexRight = new RegExp(RIGHT_BRACKET, 'g');\n const entries2 = entries1.map(([__key, value]) => {\n const _key = __key\n .replace(regexDel, sep)\n .replace(regexLeft, `[`)\n .replace(regexRight, `]`);\n const key = start ? `${sep}${_key}` : _key;\n return [key, value];\n });\n\n const output = Object.fromEntries(entries2);\n return output;\n};\n\n/* v8 ignore next 1 */\nexport const decompose: Decomposer = (val, options) =>\n _decompose(val, options);\ndecompose.low = decompose;\ndecompose.strict = decompose;\n"],"mappings":";;;;;AASA,SAAS,WACP,KACA,OAAO,IACP,UAA4BA,0BAAAA,2BAC5B,QAAQ,MACR;CACA,MAAM,EAAE,WAAW;EACjB,GAAGA,0BAAAA;EACH,GAAG;EACJ;CACD,MAAM,mBAAmB,WAAW,UAAU,WAAW;CACzD,MAAM,aAAa,WAAW,UAAU,WAAW;CAEnD,MAAM,QAAQ,OAAO,OAAOC,0BAAAA,YAAY;CACxC,MAAM,SAA0B,EAAE;AAGlC,KADgB,MAAM,QAAQ,IAAI,EACrB;AACX,MAAI,oBAAoB,CAAC,MAAO,QAAO,KAAK,CAAC,GAAG,QAAQ,IAAI,CAAC;AAE7D,MAAI,SAAS,MAAM,UAAU;GAC3B,MAAM,SAAS,WACb,MACA,GAAG,QAAQC,0BAAAA,eAAe,QAAQC,0BAAAA,iBAClC,SACA,MACD;AACD,UAAO,KAAK,GAAG,OAAO;IACtB;AACF,SAAO;;AAIT,KADiBC,gBAAAA,YAAY,IAAI,EACnB;EACZ,MAAM,UAAU,CAAC,KAAK,SAASH,0BAAAA,UAAU;AACzC,MAAI,cAAc,QAAS,QAAO,KAAK,CAAC,GAAG,QAAQ,IAAI,CAAC;AACxD,SAAO;;AAGT,KAAI,oBAAoB,SAAS,GAAI,QAAO,KAAK,CAAC,GAAG,QAAQ,IAAI,CAAC;AAEjD,QAAO,QAAQ,IAAI,CAC3B,SAAS,CAAC,KAAK,WAAW;EACjC,MAAM,SAAS,WAAW,OAAO,GAAG,QAAQ,OAAO,SAAS,MAAM;AAClE,SAAO,KAAK,GAAG,OAAO;GACtB;AAEF,QAAO;;AAiBT,MAAM,cAA4B,KAAK,YAAY;CACjD,MAAM,WAAW,WAAW,KAAK,IAAI,QAAQ;CAE7C,MAAM,EAAE,KAAK,UAAU;EACrB,GAAGD,0BAAAA;EACH,GAAG;EACJ;AACD,KAAI,SAAS,UAAU,GAAG;AACxB,MAAI,MAAM,QAAQ,IAAI,CAAE,QAAO,EAAE;AACjC,SAAO,EAAE;;CAGX,MAAM,WAAW,IAAI,OAAOC,0BAAAA,WAAW,IAAI;CAC3C,MAAM,YAAY,IAAI,OAAOC,0BAAAA,cAAc,IAAI;CAC/C,MAAM,aAAa,IAAI,OAAOC,0BAAAA,eAAe,IAAI;CACjD,MAAM,WAAW,SAAS,KAAK,CAAC,OAAO,WAAW;EAChD,MAAM,OAAO,MACV,QAAQ,UAAU,IAAI,CACtB,QAAQ,WAAW,IAAI,CACvB,QAAQ,YAAY,IAAI;AAE3B,SAAO,CADK,QAAQ,GAAG,MAAM,SAAS,MACzB,MAAM;GACnB;AAGF,QADe,OAAO,YAAY,SAAS;;;AAK7C,MAAa,aAAyB,KAAK,YACzC,WAAW,KAAK,QAAQ;AAC1B,UAAU,MAAM;AAChB,UAAU,SAAS"}
|
package/lib/decompose.js
CHANGED
|
@@ -1,71 +1,60 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import {
|
|
3
|
-
import { isPrimitive } from
|
|
4
|
-
|
|
5
|
-
function ddecompose(arg, prev =
|
|
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
|
-
const entries1 = Object.entries(arg);
|
|
34
|
-
entries1.forEach(([key, value]) => {
|
|
35
|
-
const values = ddecompose(value, `${_prev}${key}`, options, false);
|
|
36
|
-
output.push(...values);
|
|
37
|
-
});
|
|
38
|
-
return output;
|
|
1
|
+
import { DELIMITER, LEFT_BRACKET, RIGHT_BRACKET } from "./constants/strings.js";
|
|
2
|
+
import { DEFAULT_DECOMPOSE_OPTIONS } from "./constants/objects.js";
|
|
3
|
+
import { isPrimitive } from "./helpers.js";
|
|
4
|
+
//#region src/decompose.ts
|
|
5
|
+
function ddecompose(arg, prev = "", options = DEFAULT_DECOMPOSE_OPTIONS, first = true) {
|
|
6
|
+
const { object } = {
|
|
7
|
+
...DEFAULT_DECOMPOSE_OPTIONS,
|
|
8
|
+
...options
|
|
9
|
+
};
|
|
10
|
+
const canAddObjectKeys = object === "both" || object === "object";
|
|
11
|
+
const canAddKeys = object === "both" || object === "key";
|
|
12
|
+
const _prev = prev ? prev + DELIMITER : "";
|
|
13
|
+
const output = [];
|
|
14
|
+
if (Array.isArray(arg)) {
|
|
15
|
+
if (canAddObjectKeys && !first) output.push([`${prev}`, arg]);
|
|
16
|
+
arg.forEach((item, index) => {
|
|
17
|
+
const values = ddecompose(item, `${_prev}${LEFT_BRACKET}${index}${RIGHT_BRACKET}`, options, false);
|
|
18
|
+
output.push(...values);
|
|
19
|
+
});
|
|
20
|
+
return output;
|
|
21
|
+
}
|
|
22
|
+
if (isPrimitive(arg)) {
|
|
23
|
+
const isFirst = !prev.includes(DELIMITER);
|
|
24
|
+
if (canAddKeys || isFirst) output.push([`${prev}`, arg]);
|
|
25
|
+
return output;
|
|
26
|
+
}
|
|
27
|
+
if (canAddObjectKeys && prev !== "") output.push([`${prev}`, arg]);
|
|
28
|
+
Object.entries(arg).forEach(([key, value]) => {
|
|
29
|
+
const values = ddecompose(value, `${_prev}${key}`, options, false);
|
|
30
|
+
output.push(...values);
|
|
31
|
+
});
|
|
32
|
+
return output;
|
|
39
33
|
}
|
|
40
34
|
const _decompose = (val, options) => {
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
.replace(regexRight, `]`);
|
|
59
|
-
const key = start ? `${sep}${_key}` : _key;
|
|
60
|
-
return [key, value];
|
|
61
|
-
});
|
|
62
|
-
const output = Object.fromEntries(entries2);
|
|
63
|
-
return output;
|
|
35
|
+
const entries1 = ddecompose(val, "", options);
|
|
36
|
+
const { sep, start } = {
|
|
37
|
+
...DEFAULT_DECOMPOSE_OPTIONS,
|
|
38
|
+
...options
|
|
39
|
+
};
|
|
40
|
+
if (entries1.length == 0) {
|
|
41
|
+
if (Array.isArray(val)) return [];
|
|
42
|
+
return {};
|
|
43
|
+
}
|
|
44
|
+
const regexDel = new RegExp(DELIMITER, "g");
|
|
45
|
+
const regexLeft = new RegExp(LEFT_BRACKET, "g");
|
|
46
|
+
const regexRight = new RegExp(RIGHT_BRACKET, "g");
|
|
47
|
+
const entries2 = entries1.map(([__key, value]) => {
|
|
48
|
+
const _key = __key.replace(regexDel, sep).replace(regexLeft, `[`).replace(regexRight, `]`);
|
|
49
|
+
return [start ? `${sep}${_key}` : _key, value];
|
|
50
|
+
});
|
|
51
|
+
return Object.fromEntries(entries2);
|
|
64
52
|
};
|
|
65
53
|
/* v8 ignore next 1 */
|
|
66
54
|
const decompose = (val, options) => _decompose(val, options);
|
|
67
55
|
decompose.low = decompose;
|
|
68
56
|
decompose.strict = decompose;
|
|
69
|
-
|
|
57
|
+
//#endregion
|
|
70
58
|
export { decompose };
|
|
71
|
-
|
|
59
|
+
|
|
60
|
+
//# sourceMappingURL=decompose.js.map
|
package/lib/decompose.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"decompose.js","sources":["../src/decompose.ts"],"sourcesContent":["import { DEFAULT_DECOMPOSE_OPTIONS } from './constants';\nimport {\n DELIMITER,\n LEFT_BRACKET,\n RIGHT_BRACKET,\n} from './constants/strings';\nimport { isPrimitive } from './helpers';\nimport type { Decompose, DecomposeOptions } from './types.types';\n\nfunction ddecompose(\n arg: any,\n prev = '',\n options: DecomposeOptions = DEFAULT_DECOMPOSE_OPTIONS,\n first = true,\n) {\n const { object } = {\n ...DEFAULT_DECOMPOSE_OPTIONS,\n ...options,\n };\n const canAddObjectKeys = object === 'both' || object === 'object';\n const canAddKeys = object === 'both' || object === 'key';\n\n const _prev = prev ? prev + DELIMITER : '';\n const output: [string, any][] = [];\n\n const isArray = Array.isArray(arg);\n if (isArray) {\n if (canAddObjectKeys && !first) output.push([`${prev}`, arg]);\n\n arg.forEach((item, index) => {\n const values = ddecompose(\n item,\n `${_prev}${LEFT_BRACKET}${index}${RIGHT_BRACKET}`,\n options,\n false,\n );\n output.push(...values);\n });\n return output;\n }\n\n const isPrimit = isPrimitive(arg);\n if (isPrimit) {\n const isFirst = !prev.includes(DELIMITER);\n if (canAddKeys || isFirst) output.push([`${prev}`, arg]);\n return output;\n }\n\n if (canAddObjectKeys && prev !== '') output.push([`${prev}`, arg]);\n\n const entries1 = Object.entries(arg);\n entries1.forEach(([key, value]) => {\n const values = ddecompose(value, `${_prev}${key}`, options, false);\n output.push(...values);\n });\n\n return output;\n}\n\ntype Decompose_F = <\n T,\n const O extends DecomposeOptions = typeof DEFAULT_DECOMPOSE_OPTIONS,\n>(\n val: T,\n options?: O,\n) => Decompose<T, O>;\ntype _Decompose_F = (val: any, options?: DecomposeOptions) => any;\n\nexport type Decomposer = Decompose_F & {\n strict: Decompose_F;\n low: _Decompose_F;\n};\n\nconst _decompose: _Decompose_F = (val, options) => {\n const entries1 = ddecompose(val, '', options);\n\n const { sep, start } = {\n ...DEFAULT_DECOMPOSE_OPTIONS,\n ...options,\n };\n if (entries1.length == 0) {\n if (Array.isArray(val)) return [];\n return {};\n }\n\n const regexDel = new RegExp(DELIMITER, 'g');\n const regexLeft = new RegExp(LEFT_BRACKET, 'g');\n const regexRight = new RegExp(RIGHT_BRACKET, 'g');\n const entries2 = entries1.map(([__key, value]) => {\n const _key = __key\n .replace(regexDel, sep)\n .replace(regexLeft, `[`)\n .replace(regexRight, `]`);\n const key = start ? `${sep}${_key}` : _key;\n return [key, value];\n });\n\n const output = Object.fromEntries(entries2);\n return output;\n};\n\n/* v8 ignore next 1 */\nexport const decompose: Decomposer = (val, options) =>\n _decompose(val, options);\ndecompose.low = decompose;\ndecompose.strict = decompose;\n"],"
|
|
1
|
+
{"version":3,"file":"decompose.js","names":[],"sources":["../src/decompose.ts"],"sourcesContent":["import { DEFAULT_DECOMPOSE_OPTIONS } from './constants';\nimport {\n DELIMITER,\n LEFT_BRACKET,\n RIGHT_BRACKET,\n} from './constants/strings';\nimport { isPrimitive } from './helpers';\nimport type { Decompose, DecomposeOptions } from './types.types';\n\nfunction ddecompose(\n arg: any,\n prev = '',\n options: DecomposeOptions = DEFAULT_DECOMPOSE_OPTIONS,\n first = true,\n) {\n const { object } = {\n ...DEFAULT_DECOMPOSE_OPTIONS,\n ...options,\n };\n const canAddObjectKeys = object === 'both' || object === 'object';\n const canAddKeys = object === 'both' || object === 'key';\n\n const _prev = prev ? prev + DELIMITER : '';\n const output: [string, any][] = [];\n\n const isArray = Array.isArray(arg);\n if (isArray) {\n if (canAddObjectKeys && !first) output.push([`${prev}`, arg]);\n\n arg.forEach((item, index) => {\n const values = ddecompose(\n item,\n `${_prev}${LEFT_BRACKET}${index}${RIGHT_BRACKET}`,\n options,\n false,\n );\n output.push(...values);\n });\n return output;\n }\n\n const isPrimit = isPrimitive(arg);\n if (isPrimit) {\n const isFirst = !prev.includes(DELIMITER);\n if (canAddKeys || isFirst) output.push([`${prev}`, arg]);\n return output;\n }\n\n if (canAddObjectKeys && prev !== '') output.push([`${prev}`, arg]);\n\n const entries1 = Object.entries(arg);\n entries1.forEach(([key, value]) => {\n const values = ddecompose(value, `${_prev}${key}`, options, false);\n output.push(...values);\n });\n\n return output;\n}\n\ntype Decompose_F = <\n T,\n const O extends DecomposeOptions = typeof DEFAULT_DECOMPOSE_OPTIONS,\n>(\n val: T,\n options?: O,\n) => Decompose<T, O>;\ntype _Decompose_F = (val: any, options?: DecomposeOptions) => any;\n\nexport type Decomposer = Decompose_F & {\n strict: Decompose_F;\n low: _Decompose_F;\n};\n\nconst _decompose: _Decompose_F = (val, options) => {\n const entries1 = ddecompose(val, '', options);\n\n const { sep, start } = {\n ...DEFAULT_DECOMPOSE_OPTIONS,\n ...options,\n };\n if (entries1.length == 0) {\n if (Array.isArray(val)) return [];\n return {};\n }\n\n const regexDel = new RegExp(DELIMITER, 'g');\n const regexLeft = new RegExp(LEFT_BRACKET, 'g');\n const regexRight = new RegExp(RIGHT_BRACKET, 'g');\n const entries2 = entries1.map(([__key, value]) => {\n const _key = __key\n .replace(regexDel, sep)\n .replace(regexLeft, `[`)\n .replace(regexRight, `]`);\n const key = start ? `${sep}${_key}` : _key;\n return [key, value];\n });\n\n const output = Object.fromEntries(entries2);\n return output;\n};\n\n/* v8 ignore next 1 */\nexport const decompose: Decomposer = (val, options) =>\n _decompose(val, options);\ndecompose.low = decompose;\ndecompose.strict = decompose;\n"],"mappings":";;;;AASA,SAAS,WACP,KACA,OAAO,IACP,UAA4B,2BAC5B,QAAQ,MACR;CACA,MAAM,EAAE,WAAW;EACjB,GAAG;EACH,GAAG;EACJ;CACD,MAAM,mBAAmB,WAAW,UAAU,WAAW;CACzD,MAAM,aAAa,WAAW,UAAU,WAAW;CAEnD,MAAM,QAAQ,OAAO,OAAO,YAAY;CACxC,MAAM,SAA0B,EAAE;AAGlC,KADgB,MAAM,QAAQ,IAAI,EACrB;AACX,MAAI,oBAAoB,CAAC,MAAO,QAAO,KAAK,CAAC,GAAG,QAAQ,IAAI,CAAC;AAE7D,MAAI,SAAS,MAAM,UAAU;GAC3B,MAAM,SAAS,WACb,MACA,GAAG,QAAQ,eAAe,QAAQ,iBAClC,SACA,MACD;AACD,UAAO,KAAK,GAAG,OAAO;IACtB;AACF,SAAO;;AAIT,KADiB,YAAY,IAAI,EACnB;EACZ,MAAM,UAAU,CAAC,KAAK,SAAS,UAAU;AACzC,MAAI,cAAc,QAAS,QAAO,KAAK,CAAC,GAAG,QAAQ,IAAI,CAAC;AACxD,SAAO;;AAGT,KAAI,oBAAoB,SAAS,GAAI,QAAO,KAAK,CAAC,GAAG,QAAQ,IAAI,CAAC;AAEjD,QAAO,QAAQ,IAAI,CAC3B,SAAS,CAAC,KAAK,WAAW;EACjC,MAAM,SAAS,WAAW,OAAO,GAAG,QAAQ,OAAO,SAAS,MAAM;AAClE,SAAO,KAAK,GAAG,OAAO;GACtB;AAEF,QAAO;;AAiBT,MAAM,cAA4B,KAAK,YAAY;CACjD,MAAM,WAAW,WAAW,KAAK,IAAI,QAAQ;CAE7C,MAAM,EAAE,KAAK,UAAU;EACrB,GAAG;EACH,GAAG;EACJ;AACD,KAAI,SAAS,UAAU,GAAG;AACxB,MAAI,MAAM,QAAQ,IAAI,CAAE,QAAO,EAAE;AACjC,SAAO,EAAE;;CAGX,MAAM,WAAW,IAAI,OAAO,WAAW,IAAI;CAC3C,MAAM,YAAY,IAAI,OAAO,cAAc,IAAI;CAC/C,MAAM,aAAa,IAAI,OAAO,eAAe,IAAI;CACjD,MAAM,WAAW,SAAS,KAAK,CAAC,OAAO,WAAW;EAChD,MAAM,OAAO,MACV,QAAQ,UAAU,IAAI,CACtB,QAAQ,WAAW,IAAI,CACvB,QAAQ,YAAY,IAAI;AAE3B,SAAO,CADK,QAAQ,GAAG,MAAM,SAAS,MACzB,MAAM;GACnB;AAGF,QADe,OAAO,YAAY,SAAS;;;AAK7C,MAAa,aAAyB,KAAK,YACzC,WAAW,KAAK,QAAQ;AAC1B,UAAU,MAAM;AAChB,UAAU,SAAS"}
|
package/lib/decomposeKeys.cjs
CHANGED
|
@@ -1,39 +1,33 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
output.push(...values);
|
|
19
|
-
}
|
|
20
|
-
else
|
|
21
|
-
output.push(`${_prev}${key}`);
|
|
22
|
-
});
|
|
23
|
-
return output;
|
|
1
|
+
Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
|
|
2
|
+
const require_sortMap = require("./sortMap.cjs");
|
|
3
|
+
const require_constants_strings = require("./constants/strings.cjs");
|
|
4
|
+
const require_helpers = require("./helpers.cjs");
|
|
5
|
+
let _bemedev_types = require("@bemedev/types");
|
|
6
|
+
//#region src/decomposeKeys.ts
|
|
7
|
+
function ddecomposeKeys(val, prev = "", addObjectKeys = true) {
|
|
8
|
+
const _prev = prev ? prev + require_constants_strings.DELIMITER : "";
|
|
9
|
+
const output = [];
|
|
10
|
+
Object.entries(val).forEach(([key, value]) => {
|
|
11
|
+
if (!require_helpers.isPrimitive(value)) {
|
|
12
|
+
if (addObjectKeys) output.push(`${_prev}${key}`);
|
|
13
|
+
const values = ddecomposeKeys(value, `${_prev}${key}`, addObjectKeys);
|
|
14
|
+
output.push(...values);
|
|
15
|
+
} else output.push(`${_prev}${key}`);
|
|
16
|
+
});
|
|
17
|
+
return output;
|
|
24
18
|
}
|
|
25
|
-
const _decomposeKeys = (val, sorter =
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
19
|
+
const _decomposeKeys = (val, sorter = require_sortMap.sortMap, addObjectKeys = true) => {
|
|
20
|
+
const output1 = ddecomposeKeys(val, "", addObjectKeys);
|
|
21
|
+
output1.sort(sorter);
|
|
22
|
+
const regex = new RegExp(require_constants_strings.DELIMITER, "g");
|
|
23
|
+
return output1.map((value) => value.replace(regex, "."));
|
|
30
24
|
};
|
|
31
25
|
const decomposeKeys = (val, sorter, addObjectKeys) => {
|
|
32
|
-
|
|
26
|
+
return _bemedev_types.castings.commons.any(_decomposeKeys(val, sorter, addObjectKeys));
|
|
33
27
|
};
|
|
34
28
|
decomposeKeys.low = _decomposeKeys;
|
|
35
|
-
decomposeKeys.strict =
|
|
36
|
-
|
|
37
|
-
|
|
29
|
+
decomposeKeys.strict = _bemedev_types.castings.commons.unknown(_decomposeKeys);
|
|
30
|
+
//#endregion
|
|
38
31
|
exports.decomposeKeys = decomposeKeys;
|
|
39
|
-
|
|
32
|
+
|
|
33
|
+
//# sourceMappingURL=decomposeKeys.cjs.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"decomposeKeys.cjs","sources":["../src/decomposeKeys.ts"],"sourcesContent":["import { castings } from '@bemedev/types';\nimport { DELIMITER } from './constants/strings';\nimport { isPrimitive } from './helpers';\nimport { sortMap } from './sortMap';\nimport type { KeysMatching, Ru } from './types.types';\n\nfunction ddecomposeKeys(val: any, prev = '', addObjectKeys = true) {\n const _prev = prev ? prev + DELIMITER : '';\n const output: string[] = [];\n const entries1 = Object.entries(val);\n entries1.forEach(([key, value]) => {\n const isPrimit = isPrimitive(value);\n if (!isPrimit) {\n if (addObjectKeys) output.push(`${_prev}${key}`);\n const values = ddecomposeKeys(\n value,\n `${_prev}${key}`,\n addObjectKeys,\n );\n output.push(...values);\n } else output.push(`${_prev}${key}`);\n });\n return output;\n}\n\ntype DecomposeKeys_F = <\n T extends Ru,\n AddObjectKeys extends boolean = true,\n>(\n val: T,\n sorter?: typeof sortMap,\n addObjectKeys?: AddObjectKeys,\n) => KeysMatching<T, AddObjectKeys>[];\n\ntype _DecomposeKeys_F = (\n val: any,\n sorter?: typeof sortMap,\n addObjectKeys?: boolean,\n) => string[];\n\nexport type DecomposeKeys = DecomposeKeys_F & {\n strict: DecomposeKeys_F;\n low: _DecomposeKeys_F;\n};\n\nconst _decomposeKeys: _DecomposeKeys_F = (\n val,\n sorter = sortMap,\n addObjectKeys = true,\n) => {\n const output1 = ddecomposeKeys(val, '', addObjectKeys);\n output1.sort(sorter);\n const regex = new RegExp(DELIMITER, 'g');\n return output1.map(value => value.replace(regex, '.'));\n};\n\nexport const decomposeKeys: DecomposeKeys = (\n val,\n sorter,\n addObjectKeys,\n) => {\n return castings.commons.any(_decomposeKeys(val, sorter, addObjectKeys));\n};\ndecomposeKeys.low = _decomposeKeys;\ndecomposeKeys.strict =\n castings.commons.unknown<DecomposeKeys_F>(_decomposeKeys);\n"],"
|
|
1
|
+
{"version":3,"file":"decomposeKeys.cjs","names":["DELIMITER","isPrimitive","sortMap","castings"],"sources":["../src/decomposeKeys.ts"],"sourcesContent":["import { castings } from '@bemedev/types';\nimport { DELIMITER } from './constants/strings';\nimport { isPrimitive } from './helpers';\nimport { sortMap } from './sortMap';\nimport type { KeysMatching, Ru } from './types.types';\n\nfunction ddecomposeKeys(val: any, prev = '', addObjectKeys = true) {\n const _prev = prev ? prev + DELIMITER : '';\n const output: string[] = [];\n const entries1 = Object.entries(val);\n entries1.forEach(([key, value]) => {\n const isPrimit = isPrimitive(value);\n if (!isPrimit) {\n if (addObjectKeys) output.push(`${_prev}${key}`);\n const values = ddecomposeKeys(\n value,\n `${_prev}${key}`,\n addObjectKeys,\n );\n output.push(...values);\n } else output.push(`${_prev}${key}`);\n });\n return output;\n}\n\ntype DecomposeKeys_F = <\n T extends Ru,\n AddObjectKeys extends boolean = true,\n>(\n val: T,\n sorter?: typeof sortMap,\n addObjectKeys?: AddObjectKeys,\n) => KeysMatching<T, AddObjectKeys>[];\n\ntype _DecomposeKeys_F = (\n val: any,\n sorter?: typeof sortMap,\n addObjectKeys?: boolean,\n) => string[];\n\nexport type DecomposeKeys = DecomposeKeys_F & {\n strict: DecomposeKeys_F;\n low: _DecomposeKeys_F;\n};\n\nconst _decomposeKeys: _DecomposeKeys_F = (\n val,\n sorter = sortMap,\n addObjectKeys = true,\n) => {\n const output1 = ddecomposeKeys(val, '', addObjectKeys);\n output1.sort(sorter);\n const regex = new RegExp(DELIMITER, 'g');\n return output1.map(value => value.replace(regex, '.'));\n};\n\nexport const decomposeKeys: DecomposeKeys = (\n val,\n sorter,\n addObjectKeys,\n) => {\n return castings.commons.any(_decomposeKeys(val, sorter, addObjectKeys));\n};\ndecomposeKeys.low = _decomposeKeys;\ndecomposeKeys.strict =\n castings.commons.unknown<DecomposeKeys_F>(_decomposeKeys);\n"],"mappings":";;;;;;AAMA,SAAS,eAAe,KAAU,OAAO,IAAI,gBAAgB,MAAM;CACjE,MAAM,QAAQ,OAAO,OAAOA,0BAAAA,YAAY;CACxC,MAAM,SAAmB,EAAE;AACV,QAAO,QAAQ,IAAI,CAC3B,SAAS,CAAC,KAAK,WAAW;AAEjC,MAAI,CADaC,gBAAAA,YAAY,MAAM,EACpB;AACb,OAAI,cAAe,QAAO,KAAK,GAAG,QAAQ,MAAM;GAChD,MAAM,SAAS,eACb,OACA,GAAG,QAAQ,OACX,cACD;AACD,UAAO,KAAK,GAAG,OAAO;QACjB,QAAO,KAAK,GAAG,QAAQ,MAAM;GACpC;AACF,QAAO;;AAuBT,MAAM,kBACJ,KACA,SAASC,gBAAAA,SACT,gBAAgB,SACb;CACH,MAAM,UAAU,eAAe,KAAK,IAAI,cAAc;AACtD,SAAQ,KAAK,OAAO;CACpB,MAAM,QAAQ,IAAI,OAAOF,0BAAAA,WAAW,IAAI;AACxC,QAAO,QAAQ,KAAI,UAAS,MAAM,QAAQ,OAAO,IAAI,CAAC;;AAGxD,MAAa,iBACX,KACA,QACA,kBACG;AACH,QAAOG,eAAAA,SAAS,QAAQ,IAAI,eAAe,KAAK,QAAQ,cAAc,CAAC;;AAEzE,cAAc,MAAM;AACpB,cAAc,SACZA,eAAAA,SAAS,QAAQ,QAAyB,eAAe"}
|
package/lib/decomposeKeys.js
CHANGED
|
@@ -1,37 +1,32 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import { DELIMITER } from
|
|
3
|
-
import { isPrimitive } from
|
|
4
|
-
import {
|
|
5
|
-
|
|
6
|
-
function ddecomposeKeys(val, prev =
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
}
|
|
18
|
-
else
|
|
19
|
-
output.push(`${_prev}${key}`);
|
|
20
|
-
});
|
|
21
|
-
return output;
|
|
1
|
+
import { sortMap } from "./sortMap.js";
|
|
2
|
+
import { DELIMITER } from "./constants/strings.js";
|
|
3
|
+
import { isPrimitive } from "./helpers.js";
|
|
4
|
+
import { castings } from "@bemedev/types";
|
|
5
|
+
//#region src/decomposeKeys.ts
|
|
6
|
+
function ddecomposeKeys(val, prev = "", addObjectKeys = true) {
|
|
7
|
+
const _prev = prev ? prev + DELIMITER : "";
|
|
8
|
+
const output = [];
|
|
9
|
+
Object.entries(val).forEach(([key, value]) => {
|
|
10
|
+
if (!isPrimitive(value)) {
|
|
11
|
+
if (addObjectKeys) output.push(`${_prev}${key}`);
|
|
12
|
+
const values = ddecomposeKeys(value, `${_prev}${key}`, addObjectKeys);
|
|
13
|
+
output.push(...values);
|
|
14
|
+
} else output.push(`${_prev}${key}`);
|
|
15
|
+
});
|
|
16
|
+
return output;
|
|
22
17
|
}
|
|
23
18
|
const _decomposeKeys = (val, sorter = sortMap, addObjectKeys = true) => {
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
19
|
+
const output1 = ddecomposeKeys(val, "", addObjectKeys);
|
|
20
|
+
output1.sort(sorter);
|
|
21
|
+
const regex = new RegExp(DELIMITER, "g");
|
|
22
|
+
return output1.map((value) => value.replace(regex, "."));
|
|
28
23
|
};
|
|
29
24
|
const decomposeKeys = (val, sorter, addObjectKeys) => {
|
|
30
|
-
|
|
25
|
+
return castings.commons.any(_decomposeKeys(val, sorter, addObjectKeys));
|
|
31
26
|
};
|
|
32
27
|
decomposeKeys.low = _decomposeKeys;
|
|
33
|
-
decomposeKeys.strict =
|
|
34
|
-
|
|
35
|
-
|
|
28
|
+
decomposeKeys.strict = castings.commons.unknown(_decomposeKeys);
|
|
29
|
+
//#endregion
|
|
36
30
|
export { decomposeKeys };
|
|
37
|
-
|
|
31
|
+
|
|
32
|
+
//# sourceMappingURL=decomposeKeys.js.map
|
package/lib/decomposeKeys.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"decomposeKeys.js","sources":["../src/decomposeKeys.ts"],"sourcesContent":["import { castings } from '@bemedev/types';\nimport { DELIMITER } from './constants/strings';\nimport { isPrimitive } from './helpers';\nimport { sortMap } from './sortMap';\nimport type { KeysMatching, Ru } from './types.types';\n\nfunction ddecomposeKeys(val: any, prev = '', addObjectKeys = true) {\n const _prev = prev ? prev + DELIMITER : '';\n const output: string[] = [];\n const entries1 = Object.entries(val);\n entries1.forEach(([key, value]) => {\n const isPrimit = isPrimitive(value);\n if (!isPrimit) {\n if (addObjectKeys) output.push(`${_prev}${key}`);\n const values = ddecomposeKeys(\n value,\n `${_prev}${key}`,\n addObjectKeys,\n );\n output.push(...values);\n } else output.push(`${_prev}${key}`);\n });\n return output;\n}\n\ntype DecomposeKeys_F = <\n T extends Ru,\n AddObjectKeys extends boolean = true,\n>(\n val: T,\n sorter?: typeof sortMap,\n addObjectKeys?: AddObjectKeys,\n) => KeysMatching<T, AddObjectKeys>[];\n\ntype _DecomposeKeys_F = (\n val: any,\n sorter?: typeof sortMap,\n addObjectKeys?: boolean,\n) => string[];\n\nexport type DecomposeKeys = DecomposeKeys_F & {\n strict: DecomposeKeys_F;\n low: _DecomposeKeys_F;\n};\n\nconst _decomposeKeys: _DecomposeKeys_F = (\n val,\n sorter = sortMap,\n addObjectKeys = true,\n) => {\n const output1 = ddecomposeKeys(val, '', addObjectKeys);\n output1.sort(sorter);\n const regex = new RegExp(DELIMITER, 'g');\n return output1.map(value => value.replace(regex, '.'));\n};\n\nexport const decomposeKeys: DecomposeKeys = (\n val,\n sorter,\n addObjectKeys,\n) => {\n return castings.commons.any(_decomposeKeys(val, sorter, addObjectKeys));\n};\ndecomposeKeys.low = _decomposeKeys;\ndecomposeKeys.strict =\n castings.commons.unknown<DecomposeKeys_F>(_decomposeKeys);\n"],"
|
|
1
|
+
{"version":3,"file":"decomposeKeys.js","names":[],"sources":["../src/decomposeKeys.ts"],"sourcesContent":["import { castings } from '@bemedev/types';\nimport { DELIMITER } from './constants/strings';\nimport { isPrimitive } from './helpers';\nimport { sortMap } from './sortMap';\nimport type { KeysMatching, Ru } from './types.types';\n\nfunction ddecomposeKeys(val: any, prev = '', addObjectKeys = true) {\n const _prev = prev ? prev + DELIMITER : '';\n const output: string[] = [];\n const entries1 = Object.entries(val);\n entries1.forEach(([key, value]) => {\n const isPrimit = isPrimitive(value);\n if (!isPrimit) {\n if (addObjectKeys) output.push(`${_prev}${key}`);\n const values = ddecomposeKeys(\n value,\n `${_prev}${key}`,\n addObjectKeys,\n );\n output.push(...values);\n } else output.push(`${_prev}${key}`);\n });\n return output;\n}\n\ntype DecomposeKeys_F = <\n T extends Ru,\n AddObjectKeys extends boolean = true,\n>(\n val: T,\n sorter?: typeof sortMap,\n addObjectKeys?: AddObjectKeys,\n) => KeysMatching<T, AddObjectKeys>[];\n\ntype _DecomposeKeys_F = (\n val: any,\n sorter?: typeof sortMap,\n addObjectKeys?: boolean,\n) => string[];\n\nexport type DecomposeKeys = DecomposeKeys_F & {\n strict: DecomposeKeys_F;\n low: _DecomposeKeys_F;\n};\n\nconst _decomposeKeys: _DecomposeKeys_F = (\n val,\n sorter = sortMap,\n addObjectKeys = true,\n) => {\n const output1 = ddecomposeKeys(val, '', addObjectKeys);\n output1.sort(sorter);\n const regex = new RegExp(DELIMITER, 'g');\n return output1.map(value => value.replace(regex, '.'));\n};\n\nexport const decomposeKeys: DecomposeKeys = (\n val,\n sorter,\n addObjectKeys,\n) => {\n return castings.commons.any(_decomposeKeys(val, sorter, addObjectKeys));\n};\ndecomposeKeys.low = _decomposeKeys;\ndecomposeKeys.strict =\n castings.commons.unknown<DecomposeKeys_F>(_decomposeKeys);\n"],"mappings":";;;;;AAMA,SAAS,eAAe,KAAU,OAAO,IAAI,gBAAgB,MAAM;CACjE,MAAM,QAAQ,OAAO,OAAO,YAAY;CACxC,MAAM,SAAmB,EAAE;AACV,QAAO,QAAQ,IAAI,CAC3B,SAAS,CAAC,KAAK,WAAW;AAEjC,MAAI,CADa,YAAY,MAAM,EACpB;AACb,OAAI,cAAe,QAAO,KAAK,GAAG,QAAQ,MAAM;GAChD,MAAM,SAAS,eACb,OACA,GAAG,QAAQ,OACX,cACD;AACD,UAAO,KAAK,GAAG,OAAO;QACjB,QAAO,KAAK,GAAG,QAAQ,MAAM;GACpC;AACF,QAAO;;AAuBT,MAAM,kBACJ,KACA,SAAS,SACT,gBAAgB,SACb;CACH,MAAM,UAAU,eAAe,KAAK,IAAI,cAAc;AACtD,SAAQ,KAAK,OAAO;CACpB,MAAM,QAAQ,IAAI,OAAO,WAAW,IAAI;AACxC,QAAO,QAAQ,KAAI,UAAS,MAAM,QAAQ,OAAO,IAAI,CAAC;;AAGxD,MAAa,iBACX,KACA,QACA,kBACG;AACH,QAAO,SAAS,QAAQ,IAAI,eAAe,KAAK,QAAQ,cAAc,CAAC;;AAEzE,cAAc,MAAM;AACpB,cAAc,SACZ,SAAS,QAAQ,QAAyB,eAAe"}
|
package/lib/decomposeSV.cjs
CHANGED
|
@@ -1,35 +1,32 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
const keys = Object.keys(val);
|
|
17
|
-
output.push(...keys.map(key => ddecompose(val[key], `${_prev}${key}`)).flat());
|
|
18
|
-
}
|
|
19
|
-
return output;
|
|
1
|
+
Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
|
|
2
|
+
const require_sortMap = require("./sortMap.cjs");
|
|
3
|
+
const require_constants_strings = require("./constants/strings.cjs");
|
|
4
|
+
let _bemedev_types = require("@bemedev/types");
|
|
5
|
+
//#region src/decomposeSV.ts
|
|
6
|
+
function ddecompose(val, prev = "") {
|
|
7
|
+
const output = [];
|
|
8
|
+
const _prev = prev ? prev + require_constants_strings.DELIMITER : "";
|
|
9
|
+
if (prev !== "") output.push(prev);
|
|
10
|
+
if (typeof val === "string") output.push(`${_prev}${val}`);
|
|
11
|
+
else {
|
|
12
|
+
const keys = Object.keys(val);
|
|
13
|
+
output.push(...keys.map((key) => ddecompose(val[key], `${_prev}${key}`)).flat());
|
|
14
|
+
}
|
|
15
|
+
return output;
|
|
20
16
|
}
|
|
21
|
-
const _decomposeSV = (val, sorter =
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
17
|
+
const _decomposeSV = (val, sorter = require_sortMap.sortMap) => {
|
|
18
|
+
const output1 = ddecompose(val, "");
|
|
19
|
+
output1.sort(sorter);
|
|
20
|
+
const regex = new RegExp(require_constants_strings.DELIMITER, "g");
|
|
21
|
+
return output1.map((value) => value.replace(regex, "."));
|
|
26
22
|
};
|
|
27
23
|
/* v8 ignore next 3 */
|
|
28
24
|
const decomposeSV = (val, sorter) => {
|
|
29
|
-
|
|
25
|
+
return _bemedev_types.castings.commons.any(_decomposeSV(val, sorter));
|
|
30
26
|
};
|
|
31
27
|
decomposeSV.low = _decomposeSV;
|
|
32
|
-
decomposeSV.strict =
|
|
33
|
-
|
|
28
|
+
decomposeSV.strict = _bemedev_types.castings.commons.unknown(_decomposeSV);
|
|
29
|
+
//#endregion
|
|
34
30
|
exports.decomposeSV = decomposeSV;
|
|
35
|
-
|
|
31
|
+
|
|
32
|
+
//# sourceMappingURL=decomposeSV.cjs.map
|
package/lib/decomposeSV.cjs.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"decomposeSV.cjs","sources":["../src/decomposeSV.ts"],"sourcesContent":["import { castings } from '@bemedev/types';\nimport { DELIMITER } from './constants/strings';\nimport { sortMap } from './sortMap';\nimport type { StateMatching, StateValue } from './types.types';\n\nfunction ddecompose(val: StateValue, prev = '') {\n const output: string[] = [];\n\n const _prev = prev ? prev + DELIMITER : '';\n if (prev !== '') output.push(prev);\n\n if (typeof val === 'string') {\n output.push(`${_prev}${val}`);\n } else {\n const keys = Object.keys(val);\n output.push(\n ...keys.map(key => ddecompose(val[key], `${_prev}${key}`)).flat(),\n );\n }\n\n return output;\n}\n\ntype DecomposeSV_F = <T extends StateValue>(\n val: T,\n sorter?: typeof sortMap,\n) => StateMatching<T>[];\n\ntype _DecomposeSV_F = (val: any, sorter?: typeof sortMap) => string[];\n\nexport type DecomposeSV = DecomposeSV_F & {\n strict: DecomposeSV_F;\n low: _DecomposeSV_F;\n};\n\nconst _decomposeSV: _DecomposeSV_F = (val, sorter = sortMap) => {\n const output1 = ddecompose(val, '');\n output1.sort(sorter);\n const regex = new RegExp(DELIMITER, 'g');\n return output1.map(value => value.replace(regex, '.'));\n};\n\n/* v8 ignore next 3 */\nexport const decomposeSV: DecomposeSV = (val, sorter) => {\n return castings.commons.any(_decomposeSV(val, sorter));\n};\ndecomposeSV.low = _decomposeSV;\ndecomposeSV.strict = castings.commons.unknown<DecomposeSV_F>(_decomposeSV);\n"],"
|
|
1
|
+
{"version":3,"file":"decomposeSV.cjs","names":["DELIMITER","sortMap","castings"],"sources":["../src/decomposeSV.ts"],"sourcesContent":["import { castings } from '@bemedev/types';\nimport { DELIMITER } from './constants/strings';\nimport { sortMap } from './sortMap';\nimport type { StateMatching, StateValue } from './types.types';\n\nfunction ddecompose(val: StateValue, prev = '') {\n const output: string[] = [];\n\n const _prev = prev ? prev + DELIMITER : '';\n if (prev !== '') output.push(prev);\n\n if (typeof val === 'string') {\n output.push(`${_prev}${val}`);\n } else {\n const keys = Object.keys(val);\n output.push(\n ...keys.map(key => ddecompose(val[key], `${_prev}${key}`)).flat(),\n );\n }\n\n return output;\n}\n\ntype DecomposeSV_F = <T extends StateValue>(\n val: T,\n sorter?: typeof sortMap,\n) => StateMatching<T>[];\n\ntype _DecomposeSV_F = (val: any, sorter?: typeof sortMap) => string[];\n\nexport type DecomposeSV = DecomposeSV_F & {\n strict: DecomposeSV_F;\n low: _DecomposeSV_F;\n};\n\nconst _decomposeSV: _DecomposeSV_F = (val, sorter = sortMap) => {\n const output1 = ddecompose(val, '');\n output1.sort(sorter);\n const regex = new RegExp(DELIMITER, 'g');\n return output1.map(value => value.replace(regex, '.'));\n};\n\n/* v8 ignore next 3 */\nexport const decomposeSV: DecomposeSV = (val, sorter) => {\n return castings.commons.any(_decomposeSV(val, sorter));\n};\ndecomposeSV.low = _decomposeSV;\ndecomposeSV.strict = castings.commons.unknown<DecomposeSV_F>(_decomposeSV);\n"],"mappings":";;;;;AAKA,SAAS,WAAW,KAAiB,OAAO,IAAI;CAC9C,MAAM,SAAmB,EAAE;CAE3B,MAAM,QAAQ,OAAO,OAAOA,0BAAAA,YAAY;AACxC,KAAI,SAAS,GAAI,QAAO,KAAK,KAAK;AAElC,KAAI,OAAO,QAAQ,SACjB,QAAO,KAAK,GAAG,QAAQ,MAAM;MACxB;EACL,MAAM,OAAO,OAAO,KAAK,IAAI;AAC7B,SAAO,KACL,GAAG,KAAK,KAAI,QAAO,WAAW,IAAI,MAAM,GAAG,QAAQ,MAAM,CAAC,CAAC,MAAM,CAClE;;AAGH,QAAO;;AAeT,MAAM,gBAAgC,KAAK,SAASC,gBAAAA,YAAY;CAC9D,MAAM,UAAU,WAAW,KAAK,GAAG;AACnC,SAAQ,KAAK,OAAO;CACpB,MAAM,QAAQ,IAAI,OAAOD,0BAAAA,WAAW,IAAI;AACxC,QAAO,QAAQ,KAAI,UAAS,MAAM,QAAQ,OAAO,IAAI,CAAC;;;AAIxD,MAAa,eAA4B,KAAK,WAAW;AACvD,QAAOE,eAAAA,SAAS,QAAQ,IAAI,aAAa,KAAK,OAAO,CAAC;;AAExD,YAAY,MAAM;AAClB,YAAY,SAASA,eAAAA,SAAS,QAAQ,QAAuB,aAAa"}
|