ghtml 3.0.10 → 3.0.13
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/package.json +2 -2
- package/src/index.js +42 -34
package/package.json
CHANGED
|
@@ -3,7 +3,7 @@
|
|
|
3
3
|
"description": "Replace your template engine with fast JavaScript by leveraging the power of tagged templates.",
|
|
4
4
|
"author": "Gürgün Dayıoğlu",
|
|
5
5
|
"license": "MIT",
|
|
6
|
-
"version": "3.0.
|
|
6
|
+
"version": "3.0.13",
|
|
7
7
|
"type": "module",
|
|
8
8
|
"bin": "./bin/src/index.js",
|
|
9
9
|
"main": "./src/index.js",
|
|
@@ -27,7 +27,7 @@
|
|
|
27
27
|
"devDependencies": {
|
|
28
28
|
"@fastify/pre-commit": "^2.1.0",
|
|
29
29
|
"c8": "^10.1.2",
|
|
30
|
-
"grules": "^0.25.
|
|
30
|
+
"grules": "^0.25.10",
|
|
31
31
|
"tinybench": "^2.9.0",
|
|
32
32
|
"typescript": ">=5.6.2"
|
|
33
33
|
},
|
package/src/index.js
CHANGED
|
@@ -1,3 +1,8 @@
|
|
|
1
|
+
const _isArray = Array.isArray;
|
|
2
|
+
|
|
3
|
+
const _iterator = Symbol.iterator;
|
|
4
|
+
const _asyncIterator = Symbol.asyncIterator;
|
|
5
|
+
|
|
1
6
|
const escapeRegExp = /["&'<=>]/g;
|
|
2
7
|
|
|
3
8
|
const escapeFunction = (string) => {
|
|
@@ -56,14 +61,14 @@ export const html = (literals, ...expressions) => {
|
|
|
56
61
|
|
|
57
62
|
for (let i = 0; i !== expressions.length; ++i) {
|
|
58
63
|
let literal = literals.raw[i];
|
|
59
|
-
let string =
|
|
64
|
+
let string = _isArray(expressions[i])
|
|
60
65
|
? expressions[i].join("")
|
|
61
|
-
:
|
|
66
|
+
: `${expressions[i] ?? ""}`;
|
|
62
67
|
|
|
63
|
-
if (literal && literal.charCodeAt(literal.length - 1) === 33) {
|
|
68
|
+
if (literal.length !== 0 && literal.charCodeAt(literal.length - 1) === 33) {
|
|
64
69
|
literal = literal.slice(0, -1);
|
|
65
|
-
} else {
|
|
66
|
-
string
|
|
70
|
+
} else if (string.length !== 0) {
|
|
71
|
+
string = escapeFunction(string);
|
|
67
72
|
}
|
|
68
73
|
|
|
69
74
|
accumulator += literal + string;
|
|
@@ -89,15 +94,15 @@ export const htmlGenerator = function* (literals, ...expressions) {
|
|
|
89
94
|
} else if (expression === undefined || expression === null) {
|
|
90
95
|
string = "";
|
|
91
96
|
} else {
|
|
92
|
-
if (expression[
|
|
97
|
+
if (typeof expression[_iterator] === "function") {
|
|
93
98
|
const isRaw =
|
|
94
|
-
|
|
99
|
+
literal.length !== 0 && literal.charCodeAt(literal.length - 1) === 33;
|
|
95
100
|
|
|
96
101
|
if (isRaw) {
|
|
97
102
|
literal = literal.slice(0, -1);
|
|
98
103
|
}
|
|
99
104
|
|
|
100
|
-
if (literal) {
|
|
105
|
+
if (literal.length !== 0) {
|
|
101
106
|
yield literal;
|
|
102
107
|
}
|
|
103
108
|
|
|
@@ -109,15 +114,15 @@ export const htmlGenerator = function* (literals, ...expressions) {
|
|
|
109
114
|
continue;
|
|
110
115
|
}
|
|
111
116
|
|
|
112
|
-
if (expression[
|
|
117
|
+
if (typeof expression[_iterator] === "function") {
|
|
113
118
|
for (expression of expression) {
|
|
114
119
|
if (expression === undefined || expression === null) {
|
|
115
120
|
continue;
|
|
116
121
|
}
|
|
117
122
|
|
|
118
|
-
string =
|
|
123
|
+
string = `${expression}`;
|
|
119
124
|
|
|
120
|
-
if (string) {
|
|
125
|
+
if (string.length !== 0) {
|
|
121
126
|
if (!isRaw) {
|
|
122
127
|
string = escapeFunction(string);
|
|
123
128
|
}
|
|
@@ -129,10 +134,10 @@ export const htmlGenerator = function* (literals, ...expressions) {
|
|
|
129
134
|
continue;
|
|
130
135
|
}
|
|
131
136
|
|
|
132
|
-
string =
|
|
137
|
+
string = `${expression}`;
|
|
133
138
|
}
|
|
134
139
|
|
|
135
|
-
if (string) {
|
|
140
|
+
if (string.length !== 0) {
|
|
136
141
|
if (!isRaw) {
|
|
137
142
|
string = escapeFunction(string);
|
|
138
143
|
}
|
|
@@ -144,21 +149,21 @@ export const htmlGenerator = function* (literals, ...expressions) {
|
|
|
144
149
|
continue;
|
|
145
150
|
}
|
|
146
151
|
|
|
147
|
-
string =
|
|
152
|
+
string = `${expression}`;
|
|
148
153
|
}
|
|
149
154
|
|
|
150
|
-
if (literal && literal.charCodeAt(literal.length - 1) === 33) {
|
|
155
|
+
if (literal.length !== 0 && literal.charCodeAt(literal.length - 1) === 33) {
|
|
151
156
|
literal = literal.slice(0, -1);
|
|
152
|
-
} else {
|
|
153
|
-
string
|
|
157
|
+
} else if (string.length !== 0) {
|
|
158
|
+
string = escapeFunction(string);
|
|
154
159
|
}
|
|
155
160
|
|
|
156
|
-
if (literal || string) {
|
|
161
|
+
if (literal.length !== 0 || string.length !== 0) {
|
|
157
162
|
yield literal + string;
|
|
158
163
|
}
|
|
159
164
|
}
|
|
160
165
|
|
|
161
|
-
if (literals.raw[expressions.length]) {
|
|
166
|
+
if (literals.raw[expressions.length].length !== 0) {
|
|
162
167
|
yield literals.raw[expressions.length];
|
|
163
168
|
}
|
|
164
169
|
};
|
|
@@ -180,15 +185,18 @@ export const htmlAsyncGenerator = async function* (literals, ...expressions) {
|
|
|
180
185
|
} else if (expression === undefined || expression === null) {
|
|
181
186
|
string = "";
|
|
182
187
|
} else {
|
|
183
|
-
if (
|
|
188
|
+
if (
|
|
189
|
+
typeof expression[_iterator] === "function" ||
|
|
190
|
+
typeof expression[_asyncIterator] === "function"
|
|
191
|
+
) {
|
|
184
192
|
const isRaw =
|
|
185
|
-
|
|
193
|
+
literal.length !== 0 && literal.charCodeAt(literal.length - 1) === 33;
|
|
186
194
|
|
|
187
195
|
if (isRaw) {
|
|
188
196
|
literal = literal.slice(0, -1);
|
|
189
197
|
}
|
|
190
198
|
|
|
191
|
-
if (literal) {
|
|
199
|
+
if (literal.length !== 0) {
|
|
192
200
|
yield literal;
|
|
193
201
|
}
|
|
194
202
|
|
|
@@ -201,17 +209,17 @@ export const htmlAsyncGenerator = async function* (literals, ...expressions) {
|
|
|
201
209
|
}
|
|
202
210
|
|
|
203
211
|
if (
|
|
204
|
-
expression[
|
|
205
|
-
expression[
|
|
212
|
+
typeof expression[_iterator] === "function" ||
|
|
213
|
+
typeof expression[_asyncIterator] === "function"
|
|
206
214
|
) {
|
|
207
215
|
for await (expression of expression) {
|
|
208
216
|
if (expression === undefined || expression === null) {
|
|
209
217
|
continue;
|
|
210
218
|
}
|
|
211
219
|
|
|
212
|
-
string =
|
|
220
|
+
string = `${expression}`;
|
|
213
221
|
|
|
214
|
-
if (string) {
|
|
222
|
+
if (string.length !== 0) {
|
|
215
223
|
if (!isRaw) {
|
|
216
224
|
string = escapeFunction(string);
|
|
217
225
|
}
|
|
@@ -223,10 +231,10 @@ export const htmlAsyncGenerator = async function* (literals, ...expressions) {
|
|
|
223
231
|
continue;
|
|
224
232
|
}
|
|
225
233
|
|
|
226
|
-
string =
|
|
234
|
+
string = `${expression}`;
|
|
227
235
|
}
|
|
228
236
|
|
|
229
|
-
if (string) {
|
|
237
|
+
if (string.length !== 0) {
|
|
230
238
|
if (!isRaw) {
|
|
231
239
|
string = escapeFunction(string);
|
|
232
240
|
}
|
|
@@ -238,21 +246,21 @@ export const htmlAsyncGenerator = async function* (literals, ...expressions) {
|
|
|
238
246
|
continue;
|
|
239
247
|
}
|
|
240
248
|
|
|
241
|
-
string =
|
|
249
|
+
string = `${expression}`;
|
|
242
250
|
}
|
|
243
251
|
|
|
244
|
-
if (literal && literal.charCodeAt(literal.length - 1) === 33) {
|
|
252
|
+
if (literal.length !== 0 && literal.charCodeAt(literal.length - 1) === 33) {
|
|
245
253
|
literal = literal.slice(0, -1);
|
|
246
|
-
} else {
|
|
247
|
-
string
|
|
254
|
+
} else if (string.length !== 0) {
|
|
255
|
+
string = escapeFunction(string);
|
|
248
256
|
}
|
|
249
257
|
|
|
250
|
-
if (literal || string) {
|
|
258
|
+
if (literal.length !== 0 || string.length !== 0) {
|
|
251
259
|
yield literal + string;
|
|
252
260
|
}
|
|
253
261
|
}
|
|
254
262
|
|
|
255
|
-
if (literals.raw[expressions.length]) {
|
|
263
|
+
if (literals.raw[expressions.length].length !== 0) {
|
|
256
264
|
yield literals.raw[expressions.length];
|
|
257
265
|
}
|
|
258
266
|
};
|