@voxgig/model 1.1.0 → 1.3.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/lib/util.d.ts +4 -1
- package/dist/lib/util.js +37 -3
- package/dist/lib/util.js.map +1 -1
- package/dist/model.d.ts +2 -2
- package/dist/model.js +4 -1
- package/dist/model.js.map +1 -1
- package/lib/util.ts +47 -2
- package/model.ts +6 -0
- package/package.json +1 -1
package/dist/lib/util.d.ts
CHANGED
|
@@ -1,4 +1,7 @@
|
|
|
1
1
|
type DiveMapper = (path: any[], leaf: any) => any[];
|
|
2
2
|
declare function dive(node: any, depth?: number | DiveMapper, mapper?: DiveMapper): any[];
|
|
3
3
|
declare function joins(arr: any[], ...seps: string[]): string;
|
|
4
|
-
|
|
4
|
+
declare function get(root: any, path: string | string[]): any;
|
|
5
|
+
declare function pinify(path: string[]): string;
|
|
6
|
+
declare function camelify(input: any[] | string): string;
|
|
7
|
+
export { dive, joins, get, pinify, camelify, };
|
package/dist/lib/util.js
CHANGED
|
@@ -1,18 +1,28 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
/* Copyright © 2021-2023 Voxgig Ltd, MIT License. */
|
|
3
3
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
4
|
-
exports.joins = exports.dive = void 0;
|
|
4
|
+
exports.camelify = exports.pinify = exports.get = exports.joins = exports.dive = void 0;
|
|
5
5
|
function dive(node, depth, mapper) {
|
|
6
6
|
let d = (null == depth || 'number' != typeof depth) ? 2 : depth;
|
|
7
7
|
mapper = 'function' === typeof depth ? depth : mapper;
|
|
8
8
|
let items = [];
|
|
9
|
-
Object.entries(node).reduce((items, entry) => {
|
|
9
|
+
Object.entries(node || {}).reduce((items, entry) => {
|
|
10
10
|
let key = entry[0];
|
|
11
11
|
let child = entry[1];
|
|
12
|
-
|
|
12
|
+
// console.log('CHILD', d, key, child)
|
|
13
|
+
if ('$' === key) {
|
|
14
|
+
// console.log('BBB', d)
|
|
15
|
+
items.push([[], child]);
|
|
16
|
+
}
|
|
17
|
+
else if (d <= 1 ||
|
|
18
|
+
null == child ||
|
|
19
|
+
'object' !== typeof child ||
|
|
20
|
+
0 === Object.keys(child).length) {
|
|
21
|
+
// console.log('AAA', d)
|
|
13
22
|
items.push([[key], child]);
|
|
14
23
|
}
|
|
15
24
|
else {
|
|
25
|
+
// console.log('CCC', d)
|
|
16
26
|
let children = dive(child, d - 1);
|
|
17
27
|
children = children.map(child => {
|
|
18
28
|
child[0].unshift(key);
|
|
@@ -22,6 +32,7 @@ function dive(node, depth, mapper) {
|
|
|
22
32
|
}
|
|
23
33
|
return items;
|
|
24
34
|
}, items);
|
|
35
|
+
// console.log('ITEMS', items)
|
|
25
36
|
if (mapper) {
|
|
26
37
|
return items.reduce(((a, entry) => {
|
|
27
38
|
entry = mapper(entry[0], entry[1]);
|
|
@@ -55,4 +66,27 @@ function joins(arr, ...seps) {
|
|
|
55
66
|
return sa.join('');
|
|
56
67
|
}
|
|
57
68
|
exports.joins = joins;
|
|
69
|
+
function get(root, path) {
|
|
70
|
+
path = 'string' === typeof path ? path.split('.') : path;
|
|
71
|
+
let node = root;
|
|
72
|
+
for (let i = 0; i < path.length && null != node; i++) {
|
|
73
|
+
node = node[path[i]];
|
|
74
|
+
}
|
|
75
|
+
return node;
|
|
76
|
+
}
|
|
77
|
+
exports.get = get;
|
|
78
|
+
function pinify(path) {
|
|
79
|
+
let pin = path
|
|
80
|
+
.map((p, i) => p + (i % 2 ? (i === path.length - 1 ? '' : ',') : ':'))
|
|
81
|
+
.join('');
|
|
82
|
+
return pin;
|
|
83
|
+
}
|
|
84
|
+
exports.pinify = pinify;
|
|
85
|
+
function camelify(input) {
|
|
86
|
+
let parts = 'string' == typeof input ? input.split('-') : input.map(n => '' + n);
|
|
87
|
+
return parts
|
|
88
|
+
.map((p) => ('' === p ? '' : (p[0].toUpperCase() + p.substring(1))))
|
|
89
|
+
.join('');
|
|
90
|
+
}
|
|
91
|
+
exports.camelify = camelify;
|
|
58
92
|
//# sourceMappingURL=util.js.map
|
package/dist/lib/util.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"util.js","sourceRoot":"","sources":["../../lib/util.ts"],"names":[],"mappings":";AAAA,oDAAoD;;;AAKpD,SAAS,IAAI,CAAC,IAAS,EAAE,KAA2B,EAAE,MAAmB;IACvE,IAAI,CAAC,GAAG,CAAC,IAAI,IAAI,KAAK,IAAI,QAAQ,IAAI,OAAO,KAAK,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,KAAK,CAAA;IAC/D,MAAM,GAAG,UAAU,KAAK,OAAO,KAAK,CAAC,CAAC,CAAC,KAAK,CAAC,CAAC,CAAC,MAAM,CAAA;IAErD,IAAI,KAAK,GAAU,EAAE,CAAA;IAErB,MAAM,CAAC,OAAO,CAAC,IAAI,CAAC,CAAC,MAAM,
|
|
1
|
+
{"version":3,"file":"util.js","sourceRoot":"","sources":["../../lib/util.ts"],"names":[],"mappings":";AAAA,oDAAoD;;;AAKpD,SAAS,IAAI,CAAC,IAAS,EAAE,KAA2B,EAAE,MAAmB;IACvE,IAAI,CAAC,GAAG,CAAC,IAAI,IAAI,KAAK,IAAI,QAAQ,IAAI,OAAO,KAAK,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,KAAK,CAAA;IAC/D,MAAM,GAAG,UAAU,KAAK,OAAO,KAAK,CAAC,CAAC,CAAC,KAAK,CAAC,CAAC,CAAC,MAAM,CAAA;IAErD,IAAI,KAAK,GAAU,EAAE,CAAA;IAErB,MAAM,CAAC,OAAO,CAAC,IAAI,IAAI,EAAE,CAAC,CAAC,MAAM,CAC/B,CAAC,KAAY,EAAE,KAAY,EAAE,EAAE;QAC7B,IAAI,GAAG,GAAG,KAAK,CAAC,CAAC,CAAC,CAAA;QAClB,IAAI,KAAK,GAAG,KAAK,CAAC,CAAC,CAAC,CAAA;QAEpB,sCAAsC;QAEtC,IAAI,G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AC,CAAC,CAAA;IACtB,CAAC;IACD,OAAO,IAAI,CAAA;AACb,CAAC;AAsBC,kBAAG;AAnBL,SAAS,MAAM,CAAC,IAAc;IAC5B,IAAI,GAAG,GAAG,IAAI;SACX,GAAG,CAAC,CAAC,CAAS,EAAE,CAAS,EAAE,EAAE,CAC5B,CAAC,GAAG,CAAC,CAAC,GAAG,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,KAAK,IAAI,CAAC,MAAM,GAAG,CAAC,CAAC,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC,GAAG,CAAC,CAAC,CAAC,CAAC,GAAG,CAAC,CAAC;SACxD,IAAI,CAAC,EAAE,CAAC,CAAA;IACX,OAAO,GAAG,CAAA;AACZ,CAAC;AAcC,wBAAM;AAXR,SAAS,QAAQ,CAAC,KAAqB;IACrC,IAAI,KAAK,GAAG,QAAQ,IAAI,OAAO,KAAK,CAAC,CAAC,CAAC,KAAK,CAAC,KAAK,CAAC,GAAG,CAAC,CAAC,CAAC,CAAC,KAAK,CAAC,GAAG,CAAC,CAAC,CAAC,EAAE,CAAC,EAAE,GAAG,CAAC,CAAC,CAAA;IAChF,OAAO,KAAK;SACT,GAAG,CAAC,CAAC,CAAS,EAAE,EAAE,CAAC,CAAC,EAAE,KAAK,CAAC,CAAC,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,WAAW,EAAE,GAAG,CAAC,CAAC,SAAS,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC;SAC3E,IAAI,CAAC,EAAE,CAAC,CAAA;AACb,CAAC;AAOC,4BAAQ"}
|
package/dist/model.d.ts
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { Config } from './lib/config';
|
|
2
2
|
import { BuildResult, Spec } from './lib/build';
|
|
3
3
|
import { Watch } from './lib/watch';
|
|
4
|
-
import { dive, joins } from './lib/util';
|
|
4
|
+
import { dive, joins, get, pinify, camelify } from './lib/util';
|
|
5
5
|
declare class Model {
|
|
6
6
|
config: Config;
|
|
7
7
|
build: any;
|
|
@@ -12,4 +12,4 @@ declare class Model {
|
|
|
12
12
|
start(): Promise<void>;
|
|
13
13
|
stop(): Promise<void>;
|
|
14
14
|
}
|
|
15
|
-
export { Model, Spec, dive, joins, };
|
|
15
|
+
export { Model, Spec, dive, joins, get, pinify, camelify, };
|
package/dist/model.js
CHANGED
|
@@ -4,7 +4,7 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
|
4
4
|
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
5
5
|
};
|
|
6
6
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
7
|
-
exports.joins = exports.dive = exports.Model = void 0;
|
|
7
|
+
exports.camelify = exports.pinify = exports.get = exports.joins = exports.dive = exports.Model = void 0;
|
|
8
8
|
// TODO: remove need for this
|
|
9
9
|
const fs_1 = __importDefault(require("fs"));
|
|
10
10
|
const config_1 = require("./lib/config");
|
|
@@ -14,6 +14,9 @@ const local_1 = require("./lib/builder/local");
|
|
|
14
14
|
const util_1 = require("./lib/util");
|
|
15
15
|
Object.defineProperty(exports, "dive", { enumerable: true, get: function () { return util_1.dive; } });
|
|
16
16
|
Object.defineProperty(exports, "joins", { enumerable: true, get: function () { return util_1.joins; } });
|
|
17
|
+
Object.defineProperty(exports, "get", { enumerable: true, get: function () { return util_1.get; } });
|
|
18
|
+
Object.defineProperty(exports, "pinify", { enumerable: true, get: function () { return util_1.pinify; } });
|
|
19
|
+
Object.defineProperty(exports, "camelify", { enumerable: true, get: function () { return util_1.camelify; } });
|
|
17
20
|
const intern = makeIntern();
|
|
18
21
|
class Model {
|
|
19
22
|
constructor(spec) {
|
package/dist/model.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"model.js","sourceRoot":"","sources":["../model.ts"],"names":[],"mappings":";AAAA,oDAAoD;;;;;;AAEpD,6BAA6B;AAC7B,4CAAmB;AAEnB,yCAAqC;AAErC,uC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AAE,KAAK;gBACX,GAAG,EAAE;oBAEH,iDAAiD;oBACjD;wBACE,IAAI,EAAE,GAAG;wBACT,KAAK,EAAE,qBAAa;qBACrB;oBAED,mBAAmB;iBACpB;gBACD,OAAO,EAAE,IAAI,CAAC,OAAO;aACtB,CAAA;YAED,OAAO,IAAI,eAAM,CAAC,KAAK,CAAC,CAAA;QAC1B,CAAC;KACF,CAAA;AACH,CAAC"}
|
package/lib/util.ts
CHANGED
|
@@ -9,15 +9,28 @@ function dive(node: any, depth?: number | DiveMapper, mapper?: DiveMapper): any[
|
|
|
9
9
|
|
|
10
10
|
let items: any[] = []
|
|
11
11
|
|
|
12
|
-
Object.entries(node).reduce(
|
|
12
|
+
Object.entries(node || {}).reduce(
|
|
13
13
|
(items: any[], entry: any[]) => {
|
|
14
14
|
let key = entry[0]
|
|
15
15
|
let child = entry[1]
|
|
16
16
|
|
|
17
|
-
|
|
17
|
+
// console.log('CHILD', d, key, child)
|
|
18
|
+
|
|
19
|
+
if ('$' === key) {
|
|
20
|
+
// console.log('BBB', d)
|
|
21
|
+
items.push([[], child])
|
|
22
|
+
}
|
|
23
|
+
else if (
|
|
24
|
+
d <= 1 ||
|
|
25
|
+
null == child ||
|
|
26
|
+
'object' !== typeof child ||
|
|
27
|
+
0 === Object.keys(child).length
|
|
28
|
+
) {
|
|
29
|
+
// console.log('AAA', d)
|
|
18
30
|
items.push([[key], child])
|
|
19
31
|
}
|
|
20
32
|
else {
|
|
33
|
+
// console.log('CCC', d)
|
|
21
34
|
let children = dive(child, d - 1)
|
|
22
35
|
children = children.map(child => {
|
|
23
36
|
child[0].unshift(key)
|
|
@@ -31,6 +44,8 @@ function dive(node: any, depth?: number | DiveMapper, mapper?: DiveMapper): any[
|
|
|
31
44
|
items
|
|
32
45
|
)
|
|
33
46
|
|
|
47
|
+
// console.log('ITEMS', items)
|
|
48
|
+
|
|
34
49
|
if (mapper) {
|
|
35
50
|
return items.reduce(((a, entry) => {
|
|
36
51
|
entry = (mapper as any)(entry[0], entry[1])
|
|
@@ -66,7 +81,37 @@ function joins(arr: any[], ...seps: string[]) {
|
|
|
66
81
|
return sa.join('')
|
|
67
82
|
}
|
|
68
83
|
|
|
84
|
+
|
|
85
|
+
function get(root: any, path: string | string[]): any {
|
|
86
|
+
path = 'string' === typeof path ? path.split('.') : path
|
|
87
|
+
let node = root
|
|
88
|
+
for (let i = 0; i < path.length && null != node; i++) {
|
|
89
|
+
node = node[path[i]]
|
|
90
|
+
}
|
|
91
|
+
return node
|
|
92
|
+
}
|
|
93
|
+
|
|
94
|
+
|
|
95
|
+
function pinify(path: string[]) {
|
|
96
|
+
let pin = path
|
|
97
|
+
.map((p: string, i: number) =>
|
|
98
|
+
p + (i % 2 ? (i === path.length - 1 ? '' : ',') : ':'))
|
|
99
|
+
.join('')
|
|
100
|
+
return pin
|
|
101
|
+
}
|
|
102
|
+
|
|
103
|
+
|
|
104
|
+
function camelify(input: any[] | string) {
|
|
105
|
+
let parts = 'string' == typeof input ? input.split('-') : input.map(n => '' + n)
|
|
106
|
+
return parts
|
|
107
|
+
.map((p: string) => ('' === p ? '' : (p[0].toUpperCase() + p.substring(1))))
|
|
108
|
+
.join('')
|
|
109
|
+
}
|
|
110
|
+
|
|
69
111
|
export {
|
|
70
112
|
dive,
|
|
71
113
|
joins,
|
|
114
|
+
get,
|
|
115
|
+
pinify,
|
|
116
|
+
camelify,
|
|
72
117
|
}
|
package/model.ts
CHANGED
|
@@ -13,6 +13,9 @@ import { local_builder } from './lib/builder/local'
|
|
|
13
13
|
import {
|
|
14
14
|
dive,
|
|
15
15
|
joins,
|
|
16
|
+
get,
|
|
17
|
+
pinify,
|
|
18
|
+
camelify,
|
|
16
19
|
} from './lib/util'
|
|
17
20
|
|
|
18
21
|
|
|
@@ -127,6 +130,9 @@ export {
|
|
|
127
130
|
Spec,
|
|
128
131
|
dive,
|
|
129
132
|
joins,
|
|
133
|
+
get,
|
|
134
|
+
pinify,
|
|
135
|
+
camelify,
|
|
130
136
|
}
|
|
131
137
|
|
|
132
138
|
|