Skip to content

[Node.js] Removes a given escape sequence from before characters in a string. Correctly handles double-escapes by only unescaping them once.

License

Notifications You must be signed in to change notification settings

lamansky/char-unescape

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

1 Commit
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

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

About

[Node.js] Removes a given escape sequence from before characters in a string. Correctly handles double-escapes by only unescaping them once.

Resources

License

Stars

Watchers

Forks

Packages

No packages published