-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.js
55 lines (47 loc) · 1.12 KB
/
index.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
import 'es5-shim'
import 'es6-shim'
export function decodeHTML(html) {
let txt = document.createElement("textarea");
txt.innerHTML = html;
return txt.value;
}
function mapHTML(obj) {
if(isString(obj))
return decodeHTML(decodeHTML(obj))
return obj
}
function isString(val) {
return typeof val === 'string' || (
(!!val && typeof val === 'object') &&
Object.prototype.toString.call(val) === '[object String]'
);
}
export function deepDecodeHTML(json) {
return deepMap(json, mapHTML)
}
function mapObject(obj, fn) {
return Object.keys(obj).reduce(
(res, key) => {
res[key] = fn(obj[key]);
return res;
},
{}
)
}
function deepMap(obj, fn) {
const deepMapper = val => typeof val === 'object' ? deepMap(val, fn) : fn(val);
if(obj != null) {
if (Array.isArray(obj)) {
return obj.map(deepMapper);
}
if (typeof obj === 'object') {
return mapObject(obj, deepMapper);
}
}
return obj;
}
export function parseFormProps(props) {
var element = document.createElement("div")
element.innerHTML = props.substring(4)
return JSON.parse(element.innerHTML)
}