ghtml 1.7.0 → 1.7.2
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 +1 -1
- package/package.json +3 -3
- package/src/html.js +24 -22
package/README.md
CHANGED
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": "1.7.
|
|
6
|
+
"version": "1.7.2",
|
|
7
7
|
"type": "module",
|
|
8
8
|
"main": "./src/index.js",
|
|
9
9
|
"exports": {
|
|
@@ -22,8 +22,8 @@
|
|
|
22
22
|
"devDependencies": {
|
|
23
23
|
"@fastify/pre-commit": "^2.1.0",
|
|
24
24
|
"c8": "^9.1.0",
|
|
25
|
-
"grules": "^0.
|
|
26
|
-
"tinybench": "^2.
|
|
25
|
+
"grules": "^0.17.1",
|
|
26
|
+
"tinybench": "^2.8.0"
|
|
27
27
|
},
|
|
28
28
|
"repository": {
|
|
29
29
|
"type": "git",
|
package/src/html.js
CHANGED
|
@@ -19,7 +19,6 @@ const escapeFunction = (string) => {
|
|
|
19
19
|
|
|
20
20
|
do {
|
|
21
21
|
const escapedCharacter = escapeDictionary[string[end++]];
|
|
22
|
-
|
|
23
22
|
if (escapedCharacter) {
|
|
24
23
|
escaped += string.slice(start, end - 1) + escapedCharacter;
|
|
25
24
|
start = end;
|
|
@@ -37,17 +36,18 @@ const arrayIsArray = Array.isArray;
|
|
|
37
36
|
* @returns {string} The HTML string.
|
|
38
37
|
*/
|
|
39
38
|
const html = ({ raw: literals }, ...expressions) => {
|
|
39
|
+
const expressionsLength = expressions.length;
|
|
40
40
|
let index = 0;
|
|
41
41
|
let accumulator = "";
|
|
42
42
|
|
|
43
|
-
for (; index !==
|
|
43
|
+
for (; index !== expressionsLength; ++index) {
|
|
44
44
|
const expression = expressions[index];
|
|
45
45
|
let literal = literals[index];
|
|
46
46
|
let string =
|
|
47
|
-
|
|
48
|
-
?
|
|
49
|
-
:
|
|
50
|
-
?
|
|
47
|
+
typeof expression === "string"
|
|
48
|
+
? expression
|
|
49
|
+
: expression === undefined || expression === null
|
|
50
|
+
? ""
|
|
51
51
|
: arrayIsArray(expression)
|
|
52
52
|
? expression.join("")
|
|
53
53
|
: `${expression}`;
|
|
@@ -70,17 +70,18 @@ const html = ({ raw: literals }, ...expressions) => {
|
|
|
70
70
|
* @yields {string} The HTML strings.
|
|
71
71
|
*/
|
|
72
72
|
const htmlGenerator = function* ({ raw: literals }, ...expressions) {
|
|
73
|
+
const expressionsLength = expressions.length;
|
|
73
74
|
let index = 0;
|
|
74
75
|
|
|
75
|
-
for (; index !==
|
|
76
|
+
for (; index !== expressionsLength; ++index) {
|
|
76
77
|
let expression = expressions[index];
|
|
77
78
|
let literal = literals[index];
|
|
78
79
|
let string;
|
|
79
80
|
|
|
80
|
-
if (
|
|
81
|
-
string = "";
|
|
82
|
-
} else if (typeof expression === "string") {
|
|
81
|
+
if (typeof expression === "string") {
|
|
83
82
|
string = expression;
|
|
83
|
+
} else if (expression === undefined || expression === null) {
|
|
84
|
+
string = "";
|
|
84
85
|
} else {
|
|
85
86
|
if (expression[Symbol.iterator]) {
|
|
86
87
|
const isRaw =
|
|
@@ -95,13 +96,13 @@ const htmlGenerator = function* ({ raw: literals }, ...expressions) {
|
|
|
95
96
|
}
|
|
96
97
|
|
|
97
98
|
for (expression of expression) {
|
|
98
|
-
if (expression === undefined || expression === null) {
|
|
99
|
-
continue;
|
|
100
|
-
}
|
|
101
|
-
|
|
102
99
|
if (typeof expression === "string") {
|
|
103
100
|
string = expression;
|
|
104
101
|
} else {
|
|
102
|
+
if (expression === undefined || expression === null) {
|
|
103
|
+
continue;
|
|
104
|
+
}
|
|
105
|
+
|
|
105
106
|
if (expression[Symbol.iterator]) {
|
|
106
107
|
for (expression of expression) {
|
|
107
108
|
if (expression === undefined || expression === null) {
|
|
@@ -162,17 +163,18 @@ const htmlGenerator = function* ({ raw: literals }, ...expressions) {
|
|
|
162
163
|
* @yields {string} The HTML strings.
|
|
163
164
|
*/
|
|
164
165
|
const htmlAsyncGenerator = async function* ({ raw: literals }, ...expressions) {
|
|
166
|
+
const expressionsLength = expressions.length;
|
|
165
167
|
let index = 0;
|
|
166
168
|
|
|
167
|
-
for (; index !==
|
|
169
|
+
for (; index !== expressionsLength; ++index) {
|
|
168
170
|
let expression = await expressions[index];
|
|
169
171
|
let literal = literals[index];
|
|
170
172
|
let string;
|
|
171
173
|
|
|
172
|
-
if (
|
|
173
|
-
string = "";
|
|
174
|
-
} else if (typeof expression === "string") {
|
|
174
|
+
if (typeof expression === "string") {
|
|
175
175
|
string = expression;
|
|
176
|
+
} else if (expression === undefined || expression === null) {
|
|
177
|
+
string = "";
|
|
176
178
|
} else {
|
|
177
179
|
if (expression[Symbol.iterator] || expression[Symbol.asyncIterator]) {
|
|
178
180
|
const isRaw =
|
|
@@ -187,13 +189,13 @@ const htmlAsyncGenerator = async function* ({ raw: literals }, ...expressions) {
|
|
|
187
189
|
}
|
|
188
190
|
|
|
189
191
|
for await (expression of expression) {
|
|
190
|
-
if (expression === undefined || expression === null) {
|
|
191
|
-
continue;
|
|
192
|
-
}
|
|
193
|
-
|
|
194
192
|
if (typeof expression === "string") {
|
|
195
193
|
string = expression;
|
|
196
194
|
} else {
|
|
195
|
+
if (expression === undefined || expression === null) {
|
|
196
|
+
continue;
|
|
197
|
+
}
|
|
198
|
+
|
|
197
199
|
if (
|
|
198
200
|
expression[Symbol.iterator] ||
|
|
199
201
|
expression[Symbol.asyncIterator]
|