@bemedev/decompose 0.1.6 → 0.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/README.md +1 -1
- package/lib/constants/strings.cjs +6 -0
- package/lib/constants/strings.cjs.map +1 -0
- package/lib/constants/strings.d.ts +2 -0
- package/lib/constants/strings.d.ts.map +1 -0
- package/lib/constants/strings.js +4 -0
- package/lib/constants/strings.js.map +1 -0
- package/lib/decompose.cjs +28 -0
- package/lib/decompose.cjs.map +1 -0
- package/lib/decompose.d.ts +3 -0
- package/lib/decompose.d.ts.map +1 -0
- package/lib/decompose.js +26 -0
- package/lib/decompose.js.map +1 -0
- package/lib/index.cjs +10 -0
- package/lib/index.cjs.map +1 -0
- package/lib/index.d.ts +4 -21
- package/lib/index.d.ts.map +1 -0
- package/lib/index.js +2 -1
- package/lib/index.js.map +1 -1
- package/lib/sortMap.cjs +13 -0
- package/lib/sortMap.cjs.map +1 -0
- package/lib/sortMap.d.ts +2 -0
- package/lib/sortMap.d.ts.map +1 -0
- package/lib/sortMap.js +11 -0
- package/lib/sortMap.js.map +1 -0
- package/lib/types.d.ts +17 -0
- package/lib/types.d.ts.map +1 -0
- package/package.json +66 -34
- package/lib/index.mjs +0 -2
- package/lib/index.mjs.map +0 -1
package/README.md
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
|
|
1
|
+
## Decompose object to string paths
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"strings.cjs","sources":["../../src/constants/strings.ts"],"sourcesContent":["export const DELIMITER = '-{/./:}-' as const;\n"],"names":[],"mappings":";;AAAO,MAAM,SAAS,GAAG;;;;"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"strings.d.ts","sourceRoot":"","sources":["../../src/constants/strings.ts"],"names":[],"mappings":"AAAA,eAAO,MAAM,SAAS,YAAsB,CAAC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"strings.js","sources":["../../src/constants/strings.ts"],"sourcesContent":["export const DELIMITER = '-{/./:}-' as const;\n"],"names":[],"mappings":"AAAO,MAAM,SAAS,GAAG;;;;"}
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
var constants_strings = require('./constants/strings.cjs');
|
|
4
|
+
var sortMap = require('./sortMap.cjs');
|
|
5
|
+
|
|
6
|
+
function ddecompose(val, prev = '') {
|
|
7
|
+
const _prev = prev ? prev + constants_strings.DELIMITER : '';
|
|
8
|
+
const output = [];
|
|
9
|
+
prev !== '' && output.push(prev);
|
|
10
|
+
if (typeof val === 'string') {
|
|
11
|
+
output.push(`${_prev}${val}`);
|
|
12
|
+
}
|
|
13
|
+
else {
|
|
14
|
+
const keys = Object.keys(val);
|
|
15
|
+
output.push(...keys.map(key => ddecompose(val[key], `${_prev}${key}`)).flat());
|
|
16
|
+
}
|
|
17
|
+
return output;
|
|
18
|
+
}
|
|
19
|
+
function decompose(val, sorter) {
|
|
20
|
+
const first = ddecompose(val, '');
|
|
21
|
+
first.sort(sorter ?? sortMap.sortMap(constants_strings.DELIMITER));
|
|
22
|
+
const regex = new RegExp(constants_strings.DELIMITER, 'g');
|
|
23
|
+
const output = first.map(value => value.replace(regex, '.'));
|
|
24
|
+
return Object.freeze(output);
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
exports.decompose = decompose;
|
|
28
|
+
//# sourceMappingURL=decompose.cjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"decompose.cjs","sources":["../src/decompose.ts"],"sourcesContent":["import { DELIMITER } from './constants/strings';\nimport { sortMap } from './sortMap';\nimport { StateMatching, StateValue } from './types';\n\nfunction ddecompose(val: StateValue, prev = '') {\n const _prev = prev ? prev + DELIMITER : '';\n const output: string[] = [];\n prev !== '' && output.push(prev);\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\nexport function decompose<T extends StateValue>(\n val: T,\n sorter?: (a: string, b: string) => number,\n): readonly StateMatching<T>[] {\n const first = ddecompose(val, '');\n first.sort(sorter ?? sortMap(DELIMITER));\n const regex = new RegExp(DELIMITER, 'g');\n const output = first.map(value => value.replace(regex, '.'));\n\n return Object.freeze(output) as StateMatching<T>[];\n}\n"],"names":["DELIMITER","sortMap"],"mappings":";;;;;AAIA,SAAS,UAAU,CAAC,GAAe,EAAE,IAAI,GAAG,EAAE,EAAA;AAC5C,IAAA,MAAM,KAAK,GAAG,IAAI,GAAG,IAAI,GAAGA,2BAAS,GAAG,EAAE,CAAC;IAC3C,MAAM,MAAM,GAAa,EAAE,CAAC;IAC5B,IAAI,KAAK,EAAE,IAAI,MAAM,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC;AACjC,IAAA,IAAI,OAAO,GAAG,KAAK,QAAQ,EAAE;QAC3B,MAAM,CAAC,IAAI,CAAC,CAAA,EAAG,KAAK,CAAG,EAAA,GAAG,CAAE,CAAA,CAAC,CAAC;KAC/B;SAAM;QACL,MAAM,IAAI,GAAG,MAAM,CAAC,IAAI,CAAC,GAAG,CAAC,CAAC;AAC9B,QAAA,MAAM,CAAC,IAAI,CACT,GAAG,IAAI,CAAC,GAAG,CAAC,GAAG,IAAI,UAAU,CAAC,GAAG,CAAC,GAAG,CAAC,EAAE,CAAG,EAAA,KAAK,CAAG,EAAA,GAAG,CAAE,CAAA,CAAC,CAAC,CAAC,IAAI,EAAE,CAClE,CAAC;KACH;AAED,IAAA,OAAO,MAAM,CAAC;AAChB,CAAC;AAEe,SAAA,SAAS,CACvB,GAAM,EACN,MAAyC,EAAA;IAEzC,MAAM,KAAK,GAAG,UAAU,CAAC,GAAG,EAAE,EAAE,CAAC,CAAC;IAClC,KAAK,CAAC,IAAI,CAAC,MAAM,IAAIC,eAAO,CAACD,2BAAS,CAAC,CAAC,CAAC;IACzC,MAAM,KAAK,GAAG,IAAI,MAAM,CAACA,2BAAS,EAAE,GAAG,CAAC,CAAC;AACzC,IAAA,MAAM,MAAM,GAAG,KAAK,CAAC,GAAG,CAAC,KAAK,IAAI,KAAK,CAAC,OAAO,CAAC,KAAK,EAAE,GAAG,CAAC,CAAC,CAAC;AAE7D,IAAA,OAAO,MAAM,CAAC,MAAM,CAAC,MAAM,CAAuB,CAAC;AACrD;;;;"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"decompose.d.ts","sourceRoot":"","sources":["../src/decompose.ts"],"names":[],"mappings":"AAEA,OAAO,EAAE,aAAa,EAAE,UAAU,EAAE,MAAM,SAAS,CAAC;AAkBpD,wBAAgB,SAAS,CAAC,CAAC,SAAS,UAAU,EAC5C,GAAG,EAAE,CAAC,EACN,MAAM,CAAC,EAAE,CAAC,CAAC,EAAE,MAAM,EAAE,CAAC,EAAE,MAAM,KAAK,MAAM,GACxC,SAAS,aAAa,CAAC,CAAC,CAAC,EAAE,CAO7B"}
|
package/lib/decompose.js
ADDED
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
import { DELIMITER } from './constants/strings.js';
|
|
2
|
+
import { sortMap } from './sortMap.js';
|
|
3
|
+
|
|
4
|
+
function ddecompose(val, prev = '') {
|
|
5
|
+
const _prev = prev ? prev + DELIMITER : '';
|
|
6
|
+
const output = [];
|
|
7
|
+
prev !== '' && output.push(prev);
|
|
8
|
+
if (typeof val === 'string') {
|
|
9
|
+
output.push(`${_prev}${val}`);
|
|
10
|
+
}
|
|
11
|
+
else {
|
|
12
|
+
const keys = Object.keys(val);
|
|
13
|
+
output.push(...keys.map(key => ddecompose(val[key], `${_prev}${key}`)).flat());
|
|
14
|
+
}
|
|
15
|
+
return output;
|
|
16
|
+
}
|
|
17
|
+
function decompose(val, sorter) {
|
|
18
|
+
const first = ddecompose(val, '');
|
|
19
|
+
first.sort(sorter ?? sortMap(DELIMITER));
|
|
20
|
+
const regex = new RegExp(DELIMITER, 'g');
|
|
21
|
+
const output = first.map(value => value.replace(regex, '.'));
|
|
22
|
+
return Object.freeze(output);
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
export { decompose };
|
|
26
|
+
//# sourceMappingURL=decompose.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"decompose.js","sources":["../src/decompose.ts"],"sourcesContent":["import { DELIMITER } from './constants/strings';\nimport { sortMap } from './sortMap';\nimport { StateMatching, StateValue } from './types';\n\nfunction ddecompose(val: StateValue, prev = '') {\n const _prev = prev ? prev + DELIMITER : '';\n const output: string[] = [];\n prev !== '' && output.push(prev);\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\nexport function decompose<T extends StateValue>(\n val: T,\n sorter?: (a: string, b: string) => number,\n): readonly StateMatching<T>[] {\n const first = ddecompose(val, '');\n first.sort(sorter ?? sortMap(DELIMITER));\n const regex = new RegExp(DELIMITER, 'g');\n const output = first.map(value => value.replace(regex, '.'));\n\n return Object.freeze(output) as StateMatching<T>[];\n}\n"],"names":[],"mappings":";;;AAIA,SAAS,UAAU,CAAC,GAAe,EAAE,IAAI,GAAG,EAAE,EAAA;AAC5C,IAAA,MAAM,KAAK,GAAG,IAAI,GAAG,IAAI,GAAG,SAAS,GAAG,EAAE,CAAC;IAC3C,MAAM,MAAM,GAAa,EAAE,CAAC;IAC5B,IAAI,KAAK,EAAE,IAAI,MAAM,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC;AACjC,IAAA,IAAI,OAAO,GAAG,KAAK,QAAQ,EAAE;QAC3B,MAAM,CAAC,IAAI,CAAC,CAAA,EAAG,KAAK,CAAG,EAAA,GAAG,CAAE,CAAA,CAAC,CAAC;KAC/B;SAAM;QACL,MAAM,IAAI,GAAG,MAAM,CAAC,IAAI,CAAC,GAAG,CAAC,CAAC;AAC9B,QAAA,MAAM,CAAC,IAAI,CACT,GAAG,IAAI,CAAC,GAAG,CAAC,GAAG,IAAI,UAAU,CAAC,GAAG,CAAC,GAAG,CAAC,EAAE,CAAG,EAAA,KAAK,CAAG,EAAA,GAAG,CAAE,CAAA,CAAC,CAAC,CAAC,IAAI,EAAE,CAClE,CAAC;KACH;AAED,IAAA,OAAO,MAAM,CAAC;AAChB,CAAC;AAEe,SAAA,SAAS,CACvB,GAAM,EACN,MAAyC,EAAA;IAEzC,MAAM,KAAK,GAAG,UAAU,CAAC,GAAG,EAAE,EAAE,CAAC,CAAC;IAClC,KAAK,CAAC,IAAI,CAAC,MAAM,IAAI,OAAO,CAAC,SAAS,CAAC,CAAC,CAAC;IACzC,MAAM,KAAK,GAAG,IAAI,MAAM,CAAC,SAAS,EAAE,GAAG,CAAC,CAAC;AACzC,IAAA,MAAM,MAAM,GAAG,KAAK,CAAC,GAAG,CAAC,KAAK,IAAI,KAAK,CAAC,OAAO,CAAC,KAAK,EAAE,GAAG,CAAC,CAAC,CAAC;AAE7D,IAAA,OAAO,MAAM,CAAC,MAAM,CAAC,MAAM,CAAuB,CAAC;AACrD;;;;"}
|
package/lib/index.cjs
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.cjs","sources":[],"sourcesContent":[],"names":[],"mappings":";;;;;;;;"}
|
package/lib/index.d.ts
CHANGED
|
@@ -1,21 +1,4 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
sorter?: (a: string, b: string) => number;
|
|
6
|
-
};
|
|
7
|
-
declare type _UnionToIntersection<U> = (U extends unknown ? (k: U) => void : never) extends (k: infer I) => void ? I : never;
|
|
8
|
-
declare type _LastOf<T> = _UnionToIntersection<T extends unknown ? () => T : never> extends () => infer R ? R : never;
|
|
9
|
-
declare type _Push<T extends unknown[], V> = [...T, V];
|
|
10
|
-
declare type _TuplifyUnionBoolean<T> = [T] extends [never] ? true : false;
|
|
11
|
-
declare type TuplifyUnion<T> = true extends _TuplifyUnionBoolean<T> ? [] : _Push<TuplifyUnion<Exclude<T, _LastOf<T>>>, _LastOf<T>>;
|
|
12
|
-
declare type StateValue = string | StateValueMap;
|
|
13
|
-
interface StateValueMap {
|
|
14
|
-
[key: string]: StateValue;
|
|
15
|
-
}
|
|
16
|
-
|
|
17
|
-
declare function decompose<T extends StateValue>(val: T, sorter?: (a: string, b: string) => number): readonly StateMatching<T>[];
|
|
18
|
-
|
|
19
|
-
declare function sortMap(delimiter?: string): ((a: string, b: string) => number) | undefined;
|
|
20
|
-
|
|
21
|
-
export { DecomposeOptions, LengthOf, StateMatching, StateValue, StateValueMap, TuplifyUnion, decompose, sortMap };
|
|
1
|
+
export * from './decompose';
|
|
2
|
+
export * from './sortMap';
|
|
3
|
+
export * from './types';
|
|
4
|
+
//# sourceMappingURL=index.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,cAAc,aAAa,CAAC;AAC5B,cAAc,WAAW,CAAC;AAC1B,cAAc,SAAS,CAAC"}
|
package/lib/index.js
CHANGED
|
@@ -1,2 +1,3 @@
|
|
|
1
|
-
|
|
1
|
+
export { decompose } from './decompose.js';
|
|
2
|
+
export { sortMap } from './sortMap.js';
|
|
2
3
|
//# sourceMappingURL=index.js.map
|
package/lib/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sources":[
|
|
1
|
+
{"version":3,"file":"index.js","sources":[],"sourcesContent":[],"names":[],"mappings":";"}
|
package/lib/sortMap.cjs
ADDED
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
var constants_strings = require('./constants/strings.cjs');
|
|
4
|
+
|
|
5
|
+
function sortMap(delimiter = constants_strings.DELIMITER) {
|
|
6
|
+
return (a, b) => {
|
|
7
|
+
return (a.split(delimiter).length - b.split(delimiter).length ||
|
|
8
|
+
a.localeCompare(b));
|
|
9
|
+
};
|
|
10
|
+
}
|
|
11
|
+
|
|
12
|
+
exports.sortMap = sortMap;
|
|
13
|
+
//# sourceMappingURL=sortMap.cjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"sortMap.cjs","sources":["../src/sortMap.ts"],"sourcesContent":["import { DELIMITER } from './constants/strings';\n\nexport function sortMap(\n delimiter: string = DELIMITER,\n): ((a: string, b: string) => number) | undefined {\n return (a, b) => {\n return (\n a.split(delimiter).length - b.split(delimiter).length ||\n a.localeCompare(b)\n );\n };\n}\n"],"names":["DELIMITER"],"mappings":";;;;AAEgB,SAAA,OAAO,CACrB,SAAA,GAAoBA,2BAAS,EAAA;AAE7B,IAAA,OAAO,CAAC,CAAC,EAAE,CAAC,KAAI;AACd,QAAA,QACE,CAAC,CAAC,KAAK,CAAC,SAAS,CAAC,CAAC,MAAM,GAAG,CAAC,CAAC,KAAK,CAAC,SAAS,CAAC,CAAC,MAAM;AACrD,YAAA,CAAC,CAAC,aAAa,CAAC,CAAC,CAAC,EAClB;AACJ,KAAC,CAAC;AACJ;;;;"}
|
package/lib/sortMap.d.ts
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"sortMap.d.ts","sourceRoot":"","sources":["../src/sortMap.ts"],"names":[],"mappings":"AAEA,wBAAgB,OAAO,CACrB,SAAS,GAAE,MAAkB,GAC5B,CAAC,CAAC,CAAC,EAAE,MAAM,EAAE,CAAC,EAAE,MAAM,KAAK,MAAM,CAAC,GAAG,SAAS,CAOhD"}
|
package/lib/sortMap.js
ADDED
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import { DELIMITER } from './constants/strings.js';
|
|
2
|
+
|
|
3
|
+
function sortMap(delimiter = DELIMITER) {
|
|
4
|
+
return (a, b) => {
|
|
5
|
+
return (a.split(delimiter).length - b.split(delimiter).length ||
|
|
6
|
+
a.localeCompare(b));
|
|
7
|
+
};
|
|
8
|
+
}
|
|
9
|
+
|
|
10
|
+
export { sortMap };
|
|
11
|
+
//# sourceMappingURL=sortMap.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"sortMap.js","sources":["../src/sortMap.ts"],"sourcesContent":["import { DELIMITER } from './constants/strings';\n\nexport function sortMap(\n delimiter: string = DELIMITER,\n): ((a: string, b: string) => number) | undefined {\n return (a, b) => {\n return (\n a.split(delimiter).length - b.split(delimiter).length ||\n a.localeCompare(b)\n );\n };\n}\n"],"names":[],"mappings":";;AAEgB,SAAA,OAAO,CACrB,SAAA,GAAoB,SAAS,EAAA;AAE7B,IAAA,OAAO,CAAC,CAAC,EAAE,CAAC,KAAI;AACd,QAAA,QACE,CAAC,CAAC,KAAK,CAAC,SAAS,CAAC,CAAC,MAAM,GAAG,CAAC,CAAC,KAAK,CAAC,SAAS,CAAC,CAAC,MAAM;AACrD,YAAA,CAAC,CAAC,aAAa,CAAC,CAAC,CAAC,EAClB;AACJ,KAAC,CAAC;AACJ;;;;"}
|
package/lib/types.d.ts
ADDED
|
@@ -0,0 +1,17 @@
|
|
|
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}.${T[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
|
+
type _UnionToIntersection<U> = (U extends unknown ? (k: U) => void : never) extends (k: infer I) => void ? I : never;
|
|
8
|
+
type _LastOf<T> = _UnionToIntersection<T extends unknown ? () => T : never> extends () => infer R ? R : never;
|
|
9
|
+
type _Push<T extends unknown[], V> = [...T, V];
|
|
10
|
+
type _TuplifyUnionBoolean<T> = [T] extends [never] ? true : false;
|
|
11
|
+
export type TuplifyUnion<T> = true extends _TuplifyUnionBoolean<T> ? [] : _Push<TuplifyUnion<Exclude<T, _LastOf<T>>>, _LastOf<T>>;
|
|
12
|
+
export type StateValue = string | StateValueMap;
|
|
13
|
+
export interface StateValueMap {
|
|
14
|
+
[key: string]: StateValue;
|
|
15
|
+
}
|
|
16
|
+
export {};
|
|
17
|
+
//# sourceMappingURL=types.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
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,IAAI,CAAC,CAAC,GAAG,CAAC,GAAG,MAAM,EAAE,GAAG,CAAC,GAAG,GAAG,MAAM,CAAC,GAC9C,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,KAAK,oBAAoB,CAAC,CAAC,IAAI,CAC7B,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,OAAO,CAAC,CAAC,IACZ,oBAAoB,CAClB,CAAC,SAAS,OAAO,GAAG,MAAM,CAAC,GAAG,KAAK,CACpC,SAAS,MAAM,MAAM,CAAC,GACnB,CAAC,GACD,KAAK,CAAC;AAEZ,KAAK,KAAK,CAAC,CAAC,SAAS,OAAO,EAAE,EAAE,CAAC,IAAI,CAAC,GAAG,CAAC,EAAE,CAAC,CAAC,CAAC;AAE/C,KAAK,oBAAoB,CAAC,CAAC,IAAI,CAAC,CAAC,CAAC,SAAS,CAAC,KAAK,CAAC,GAAG,IAAI,GAAG,KAAK,CAAC;AAGlE,MAAM,MAAM,YAAY,CAAC,CAAC,IACxB,IAAI,SAAS,oBAAoB,CAAC,CAAC,CAAC,GAChC,EAAE,GACF,KAAK,CAAC,YAAY,CAAC,OAAO,CAAC,CAAC,EAAE,OAAO,CAAC,CAAC,CAAC,CAAC,CAAC,EAAE,OAAO,CAAC,CAAC,CAAC,CAAC,CAAC;AAI9D,MAAM,MAAM,UAAU,GAAG,MAAM,GAAG,aAAa,CAAC;AAEhD,MAAM,WAAW,aAAa;IAC5B,CAAC,GAAG,EAAE,MAAM,GAAG,UAAU,CAAC;CAC3B"}
|
package/package.json
CHANGED
|
@@ -1,56 +1,88 @@
|
|
|
1
1
|
{
|
|
2
|
-
"
|
|
2
|
+
"name": "@bemedev/decompose",
|
|
3
|
+
"version": "0.2.0",
|
|
4
|
+
"description": "Decompose object to string paths",
|
|
5
|
+
"author": {
|
|
6
|
+
"email": "bri_lvi@icloud.com",
|
|
7
|
+
"name": "chlbri",
|
|
8
|
+
"url": "https://bemedev.vercel.app"
|
|
9
|
+
},
|
|
10
|
+
"repository": {
|
|
11
|
+
"type": "git",
|
|
12
|
+
"url": "https://github.com/chlbri/decompose"
|
|
13
|
+
},
|
|
3
14
|
"license": "MIT",
|
|
15
|
+
"type": "module",
|
|
4
16
|
"main": "lib/index.js",
|
|
5
17
|
"typings": "lib/index.d.ts",
|
|
6
|
-
"module": "lib/index.
|
|
18
|
+
"module": "lib/index.js",
|
|
19
|
+
"keywords": [
|
|
20
|
+
"For",
|
|
21
|
+
"creating",
|
|
22
|
+
"new",
|
|
23
|
+
"npm",
|
|
24
|
+
"package"
|
|
25
|
+
],
|
|
7
26
|
"files": [
|
|
8
|
-
"lib"
|
|
27
|
+
"lib",
|
|
28
|
+
"public"
|
|
9
29
|
],
|
|
10
30
|
"engines": {
|
|
11
|
-
"node": ">=
|
|
31
|
+
"node": ">=20"
|
|
12
32
|
},
|
|
13
33
|
"scripts": {
|
|
14
34
|
"config": "pnpm install",
|
|
15
|
-
"
|
|
16
|
-
"
|
|
17
|
-
"
|
|
35
|
+
"config:off": "pnpm run config --offline",
|
|
36
|
+
"ci": "pnpm run config:off && pnpm run lint && pnpm run test && pnpm run build",
|
|
37
|
+
"ci:online": "pnpm run config && pnpm run lint && pnpm run test && pnpm run build",
|
|
38
|
+
"ci:admin": "pnpm run rm && pnpm run ci:online",
|
|
39
|
+
"rollup": "rollup -c",
|
|
40
|
+
"build": "rm -rf lib && pnpm run rollup",
|
|
41
|
+
"rm": "rm -rf node_modules pnpm-lock.yaml",
|
|
42
|
+
"rinit": "pnpm run rm && pnpm run config",
|
|
43
|
+
"rinit:off": "pnpm run rm && pnpm run config:off",
|
|
44
|
+
"test": "pnpm run test:coverage --no-coverage",
|
|
45
|
+
"test:coverage": "vitest run --passWithNoTests",
|
|
46
|
+
"test:watch": "vitest --passWithNoTests",
|
|
18
47
|
"remove": "rm -rf lib node_modules pnpm-lock.yaml",
|
|
19
48
|
"clean": "pnpm run remove && pnpm run config",
|
|
20
|
-
"test-watch": "pnpm test -- --watch",
|
|
21
49
|
"prettier": "prettier --write \"src/**/*.{ts,tsx}\"",
|
|
22
50
|
"eslint": "eslint \"{src/**/*,App}.{ts,tsx}\"",
|
|
23
51
|
"lint": "pnpm run prettier && pnpm run eslint --fix",
|
|
24
52
|
"lint-watch": "onchange --await-write-finish 5500 \"**/*\" -- pnpm run lint",
|
|
25
|
-
"
|
|
26
|
-
"
|
|
27
|
-
},
|
|
28
|
-
"husky": {
|
|
29
|
-
"hooks": {
|
|
30
|
-
"pre-commit": "prettier --write \"**/**.{ts,tsx,json,js,jsx,yml}\""
|
|
31
|
-
}
|
|
53
|
+
"prepublishOnly": "",
|
|
54
|
+
"prepare": "husky"
|
|
32
55
|
},
|
|
33
|
-
"name": "@bemedev/decompose",
|
|
34
|
-
"author": "chlbri",
|
|
35
56
|
"devDependencies": {
|
|
36
|
-
"@
|
|
37
|
-
"@
|
|
38
|
-
"@
|
|
39
|
-
"
|
|
40
|
-
"eslint": "^
|
|
41
|
-
"
|
|
57
|
+
"@bemedev/fsf": "^0.7.0",
|
|
58
|
+
"@bemedev/vitest-alias": "^0.0.2",
|
|
59
|
+
"@types/deep-diff": "^1.0.5",
|
|
60
|
+
"@types/node": "^20.12.8",
|
|
61
|
+
"@typescript-eslint/eslint-plugin": "^7.7.1",
|
|
62
|
+
"@typescript-eslint/parser": "^7.7.1",
|
|
63
|
+
"@vitest/coverage-v8": "^1.5.2",
|
|
64
|
+
"@xstate/immer": "^0.3.3",
|
|
65
|
+
"dequal": "^2.0.3",
|
|
66
|
+
"esbuild": "^0.20.2",
|
|
67
|
+
"eslint": "^8.57.0",
|
|
68
|
+
"glob": "^10.3.12",
|
|
69
|
+
"husky": "^9.0.11",
|
|
70
|
+
"immer": "^10.0.4",
|
|
42
71
|
"onchange": "^7.1.0",
|
|
43
|
-
"prettier": "^2.
|
|
44
|
-
"
|
|
45
|
-
"rollup
|
|
46
|
-
"rollup-plugin-
|
|
47
|
-
"rollup-plugin-
|
|
48
|
-
"tslib": "^2.
|
|
49
|
-
"typescript": "^4.
|
|
50
|
-
"
|
|
51
|
-
"
|
|
72
|
+
"prettier": "^3.2.5",
|
|
73
|
+
"pretty-quick": "^4.0.0",
|
|
74
|
+
"rollup": "^4.14.1",
|
|
75
|
+
"rollup-plugin-tsc-alias": "^1.1.2",
|
|
76
|
+
"rollup-plugin-typescript2": "^0.36.0",
|
|
77
|
+
"tslib": "^2.6.2",
|
|
78
|
+
"typescript": "^5.4.4",
|
|
79
|
+
"vitest": "^1.5.2",
|
|
80
|
+
"xstate": "^4.38.3",
|
|
81
|
+
"zod": "^3.23.4"
|
|
52
82
|
},
|
|
53
|
-
"
|
|
54
|
-
"
|
|
83
|
+
"dependencies": {
|
|
84
|
+
"@bemedev/decompose": "^0.1.6",
|
|
85
|
+
"@bemedev/usefull-functions": "^0.1.1",
|
|
86
|
+
"firebase": "^10.11.1"
|
|
55
87
|
}
|
|
56
88
|
}
|
package/lib/index.mjs
DELETED
|
@@ -1,2 +0,0 @@
|
|
|
1
|
-
function e(e="-{/./:}-"){return(t,n)=>t.split(e).length-n.split(e).length||t.localeCompare(n)}function t(e,n=""){const s=n?n+"-{/./:}-":"",o=[];if(""!==n&&o.push(n),"string"==typeof e)o.push(`${s}${e}`);else{const n=Object.keys(e);o.push(...n.map((n=>t(e[n],`${s}${n}`))).flat())}return o}function n(n,s){const o=t(n,"");o.sort(null!=s?s:e("-{/./:}-"));const p=new RegExp("-{/./:}-","g"),r=o.map((e=>e.replace(p,".")));return Object.freeze(r)}export{n as decompose,e as sortMap};
|
|
2
|
-
//# sourceMappingURL=index.mjs.map
|
package/lib/index.mjs.map
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"index.mjs","sources":["../src/sortMap.ts","../src/constants/strings.ts","../src/decompose.ts"],"sourcesContent":["import { DELIMITER } from './constants/strings';\n\nexport function sortMap(\n delimiter: string = DELIMITER,\n): ((a: string, b: string) => number) | undefined {\n return (a, b) => {\n return (\n a.split(delimiter).length - b.split(delimiter).length ||\n a.localeCompare(b)\n );\n };\n}\n","export const DELIMITER = '-{/./:}-' as const;\n","import { DELIMITER } from './constants/strings';\nimport { sortMap } from './sortMap';\nimport { StateMatching, StateValue } from './types';\n\nfunction ddecompose(val: StateValue, prev = '') {\n const _prev = prev ? prev + DELIMITER : '';\n const output: string[] = [];\n prev !== '' && output.push(prev);\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\nexport function decompose<T extends StateValue>(\n val: T,\n sorter?: (a: string, b: string) => number,\n): readonly StateMatching<T>[] {\n const first = ddecompose(val, '');\n first.sort(sorter ?? sortMap(DELIMITER));\n const regex = new RegExp(DELIMITER, 'g');\n const output = first.map(value => value.replace(regex, '.'));\n\n return Object.freeze(output) as StateMatching<T>[];\n}\n"],"names":["sortMap","delimiter","a","b","split","length","localeCompare","ddecompose","val","prev","_prev","output","push","keys","Object","map","key","flat","decompose","sorter","first","sort","regex","RegExp","value","replace","freeze"],"mappings":"AAEgB,SAAAA,EACdC,ECHuB,YDKhB,MAAA,CAACC,EAAGC,IAEPD,EAAEE,MAAMH,GAAWI,OAASF,EAAEC,MAAMH,GAAWI,QAC/CH,EAAEI,cAAcH,EAGtB,CEPA,SAASI,EAAWC,EAAiBC,EAAO,IACpC,MAAAC,EAAQD,EAAOA,EDLE,WCKiB,GAClCE,EAAmB,GAErB,GADK,KAAAF,GAAME,EAAOC,KAAKH,GACR,iBAARD,EACFG,EAAAC,KAAK,GAAGF,IAAQF,SAClB,CACC,MAAAK,EAAOC,OAAOD,KAAKL,GAClBG,EAAAC,QACFC,EAAKE,KAAIC,GAAOT,EAAWC,EAAIQ,GAAM,GAAGN,IAAQM,OAAQC,OAE/D,CAEO,OAAAN,CACT,CAEgB,SAAAO,EACdV,EACAW,GAEM,MAAAC,EAAQb,EAAWC,EAAK,IAC9BY,EAAMC,KAAK,MAAAF,EAAAA,EAAUnB,EDzBE,aC0BvB,MAAMsB,EAAQ,IAAIC,OD1BK,WC0Ba,KAC9BZ,EAASS,EAAML,KAAIS,GAASA,EAAMC,QAAQH,EAAO,OAEhD,OAAAR,OAAOY,OAAOf,EACvB"}
|