json-to-spec 21.1.1 → 24.1.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/docs/dist/min.js +154 -116
- package/docs/dist/v21/min.js +116 -116
- package/docs/dist/v23/min.js +154 -0
- package/package.json +6 -6
- package/samples/table3/index.js +8 -10
- package/src/index.js +2 -2
- package/src/v22/buildSpec/buildChildrenNodes.js +24 -0
- package/src/v22/buildSpec/buildSingleElement.js +18 -0
- package/src/v22/buildSpec/buildSpecArray.js +16 -0
- package/src/v22/buildSpec/forArray/v1/index.js +27 -0
- package/src/v22/buildSpec/forObject/v1/index.js +47 -0
- package/src/v22/buildSpec/forSpec/v3/index.js +84 -0
- package/src/v22/buildSpec/forSpec.js +76 -0
- package/src/v22/buildSpec/guards.js +26 -0
- package/src/v22/buildSpec/index.js +97 -0
- package/src/v22/index.js +21 -0
- package/src/v22/meta.js +6 -0
- package/src/v22/registerGlobal.js +17 -0
- package/src/v23/buildSpec/buildSpecArray.js +16 -0
- package/src/v23/buildSpec/forArray/v1/index.js +27 -0
- package/src/v23/buildSpec/forArrayStrings/v1/index.js +24 -0
- package/src/v23/buildSpec/forObject/v1/index.js +47 -0
- package/src/v23/buildSpec/forSpec/v3/index.js +114 -0
- package/src/v23/buildSpec/guards.js +20 -0
- package/src/v23/buildSpec/index.js +122 -0
- package/src/v23/index.js +21 -0
- package/src/v23/meta.js +6 -0
- package/src/v23/registerGlobal.js +17 -0
- package/src/v24/buildSpec/buildSpecArray.js +16 -0
- package/src/v24/buildSpec/forArray/v1/index.js +27 -0
- package/src/v24/buildSpec/forArrayStrings/v1/index.js +24 -0
- package/src/v24/buildSpec/forObject/v1/index.js +47 -0
- package/src/v24/buildSpec/forSpec/v3/index.js +114 -0
- package/src/v24/buildSpec/guards.js +20 -0
- package/src/v24/buildSpec/index.js +122 -0
- package/src/v24/index.js +21 -0
- package/src/v24/meta.js +6 -0
- package/src/v24/registerGlobal.js +22 -0
package/docs/dist/min.js
CHANGED
|
@@ -1,116 +1,154 @@
|
|
|
1
|
-
const
|
|
2
|
-
version: "
|
|
3
|
-
description: "Pure spec engine no document at all"
|
|
4
|
-
},
|
|
5
|
-
typeof globalThis > "u" || !e || (globalThis.ks ?? (globalThis.ks = {}), globalThis.ks["json-to-spec"] = {
|
|
6
|
-
meta:
|
|
7
|
-
buildSpecElement: e
|
|
8
|
-
});
|
|
9
|
-
},
|
|
10
|
-
const
|
|
11
|
-
return
|
|
12
|
-
},
|
|
13
|
-
const
|
|
14
|
-
return Array.isArray(
|
|
15
|
-
inSpecJson:
|
|
16
|
-
inShowLog:
|
|
17
|
-
inDataJson:
|
|
18
|
-
})).flat().filter(Boolean) : [];
|
|
19
|
-
},
|
|
20
|
-
const
|
|
21
|
-
let
|
|
22
|
-
for (const
|
|
23
|
-
if (
|
|
24
|
-
return "";
|
|
25
|
-
|
|
26
|
-
}
|
|
27
|
-
return
|
|
28
|
-
}),
|
|
29
|
-
e
|
|
30
|
-
t
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
)
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
},
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
const
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
}
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
if (
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
inDataJson:
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
}
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
1
|
+
const f = {
|
|
2
|
+
version: "v23.0",
|
|
3
|
+
description: "Pure spec engine no document at all"
|
|
4
|
+
}, d = (e) => {
|
|
5
|
+
typeof globalThis > "u" || !e || (globalThis.ks ?? (globalThis.ks = {}), globalThis.ks["json-to-spec"] = {
|
|
6
|
+
meta: f,
|
|
7
|
+
buildSpecElement: e
|
|
8
|
+
});
|
|
9
|
+
}, y = ({ inSpec: e }) => {
|
|
10
|
+
const n = e;
|
|
11
|
+
return n == null;
|
|
12
|
+
}, m = ({ inSpec: e }) => typeof Node < "u" && e instanceof Node, b = ({ inSpecJson: e }) => Array.isArray(e), A = ({ inArray: e = [], inShowLog: n = !1, inDataJson: o }) => {
|
|
13
|
+
const t = e, c = n, r = o;
|
|
14
|
+
return Array.isArray(t) ? t.map((s) => i({
|
|
15
|
+
inSpecJson: s,
|
|
16
|
+
inShowLog: c,
|
|
17
|
+
inDataJson: r
|
|
18
|
+
})).flat().filter(Boolean) : [];
|
|
19
|
+
}, a = (e, n) => typeof e != "string" ? e : e.replace(/\$\{([^}]+)\}/g, (o, t) => {
|
|
20
|
+
const c = t.trim().split(".");
|
|
21
|
+
let r = n;
|
|
22
|
+
for (const s of c) {
|
|
23
|
+
if (r == null)
|
|
24
|
+
return "";
|
|
25
|
+
r = r[s];
|
|
26
|
+
}
|
|
27
|
+
return r === null || typeof r == "string" || typeof r == "number" || typeof r == "boolean" ? String(r ?? "") : r;
|
|
28
|
+
}), u = ({ inSpecJson: e, inData: n, inShowLog: o }) => {
|
|
29
|
+
const t = structuredClone(e);
|
|
30
|
+
return typeof n == "string" ? ("textContent" in t && (t.textContent === "${}" ? t.textContent = n : typeof t.textContent == "string" && (t.textContent = t.textContent.replaceAll("${}", () => n))), "attributes" in t && (t.attributes = Object.fromEntries(
|
|
31
|
+
Object.entries(t.attributes).map(
|
|
32
|
+
([c, r]) => [
|
|
33
|
+
c,
|
|
34
|
+
r === "${}" ? n : typeof r == "string" ? r.replaceAll("${}", () => n) : r
|
|
35
|
+
]
|
|
36
|
+
)
|
|
37
|
+
))) : "key" in n && "value" in n ? "textContent" in t && (t.textContent = a(
|
|
38
|
+
t.textContent,
|
|
39
|
+
n
|
|
40
|
+
)) : ("textContent" in t && (t.textContent = a(
|
|
41
|
+
t.textContent,
|
|
42
|
+
n
|
|
43
|
+
)), "attributes" in t && (t.attributes = Object.fromEntries(
|
|
44
|
+
Object.entries(t.attributes).map(
|
|
45
|
+
([c, r]) => [
|
|
46
|
+
c,
|
|
47
|
+
a(r, n)
|
|
48
|
+
]
|
|
49
|
+
)
|
|
50
|
+
)), "children" in t && (t.children = t.children.map((c) => i({
|
|
51
|
+
inSpecJson: c,
|
|
52
|
+
inShowLog: o,
|
|
53
|
+
inDataJson: n
|
|
54
|
+
})))), t;
|
|
55
|
+
}, j = ({ inTemplate: e, inDataAsArray: n }) => {
|
|
56
|
+
const o = n, t = e;
|
|
57
|
+
return Array.isArray(o) ? o.map((r) => {
|
|
58
|
+
const s = structuredClone(t);
|
|
59
|
+
return i({
|
|
60
|
+
inSpecJson: s,
|
|
61
|
+
inDataJson: r
|
|
62
|
+
});
|
|
63
|
+
}) : [];
|
|
64
|
+
}, S = ({ inTemplate: e, inDataAsObject: n }) => {
|
|
65
|
+
const o = n, t = e;
|
|
66
|
+
if (o === null || typeof o != "object")
|
|
67
|
+
return [];
|
|
68
|
+
const c = [];
|
|
69
|
+
for (const [r, s] of Object.entries(o)) {
|
|
70
|
+
const l = structuredClone(t), p = i({
|
|
71
|
+
inSpecJson: l,
|
|
72
|
+
inDataJson: {
|
|
73
|
+
key: r,
|
|
74
|
+
value: s
|
|
75
|
+
}
|
|
76
|
+
});
|
|
77
|
+
c.push(p);
|
|
78
|
+
}
|
|
79
|
+
return c;
|
|
80
|
+
}, i = ({
|
|
81
|
+
inSpecJson: e,
|
|
82
|
+
inShowLog: n = !1,
|
|
83
|
+
inDataJson: o
|
|
84
|
+
} = {}) => {
|
|
85
|
+
if (y({ inSpec: e }))
|
|
86
|
+
return null;
|
|
87
|
+
if (m({ inSpec: e }))
|
|
88
|
+
return e;
|
|
89
|
+
if (b({ inSpecJson: e }))
|
|
90
|
+
return A({
|
|
91
|
+
inArray: e,
|
|
92
|
+
inShowLog: n,
|
|
93
|
+
inDataJson: o
|
|
94
|
+
});
|
|
95
|
+
if ("jsonToSpec" in e) {
|
|
96
|
+
if (e.jsonToSpec.operation === "loopArray") {
|
|
97
|
+
const c = j({
|
|
98
|
+
inTemplate: e.jsonToSpec.template,
|
|
99
|
+
inDataAsArray: o[e.jsonToSpec.source]
|
|
100
|
+
}), {
|
|
101
|
+
jsonToSpec: r,
|
|
102
|
+
...s
|
|
103
|
+
} = e, l = {
|
|
104
|
+
...s,
|
|
105
|
+
children: c
|
|
106
|
+
};
|
|
107
|
+
return u({
|
|
108
|
+
inSpecJson: l,
|
|
109
|
+
inShowLog: n,
|
|
110
|
+
inData: o
|
|
111
|
+
});
|
|
112
|
+
}
|
|
113
|
+
if (e.jsonToSpec.operation === "loopObject") {
|
|
114
|
+
const c = S({
|
|
115
|
+
inTemplate: e.jsonToSpec.template,
|
|
116
|
+
inDataAsObject: o
|
|
117
|
+
}), {
|
|
118
|
+
jsonToSpec: r,
|
|
119
|
+
...s
|
|
120
|
+
} = e, l = {
|
|
121
|
+
...s,
|
|
122
|
+
children: c
|
|
123
|
+
};
|
|
124
|
+
return u({
|
|
125
|
+
inSpecJson: l,
|
|
126
|
+
inShowLog: n,
|
|
127
|
+
inData: o
|
|
128
|
+
});
|
|
129
|
+
}
|
|
130
|
+
}
|
|
131
|
+
return u({
|
|
132
|
+
inSpecJson: e,
|
|
133
|
+
inShowLog: n,
|
|
134
|
+
inData: o
|
|
135
|
+
});
|
|
136
|
+
}, T = ({
|
|
137
|
+
specJson: e,
|
|
138
|
+
showLog: n,
|
|
139
|
+
dataJson: o
|
|
140
|
+
}) => {
|
|
141
|
+
try {
|
|
142
|
+
return i({
|
|
143
|
+
inSpecJson: e,
|
|
144
|
+
inShowLog: n,
|
|
145
|
+
inDataJson: o
|
|
146
|
+
});
|
|
147
|
+
} catch (t) {
|
|
148
|
+
console.log("error : ", t);
|
|
149
|
+
}
|
|
150
|
+
};
|
|
151
|
+
d(T);
|
|
152
|
+
export {
|
|
153
|
+
T as default
|
|
154
|
+
};
|
package/docs/dist/v21/min.js
CHANGED
|
@@ -1,116 +1,116 @@
|
|
|
1
|
-
const u = {
|
|
2
|
-
version: "v21.0",
|
|
3
|
-
description: "Pure spec engine no document at all"
|
|
4
|
-
}, i = (e) => {
|
|
5
|
-
typeof globalThis > "u" || !e || (globalThis.ks ?? (globalThis.ks = {}), globalThis.ks["json-to-spec"] = {
|
|
6
|
-
meta: u,
|
|
7
|
-
buildSpecElement: e
|
|
8
|
-
});
|
|
9
|
-
}, f = ({ inSpec: e }) => {
|
|
10
|
-
const t = e;
|
|
11
|
-
return t == null;
|
|
12
|
-
}, d = ({ inSpec: e }) => typeof Node < "u" && e instanceof Node, p = ({ inSpecJson: e }) => Array.isArray(e), y = ({ inArray: e = [], inShowLog: t = !1, inDataJson: o }) => {
|
|
13
|
-
const r = e, l = t, n = o;
|
|
14
|
-
return Array.isArray(r) ? r.map((c) => a({
|
|
15
|
-
inSpecJson: c,
|
|
16
|
-
inShowLog: l,
|
|
17
|
-
inDataJson: n
|
|
18
|
-
})).flat().filter(Boolean) : [];
|
|
19
|
-
}, s = (e, t) => typeof e != "string" ? e : e.replace(/\$\{([^}]+)\}/g, (o, r) => {
|
|
20
|
-
const l = r.trim().split(".");
|
|
21
|
-
let n = t;
|
|
22
|
-
for (const c of l) {
|
|
23
|
-
if (n == null)
|
|
24
|
-
return "";
|
|
25
|
-
n = n[c];
|
|
26
|
-
}
|
|
27
|
-
return n === null || typeof n == "string" || typeof n == "number" || typeof n == "boolean" ? String(n ?? "") : n;
|
|
28
|
-
}), m = ({ inSpecJson: e, inData: t, inShowLog: o }) => ("key" in t && "value" in t ? "textContent" in e && (e.textContent = s(
|
|
29
|
-
e.textContent,
|
|
30
|
-
t
|
|
31
|
-
)) : ("textContent" in e && (e.textContent = s(
|
|
32
|
-
e.textContent,
|
|
33
|
-
t
|
|
34
|
-
)), "attributes" in e && (e.attributes = Object.fromEntries(
|
|
35
|
-
Object.entries(e.attributes).map(
|
|
36
|
-
([r, l]) => [
|
|
37
|
-
r,
|
|
38
|
-
s(l, t)
|
|
39
|
-
]
|
|
40
|
-
)
|
|
41
|
-
)), "children" in e && (e.children = e.children.map((r) => a({
|
|
42
|
-
inSpecJson: r,
|
|
43
|
-
inShowLog: o,
|
|
44
|
-
inDataJson: t
|
|
45
|
-
})))), e), b = ({ inTemplate: e, inDataAsArray: t }) => {
|
|
46
|
-
const o = t, r = e;
|
|
47
|
-
return o.map((n) => {
|
|
48
|
-
const c = structuredClone(r);
|
|
49
|
-
return a({
|
|
50
|
-
inSpecJson: c,
|
|
51
|
-
inDataJson: n
|
|
52
|
-
});
|
|
53
|
-
});
|
|
54
|
-
}, h = ({ inTemplate: e, inDataAsObject: t }) => {
|
|
55
|
-
let o = [];
|
|
56
|
-
console.log("11111111--------loopObject : ", t);
|
|
57
|
-
for (const [r, l] of Object.entries(t)) {
|
|
58
|
-
const n = structuredClone(e), c = a({
|
|
59
|
-
inSpecJson: n,
|
|
60
|
-
inDataJson: { key: r, value: l }
|
|
61
|
-
});
|
|
62
|
-
o.push(c);
|
|
63
|
-
}
|
|
64
|
-
return o;
|
|
65
|
-
}, a = ({ inSpecJson: e, inShowLog: t = !1, inDataJson: o } = {}) => {
|
|
66
|
-
if (f({ inSpec: e })) return null;
|
|
67
|
-
if (d({ inSpec: e })) return e;
|
|
68
|
-
if (p({ inSpecJson: e }))
|
|
69
|
-
return y({
|
|
70
|
-
inArray: e,
|
|
71
|
-
inShowLog: t,
|
|
72
|
-
inDataJson: o
|
|
73
|
-
});
|
|
74
|
-
if ("jsonToSpec" in e) {
|
|
75
|
-
if ("isSpecBuilt" in e)
|
|
76
|
-
return e;
|
|
77
|
-
if (e.jsonToSpec.operation === "loopArray") {
|
|
78
|
-
const r = b({
|
|
79
|
-
inTemplate: e.jsonToSpec.template,
|
|
80
|
-
inDataAsArray: o[e.jsonToSpec.source]
|
|
81
|
-
});
|
|
82
|
-
e.children = r;
|
|
83
|
-
}
|
|
84
|
-
if (e.jsonToSpec.operation === "loopObject") {
|
|
85
|
-
const r = h({
|
|
86
|
-
inTemplate: e.jsonToSpec.template,
|
|
87
|
-
inDataAsObject: o
|
|
88
|
-
});
|
|
89
|
-
e.children = r;
|
|
90
|
-
}
|
|
91
|
-
e.isSpecBuilt = !0;
|
|
92
|
-
}
|
|
93
|
-
return m({
|
|
94
|
-
inSpecJson: e,
|
|
95
|
-
inShowLog: t,
|
|
96
|
-
inData: o
|
|
97
|
-
});
|
|
98
|
-
}, A = ({
|
|
99
|
-
specJson: e,
|
|
100
|
-
showLog: t,
|
|
101
|
-
dataJson: o
|
|
102
|
-
}) => {
|
|
103
|
-
try {
|
|
104
|
-
return a({
|
|
105
|
-
inSpecJson: e,
|
|
106
|
-
inShowLog: t,
|
|
107
|
-
inDataJson: o
|
|
108
|
-
});
|
|
109
|
-
} catch (r) {
|
|
110
|
-
console.log("error : ", r);
|
|
111
|
-
}
|
|
112
|
-
};
|
|
113
|
-
i(A);
|
|
114
|
-
export {
|
|
115
|
-
A as default
|
|
116
|
-
};
|
|
1
|
+
const u = {
|
|
2
|
+
version: "v21.0",
|
|
3
|
+
description: "Pure spec engine no document at all"
|
|
4
|
+
}, i = (e) => {
|
|
5
|
+
typeof globalThis > "u" || !e || (globalThis.ks ?? (globalThis.ks = {}), globalThis.ks["json-to-spec"] = {
|
|
6
|
+
meta: u,
|
|
7
|
+
buildSpecElement: e
|
|
8
|
+
});
|
|
9
|
+
}, f = ({ inSpec: e }) => {
|
|
10
|
+
const t = e;
|
|
11
|
+
return t == null;
|
|
12
|
+
}, d = ({ inSpec: e }) => typeof Node < "u" && e instanceof Node, p = ({ inSpecJson: e }) => Array.isArray(e), y = ({ inArray: e = [], inShowLog: t = !1, inDataJson: o }) => {
|
|
13
|
+
const r = e, l = t, n = o;
|
|
14
|
+
return Array.isArray(r) ? r.map((c) => a({
|
|
15
|
+
inSpecJson: c,
|
|
16
|
+
inShowLog: l,
|
|
17
|
+
inDataJson: n
|
|
18
|
+
})).flat().filter(Boolean) : [];
|
|
19
|
+
}, s = (e, t) => typeof e != "string" ? e : e.replace(/\$\{([^}]+)\}/g, (o, r) => {
|
|
20
|
+
const l = r.trim().split(".");
|
|
21
|
+
let n = t;
|
|
22
|
+
for (const c of l) {
|
|
23
|
+
if (n == null)
|
|
24
|
+
return "";
|
|
25
|
+
n = n[c];
|
|
26
|
+
}
|
|
27
|
+
return n === null || typeof n == "string" || typeof n == "number" || typeof n == "boolean" ? String(n ?? "") : n;
|
|
28
|
+
}), m = ({ inSpecJson: e, inData: t, inShowLog: o }) => ("key" in t && "value" in t ? "textContent" in e && (e.textContent = s(
|
|
29
|
+
e.textContent,
|
|
30
|
+
t
|
|
31
|
+
)) : ("textContent" in e && (e.textContent = s(
|
|
32
|
+
e.textContent,
|
|
33
|
+
t
|
|
34
|
+
)), "attributes" in e && (e.attributes = Object.fromEntries(
|
|
35
|
+
Object.entries(e.attributes).map(
|
|
36
|
+
([r, l]) => [
|
|
37
|
+
r,
|
|
38
|
+
s(l, t)
|
|
39
|
+
]
|
|
40
|
+
)
|
|
41
|
+
)), "children" in e && (e.children = e.children.map((r) => a({
|
|
42
|
+
inSpecJson: r,
|
|
43
|
+
inShowLog: o,
|
|
44
|
+
inDataJson: t
|
|
45
|
+
})))), e), b = ({ inTemplate: e, inDataAsArray: t }) => {
|
|
46
|
+
const o = t, r = e;
|
|
47
|
+
return o.map((n) => {
|
|
48
|
+
const c = structuredClone(r);
|
|
49
|
+
return a({
|
|
50
|
+
inSpecJson: c,
|
|
51
|
+
inDataJson: n
|
|
52
|
+
});
|
|
53
|
+
});
|
|
54
|
+
}, h = ({ inTemplate: e, inDataAsObject: t }) => {
|
|
55
|
+
let o = [];
|
|
56
|
+
console.log("11111111--------loopObject : ", t);
|
|
57
|
+
for (const [r, l] of Object.entries(t)) {
|
|
58
|
+
const n = structuredClone(e), c = a({
|
|
59
|
+
inSpecJson: n,
|
|
60
|
+
inDataJson: { key: r, value: l }
|
|
61
|
+
});
|
|
62
|
+
o.push(c);
|
|
63
|
+
}
|
|
64
|
+
return o;
|
|
65
|
+
}, a = ({ inSpecJson: e, inShowLog: t = !1, inDataJson: o } = {}) => {
|
|
66
|
+
if (f({ inSpec: e })) return null;
|
|
67
|
+
if (d({ inSpec: e })) return e;
|
|
68
|
+
if (p({ inSpecJson: e }))
|
|
69
|
+
return y({
|
|
70
|
+
inArray: e,
|
|
71
|
+
inShowLog: t,
|
|
72
|
+
inDataJson: o
|
|
73
|
+
});
|
|
74
|
+
if ("jsonToSpec" in e) {
|
|
75
|
+
if ("isSpecBuilt" in e)
|
|
76
|
+
return e;
|
|
77
|
+
if (e.jsonToSpec.operation === "loopArray") {
|
|
78
|
+
const r = b({
|
|
79
|
+
inTemplate: e.jsonToSpec.template,
|
|
80
|
+
inDataAsArray: o[e.jsonToSpec.source]
|
|
81
|
+
});
|
|
82
|
+
e.children = r;
|
|
83
|
+
}
|
|
84
|
+
if (e.jsonToSpec.operation === "loopObject") {
|
|
85
|
+
const r = h({
|
|
86
|
+
inTemplate: e.jsonToSpec.template,
|
|
87
|
+
inDataAsObject: o
|
|
88
|
+
});
|
|
89
|
+
e.children = r;
|
|
90
|
+
}
|
|
91
|
+
e.isSpecBuilt = !0;
|
|
92
|
+
}
|
|
93
|
+
return m({
|
|
94
|
+
inSpecJson: e,
|
|
95
|
+
inShowLog: t,
|
|
96
|
+
inData: o
|
|
97
|
+
});
|
|
98
|
+
}, A = ({
|
|
99
|
+
specJson: e,
|
|
100
|
+
showLog: t,
|
|
101
|
+
dataJson: o
|
|
102
|
+
}) => {
|
|
103
|
+
try {
|
|
104
|
+
return a({
|
|
105
|
+
inSpecJson: e,
|
|
106
|
+
inShowLog: t,
|
|
107
|
+
inDataJson: o
|
|
108
|
+
});
|
|
109
|
+
} catch (r) {
|
|
110
|
+
console.log("error : ", r);
|
|
111
|
+
}
|
|
112
|
+
};
|
|
113
|
+
i(A);
|
|
114
|
+
export {
|
|
115
|
+
A as default
|
|
116
|
+
};
|
|
@@ -0,0 +1,154 @@
|
|
|
1
|
+
const f = {
|
|
2
|
+
version: "v23.0",
|
|
3
|
+
description: "Pure spec engine no document at all"
|
|
4
|
+
}, d = (e) => {
|
|
5
|
+
typeof globalThis > "u" || !e || (globalThis.ks ?? (globalThis.ks = {}), globalThis.ks["json-to-spec"] = {
|
|
6
|
+
meta: f,
|
|
7
|
+
buildSpecElement: e
|
|
8
|
+
});
|
|
9
|
+
}, y = ({ inSpec: e }) => {
|
|
10
|
+
const n = e;
|
|
11
|
+
return n == null;
|
|
12
|
+
}, m = ({ inSpec: e }) => typeof Node < "u" && e instanceof Node, b = ({ inSpecJson: e }) => Array.isArray(e), A = ({ inArray: e = [], inShowLog: n = !1, inDataJson: o }) => {
|
|
13
|
+
const t = e, c = n, r = o;
|
|
14
|
+
return Array.isArray(t) ? t.map((s) => i({
|
|
15
|
+
inSpecJson: s,
|
|
16
|
+
inShowLog: c,
|
|
17
|
+
inDataJson: r
|
|
18
|
+
})).flat().filter(Boolean) : [];
|
|
19
|
+
}, a = (e, n) => typeof e != "string" ? e : e.replace(/\$\{([^}]+)\}/g, (o, t) => {
|
|
20
|
+
const c = t.trim().split(".");
|
|
21
|
+
let r = n;
|
|
22
|
+
for (const s of c) {
|
|
23
|
+
if (r == null)
|
|
24
|
+
return "";
|
|
25
|
+
r = r[s];
|
|
26
|
+
}
|
|
27
|
+
return r === null || typeof r == "string" || typeof r == "number" || typeof r == "boolean" ? String(r ?? "") : r;
|
|
28
|
+
}), u = ({ inSpecJson: e, inData: n, inShowLog: o }) => {
|
|
29
|
+
const t = structuredClone(e);
|
|
30
|
+
return typeof n == "string" ? ("textContent" in t && (t.textContent === "${}" ? t.textContent = n : typeof t.textContent == "string" && (t.textContent = t.textContent.replaceAll("${}", () => n))), "attributes" in t && (t.attributes = Object.fromEntries(
|
|
31
|
+
Object.entries(t.attributes).map(
|
|
32
|
+
([c, r]) => [
|
|
33
|
+
c,
|
|
34
|
+
r === "${}" ? n : typeof r == "string" ? r.replaceAll("${}", () => n) : r
|
|
35
|
+
]
|
|
36
|
+
)
|
|
37
|
+
))) : "key" in n && "value" in n ? "textContent" in t && (t.textContent = a(
|
|
38
|
+
t.textContent,
|
|
39
|
+
n
|
|
40
|
+
)) : ("textContent" in t && (t.textContent = a(
|
|
41
|
+
t.textContent,
|
|
42
|
+
n
|
|
43
|
+
)), "attributes" in t && (t.attributes = Object.fromEntries(
|
|
44
|
+
Object.entries(t.attributes).map(
|
|
45
|
+
([c, r]) => [
|
|
46
|
+
c,
|
|
47
|
+
a(r, n)
|
|
48
|
+
]
|
|
49
|
+
)
|
|
50
|
+
)), "children" in t && (t.children = t.children.map((c) => i({
|
|
51
|
+
inSpecJson: c,
|
|
52
|
+
inShowLog: o,
|
|
53
|
+
inDataJson: n
|
|
54
|
+
})))), t;
|
|
55
|
+
}, j = ({ inTemplate: e, inDataAsArray: n }) => {
|
|
56
|
+
const o = n, t = e;
|
|
57
|
+
return Array.isArray(o) ? o.map((r) => {
|
|
58
|
+
const s = structuredClone(t);
|
|
59
|
+
return i({
|
|
60
|
+
inSpecJson: s,
|
|
61
|
+
inDataJson: r
|
|
62
|
+
});
|
|
63
|
+
}) : [];
|
|
64
|
+
}, S = ({ inTemplate: e, inDataAsObject: n }) => {
|
|
65
|
+
const o = n, t = e;
|
|
66
|
+
if (o === null || typeof o != "object")
|
|
67
|
+
return [];
|
|
68
|
+
const c = [];
|
|
69
|
+
for (const [r, s] of Object.entries(o)) {
|
|
70
|
+
const l = structuredClone(t), p = i({
|
|
71
|
+
inSpecJson: l,
|
|
72
|
+
inDataJson: {
|
|
73
|
+
key: r,
|
|
74
|
+
value: s
|
|
75
|
+
}
|
|
76
|
+
});
|
|
77
|
+
c.push(p);
|
|
78
|
+
}
|
|
79
|
+
return c;
|
|
80
|
+
}, i = ({
|
|
81
|
+
inSpecJson: e,
|
|
82
|
+
inShowLog: n = !1,
|
|
83
|
+
inDataJson: o
|
|
84
|
+
} = {}) => {
|
|
85
|
+
if (y({ inSpec: e }))
|
|
86
|
+
return null;
|
|
87
|
+
if (m({ inSpec: e }))
|
|
88
|
+
return e;
|
|
89
|
+
if (b({ inSpecJson: e }))
|
|
90
|
+
return A({
|
|
91
|
+
inArray: e,
|
|
92
|
+
inShowLog: n,
|
|
93
|
+
inDataJson: o
|
|
94
|
+
});
|
|
95
|
+
if ("jsonToSpec" in e) {
|
|
96
|
+
if (e.jsonToSpec.operation === "loopArray") {
|
|
97
|
+
const c = j({
|
|
98
|
+
inTemplate: e.jsonToSpec.template,
|
|
99
|
+
inDataAsArray: o[e.jsonToSpec.source]
|
|
100
|
+
}), {
|
|
101
|
+
jsonToSpec: r,
|
|
102
|
+
...s
|
|
103
|
+
} = e, l = {
|
|
104
|
+
...s,
|
|
105
|
+
children: c
|
|
106
|
+
};
|
|
107
|
+
return u({
|
|
108
|
+
inSpecJson: l,
|
|
109
|
+
inShowLog: n,
|
|
110
|
+
inData: o
|
|
111
|
+
});
|
|
112
|
+
}
|
|
113
|
+
if (e.jsonToSpec.operation === "loopObject") {
|
|
114
|
+
const c = S({
|
|
115
|
+
inTemplate: e.jsonToSpec.template,
|
|
116
|
+
inDataAsObject: o
|
|
117
|
+
}), {
|
|
118
|
+
jsonToSpec: r,
|
|
119
|
+
...s
|
|
120
|
+
} = e, l = {
|
|
121
|
+
...s,
|
|
122
|
+
children: c
|
|
123
|
+
};
|
|
124
|
+
return u({
|
|
125
|
+
inSpecJson: l,
|
|
126
|
+
inShowLog: n,
|
|
127
|
+
inData: o
|
|
128
|
+
});
|
|
129
|
+
}
|
|
130
|
+
}
|
|
131
|
+
return u({
|
|
132
|
+
inSpecJson: e,
|
|
133
|
+
inShowLog: n,
|
|
134
|
+
inData: o
|
|
135
|
+
});
|
|
136
|
+
}, T = ({
|
|
137
|
+
specJson: e,
|
|
138
|
+
showLog: n,
|
|
139
|
+
dataJson: o
|
|
140
|
+
}) => {
|
|
141
|
+
try {
|
|
142
|
+
return i({
|
|
143
|
+
inSpecJson: e,
|
|
144
|
+
inShowLog: n,
|
|
145
|
+
inDataJson: o
|
|
146
|
+
});
|
|
147
|
+
} catch (t) {
|
|
148
|
+
console.log("error : ", t);
|
|
149
|
+
}
|
|
150
|
+
};
|
|
151
|
+
d(T);
|
|
152
|
+
export {
|
|
153
|
+
T as default
|
|
154
|
+
};
|
package/package.json
CHANGED
|
@@ -1,9 +1,9 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "json-to-spec",
|
|
3
|
-
"version": "
|
|
3
|
+
"version": "24.1.1",
|
|
4
4
|
"description": "Pure JSON Specification Compiler with jsonToSpec namespace: (structure, data) -> Spec JSON",
|
|
5
|
-
"main": "src/
|
|
6
|
-
"module": "./src/
|
|
5
|
+
"main": "src/v24/index.js",
|
|
6
|
+
"module": "./src/v24/index.js",
|
|
7
7
|
"files": [
|
|
8
8
|
"index.js",
|
|
9
9
|
"src",
|
|
@@ -35,9 +35,9 @@
|
|
|
35
35
|
"type": "module",
|
|
36
36
|
"exports": {
|
|
37
37
|
".": {
|
|
38
|
-
"import": "./src/
|
|
39
|
-
"require": "./src/
|
|
40
|
-
"default": "./src/
|
|
38
|
+
"import": "./src/v24/index.js",
|
|
39
|
+
"require": "./src/v24/index.js",
|
|
40
|
+
"default": "./src/v24/index.js"
|
|
41
41
|
}
|
|
42
42
|
},
|
|
43
43
|
"bugs": {
|