ghtml 3.1.3 → 3.1.4
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 +19 -10
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.1.
|
|
6
|
+
"version": "3.1.4",
|
|
7
7
|
"type": "commonjs",
|
|
8
8
|
"bin": "./bin/src/index.js",
|
|
9
9
|
"main": "./src/index.js",
|
|
@@ -29,7 +29,7 @@
|
|
|
29
29
|
"c8": "^10.1.2",
|
|
30
30
|
"globals": "^16.0.0",
|
|
31
31
|
"grules": "^0.26.1",
|
|
32
|
-
"tinybench": "^
|
|
32
|
+
"tinybench": "^5.0.1",
|
|
33
33
|
"typescript": ">=5.7.2"
|
|
34
34
|
},
|
|
35
35
|
"repository": {
|
package/src/index.js
CHANGED
|
@@ -3,10 +3,14 @@
|
|
|
3
3
|
const escapeRegExp = /["&'<=>]/g;
|
|
4
4
|
|
|
5
5
|
const escapeFunction = (string) => {
|
|
6
|
+
if (!escapeRegExp.test(string)) {
|
|
7
|
+
return string;
|
|
8
|
+
}
|
|
9
|
+
|
|
6
10
|
let escaped = "";
|
|
7
11
|
let start = 0;
|
|
8
12
|
|
|
9
|
-
|
|
13
|
+
do {
|
|
10
14
|
const i = escapeRegExp.lastIndex - 1;
|
|
11
15
|
|
|
12
16
|
switch (string.charCodeAt(i)) {
|
|
@@ -43,7 +47,7 @@ const escapeFunction = (string) => {
|
|
|
43
47
|
}
|
|
44
48
|
|
|
45
49
|
start = escapeRegExp.lastIndex;
|
|
46
|
-
}
|
|
50
|
+
} while (escapeRegExp.test(string));
|
|
47
51
|
|
|
48
52
|
return escaped + string.slice(start);
|
|
49
53
|
};
|
|
@@ -55,8 +59,9 @@ const escapeFunction = (string) => {
|
|
|
55
59
|
*/
|
|
56
60
|
const html = (literals, ...expressions) => {
|
|
57
61
|
let accumulator = "";
|
|
62
|
+
const expressionsLength = expressions.length;
|
|
58
63
|
|
|
59
|
-
for (let i = 0; i
|
|
64
|
+
for (let i = 0; i < expressionsLength; ++i) {
|
|
60
65
|
let literal = literals.raw[i];
|
|
61
66
|
let string =
|
|
62
67
|
typeof expressions[i] === "string"
|
|
@@ -76,7 +81,7 @@ const html = (literals, ...expressions) => {
|
|
|
76
81
|
accumulator += literal + string;
|
|
77
82
|
}
|
|
78
83
|
|
|
79
|
-
return accumulator + literals.raw[
|
|
84
|
+
return accumulator + literals.raw[expressionsLength];
|
|
80
85
|
};
|
|
81
86
|
|
|
82
87
|
/**
|
|
@@ -86,7 +91,9 @@ const html = (literals, ...expressions) => {
|
|
|
86
91
|
* @returns {Generator<string, void, void>} Generator<string, void, void>
|
|
87
92
|
*/
|
|
88
93
|
const htmlGenerator = function* (literals, ...expressions) {
|
|
89
|
-
|
|
94
|
+
const expressionsLength = expressions.length;
|
|
95
|
+
|
|
96
|
+
for (let i = 0; i < expressionsLength; ++i) {
|
|
90
97
|
let expression = expressions[i];
|
|
91
98
|
let literal = literals.raw[i];
|
|
92
99
|
let string;
|
|
@@ -165,8 +172,8 @@ const htmlGenerator = function* (literals, ...expressions) {
|
|
|
165
172
|
}
|
|
166
173
|
}
|
|
167
174
|
|
|
168
|
-
if (literals.raw[
|
|
169
|
-
yield literals.raw[
|
|
175
|
+
if (literals.raw[expressionsLength].length) {
|
|
176
|
+
yield literals.raw[expressionsLength];
|
|
170
177
|
}
|
|
171
178
|
};
|
|
172
179
|
|
|
@@ -177,7 +184,9 @@ const htmlGenerator = function* (literals, ...expressions) {
|
|
|
177
184
|
* @returns {AsyncGenerator<string, void, void>} AsyncGenerator<string, void, void>
|
|
178
185
|
*/
|
|
179
186
|
const htmlAsyncGenerator = async function* (literals, ...expressions) {
|
|
180
|
-
|
|
187
|
+
const expressionsLength = expressions.length;
|
|
188
|
+
|
|
189
|
+
for (let i = 0; i < expressionsLength; ++i) {
|
|
181
190
|
let expression = await expressions[i];
|
|
182
191
|
let literal = literals.raw[i];
|
|
183
192
|
let string;
|
|
@@ -262,8 +271,8 @@ const htmlAsyncGenerator = async function* (literals, ...expressions) {
|
|
|
262
271
|
}
|
|
263
272
|
}
|
|
264
273
|
|
|
265
|
-
if (literals.raw[
|
|
266
|
-
yield literals.raw[
|
|
274
|
+
if (literals.raw[expressionsLength].length) {
|
|
275
|
+
yield literals.raw[expressionsLength];
|
|
267
276
|
}
|
|
268
277
|
};
|
|
269
278
|
|