json-to-spec 19.1.0 → 20.1.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.
Files changed (79) hide show
  1. package/docs/dist/min.js +275 -118
  2. package/docs/dist/v20/min.js +321 -0
  3. package/package.json +1 -1
  4. package/samples/dataList1/index.html +31 -0
  5. package/samples/dataList1/index.js +62 -0
  6. package/samples/dataList1/input/data.json +5043 -0
  7. package/samples/dataList1/input/structure.json +38 -0
  8. package/samples/form1/index.html +29 -0
  9. package/samples/form1/index.js +64 -0
  10. package/samples/form1/input/data.json +38 -0
  11. package/samples/form1/input/structure.json +278 -0
  12. package/samples/table/index.html +14 -0
  13. package/samples/table/index.js +9 -11
  14. package/samples/table/input/data.json +7 -35284
  15. package/samples/table/input/structure.json +10 -82
  16. package/samples/table1/index.html +43 -0
  17. package/samples/table1/index.js +59 -0
  18. package/samples/table1/input/data.json +10 -0
  19. package/samples/table1/input/structure.json +11 -0
  20. package/samples/table2/index.html +40 -0
  21. package/samples/table2/index.js +59 -0
  22. package/samples/table2/input/data.json +17 -0
  23. package/samples/table2/input/structure.json +19 -0
  24. package/samples/table3/index.html +35 -0
  25. package/samples/table3/index.js +60 -0
  26. package/samples/table3/input/data.json +31 -0
  27. package/samples/table3/input/structure.json +45 -0
  28. package/src/index.js +2 -2
  29. package/src/v19/index.js +19 -28
  30. package/src/v19/walk/loopArray/v1/createChildren.js +27 -0
  31. package/src/v19/walk/loopArray/v1/index.js +33 -0
  32. package/src/v19/walk/loopObject/v1/createChildren.js +27 -0
  33. package/src/v19/walk/loopObject/v1/index.js +25 -0
  34. package/src/v19/walk/loopObject/v2/createChildren.js +32 -0
  35. package/src/v19/walk/loopObject/v2/index.js +29 -0
  36. package/src/v19/walk/replaceWithArray/v1/index.js +15 -0
  37. package/src/v19/walk/replaceWithArray/v1/replaceAttributes.js +26 -0
  38. package/src/v19/walk/replaceWithArray/v1/replaceCommon.js +23 -0
  39. package/src/v19/walk/replaceWithArray/v1/replaceNodeValue.js +17 -0
  40. package/src/v19/walk/replaceWithObject/v1/index.js +15 -0
  41. package/src/v19/walk/replaceWithObject/v1/replaceAttributes.js +28 -0
  42. package/src/v19/walk/replaceWithObject/v1/replaceCommon.js +23 -0
  43. package/src/v19/walk/replaceWithObject/v1/replaceNodeValue.js +18 -0
  44. package/src/v19/walk/walk.js +37 -2
  45. package/src/v20/index.js +46 -0
  46. package/src/v20/meta.js +7 -0
  47. package/src/v20/registerGlobal.js +17 -0
  48. package/src/v20/replace.js +18 -0
  49. package/src/v20/resolvePath.js +29 -0
  50. package/src/v20/walk/iterate/v1/index.js +42 -0
  51. package/src/v20/walk/iterate/v2/index.js +32 -0
  52. package/src/v20/walk/iterate/v3/index.js +46 -0
  53. package/src/v20/walk/iterate/v4/createChildren.js +27 -0
  54. package/src/v20/walk/iterate/v4/index.js +25 -0
  55. package/src/v20/walk/loopArray/v1/createChildren.js +42 -0
  56. package/src/v20/walk/loopArray/v1/index.js +33 -0
  57. package/src/v20/walk/loopArray/v2/createChildren.js +48 -0
  58. package/src/v20/walk/loopArray/v2/index.js +33 -0
  59. package/src/v20/walk/loopObject/v1/createChildren.js +27 -0
  60. package/src/v20/walk/loopObject/v1/index.js +25 -0
  61. package/src/v20/walk/loopObject/v2/createChildren.js +32 -0
  62. package/src/v20/walk/loopObject/v2/index.js +29 -0
  63. package/src/v20/walk/replaceWithArray/v1/index.js +15 -0
  64. package/src/v20/walk/replaceWithArray/v1/replaceAttributes.js +26 -0
  65. package/src/v20/walk/replaceWithArray/v1/replaceCommon.js +23 -0
  66. package/src/v20/walk/replaceWithArray/v1/replaceTextContent.js +42 -0
  67. package/src/v20/walk/replaceWithData/v1/index.js +42 -0
  68. package/src/v20/walk/replaceWithData/v1/replaceCommon.js +21 -0
  69. package/src/v20/walk/replaceWithData/v2/index.js +105 -0
  70. package/src/v20/walk/replaceWithData/v2/replaceCommon.js +21 -0
  71. package/src/v20/walk/replaceWithData/v3/index.js +15 -0
  72. package/src/v20/walk/replaceWithData/v3/replaceAttributes.js +29 -0
  73. package/src/v20/walk/replaceWithData/v3/replaceCommon.js +23 -0
  74. package/src/v20/walk/replaceWithData/v3/replaceNodeValue.js +27 -0
  75. package/src/v20/walk/replaceWithObject/v1/index.js +15 -0
  76. package/src/v20/walk/replaceWithObject/v1/replaceAttributes.js +28 -0
  77. package/src/v20/walk/replaceWithObject/v1/replaceCommon.js +23 -0
  78. package/src/v20/walk/replaceWithObject/v1/replaceNodeValue.js +18 -0
  79. package/src/v20/walk/walk.js +132 -0
