Add unquote method

This commit is contained in:
pyoor 2018-08-29 17:46:46 -04:00
parent aaa01050e2
commit ac7f4b3580
1 changed files with 13 additions and 0 deletions

View File

@ -24,6 +24,19 @@ class common extends utils {
}
}
/**
* Remove quotes and escape sequence from string
* @param {string} s
* @returns {string}
*/
static unquote (s) {
return s.replace(/\\'/g, '\'')
.replace(/\\"/g, '"')
.replace(/\\0/g, '\0')
.replace(/\\\\/g, '\\')
.replace(/(^['|"])(.*)\1$/gm, '$2')
}
/**
* Unicode safe b64 encoding
* https://developer.mozilla.org/en-US/docs/Web/API/WindowBase64/Base64_encoding_and_decoding#The_Unicode_Problem