@server/next 0.21.4 → 0.21.6
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 +1 -1
- package/src/helpers/jsx.js +26 -0
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@server/next",
|
|
3
|
-
"version": "0.21.
|
|
3
|
+
"version": "0.21.6",
|
|
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",
|
package/src/helpers/jsx.js
CHANGED
|
@@ -13,9 +13,35 @@ const altAttrs = {
|
|
|
13
13
|
classname: "class",
|
|
14
14
|
};
|
|
15
15
|
|
|
16
|
+
const minifyCss = (str) =>
|
|
17
|
+
str
|
|
18
|
+
.replace(/\s+/g, " ")
|
|
19
|
+
.replace(/(?!<\")\/\*[^\*]+\*\/(?!\")/g, "")
|
|
20
|
+
.replace(/(\w|\*) (\{)/g, "$1$2")
|
|
21
|
+
.replace(/(\}) (\w|\*)/g, "$1$2")
|
|
22
|
+
.replace(/(\{) (\w)/g, "$1$2")
|
|
23
|
+
.replace(/(\w)(\:) /g, "$1$2")
|
|
24
|
+
.replace(/(\;) (\})/g, "$1$2")
|
|
25
|
+
.replace(/(\;) (\w)/g, "$1$2")
|
|
26
|
+
.replace(/\;(\})/g, "$1")
|
|
27
|
+
.replace(/(\w), (\w)/g, "$1,$2")
|
|
28
|
+
.replace(/(\w), (\w)/g, "$1,$2")
|
|
29
|
+
.replace(/(\{) (\w)/g, "$1$2")
|
|
30
|
+
.trim();
|
|
31
|
+
|
|
16
32
|
export const jsx = (tag, { children, ...props }) => {
|
|
17
33
|
if (typeof tag === "function") return tag({ children, ...props });
|
|
18
34
|
|
|
35
|
+
// If they include an explicit <script>, let them be, just render it
|
|
36
|
+
// without escaping
|
|
37
|
+
if (tag === "script" && children) {
|
|
38
|
+
const src = children;
|
|
39
|
+
children = () => src;
|
|
40
|
+
}
|
|
41
|
+
if (tag === "style" && children) {
|
|
42
|
+
const src = minifyCss(children);
|
|
43
|
+
children = () => src;
|
|
44
|
+
}
|
|
19
45
|
if (props.dangerouslySetInnerHTML)
|
|
20
46
|
children = () => props.dangerouslySetInnerHTML.__html;
|
|
21
47
|
if (!children) children = [];
|