@server/next 0.27.0 → 0.27.3

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 CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@server/next",
3
- "version": "0.27.0",
3
+ "version": "0.27.3",
4
4
  "description": "A fully-fledged web server with routing, file uploads, sessions, static files, schema validation, websockets, testing, etc.",
5
5
  "homepage": "https://server-js.com/",
6
6
  "repository": "https://github.com/franciscop/server-next.git",
@@ -19,7 +19,8 @@
19
19
  "scripts": {
20
20
  "build": "bunx tsup src/index.ts --format esm --dts --out-dir . --target node24",
21
21
  "start": "bun test --watch",
22
- "lint": "npx @biomejs/biome lint ./src --skip=lint/style/noParameterAssign --skip=lint/suspicious/noExplicitAny --skip=lint/suspicious/noConfusingVoidType",
22
+ "lint": "npx @biomejs/biome lint ./src --skip=lint/suspicious/noExplicitAny --skip=lint/style/noParameterAssign --skip=lint/suspicious/noConfusingVoidType",
23
+ "types": "npx tsc --noEmit",
23
24
  "test": "npm run test:bun && tsc --noEmit",
24
25
  "test:bun": "bun test",
25
26
  "test:jest": "node --experimental-vm-modules node_modules/jest/bin/jest.js"
@@ -37,7 +38,7 @@
37
38
  ],
38
39
  "exports": {
39
40
  ".": "./index.js",
40
- "./jsx-runtime": "./src/jsx/jsx-dev-runtime.js",
41
+ "./jsx-runtime": "./src/jsx/jsx-runtime.js",
41
42
  "./jsx-dev-runtime": "./src/jsx/jsx-dev-runtime.js"
42
43
  },
