26 lines
571 B
TypeScript
26 lines
571 B
TypeScript
const escape = (str: string) => {
|
|
const replacer = (match: string) => {
|
|
const replace: any = {
|
|
'!': '%21',
|
|
"'": '%27',
|
|
'(': '%28',
|
|
')': '%29',
|
|
'~': '%7E',
|
|
'%20': '+',
|
|
'%00': '\x00'
|
|
};
|
|
return replace[match];
|
|
}
|
|
return encodeURIComponent(str).replace(/[!'()~]|%20|%00/g, replacer);
|
|
}
|
|
|
|
const unescape = (str: string) => {
|
|
return decodeURIComponent(str.replace(/\+/g, ' '));
|
|
}
|
|
|
|
const Functions = {
|
|
escape,
|
|
unescape
|
|
};
|
|
|
|
export default Functions; |