@unhead/ssr 1.3.8 → 1.4.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/dist/index.cjs CHANGED
@@ -2,17 +2,16 @@
2
2
 
3
3
  const shared = require('@unhead/shared');
4
4
 
5
+ function encodeAttribute(value) {
6
+ return String(value).replace(/"/g, """);
7
+ }
5
8
  function propsToString(props) {
6
- const handledAttributes = [];
9
+ const attrs = [];
7
10
  for (const [key, value] of Object.entries(props)) {
8
- if (value === false || value == null)
9
- continue;
10
- let attribute = key;
11
- if (value !== true)
12
- attribute += `="${String(value).replace(/"/g, """)}"`;
13
- handledAttributes.push(attribute);
11
+ if (value !== false && value !== null)
12
+ attrs.push(value === true ? key : `${key}="${encodeAttribute(value)}"`);
14
13
  }
15
- return handledAttributes.length > 0 ? ` ${handledAttributes.join(" ")}` : "";
14
+ return `${attrs.length > 0 ? " " : ""}${attrs.join(" ")}`;
16
15
  }
17
16
 
18
17
  function escapeHtml(str) {
@@ -0,0 +1,20 @@
1
+ import { Unhead, SSRHeadPayload, HeadTag } from '@unhead/schema';
2
+ export { SSRHeadPayload } from '@unhead/schema';
3
+
4
+ declare function renderSSRHead<T extends {}>(head: Unhead<T>): Promise<SSRHeadPayload>;
5
+
6
+ declare function propsToString(props: Record<string, any>): string;
7
+
8
+ declare function escapeHtml(str: string): string;
9
+ declare function escapeJson(str: string): string;
10
+ declare function tagToString<T extends HeadTag>(tag: T): string;
11
+
12
+ declare function ssrRenderTags<T extends HeadTag>(tags: T[]): {
13
+ headTags: string;
14
+ bodyTags: string;
15
+ bodyTagsOpen: string;
16
+ htmlAttrs: string;
17
+ bodyAttrs: string;
18
+ };
19
+
20
+ export { escapeHtml, escapeJson, propsToString, renderSSRHead, ssrRenderTags, tagToString };
@@ -0,0 +1,20 @@
1
+ import { Unhead, SSRHeadPayload, HeadTag } from '@unhead/schema';
2
+ export { SSRHeadPayload } from '@unhead/schema';
3
+
4
+ declare function renderSSRHead<T extends {}>(head: Unhead<T>): Promise<SSRHeadPayload>;
5
+
6
+ declare function propsToString(props: Record<string, any>): string;
7
+
8
+ declare function escapeHtml(str: string): string;
9
+ declare function escapeJson(str: string): string;
10
+ declare function tagToString<T extends HeadTag>(tag: T): string;
11
+
12
+ declare function ssrRenderTags<T extends HeadTag>(tags: T[]): {
13
+ headTags: string;
14
+ bodyTags: string;
15
+ bodyTagsOpen: string;
16
+ htmlAttrs: string;
17
+ bodyAttrs: string;
18
+ };
19
+
20
+ export { escapeHtml, escapeJson, propsToString, renderSSRHead, ssrRenderTags, tagToString };
package/dist/index.mjs CHANGED
@@ -1,16 +1,15 @@
1
1
  import { TagsWithInnerContent, SelfClosingTags } from '@unhead/shared';
2
2
 
3
+ function encodeAttribute(value) {
4
+ return String(value).replace(/"/g, "&quot;");
5
+ }
3
6
  function propsToString(props) {
4
- const handledAttributes = [];
7
+ const attrs = [];
5
8
  for (const [key, value] of Object.entries(props)) {
6
- if (value === false || value == null)
7
- continue;
8
- let attribute = key;
9
- if (value !== true)
10
- attribute += `="${String(value).replace(/"/g, "&quot;")}"`;
11
- handledAttributes.push(attribute);
9
+ if (value !== false && value !== null)
10
+ attrs.push(value === true ? key : `${key}="${encodeAttribute(value)}"`);
12
11
  }
13
- return handledAttributes.length > 0 ? ` ${handledAttributes.join(" ")}` : "";
12
+ return `${attrs.length > 0 ? " " : ""}${attrs.join(" ")}`;
14
13
  }
15
14
 
16
15
  function escapeHtml(str) {
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@unhead/ssr",
3
3
  "type": "module",
4
- "version": "1.3.8",
4
+ "version": "1.4.0",
5
5
  "author": "Harlan Wilton <harlan@harlanzw.com>",
6
6
  "license": "MIT",
7
7
  "funding": "https://github.com/sponsors/harlan-zw",
@@ -29,8 +29,8 @@
29
29
  "dist"
30
30
  ],
31
31
  "dependencies": {
32
- "@unhead/schema": "1.3.8",
33
- "@unhead/shared": "1.3.8"
32
+ "@unhead/schema": "1.4.0",
33
+ "@unhead/shared": "1.4.0"
34
34
  },
35
35
  "scripts": {
36
36
  "build": "unbuild .",