-
-
Notifications
You must be signed in to change notification settings - Fork 4
/
Html.js
88 lines (71 loc) · 2.19 KB
/
Html.js
1
2
3
4
5
6
7
8
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
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
(f => {
'use strict';
if (typeof module === 'object' && typeof module.exports === 'object') {
module.exports = f (require ('sanctuary-def'),
require ('sanctuary-show'),
require ('sanctuary-type-identifiers'));
} else {
self.Html = f (self.sanctuaryDef,
self.sanctuaryShow,
self.sanctuaryTypeIdentifiers);
}
}) (($, show, type) => {
'use strict';
const def = $.create ({checkTypes: true, env: []});
// htmlTypeIdent :: String
const htmlTypeIdent = 'sanctuary-site/Html';
const HtmlType = $.NullaryType
('Html')
('https://github.com/sanctuary-js/sanctuary-site/blob/gh-pages/adt/Html.js')
([])
(x => type (x) === htmlTypeIdent);
// Html :: String -> Html
const Html =
def ('Html')
({})
([$.String, HtmlType])
(value => Object.assign (Object.create (Html$prototype), {value}));
const Html$prototype = {
'@@type': htmlTypeIdent,
'fantasy-land/concat': function(other) {
return Html (this.value + other.value);
},
'@@show': function() {
return 'Html (' + show (this.value) + ')';
},
};
Html['fantasy-land/empty'] = () => Html ('');
// Html.unwrap :: Html -> String
Html.unwrap =
def ('Html.unwrap')
({})
([HtmlType, $.String])
(html => html.value);
// Html.encode :: String -> Html
Html.encode =
def ('Html.encode')
({})
([$.String, HtmlType])
(text => Html (text.replace (/&/g, '&')
.replace (/</g, '<')
.replace (/"/g, '"')));
// Html.decode :: Html -> String
Html.decode =
def ('Html.decode')
({})
([HtmlType, $.String])
(html => html.value
.replace (/"/g, '"')
.replace (/</g, '<')
.replace (/&/g, '&'));
// Html.indent :: NonNegativeInteger -> Html -> Html
Html.indent =
def ('Html.indent')
({})
([$.NonNegativeInteger, HtmlType, HtmlType])
(indent => html =>
Html (html.value.replace (/^(?!$)/gm, ' '.repeat (indent))));
// Html.Type :: Type
Html.Type = HtmlType;
return Html;
});