@bemedev/decompose 0.1.2 → 0.1.4
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/index.d.ts +21 -3
- package/lib/index.js +2 -0
- package/lib/index.js.map +1 -0
- package/lib/index.mjs +2 -0
- package/lib/index.mjs.map +1 -0
- package/package.json +12 -25
- package/lib/constants/strings.d.ts +0 -1
- package/lib/decompose.d.ts +0 -3
- package/lib/index.cjs +0 -2
- package/lib/index.cjs.map +0 -1
- package/lib/index.esm.js +0 -2
- package/lib/index.esm.js.map +0 -1
- package/lib/index.modern.js +0 -2
- package/lib/index.modern.js.map +0 -1
- package/lib/index.umd.js +0 -2
- package/lib/index.umd.js.map +0 -1
- package/lib/sortMap.d.ts +0 -1
- package/lib/types.d.ts +0 -14
- package/src/constants/strings.ts +0 -1
- package/src/decompose.test.ts +0 -71
- package/src/decompose.ts +0 -32
- package/src/index.ts +0 -3
- package/src/sortMap.ts +0 -12
- package/src/types.ts +0 -51
package/lib/index.d.ts
CHANGED
|
@@ -1,3 +1,21 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
1
|
+
declare 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
|
+
declare type LengthOf<T> = T extends ReadonlyArray<unknown> ? T['length'] : number;
|
|
3
|
+
declare type DecomposeOptions = {
|
|
4
|
+
delimiter?: string;
|
|
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 };
|
package/lib/index.js
ADDED
|
@@ -0,0 +1,2 @@
|
|
|
1
|
+
"use strict";Object.defineProperty(exports,"__esModule",{value:!0});function e(e="-{/./:}-"){return(t,s)=>t.split(e).length-s.split(e).length||t.localeCompare(s)}function t(e,s=""){const n=s?s+"-{/./:}-":"",o=[];if(""!==s&&o.push(s),"string"==typeof e)o.push(`${n}${e}`);else{const s=Object.keys(e);o.push(...s.map((s=>t(e[s],`${n}${s}`))).flat())}return o}exports.decompose=function(s,n){const o=t(s,"");o.sort(null!=n?n:e("-{/./:}-"));const r=new RegExp("-{/./:}-","g"),p=o.map((e=>e.replace(r,".")));return Object.freeze(p)},exports.sortMap=e;
|
|
2
|
+
//# sourceMappingURL=index.js.map
|
package/lib/index.js.map
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","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","sorter","first","sort","regex","RegExp","value","replace","freeze"],"mappings":"oEAEgB,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,mBAEgB,SACdH,EACAU,GAEM,MAAAC,EAAQZ,EAAWC,EAAK,IAC9BW,EAAMC,KAAK,MAAAF,EAAAA,EAAUlB,EDzBE,aC0BvB,MAAMqB,EAAQ,IAAIC,OD1BK,WC0Ba,KAC9BX,EAASQ,EAAMJ,KAAIQ,GAASA,EAAMC,QAAQH,EAAO,OAEhD,OAAAP,OAAOW,OAAOd,EACvB"}
|
package/lib/index.mjs
ADDED
|
@@ -0,0 +1,2 @@
|
|
|
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
|
|
@@ -0,0 +1 @@
|
|
|
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"}
|
package/package.json
CHANGED
|
@@ -1,27 +1,20 @@
|
|
|
1
1
|
{
|
|
2
|
-
"version": "0.1.
|
|
2
|
+
"version": "0.1.4",
|
|
3
3
|
"license": "MIT",
|
|
4
4
|
"type": "module",
|
|
5
5
|
"main": "lib/index.js",
|
|
6
|
-
"umd:main": "lib/index.umd.js",
|
|
7
|
-
"unpkg": "lib/index.umd.js",
|
|
8
6
|
"typings": "lib/index.d.ts",
|
|
9
7
|
"files": [
|
|
10
|
-
"lib"
|
|
11
|
-
"src"
|
|
8
|
+
"lib"
|
|
12
9
|
],
|
|
13
10
|
"engines": {
|
|
14
11
|
"node": ">=12"
|
|
15
12
|
},
|
|
16
|
-
"exports": {
|
|
17
|
-
"require": "./lib/index.cjs",
|
|
18
|
-
"default": "./lib/index.modern.js"
|
|
19
|
-
},
|
|
20
13
|
"scripts": {
|
|
21
14
|
"config": "pnpm install",
|
|
22
15
|
"start": "pnpm run config && microbundle watch",
|
|
23
|
-
"build": "rm -rf lib &&
|
|
24
|
-
"test": "
|
|
16
|
+
"build": "rm -rf lib && rollup -c",
|
|
17
|
+
"test": "vitest run",
|
|
25
18
|
"remove": "rm -rf lib node_modules pnpm-lock.yaml",
|
|
26
19
|
"clean": "pnpm run remove && pnpm run config",
|
|
27
20
|
"test-watch": "pnpm test -- --watch",
|
|
@@ -39,29 +32,23 @@
|
|
|
39
32
|
},
|
|
40
33
|
"name": "@bemedev/decompose",
|
|
41
34
|
"author": "chlbri",
|
|
42
|
-
"module": "lib/index.esm.js",
|
|
43
|
-
"peerDependencies": {
|
|
44
|
-
"tslib": "^2.4.0",
|
|
45
|
-
"typescript": "^4.7.4",
|
|
46
|
-
"xstate": "^4.33.2"
|
|
47
|
-
},
|
|
48
35
|
"devDependencies": {
|
|
49
|
-
"@swc/core": "^1.2.239",
|
|
50
|
-
"@swc/jest": "^0.2.22",
|
|
51
|
-
"@types/jest": "^28.1.7",
|
|
52
36
|
"@types/node": "^18.7.6",
|
|
53
37
|
"@typescript-eslint/eslint-plugin": "^5.33.1",
|
|
54
38
|
"@typescript-eslint/parser": "^5.33.1",
|
|
39
|
+
"esbuild": "^0.15.9",
|
|
55
40
|
"eslint": "^8.22.0",
|
|
56
41
|
"husky": "^8.0.1",
|
|
57
|
-
"jest": "27.5.0",
|
|
58
|
-
"jest-extended": "^3.0.2",
|
|
59
|
-
"microbundle": "^0.15.1",
|
|
60
42
|
"onchange": "^7.1.0",
|
|
61
43
|
"prettier": "^2.7.1",
|
|
62
|
-
"
|
|
44
|
+
"rollup": "^2.79.1",
|
|
45
|
+
"rollup-plugin-dts": "^4.2.2",
|
|
46
|
+
"rollup-plugin-esbuild": "^4.10.1",
|
|
47
|
+
"rollup-plugin-terser": "^7.0.2",
|
|
48
|
+
"tslib": "^2.4.0",
|
|
63
49
|
"typescript": "^4.7.4",
|
|
64
|
-
"
|
|
50
|
+
"vite": "^3.1.3",
|
|
51
|
+
"vitest": "^0.23.4"
|
|
65
52
|
},
|
|
66
53
|
"wallaby": {
|
|
67
54
|
"slowTestThreshold": 200
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export declare const DELIMITER: "-{/./:}-";
|
package/lib/decompose.d.ts
DELETED
package/lib/index.cjs
DELETED
|
@@ -1,2 +0,0 @@
|
|
|
1
|
-
function e(e){return void 0===e&&(e="-{/./:}-"),function(t,r){return t.split(e).length-r.split(e).length||t.localeCompare(r)}}function t(e,r){void 0===r&&(r="");var n=r?r+"-{/./:}-":"",o=[];if(""!==r&&o.push(r),"string"==typeof e)o.push(""+n+e);else{var p=Object.keys(e);o.push.apply(o,p.map(function(r){return t(e[r],""+n+r)}).flat())}return o}exports.decompose=function(r,n){var o=t(r,"");o.sort(null!=n?n:e("-{/./:}-"));var p=new RegExp("-{/./:}-","g"),u=o.map(function(e){return e.replace(p,".")});return Object.freeze(u)},exports.sortMap=e;
|
|
2
|
-
//# sourceMappingURL=index.cjs.map
|
package/lib/index.cjs.map
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"index.cjs","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 { StateValue } from 'xstate';\nimport { DELIMITER } from './constants/strings';\nimport { sortMap } from './sortMap';\nimport { StateMatching } 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","Object","keys","map","key","flat","sorter","first","sort","value","replace","regex","freeze"],"mappings":"AAEgBA,SAAAA,EACdC,GAEA,YAF6B,IAA7BA,IAAAA,ECHuB,YDKhB,SAACC,EAAGC,GACT,OACED,EAAEE,MAAMH,GAAWI,OAASF,EAAEC,MAAMH,GAAWI,QAC/CH,EAAEI,cAAcH,EAEnB,CACF,CEND,SAAAI,EAAoBC,EAAiBC,YAAAA,IAAAA,EAAO,IAC1C,IAAWC,EAAGD,EAAOA,EDNE,WCMiB,KACf,GAEzB,GADS,KAATA,GAAeE,EAAOC,KAAKH,GACR,mBACjBE,EAAOC,KAAP,GAAeF,EAAQF,OAClB,CACL,MAAaK,OAAOC,KAAKN,GACzBG,EAAOC,WAAPD,EACKG,EAAKC,IAAI,SAAAC,GAAOT,OAAAA,EAAWC,EAAIQ,GAAL,GAAcN,EAAQM,EAApC,GAA4CC,OAE9D,CAED,OAAON,CACR,mBAEe,SACdH,EACAU,GAEA,MAAcX,EAAWC,EAAK,IAC9BW,EAAMC,KAAN,MAAWF,EAAAA,EAAUlB,ED1BE,aC2BvB,MAAc,WD3BS,WC2Ba,KAC9BW,EAASQ,EAAMJ,IAAI,SAAAM,GAASA,OAAAA,EAAMC,QAAQC,EAAO,IAAzB,GAE9B,OAAOV,OAAOW,OAAOb,EACtB"}
|
package/lib/index.esm.js
DELETED
|
@@ -1,2 +0,0 @@
|
|
|
1
|
-
function e(e){return void 0===e&&(e="-{/./:}-"),function(n,t){return n.split(e).length-t.split(e).length||n.localeCompare(t)}}function n(e,t){void 0===t&&(t="");var r=t?t+"-{/./:}-":"",u=[];if(""!==t&&u.push(t),"string"==typeof e)u.push(""+r+e);else{var p=Object.keys(e);u.push.apply(u,p.map(function(t){return n(e[t],""+r+t)}).flat())}return u}function t(t,r){var u=n(t,"");u.sort(null!=r?r:e("-{/./:}-"));var p=new RegExp("-{/./:}-","g"),o=u.map(function(e){return e.replace(p,".")});return Object.freeze(o)}export{t as decompose,e as sortMap};
|
|
2
|
-
//# sourceMappingURL=index.esm.js.map
|
package/lib/index.esm.js.map
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"index.esm.js","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 { StateValue } from 'xstate';\nimport { DELIMITER } from './constants/strings';\nimport { sortMap } from './sortMap';\nimport { StateMatching } 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","Object","keys","map","key","flat","decompose","sorter","first","sort","value","replace","regex","freeze"],"mappings":"AAEgBA,SAAAA,EACdC,GAEA,YAF6B,IAA7BA,IAAAA,ECHuB,YDKhB,SAACC,EAAGC,GACT,OACED,EAAEE,MAAMH,GAAWI,OAASF,EAAEC,MAAMH,GAAWI,QAC/CH,EAAEI,cAAcH,EAEnB,CACF,CEND,SAAAI,EAAoBC,EAAiBC,YAAAA,IAAAA,EAAO,IAC1C,IAAWC,EAAGD,EAAOA,EDNE,WCMiB,KACf,GAEzB,GADS,KAATA,GAAeE,EAAOC,KAAKH,GACR,mBACjBE,EAAOC,KAAP,GAAeF,EAAQF,OAClB,CACL,MAAaK,OAAOC,KAAKN,GACzBG,EAAOC,WAAPD,EACKG,EAAKC,IAAI,SAAAC,GAAOT,OAAAA,EAAWC,EAAIQ,GAAL,GAAcN,EAAQM,EAApC,GAA4CC,OAE9D,CAED,OAAON,CACR,CAEe,SAAAO,EACdV,EACAW,GAEA,MAAcZ,EAAWC,EAAK,IAC9BY,EAAMC,KAAN,MAAWF,EAAAA,EAAUnB,ED1BE,aC2BvB,MAAc,WD3BS,WC2Ba,KAC9BW,EAASS,EAAML,IAAI,SAAAO,GAASA,OAAAA,EAAMC,QAAQC,EAAO,IAAzB,GAE9B,OAAOX,OAAOY,OAAOd,EACtB"}
|
package/lib/index.modern.js
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.modern.js.map
|
package/lib/index.modern.js.map
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"index.modern.js","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 { StateValue } from 'xstate';\nimport { DELIMITER } from './constants/strings';\nimport { sortMap } from './sortMap';\nimport { StateMatching } 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","a","b","split","length","localeCompare","ddecompose","val","prev","_prev","output","push","Object","keys","map","key","flat","decompose","sorter","first","sort","sortMap","RegExp","value","replace","regex","freeze"],"mappings":"AAEgB,WACdA,ECHuB,YDKvB,MAAO,CAACC,EAAGC,MAELC,MAAMH,GAAWI,OAASF,EAAEC,MAAMH,GAAWI,QAC/CH,EAAEI,cAAcH,EAGrB,CEND,SAASI,EAAWC,EAAiBC,EAAO,IAC1C,MAAWC,EAAGD,EAAOA,EDNE,WCMiB,KACf,GAEzB,GADS,KAATA,GAAeE,EAAOC,KAAKH,GACR,mBACjBE,EAAOC,KAAK,GAAGF,IAAQF,SAClB,CACL,QAAaK,OAAOC,KAAKN,GACzBG,EAAOC,QACFE,EAAKC,IAAIC,GAAOT,EAAWC,EAAIQ,GAAS,GAAAN,IAAQM,MAAQC,OAE9D,CAED,OAAON,CACR,CAEe,SAAAO,EACdV,EACAW,GAEA,QAAcZ,EAAWC,EAAK,IAC9BY,EAAMC,KAAN,MAAWF,EAAAA,EAAUG,ED1BE,aC2BvB,QAAc,IAAAC,OD3BS,WC2Ba,OACrBH,EAAML,IAAIS,GAASA,EAAMC,QAAQC,EAAO,MAEvD,OAAOb,OAAOc,OAAOhB,EACtB"}
|
package/lib/index.umd.js
DELETED
|
@@ -1,2 +0,0 @@
|
|
|
1
|
-
!function(e,n){"object"==typeof exports&&"undefined"!=typeof module?n(exports):"function"==typeof define&&define.amd?define(["exports"],n):n((e||self).decompose={})}(this,function(e){var n="-{/./:}-";function t(e){return void 0===e&&(e=n),function(n,t){return n.split(e).length-t.split(e).length||n.localeCompare(t)}}function o(e,t){void 0===t&&(t="");var r=t?t+n:"",f=[];if(""!==t&&f.push(t),"string"==typeof e)f.push(""+r+e);else{var i=Object.keys(e);f.push.apply(f,i.map(function(n){return o(e[n],""+r+n)}).flat())}return f}e.decompose=function(e,r){var f=o(e,"");f.sort(null!=r?r:t(n));var i=new RegExp(n,"g"),p=f.map(function(e){return e.replace(i,".")});return Object.freeze(p)},e.sortMap=t});
|
|
2
|
-
//# sourceMappingURL=index.umd.js.map
|
package/lib/index.umd.js.map
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"index.umd.js","sources":["../src/constants/strings.ts","../src/sortMap.ts","../src/decompose.ts"],"sourcesContent":["export const DELIMITER = '-{/./:}-' as const;\n","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","import { StateValue } from 'xstate';\nimport { DELIMITER } from './constants/strings';\nimport { sortMap } from './sortMap';\nimport { StateMatching } 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","delimiter","a","b","split","length","localeCompare","ddecompose","val","prev","_prev","output","push","Object","keys","map","key","flat","sorter","first","sort","value","replace","regex","freeze"],"mappings":"mOAAO,IAAeA,EAAG,WCETC,SAAAA,EACdC,GAEA,YAF6B,IAA7BA,IAAAA,EAAoBF,GAEb,SAACG,EAAGC,GACT,OACED,EAAEE,MAAMH,GAAWI,OAASF,EAAEC,MAAMH,GAAWI,QAC/CH,EAAEI,cAAcH,EAEnB,CACF,CCND,SAAAI,EAAoBC,EAAiBC,YAAAA,IAAAA,EAAO,IAC1C,IAAWC,EAAGD,EAAOA,EAAOV,EAAY,KACf,GAEzB,GADS,KAATU,GAAeE,EAAOC,KAAKH,GACR,mBACjBE,EAAOC,KAAP,GAAeF,EAAQF,OAClB,CACL,MAAaK,OAAOC,KAAKN,GACzBG,EAAOC,WAAPD,EACKG,EAAKC,IAAI,SAAAC,GAAOT,OAAAA,EAAWC,EAAIQ,GAAL,GAAcN,EAAQM,EAApC,GAA4CC,OAE9D,CAED,OAAON,CACR,aAEe,SACdH,EACAU,GAEA,MAAcX,EAAWC,EAAK,IAC9BW,EAAMC,KAAN,MAAWF,EAAAA,EAAUlB,EAAQD,IAC7B,MAAc,WAAWA,EAAW,KAC9BY,EAASQ,EAAMJ,IAAI,SAAAM,GAASA,OAAAA,EAAMC,QAAQC,EAAO,IAAzB,GAE9B,OAAOV,OAAOW,OAAOb,EACtB"}
|
package/lib/sortMap.d.ts
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export declare function sortMap(delimiter?: string): ((a: string, b: string) => number) | undefined;
|
package/lib/types.d.ts
DELETED
|
@@ -1,14 +0,0 @@
|
|
|
1
|
-
import { EventFrom, Interpreter } from 'xstate';
|
|
2
|
-
export declare 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;
|
|
3
|
-
export declare type LengthOf<T> = T extends ReadonlyArray<unknown> ? T['length'] : number;
|
|
4
|
-
export declare type DecomposeOptions = {
|
|
5
|
-
delimiter?: string;
|
|
6
|
-
sorter?: (a: string, b: string) => number;
|
|
7
|
-
};
|
|
8
|
-
declare type _UnionToIntersection<U> = (U extends unknown ? (k: U) => void : never) extends (k: infer I) => void ? I : never;
|
|
9
|
-
declare type _LastOf<T> = _UnionToIntersection<T extends unknown ? () => T : never> extends () => infer R ? R : never;
|
|
10
|
-
declare type _Push<T extends unknown[], V> = [...T, V];
|
|
11
|
-
declare type _TuplifyUnionBoolean<T> = [T] extends [never] ? true : false;
|
|
12
|
-
export declare type TuplifyUnion<T> = true extends _TuplifyUnionBoolean<T> ? [] : _Push<TuplifyUnion<Exclude<T, _LastOf<T>>>, _LastOf<T>>;
|
|
13
|
-
export declare type OmitEvent<T extends Interpreter<never, never, never, never, never>, K extends EventFrom<T>['type']> = LengthOf<TuplifyUnion<keyof EventFrom<T, K>>> extends 1 ? () => unknown : (data: Omit<EventFrom<T>, 'type'>) => unknown;
|
|
14
|
-
export {};
|
package/src/constants/strings.ts
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export const DELIMITER = '-{/./:}-' as const;
|
package/src/decompose.test.ts
DELETED
|
@@ -1,71 +0,0 @@
|
|
|
1
|
-
import { decompose } from './decompose';
|
|
2
|
-
|
|
3
|
-
it('String', () => {
|
|
4
|
-
expect(decompose('Hello World')).toEqual(['Hello World']);
|
|
5
|
-
});
|
|
6
|
-
|
|
7
|
-
it('Simple object', () => {
|
|
8
|
-
const obj = {
|
|
9
|
-
a: 'Hello',
|
|
10
|
-
b: 'World',
|
|
11
|
-
};
|
|
12
|
-
expect(decompose(obj)).toEqual(['a', 'b', 'a.Hello', 'b.World']);
|
|
13
|
-
});
|
|
14
|
-
|
|
15
|
-
it('Complex object', () => {
|
|
16
|
-
const obj = {
|
|
17
|
-
a: 'Hello',
|
|
18
|
-
b: 'World',
|
|
19
|
-
c: {
|
|
20
|
-
d: 'Hello',
|
|
21
|
-
e: {
|
|
22
|
-
f: 'World',
|
|
23
|
-
g: 'Again',
|
|
24
|
-
},
|
|
25
|
-
},
|
|
26
|
-
};
|
|
27
|
-
expect(decompose(obj)).toEqual([
|
|
28
|
-
'a',
|
|
29
|
-
'b',
|
|
30
|
-
'c',
|
|
31
|
-
'a.Hello',
|
|
32
|
-
'b.World',
|
|
33
|
-
'c.d',
|
|
34
|
-
'c.e',
|
|
35
|
-
'c.d.Hello',
|
|
36
|
-
'c.e.f',
|
|
37
|
-
'c.e.g',
|
|
38
|
-
'c.e.f.World',
|
|
39
|
-
'c.e.g.Again',
|
|
40
|
-
]);
|
|
41
|
-
});
|
|
42
|
-
|
|
43
|
-
it('Complex object with custom order', () => {
|
|
44
|
-
const obj = {
|
|
45
|
-
a: 'Hello',
|
|
46
|
-
b: 'World',
|
|
47
|
-
c: {
|
|
48
|
-
d: 'Hello',
|
|
49
|
-
e: {
|
|
50
|
-
f: 'World',
|
|
51
|
-
g: 'Again',
|
|
52
|
-
},
|
|
53
|
-
},
|
|
54
|
-
};
|
|
55
|
-
|
|
56
|
-
const actual = decompose(obj, (a, b) => a.localeCompare(b));
|
|
57
|
-
expect(actual).toEqual([
|
|
58
|
-
'a',
|
|
59
|
-
'a.Hello',
|
|
60
|
-
'b',
|
|
61
|
-
'b.World',
|
|
62
|
-
'c',
|
|
63
|
-
'c.d',
|
|
64
|
-
'c.d.Hello',
|
|
65
|
-
'c.e',
|
|
66
|
-
'c.e.f',
|
|
67
|
-
'c.e.f.World',
|
|
68
|
-
'c.e.g',
|
|
69
|
-
'c.e.g.Again',
|
|
70
|
-
]);
|
|
71
|
-
});
|
package/src/decompose.ts
DELETED
|
@@ -1,32 +0,0 @@
|
|
|
1
|
-
import { StateValue } from 'xstate';
|
|
2
|
-
import { DELIMITER } from './constants/strings';
|
|
3
|
-
import { sortMap } from './sortMap';
|
|
4
|
-
import { StateMatching } from './types';
|
|
5
|
-
|
|
6
|
-
function ddecompose(val: StateValue, prev = '') {
|
|
7
|
-
const _prev = prev ? prev + DELIMITER : '';
|
|
8
|
-
const output: string[] = [];
|
|
9
|
-
prev !== '' && output.push(prev);
|
|
10
|
-
if (typeof val === 'string') {
|
|
11
|
-
output.push(`${_prev}${val}`);
|
|
12
|
-
} else {
|
|
13
|
-
const keys = Object.keys(val);
|
|
14
|
-
output.push(
|
|
15
|
-
...keys.map(key => ddecompose(val[key], `${_prev}${key}`)).flat(),
|
|
16
|
-
);
|
|
17
|
-
}
|
|
18
|
-
|
|
19
|
-
return output;
|
|
20
|
-
}
|
|
21
|
-
|
|
22
|
-
export function decompose<T extends StateValue>(
|
|
23
|
-
val: T,
|
|
24
|
-
sorter?: (a: string, b: string) => number,
|
|
25
|
-
): readonly StateMatching<T>[] {
|
|
26
|
-
const first = ddecompose(val, '');
|
|
27
|
-
first.sort(sorter ?? sortMap(DELIMITER));
|
|
28
|
-
const regex = new RegExp(DELIMITER, 'g');
|
|
29
|
-
const output = first.map(value => value.replace(regex, '.'));
|
|
30
|
-
|
|
31
|
-
return Object.freeze(output) as StateMatching<T>[];
|
|
32
|
-
}
|
package/src/index.ts
DELETED
package/src/sortMap.ts
DELETED
|
@@ -1,12 +0,0 @@
|
|
|
1
|
-
import { DELIMITER } from './constants/strings';
|
|
2
|
-
|
|
3
|
-
export function sortMap(
|
|
4
|
-
delimiter: string = DELIMITER,
|
|
5
|
-
): ((a: string, b: string) => number) | undefined {
|
|
6
|
-
return (a, b) => {
|
|
7
|
-
return (
|
|
8
|
-
a.split(delimiter).length - b.split(delimiter).length ||
|
|
9
|
-
a.localeCompare(b)
|
|
10
|
-
);
|
|
11
|
-
};
|
|
12
|
-
}
|
package/src/types.ts
DELETED
|
@@ -1,51 +0,0 @@
|
|
|
1
|
-
import { EventFrom, Interpreter } from 'xstate';
|
|
2
|
-
|
|
3
|
-
export type StateMatching<
|
|
4
|
-
T extends Record<string, unknown> | string,
|
|
5
|
-
Key = keyof T,
|
|
6
|
-
> = T extends Record<string, unknown>
|
|
7
|
-
? Key extends string
|
|
8
|
-
? T[Key] extends Record<string, unknown>
|
|
9
|
-
? `${Key}.${StateMatching<T[Key]>}` | (Key & string)
|
|
10
|
-
: `${Key}.${T[Key] & string}` | (Key & string)
|
|
11
|
-
: never
|
|
12
|
-
: T;
|
|
13
|
-
|
|
14
|
-
export type LengthOf<T> = T extends ReadonlyArray<unknown>
|
|
15
|
-
? T['length']
|
|
16
|
-
: number;
|
|
17
|
-
|
|
18
|
-
export type DecomposeOptions = {
|
|
19
|
-
delimiter?: string;
|
|
20
|
-
sorter?: (a: string, b: string) => number;
|
|
21
|
-
};
|
|
22
|
-
|
|
23
|
-
type _UnionToIntersection<U> = (
|
|
24
|
-
U extends unknown ? (k: U) => void : never
|
|
25
|
-
) extends (k: infer I) => void
|
|
26
|
-
? I
|
|
27
|
-
: never;
|
|
28
|
-
|
|
29
|
-
type _LastOf<T> = _UnionToIntersection<
|
|
30
|
-
T extends unknown ? () => T : never
|
|
31
|
-
> extends () => infer R
|
|
32
|
-
? R
|
|
33
|
-
: never;
|
|
34
|
-
|
|
35
|
-
type _Push<T extends unknown[], V> = [...T, V];
|
|
36
|
-
|
|
37
|
-
type _TuplifyUnionBoolean<T> = [T] extends [never] ? true : false;
|
|
38
|
-
|
|
39
|
-
// TS4.1+
|
|
40
|
-
export type TuplifyUnion<T> = true extends _TuplifyUnionBoolean<T>
|
|
41
|
-
? []
|
|
42
|
-
: _Push<TuplifyUnion<Exclude<T, _LastOf<T>>>, _LastOf<T>>;
|
|
43
|
-
|
|
44
|
-
// #endregion
|
|
45
|
-
|
|
46
|
-
export type OmitEvent<
|
|
47
|
-
T extends Interpreter<never, never, never, never, never>,
|
|
48
|
-
K extends EventFrom<T>['type'],
|
|
49
|
-
> = LengthOf<TuplifyUnion<keyof EventFrom<T, K>>> extends 1
|
|
50
|
-
? () => unknown
|
|
51
|
-
: (data: Omit<EventFrom<T>, 'type'>) => unknown;
|