functionalscript 0.12.2 → 0.12.4
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/html/module.f.d.ts
CHANGED
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import { type List } from '../types/list/module.f.ts';
|
|
2
|
+
import { type Vec } from '../types/bit_vec/module.f.ts';
|
|
2
3
|
type Tag = string;
|
|
3
4
|
type Element1 = readonly [Tag, ...Node[]];
|
|
4
5
|
type Element2 = readonly [Tag, Attributes, ...Node[]];
|
|
@@ -28,4 +29,5 @@ export declare const html: (_: Element) => List<string>;
|
|
|
28
29
|
* Renders an HTML element tree to a final string.
|
|
29
30
|
*/
|
|
30
31
|
export declare const htmlToString: (_: Element) => string;
|
|
32
|
+
export declare const htmlUtf8: (...head: readonly Node[]) => (...body: readonly Node[]) => Vec;
|
|
31
33
|
export {};
|
package/html/module.f.js
CHANGED
|
@@ -3,6 +3,8 @@ import { concat, concat as stringConcat } from "../types/string/module.f.js";
|
|
|
3
3
|
import { compose } from "../types/function/module.f.js";
|
|
4
4
|
import { stringToList } from "../text/utf16/module.f.js";
|
|
5
5
|
import { includes } from "../types/array/module.f.js";
|
|
6
|
+
import {} from "../types/bit_vec/module.f.js";
|
|
7
|
+
import { utf8 } from "../text/module.f.js";
|
|
6
8
|
const { fromCharCode } = String;
|
|
7
9
|
const { entries } = Object;
|
|
8
10
|
/**
|
|
@@ -87,3 +89,5 @@ export const html = compose(element)(listConcat(['<!DOCTYPE html>']));
|
|
|
87
89
|
* Renders an HTML element tree to a final string.
|
|
88
90
|
*/
|
|
89
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]]));
|
package/package.json
CHANGED
package/types/rtti/module.f.d.ts
CHANGED
|
@@ -62,4 +62,6 @@ export declare const record: MakeType1<'record'>;
|
|
|
62
62
|
export type Or<T extends readonly Type[]> = () => readonly ['or', ...T];
|
|
63
63
|
/** Constructs a schema that validates a value matching any of the given schemas. */
|
|
64
64
|
export declare const or: <T extends readonly Type[]>(...types: T) => Or<T>;
|
|
65
|
+
/** Constructs a schema that validates a value matching `T` or `undefined`. */
|
|
66
|
+
export declare const option: <T extends Type>(t: T) => Or<readonly [T, undefined]>;
|
|
65
67
|
export {};
|
package/types/rtti/module.f.js
CHANGED
|
@@ -21,3 +21,5 @@ export const array = type1('array');
|
|
|
21
21
|
export const record = type1('record');
|
|
22
22
|
/** Constructs a schema that validates a value matching any of the given schemas. */
|
|
23
23
|
export const or = (...types) => () => ['or', ...types];
|
|
24
|
+
/** Constructs a schema that validates a value matching `T` or `undefined`. */
|
|
25
|
+
export const option = (t) => or(t, undefined);
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { validate } from "./module.f.js";
|
|
2
|
-
import { boolean, number, string, bigint, unknown, array, record, or } from "../module.f.js";
|
|
2
|
+
import { boolean, number, string, bigint, unknown, array, record, or, option } from "../module.f.js";
|
|
3
3
|
const assertOk = ([k]) => { if (k !== 'ok') {
|
|
4
4
|
throw 'expected ok';
|
|
5
5
|
} };
|
|
@@ -195,6 +195,18 @@ export default {
|
|
|
195
195
|
},
|
|
196
196
|
},
|
|
197
197
|
},
|
|
198
|
+
option: {
|
|
199
|
+
ok: () => {
|
|
200
|
+
const t = option(number);
|
|
201
|
+
assertOk(validate(t)(42));
|
|
202
|
+
assertOk(validate(t)(undefined));
|
|
203
|
+
},
|
|
204
|
+
error: () => {
|
|
205
|
+
const t = option(number);
|
|
206
|
+
assertError(validate(t)(null));
|
|
207
|
+
assertError(validate(t)('42'));
|
|
208
|
+
},
|
|
209
|
+
},
|
|
198
210
|
recursive: {
|
|
199
211
|
arrayOfArrays: () => {
|
|
200
212
|
// self-referential schema: an array whose elements are also arrays of the same type
|