1.0.0 • Published 5 years ago

char-unescape v1.0.0

Weekly downloads
3
License
MIT
Repository
github
Last release
5 years ago

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'"

Related