ghtml 2.1.2 → 2.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/.eslintrc.json +1 -4
- package/bin/README.md +1 -1
- package/bin/example/assets/sun.webp +0 -0
- package/bin/example/routes/index.js +1 -1
- package/package.json +3 -3
- package/src/html.js +17 -23
- package/bin/example/assets/cat.jpeg +0 -0
package/.eslintrc.json
CHANGED
package/bin/README.md
CHANGED
|
@@ -5,7 +5,7 @@ Append unique hashes to assets referenced in your views to aggressively cache th
|
|
|
5
5
|
Running the following command will scan asset files found in the `roots` path(s) and replace their references with hashed versions in the `refs` path(s):
|
|
6
6
|
|
|
7
7
|
```sh
|
|
8
|
-
npx ghtml --roots="path/to/scan/
|
|
8
|
+
npx ghtml --roots="path/to/scan/assets/1/,path/to/scan/assets/2/" --refs="views/path/to/append/hashes/1/,views/path/to/append/hashes/2/"
|
|
9
9
|
```
|
|
10
10
|
|
|
11
11
|
## Example (Fastify)
|
|
Binary file
|
|
@@ -22,7 +22,7 @@ export default async (fastify) => {
|
|
|
22
22
|
fastify.get("/", async (request, reply) => {
|
|
23
23
|
return reply.html`
|
|
24
24
|
<h1 class="caption">Hello, world!</h1>
|
|
25
|
-
<img width="500" src="/p/assets/
|
|
25
|
+
<img width="500" src="/p/assets/sun.webp" alt="Picture of a cat" />
|
|
26
26
|
`;
|
|
27
27
|
});
|
|
28
28
|
};
|
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": "2.1.
|
|
6
|
+
"version": "2.1.4",
|
|
7
7
|
"type": "module",
|
|
8
8
|
"bin": "./bin/src/index.js",
|
|
9
9
|
"main": "./src/index.js",
|
|
@@ -21,12 +21,12 @@
|
|
|
21
21
|
"lint:fix": "eslint --fix . && prettier --write ."
|
|
22
22
|
},
|
|
23
23
|
"dependencies": {
|
|
24
|
-
"glob": "^10.4.
|
|
24
|
+
"glob": "^10.4.5"
|
|
25
25
|
},
|
|
26
26
|
"devDependencies": {
|
|
27
27
|
"@fastify/pre-commit": "^2.1.0",
|
|
28
28
|
"c8": "^10.1.2",
|
|
29
|
-
"grules": "^0.17.
|
|
29
|
+
"grules": "^0.17.3",
|
|
30
30
|
"tinybench": "^2.8.0"
|
|
31
31
|
},
|
|
32
32
|
"repository": {
|
package/src/html.js
CHANGED
|
@@ -1,11 +1,10 @@
|
|
|
1
1
|
const escapeRegExp = /["&'<>`]/;
|
|
2
2
|
|
|
3
3
|
const escapeFunction = (string) => {
|
|
4
|
-
const stringLength = string.length;
|
|
5
|
-
let start = 0;
|
|
6
4
|
let escaped = "";
|
|
5
|
+
let start = 0;
|
|
7
6
|
|
|
8
|
-
for (let end = 0; end !==
|
|
7
|
+
for (let end = 0; end !== string.length; ++end) {
|
|
9
8
|
switch (string.charCodeAt(end)) {
|
|
10
9
|
case 34: // "
|
|
11
10
|
escaped += string.slice(start, end) + """;
|
|
@@ -34,7 +33,7 @@ const escapeFunction = (string) => {
|
|
|
34
33
|
}
|
|
35
34
|
}
|
|
36
35
|
|
|
37
|
-
escaped += string.slice(start,
|
|
36
|
+
escaped += string.slice(start, string.length);
|
|
38
37
|
|
|
39
38
|
return escaped;
|
|
40
39
|
};
|
|
@@ -45,12 +44,11 @@ const escapeFunction = (string) => {
|
|
|
45
44
|
* @returns {string} The HTML string.
|
|
46
45
|
*/
|
|
47
46
|
const html = ({ raw: literals }, ...expressions) => {
|
|
48
|
-
const expressionsLength = expressions.length;
|
|
49
47
|
let accumulator = "";
|
|
50
48
|
|
|
51
|
-
for (let
|
|
52
|
-
const expression = expressions[
|
|
53
|
-
let literal = literals[
|
|
49
|
+
for (let i = 0; i !== expressions.length; ++i) {
|
|
50
|
+
const expression = expressions[i];
|
|
51
|
+
let literal = literals[i];
|
|
54
52
|
let string =
|
|
55
53
|
typeof expression === "string"
|
|
56
54
|
? expression
|
|
@@ -69,7 +67,7 @@ const html = ({ raw: literals }, ...expressions) => {
|
|
|
69
67
|
accumulator += literal + string;
|
|
70
68
|
}
|
|
71
69
|
|
|
72
|
-
accumulator += literals[
|
|
70
|
+
accumulator += literals[expressions.length];
|
|
73
71
|
|
|
74
72
|
return accumulator;
|
|
75
73
|
};
|
|
@@ -80,11 +78,9 @@ const html = ({ raw: literals }, ...expressions) => {
|
|
|
80
78
|
* @yields {string} The HTML strings.
|
|
81
79
|
*/
|
|
82
80
|
const htmlGenerator = function* ({ raw: literals }, ...expressions) {
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
let expression = expressions[index];
|
|
87
|
-
let literal = literals[index];
|
|
81
|
+
for (let i = 0; i !== expressions.length; ++i) {
|
|
82
|
+
let expression = expressions[i];
|
|
83
|
+
let literal = literals[i];
|
|
88
84
|
let string;
|
|
89
85
|
|
|
90
86
|
if (typeof expression === "string") {
|
|
@@ -165,8 +161,8 @@ const htmlGenerator = function* ({ raw: literals }, ...expressions) {
|
|
|
165
161
|
}
|
|
166
162
|
}
|
|
167
163
|
|
|
168
|
-
if (literals[
|
|
169
|
-
yield literals[
|
|
164
|
+
if (literals[expressions.length]) {
|
|
165
|
+
yield literals[expressions.length];
|
|
170
166
|
}
|
|
171
167
|
};
|
|
172
168
|
|
|
@@ -176,11 +172,9 @@ const htmlGenerator = function* ({ raw: literals }, ...expressions) {
|
|
|
176
172
|
* @yields {string} The HTML strings.
|
|
177
173
|
*/
|
|
178
174
|
const htmlAsyncGenerator = async function* ({ raw: literals }, ...expressions) {
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
let expression = await expressions[index];
|
|
183
|
-
let literal = literals[index];
|
|
175
|
+
for (let i = 0; i !== expressions.length; ++i) {
|
|
176
|
+
let expression = await expressions[i];
|
|
177
|
+
let literal = literals[i];
|
|
184
178
|
let string;
|
|
185
179
|
|
|
186
180
|
if (typeof expression === "string") {
|
|
@@ -264,8 +258,8 @@ const htmlAsyncGenerator = async function* ({ raw: literals }, ...expressions) {
|
|
|
264
258
|
}
|
|
265
259
|
}
|
|
266
260
|
|
|
267
|
-
if (literals[
|
|
268
|
-
yield literals[
|
|
261
|
+
if (literals[expressions.length]) {
|
|
262
|
+
yield literals[expressions.length];
|
|
269
263
|
}
|
|
270
264
|
};
|
|
271
265
|
|
|
Binary file
|