package/docs/dist/min.js CHANGED
@@ -1,164 +1,321 @@
1
- const p = {
1
+ const f = {
2
2
  version: "19.0.0",
3
3
  name: "json-to-spec/v19",
4
4
  description: "Minimalist 2-layer compiler: pure value replace + jsonToSpec iterate"
5
- }, d = (r) => {
6
- typeof globalThis > "u" || !r || (globalThis.ks ?? (globalThis.ks = {}), globalThis.ks["json-to-spec"] = {
7
- meta: p,
8
- compile: r
5
+ }, b = (n) => {
6
+ typeof globalThis > "u" || !n || (globalThis.ks ?? (globalThis.ks = {}), globalThis.ks["json-to-spec"] = {
7
+ meta: f,
8
+ compile: n
9
9
  });
10
- }, f = ({ inData: r, inDataKey: o }) => {
11
- const t = o;
12
- if (t === "") return r;
13
- let n = r[t];
14
- return t.includes(".") && (n = t.split(".").reduce(
15
- (s, c) => s == null ? void 0 : s[c],
16
- r
17
- )), n;
18
- }, y = ({
19
- inNode: r,
20
- inData: o
21
- } = {}) => {
22
- const t = r, n = o;
10
+ }, d = ({ inData: n, inDataKey: r }) => {
11
+ const t = r;
12
+ if (t === "") return n;
13
+ let e = n[t];
14
+ return t.includes(".") && (e = t.split(".").reduce(
15
+ (c, a) => c == null ? void 0 : c[a],
16
+ n
17
+ )), e;
18
+ }, O = ({
19
+ inNode: n,
20
+ inData: r
21
+ } = {}) => {
22
+ const t = n, e = r;
23
23
  if (!(t != null && t.textContent)) return "no-textContent";
24
24
  if (typeof t.textContent != "string") return "not-a-string";
25
25
  if (!t.textContent.includes("${")) return "no-template-token";
26
- const e = t.textContent.replace(/^\$\{/, "").replace(/\}$/, "");
27
- t.textContent = f({
28
- inData: n,
29
- inDataKey: e
26
+ const o = t.textContent.replace(/^\$\{/, "").replace(/\}$/, "");
27
+ t.textContent = d({
28
+ inData: e,
29
+ inDataKey: o
30
30
  });
31
- }, h = ({
32
- inNode: r,
33
- inData: o
31
+ }, C = ({
32
+ inNode: n,
33
+ inData: r
34
34
  } = {}) => {
35
- const t = r, n = o;
35
+ const t = n, e = r;
36
36
  if ("attributes" in t) {
37
- const e = Object.fromEntries(
38
- Object.entries(t.attributes || {}).map(([a, s]) => [
39
- a,
40
- typeof s == "string" && s.includes("${") ? f({
41
- inData: n,
42
- inDataKey: s.replace(/^\$\{/, "").replace(/\}$/, "")
43
- }) : s
37
+ const o = Object.fromEntries(
38
+ Object.entries(t.attributes || {}).map(([s, c]) => [
39
+ s,
40
+ typeof c == "string" && c.includes("${") ? d({
41
+ inData: e,
42
+ inDataKey: c.replace(/^\$\{/, "").replace(/\}$/, "")
43
+ }) : c
44
44
  ])
45
45
  );
46
- t.attributes = { ...e };
46
+ t.attributes = { ...o };
47
47
  }
48
- }, j = ({
49
- inNode: r,
50
- inData: o
48
+ }, $ = ({
49
+ inNode: n,
50
+ inData: r
51
51
  } = {}) => {
52
- const t = r, n = o;
53
- y({ inNode: t, inData: n }), h({ inNode: t, inData: n });
54
- }, A = ({
55
- inTemplate: r,
56
- inSourceValues: o
57
- } = {}) => {
58
- const t = o;
59
- return t === void 0 ? void 0 : t.map((e) => {
60
- const a = structuredClone(r);
61
- return i({
62
- inNode: a,
63
- inData: e,
52
+ const t = n, e = r;
53
+ O({ inNode: t, inData: e }), C({ inNode: t, inData: e });
54
+ }, T = ({
55
+ inTemplate: n,
56
+ inSourceValues: r
57
+ } = {}) => {
58
+ const t = r;
59
+ return t === void 0 ? void 0 : t.map((o) => {
60
+ const s = structuredClone(n);
61
+ return l({
62
+ inNode: s,
63
+ inData: o,
64
64
  inOperation: "replace"
65
65
  });
66
66
  });
67
+ }, k = ({
68
+ inNode: n,
69
+ inData: r,
70
+ inShowLog: t
71
+ } = {}) => {
72
+ const e = n, o = r;
73
+ if (!("jsonToSpec" in e) || !("operation" in e.jsonToSpec) || e.jsonToSpec.operation !== "iterate" || !("source" in e.jsonToSpec)) return;
74
+ const s = o[e.jsonToSpec.source], c = T({
75
+ inTemplate: e.jsonToSpec.template,
76
+ inSourceValues: s
77
+ });
78
+ e.children = c;
79
+ }, A = ({
80
+ inNode: n,
81
+ inData: r
82
+ } = {}) => {
83
+ const t = n;
84
+ if (!(t != null && t.textContent)) return "no-textContent";
85
+ if (typeof t.textContent != "string") return "not-a-string";
86
+ if (!t.textContent.includes("${")) return "no-template-token";
87
+ t.textContent === "${key}" && (t.textContent = r.key), t.textContent === "${value}" && (t.textContent = r.value);
88
+ }, x = ({
89
+ inNode: n,
90
+ inData: r
91
+ } = {}) => {
92
+ const t = n;
93
+ if ("attributes" in t) {
94
+ const e = Object.fromEntries(
95
+ Object.entries(t.attributes).map(([o, s]) => {
96
+ let c = s;
97
+ return s === "${key}" ? c = r.key : s === "${value}" && (c = r.value), [o, c];
98
+ })
99
+ );
100
+ t.attributes = { ...e };
101
+ }
102
+ }, j = ({
103
+ inNode: n,
104
+ inData: r
105
+ } = {}) => {
106
+ const t = n, e = r;
107
+ A({ inNode: t, inData: e }), x({ inNode: t, inData: e });
108
+ };
109
+ function m(n) {
110
+ return n !== null && typeof n == "object" && Object.getPrototypeOf(n) === Object.prototype;
111
+ }
112
+ const h = ({
113
+ inTemplate: n,
114
+ inSourceValues: r,
115
+ inShowLog: t
116
+ } = {}) => {
117
+ const e = r;
118
+ if (e === void 0 || !m(e)) return;
119
+ t && console.log("loopObject:createChildren:1 ", n, r);
120
+ let o = [];
121
+ for (const [s, c] of Object.entries(e)) {
122
+ const a = structuredClone(n);
123
+ j({ inNode: a, inData: { key: s, value: c } }), o.push(a);
124
+ }
125
+ return o;
67
126
  }, D = ({
68
- inNode: r,
69
- inData: o,
127
+ inNode: n,
128
+ inData: r,
129
+ inShowLog: t
130
+ } = {}) => {
131
+ const e = n, o = r;
132
+ if (t && console.log("loopObject:1 ", n, r), !("jsonToSpec" in e) || !("operation" in e.jsonToSpec) || e.jsonToSpec.operation !== "loopObject" || !("source" in e.jsonToSpec)) return;
133
+ t && console.log("loopObject:2 ", n, r);
134
+ const s = o[e.jsonToSpec.source], c = h({
135
+ inTemplate: e.jsonToSpec.template,
136
+ inSourceValues: s,
137
+ inShowLog: t
138
+ });
139
+ e.children = c;
140
+ };
141
+ function S(n) {
142
+ return n !== null && typeof n == "object" && Object.getPrototypeOf(n) === Object.prototype;
143
+ }
144
+ const g = ({
145
+ inNode: n,
146
+ inData: r
147
+ } = {}) => {
148
+ if (Object.keys(r).map((o) => `\${${o}}`).includes(n.textContent)) {
149
+ const o = n.textContent.slice(2, -1);
150
+ n.textContent = r[o];
151
+ }
152
+ }, F = ({
153
+ inNode: n,
154
+ inData: r
155
+ } = {}) => {
156
+ const t = n, e = r;
157
+ if (console.log("localData------- : ", e), !(t != null && t.textContent)) return "no-textContent";
158
+ if (typeof t.textContent != "string") return "not-a-string";
159
+ if (!t.textContent.includes("${")) return "no-template-token";
160
+ S(e) ? g({ inNode: n, inData: r }) : t.textContent === "${}" && (t.textContent = e);
161
+ }, N = ({
162
+ inNode: n,
163
+ inData: r
164
+ } = {}) => {
165
+ const t = n;
166
+ if ("attributes" in t) {
167
+ const e = Object.fromEntries(
168
+ Object.entries(t.attributes).map(([o, s]) => {
169
+ let c = s;
170
+ return s === "${}" && (c = r.key), [o, c];
171
+ })
172
+ );
173
+ t.attributes = { ...e };
174
+ }
175
+ }, V = ({
176
+ inNode: n,
177
+ inData: r
178
+ } = {}) => {
179
+ const t = n, e = r;
180
+ F({ inNode: t, inData: e }), N({ inNode: t, inData: e });
181
+ }, w = ({
182
+ inTemplate: n,
183
+ inSourceValuesAsArray: r,
184
+ inShowLog: t
185
+ } = {}) => {
186
+ const e = r;
187
+ if (e === void 0 || !Array.isArray(e)) return;
188
+ t && console.log("loopObject:createChildren:1 ", n, inSourceValues);
189
+ let o = [];
190
+ return e.forEach((s) => {
191
+ var a, i;
192
+ const c = structuredClone(n);
193
+ if ("jsonToSpec" in c) {
194
+ const y = (a = c == null ? void 0 : c.jsonToSpec) == null ? void 0 : a.source;
195
+ let u = {};
196
+ u[y] = s, l({
197
+ inNode: c,
198
+ inData: u,
199
+ inOperation: (i = c == null ? void 0 : c.jsonToSpec) == null ? void 0 : i.operation,
200
+ inShowLog: t
201
+ });
202
+ }
203
+ V({ inNode: c, inData: s }), o.push(c);
204
+ }), o;
205
+ }, K = ({
206
+ inNode: n,
207
+ inData: r,
70
208
  inShowLog: t
71
209
  } = {}) => {
72
- const n = r, e = o;
73
- if (!("jsonToSpec" in n) || !("operation" in n.jsonToSpec) || n.jsonToSpec.operation !== "iterate" || !("source" in n.jsonToSpec)) return;
74
- const a = e[n.jsonToSpec.source], s = A({
75
- inTemplate: n.jsonToSpec.template,
76
- inSourceValues: a
210
+ const e = n, o = r;
211
+ if (console.log("loopArray:1 ", n, r), t && console.log("loopObject:1 ", n, r), !("jsonToSpec" in e) || !("operation" in e.jsonToSpec) || e.jsonToSpec.operation !== "loopArray" || !("source" in e.jsonToSpec)) return;
212
+ const s = o[e.jsonToSpec.source];
213
+ if (!Array.isArray(s)) return;
214
+ t && console.log("loopObject:2 ", n, r);
215
+ const c = w({
216
+ inTemplate: e.jsonToSpec.template,
217
+ inSourceValuesAsArray: s,
218
+ inShowLog: t
77
219
  });
78
- n.children = s;
79
- }, l = ({ inNode: r, inData: o, inOperation: t }) => {
80
- const n = r, e = t;
81
- if (Array.isArray(n)) {
82
- const a = [];
83
- for (const s of n) {
84
- const c = i({
85
- inNode: s,
220
+ e.children = c;
221
+ }, p = ({ inNode: n, inData: r, inOperation: t }) => {
222
+ const e = n, o = r, s = t;
223
+ if (Array.isArray(e)) {
224
+ const c = [];
225
+ for (const a of e) {
226
+ const i = l({
227
+ inNode: a,
86
228
  inData: o,
87
- inOperation: e
229
+ inOperation: s
88
230
  });
89
- Array.isArray(c) ? a.push(...c) : c != null && a.push(c);
231
+ Array.isArray(i) ? c.push(...i) : i != null && c.push(i);
90
232
  }
91
- return a;
233
+ return c;
92
234
  }
93
- }, i = ({
94
- inNode: r,
95
- inData: o = {},
235
+ }, l = ({
236
+ inNode: n,
237
+ inData: r = {},
96
238
  inOperation: t,
97
- inShowLog: n = !1
239
+ inShowLog: e = !1
98
240
  } = {}) => {
99
- const e = r, a = o, s = t;
100
- if (n && console.log("walk ", r, o, t), e == null)
101
- return e;
102
- if (Array.isArray(e))
103
- return l({
104
- inNode: e,
105
- inData: o,
106
- inOperation: s
241
+ const o = n, s = r, c = t;
242
+ if (e && console.log("walk ", n, r, t), o == null)
243
+ return o;
244
+ if (Array.isArray(o))
245
+ return p({
246
+ inNode: o,
247
+ inData: r,
248
+ inOperation: c
107
249
  });
108
- if ("children" in e && Array.isArray(e == null ? void 0 : e.children) && (e.children = l({
109
- inNode: e == null ? void 0 : e.children,
110
- inData: o,
111
- inOperation: s
112
- })), typeof e != "object")
113
- return e;
114
- switch (s) {
250
+ if ("children" in o && Array.isArray(o == null ? void 0 : o.children) && (o.children = p({
251
+ inNode: o == null ? void 0 : o.children,
252
+ inData: r,
253
+ inOperation: c
254
+ })), typeof o != "object")
255
+ return o;
256
+ switch (e && console.log("localOperation ", c), c) {
115
257
  case "replace":
116
- typeof e == "object" && j({
117
- inNode: e,
118
- inData: o
258
+ typeof o == "object" && $({
259
+ inNode: o,
260
+ inData: r
261
+ });
262
+ break;
263
+ case "replaceObject":
264
+ typeof o == "object" && j({
265
+ inNode: o,
266
+ inData: r
119
267
  });
120
268
  break;
121
269
  case "iterateDo":
270
+ k({
271
+ inNode: o,
272
+ inData: s,
273
+ inShowLog: e
274
+ });
275
+ break;
276
+ case "loopObject":
122
277
  D({
123
- inNode: e,
124
- inData: a,
125
- inShowLog: n
278
+ inNode: o,
279
+ inData: s,
280
+ inShowLog: e
281
+ });
282
+ break;
283
+ case "loopArray":
284
+ K({
285
+ inNode: o,
286
+ inData: s,
287
+ inShowLog: e
126
288
  });
289
+ break;
127
290
  }
128
- return e;
129
- }, u = ({ inStructureAsJson: r, inDataAsJson: o, inOperation: t, inShowLog: n }) => {
291
+ return o;
292
+ }, E = ({ inStructureAsJson: n, inDataAsJson: r, inOperation: t, inShowLog: e }) => {
130
293
  try {
131
- return i({
132
- inNode: r,
133
- inData: o,
294
+ return l({
295
+ inNode: n,
296
+ inData: r,
134
297
  inOperation: t,
135
- inShowLog: n
298
+ inShowLog: e
136
299
  });
137
- } catch (e) {
138
- throw console.error("[json-to-spec/v17] replace error:", e), e;
300
+ } catch (o) {
301
+ throw console.error("[json-to-spec/v17] replace error:", o), o;
139
302
  }
140
- }, m = (r, o = {}, t = !1) => {
141
- let n = r, e = o;
142
- t && console.log(p.name, n, e);
303
+ }, P = (n, r = {}, t = !1) => {
304
+ let e = n, o = r;
305
+ t && console.log(f.name, e, o);
143
306
  try {
144
- const a = u({
145
- inStructureAsJson: n,
146
- inDataAsJson: e,
147
- inOperation: "iterateDo",
148
- inShowLog: t
149
- }), s = u({
150
- inStructureAsJson: a,
151
- inDataAsJson: e,
152
- inOperation: "replace",
307
+ return E({
308
+ inStructureAsJson: e,
309
+ inDataAsJson: o,
310
+ inOperation: "loopArray",
153
311
  inShowLog: t
154
312
  });
155
- return t && console.log("iteratedData : ", a, s), s;
156
- } catch (a) {
157
- throw console.error("[json-to-spec/v19] compile error:", a), a;
313
+ } catch (s) {
314
+ throw console.error("[json-to-spec/v19] compile error:", s), s;
158
315
  }
159
316
  };
160
- d(m);
317
+ b(P);
161
318
  export {
162
- m as compile,
163
- m as default
319
+ P as compile,
320
+ P as default
164
321
  };