@voxgig/model 0.6.1 → 0.9.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.
@@ -0,0 +1,4 @@
1
+ declare type DiveMapper = (path: any[], leaf: any) => any[];
2
+ declare function dive(node: any, depth?: number | DiveMapper, mapper?: DiveMapper): any[];
3
+ declare function joins(arr: any[], ...seps: string[]): string;
4
+ export { dive, joins, };
@@ -0,0 +1,57 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.joins = exports.dive = void 0;
4
+ function dive(node, depth, mapper) {
5
+ let d = (null == depth || 'number' != typeof depth) ? 2 : depth;
6
+ mapper = 'function' === typeof depth ? depth : mapper;
7
+ let items = [];
8
+ Object.entries(node).reduce((items, entry) => {
9
+ let key = entry[0];
10
+ let child = entry[1];
11
+ if (d <= 1) {
12
+ items.push([[key], child]);
13
+ }
14
+ else {
15
+ let children = dive(child, d - 1);
16
+ children = children.map(child => {
17
+ child[0].unshift(key);
18
+ return child;
19
+ });
20
+ items.push(...children);
21
+ }
22
+ return items;
23
+ }, items);
24
+ if (mapper) {
25
+ return items.reduce(((a, entry) => {
26
+ entry = mapper(entry[0], entry[1]);
27
+ a[entry[0]] = entry[1];
28
+ return a;
29
+ }), {});
30
+ }
31
+ return items;
32
+ }
33
+ exports.dive = dive;
34
+ /*
35
+ * , => a,b
36
+ * :, => a:1,b:2
37
+ * :,/ => a:1,b:2/c:3,d:4/e:5,f:6
38
+ */
39
+ function joins(arr, ...seps) {
40
+ arr = arr || [];
41
+ seps = seps || [];
42
+ let sa = [];
43
+ for (let i = 0; i < arr.length; i++) {
44
+ sa.push(arr[i]);
45
+ if (i < arr.length - 1) {
46
+ for (let j = seps.length - 1; -1 < j; j--) {
47
+ if (0 === (i + 1) % (1 << j)) {
48
+ sa.push(seps[j]);
49
+ break;
50
+ }
51
+ }
52
+ }
53
+ }
54
+ return sa.join('');
55
+ }
56
+ exports.joins = joins;
57
+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,EAAE,EAAE;YAChC,KAAK,GAAI,MAAc,CAAC,KAAK,CAAC,CAAC,CAAC,EAAE,KAAK,CAAC,CAAC,CAAC,CAAC,CAAA;YAC3C,CAAC,CAAC,KAAK,CAAC,CAAC,CAAC,CAAC,GAAG,KAAK,CAAC,CAAC,CAAC,CAAA;YACtB,OAAO,CAAC,CAAA;QACV,CAAC,CAAC,EAAE,EAAS,CAAC,CAAA;KACf;IAED,OAAO,KAAK,CAAA;AACd,CAAC;AA2BC,oBAAI;AAxBN;;;;EAIE;AACF,SAAS,KAAK,CAAC,GAAU,EAAE,GAAG,IAAc;IAC1C,GAAG,GAAG,GAAG,IAAI,EAAE,CAAA;IACf,IAAI,GAAG,IAAI,IAAI,EAAE,CAAA;IACjB,IAAI,EAAE,GAAG,EAAE,CAAA;IACX,KAAK,IAAI,CAAC,GAAG,CAAC,EAAE,CAAC,GAAG,GAAG,CAAC,MAAM,EAAE,CAAC,EAAE,EAAE;QACnC,EAAE,CAAC,IAAI,CAAC,GAAG,CAAC,CAAC,CAAC,CAAC,CAAA;QACf,IAAI,CAAC,GAAG,GAAG,CAAC,MAAM,GAAG,CAAC,EAAE;YACtB,KAAK,IAAI,CAAC,GAAG,IAAI,CAAC,MAAM,GAAG,CAAC,EAAE,CAAC,CAAC,GAAG,CAAC,EAAE,CAAC,EAAE,EAAE;gBACzC,IAAI,CAAC,KAAK,CAAC,CAAC,GAAG,CAAC,CAAC,GAAG,CAAC,CAAC,IAAI,CAAC,CAAC,EAAE;oBAC5B,EAAE,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC,CAAA;oBAChB,MAAK;iBACN;aACF;SACF;KACF;IACD,OAAO,EAAE,CAAC,IAAI,CAAC,EAAE,CAAC,CAAA;AACpB,CAAC;AAIC,sBAAK"}
package/dist/model.d.ts CHANGED
@@ -1,6 +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
5
  declare class Model {
5
6
  config: Config;
6
7
  build: any;
@@ -11,4 +12,4 @@ declare class Model {
11
12
  start(): Promise<void>;
12
13
  stop(): Promise<void>;
13
14
  }
14
- export { Model, Spec };
15
+ export { Model, Spec, dive, joins, };
package/dist/model.js CHANGED
@@ -4,13 +4,16 @@ 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.Model = void 0;
7
+ 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");
11
11
  const watch_1 = require("./lib/watch");
12
12
  const model_1 = require("./lib/builder/model");
13
13
  const local_1 = require("./lib/builder/local");
14
+ const util_1 = require("./lib/util");
15
+ Object.defineProperty(exports, "dive", { enumerable: true, get: function () { return util_1.dive; } });
16
+ Object.defineProperty(exports, "joins", { enumerable: true, get: function () { return util_1.joins; } });
14
17
  const intern = makeIntern();
15
18
  class Model {
16
19
  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,uCAAmC;AAEnC,+CAAmD;AACnD,+CAAmD;AAGnD,MAAM,MAAM,GAAG,UAAU,EAAE,CAAA;AAE3B,MAAM,KAAK;IAQT,YAAY,IAAU;QAHtB,kBAAa,GAAG,KAAK,CAAA;QAInB,IAAI,CAAC,MAAM,GAAG,MAAM,CAAC,UAAU,CAAC,IAAI,EAAE;YACpC,IAAI,EAAE,GAAG;YACT,KAAK,EAAE,KAAK,EAAE,KAAY,EAAE,EAAE;gBAC5B,OAAO,CAAC,GAAG,CAAC,eAAe,EAAE,IAAI,CAAC,aAAa,CAAC,CAAA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Mapper): any[] {
5
+ let d = (null == depth || 'number' != typeof depth) ? 2 : depth
6
+ mapper = 'function' === typeof depth ? depth : mapper
7
+
8
+ let items: any[] = []
9
+
10
+ Object.entries(node).reduce(
11
+ (items: any[], entry: any[]) => {
12
+ let key = entry[0]
13
+ let child = entry[1]
14
+
15
+ if (d <= 1) {
16
+ items.push([[key], child])
17
+ }
18
+ else {
19
+ let children = dive(child, d - 1)
20
+ children = children.map(child => {
21
+ child[0].unshift(key)
22
+ return child
23
+ })
24
+ items.push(...children)
25
+ }
26
+
27
+ return items
28
+ },
29
+ items
30
+ )
31
+
32
+ if (mapper) {
33
+ return items.reduce(((a, entry) => {
34
+ entry = (mapper as any)(entry[0], entry[1])
35
+ a[entry[0]] = entry[1]
36
+ return a
37
+ }), {} as any)
38
+ }
39
+
40
+ return items
41
+ }
42
+
43
+
44
+ /*
45
+ * , => a,b
46
+ * :, => a:1,b:2
47
+ * :,/ => a:1,b:2/c:3,d:4/e:5,f:6
48
+ */
49
+ function joins(arr: any[], ...seps: string[]) {
50
+ arr = arr || []
51
+ seps = seps || []
52
+ let sa = []
53
+ for (let i = 0; i < arr.length; i++) {
54
+ sa.push(arr[i])
55
+ if (i < arr.length - 1) {
56
+ for (let j = seps.length - 1; -1 < j; j--) {
57
+ if (0 === (i + 1) % (1 << j)) {
58
+ sa.push(seps[j])
59
+ break
60
+ }
61
+ }
62
+ }
63
+ }
64
+ return sa.join('')
65
+ }
66
+
67
+ export {
68
+ dive,
69
+ joins,
70
+ }
package/lib/util.ts~ ADDED
@@ -0,0 +1,10 @@
1
+
2
+
3
+ function dive() {
4
+
5
+ }
6
+
7
+
8
+ export {
9
+ dive
10
+ }
package/model.ts CHANGED
@@ -10,6 +10,11 @@ import { Watch } from './lib/watch'
10
10
  import { model_builder } from './lib/builder/model'
11
11
  import { local_builder } from './lib/builder/local'
12
12
 
13
+ import {
14
+ dive,
15
+ joins,
16
+ } from './lib/util'
17
+
13
18
 
14
19
  const intern = makeIntern()
15
20
 
@@ -119,6 +124,11 @@ function makeIntern() {
119
124
  }
120
125
 
121
126
 
122
- export { Model, Spec }
127
+ export {
128
+ Model,
129
+ Spec,
130
+ dive,
131
+ joins,
132
+ }
123
133
 
124
134
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@voxgig/model",
3
- "version": "0.6.1",
3
+ "version": "0.9.0",
4
4
  "main": "dist/model.js",
5
5
  "type": "commonjs",
6
6
  "types": "dist/model.d.ts",
@@ -41,12 +41,12 @@
41
41
  "LICENSE"
42
42
  ],
43
43
  "dependencies": {
44
- "aontu": "^0.4.0",
44
+ "aontu": "^0.5.0",
45
45
  "chokidar": "^3.5.3"
46
46
  },
47
47
  "devDependencies": {
48
48
  "@types/jest": "^28.1.6",
49
- "esbuild": "^0.14.53",
49
+ "esbuild": "^0.15.3",
50
50
  "esbuild-jest": "^0.5.0",
51
51
  "jest": "^28.1.3",
52
52
  "ts-jest": "^28.0.7",