cloudcmd
Version:
File manager for the web with console and editor
32 lines (24 loc) • 586 B
JavaScript
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;
};