From ac7f4b3580f8cf68655cce55590737414f71bfe8 Mon Sep 17 00:00:00 2001 From: pyoor Date: Wed, 29 Aug 2018 17:46:46 -0400 Subject: [PATCH] Add unquote method --- lib/utils/common.js | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/lib/utils/common.js b/lib/utils/common.js index 7cb9d70..a04cbe7 100644 --- a/lib/utils/common.js +++ b/lib/utils/common.js @@ -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