@avstantso/utils-names-tree 1.1.0 → 1.2.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/CHANGELOG.md CHANGED
@@ -1,5 +1,12 @@
1
1
  # Changelog
2
2
 
3
+
4
+ ## [1.2.1] - 2026-01-18
5
+
6
+ ### Changed
7
+
8
+ - Fix publishing
9
+
3
10
  All notable changes to this project will be documented in this file.
4
11
 
5
12
  ## [1.1.0] - 2026-01-18
@@ -0,0 +1,218 @@
1
+ declare namespace AVStantso {
2
+ const BaseKinds: {
3
+ name: Kinds.Method;
4
+ path: Kinds.Method;
5
+ url: Kinds.Method;
6
+ i18n: Kinds.Method;
7
+ domain: Kinds.Method;
8
+ };
9
+ export namespace NamesTree {
10
+ export namespace Kinds {
11
+ type Method = (path: string[], options?: Options) => string;
12
+ /**
13
+ * @summary List of all allow tree kinds
14
+ */
15
+ type All = TS.Union.ToTuple<keyof Kinds>;
16
+ }
17
+ type BaseKinds = typeof BaseKinds;
18
+ export interface Kinds extends BaseKinds {
19
+ }
20
+ /**
21
+ * @summary Allow tree kind
22
+ */
23
+ export type Kind = Kinds.All[number];
24
+ /**
25
+ * @summary Tree node data source
26
+ */
27
+ export type Source = Source.Root | string;
28
+ export namespace Source {
29
+ /**
30
+ * @summary Tree root node data source
31
+ */
32
+ type Root = object | Function;
33
+ }
34
+ type _NodeKinds<KDs extends readonly Kind[], R = unknown> = KDs extends readonly [infer C extends Kind, ...infer Rest extends readonly Kind[]] ? _NodeKinds<Rest, R & {
35
+ [K in `_${C}`]: string;
36
+ }> : {
37
+ [K in keyof R]: R[K];
38
+ };
39
+ /**
40
+ * @summary Tree node for source `T` with allow kinds `KDs`
41
+ *
42
+ * If `S = true`, allows tails nodes as string
43
+ */
44
+ export type Node<T extends Source = Source, KDs extends readonly Kind[] = Kinds.All, S extends boolean = false> = (S extends true ? unknown : _NodeKinds<KDs>) & Node.Data<T, KDs, S>;
45
+ export namespace Node {
46
+ /**
47
+ * @summary Tree node data part for source `T` with allow kinds `KDs`
48
+ *
49
+ * If `S = true`, allows tails nodes as string
50
+ */
51
+ type Data<T extends Source = Source, KDs extends readonly Kind[] = Kinds.All, S extends boolean = false> = T extends Source.Root ? (T extends Function ? T : unknown) & {
52
+ [K in keyof T]: Node<Extract<T[K], Source>, KDs, S>;
53
+ } : S extends true ? T : unknown;
54
+ }
55
+ /**
56
+ * @summary Tree options
57
+ */
58
+ export interface Options {
59
+ prefix?: string;
60
+ }
61
+ /**
62
+ * @summary `NamesTree` kinds presets
63
+ */
64
+ export namespace Presets {
65
+ /**
66
+ * @summary `Names` preset
67
+ */
68
+ namespace Names {
69
+ /**
70
+ * @summary `Names` preset kinds
71
+ */
72
+ type Kinds = ['name'];
73
+ /**
74
+ * @summary `Names` preset tree node for source `T`
75
+ *
76
+ * If `S = true`, allows tails nodes as string
77
+ */
78
+ type Node<T extends Source = Source, S extends boolean = false> = NamesTree.Node<T, Kinds, S>;
79
+ /**
80
+ * @summary `Names` preset `NamesTree` for data `T`
81
+ *
82
+ * If `S = true`, allows tails nodes as string
83
+ */
84
+ type Tree<T extends NamesTree.Source.Root, S extends boolean = false> = AVStantso.NamesTree<T, Kinds, S>;
85
+ }
86
+ /**
87
+ * @summary `I18ns` preset
88
+ */
89
+ namespace I18ns {
90
+ /**
91
+ * @summary `I18ns` preset kinds
92
+ */
93
+ type Kinds = ['i18n', 'name'];
94
+ /**
95
+ * @summary `I18ns` preset tree node for source `T`
96
+ *
97
+ * If `S = true`, allows tails nodes as string
98
+ */
99
+ type Node<T extends Source = Source, S extends boolean = false> = NamesTree.Node<T, Kinds, S>;
100
+ /**
101
+ * @summary `I18ns` preset `NamesTree` for data `T`
102
+ *
103
+ * If `S = true`, allows tails nodes as string
104
+ */
105
+ type Tree<T extends NamesTree.Source.Root, S extends boolean = false> = AVStantso.NamesTree<T, Kinds, S>;
106
+ }
107
+ /**
108
+ * @summary `Urls` preset
109
+ */
110
+ namespace Urls {
111
+ /**
112
+ * @summary `Urls` preset kinds
113
+ */
114
+ type Kinds = ['name', 'path', 'url'];
115
+ /**
116
+ * @summary `Urls` preset tree node for source `T`
117
+ *
118
+ * If `S = true`, allows tails nodes as string
119
+ */
120
+ type Node<T extends Source = Source, S extends boolean = false> = NamesTree.Node<T, Kinds, S>;
121
+ /**
122
+ * @summary `Urls` preset `NamesTree` for data `T`
123
+ *
124
+ * If `S = true`, allows tails nodes as string
125
+ */
126
+ type Tree<T extends NamesTree.Source.Root, S extends boolean = false> = AVStantso.NamesTree<T, Kinds, S>;
127
+ }
128
+ }
129
+ export {};
130
+ }
131
+ namespace _NamesTree {
132
+ type _Splitted<T extends NamesTree.Source.Root, KDs extends readonly NamesTree.Kind[], R extends TS.Arr = []> = KDs extends readonly [
133
+ infer C extends NamesTree.Kind,
134
+ ...infer Rest extends readonly NamesTree.Kind[]
135
+ ] ? _Splitted<T, Rest, [
136
+ ...R,
137
+ NamesTree<T, [C], true>
138
+ ]> : R;
139
+ export type Splitted<T extends NamesTree.Source.Root, KDs extends readonly NamesTree.Kind[]> = _Splitted<T, KDs>;
140
+ export type ExtractByKinds<T extends NamesTree.Source.Root, KDs extends readonly NamesTree.Kind[], R = unknown> = KDs extends readonly [
141
+ infer C extends NamesTree.Kind,
142
+ ...infer Rest extends readonly NamesTree.Kind[]
143
+ ] ? ExtractByKinds<T, Rest, R & {
144
+ [K in Capitalize<C>]: NamesTree<T, [C], true>;
145
+ }> : R;
146
+ export {};
147
+ }
148
+ /**
149
+ * @summary Names tree for data `T` with allow kinds `KDs`
150
+ *
151
+ * If `S = true`, allows tails nodes as string
152
+ */
153
+ export type NamesTree<T extends NamesTree.Source.Root, KDs extends readonly NamesTree.Kind[], S extends boolean = false> = NamesTree.Node.Data<T, KDs, S> & (S extends true ? {} : {
154
+ /**
155
+ * @summary Get array of splitted trees each with unique kind
156
+ */
157
+ splitted: _NamesTree.Splitted<T, KDs>;
158
+ /**
159
+ * @summary Modify existing tree by additional data
160
+ */
161
+ merge<M extends NamesTree.Source.Root>(data: M): NamesTree<T & M, KDs, S>;
162
+ } & _NamesTree.ExtractByKinds<T, KDs>);
163
+ export namespace Code {
164
+ /**
165
+ * @summary `AVStantso.NamesTree` utility
166
+ */
167
+ interface NamesTree {
168
+ <T extends AVStantso.NamesTree.Source.Root, K0 extends AVStantso.NamesTree.Kind, K1 extends Exclude<AVStantso.NamesTree.Kind, K0> = undefined, K2 extends Exclude<AVStantso.NamesTree.Kind, K0 | K1> = undefined, K3 extends Exclude<AVStantso.NamesTree.Kind, K0 | K1 | K2> = undefined, K4 extends Exclude<AVStantso.NamesTree.Kind, K0 | K1 | K2 | K3> = undefined, K5 extends Exclude<AVStantso.NamesTree.Kind, K0 | K1 | K2 | K3 | K4> = undefined, K6 extends Exclude<AVStantso.NamesTree.Kind, K0 | K1 | K2 | K3 | K4 | K5> = undefined, K7 extends Exclude<AVStantso.NamesTree.Kind, K0 | K1 | K2 | K3 | K4 | K5 | K6> = undefined, K8 extends Exclude<AVStantso.NamesTree.Kind, K0 | K1 | K2 | K3 | K4 | K5 | K6 | K7> = undefined, K9 extends Exclude<AVStantso.NamesTree.Kind, K0 | K1 | K2 | K3 | K4 | K5 | K6 | K7 | K8> = undefined>(data: T, options: AVStantso.NamesTree.Options, kind0: K0, kind1?: K1, kind2?: K2, kind3?: K3, kind4?: K4, kind5?: K5, kind6?: K6, kind7?: K7, kind8?: K8, kind9?: K9): AVStantso.NamesTree<T, AVStantso.TS.Array.FilterUnique<[
169
+ K0,
170
+ K1,
171
+ K2,
172
+ K3,
173
+ K4,
174
+ K5,
175
+ K6,
176
+ K7,
177
+ K8,
178
+ K9
179
+ ]>>;
180
+ <T extends AVStantso.NamesTree.Source.Root, K0 extends AVStantso.NamesTree.Kind, K1 extends Exclude<AVStantso.NamesTree.Kind, K0> = undefined, K2 extends Exclude<AVStantso.NamesTree.Kind, K0 | K1> = undefined, K3 extends Exclude<AVStantso.NamesTree.Kind, K0 | K1 | K2> = undefined, K4 extends Exclude<AVStantso.NamesTree.Kind, K0 | K1 | K2 | K3> = undefined, K5 extends Exclude<AVStantso.NamesTree.Kind, K0 | K1 | K2 | K3 | K4> = undefined, K6 extends Exclude<AVStantso.NamesTree.Kind, K0 | K1 | K2 | K3 | K4 | K5> = undefined, K7 extends Exclude<AVStantso.NamesTree.Kind, K0 | K1 | K2 | K3 | K4 | K5 | K6> = undefined, K8 extends Exclude<AVStantso.NamesTree.Kind, K0 | K1 | K2 | K3 | K4 | K5 | K6 | K7> = undefined, K9 extends Exclude<AVStantso.NamesTree.Kind, K0 | K1 | K2 | K3 | K4 | K5 | K6 | K7 | K8> = undefined>(data: T, kind0: K0, kind1?: K1, kind2?: K2, kind3?: K3, kind4?: K4, kind5?: K5, kind6?: K6, kind7?: K7, kind8?: K8, kind9?: K9): AVStantso.NamesTree<T, AVStantso.TS.Array.FilterUnique<[
181
+ K0,
182
+ K1,
183
+ K2,
184
+ K3,
185
+ K4,
186
+ K5,
187
+ K6,
188
+ K7,
189
+ K8,
190
+ K9
191
+ ]>>;
192
+ /**
193
+ * @summary Register external `NamesTree` kinds
194
+ */
195
+ _RegKinds(kinds: NodeJS.Dict<AVStantso.NamesTree.Kinds.Method>): void;
196
+ /**
197
+ * @summary Make `Name` `NamesTree`
198
+ */
199
+ Names<T extends AVStantso.NamesTree.Source.Root>(data: T, options?: AVStantso.NamesTree.Options): AVStantso.NamesTree.Presets.Names.Tree<T>;
200
+ /**
201
+ * @summary Make `i18n` `NamesTree`
202
+ */
203
+ I18ns<T extends AVStantso.NamesTree.Source.Root>(data: T, options?: AVStantso.NamesTree.Options): AVStantso.NamesTree.Presets.I18ns.Tree<T>;
204
+ /**
205
+ * @summary Make `urls` `NamesTree`
206
+ */
207
+ Urls<T extends AVStantso.NamesTree.Source.Root>(data: T, options?: AVStantso.NamesTree.Options): AVStantso.NamesTree.Presets.Urls.Tree<T>;
208
+ }
209
+ }
210
+ export interface Code {
211
+ /**
212
+ * @summary `AVStantso.NamesTree` utility
213
+ */
214
+ NamesTree: Code.NamesTree;
215
+ }
216
+ export const NamesTree: Code.NamesTree;
217
+ export {};
218
+ }
@@ -0,0 +1 @@
1
+ import './_register';
@@ -0,0 +1,2 @@
1
+ import NamesTree = AVStantso.NamesTree;
2
+ export { NamesTree };
@@ -0,0 +1,4 @@
1
+ import '@avstantso/errors';
2
+ import '@avstantso/js';
3
+ import './_global';
4
+ export * from './export';
package/dist/index.js ADDED
@@ -0,0 +1,112 @@
1
+ 'use strict';
2
+
3
+ require('@avstantso/errors');
4
+ require('@avstantso/js');
5
+
6
+ var AVStantso$1;
7
+ (function (AVStantso) {
8
+ const BaseKinds = (() => {
9
+ const name = (path) => path.peek();
10
+ const path = (path) => path.join('/');
11
+ const url = (path) => `/${path.join('/')}`;
12
+ const dot = (path) => path.join('.');
13
+ return { name, path, url, i18n: dot, domain: dot };
14
+ })();
15
+ AVStantso.NamesTree = avstantso._reg.NamesTree(({ JS }) => {
16
+ const kindsMethods = {
17
+ ...BaseKinds
18
+ };
19
+ const _RegKinds = (kinds) => Object.assign(kindsMethods, kinds);
20
+ function PathMethods(path, options) {
21
+ const { prefix = '' } = options || {};
22
+ return Object.entries(kindsMethods).reduce((r, [k, v]) => Object.assign(r, { [k]: () => `${prefix}${v(path, options)}` }), {});
23
+ }
24
+ function NodeData(context) {
25
+ const { strTail, kinds, options, dest, data, path = [] } = context;
26
+ if (!JS.is.string(data)) {
27
+ Object.entries(data)
28
+ .filter(([k]) => 'toString' !== k)
29
+ .forEach(([k, v]) => {
30
+ const oldDs = dest[k];
31
+ const fds = JS.is.function(oldDs);
32
+ const fv = JS.is.function(v);
33
+ if (fds && fv) {
34
+ console.warn('%O', { oldDs, v, fds, fv, data });
35
+ throw Error(`Can't merge NamesTrees functions nodes at "${path.join('.')}"`);
36
+ }
37
+ const needReMake = oldDs && !fds && fv;
38
+ const subPath = [...path, k];
39
+ const methods = PathMethods(subPath, options);
40
+ const ds = oldDs && !needReMake
41
+ ? oldDs
42
+ : fv
43
+ ? (...args) => v(...args)
44
+ : strTail && JS.is.string(v)
45
+ ? methods[kinds[0]]()
46
+ : {};
47
+ if (needReMake)
48
+ Object.assign(ds, oldDs);
49
+ if (!JS.is.string(ds)) {
50
+ ds.toString = methods[kinds[0]];
51
+ if (!strTail)
52
+ Object.entries(methods).forEach(([m, get]) => {
53
+ const p = `_${m}`;
54
+ if (p in ds)
55
+ delete ds[p];
56
+ Object.defineProperty(ds, p, { get });
57
+ });
58
+ }
59
+ NodeData({ ...context, dest: ds, data: v, path: subPath });
60
+ Object.assign(dest, { [k]: ds });
61
+ });
62
+ }
63
+ return dest;
64
+ }
65
+ function MakeTree(data, strTail, options, ...kinds) {
66
+ /* eslint-disable @typescript-eslint/no-explicit-any */
67
+ let subs = {};
68
+ function getSub(kind) {
69
+ if (!subs[kind])
70
+ subs[kind] = MakeTree(data, true, options, kind);
71
+ return subs[kind];
72
+ }
73
+ const tree = {};
74
+ if (!strTail) {
75
+ Object.defineProperties(tree, {
76
+ splitted: { get: () => kinds.map(getSub) },
77
+ merge: {
78
+ value: (addData) => {
79
+ NodeData({ strTail, kinds, options, dest: tree, data: addData });
80
+ subs = {};
81
+ return tree;
82
+ },
83
+ writable: false
84
+ }
85
+ });
86
+ kinds.forEach((kind) => Object.defineProperty(tree, kind.toCapitalized(), {
87
+ get: () => getSub(kind)
88
+ }));
89
+ }
90
+ NodeData({ strTail, kinds, options, dest: tree, data });
91
+ return tree;
92
+ }
93
+ function NamesTree(data, ...params) {
94
+ const options = !JS.is.string(params[0]) ? params.shift() : undefined;
95
+ return MakeTree(data, false, options, ...params);
96
+ }
97
+ function MakePreset(...params) {
98
+ return (data, options) => NamesTree(data, options, ...params);
99
+ }
100
+ return Object.assign(NamesTree, {
101
+ _RegKinds,
102
+ Names: MakePreset('name'),
103
+ I18ns: MakePreset('i18n', 'name'),
104
+ Urls: MakePreset('name', 'path', 'url')
105
+ });
106
+ });
107
+ })(AVStantso$1 || (AVStantso$1 = {}));
108
+
109
+ var NamesTree = AVStantso.NamesTree;
110
+
111
+ exports.NamesTree = NamesTree;
112
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.js","sources":["../src/_global/_register.ts","../src/export.ts"],"sourcesContent":["namespace AVStantso {\n const BaseKinds = (() => {\n type M = NamesTree.Kinds.Method;\n\n const name: M = (path) => path.peek();\n const path: M = (path) => path.join('/');\n const url: M = (path) => `/${path.join('/')}`;\n const dot: M = (path) => path.join('.');\n\n return { name, path, url, i18n: dot, domain: dot };\n })();\n\n export namespace NamesTree {\n export namespace Kinds {\n export type Method = (path: string[], options?: Options) => string;\n\n /**\n * @summary List of all allow tree kinds\n */\n export type All = TS.Union.ToTuple<keyof Kinds>;\n }\n\n type BaseKinds = typeof BaseKinds;\n\n // eslint-disable-next-line @typescript-eslint/no-empty-object-type\n export interface Kinds extends BaseKinds {}\n\n /**\n * @summary Allow tree kind\n */\n export type Kind = Kinds.All[number];\n\n //#region Source\n /**\n * @summary Tree node data source\n */\n export type Source = Source.Root | string;\n\n export namespace Source {\n /**\n * @summary Tree root node data source\n */\n // eslint-disable-next-line @typescript-eslint/no-unsafe-function-type\n export type Root = object | Function;\n }\n //#endregion\n\n //#region Node\n type _NodeKinds<\n KDs extends readonly Kind[],\n R = unknown\n > = KDs extends readonly [infer C extends Kind, ...infer Rest extends readonly Kind[]]\n ? _NodeKinds<Rest, R & { [K in `_${C}`]: string }>\n : { [K in keyof R]: R[K] };\n\n /**\n * @summary Tree node for source `T` with allow kinds `KDs`\n *\n * If `S = true`, allows tails nodes as string\n */\n export type Node<\n T extends Source = Source,\n KDs extends readonly Kind[] = Kinds.All,\n S extends boolean = false\n > = (S extends true ? unknown : _NodeKinds<KDs>) & Node.Data<T, KDs, S>;\n\n export namespace Node {\n /**\n * @summary Tree node data part for source `T` with allow kinds `KDs`\n *\n * If `S = true`, allows tails nodes as string\n */\n export type Data<\n T extends Source = Source,\n KDs extends readonly Kind[] = Kinds.All,\n S extends boolean = false\n > = T extends Source.Root\n // eslint-disable-next-line @typescript-eslint/no-unsafe-function-type\n ? (T extends Function ? T : unknown) & {\n [K in keyof T]: Node<Extract<T[K], Source>, KDs, S>;\n }\n : S extends true\n ? T\n : unknown;\n }\n //#endregion\n\n /**\n * @summary Tree options\n */\n export interface Options {\n prefix?: string;\n }\n\n /**\n * @summary `NamesTree` kinds presets\n */\n export namespace Presets {\n /**\n * @summary `Names` preset\n */\n export namespace Names {\n /**\n * @summary `Names` preset kinds\n */\n export type Kinds = ['name'];\n\n /**\n * @summary `Names` preset tree node for source `T`\n *\n * If `S = true`, allows tails nodes as string\n */\n export type Node<\n T extends Source = Source,\n S extends boolean = false\n > = NamesTree.Node<T, Kinds, S>;\n\n /**\n * @summary `Names` preset `NamesTree` for data `T`\n *\n * If `S = true`, allows tails nodes as string\n */\n export type Tree<\n T extends NamesTree.Source.Root,\n S extends boolean = false\n > = AVStantso.NamesTree<T, Kinds, S>;\n }\n\n /**\n * @summary `I18ns` preset\n */\n export namespace I18ns {\n /**\n * @summary `I18ns` preset kinds\n */\n export type Kinds = ['i18n', 'name'];\n\n /**\n * @summary `I18ns` preset tree node for source `T`\n *\n * If `S = true`, allows tails nodes as string\n */\n export type Node<\n T extends Source = Source,\n S extends boolean = false\n > = NamesTree.Node<T, Kinds, S>;\n\n /**\n * @summary `I18ns` preset `NamesTree` for data `T`\n *\n * If `S = true`, allows tails nodes as string\n */\n export type Tree<\n T extends NamesTree.Source.Root,\n S extends boolean = false\n > = AVStantso.NamesTree<T, Kinds, S>;\n }\n\n /**\n * @summary `Urls` preset\n */\n export namespace Urls {\n /**\n * @summary `Urls` preset kinds\n */\n export type Kinds = ['name', 'path', 'url'];\n\n /**\n * @summary `Urls` preset tree node for source `T`\n *\n * If `S = true`, allows tails nodes as string\n */\n export type Node<\n T extends Source = Source,\n S extends boolean = false\n > = NamesTree.Node<T, Kinds, S>;\n\n /**\n * @summary `Urls` preset `NamesTree` for data `T`\n *\n * If `S = true`, allows tails nodes as string\n */\n export type Tree<\n T extends NamesTree.Source.Root,\n S extends boolean = false\n > = AVStantso.NamesTree<T, Kinds, S>;\n }\n }\n }\n\n namespace _NamesTree {\n //#region Splitted\n type _Splitted<\n T extends NamesTree.Source.Root,\n KDs extends readonly NamesTree.Kind[],\n R extends TS.Arr = []\n > = KDs extends readonly [\n infer C extends NamesTree.Kind,\n ...infer Rest extends readonly NamesTree.Kind[]\n ]\n ? _Splitted<\n T,\n Rest,\n [...R, NamesTree<T, [C], true>]\n >\n : R;\n\n export type Splitted<\n T extends NamesTree.Source.Root,\n KDs extends readonly NamesTree.Kind[]\n > = _Splitted<T, KDs>;\n //#endregion\n\n export type ExtractByKinds<\n T extends NamesTree.Source.Root,\n KDs extends readonly NamesTree.Kind[],\n R = unknown\n > = KDs extends readonly [\n infer C extends NamesTree.Kind,\n ...infer Rest extends readonly NamesTree.Kind[]\n ]\n ? ExtractByKinds<\n T,\n Rest,\n R & { [K in Capitalize<C>]: NamesTree<T, [C], true> }\n >\n : R;\n }\n\n /**\n * @summary Names tree for data `T` with allow kinds `KDs`\n *\n * If `S = true`, allows tails nodes as string\n */\n export type NamesTree<\n T extends NamesTree.Source.Root,\n KDs extends readonly NamesTree.Kind[],\n S extends boolean = false\n > = NamesTree.Node.Data<T, KDs, S>\n & (S extends true\n // eslint-disable-next-line @typescript-eslint/no-empty-object-type\n ? {}\n : {\n /**\n * @summary Get array of splitted trees each with unique kind\n */\n splitted: _NamesTree.Splitted<T, KDs>;\n\n /**\n * @summary Modify existing tree by additional data\n */\n merge<M extends NamesTree.Source.Root>(\n data: M\n ): NamesTree<T & M, KDs, S>;\n } & _NamesTree.ExtractByKinds<T, KDs>);\n\n export namespace Code {\n /**\n * @summary `AVStantso.NamesTree` utility\n */\n export interface NamesTree {\n <\n T extends AVStantso.NamesTree.Source.Root,\n K0 extends AVStantso.NamesTree.Kind,\n K1 extends Exclude<AVStantso.NamesTree.Kind, K0> = undefined,\n K2 extends Exclude<AVStantso.NamesTree.Kind, K0 | K1> = undefined,\n K3 extends Exclude<AVStantso.NamesTree.Kind, K0 | K1 | K2> = undefined,\n K4 extends Exclude<\n AVStantso.NamesTree.Kind,\n K0 | K1 | K2 | K3\n > = undefined,\n K5 extends Exclude<\n AVStantso.NamesTree.Kind,\n K0 | K1 | K2 | K3 | K4\n > = undefined,\n K6 extends Exclude<\n AVStantso.NamesTree.Kind,\n K0 | K1 | K2 | K3 | K4 | K5\n > = undefined,\n K7 extends Exclude<\n AVStantso.NamesTree.Kind,\n K0 | K1 | K2 | K3 | K4 | K5 | K6\n > = undefined,\n K8 extends Exclude<\n AVStantso.NamesTree.Kind,\n K0 | K1 | K2 | K3 | K4 | K5 | K6 | K7\n > = undefined,\n K9 extends Exclude<\n AVStantso.NamesTree.Kind,\n K0 | K1 | K2 | K3 | K4 | K5 | K6 | K7 | K8\n > = undefined\n >(\n data: T,\n options: AVStantso.NamesTree.Options,\n kind0: K0,\n kind1?: K1,\n kind2?: K2,\n kind3?: K3,\n kind4?: K4,\n kind5?: K5,\n kind6?: K6,\n kind7?: K7,\n kind8?: K8,\n kind9?: K9\n ): AVStantso.NamesTree<\n T,\n AVStantso.TS.Array.FilterUnique<\n [K0, K1, K2, K3, K4, K5, K6, K7, K8, K9]\n >\n >;\n\n <\n T extends AVStantso.NamesTree.Source.Root,\n K0 extends AVStantso.NamesTree.Kind,\n K1 extends Exclude<AVStantso.NamesTree.Kind, K0> = undefined,\n K2 extends Exclude<AVStantso.NamesTree.Kind, K0 | K1> = undefined,\n K3 extends Exclude<AVStantso.NamesTree.Kind, K0 | K1 | K2> = undefined,\n K4 extends Exclude<\n AVStantso.NamesTree.Kind,\n K0 | K1 | K2 | K3\n > = undefined,\n K5 extends Exclude<\n AVStantso.NamesTree.Kind,\n K0 | K1 | K2 | K3 | K4\n > = undefined,\n K6 extends Exclude<\n AVStantso.NamesTree.Kind,\n K0 | K1 | K2 | K3 | K4 | K5\n > = undefined,\n K7 extends Exclude<\n AVStantso.NamesTree.Kind,\n K0 | K1 | K2 | K3 | K4 | K5 | K6\n > = undefined,\n K8 extends Exclude<\n AVStantso.NamesTree.Kind,\n K0 | K1 | K2 | K3 | K4 | K5 | K6 | K7\n > = undefined,\n K9 extends Exclude<\n AVStantso.NamesTree.Kind,\n K0 | K1 | K2 | K3 | K4 | K5 | K6 | K7 | K8\n > = undefined\n >(\n data: T,\n kind0: K0,\n kind1?: K1,\n kind2?: K2,\n kind3?: K3,\n kind4?: K4,\n kind5?: K5,\n kind6?: K6,\n kind7?: K7,\n kind8?: K8,\n kind9?: K9\n ): AVStantso.NamesTree<\n T,\n AVStantso.TS.Array.FilterUnique<\n [K0, K1, K2, K3, K4, K5, K6, K7, K8, K9]\n >\n >;\n\n /**\n * @summary Register external `NamesTree` kinds\n */\n _RegKinds(kinds: NodeJS.Dict<AVStantso.NamesTree.Kinds.Method>): void;\n\n /**\n * @summary Make `Name` `NamesTree`\n */\n Names<T extends AVStantso.NamesTree.Source.Root>(\n data: T,\n options?: AVStantso.NamesTree.Options\n ): AVStantso.NamesTree.Presets.Names.Tree<T>;\n\n /**\n * @summary Make `i18n` `NamesTree`\n */\n I18ns<T extends AVStantso.NamesTree.Source.Root>(\n data: T,\n options?: AVStantso.NamesTree.Options\n ): AVStantso.NamesTree.Presets.I18ns.Tree<T>;\n\n /**\n * @summary Make `urls` `NamesTree`\n */\n Urls<T extends AVStantso.NamesTree.Source.Root>(\n data: T,\n options?: AVStantso.NamesTree.Options\n ): AVStantso.NamesTree.Presets.Urls.Tree<T>;\n }\n }\n\n export interface Code {\n /**\n * @summary `AVStantso.NamesTree` utility\n */\n NamesTree: Code.NamesTree;\n }\n\n export const NamesTree = avstantso._reg.NamesTree(({ JS }) => {\n const kindsMethods: NodeJS.Dict<AVStantso.NamesTree.Kinds.Method> = {\n ...BaseKinds\n };\n\n const _RegKinds: Code.NamesTree['_RegKinds'] = (kinds) =>\n Object.assign(kindsMethods, kinds);\n\n type PathMethods = Record<NamesTree.Kind, () => string>;\n function PathMethods(\n path: string[],\n options?: NamesTree.Options\n ): PathMethods {\n const { prefix = '' } = options || {};\n\n return Object.entries(kindsMethods).reduce(\n (r, [k, v]) => Object.assign(r, { [k]: () => `${prefix}${v(path, options)}` }),\n {} as PathMethods\n );\n }\n\n type NDContext = {\n strTail: boolean;\n kinds: NamesTree.Kind[];\n options: NamesTree.Options;\n\n dest: NamesTree.Node.Data;\n data: NamesTree.Source;\n path?: string[];\n };\n function NodeData(context: NDContext): NamesTree.Node.Data {\n const { strTail, kinds, options, dest, data, path = [] } = context;\n\n if (!JS.is.string(data)) {\n Object.entries(data)\n .filter(([k]) => 'toString' !== k)\n .forEach(([k, v]) => {\n const oldDs = dest[k as keyof typeof dest];\n\n const fds = JS.is.function(oldDs);\n const fv = JS.is.function(v);\n\n if (fds && fv) {\n console.warn('%O', { oldDs, v, fds, fv, data });\n\n throw Error(\n `Can't merge NamesTrees functions nodes at \"${path.join('.')}\"`\n );\n }\n\n const needReMake = oldDs && !fds && fv;\n\n const subPath = [...path, k];\n\n const methods = PathMethods(subPath, options);\n\n const ds =\n oldDs && !needReMake\n ? oldDs\n : fv\n ? (...args: TS.Arr) => v(...args)\n : strTail && JS.is.string(v)\n ? methods[kinds[0]]()\n : {};\n\n if (needReMake) Object.assign(ds, oldDs);\n\n if (!JS.is.string(ds)) {\n ds.toString = methods[kinds[0]];\n\n if (!strTail)\n Object.entries(methods).forEach(([m, get]) => {\n const p = `_${m}`;\n if (p in ds) delete ds[p as keyof typeof ds];\n\n Object.defineProperty(ds, p, { get });\n });\n }\n\n NodeData({ ...context, dest: ds, data: v, path: subPath });\n\n Object.assign(dest, { [k]: ds });\n });\n }\n\n return dest;\n }\n\n function MakeTree(\n data: NamesTree.Source.Root,\n strTail: boolean,\n options: NamesTree.Options,\n ...kinds: NamesTree.Kind[]\n ) {\n /* eslint-disable @typescript-eslint/no-explicit-any */\n\n let subs: any = {};\n function getSub(kind: NamesTree.Kind) {\n if (!subs[kind]) subs[kind] = MakeTree(data, true, options, kind);\n\n return subs[kind];\n }\n\n const tree: any = {};\n\n if (!strTail) {\n Object.defineProperties(tree, {\n splitted: { get: () => kinds.map(getSub) },\n\n merge: {\n value: (addData: NamesTree.Source.Root) => {\n NodeData({ strTail, kinds, options, dest: tree, data: addData });\n subs = {};\n return tree;\n },\n writable: false\n }\n });\n\n kinds.forEach((kind) =>\n Object.defineProperty(tree, kind.toCapitalized(), {\n get: () => getSub(kind)\n })\n );\n }\n\n NodeData({ strTail, kinds, options, dest: tree, data });\n\n return tree;\n }\n\n function NamesTree(data: NamesTree.Source.Root, ...params: TS.Arr) {\n const options = !JS.is.string(params[0]) ? params.shift() : undefined;\n\n return MakeTree(data, false, options, ...params);\n }\n\n function MakePreset(...params: string[]) {\n return (\n data: NamesTree.Source.Root,\n options: NamesTree.Options\n ) => NamesTree(data, options, ...params);\n }\n\n return Object.assign(\n NamesTree,\n {\n _RegKinds,\n Names: MakePreset('name'),\n I18ns: MakePreset('i18n', 'name'),\n Urls: MakePreset('name', 'path', 'url')\n }\n );\n });\n}\n","import NamesTree = AVStantso.NamesTree;\n\nexport {\n NamesTree\n};\n"],"names":["AVStantso"],"mappings":";;;;;AAAA,IAAUA,WAAS;AAAnB,CAAA,UAAU,SAAS,EAAA;AACjB,IAAA,MAAM,SAAS,GAAG,CAAC,MAAK;QAGtB,MAAM,IAAI,GAAM,CAAC,IAAI,KAAK,IAAI,CAAC,IAAI,EAAE;AACrC,QAAA,MAAM,IAAI,GAAM,CAAC,IAAI,KAAK,IAAI,CAAC,IAAI,CAAC,GAAG,CAAC;AACxC,QAAA,MAAM,GAAG,GAAM,CAAC,IAAI,KAAK,CAAA,CAAA,EAAI,IAAI,CAAC,IAAI,CAAC,GAAG,CAAC,EAAE;AAC7C,QAAA,MAAM,GAAG,GAAM,CAAC,IAAI,KAAK,IAAI,CAAC,IAAI,CAAC,GAAG,CAAC;AAEvC,QAAA,OAAO,EAAE,IAAI,EAAE,IAAI,EAAE,GAAG,EAAE,IAAI,EAAE,G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,GAAA,EAAA,CAAA,CAAA;;ACAnB,IAAO,SAAS,GAAG,SAAS,CAAC;;;;"}
package/package.json CHANGED
@@ -2,7 +2,7 @@
2
2
  "name": "@avstantso/utils-names-tree",
3
3
  "license": "MIT",
4
4
  "author": "avstantso",
5
- "version": "1.1.0",
5
+ "version": "1.2.1",
6
6
  "description": "AVStantso framework utils: NamesTree",
7
7
  "keywords": [
8
8
  "NamesTree"
@@ -23,12 +23,12 @@
23
23
  "test": "NODE_ENV=test jest --coverage"
24
24
  },
25
25
  "dependencies": {
26
- "@avstantso/concepts": "1.1.0",
27
- "@avstantso/core": "1.1.0",
28
- "@avstantso/errors": "1.1.0",
29
- "@avstantso/js": "1.1.0",
30
- "@avstantso/std-ext": "1.1.0",
31
- "@avstantso/ts": "1.1.0"
26
+ "@avstantso/concepts": "1.2.1",
27
+ "@avstantso/core": "1.2.1",
28
+ "@avstantso/errors": "1.2.1",
29
+ "@avstantso/js": "1.2.1",
30
+ "@avstantso/std-ext": "1.2.1",
31
+ "@avstantso/ts": "1.2.1"
32
32
  },
33
33
  "devDependencies": {
34
34
  "@avstantso/dev-basic": "1.0.0"