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 CHANGED
@@ -1,10 +1,12 @@
1
- /* eslint-disable no-unused-vars */
2
- import { html } from "ghtml";
3
- import { Bench } from "tinybench";
4
- import { writeFileSync } from "node:fs";
5
- import { Buffer } from "node:buffer";
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
- await bench.warmup();
112
- await bench.run();
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
- "bench/results.json",
119
- Buffer.from(JSON.stringify(table), "utf8").toString("base64"),
120
- );
120
+ writeFileSync(
121
+ "bench/results.json",
122
+ Buffer.from(JSON.stringify(table), "utf8").toString("base64"),
123
+ );
124
+ })();
package/bin/src/index.js CHANGED
@@ -1,6 +1,8 @@
1
1
  #!/usr/bin/env node
2
- import { generateHashesAndReplace } from "./utils.js";
3
- import process from "node:process";
2
+
3
+ "use strict";
4
+
5
+ const { generateHashesAndReplace } = require("./utils.js");
4
6
 
5
7
  const parseArguments = (args) => {
6
8
  let roots = null;
package/bin/src/utils.js CHANGED
@@ -1,7 +1,9 @@
1
- import { Glob } from "glob";
2
- import { createHash } from "node:crypto";
3
- import { readFile, writeFile } from "node:fs/promises";
4
- import { win32, posix } from "node:path";
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
- export const generateHashesAndReplace = async ({
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;
@@ -1,7 +1,15 @@
1
1
  import grules from "grules";
2
+ import globals from "globals";
2
3
 
3
4
  export default [
4
5
  ...grules,
6
+ {
7
+ languageOptions: {
8
+ globals: {
9
+ ...globals.node,
10
+ },
11
+ },
12
+ },
5
13
  {
6
14
  rules: {
7
15
  "no-await-in-loop": "off",
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.13",
7
- "type": "module",
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"
@@ -1 +1,5 @@
1
+ /**
2
+ * @param {string} path path
3
+ * @returns {string} string
4
+ */
1
5
  export function includeFile(path: string): string;
@@ -1,4 +1,6 @@
1
- import { readFileSync } from "node:fs";
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
- export const includeFile = (path) => {
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
- export const html = (literals, ...expressions) => {
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
- export const htmlGenerator = function* (literals, ...expressions) {
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
- export const htmlAsyncGenerator = async function* (literals, ...expressions) {
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
- import { html, htmlGenerator, htmlAsyncGenerator } from "../src/index.js";
2
- import { readFile } from "node:fs/promises";
3
- import { readFileSync } from "node:fs";
4
- import test from "node:test";
5
- import assert from "node:assert";
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;