https://github.com/lamansky/char-unescape
[Node.js] Removes a given escape sequence from before characters in a string. Correctly handles double-escapes by only unescaping them once.
https://github.com/lamansky/char-unescape
Last synced: 3 months ago
JSON representation
[Node.js] Removes a given escape sequence from before characters in a string. Correctly handles double-escapes by only unescaping them once.
- Host: GitHub
- URL: https://github.com/lamansky/char-unescape
- Owner: lamansky
- License: mit
- Created: 2019-09-02T09:43:56.000Z (almost 7 years ago)
- Default Branch: master
- Last Pushed: 2019-09-02T09:45:11.000Z (almost 7 years ago)
- Last Synced: 2025-01-28T16:45:12.395Z (over 1 year ago)
- Language: JavaScript
- Size: 1.95 KB
- Stars: 0
- Watchers: 2
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: readme.md
- License: license.txt
Awesome Lists containing this project
README
# char-unescape
Removes a given escape sequence from before characters in a string. Correctly handles double-escapes by only unescaping them once.
## Installation
Requires [Node.js](https://nodejs.org/) 8 or above.
```bash
npm i char-unescape
```
## API
The module exports a single function.
### Parameter
Optional: `escapeChar` (string): The escape sequence to remove. Defaults to `\`.
### Return Value
Returns a function which accepts a single parameter: a string to which the unescape operation should be applied.
## Example
```javascript
// Note the function call!
// No arguments are passed here because we're using
// the default backslash escape character.
const charUnescape = require('char-unescape')()
charUnescape("This is \\\\a \\'test\\'") // "This is \\a 'test'"
```
```javascript
const charUnescape = require('char-unescape')('@')
charUnescape("This is @@a @'test@'") // "This is @a 'test'"
```
## Related
* [char-escape](https://github.com/lamansky/char-escape)