html-express-js 3.1.0 → 4.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 +9 -9
- package/src/index.d.ts +6 -8
- package/src/index.js +4 -3
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "html-express-js",
|
|
3
|
-
"version": "
|
|
3
|
+
"version": "4.1.0",
|
|
4
4
|
"description": "An Express template engine to render HTML views using native JavaScript",
|
|
5
5
|
"main": "src/index.js",
|
|
6
6
|
"type": "module",
|
|
@@ -39,23 +39,23 @@
|
|
|
39
39
|
},
|
|
40
40
|
"homepage": "https://github.com/markcellus/html-express-js#readme",
|
|
41
41
|
"dependencies": {
|
|
42
|
-
"glob": "^
|
|
42
|
+
"glob": "^11.0.0"
|
|
43
43
|
},
|
|
44
44
|
"devDependencies": {
|
|
45
|
-
"@types/chai": "^
|
|
46
|
-
"@types/express": "^
|
|
45
|
+
"@types/chai": "^5.0.0",
|
|
46
|
+
"@types/express": "^5.0.0",
|
|
47
47
|
"@types/mocha": "^10.0.6",
|
|
48
48
|
"@types/reload": "^3.2.3",
|
|
49
49
|
"@types/sinon": "^17.0.3",
|
|
50
50
|
"chai": "^5.1.0",
|
|
51
|
-
"chokidar": "^
|
|
52
|
-
"express": "^
|
|
51
|
+
"chokidar": "^4.0.1",
|
|
52
|
+
"express": "^5.1.0",
|
|
53
53
|
"husky": "^9.0.7",
|
|
54
|
-
"mocha": "^
|
|
54
|
+
"mocha": "^11.0.1",
|
|
55
55
|
"prettier": "^3.0.3",
|
|
56
|
-
"release-it": "
|
|
56
|
+
"release-it": "17.1.1",
|
|
57
57
|
"reload": "^3.2.0",
|
|
58
|
-
"sinon": "^
|
|
58
|
+
"sinon": "^21.0.0",
|
|
59
59
|
"typescript": "^5.4.3"
|
|
60
60
|
}
|
|
61
61
|
}
|
package/src/index.d.ts
CHANGED
|
@@ -5,9 +5,9 @@
|
|
|
5
5
|
* @param {import('express').Request} req
|
|
6
6
|
* @param {import('express').Response} res
|
|
7
7
|
* @param {Record<string, any>} [data]
|
|
8
|
-
* @returns {Promise<
|
|
8
|
+
* @returns {Promise<string>} HTML with includes available (appended to state)
|
|
9
9
|
*/
|
|
10
|
-
export function renderView(filePath: string, req: import(
|
|
10
|
+
export function renderView(filePath: string, req: import("express").Request, res: import("express").Response, data?: Record<string, any>): Promise<string>;
|
|
11
11
|
/**
|
|
12
12
|
* Template literal that supports string
|
|
13
13
|
* interpolating in passed HTML.
|
|
@@ -27,12 +27,12 @@ export function html(strings: any, ...data: any[]): string;
|
|
|
27
27
|
* engine: Parameters<import('express').Application['engine']>[1],
|
|
28
28
|
* }}
|
|
29
29
|
*/
|
|
30
|
-
export default function _default(opts?: HTMLExpressOptions
|
|
30
|
+
export default function _default(opts?: HTMLExpressOptions): {
|
|
31
31
|
staticIndexHandler: HTMLExpressStaticIndexHandler;
|
|
32
|
-
engine:
|
|
32
|
+
engine: Parameters<import("express").Application["engine"]>[1];
|
|
33
33
|
};
|
|
34
|
-
export type HTMLExpressStaticIndexHandler = () => import(
|
|
35
|
-
export type HTMLExpressBuildStateHandler = (req: import(
|
|
34
|
+
export type HTMLExpressStaticIndexHandler = () => import("express").RequestHandler;
|
|
35
|
+
export type HTMLExpressBuildStateHandler = (req: import("express").Request) => Promise<Record<string, any>>;
|
|
36
36
|
export type HTMLExpressOptions = {
|
|
37
37
|
/**
|
|
38
38
|
* - The directory that houses any potential index files
|
|
@@ -58,5 +58,3 @@ export type HTMLExpressViewState = Record<string, string> & {
|
|
|
58
58
|
includes: Record<string, string>;
|
|
59
59
|
};
|
|
60
60
|
export type HTMLExpressView<D extends Record<string, any> = Record<string, any>> = (data: D, state: HTMLExpressViewState) => string;
|
|
61
|
-
declare function staticIndexHandler(): import('express').RequestHandler;
|
|
62
|
-
export {};
|
package/src/index.js
CHANGED
|
@@ -5,7 +5,7 @@ import { stat } from 'fs/promises';
|
|
|
5
5
|
/**
|
|
6
6
|
* @callback HTMLExpressBuildStateHandler
|
|
7
7
|
* @param {import('express').Request} req
|
|
8
|
-
* @returns {Record<string, any
|
|
8
|
+
* @returns {Promise<Record<string, any>>}
|
|
9
9
|
*/
|
|
10
10
|
|
|
11
11
|
/**
|
|
@@ -79,12 +79,13 @@ async function renderFileTemplate(path, data, state) {
|
|
|
79
79
|
* @param {import('express').Request} req
|
|
80
80
|
* @param {import('express').Response} res
|
|
81
81
|
* @param {Record<string, any>} [data]
|
|
82
|
-
* @returns {Promise<
|
|
82
|
+
* @returns {Promise<string>} HTML with includes available (appended to state)
|
|
83
83
|
*/
|
|
84
84
|
export async function renderView(filePath, req, res, data = {}) {
|
|
85
|
-
const requestState = buildRequestState ? buildRequestState(req) : {};
|
|
85
|
+
const requestState = buildRequestState ? await buildRequestState(req) : {};
|
|
86
86
|
const html = await buildViewHtml(filePath, data, requestState);
|
|
87
87
|
res.send(html);
|
|
88
|
+
return html;
|
|
88
89
|
}
|
|
89
90
|
|
|
90
91
|
/**
|