functionalscript 0.13.0 → 0.13.1

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.
@@ -29,5 +29,19 @@ export declare const html: (_: Element) => List<string>;
29
29
  * Renders an HTML element tree to a final string.
30
30
  */
31
31
  export declare const htmlToString: (_: Element) => string;
32
+ /**
33
+ * Renders a complete UTF-8 encoded HTML document as a `Vec`.
34
+ *
35
+ * Produces a full page with `<!DOCTYPE html>`, a `<head>` containing a UTF-8
36
+ * `<meta charset>` and a responsive-viewport `<meta>` followed by any extra
37
+ * `head` nodes, and a `<body>` containing the provided `body` nodes.
38
+ *
39
+ * @example
40
+ * ```ts
41
+ * htmlUtf8(['title', 'My Page'])(['h1', 'Hello'])
42
+ * // Vec of UTF-8 bytes for:
43
+ * // <!DOCTYPE html><html><head><meta charset="UTF-8">...<title>My Page</title></head><body><h1>Hello</h1></body></html>
44
+ * ```
45
+ */
32
46
  export declare const htmlUtf8: (...head: readonly Node[]) => (...body: readonly Node[]) => Vec;
33
47
  export {};
package/html/module.f.js CHANGED
@@ -89,5 +89,24 @@ export const html = compose(element)(listConcat(['<!DOCTYPE html>']));
89
89
  * Renders an HTML element tree to a final string.
90
90
  */
91
91
  export const htmlToString = compose(html)(stringConcat);
92
- const metaUtf8 = ['meta', { charset: 'UTF-8' }];
93
- export const htmlUtf8 = (...head) => (...body) => utf8(htmlToString(['html', ['head', metaUtf8, ...head], ['body', ...body]]));
92
+ const commonHead = [
93
+ ['meta', { charset: 'UTF-8' }],
94
+ ['meta', { name: 'viewport', content: 'width=device-width,initial-scale=1.0' }],
95
+ ];
96
+ /**
97
+ * Renders a complete UTF-8 encoded HTML document as a `Vec`.
98
+ *
99
+ * Produces a full page with `<!DOCTYPE html>`, a `<head>` containing a UTF-8
100
+ * `<meta charset>` and a responsive-viewport `<meta>` followed by any extra
101
+ * `head` nodes, and a `<body>` containing the provided `body` nodes.
102
+ *
103
+ * @example
104
+ * ```ts
105
+ * htmlUtf8(['title', 'My Page'])(['h1', 'Hello'])
106
+ * // Vec of UTF-8 bytes for:
107
+ * // <!DOCTYPE html><html><head><meta charset="UTF-8">...<title>My Page</title></head><body><h1>Hello</h1></body></html>
108
+ * ```
109
+ */
110
+ export const htmlUtf8 = (...head) => (...body) => utf8(htmlToString(['html',
111
+ ['head', ...commonHead, ...head],
112
+ ['body', ...body]]));
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "functionalscript",
3
- "version": "0.13.0",
3
+ "version": "0.13.1",
4
4
  "type": "module",
5
5
  "files": [
6
6
  "**/*.js",
@@ -1,4 +1,4 @@
1
- import { type NodeOp } from '../types/effects/node/module.f.ts';
1
+ import { type WriteFile } from '../types/effects/node/module.f.ts';
2
2
  import { type Effect } from '../types/effects/module.f.ts';
3
- declare const _default: () => Effect<NodeOp, number>;
3
+ declare const _default: () => Effect<WriteFile, number>;
4
4
  export default _default;
@@ -3,17 +3,13 @@
3
3
  *
4
4
  * @module
5
5
  */
6
- import { htmlToString } from "../html/module.f.js";
6
+ import { htmlUtf8 } from "../html/module.f.js";
7
7
  import { writeFile } from "../types/effects/node/module.f.js";
8
- import { utf8 } from "../text/module.f.js";
9
- import { begin, pure } from "../types/effects/module.f.js";
10
- const html = utf8(htmlToString(['body',
11
- ['a',
12
- { href: 'https://github.com/functionalscript/functionalscript' },
13
- 'GitHub Repository'
14
- ]
15
- ]));
16
- const program = begin
17
- .step(() => writeFile('index.html', html))
8
+ import { pure } from "../types/effects/module.f.js";
9
+ const html = htmlUtf8()(['a',
10
+ { href: 'https://github.com/functionalscript/functionalscript' },
11
+ 'GitHub Repository'
12
+ ]);
13
+ const program = writeFile('index.html', html)
18
14
  .step(() => pure(0));
19
15
  export default () => program;