@bemedev/decompose 0.3.0 → 0.3.1
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/package.json +6 -2
- package/.eslintignore +0 -7
- package/.eslintrc.yml +0 -19
- package/.github/workflows/ci.yml +0 -54
- package/.github/workflows/publish-NPM.yml +0 -63
- package/.gitpod-config/cleanYaml.sh +0 -2
- package/.gitpod-config/dependencies.sh +0 -1
- package/.gitpod-config/exec-gitpod.sh +0 -2
- package/.gitpod-config/exec-upgrade.sh +0 -2
- package/.gitpod-config/exec.sh +0 -3
- package/.gitpod-config/globalDependencies.sh +0 -1
- package/.gitpod-config/package.js +0 -17
- package/.gitpod-config/upgrade.sh +0 -1
- package/.gitpod-config/vsix/alexkrechik.cucumberautocomplete-2.15.1.vsix +0 -0
- package/.gitpod-config/vsix/commit-message-editor-0.18.1.vsix +0 -0
- package/.gitpod-config/vsix/formulahendry.auto-rename-tag-0.1.7.vsix +0 -0
- package/.gitpod.yml +0 -25
- package/.husky/pre-commit +0 -1
- package/.prettierignore +0 -4
- package/.prettierrc.yml +0 -18
- package/gitpod.temp.yml +0 -25
- package/package/lib/constants/strings.cjs +0 -8
- package/package/lib/constants/strings.cjs.map +0 -1
- package/package/lib/constants/strings.d.ts +0 -3
- package/package/lib/constants/strings.d.ts.map +0 -1
- package/package/lib/constants/strings.js +0 -5
- package/package/lib/constants/strings.js.map +0 -1
- package/package/lib/decompose.cjs +0 -31
- package/package/lib/decompose.cjs.map +0 -1
- package/package/lib/decompose.d.ts +0 -3
- package/package/lib/decompose.d.ts.map +0 -1
- package/package/lib/decompose.js +0 -29
- package/package/lib/decompose.js.map +0 -1
- package/package/lib/decomposeSV.cjs +0 -28
- package/package/lib/decomposeSV.cjs.map +0 -1
- package/package/lib/decomposeSV.d.ts +0 -3
- package/package/lib/decomposeSV.d.ts.map +0 -1
- package/package/lib/decomposeSV.js +0 -26
- package/package/lib/decomposeSV.js.map +0 -1
- package/package/lib/helpers.cjs +0 -12
- package/package/lib/helpers.cjs.map +0 -1
- package/package/lib/helpers.d.ts +0 -4
- package/package/lib/helpers.d.ts.map +0 -1
- package/package/lib/helpers.js +0 -10
- package/package/lib/helpers.js.map +0 -1
- package/package/lib/index.cjs +0 -15
- package/package/lib/index.cjs.map +0 -1
- package/package/lib/index.d.ts +0 -6
- package/package/lib/index.d.ts.map +0 -1
- package/package/lib/index.js +0 -5
- package/package/lib/index.js.map +0 -1
- package/package/lib/recompose.cjs +0 -34
- package/package/lib/recompose.cjs.map +0 -1
- package/package/lib/recompose.d.ts +0 -4
- package/package/lib/recompose.d.ts.map +0 -1
- package/package/lib/recompose.js +0 -31
- package/package/lib/recompose.js.map +0 -1
- package/package/lib/sortMap.cjs +0 -8
- package/package/lib/sortMap.cjs.map +0 -1
- package/package/lib/sortMap.d.ts +0 -2
- package/package/lib/sortMap.d.ts.map +0 -1
- package/package/lib/sortMap.js +0 -6
- package/package/lib/sortMap.js.map +0 -1
- package/package/lib/types.d.ts +0 -22
- package/package/lib/types.d.ts.map +0 -1
- package/rollup.config.mjs +0 -68
- package/src/constants/strings.ts +0 -2
- package/src/decompose.test.ts +0 -37
- package/src/decompose.ts +0 -32
- package/src/decomposeSV.test.ts +0 -72
- package/src/decomposeSV.ts +0 -31
- package/src/helpers.ts +0 -11
- package/src/index.ts +0 -5
- package/src/recompose.test.ts +0 -163
- package/src/recompose.ts +0 -30
- package/src/sortMap.ts +0 -3
- package/src/types.test-d.ts +0 -45
- package/src/types.test.ts +0 -12
- package/src/types.ts +0 -57
- package/tsconfig.json +0 -26
- package/vitest.config.ts +0 -24
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"recompose.d.ts","sourceRoot":"","sources":["../src/recompose.ts"],"names":[],"mappings":"AAGA,OAAO,KAAK,EAAa,EAAE,EAAE,MAAM,SAAS,CAAC;AAE7C,wBAAgB,kBAAkB,CAAC,CAAC,EAAE,KAAK,EAAE,MAAM,EAAE,KAAK,EAAE,CAAC,MAc5D;AAED,wBAAgB,SAAS,CAAC,CAAC,SAAS,EAAE,EAAE,KAAK,EAAE,CAAC,unns6BAQ/C"}
|
package/package/lib/recompose.js
DELETED
|
@@ -1,31 +0,0 @@
|
|
|
1
|
-
import { merge } from 'ts-deepmerge';
|
|
2
|
-
import { SEPARETOR } from './constants/strings.js';
|
|
3
|
-
|
|
4
|
-
/* eslint-disable @typescript-eslint/no-explicit-any */
|
|
5
|
-
function recomposeObjectUrl(shape, value) {
|
|
6
|
-
const obj = {};
|
|
7
|
-
if (shape.length <= 0)
|
|
8
|
-
return obj;
|
|
9
|
-
const keys = shape.split(SEPARETOR);
|
|
10
|
-
if (keys.length === 1) {
|
|
11
|
-
const key = keys.shift();
|
|
12
|
-
obj[key] = value;
|
|
13
|
-
}
|
|
14
|
-
else {
|
|
15
|
-
const key = keys.shift();
|
|
16
|
-
obj[key] = recomposeObjectUrl(keys.join(SEPARETOR), value);
|
|
17
|
-
}
|
|
18
|
-
return obj;
|
|
19
|
-
}
|
|
20
|
-
function recompose(shape) {
|
|
21
|
-
const entries = Object.entries(shape);
|
|
22
|
-
const arr = [];
|
|
23
|
-
entries.forEach(([key, value]) => {
|
|
24
|
-
arr.push(recomposeObjectUrl(key, value));
|
|
25
|
-
});
|
|
26
|
-
const output = merge(...arr);
|
|
27
|
-
return Object.freeze(output);
|
|
28
|
-
}
|
|
29
|
-
|
|
30
|
-
export { recompose, recomposeObjectUrl };
|
|
31
|
-
//# sourceMappingURL=recompose.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"recompose.js","sources":["../src/recompose.ts"],"sourcesContent":["/* eslint-disable @typescript-eslint/no-explicit-any */\nimport { merge } from 'ts-deepmerge';\nimport { SEPARETOR } from './constants/strings';\nimport type { Recompose, Ru } from './types';\n\nexport function recomposeObjectUrl<T>(shape: string, value: T) {\n const obj: Ru = {};\n if (shape.length <= 0) return obj;\n\n const keys = shape.split(SEPARETOR);\n if (keys.length === 1) {\n const key = keys.shift();\n obj[key!] = value;\n } else {\n const key = keys.shift();\n obj[key!] = recomposeObjectUrl(keys.join(SEPARETOR), value);\n }\n\n return obj;\n}\n\nexport function recompose<T extends Ru>(shape: T) {\n const entries = Object.entries(shape);\n const arr: any[] = [];\n entries.forEach(([key, value]) => {\n arr.push(recomposeObjectUrl(key, value));\n });\n const output = merge(...arr);\n return Object.freeze(output) as Recompose<T>;\n}\n"],"names":[],"mappings":";;;AAAA;AAKgB,SAAA,kBAAkB,CAAI,KAAa,EAAE,KAAQ,EAAA;IAC3D,MAAM,GAAG,GAAO,EAAE,CAAC;AACnB,IAAA,IAAI,KAAK,CAAC,MAAM,IAAI,CAAC;AAAE,QAAA,OAAO,GAAG,CAAC;IAElC,MAAM,IAAI,GAAG,KAAK,CAAC,KAAK,CAAC,SAAS,CAAC,CAAC;AACpC,IAAA,IAAI,IAAI,CAAC,MAAM,KAAK,CAAC,EAAE;AACrB,QAAA,MAAM,GAAG,GAAG,IAAI,CAAC,KAAK,EAAE,CAAC;AACzB,QAAA,GAAG,CAAC,GAAI,CAAC,GAAG,KAAK,CAAC;KACnB;SAAM;AACL,QAAA,MAAM,GAAG,GAAG,IAAI,CAAC,KAAK,EAAE,CAAC;AACzB,QAAA,GAAG,CAAC,GAAI,CAAC,GAAG,kBAAkB,CAAC,IAAI,CAAC,IAAI,CAAC,SAAS,CAAC,EAAE,KAAK,CAAC,CAAC;KAC7D;AAED,IAAA,OAAO,GAAG,CAAC;AACb,CAAC;AAEK,SAAU,SAAS,CAAe,KAAQ,EAAA;IAC9C,MAAM,OAAO,GAAG,MAAM,CAAC,OAAO,CAAC,KAAK,CAAC,CAAC;IACtC,MAAM,GAAG,GAAU,EAAE,CAAC;IACtB,OAAO,CAAC,OAAO,CAAC,CAAC,CAAC,GAAG,EAAE,KAAK,CAAC,KAAI;QAC/B,GAAG,CAAC,IAAI,CAAC,kBAAkB,CAAC,GAAG,EAAE,KAAK,CAAC,CAAC,CAAC;AAC3C,KAAC,CAAC,CAAC;AACH,IAAA,MAAM,MAAM,GAAG,KAAK,CAAC,GAAG,GAAG,CAAC,CAAC;AAC7B,IAAA,OAAO,MAAM,CAAC,MAAM,CAAC,MAAM,CAAiB,CAAC;AAC/C;;;;"}
|
package/package/lib/sortMap.cjs
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"sortMap.cjs","sources":["../src/sortMap.ts"],"sourcesContent":["export function sortMap(a: string, b: string) {\n return a.localeCompare(b);\n}\n"],"names":[],"mappings":";;AAAgB,SAAA,OAAO,CAAC,CAAS,EAAE,CAAS,EAAA;AAC1C,IAAA,OAAO,CAAC,CAAC,aAAa,CAAC,CAAC,CAAC,CAAC;AAC5B;;;;"}
|
package/package/lib/sortMap.d.ts
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"sortMap.d.ts","sourceRoot":"","sources":["../src/sortMap.ts"],"names":[],"mappings":"AAAA,wBAAgB,OAAO,CAAC,CAAC,EAAE,MAAM,EAAE,CAAC,EAAE,MAAM,UAE3C"}
|
package/package/lib/sortMap.js
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"sortMap.js","sources":["../src/sortMap.ts"],"sourcesContent":["export function sortMap(a: string, b: string) {\n return a.localeCompare(b);\n}\n"],"names":[],"mappings":"AAAgB,SAAA,OAAO,CAAC,CAAS,EAAE,CAAS,EAAA;AAC1C,IAAA,OAAO,CAAC,CAAC,aAAa,CAAC,CAAC,CAAC,CAAC;AAC5B;;;;"}
|
package/package/lib/types.d.ts
DELETED
|
@@ -1,22 +0,0 @@
|
|
|
1
|
-
export type StateMatching<T extends Record<string, unknown> | string, Key = keyof T> = T extends Record<string, unknown> ? Key extends string ? T[Key] extends Record<string, unknown> ? `${Key}.${StateMatching<T[Key]>}` | (Key & string) : Key & string : never : T;
|
|
2
|
-
export type LengthOf<T> = T extends ReadonlyArray<unknown> ? T['length'] : number;
|
|
3
|
-
export type DecomposeOptions = {
|
|
4
|
-
delimiter?: string;
|
|
5
|
-
sorter?: (a: string, b: string) => number;
|
|
6
|
-
};
|
|
7
|
-
export type StateValue = string | StateValueMap;
|
|
8
|
-
export interface StateValueMap {
|
|
9
|
-
[key: string]: StateValue;
|
|
10
|
-
}
|
|
11
|
-
export type Ru = Record<string, unknown>;
|
|
12
|
-
type _SplitString<T extends Ru> = {
|
|
13
|
-
[key in keyof T]: key extends `${string}.${infer A}` ? A extends `${string}.${string}` ? _SplitString<Record<A, T[key]>> : Record<A, T[key]> : T[key];
|
|
14
|
-
};
|
|
15
|
-
type UnionToIntersection<U> = (U extends unknown ? (k: U) => void : never) extends (k: infer I) => void ? I : never;
|
|
16
|
-
type SplitSeparator<S extends string> = S extends `${infer A}.${string}` ? A : S;
|
|
17
|
-
type SplitKeys<T extends Ru> = {
|
|
18
|
-
[key in keyof T as SplitSeparator<key & string>]: T[key] extends Ru ? UnionToIntersection<SplitKeys<T[key]>> : T[key];
|
|
19
|
-
};
|
|
20
|
-
export type Recompose<T extends Ru> = SplitKeys<_SplitString<T>>;
|
|
21
|
-
export {};
|
|
22
|
-
//# sourceMappingURL=types.d.ts.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../src/types.ts"],"names":[],"mappings":"AAAA,MAAM,MAAM,aAAa,CACvB,CAAC,SAAS,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,GAAG,MAAM,EAC1C,GAAG,GAAG,MAAM,CAAC,IAEb,CAAC,SAAS,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,GAC7B,GAAG,SAAS,MAAM,GAChB,CAAC,CAAC,GAAG,CAAC,SAAS,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,GACpC,GAAG,GAAG,IAAI,aAAa,CAAC,CAAC,CAAC,GAAG,CAAC,CAAC,EAAE,GAAG,CAAC,GAAG,GAAG,MAAM,CAAC,GAClD,GAAG,GAAG,MAAM,GACd,KAAK,GACP,CAAC,CAAC;AAER,MAAM,MAAM,QAAQ,CAAC,CAAC,IACpB,CAAC,SAAS,aAAa,CAAC,OAAO,CAAC,GAAG,CAAC,CAAC,QAAQ,CAAC,GAAG,MAAM,CAAC;AAE1D,MAAM,MAAM,gBAAgB,GAAG;IAC7B,SAAS,CAAC,EAAE,MAAM,CAAC;IACnB,MAAM,CAAC,EAAE,CAAC,CAAC,EAAE,MAAM,EAAE,CAAC,EAAE,MAAM,KAAK,MAAM,CAAC;CAC3C,CAAC;AAEF,MAAM,MAAM,UAAU,GAAG,MAAM,GAAG,aAAa,CAAC;AAEhD,MAAM,WAAW,aAAa;IAC5B,CAAC,GAAG,EAAE,MAAM,GAAG,UAAU,CAAC;CAC3B;AAED,MAAM,MAAM,EAAE,GAAG,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC;AAIzC,KAAK,YAAY,CAAC,CAAC,SAAS,EAAE,IAAI;KAC/B,GAAG,IAAI,MAAM,CAAC,GAAG,GAAG,SAAS,GAAG,MAAM,IAAI,MAAM,CAAC,EAAE,GAChD,CAAC,SAAS,GAAG,MAAM,IAAI,MAAM,EAAE,GAC7B,YAAY,CAAC,MAAM,CAAC,CAAC,EAAE,CAAC,CAAC,GAAG,CAAC,CAAC,CAAC,GAC/B,MAAM,CAAC,CAAC,EAAE,CAAC,CAAC,GAAG,CAAC,CAAC,GACnB,CAAC,CAAC,GAAG,CAAC;CACX,CAAC;AAEF,KAAK,mBAAmB,CAAC,CAAC,IAAI,CAC5B,CAAC,SAAS,OAAO,GAAG,CAAC,CAAC,EAAE,CAAC,KAAK,IAAI,GAAG,KAAK,CAC3C,SAAS,CAAC,CAAC,EAAE,MAAM,CAAC,KAAK,IAAI,GAC1B,CAAC,GACD,KAAK,CAAC;AAEV,KAAK,cAAc,CAAC,CAAC,SAAS,MAAM,IAAI,CAAC,SAAS,GAAG,MAAM,CAAC,IAAI,MAAM,EAAE,GACpE,CAAC,GACD,CAAC,CAAC;AAEN,KAAK,SAAS,CAAC,CAAC,SAAS,EAAE,IAAI;KAC5B,GAAG,IAAI,MAAM,CAAC,IAAI,cAAc,CAAC,GAAG,GAAG,MAAM,CAAC,GAAG,CAAC,CAAC,GAAG,CAAC,SAAS,EAAE,GAC/D,mBAAmB,CAAC,SAAS,CAAC,CAAC,CAAC,GAAG,CAAC,CAAC,CAAC,GACtC,CAAC,CAAC,GAAG,CAAC;CACX,CAAC;AAGF,MAAM,MAAM,SAAS,CAAC,CAAC,SAAS,EAAE,IAAI,SAAS,CAAC,YAAY,CAAC,CAAC,CAAC,CAAC,CAAC"}
|
package/rollup.config.mjs
DELETED
|
@@ -1,68 +0,0 @@
|
|
|
1
|
-
import { globSync } from 'glob';
|
|
2
|
-
import path from 'node:path';
|
|
3
|
-
import { fileURLToPath } from 'node:url';
|
|
4
|
-
import { defineConfig } from 'rollup';
|
|
5
|
-
import tscAlias from 'rollup-plugin-tsc-alias';
|
|
6
|
-
import typescript from 'rollup-plugin-typescript2';
|
|
7
|
-
|
|
8
|
-
const input = Object.fromEntries(
|
|
9
|
-
globSync('./src/**/*.ts', {
|
|
10
|
-
ignore: [
|
|
11
|
-
'**/*.test.ts',
|
|
12
|
-
'**/*.test-d.ts',
|
|
13
|
-
'**/*.fixtures.ts',
|
|
14
|
-
'./src/config/**/*.ts',
|
|
15
|
-
'./src/types.ts',
|
|
16
|
-
],
|
|
17
|
-
}).map(file => [
|
|
18
|
-
// This remove `src/` as well as the file extension from each
|
|
19
|
-
// file, so e.g. src/nested/foo.js becomes nested/foo
|
|
20
|
-
path.relative(
|
|
21
|
-
'src',
|
|
22
|
-
file.slice(0, file.length - path.extname(file).length),
|
|
23
|
-
),
|
|
24
|
-
// This expands the relative paths to absolute paths, so e.g.
|
|
25
|
-
// src/nested/foo becomes /project/src/nested/foo.js
|
|
26
|
-
fileURLToPath(new URL(file, import.meta.url)),
|
|
27
|
-
]),
|
|
28
|
-
);
|
|
29
|
-
|
|
30
|
-
export default defineConfig({
|
|
31
|
-
input,
|
|
32
|
-
|
|
33
|
-
plugins: [
|
|
34
|
-
typescript({
|
|
35
|
-
tsconfigOverride: {
|
|
36
|
-
exclude: [
|
|
37
|
-
'**/*.test.ts',
|
|
38
|
-
'**/*.test-d.ts',
|
|
39
|
-
'src/fixtures',
|
|
40
|
-
'src/config',
|
|
41
|
-
// 'src/types.ts',
|
|
42
|
-
],
|
|
43
|
-
},
|
|
44
|
-
}),
|
|
45
|
-
tscAlias({}),
|
|
46
|
-
],
|
|
47
|
-
external: ['ts-deepmerge'],
|
|
48
|
-
|
|
49
|
-
output: [
|
|
50
|
-
{
|
|
51
|
-
format: 'cjs',
|
|
52
|
-
sourcemap: true,
|
|
53
|
-
dir: `lib`,
|
|
54
|
-
preserveModulesRoot: 'src',
|
|
55
|
-
preserveModules: true,
|
|
56
|
-
|
|
57
|
-
entryFileNames: '[name].cjs',
|
|
58
|
-
},
|
|
59
|
-
{
|
|
60
|
-
format: 'es',
|
|
61
|
-
sourcemap: true,
|
|
62
|
-
dir: `lib`,
|
|
63
|
-
preserveModulesRoot: 'src',
|
|
64
|
-
preserveModules: true,
|
|
65
|
-
entryFileNames: '[name].js',
|
|
66
|
-
},
|
|
67
|
-
],
|
|
68
|
-
});
|
package/src/constants/strings.ts
DELETED
package/src/decompose.test.ts
DELETED
|
@@ -1,37 +0,0 @@
|
|
|
1
|
-
import { createTests } from '@bemedev/vitest-extended';
|
|
2
|
-
import { decompose } from './decompose';
|
|
3
|
-
|
|
4
|
-
const useTests = createTests(decompose);
|
|
5
|
-
|
|
6
|
-
useTests(
|
|
7
|
-
['Empty object', [{}], []],
|
|
8
|
-
['Simple object', [{ age: 16, name: 'Alfred' }], ['age', 'name']],
|
|
9
|
-
[
|
|
10
|
-
'Recursive object',
|
|
11
|
-
[
|
|
12
|
-
{
|
|
13
|
-
_id: 'nanoid',
|
|
14
|
-
data: {
|
|
15
|
-
name: {
|
|
16
|
-
firstName: 'Charles-Lévi',
|
|
17
|
-
lastName: 'BRI',
|
|
18
|
-
},
|
|
19
|
-
},
|
|
20
|
-
statistics: {
|
|
21
|
-
updations: 5,
|
|
22
|
-
deletions: 34,
|
|
23
|
-
},
|
|
24
|
-
},
|
|
25
|
-
],
|
|
26
|
-
[
|
|
27
|
-
'_id',
|
|
28
|
-
'data',
|
|
29
|
-
'data.name',
|
|
30
|
-
'data.name.firstName',
|
|
31
|
-
'data.name.lastName',
|
|
32
|
-
'statistics',
|
|
33
|
-
'statistics.deletions',
|
|
34
|
-
'statistics.updations',
|
|
35
|
-
],
|
|
36
|
-
],
|
|
37
|
-
);
|
package/src/decompose.ts
DELETED
|
@@ -1,32 +0,0 @@
|
|
|
1
|
-
import { DELIMITER } from './constants/strings';
|
|
2
|
-
import { isPrimitive } from './helpers';
|
|
3
|
-
import { sortMap } from './sortMap';
|
|
4
|
-
import { Ru } from './types';
|
|
5
|
-
|
|
6
|
-
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
7
|
-
function ddecompose(val: any, prev = '') {
|
|
8
|
-
const _prev = prev ? prev + DELIMITER : '';
|
|
9
|
-
const output: string[] = [];
|
|
10
|
-
const entries1 = Object.entries(val);
|
|
11
|
-
entries1.forEach(([key, value]) => {
|
|
12
|
-
output.push(`${_prev}${key}`);
|
|
13
|
-
const isPrimit = isPrimitive(value);
|
|
14
|
-
if (!isPrimit) {
|
|
15
|
-
const values = ddecompose(value, `${_prev}${key}`);
|
|
16
|
-
output.push(...values);
|
|
17
|
-
}
|
|
18
|
-
});
|
|
19
|
-
return output;
|
|
20
|
-
}
|
|
21
|
-
|
|
22
|
-
export function decompose<T extends Ru>(
|
|
23
|
-
val: T,
|
|
24
|
-
sorter?: (a: string, b: string) => number,
|
|
25
|
-
) {
|
|
26
|
-
const output1 = ddecompose(val, '');
|
|
27
|
-
output1.sort(sorter ?? sortMap);
|
|
28
|
-
const regex = new RegExp(DELIMITER, 'g');
|
|
29
|
-
const output2 = output1.map(value => value.replace(regex, '.'));
|
|
30
|
-
|
|
31
|
-
return Object.freeze(output2);
|
|
32
|
-
}
|
package/src/decomposeSV.test.ts
DELETED
|
@@ -1,72 +0,0 @@
|
|
|
1
|
-
import { expect, it } from 'vitest';
|
|
2
|
-
import { decomposeSV } from './decomposeSV';
|
|
3
|
-
|
|
4
|
-
it('String', () => {
|
|
5
|
-
expect(decomposeSV('Hello World')).toEqual(['Hello World']);
|
|
6
|
-
});
|
|
7
|
-
|
|
8
|
-
it('Simple object', () => {
|
|
9
|
-
const obj = {
|
|
10
|
-
a: 'Hello',
|
|
11
|
-
b: 'World',
|
|
12
|
-
};
|
|
13
|
-
expect(decomposeSV(obj)).toEqual(['a', 'a.Hello', 'b', 'b.World']);
|
|
14
|
-
});
|
|
15
|
-
|
|
16
|
-
it('Complex object', () => {
|
|
17
|
-
const obj = {
|
|
18
|
-
a: 'Hello',
|
|
19
|
-
b: 'World',
|
|
20
|
-
c: {
|
|
21
|
-
d: 'Hello',
|
|
22
|
-
e: {
|
|
23
|
-
f: 'World',
|
|
24
|
-
g: 'Again',
|
|
25
|
-
},
|
|
26
|
-
},
|
|
27
|
-
};
|
|
28
|
-
expect(decomposeSV(obj)).toEqual([
|
|
29
|
-
'a',
|
|
30
|
-
'a.Hello',
|
|
31
|
-
'b',
|
|
32
|
-
'b.World',
|
|
33
|
-
'c',
|
|
34
|
-
'c.d',
|
|
35
|
-
'c.d.Hello',
|
|
36
|
-
'c.e',
|
|
37
|
-
'c.e.f',
|
|
38
|
-
'c.e.f.World',
|
|
39
|
-
'c.e.g',
|
|
40
|
-
'c.e.g.Again',
|
|
41
|
-
]);
|
|
42
|
-
});
|
|
43
|
-
|
|
44
|
-
it('Complex object with custom order', () => {
|
|
45
|
-
const obj = {
|
|
46
|
-
a: 'Hello',
|
|
47
|
-
b: 'World',
|
|
48
|
-
c: {
|
|
49
|
-
d: 'Hello',
|
|
50
|
-
e: {
|
|
51
|
-
f: 'World',
|
|
52
|
-
g: 'Again',
|
|
53
|
-
},
|
|
54
|
-
},
|
|
55
|
-
};
|
|
56
|
-
|
|
57
|
-
const actual = decomposeSV(obj, (a, b) => a.localeCompare(b));
|
|
58
|
-
expect(actual).toEqual([
|
|
59
|
-
'a',
|
|
60
|
-
'a.Hello',
|
|
61
|
-
'b',
|
|
62
|
-
'b.World',
|
|
63
|
-
'c',
|
|
64
|
-
'c.d',
|
|
65
|
-
'c.d.Hello',
|
|
66
|
-
'c.e',
|
|
67
|
-
'c.e.f',
|
|
68
|
-
'c.e.f.World',
|
|
69
|
-
'c.e.g',
|
|
70
|
-
'c.e.g.Again',
|
|
71
|
-
]);
|
|
72
|
-
});
|
package/src/decomposeSV.ts
DELETED
|
@@ -1,31 +0,0 @@
|
|
|
1
|
-
import { DELIMITER } from './constants/strings';
|
|
2
|
-
import { sortMap } from './sortMap';
|
|
3
|
-
import type { StateMatching, StateValue } from './types';
|
|
4
|
-
|
|
5
|
-
function ddecompose(val: StateValue, prev = '') {
|
|
6
|
-
const _prev = prev ? prev + DELIMITER : '';
|
|
7
|
-
const output: string[] = [];
|
|
8
|
-
prev !== '' && output.push(prev);
|
|
9
|
-
if (typeof val === 'string') {
|
|
10
|
-
output.push(`${_prev}${val}`);
|
|
11
|
-
} else {
|
|
12
|
-
const keys = Object.keys(val);
|
|
13
|
-
output.push(
|
|
14
|
-
...keys.map(key => ddecompose(val[key], `${_prev}${key}`)).flat(),
|
|
15
|
-
);
|
|
16
|
-
}
|
|
17
|
-
|
|
18
|
-
return output;
|
|
19
|
-
}
|
|
20
|
-
|
|
21
|
-
export function decomposeSV<T extends StateValue>(
|
|
22
|
-
val: T,
|
|
23
|
-
sorter?: (a: string, b: string) => number,
|
|
24
|
-
): readonly StateMatching<T>[] {
|
|
25
|
-
const first = ddecompose(val, '');
|
|
26
|
-
first.sort(sorter ?? sortMap);
|
|
27
|
-
const regex = new RegExp(DELIMITER, 'g');
|
|
28
|
-
const output = first.map(value => value.replace(regex, '.'));
|
|
29
|
-
|
|
30
|
-
return Object.freeze(output) as StateMatching<T>[];
|
|
31
|
-
}
|
package/src/helpers.ts
DELETED
|
@@ -1,11 +0,0 @@
|
|
|
1
|
-
type Primitive = string | number | boolean | null | undefined;
|
|
2
|
-
|
|
3
|
-
export function isPrimitive(arg: unknown): arg is Primitive {
|
|
4
|
-
return (
|
|
5
|
-
typeof arg === 'number' ||
|
|
6
|
-
typeof arg === 'string' ||
|
|
7
|
-
typeof arg === 'boolean' ||
|
|
8
|
-
arg === undefined ||
|
|
9
|
-
arg === null
|
|
10
|
-
);
|
|
11
|
-
}
|
package/src/index.ts
DELETED
package/src/recompose.test.ts
DELETED
|
@@ -1,163 +0,0 @@
|
|
|
1
|
-
import { createTests } from '@bemedev/vitest-extended';
|
|
2
|
-
import { describe } from 'vitest';
|
|
3
|
-
import { recompose, recomposeObjectUrl } from './recompose';
|
|
4
|
-
|
|
5
|
-
describe('#1 => Recompose', () => {
|
|
6
|
-
describe('#1 => URL for coverage', () => {
|
|
7
|
-
const useTests = createTests(recomposeObjectUrl);
|
|
8
|
-
const value = 10;
|
|
9
|
-
|
|
10
|
-
useTests(['Empty string', ['', value], {}]);
|
|
11
|
-
});
|
|
12
|
-
|
|
13
|
-
describe('#2 => Object', () => {
|
|
14
|
-
const useTests = createTests(recompose);
|
|
15
|
-
|
|
16
|
-
useTests(
|
|
17
|
-
['Empty object', [{}], {}],
|
|
18
|
-
[
|
|
19
|
-
'Object with simple keys',
|
|
20
|
-
[{ age: 10, login: 'login' }],
|
|
21
|
-
{ age: 10, login: 'login' },
|
|
22
|
-
],
|
|
23
|
-
[
|
|
24
|
-
'Object with keys, recursive order 1',
|
|
25
|
-
[{ 'data.age': 10, 'human.login': 'login' }],
|
|
26
|
-
{
|
|
27
|
-
data: {
|
|
28
|
-
age: 10,
|
|
29
|
-
},
|
|
30
|
-
human: {
|
|
31
|
-
login: 'login',
|
|
32
|
-
},
|
|
33
|
-
},
|
|
34
|
-
],
|
|
35
|
-
[
|
|
36
|
-
'Object with mergeable keys, recursive order 1',
|
|
37
|
-
[{ 'data.age': 10, 'data.login': 'login' }],
|
|
38
|
-
{
|
|
39
|
-
data: {
|
|
40
|
-
age: 10,
|
|
41
|
-
login: 'login',
|
|
42
|
-
},
|
|
43
|
-
},
|
|
44
|
-
],
|
|
45
|
-
[
|
|
46
|
-
'Object with keys, recursive order 4',
|
|
47
|
-
[
|
|
48
|
-
{
|
|
49
|
-
'db1.collection.entity.data.age': 10,
|
|
50
|
-
'db2.collection.entity.data.login': 'login',
|
|
51
|
-
},
|
|
52
|
-
],
|
|
53
|
-
{
|
|
54
|
-
db1: {
|
|
55
|
-
collection: {
|
|
56
|
-
entity: {
|
|
57
|
-
data: {
|
|
58
|
-
age: 10,
|
|
59
|
-
},
|
|
60
|
-
},
|
|
61
|
-
},
|
|
62
|
-
},
|
|
63
|
-
db2: {
|
|
64
|
-
collection: {
|
|
65
|
-
entity: {
|
|
66
|
-
data: {
|
|
67
|
-
login: 'login',
|
|
68
|
-
},
|
|
69
|
-
},
|
|
70
|
-
},
|
|
71
|
-
},
|
|
72
|
-
},
|
|
73
|
-
],
|
|
74
|
-
[
|
|
75
|
-
'Object with mergeable keys, recursive order 4',
|
|
76
|
-
[
|
|
77
|
-
{
|
|
78
|
-
'db1.collection.entity.data.age': 10,
|
|
79
|
-
'db1.collection.entity.data.login': 'login',
|
|
80
|
-
'db1.collection.entity.data.password': 'password',
|
|
81
|
-
},
|
|
82
|
-
],
|
|
83
|
-
{
|
|
84
|
-
db1: {
|
|
85
|
-
collection: {
|
|
86
|
-
entity: {
|
|
87
|
-
data: {
|
|
88
|
-
age: 10,
|
|
89
|
-
login: 'login',
|
|
90
|
-
password: 'password',
|
|
91
|
-
},
|
|
92
|
-
},
|
|
93
|
-
},
|
|
94
|
-
},
|
|
95
|
-
},
|
|
96
|
-
],
|
|
97
|
-
[
|
|
98
|
-
'Very complex',
|
|
99
|
-
[
|
|
100
|
-
{
|
|
101
|
-
'db1.collection.entity.data.age': 10,
|
|
102
|
-
'db1.collection.entity2.data.login': 'login',
|
|
103
|
-
'db1.collection.entity.data.password': 'password',
|
|
104
|
-
'db3.collection.entity.data.password': 'password',
|
|
105
|
-
'db3.collection.entity.data.login': 'login',
|
|
106
|
-
statistics: 1000,
|
|
107
|
-
'remainData.owner': 'admin',
|
|
108
|
-
id: 'id',
|
|
109
|
-
},
|
|
110
|
-
],
|
|
111
|
-
{
|
|
112
|
-
db1: {
|
|
113
|
-
collection: {
|
|
114
|
-
entity: {
|
|
115
|
-
data: {
|
|
116
|
-
age: 10,
|
|
117
|
-
password: 'password',
|
|
118
|
-
},
|
|
119
|
-
},
|
|
120
|
-
entity2: {
|
|
121
|
-
data: {
|
|
122
|
-
login: 'login',
|
|
123
|
-
},
|
|
124
|
-
},
|
|
125
|
-
},
|
|
126
|
-
},
|
|
127
|
-
db3: {
|
|
128
|
-
collection: {
|
|
129
|
-
entity: {
|
|
130
|
-
data: {
|
|
131
|
-
password: 'password',
|
|
132
|
-
login: 'login',
|
|
133
|
-
},
|
|
134
|
-
},
|
|
135
|
-
},
|
|
136
|
-
},
|
|
137
|
-
statistics: 1000,
|
|
138
|
-
remainData: {
|
|
139
|
-
owner: 'admin',
|
|
140
|
-
},
|
|
141
|
-
id: 'id',
|
|
142
|
-
},
|
|
143
|
-
],
|
|
144
|
-
[
|
|
145
|
-
'Conflicts',
|
|
146
|
-
[
|
|
147
|
-
{
|
|
148
|
-
statistics: 1000,
|
|
149
|
-
'statistics.owner': 'super',
|
|
150
|
-
'statistics.owner.website': 'www.supper.com',
|
|
151
|
-
},
|
|
152
|
-
],
|
|
153
|
-
{
|
|
154
|
-
statistics: {
|
|
155
|
-
owner: {
|
|
156
|
-
website: 'www.supper.com',
|
|
157
|
-
},
|
|
158
|
-
},
|
|
159
|
-
},
|
|
160
|
-
],
|
|
161
|
-
);
|
|
162
|
-
});
|
|
163
|
-
});
|
package/src/recompose.ts
DELETED
|
@@ -1,30 +0,0 @@
|
|
|
1
|
-
/* eslint-disable @typescript-eslint/no-explicit-any */
|
|
2
|
-
import { merge } from 'ts-deepmerge';
|
|
3
|
-
import { SEPARETOR } from './constants/strings';
|
|
4
|
-
import type { Recompose, Ru } from './types';
|
|
5
|
-
|
|
6
|
-
export function recomposeObjectUrl<T>(shape: string, value: T) {
|
|
7
|
-
const obj: Ru = {};
|
|
8
|
-
if (shape.length <= 0) return obj;
|
|
9
|
-
|
|
10
|
-
const keys = shape.split(SEPARETOR);
|
|
11
|
-
if (keys.length === 1) {
|
|
12
|
-
const key = keys.shift();
|
|
13
|
-
obj[key!] = value;
|
|
14
|
-
} else {
|
|
15
|
-
const key = keys.shift();
|
|
16
|
-
obj[key!] = recomposeObjectUrl(keys.join(SEPARETOR), value);
|
|
17
|
-
}
|
|
18
|
-
|
|
19
|
-
return obj;
|
|
20
|
-
}
|
|
21
|
-
|
|
22
|
-
export function recompose<T extends Ru>(shape: T) {
|
|
23
|
-
const entries = Object.entries(shape);
|
|
24
|
-
const arr: any[] = [];
|
|
25
|
-
entries.forEach(([key, value]) => {
|
|
26
|
-
arr.push(recomposeObjectUrl(key, value));
|
|
27
|
-
});
|
|
28
|
-
const output = merge(...arr);
|
|
29
|
-
return Object.freeze(output) as Recompose<T>;
|
|
30
|
-
}
|
package/src/sortMap.ts
DELETED
package/src/types.test-d.ts
DELETED
|
@@ -1,45 +0,0 @@
|
|
|
1
|
-
import { expectType } from 'tsd';
|
|
2
|
-
import type { Recompose } from './types';
|
|
3
|
-
|
|
4
|
-
// #region Simple
|
|
5
|
-
declare const et1: Recompose<{ age: number; login: string }>;
|
|
6
|
-
expectType<{ age: number; login: string }>(et1);
|
|
7
|
-
// #endregion
|
|
8
|
-
|
|
9
|
-
// #region Complex
|
|
10
|
-
declare const et2: Recompose<{
|
|
11
|
-
'data.age': number;
|
|
12
|
-
'data.login.ad.cd.ef': string;
|
|
13
|
-
'data.login.ad.cd.xd': string;
|
|
14
|
-
'data.connected': boolean;
|
|
15
|
-
id: string;
|
|
16
|
-
}>;
|
|
17
|
-
expectType<string>(et2.id);
|
|
18
|
-
expectType<string>(et2.data.login.ad.cd.ef);
|
|
19
|
-
expectType<string>(et2.data.login.ad.cd.xd);
|
|
20
|
-
expectType<boolean>(et2.data.connected);
|
|
21
|
-
// #endregion
|
|
22
|
-
|
|
23
|
-
// #region Add some class object
|
|
24
|
-
declare const et3: Recompose<{
|
|
25
|
-
'data.age': number;
|
|
26
|
-
'data.login': string;
|
|
27
|
-
id: string;
|
|
28
|
-
'other.bool': boolean;
|
|
29
|
-
'other.date': Date;
|
|
30
|
-
/**
|
|
31
|
-
* Don't known anything about this class
|
|
32
|
-
*/
|
|
33
|
-
'other.permission': PermissionState;
|
|
34
|
-
'other._class': AbortController;
|
|
35
|
-
'other.classe.another': Document;
|
|
36
|
-
}>;
|
|
37
|
-
expectType<string>(et3.id);
|
|
38
|
-
expectType<number>(et3.data.age);
|
|
39
|
-
expectType<string>(et3.data.login);
|
|
40
|
-
expectType<boolean>(et3.other.bool);
|
|
41
|
-
expectType<Date>(et3.other.date);
|
|
42
|
-
expectType<PermissionState>(et3.other.permission);
|
|
43
|
-
expectType<AbortController>(et3.other._class);
|
|
44
|
-
expectType<Document>(et3.other.classe.another);
|
|
45
|
-
// #endregion
|
package/src/types.test.ts
DELETED
|
@@ -1,12 +0,0 @@
|
|
|
1
|
-
import tsd, { formatter } from 'tsd';
|
|
2
|
-
import { expect, test } from 'vitest';
|
|
3
|
-
|
|
4
|
-
test('#0 => types', async () => {
|
|
5
|
-
const _tsd = await tsd({
|
|
6
|
-
cwd: process.cwd(),
|
|
7
|
-
testFiles: ['./src/types.test-d.ts'],
|
|
8
|
-
typingsFile: './src/types.ts',
|
|
9
|
-
});
|
|
10
|
-
const _fd = formatter(_tsd, true);
|
|
11
|
-
expect(_fd).toBe('');
|
|
12
|
-
}, 10000);
|