functionalscript 0.0.562 → 0.0.563
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.cjs +54 -69
- package/html/test.f.cjs +20 -0
- package/package.json +3 -3
package/html/module.f.cjs
CHANGED
|
@@ -7,63 +7,38 @@ const { stringToList } = require('../text/utf16/module.f.cjs')
|
|
|
7
7
|
const { fromCharCode } = String
|
|
8
8
|
const { entries } = Object
|
|
9
9
|
|
|
10
|
-
/**
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
*/
|
|
36
|
-
|
|
37
|
-
/**
|
|
38
|
-
* https://developer.mozilla.org/en-US/docs/Glossary/Void_element
|
|
39
|
-
*
|
|
40
|
-
* @typedef {
|
|
41
|
-
* | 'area'
|
|
42
|
-
* | 'base'
|
|
43
|
-
* | 'br'
|
|
44
|
-
* | 'col'
|
|
45
|
-
* | 'embed'
|
|
46
|
-
* | 'hr'
|
|
47
|
-
* | 'img'
|
|
48
|
-
* | 'input'
|
|
49
|
-
* | 'link'
|
|
50
|
-
* | 'meta'
|
|
51
|
-
* | 'param'
|
|
52
|
-
* | 'source'
|
|
53
|
-
* | 'track'
|
|
54
|
-
* | 'wbr'
|
|
55
|
-
* } VoidTag
|
|
56
|
-
*/
|
|
57
|
-
|
|
58
|
-
/** @typedef {readonly[VoidTag]} VoidElement1*/
|
|
59
|
-
|
|
60
|
-
/** @typedef {readonly[VoidTag, Attributes]} VoidElement2 */
|
|
61
|
-
|
|
62
|
-
/** @typedef {readonly[Tag, readonly Node[]]} Element2 */
|
|
10
|
+
/** @typedef {string} Tag */
|
|
11
|
+
|
|
12
|
+
// https://developer.mozilla.org/en-US/docs/Glossary/Void_element
|
|
13
|
+
const voidTagList = [
|
|
14
|
+
'area',
|
|
15
|
+
'base',
|
|
16
|
+
'br',
|
|
17
|
+
'col',
|
|
18
|
+
'embed',
|
|
19
|
+
'hr',
|
|
20
|
+
'img',
|
|
21
|
+
'input',
|
|
22
|
+
'link',
|
|
23
|
+
'meta',
|
|
24
|
+
'param',
|
|
25
|
+
'source',
|
|
26
|
+
'track',
|
|
27
|
+
'wbr',
|
|
28
|
+
]
|
|
29
|
+
|
|
30
|
+
/** @type {(tag: string) => boolean} */
|
|
31
|
+
const isVoid = tag => voidTagList.includes(tag)
|
|
32
|
+
|
|
33
|
+
/** @typedef {readonly[Tag]} Element1*/
|
|
34
|
+
|
|
35
|
+
/** @typedef {readonly[Tag, Attributes]} Element2A */
|
|
36
|
+
|
|
37
|
+
/** @typedef {readonly[Tag, readonly Node[]]} Element2N */
|
|
63
38
|
|
|
64
39
|
/** @typedef {readonly[Tag, Attributes, Nodes]} Element3*/
|
|
65
40
|
|
|
66
|
-
/** @typedef {
|
|
41
|
+
/** @typedef {Element1 | Element2A | Element2N | Element3} Element */
|
|
67
42
|
|
|
68
43
|
/**
|
|
69
44
|
* @typedef {{
|
|
@@ -103,29 +78,39 @@ const attribute = ([name, value]) => flat([[' ', name, '="'], escape(value), ['"
|
|
|
103
78
|
/** @type {(a: Attributes) => list.List<string>} */
|
|
104
79
|
const attributes = compose(entries)(flatMap(attribute))
|
|
105
80
|
|
|
81
|
+
const open = (/** @type {Element2A} */[tag, a]) => flat([[`<`, tag], attributes(a), [`>`]])
|
|
82
|
+
|
|
83
|
+
const close = (/** @type {string}*/tag) => ['</', tag, '>']
|
|
84
|
+
|
|
85
|
+
/** @type {(_: Element3) => list.List<string>} */
|
|
86
|
+
const element3 = ([tag, a, ns]) =>
|
|
87
|
+
flat([open([tag, a]), nodes(ns), close(tag)])
|
|
88
|
+
|
|
89
|
+
/** @type {(_: Element2A) => list.List<string>} */
|
|
90
|
+
const element2a = e => {
|
|
91
|
+
const [tag] = e
|
|
92
|
+
return flat([open(e), isVoid(tag) ? [] : close(tag)])
|
|
93
|
+
}
|
|
94
|
+
|
|
106
95
|
/** @type {(element: Element) => list.List<string>} */
|
|
107
96
|
const element = e => {
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
const [tag, a, ns] = e
|
|
119
|
-
return [['<', tag], attributes(a), ['>'], nodes(ns), ['</', tag, '>']]
|
|
120
|
-
}
|
|
97
|
+
switch (e.length) {
|
|
98
|
+
case 1: { return element2a([e[0], {}]) }
|
|
99
|
+
case 2: {
|
|
100
|
+
const [tag, a] = e
|
|
101
|
+
return a instanceof Array ?
|
|
102
|
+
element3([tag, {}, a]) :
|
|
103
|
+
element2a([tag, a])
|
|
104
|
+
}
|
|
105
|
+
default: {
|
|
106
|
+
return element3(e)
|
|
121
107
|
}
|
|
122
108
|
}
|
|
123
|
-
return flat(f())
|
|
124
109
|
}
|
|
125
110
|
|
|
126
111
|
const html = compose(element)(listConcat(['<!DOCTYPE html>']))
|
|
127
112
|
|
|
128
|
-
const htmlToString =
|
|
113
|
+
const htmlToString = compose(html)(stringConcat)
|
|
129
114
|
|
|
130
115
|
module.exports = {
|
|
131
116
|
/** @readonly */
|
package/html/test.f.cjs
CHANGED
|
@@ -5,10 +5,30 @@ module.exports = {
|
|
|
5
5
|
const r = _.htmlToString(['html', []])
|
|
6
6
|
if (r !== '<!DOCTYPE html><html></html>') { throw r }
|
|
7
7
|
},
|
|
8
|
+
empty2: () => {
|
|
9
|
+
const r = _.htmlToString(['html'])
|
|
10
|
+
if (r !== '<!DOCTYPE html><html></html>') { throw r }
|
|
11
|
+
},
|
|
12
|
+
void: () => {
|
|
13
|
+
const r = _.htmlToString(['area'])
|
|
14
|
+
if (r !== '<!DOCTYPE html><area>') { throw r }
|
|
15
|
+
},
|
|
8
16
|
some: () => {
|
|
9
17
|
/** @type {_.Element} */
|
|
10
18
|
const x = ['div', {}, ['<div>&</div>', ['a', { href: 'hello"' }, []]]]
|
|
11
19
|
const s = _.htmlToString(x)
|
|
12
20
|
if (s !== '<!DOCTYPE html><div><div>&amp;</div><a href="hello""></a></div>') { throw s }
|
|
21
|
+
},
|
|
22
|
+
some2: () => {
|
|
23
|
+
/** @type {_.Element} */
|
|
24
|
+
const x = ['div', ['<div>&</div>', ['a', { href: 'hello"' }, []]]]
|
|
25
|
+
const s = _.htmlToString(x)
|
|
26
|
+
if (s !== '<!DOCTYPE html><div><div>&amp;</div><a href="hello""></a></div>') { throw s }
|
|
27
|
+
},
|
|
28
|
+
someVoid: () => {
|
|
29
|
+
/** @type {_.Element} */
|
|
30
|
+
const x = ['div', [['br', {id: '5'}], '<div>&</div>', ['a', { href: 'hello"' }, []]]]
|
|
31
|
+
const s = _.htmlToString(x)
|
|
32
|
+
if (s !== '<!DOCTYPE html><div><br id="5"><div>&amp;</div><a href="hello""></a></div>') { throw s }
|
|
13
33
|
}
|
|
14
34
|
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "functionalscript",
|
|
3
|
-
"version": "0.0.
|
|
3
|
+
"version": "0.0.563",
|
|
4
4
|
"description": "FunctionalScript is a functional subset of JavaScript",
|
|
5
5
|
"main": "module.f.cjs",
|
|
6
6
|
"scripts": {
|
|
@@ -30,7 +30,7 @@
|
|
|
30
30
|
},
|
|
31
31
|
"homepage": "https://github.com/functionalscript/functionalscript#readme",
|
|
32
32
|
"devDependencies": {
|
|
33
|
-
"@types/node": "^22.
|
|
34
|
-
"typescript": "^5.
|
|
33
|
+
"@types/node": "^22.9.0",
|
|
34
|
+
"typescript": "^5.6.3"
|
|
35
35
|
}
|
|
36
36
|
}
|