-
-
Notifications
You must be signed in to change notification settings - Fork 266
Expand file tree
/
Copy pathentity.js
More file actions
31 lines (24 loc) · 586 Bytes
/
Copy pathentity.js
File metadata and controls
31 lines (24 loc) · 586 Bytes
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
const Entities = {
'<': '<',
'>': '>',
'"': '"',
'{': '{',
'}': '}',
};
const keys = Object.keys(Entities);
export const encode = (str) => {
for (const code of keys) {
const char = Entities[code];
const reg = RegExp(char, 'g');
str = str.replace(reg, code);
}
return str;
};
export const decode = (str) => {
for (const code of keys) {
const char = Entities[code];
const reg = RegExp(code, 'g');
str = str.replace(reg, char);
}
return str;
};