43
44
  "devDependencies": {
@@ -1,91 +1 @@
1
- const entities = {
2
- "&": "&",
3
- "<": "&lt;",
4
- ">": "&gt;",
5
- '"': "&quot;",
6
- };
7
-
8
- const encode = (str = "") => {
9
- if (typeof str === "number") str = String(str);
10
- if (typeof str !== "string") return "";
11
- return str.replace(/[&<>"]/g, (tag) => entities[tag]);
12
- };
13
-
14
- const SELFCLOSE = new Set(
15
- "area,base,br,col,embed,hr,img,input,link,meta,source,track,wbr".split(","),
16
- );
17
-
18
- const altAttrs = {
19
- classname: "class",
20
- };
21
-
22
- // "" and 0 are valid children, false and null and undefined are not
23
- const isValidChild = (child) => child || child === "" || child === 0;
24
-
25
- const escapeCSS = (value) => String(value).replace(/[<>&"'`]/g, "\\$&");
26
-
27
- const minifyCss = (str) =>
28
- str
29
- .replace(/\s+/g, " ")
30
- .replace(/(?!<")\/\*[^*]+\*\/(?!")/g, "")
31
- .replace(/(\w|\*) (\{)/g, "$1$2")
32
- .replace(/(\}) (\w|\*)/g, "$1$2")
33
- .replace(/(\{) (\w)/g, "$1$2")
34
- .replace(/(\w)(:) /g, "$1$2")
35
- .replace(/(;) (\})/g, "$1$2")
36
- .replace(/(;) (\w)/g, "$1$2")
37
- .replace(/;(\})/g, "$1")
38
- .replace(/(\w), (\w)/g, "$1,$2")
39
- .replace(/(\w), (\w)/g, "$1,$2")
40
- .replace(/(\{) (\w)/g, "$1$2")
41
- .trim();
42
-
43
- const jsx = (tag, { children, ...props }) => {
44
- if (typeof tag === "function") return tag({ children, ...props });
45
-
46
- if (tag === "script" && children) {
47
- const src = children;
48
- children = () => src;
49
- }
50
-
51
- if (tag === "style" && children && typeof children === "string") {
52
- const src = minifyCss(escapeCSS(children));
53
- children = () => src;
54
- }
55
-
56
- if (props?.dangerouslySetInnerHTML) {
57
- children = () => props.dangerouslySetInnerHTML.__html;
58
- }
59
-
60
- if (!isValidChild(children)) children = [];
61
- if (typeof children === "string") children = [children];
62
-
63
- children = (Array.isArray(children) ? children : [children])
64
- .flat()
65
- .map((c) => (typeof c === "function" ? c() : encode(c)))
66
- .join("");
67
-
68
- if (!tag) return () => children;
69
-
70
- let attrStr = Object.entries(props || {})
71
- .filter(([k]) => k !== "dangerouslySetInnerHTML")
72
- .filter(([k, v]) => !/on[A-Z]/.test(k) && typeof v !== "function")
73
- .filter(([, v]) => v !== false)
74
- .map(([k, v]) =>
75
- v === true
76
- ? altAttrs[k.toLowerCase()] || encode(k)
77
- : `${altAttrs[k.toLowerCase()] || encode(k)}="${encode(String(v))}"`,
78
- )
79
- .join(" ");
80
-
81
- if (attrStr) attrStr = ` ${attrStr}`;
82
-
83
- if (SELFCLOSE.has(tag)) return () => `<${tag}${attrStr} />`;
84
-
85
- const doctype = tag === "html" ? "<!DOCTYPE html>" : "";
86
- return () => `${doctype}<${tag}${attrStr}>${children}</${tag}>`;
87
- };
88
-
89
- const Fragment = "";
90
-
91
- export { jsx, jsx as jsxs, jsx as jsxDEV, Fragment };
1
+ export * from "./jsx-runtime.js";
@@ -0,0 +1,91 @@
1
+ const entities = {
2
+ "&": "&amp;",
3
+ "<": "&lt;",
4
+ ">": "&gt;",
5
+ '"': "&quot;",
6
+ };
7
+
8
+ const encode = (str = "") => {
9
+ if (typeof str === "number") str = String(str);
10
+ if (typeof str !== "string") return "";
11
+ return str.replace(/[&<>"]/g, (tag) => entities[tag]);
12
+ };
13
+
14
+ const SELFCLOSE = new Set(
15
+ "area,base,br,col,embed,hr,img,input,link,meta,source,track,wbr".split(","),
16
+ );
17
+
18
+ const altAttrs = {
19
+ classname: "class",
20
+ };
21
+
22
+ // "" and 0 are valid children, false and null and undefined are not
23
+ const isValidChild = (child) => child || child === "" || child === 0;
24
+
25
+ const escapeCSS = (value) => String(value).replace(/[<>&"'`]/g, "\\$&");
26
+
27
+ const minifyCss = (str) =>
28
+ str
29
+ .replace(/\s+/g, " ")
30
+ .replace(/(?!<")\/\*[^*]+\*\/(?!")/g, "")
31
+ .replace(/(\w|\*) (\{)/g, "$1$2")
32
+ .replace(/(\}) (\w|\*)/g, "$1$2")
33
+ .replace(/(\{) (\w)/g, "$1$2")
34
+ .replace(/(\w)(:) /g, "$1$2")
35
+ .replace(/(;) (\})/g, "$1$2")
36
+ .replace(/(;) (\w)/g, "$1$2")
37
+ .replace(/;(\})/g, "$1")
38
+ .replace(/(\w), (\w)/g, "$1,$2")
39
+ .replace(/(\w), (\w)/g, "$1,$2")
40
+ .replace(/(\{) (\w)/g, "$1$2")
41
+ .trim();
42
+
43
+ const jsx = (tag, { children, ...props }) => {
44
+ if (typeof tag === "function") return tag({ children, ...props });
45
+
46
+ if (tag === "script" && children) {
47
+ const src = children;
48
+ children = () => src;
49
+ }
50
+
51
+ if (tag === "style" && children && typeof children === "string") {
52
+ const src = minifyCss(escapeCSS(children));
53
+ children = () => src;
54
+ }
55
+
56
+ if (props?.dangerouslySetInnerHTML) {
57
+ children = () => props.dangerouslySetInnerHTML.__html;
58
+ }
59
+
60
+ if (!isValidChild(children)) children = [];
61
+ if (typeof children === "string") children = [children];
62
+
63
+ children = (Array.isArray(children) ? children : [children])
64
+ .flat()
65
+ .map((c) => (typeof c === "function" ? c() : encode(c)))
66
+ .join("");
67
+
68
+ if (!tag) return () => children;
69
+
70
+ let attrStr = Object.entries(props || {})
71
+ .filter(([k]) => k !== "dangerouslySetInnerHTML")
72
+ .filter(([k, v]) => !/on[A-Z]/.test(k) && typeof v !== "function")
73
+ .filter(([, v]) => v !== false)
74
+ .map(([k, v]) =>
75
+ v === true
76
+ ? altAttrs[k.toLowerCase()] || encode(k)
77
+ : `${altAttrs[k.toLowerCase()] || encode(k)}="${encode(String(v))}"`,
78
+ )
79
+ .join(" ");
80
+
81
+ if (attrStr) attrStr = ` ${attrStr}`;
82
+
83
+ if (SELFCLOSE.has(tag)) return () => `<${tag}${attrStr} />`;
84
+
85
+ const doctype = tag === "html" ? "<!DOCTYPE html>" : "";
86
+ return () => `${doctype}<${tag}${attrStr}>${children}</${tag}>`;
87
+ };
88
+
89
+ const Fragment = "";
90
+
91
+ export { jsx, jsx as jsxs, jsx as jsxDEV, Fragment };