ghtml 3.0.13 → 3.1.0
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 +17 -13
- package/bin/src/index.js +4 -2
- package/bin/src/utils.js +9 -5
- package/{eslint.config.js → eslint.config.mjs} +8 -0
- package/package.json +3 -2
- package/src/includeFile.d.ts +4 -0
- package/src/includeFile.js +6 -2
- package/src/index.d.ts +17 -0
- package/src/index.js +9 -3
- package/test/index.js +7 -5
package/bench/index.js
CHANGED
|
@@ -1,10 +1,12 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
const { html } = require("..");
|
|
4
|
+
const { Bench } = require("tinybench");
|
|
5
|
+
const { writeFileSync } = require("node:fs");
|
|
6
6
|
|
|
7
7
|
const bench = new Bench({ time: 500 });
|
|
8
|
+
|
|
9
|
+
// eslint-disable-next-line no-unused-vars
|
|
8
10
|
let result = "";
|
|
9
11
|
|
|
10
12
|
bench.add("simple HTML formatting", () => {
|
|
@@ -108,13 +110,15 @@ bench.add("sparse escape", () => {
|
|
|
108
110
|
result = html`<p>${`${"noescape".repeat(250)}<>`.repeat(5)}</p>`;
|
|
109
111
|
});
|
|
110
112
|
|
|
111
|
-
|
|
112
|
-
await bench.
|
|
113
|
+
(async () => {
|
|
114
|
+
await bench.warmup();
|
|
115
|
+
await bench.run();
|
|
113
116
|
|
|
114
|
-
const table = bench.table();
|
|
115
|
-
globalThis.console.table(table);
|
|
117
|
+
const table = bench.table();
|
|
118
|
+
globalThis.console.table(table);
|
|
116
119
|
|
|
117
|
-
writeFileSync(
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
);
|
|
120
|
+
writeFileSync(
|
|
121
|
+
"bench/results.json",
|
|
122
|
+
Buffer.from(JSON.stringify(table), "utf8").toString("base64"),
|
|
123
|
+
);
|
|
124
|
+
})();
|
package/bin/src/index.js
CHANGED
package/bin/src/utils.js
CHANGED
|
@@ -1,7 +1,9 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
const { Glob } = require("glob");
|
|
4
|
+
const { createHash } = require("node:crypto");
|
|
5
|
+
const { readFile, writeFile } = require("node:fs/promises");
|
|
6
|
+
const { win32, posix } = require("node:path");
|
|
5
7
|
|
|
6
8
|
const generateFileHash = async (filePath) => {
|
|
7
9
|
try {
|
|
@@ -77,7 +79,7 @@ const updateFilePathsWithHashes = async (
|
|
|
77
79
|
}
|
|
78
80
|
};
|
|
79
81
|
|
|
80
|
-
|
|
82
|
+
const generateHashesAndReplace = async ({
|
|
81
83
|
roots,
|
|
82
84
|
refs,
|
|
83
85
|
prefix,
|
|
@@ -130,3 +132,5 @@ export const generateHashesAndReplace = async ({
|
|
|
130
132
|
skipPatterns,
|
|
131
133
|
);
|
|
132
134
|
};
|
|
135
|
+
|
|
136
|
+
module.exports.generateHashesAndReplace = generateHashesAndReplace;
|
package/package.json
CHANGED
|
@@ -3,8 +3,8 @@
|
|
|
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
|
|
7
|
-
"type": "
|
|
6
|
+
"version": "3.1.0",
|
|
7
|
+
"type": "commonjs",
|
|
8
8
|
"bin": "./bin/src/index.js",
|
|
9
9
|
"main": "./src/index.js",
|
|
10
10
|
"exports": {
|
|
@@ -27,6 +27,7 @@
|
|
|
27
27
|
"devDependencies": {
|
|
28
28
|
"@fastify/pre-commit": "^2.1.0",
|
|
29
29
|
"c8": "^10.1.2",
|
|
30
|
+
"globals": "^15.11.0",
|
|
30
31
|
"grules": "^0.25.10",
|
|
31
32
|
"tinybench": "^2.9.0",
|
|
32
33
|
"typescript": ">=5.6.2"
|
package/src/includeFile.d.ts
CHANGED
package/src/includeFile.js
CHANGED
|
@@ -1,4 +1,6 @@
|
|
|
1
|
-
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
const { readFileSync } = require("node:fs");
|
|
2
4
|
|
|
3
5
|
const cache = new Map();
|
|
4
6
|
|
|
@@ -6,7 +8,7 @@ const cache = new Map();
|
|
|
6
8
|
* @param {string} path path
|
|
7
9
|
* @returns {string} string
|
|
8
10
|
*/
|
|
9
|
-
|
|
11
|
+
const includeFile = (path) => {
|
|
10
12
|
let file = cache.get(path);
|
|
11
13
|
|
|
12
14
|
if (file === undefined) {
|
|
@@ -16,3 +18,5 @@ export const includeFile = (path) => {
|
|
|
16
18
|
|
|
17
19
|
return file;
|
|
18
20
|
};
|
|
21
|
+
|
|
22
|
+
module.exports.includeFile = includeFile;
|
package/src/index.d.ts
CHANGED
|
@@ -1,3 +1,20 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @param {TemplateStringsArray} literals literals
|
|
3
|
+
* @param {...any} expressions expressions
|
|
4
|
+
* @returns {string} string
|
|
5
|
+
*/
|
|
1
6
|
export function html(literals: TemplateStringsArray, ...expressions: any[]): string;
|
|
7
|
+
/**
|
|
8
|
+
* @param {TemplateStringsArray} literals literals
|
|
9
|
+
* @param {...any} expressions expressions
|
|
10
|
+
* @yields {string} string
|
|
11
|
+
* @returns {Generator<string, void, void>} Generator<string, void, void>
|
|
12
|
+
*/
|
|
2
13
|
export function htmlGenerator(literals: TemplateStringsArray, ...expressions: any[]): Generator<string, void, void>;
|
|
14
|
+
/**
|
|
15
|
+
* @param {TemplateStringsArray} literals literals
|
|
16
|
+
* @param {...any} expressions expressions
|
|
17
|
+
* @yields {string} string
|
|
18
|
+
* @returns {AsyncGenerator<string, void, void>} AsyncGenerator<string, void, void>
|
|
19
|
+
*/
|
|
3
20
|
export function htmlAsyncGenerator(literals: TemplateStringsArray, ...expressions: any[]): AsyncGenerator<string, void, void>;
|
package/src/index.js
CHANGED
|
@@ -1,3 +1,5 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
1
3
|
const _isArray = Array.isArray;
|
|
2
4
|
|
|
3
5
|
const _iterator = Symbol.iterator;
|
|
@@ -56,7 +58,7 @@ const escapeFunction = (string) => {
|
|
|
56
58
|
* @param {...any} expressions expressions
|
|
57
59
|
* @returns {string} string
|
|
58
60
|
*/
|
|
59
|
-
|
|
61
|
+
const html = (literals, ...expressions) => {
|
|
60
62
|
let accumulator = "";
|
|
61
63
|
|
|
62
64
|
for (let i = 0; i !== expressions.length; ++i) {
|
|
@@ -83,7 +85,7 @@ export const html = (literals, ...expressions) => {
|
|
|
83
85
|
* @yields {string} string
|
|
84
86
|
* @returns {Generator<string, void, void>} Generator<string, void, void>
|
|
85
87
|
*/
|
|
86
|
-
|
|
88
|
+
const htmlGenerator = function* (literals, ...expressions) {
|
|
87
89
|
for (let i = 0; i !== expressions.length; ++i) {
|
|
88
90
|
let expression = expressions[i];
|
|
89
91
|
let literal = literals.raw[i];
|
|
@@ -174,7 +176,7 @@ export const htmlGenerator = function* (literals, ...expressions) {
|
|
|
174
176
|
* @yields {string} string
|
|
175
177
|
* @returns {AsyncGenerator<string, void, void>} AsyncGenerator<string, void, void>
|
|
176
178
|
*/
|
|
177
|
-
|
|
179
|
+
const htmlAsyncGenerator = async function* (literals, ...expressions) {
|
|
178
180
|
for (let i = 0; i !== expressions.length; ++i) {
|
|
179
181
|
let expression = await expressions[i];
|
|
180
182
|
let literal = literals.raw[i];
|
|
@@ -264,3 +266,7 @@ export const htmlAsyncGenerator = async function* (literals, ...expressions) {
|
|
|
264
266
|
yield literals.raw[expressions.length];
|
|
265
267
|
}
|
|
266
268
|
};
|
|
269
|
+
|
|
270
|
+
module.exports.html = html;
|
|
271
|
+
module.exports.htmlGenerator = htmlGenerator;
|
|
272
|
+
module.exports.htmlAsyncGenerator = htmlAsyncGenerator;
|
package/test/index.js
CHANGED
|
@@ -1,8 +1,10 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
const { html, htmlGenerator, htmlAsyncGenerator } = require("..");
|
|
4
|
+
const { readFile } = require("node:fs/promises");
|
|
5
|
+
const { readFileSync } = require("node:fs");
|
|
6
|
+
const test = require("node:test");
|
|
7
|
+
const assert = require("node:assert/strict");
|
|
6
8
|
|
|
7
9
|
const conditionTrue = true;
|
|
8
10
|
const conditionFalse = false;
|