ghtml 3.1.1 → 3.1.3

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/bench/index.js CHANGED
@@ -105,7 +105,6 @@ bench.add("sparse escape", () => {
105
105
  });
106
106
 
107
107
  (async () => {
108
- await bench.warmup();
109
108
  await bench.run();
110
109
 
111
110
  const table = bench.table();
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.1",
6
+ "version": "3.1.3",
7
7
  "type": "commonjs",
8
8
  "bin": "./bin/src/index.js",
9
9
  "main": "./src/index.js",
@@ -27,9 +27,9 @@
27
27
  "devDependencies": {
28
28
  "@fastify/pre-commit": "^2.2.0",
29
29
  "c8": "^10.1.2",
30
- "globals": "^15.13.0",
30
+ "globals": "^16.0.0",
31
31
  "grules": "^0.26.1",
32
- "tinybench": "^3.0.7",
32
+ "tinybench": "^4.0.1",
33
33
  "typescript": ">=5.7.2"
34
34
  },
35
35
  "repository": {
package/src/index.js CHANGED
@@ -55,17 +55,21 @@ const escapeFunction = (string) => {
55
55
  */
56
56
  const html = (literals, ...expressions) => {
57
57
  let accumulator = "";
58
- let i = 0;
59
58
 
60
- for (; i !== expressions.length; ++i) {
59
+ for (let i = 0; i !== expressions.length; ++i) {
61
60
  let literal = literals.raw[i];
62
- let string = Array.isArray(expressions[i])
63
- ? expressions[i].join("")
64
- : `${expressions[i] ?? ""}`;
65
-
66
- if (literal.length !== 0 && literal.charCodeAt(literal.length - 1) === 33) {
61
+ let string =
62
+ typeof expressions[i] === "string"
63
+ ? expressions[i]
64
+ : expressions[i] == null
65
+ ? ""
66
+ : Array.isArray(expressions[i])
67
+ ? expressions[i].join("")
68
+ : `${expressions[i]}`;
69
+
70
+ if (literal.length && literal.charCodeAt(literal.length - 1) === 33) {
67
71
  literal = literal.slice(0, -1);
68
- } else if (string.length !== 0) {
72
+ } else if (string.length) {
69
73
  string = escapeFunction(string);
70
74
  }
71
75
 
@@ -89,18 +93,18 @@ const htmlGenerator = function* (literals, ...expressions) {
89
93
 
90
94
  if (typeof expression === "string") {
91
95
  string = expression;
92
- } else if (expression === undefined || expression === null) {
96
+ } else if (expression == null) {
93
97
  string = "";
94
98
  } else {
95
99
  if (typeof expression[Symbol.iterator] === "function") {
96
100
  const isRaw =
97
- literal.length !== 0 && literal.charCodeAt(literal.length - 1) === 33;
101
+ literal.length && literal.charCodeAt(literal.length - 1) === 33;
98
102
 
99
103
  if (isRaw) {
100
104
  literal = literal.slice(0, -1);
101
105
  }
102
106
 
103
- if (literal.length !== 0) {
107
+ if (literal.length) {
104
108
  yield literal;
105
109
  }
106
110
 
@@ -108,19 +112,19 @@ const htmlGenerator = function* (literals, ...expressions) {
108
112
  if (typeof expression === "string") {
109
113
  string = expression;
110
114
  } else {
111
- if (expression === undefined || expression === null) {
115
+ if (expression == null) {
112
116
  continue;
113
117
  }
114
118
 
115
119
  if (typeof expression[Symbol.iterator] === "function") {
116
120
  for (expression of expression) {
117
- if (expression === undefined || expression === null) {
121
+ if (expression == null) {
118
122
  continue;
119
123
  }
120
124
 
121
125
  string = `${expression}`;
122
126
 
123
- if (string.length !== 0) {
127
+ if (string.length) {
124
128
  if (!isRaw) {
125
129
  string = escapeFunction(string);
126
130
  }
@@ -135,7 +139,7 @@ const htmlGenerator = function* (literals, ...expressions) {
135
139
  string = `${expression}`;
136
140
  }
137
141
 
138
- if (string.length !== 0) {
142
+ if (string.length) {
139
143
  if (!isRaw) {
140
144
  string = escapeFunction(string);
141
145
  }
@@ -150,18 +154,18 @@ const htmlGenerator = function* (literals, ...expressions) {
150
154
  string = `${expression}`;
151
155
  }
152
156
 
153
- if (literal.length !== 0 && literal.charCodeAt(literal.length - 1) === 33) {
157
+ if (literal.length && literal.charCodeAt(literal.length - 1) === 33) {
154
158
  literal = literal.slice(0, -1);
155
- } else if (string.length !== 0) {
159
+ } else if (string.length) {
156
160
  string = escapeFunction(string);
157
161
  }
158
162
 
159
- if (literal.length !== 0 || string.length !== 0) {
163
+ if (literal.length || string.length) {
160
164
  yield literal + string;
161
165
  }
162
166
  }
163
167
 
164
- if (literals.raw[expressions.length].length !== 0) {
168
+ if (literals.raw[expressions.length].length) {
165
169
  yield literals.raw[expressions.length];
166
170
  }
167
171
  };
@@ -180,7 +184,7 @@ const htmlAsyncGenerator = async function* (literals, ...expressions) {
180
184
 
181
185
  if (typeof expression === "string") {
182
186
  string = expression;
183
- } else if (expression === undefined || expression === null) {
187
+ } else if (expression == null) {
184
188
  string = "";
185
189
  } else {
186
190
  if (
@@ -188,13 +192,13 @@ const htmlAsyncGenerator = async function* (literals, ...expressions) {
188
192
  typeof expression[Symbol.asyncIterator] === "function"
189
193
  ) {
190
194
  const isRaw =
191
- literal.length !== 0 && literal.charCodeAt(literal.length - 1) === 33;
195
+ literal.length && literal.charCodeAt(literal.length - 1) === 33;
192
196
 
193
197
  if (isRaw) {
194
198
  literal = literal.slice(0, -1);
195
199
  }
196
200
 
197
- if (literal.length !== 0) {
201
+ if (literal.length) {
198
202
  yield literal;
199
203
  }
200
204
 
@@ -202,7 +206,7 @@ const htmlAsyncGenerator = async function* (literals, ...expressions) {
202
206
  if (typeof expression === "string") {
203
207
  string = expression;
204
208
  } else {
205
- if (expression === undefined || expression === null) {
209
+ if (expression == null) {
206
210
  continue;
207
211
  }
208
212
 
@@ -211,13 +215,13 @@ const htmlAsyncGenerator = async function* (literals, ...expressions) {
211
215
  typeof expression[Symbol.asyncIterator] === "function"
212
216
  ) {
213
217
  for await (expression of expression) {
214
- if (expression === undefined || expression === null) {
218
+ if (expression == null) {
215
219
  continue;
216
220
  }
217
221
 
218
222
  string = `${expression}`;
219
223
 
220
- if (string.length !== 0) {
224
+ if (string.length) {
221
225
  if (!isRaw) {
222
226
  string = escapeFunction(string);
223
227
  }
@@ -232,7 +236,7 @@ const htmlAsyncGenerator = async function* (literals, ...expressions) {
232
236
  string = `${expression}`;
233
237
  }
234
238
 
235
- if (string.length !== 0) {
239
+ if (string.length) {
236
240
  if (!isRaw) {
237
241
  string = escapeFunction(string);
238
242
  }
@@ -247,18 +251,18 @@ const htmlAsyncGenerator = async function* (literals, ...expressions) {
247
251
  string = `${expression}`;
248
252
  }
249
253
 
250
- if (literal.length !== 0 && literal.charCodeAt(literal.length - 1) === 33) {
254
+ if (literal.length && literal.charCodeAt(literal.length - 1) === 33) {
251
255
  literal = literal.slice(0, -1);
252
- } else if (string.length !== 0) {
256
+ } else if (string.length) {
253
257
  string = escapeFunction(string);
254
258
  }
255
259
 
256
- if (literal.length !== 0 || string.length !== 0) {
260
+ if (literal.length || string.length) {
257
261
  yield literal + string;
258
262
  }
259
263
  }
260
264
 
261
- if (literals.raw[expressions.length].length !== 0) {
265
+ if (literals.raw[expressions.length].length) {
262
266
  yield literals.raw[expressions.length];
263
267
  }
264
268
  };