@spirobel/mininext 0.2.14 → 0.2.15
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/README.md +6 -0
- package/dist/html.js +22 -0
- package/mininext/html.ts +18 -0
- package/package.json +1 -1
package/README.md
CHANGED
package/dist/html.js
CHANGED
|
@@ -13,6 +13,16 @@ export class HtmlString extends Array {
|
|
|
13
13
|
if (resolvedHtmlPiece instanceof HtmlString) {
|
|
14
14
|
resolvedHtmlPiece = await resolvedHtmlPiece.resolve(mini);
|
|
15
15
|
}
|
|
16
|
+
else {
|
|
17
|
+
if (this instanceof JsonString) {
|
|
18
|
+
resolvedHtmlPiece = JSON.stringify(resolvedHtmlPiece);
|
|
19
|
+
}
|
|
20
|
+
else {
|
|
21
|
+
const notEmpty = resolvedHtmlPiece || "";
|
|
22
|
+
// values will be escaped by default
|
|
23
|
+
resolvedHtmlPiece = Bun.escapeHTML(notEmpty + "");
|
|
24
|
+
}
|
|
25
|
+
}
|
|
16
26
|
// Replace the function with the resolved HTML piece in place
|
|
17
27
|
this[index] = resolvedHtmlPiece;
|
|
18
28
|
}
|
|
@@ -40,6 +50,7 @@ export function html(strings, ...values) {
|
|
|
40
50
|
value.every((val) => val instanceof HtmlString)) {
|
|
41
51
|
// If the value is an array of HtmlString objects, add the whole array as a single value
|
|
42
52
|
values[index] = value;
|
|
53
|
+
htmlStringArray.resolved = false; // we could bother with .find here
|
|
43
54
|
}
|
|
44
55
|
else if (typeof value === "function") {
|
|
45
56
|
htmlStringArray.resolved = false;
|
|
@@ -57,6 +68,11 @@ export function html(strings, ...values) {
|
|
|
57
68
|
// values will be escaped by default
|
|
58
69
|
values[index] = Bun.escapeHTML(notEmpty + "");
|
|
59
70
|
}
|
|
71
|
+
else if (value instanceof HtmlString) {
|
|
72
|
+
if (!value.resolved) {
|
|
73
|
+
htmlStringArray.resolved = false;
|
|
74
|
+
}
|
|
75
|
+
}
|
|
60
76
|
htmlStringArray.push(values[index]);
|
|
61
77
|
}
|
|
62
78
|
}
|
|
@@ -84,6 +100,7 @@ function JsonTemplateProcessor(danger = false) {
|
|
|
84
100
|
value.every((val) => val instanceof HtmlString)) {
|
|
85
101
|
// If the value is an array of HtmlString objects, add the whole array as a single value
|
|
86
102
|
values[index] = value;
|
|
103
|
+
jsonStringArray.resolved = false; // we could bother with .find here
|
|
87
104
|
}
|
|
88
105
|
else if (typeof value === "function") {
|
|
89
106
|
jsonStringArray.resolved = false;
|
|
@@ -94,6 +111,11 @@ function JsonTemplateProcessor(danger = false) {
|
|
|
94
111
|
// values will be turned into a JSON string
|
|
95
112
|
values[index] = JSON.stringify(notEmpty);
|
|
96
113
|
}
|
|
114
|
+
else if (value instanceof HtmlString) {
|
|
115
|
+
if (!value.resolved) {
|
|
116
|
+
jsonStringArray.resolved = false;
|
|
117
|
+
}
|
|
118
|
+
}
|
|
97
119
|
jsonStringArray.push(values[index]);
|
|
98
120
|
}
|
|
99
121
|
}
|
package/mininext/html.ts
CHANGED
|
@@ -30,6 +30,14 @@ export class HtmlString extends Array {
|
|
|
30
30
|
let resolvedHtmlPiece = await htmlPiece(mini); //passing mini
|
|
31
31
|
if (resolvedHtmlPiece instanceof HtmlString) {
|
|
32
32
|
resolvedHtmlPiece = await resolvedHtmlPiece.resolve(mini);
|
|
33
|
+
} else {
|
|
34
|
+
if (this instanceof JsonString) {
|
|
35
|
+
resolvedHtmlPiece = JSON.stringify(resolvedHtmlPiece);
|
|
36
|
+
} else {
|
|
37
|
+
const notEmpty = resolvedHtmlPiece || "";
|
|
38
|
+
// values will be escaped by default
|
|
39
|
+
resolvedHtmlPiece = Bun.escapeHTML(notEmpty + "");
|
|
40
|
+
}
|
|
33
41
|
}
|
|
34
42
|
// Replace the function with the resolved HTML piece in place
|
|
35
43
|
this[index] = resolvedHtmlPiece;
|
|
@@ -67,6 +75,7 @@ export function html<X = undefined>(
|
|
|
67
75
|
) {
|
|
68
76
|
// If the value is an array of HtmlString objects, add the whole array as a single value
|
|
69
77
|
values[index] = value;
|
|
78
|
+
htmlStringArray.resolved = false; // we could bother with .find here
|
|
70
79
|
} else if (typeof value === "function") {
|
|
71
80
|
htmlStringArray.resolved = false;
|
|
72
81
|
values[index] = value;
|
|
@@ -80,6 +89,10 @@ export function html<X = undefined>(
|
|
|
80
89
|
const notEmpty = value || "";
|
|
81
90
|
// values will be escaped by default
|
|
82
91
|
values[index] = Bun.escapeHTML(notEmpty + "");
|
|
92
|
+
} else if (value instanceof HtmlString) {
|
|
93
|
+
if (!value.resolved) {
|
|
94
|
+
htmlStringArray.resolved = false;
|
|
95
|
+
}
|
|
83
96
|
}
|
|
84
97
|
htmlStringArray.push(values[index]);
|
|
85
98
|
}
|
|
@@ -128,6 +141,7 @@ function JsonTemplateProcessor(danger: boolean = false) {
|
|
|
128
141
|
) {
|
|
129
142
|
// If the value is an array of HtmlString objects, add the whole array as a single value
|
|
130
143
|
values[index] = value;
|
|
144
|
+
jsonStringArray.resolved = false; // we could bother with .find here
|
|
131
145
|
} else if (typeof value === "function") {
|
|
132
146
|
jsonStringArray.resolved = false;
|
|
133
147
|
values[index] = value;
|
|
@@ -135,6 +149,10 @@ function JsonTemplateProcessor(danger: boolean = false) {
|
|
|
135
149
|
const notEmpty = value || "";
|
|
136
150
|
// values will be turned into a JSON string
|
|
137
151
|
values[index] = JSON.stringify(notEmpty);
|
|
152
|
+
} else if (value instanceof HtmlString) {
|
|
153
|
+
if (!value.resolved) {
|
|
154
|
+
jsonStringArray.resolved = false;
|
|
155
|
+
}
|
|
138
156
|
}
|
|
139
157
|
jsonStringArray.push(values[index]);
|
|
140
158
|
}
|