Escape special characters in a string
special-escape
is published at npmjs.com, and can be installed using npm
or yarn
.
$ npm install special-escape # npm
$ yarn add special-escape # yarn
import resolveWhen from 'special-escape'; // ES6+
const resolveWhen = require('special-escape'); // ES5
const specialChars = ['+', '-', '=', '>', '.', '!', '(', ')', '{', '}', '[', ']', '^', '"', '~', '*', '?', ':', '\\', '/',]
const escapedString = escapeChars('$2a$10$!NgGQwxmjy..4aQTdsOJw\\O7HUd6FfiFQ2e/2F6XJQh1PeZjWlEbmK', specialChars);
assert(escapedString, '$2a$10$\!NgGQwxmjy\.\.4aQTdsOJw\\O7HUd6FfiFQ2e\/2F6XJQh1PeZjWlEbmK');