ghtml 1.0.1 → 1.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/package.json +2 -2
- package/src/html.js +5 -10
- package/src/includeFile.js +2 -3
- package/test/index.js +1 -1
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.0
|
|
6
|
+
"version": "1.1.0",
|
|
7
7
|
"type": "module",
|
|
8
8
|
"main": "./src/index.js",
|
|
9
9
|
"exports": {
|
|
@@ -19,7 +19,7 @@
|
|
|
19
19
|
"lint:fix": "eslint --fix . && prettier --write ."
|
|
20
20
|
},
|
|
21
21
|
"devDependencies": {
|
|
22
|
-
"grules": "^0.
|
|
22
|
+
"grules": "^0.12.1"
|
|
23
23
|
},
|
|
24
24
|
"repository": {
|
|
25
25
|
"type": "git",
|
package/src/html.js
CHANGED
|
@@ -16,19 +16,14 @@ const escapeFunction = (key) => {
|
|
|
16
16
|
};
|
|
17
17
|
|
|
18
18
|
/**
|
|
19
|
-
* @param {{ raw: string[] }} literals
|
|
20
|
-
* @param {...any} expressions
|
|
21
|
-
* @returns {string}
|
|
19
|
+
* @param {{ raw: string[] }} literals Tagged template literals.
|
|
20
|
+
* @param {...any} expressions Expressions to interpolate.
|
|
21
|
+
* @returns {string} The HTML string.
|
|
22
22
|
*/
|
|
23
23
|
const html = (literals, ...expressions) => {
|
|
24
|
-
const lastLiteralIndex = literals.raw.length - 1;
|
|
25
24
|
let accumulator = "";
|
|
26
25
|
|
|
27
|
-
|
|
28
|
-
return accumulator;
|
|
29
|
-
}
|
|
30
|
-
|
|
31
|
-
for (let index = 0; index < lastLiteralIndex; ++index) {
|
|
26
|
+
for (let index = 0; index < expressions.length; ++index) {
|
|
32
27
|
let literal = literals.raw[index];
|
|
33
28
|
let expression =
|
|
34
29
|
typeof expressions[index] === "string"
|
|
@@ -48,7 +43,7 @@ const html = (literals, ...expressions) => {
|
|
|
48
43
|
accumulator += literal + expression;
|
|
49
44
|
}
|
|
50
45
|
|
|
51
|
-
accumulator += literals.raw[
|
|
46
|
+
accumulator += literals.raw[expressions.length];
|
|
52
47
|
|
|
53
48
|
return accumulator;
|
|
54
49
|
};
|
package/src/includeFile.js
CHANGED
|
@@ -1,12 +1,11 @@
|
|
|
1
1
|
import { readFileSync } from "node:fs";
|
|
2
2
|
|
|
3
3
|
const readFileSyncOptions = { encoding: "utf8" };
|
|
4
|
-
|
|
5
4
|
const fileCache = new Map();
|
|
6
5
|
|
|
7
6
|
/**
|
|
8
|
-
* @param {string} path
|
|
9
|
-
* @returns {string}
|
|
7
|
+
* @param {string} path The path to the file to render.
|
|
8
|
+
* @returns {string} The cached content of the file.
|
|
10
9
|
*/
|
|
11
10
|
const includeFile = (path) => {
|
|
12
11
|
let file = fileCache.get(path);
|
package/test/index.js
CHANGED