-
Notifications
You must be signed in to change notification settings - Fork 24
/
Copy pathshe.js
43 lines (37 loc) · 834 Bytes
/
she.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
'use strict';
var escapes = {
'&': '&',
'<': '<',
'>': '>',
'"': '"',
"'": '''
};
var unescapes = {
'&': '&',
'<': '<',
'>': '>',
'"': '"',
''': "'"
};
var rescaped = /(&|<|>|"|')/g;
var runescaped = /[&<>"']/g;
function escapeHtmlChar (match) {
return escapes[match];
}
function unescapeHtmlChar (match) {
return unescapes[match];
}
function escapeHtml (text) {
return text == null ? '' : String(text).replace(runescaped, escapeHtmlChar);
}
function unescapeHtml (html) {
return html == null ? '' : String(html).replace(rescaped, unescapeHtmlChar);
}
escapeHtml.options = unescapeHtml.options = {};
module.exports = {
encode: escapeHtml,
escape: escapeHtml,
decode: unescapeHtml,
unescape: unescapeHtml,
version: '1.0.0-browser'
};