@bemedev/decompose 1.2.0 → 1.3.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/flatByKey.cjs +27 -0
- package/lib/flatByKey.cjs.map +1 -0
- package/lib/{flat.d.ts → flatByKey.d.ts} +3 -3
- package/lib/flatByKey.d.ts.map +1 -0
- package/lib/flatByKey.js +25 -0
- package/lib/flatByKey.js.map +1 -0
- package/lib/index.cjs +2 -0
- package/lib/index.cjs.map +1 -1
- package/lib/index.d.ts +1 -0
- package/lib/index.d.ts.map +1 -1
- package/lib/index.js +1 -0
- package/lib/index.js.map +1 -1
- package/package.json +5 -4
- package/lib/flat.cjs +0 -40
- package/lib/flat.cjs.map +0 -1
- package/lib/flat.d.ts.map +0 -1
- package/lib/flat.js +0 -38
- package/lib/flat.js.map +0 -1
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
var types_types = require('./types.types.cjs');
|
|
4
|
+
|
|
5
|
+
const _flat = (val, omitKey, options, path = '') => {
|
|
6
|
+
const _options = { ...types_types.DEFAULT_FLAT_OPTIONS, ...options };
|
|
7
|
+
const { [omitKey]: recursives, ...rest } = val;
|
|
8
|
+
const check = _options.children;
|
|
9
|
+
let out = {};
|
|
10
|
+
out[path === '' ? _options.sep : path] = check ? val : rest;
|
|
11
|
+
if (recursives) {
|
|
12
|
+
for (const key in recursives) {
|
|
13
|
+
if (Object.prototype.hasOwnProperty.call(recursives, key)) {
|
|
14
|
+
const element = recursives[key];
|
|
15
|
+
const inner = _flat(element, omitKey, options, `${path}${_options.sep}${key}`);
|
|
16
|
+
out = { ...out, ...inner };
|
|
17
|
+
}
|
|
18
|
+
}
|
|
19
|
+
}
|
|
20
|
+
return out;
|
|
21
|
+
};
|
|
22
|
+
const flatByKey = (val, key, options) => _flat(val, key, options);
|
|
23
|
+
flatByKey.low = _flat;
|
|
24
|
+
flatByKey.strict = _flat;
|
|
25
|
+
|
|
26
|
+
exports.flatByKey = flatByKey;
|
|
27
|
+
//# sourceMappingURL=flatByKey.cjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"flatByKey.cjs","sources":["../src/flatByKey.ts"],"sourcesContent":["import type { types } from '@bemedev/types';\nimport {\n DEFAULT_FLAT_OPTIONS,\n type FlatByKey,\n type FlatOptions,\n} from './types.types';\n\ntype Flat_F = <\n T extends types.Ru,\n omit extends types.PickKeysBy<T, object> & string,\n>(\n val: T,\n omitKey: omit,\n options?: FlatOptions,\n) => FlatByKey<T, omit, FlatOptions>;\n\ntype _Flat_F = (\n val: any,\n omitKey: string,\n options?: FlatOptions,\n path?: string,\n) => any;\n\nexport type Flat = Flat_F & {\n strict: Flat_F;\n low: _Flat_F;\n};\n\nconst _flat: _Flat_F = (val, omitKey, options, path = '') => {\n const _options = { ...DEFAULT_FLAT_OPTIONS, ...options };\n const { [omitKey]: recursives, ...rest } = val;\n\n const check = _options.children;\n\n let out: any = {};\n out[path === '' ? _options.sep : path] = check ? val : rest;\n\n if (recursives) {\n for (const key in recursives) {\n if (Object.prototype.hasOwnProperty.call(recursives, key)) {\n const element = recursives[key];\n const inner = _flat(\n element,\n omitKey,\n options,\n `${path}${_options.sep}${key}`,\n );\n out = { ...out, ...inner };\n }\n }\n }\n\n return out;\n};\n\nexport const flatByKey: Flat = (val, key, options) =>\n _flat(val, key, options);\nflatByKey.low = _flat;\nflatByKey.strict = _flat;\n"],"names":["DEFAULT_FLAT_OPTIONS"],"mappings":";;;;AA4BA,MAAM,KAAK,GAAY,CAAC,GAAG,EAAE,OAAO,EAAE,OAAO,EAAE,IAAI,GAAG,EAAE,KAAI;IAC1D,MAAM,QAAQ,GAAG,EAAE,GAAGA,gCAAoB,EAAE,GAAG,OAAO,EAAE;AACxD,IAAA,MAAM,EAAE,CAAC,OAAO,GAAG,UAAU,EAAE,GAAG,IAAI,EAAE,GAAG,GAAG;AAE9C,IAAA,MAAM,KAAK,GAAG,QAAQ,CAAC,QAAQ;IAE/B,IAAI,GAAG,GAAQ,EAAE;IACjB,GAAG,CAAC,IAAI,KAAK,EAAE,GAAG,QAAQ,CAAC,GAAG,GAAG,IAAI,CAAC,GAAG,KAAK,GAAG,GAAG,GAAG,IAAI;IAE3D,IAAI,UAAU,EAAE;AACd,QAAA,KAAK,MAAM,GAAG,IAAI,UAAU,EAAE;AAC5B,YAAA,IAAI,MAAM,CAAC,SAAS,CAAC,cAAc,CAAC,IAAI,CAAC,UAAU,EAAE,GAAG,CAAC,EAAE;AACzD,gBAAA,MAAM,OAAO,GAAG,UAAU,CAAC,GAAG,CAAC;gBAC/B,MAAM,KAAK,GAAG,KAAK,CACjB,OAAO,EACP,OAAO,EACP,OAAO,EACP,GAAG,IAAI,CAAA,EAAG,QAAQ,CAAC,GAAG,GAAG,GAAG,CAAA,CAAE,CAC/B;gBACD,GAAG,GAAG,EAAE,GAAG,GAAG,EAAE,GAAG,KAAK,EAAE;YAC5B;QACF;IACF;AAEA,IAAA,OAAO,GAAG;AACZ,CAAC;MAEY,SAAS,GAAS,CAAC,GAAG,EAAE,GAAG,EAAE,OAAO,KAC/C,KAAK,CAAC,GAAG,EAAE,GAAG,EAAE,OAAO;AACzB,SAAS,CAAC,GAAG,GAAG,KAAK;AACrB,SAAS,CAAC,MAAM,GAAG,KAAK;;;;"}
|
|
@@ -1,11 +1,11 @@
|
|
|
1
1
|
import type { types } from '@bemedev/types';
|
|
2
2
|
import { type FlatByKey, type FlatOptions } from './types.types';
|
|
3
3
|
type Flat_F = <T extends types.Ru, omit extends types.PickKeysBy<T, object> & string>(val: T, omitKey: omit, options?: FlatOptions) => FlatByKey<T, omit, FlatOptions>;
|
|
4
|
-
type _Flat_F = (val: any, omitKey: string, options?: FlatOptions) => any;
|
|
4
|
+
type _Flat_F = (val: any, omitKey: string, options?: FlatOptions, path?: string) => any;
|
|
5
5
|
export type Flat = Flat_F & {
|
|
6
6
|
strict: Flat_F;
|
|
7
7
|
low: _Flat_F;
|
|
8
8
|
};
|
|
9
|
-
export declare const
|
|
9
|
+
export declare const flatByKey: Flat;
|
|
10
10
|
export {};
|
|
11
|
-
//# sourceMappingURL=
|
|
11
|
+
//# sourceMappingURL=flatByKey.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"flatByKey.d.ts","sourceRoot":"","sources":["../src/flatByKey.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,KAAK,EAAE,MAAM,gBAAgB,CAAC;AAC5C,OAAO,EAEL,KAAK,SAAS,EACd,KAAK,WAAW,EACjB,MAAM,eAAe,CAAC;AAEvB,KAAK,MAAM,GAAG,CACZ,CAAC,SAAS,KAAK,CAAC,EAAE,EAClB,IAAI,SAAS,KAAK,CAAC,UAAU,CAAC,CAAC,EAAE,MAAM,CAAC,GAAG,MAAM,EAEjD,GAAG,EAAE,CAAC,EACN,OAAO,EAAE,IAAI,EACb,OAAO,CAAC,EAAE,WAAW,KAClB,SAAS,CAAC,CAAC,EAAE,IAAI,EAAE,WAAW,CAAC,CAAC;AAErC,KAAK,OAAO,GAAG,CACb,GAAG,EAAE,GAAG,EACR,OAAO,EAAE,MAAM,EACf,OAAO,CAAC,EAAE,WAAW,EACrB,IAAI,CAAC,EAAE,MAAM,KACV,GAAG,CAAC;AAET,MAAM,MAAM,IAAI,GAAG,MAAM,GAAG;IAC1B,MAAM,EAAE,MAAM,CAAC;IACf,GAAG,EAAE,OAAO,CAAC;CACd,CAAC;AA6BF,eAAO,MAAM,SAAS,EAAE,IACE,CAAC"}
|
package/lib/flatByKey.js
ADDED
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
import { DEFAULT_FLAT_OPTIONS } from './types.types.js';
|
|
2
|
+
|
|
3
|
+
const _flat = (val, omitKey, options, path = '') => {
|
|
4
|
+
const _options = { ...DEFAULT_FLAT_OPTIONS, ...options };
|
|
5
|
+
const { [omitKey]: recursives, ...rest } = val;
|
|
6
|
+
const check = _options.children;
|
|
7
|
+
let out = {};
|
|
8
|
+
out[path === '' ? _options.sep : path] = check ? val : rest;
|
|
9
|
+
if (recursives) {
|
|
10
|
+
for (const key in recursives) {
|
|
11
|
+
if (Object.prototype.hasOwnProperty.call(recursives, key)) {
|
|
12
|
+
const element = recursives[key];
|
|
13
|
+
const inner = _flat(element, omitKey, options, `${path}${_options.sep}${key}`);
|
|
14
|
+
out = { ...out, ...inner };
|
|
15
|
+
}
|
|
16
|
+
}
|
|
17
|
+
}
|
|
18
|
+
return out;
|
|
19
|
+
};
|
|
20
|
+
const flatByKey = (val, key, options) => _flat(val, key, options);
|
|
21
|
+
flatByKey.low = _flat;
|
|
22
|
+
flatByKey.strict = _flat;
|
|
23
|
+
|
|
24
|
+
export { flatByKey };
|
|
25
|
+
//# sourceMappingURL=flatByKey.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"flatByKey.js","sources":["../src/flatByKey.ts"],"sourcesContent":["import type { types } from '@bemedev/types';\nimport {\n DEFAULT_FLAT_OPTIONS,\n type FlatByKey,\n type FlatOptions,\n} from './types.types';\n\ntype Flat_F = <\n T extends types.Ru,\n omit extends types.PickKeysBy<T, object> & string,\n>(\n val: T,\n omitKey: omit,\n options?: FlatOptions,\n) => FlatByKey<T, omit, FlatOptions>;\n\ntype _Flat_F = (\n val: any,\n omitKey: string,\n options?: FlatOptions,\n path?: string,\n) => any;\n\nexport type Flat = Flat_F & {\n strict: Flat_F;\n low: _Flat_F;\n};\n\nconst _flat: _Flat_F = (val, omitKey, options, path = '') => {\n const _options = { ...DEFAULT_FLAT_OPTIONS, ...options };\n const { [omitKey]: recursives, ...rest } = val;\n\n const check = _options.children;\n\n let out: any = {};\n out[path === '' ? _options.sep : path] = check ? val : rest;\n\n if (recursives) {\n for (const key in recursives) {\n if (Object.prototype.hasOwnProperty.call(recursives, key)) {\n const element = recursives[key];\n const inner = _flat(\n element,\n omitKey,\n options,\n `${path}${_options.sep}${key}`,\n );\n out = { ...out, ...inner };\n }\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
package/lib/index.cjs
CHANGED
|
@@ -3,6 +3,7 @@
|
|
|
3
3
|
var decompose = require('./decompose.cjs');
|
|
4
4
|
var decomposeKeys = require('./decomposeKeys.cjs');
|
|
5
5
|
var decomposeSV = require('./decomposeSV.cjs');
|
|
6
|
+
var flatByKey = require('./flatByKey.cjs');
|
|
6
7
|
var recompose = require('./recompose.cjs');
|
|
7
8
|
var sortMap = require('./sortMap.cjs');
|
|
8
9
|
var types_types = require('./types.types.cjs');
|
|
@@ -12,6 +13,7 @@ var types_types = require('./types.types.cjs');
|
|
|
12
13
|
exports.decompose = decompose.decompose;
|
|
13
14
|
exports.decomposeKeys = decomposeKeys.decomposeKeys;
|
|
14
15
|
exports.decomposeSV = decomposeSV.decomposeSV;
|
|
16
|
+
exports.flatByKey = flatByKey.flatByKey;
|
|
15
17
|
exports.recompose = recompose.recompose;
|
|
16
18
|
exports.recomposeObjectUrl = recompose.recomposeObjectUrl;
|
|
17
19
|
exports.sortMap = sortMap.sortMap;
|
package/lib/index.cjs.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.cjs","sources":[],"sourcesContent":[],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"index.cjs","sources":[],"sourcesContent":[],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;"}
|
package/lib/index.d.ts
CHANGED
package/lib/index.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,cAAc,aAAa,CAAC;AAC5B,cAAc,iBAAiB,CAAC;AAChC,cAAc,eAAe,CAAC;AAC9B,cAAc,aAAa,CAAC;AAC5B,cAAc,WAAW,CAAC;AAC1B,cAAc,eAAe,CAAC"}
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,cAAc,aAAa,CAAC;AAC5B,cAAc,iBAAiB,CAAC;AAChC,cAAc,eAAe,CAAC;AAC9B,cAAc,aAAa,CAAC;AAC5B,cAAc,aAAa,CAAC;AAC5B,cAAc,WAAW,CAAC;AAC1B,cAAc,eAAe,CAAC"}
|
package/lib/index.js
CHANGED
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
export { decompose } from './decompose.js';
|
|
2
2
|
export { decomposeKeys } from './decomposeKeys.js';
|
|
3
3
|
export { decomposeSV } from './decomposeSV.js';
|
|
4
|
+
export { flatByKey } from './flatByKey.js';
|
|
4
5
|
export { recompose, recomposeObjectUrl } from './recompose.js';
|
|
5
6
|
export { sortMap } from './sortMap.js';
|
|
6
7
|
export { DEFAULT_DECOMPOSE_OPTIONS, DEFAULT_FLAT_OPTIONS } from './types.types.js';
|
package/lib/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sources":[],"sourcesContent":[],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"index.js","sources":[],"sourcesContent":[],"names":[],"mappings":";;;;;;"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@bemedev/decompose",
|
|
3
|
-
"version": "1.
|
|
3
|
+
"version": "1.3.0",
|
|
4
4
|
"description": "Decompose object and so more",
|
|
5
5
|
"author": {
|
|
6
6
|
"email": "bri_lvi@icloud.com",
|
|
@@ -37,8 +37,8 @@
|
|
|
37
37
|
"ci:admin": "pnpm run rm && pnpm run upgrade && pnpm run ci",
|
|
38
38
|
"rollup": "rollup -c",
|
|
39
39
|
"build": "rm -rf lib && pnpm run rollup",
|
|
40
|
-
"pretest": "pnpm run build",
|
|
41
|
-
"posttest": "pnpm run prettier && pnpm run p-q",
|
|
40
|
+
"pretest": "pnpm run build && pnpm build-tests pre",
|
|
41
|
+
"posttest": "pnpm build-tests post && pnpm run prettier && pnpm run p-q",
|
|
42
42
|
"rm": "pnpx rimraf -rf node_modules pnpm-lock.yaml",
|
|
43
43
|
"p-q": "pretty-quick",
|
|
44
44
|
"rinit": "pnpm run rm && pnpm run config",
|
|
@@ -58,7 +58,7 @@
|
|
|
58
58
|
},
|
|
59
59
|
"devDependencies": {
|
|
60
60
|
"@bemedev/fsf": "^0.8.0",
|
|
61
|
-
"@bemedev/rollup-config": "^0.1.
|
|
61
|
+
"@bemedev/rollup-config": "^0.1.2",
|
|
62
62
|
"@bemedev/vitest-alias": "^0.0.3",
|
|
63
63
|
"@bemedev/vitest-exclude": "^0.1.1",
|
|
64
64
|
"@bemedev/vitest-extended": "^1.3.6",
|
|
@@ -84,6 +84,7 @@
|
|
|
84
84
|
"vitest": "^3.2.4"
|
|
85
85
|
},
|
|
86
86
|
"dependencies": {
|
|
87
|
+
"@bemedev/build-tests": "^0.1.1",
|
|
87
88
|
"ts-deepmerge": "^7.0.3"
|
|
88
89
|
},
|
|
89
90
|
"peerDependencies": {
|
package/lib/flat.cjs
DELETED
|
@@ -1,40 +0,0 @@
|
|
|
1
|
-
'use strict';
|
|
2
|
-
|
|
3
|
-
var decompose = require('./decompose.cjs');
|
|
4
|
-
var types_types = require('./types.types.cjs');
|
|
5
|
-
|
|
6
|
-
const _flat = (val, omitKey, options = types_types.DEFAULT_FLAT_OPTIONS) => {
|
|
7
|
-
const { sep, children } = {
|
|
8
|
-
...types_types.DEFAULT_FLAT_OPTIONS,
|
|
9
|
-
...options,
|
|
10
|
-
};
|
|
11
|
-
const first = decompose.decompose(val, {
|
|
12
|
-
object: 'object',
|
|
13
|
-
sep,
|
|
14
|
-
start: true,
|
|
15
|
-
});
|
|
16
|
-
const output = {};
|
|
17
|
-
const entries = Object.entries(first);
|
|
18
|
-
if (entries.length === 0)
|
|
19
|
-
return output;
|
|
20
|
-
entries
|
|
21
|
-
.filter(([k]) => {
|
|
22
|
-
const splits = k.split(`${sep}${omitKey}${sep}`);
|
|
23
|
-
const last = splits[splits.length - 1];
|
|
24
|
-
return !last.includes(omitKey);
|
|
25
|
-
})
|
|
26
|
-
.forEach(([k, v]) => {
|
|
27
|
-
const _value = structuredClone(v);
|
|
28
|
-
if (!children)
|
|
29
|
-
delete _value[omitKey];
|
|
30
|
-
const key = k.replace(new RegExp(`${omitKey}${sep}`, 'g'), '');
|
|
31
|
-
output[key] = _value;
|
|
32
|
-
});
|
|
33
|
-
return output;
|
|
34
|
-
};
|
|
35
|
-
const flat = (val, key, options) => _flat(val, key, options);
|
|
36
|
-
flat.low = _flat;
|
|
37
|
-
flat.strict = _flat;
|
|
38
|
-
|
|
39
|
-
exports.flat = flat;
|
|
40
|
-
//# sourceMappingURL=flat.cjs.map
|
package/lib/flat.cjs.map
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"flat.cjs","sources":["../src/flat.ts"],"sourcesContent":["import type { types } from '@bemedev/types';\nimport { decompose } from './decompose';\nimport {\n DEFAULT_FLAT_OPTIONS,\n type FlatByKey,\n type FlatOptions,\n} from './types.types';\n\ntype Flat_F = <\n T extends types.Ru,\n omit extends types.PickKeysBy<T, object> & string,\n>(\n val: T,\n omitKey: omit,\n options?: FlatOptions,\n) => FlatByKey<T, omit, FlatOptions>;\n\ntype _Flat_F = (val: any, omitKey: string, options?: FlatOptions) => any;\n\nexport type Flat = Flat_F & {\n strict: Flat_F;\n low: _Flat_F;\n};\n\nconst _flat: _Flat_F = (val, omitKey, options = DEFAULT_FLAT_OPTIONS) => {\n const { sep, children } = {\n ...DEFAULT_FLAT_OPTIONS,\n ...options,\n };\n\n const first = decompose(val, {\n object: 'object',\n sep,\n start: true,\n });\n\n const output: any = {};\n\n const entries: [string, any][] = Object.entries(first);\n if (entries.length === 0) return output;\n\n entries\n .filter(([k]) => {\n const splits = k.split(`${sep}${omitKey}${sep}`);\n const last = splits[splits.length - 1];\n\n return !last.includes(omitKey);\n })\n .forEach(([k, v]) => {\n const _value = structuredClone(v);\n if (!children) delete _value[omitKey];\n const key = k.replace(new RegExp(`${omitKey}${sep}`, 'g'), '');\n\n output[key] = _value;\n });\n\n return output;\n};\n\n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A,EAAG,GAAG,EAAE,EAAE,GAAG,CAAC,EAAE,EAAE,CAAC;AAE9D,QAAA,MAAM,CAAC,GAAG,CAAC,GAAG,MAAM;AACtB,IAAA,CAAC,CAAC;AAEJ,IAAA,OAAO,MAAM;AACf,CAAC;MAEY,IAAI,GAAS,CAAC,GAAG,EAAE,GAAG,EAAE,OAAO,KAAK,KAAK,CAAC,GAAG,EAAE,GAAG,EAAE,OAAO;AACxE,IAAI,CAAC,GAAG,GAAG,KAAK;AAChB,IAAI,CAAC,MAAM,GAAG,KAAK;;;;"}
|
package/lib/flat.d.ts.map
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"flat.d.ts","sourceRoot":"","sources":["../src/flat.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,KAAK,EAAE,MAAM,gBAAgB,CAAC;AAE5C,OAAO,EAEL,KAAK,SAAS,EACd,KAAK,WAAW,EACjB,MAAM,eAAe,CAAC;AAEvB,KAAK,MAAM,GAAG,CACZ,CAAC,SAAS,KAAK,CAAC,EAAE,EAClB,IAAI,SAAS,KAAK,CAAC,UAAU,CAAC,CAAC,EAAE,MAAM,CAAC,GAAG,MAAM,EAEjD,GAAG,EAAE,CAAC,EACN,OAAO,EAAE,IAAI,EACb,OAAO,CAAC,EAAE,WAAW,KAClB,SAAS,CAAC,CAAC,EAAE,IAAI,EAAE,WAAW,CAAC,CAAC;AAErC,KAAK,OAAO,GAAG,CAAC,GAAG,EAAE,GAAG,EAAE,OAAO,EAAE,MAAM,EAAE,OAAO,CAAC,EAAE,WAAW,KAAK,GAAG,CAAC;AAEzE,MAAM,MAAM,IAAI,GAAG,MAAM,GAAG;IAC1B,MAAM,EAAE,MAAM,CAAC;IACf,GAAG,EAAE,OAAO,CAAC;CACd,CAAC;AAqCF,eAAO,MAAM,IAAI,EAAE,IAAsD,CAAC"}
|
package/lib/flat.js
DELETED
|
@@ -1,38 +0,0 @@
|
|
|
1
|
-
import { decompose } from './decompose.js';
|
|
2
|
-
import { DEFAULT_FLAT_OPTIONS } from './types.types.js';
|
|
3
|
-
|
|
4
|
-
const _flat = (val, omitKey, options = DEFAULT_FLAT_OPTIONS) => {
|
|
5
|
-
const { sep, children } = {
|
|
6
|
-
...DEFAULT_FLAT_OPTIONS,
|
|
7
|
-
...options,
|
|
8
|
-
};
|
|
9
|
-
const first = decompose(val, {
|
|
10
|
-
object: 'object',
|
|
11
|
-
sep,
|
|
12
|
-
start: true,
|
|
13
|
-
});
|
|
14
|
-
const output = {};
|
|
15
|
-
const entries = Object.entries(first);
|
|
16
|
-
if (entries.length === 0)
|
|
17
|
-
return output;
|
|
18
|
-
entries
|
|
19
|
-
.filter(([k]) => {
|
|
20
|
-
const splits = k.split(`${sep}${omitKey}${sep}`);
|
|
21
|
-
const last = splits[splits.length - 1];
|
|
22
|
-
return !last.includes(omitKey);
|
|
23
|
-
})
|
|
24
|
-
.forEach(([k, v]) => {
|
|
25
|
-
const _value = structuredClone(v);
|
|
26
|
-
if (!children)
|
|
27
|
-
delete _value[omitKey];
|
|
28
|
-
const key = k.replace(new RegExp(`${omitKey}${sep}`, 'g'), '');
|
|
29
|
-
output[key] = _value;
|
|
30
|
-
});
|
|
31
|
-
return output;
|
|
32
|
-
};
|
|
33
|
-
const flat = (val, key, options) => _flat(val, key, options);
|
|
34
|
-
flat.low = _flat;
|
|
35
|
-
flat.strict = _flat;
|
|
36
|
-
|
|
37
|
-
export { flat };
|
|
38
|
-
//# sourceMappingURL=flat.js.map
|
package/lib/flat.js.map
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"flat.js","sources":["../src/flat.ts"],"sourcesContent":["import type { types } from '@bemedev/types';\nimport { decompose } from './decompose';\nimport {\n DEFAULT_FLAT_OPTIONS,\n type FlatByKey,\n type FlatOptions,\n} from './types.types';\n\ntype Flat_F = <\n T extends types.Ru,\n omit extends types.PickKeysBy<T, object> & string,\n>(\n val: T,\n omitKey: omit,\n options?: FlatOptions,\n) => FlatByKey<T, omit, FlatOptions>;\n\ntype _Flat_F = (val: any, omitKey: string, options?: FlatOptions) => any;\n\nexport type Flat = Flat_F & {\n strict: Flat_F;\n low: _Flat_F;\n};\n\nconst _flat: _Flat_F = (val, omitKey, options = DEFAULT_FLAT_OPTIONS) => {\n const { sep, children } = {\n ...DEFAULT_FLAT_OPTIONS,\n ...options,\n };\n\n const first = decompose(val, {\n object: 'object',\n sep,\n start: true,\n });\n\n const output: any = {};\n\n const entries: [string, any][] = Object.entries(first);\n if (entries.length === 0) return output;\n\n entries\n .filter(([k]) => {\n const splits = k.split(`${sep}${omitKey}${sep}`);\n const last = splits[splits.length - 1];\n\n return !last.includes(omitKey);\n })\n .forEach(([k, v]) => {\n const _value = structuredClone(v);\n if (!children) delete _value[omitKey];\n const key = k.replace(new RegExp(`${omitKey}${sep}`, 'g'), '');\n\n output[key] = _value;\n });\n\n return output;\n};\n\nexport const flat: Flat = (val, key, options) => _flat(val, key, options);\nflat.low = _flat;\nflat.strict = _flat;\n"],"names":[],"mappings":";;;AAwBA,MAAM,KAAK,GAAY,CAAC,GAAG,EAAE,OAAO,EAAE,OAAO,GAAG,oBAAoB,KAAI;AACtE,IAAA,MAAM,EAAE,GAAG,EAAE,QAAQ,EAAE,GAAG;AACxB,QAAA,GAAG,oBAAoB;AACvB,QAAA,GAAG,OAAO;KACX;AAED,IAAA,MAAM,KAAK,GAAG,SAAS,CAAC,GAAG,EAAE;AAC3B,QAAA,MAAM,EAAE,QAAQ;QAChB,GAAG;AACH,QAAA,KAAK,EAAE,IAAI;AACZ,KAAA,CAAC;IAEF,MAAM,MAAM,GAAQ,EAAE;IAEtB,MAAM,OAAO,GAAoB,MAAM,CAAC,OAAO,CAAC,KAAK,CAAC;AACtD,IAAA,IAAI,OAAO,CAAC,MAAM,KAAK,CAAC;AAAE,QAAA,OAAO,MAAM;IAEvC;AACG,SAAA,MAAM,CAAC,CAAC,CAAC,CAAC,CAAC,KAAI;AACd,QAAA,MAAM,MAAM,G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