char-unescape
v1.0.0
Published
Removes a given escape sequence from before characters in a string. Correctly handles double-escapes by only unescaping them once.
Downloads
3
Maintainers
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 8 or above.
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
// 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'"
const charUnescape = require('char-unescape')('@')
charUnescape("This is @@a @'test@'") // "This is @a 'test'"