https://github.com/d4nyll/escape-chars
Escape special characters in a string
https://github.com/d4nyll/escape-chars
Last synced: 9 months ago
JSON representation
Escape special characters in a string
- Host: GitHub
- URL: https://github.com/d4nyll/escape-chars
- Owner: d4nyll
- Created: 2018-09-22T14:01:02.000Z (over 7 years ago)
- Default Branch: master
- Last Pushed: 2022-12-30T18:15:53.000Z (over 3 years ago)
- Last Synced: 2025-07-12T21:37:58.498Z (11 months ago)
- Language: JavaScript
- Size: 153 KB
- Stars: 1
- Watchers: 1
- Forks: 0
- Open Issues: 6
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
README
# special-escape
Escape special characters in a string
## Installation
[](https://nodei.co/npm/special-escape/)
`special-escape` is published at [npmjs.com](https://www.npmjs.com/), and can be installed using [`npm`](https://docs.npmjs.com/cli/npm) or [`yarn`](https://yarnpkg.com/lang/en/).
```bash
$ npm install special-escape # npm
$ yarn add special-escape # yarn
```
```js
import resolveWhen from 'special-escape'; // ES6+
const resolveWhen = require('special-escape'); // ES5
```
## Usage
```js
const specialChars = ['+', '-', '=', '>', '.', '!', '(', ')', '{', '}', '[', ']', '^', '"', '~', '*', '?', ':', '\\', '/',]
const escapedString = escapeChars('$2a$10$!NgGQwxmjy..4aQTdsOJw\\O7HUd6FfiFQ2e/2F6XJQh1PeZjWlEbmK', specialChars);
assert(escapedString, '$2a$10$\!NgGQwxmjy\.\.4aQTdsOJw\\O7HUd6FfiFQ2e\/2F6XJQh1PeZjWlEbmK');
```