Unescape JavaScript and Python Escape Sequences

1.1.4 · abandoned · verified Sun Apr 19

unescape-js is a lightweight JavaScript utility designed to convert strings containing JavaScript and Python-style escape sequences back into their literal characters. This includes standard JavaScript escapes like `\n`, `\t`, Unicode escapes such as `\u00A9` for copyright, and ES2015 Unicode code point escapes like `\u{1F604}`. It also supports Python-style Unicode character escapes (`\UXXXXXXXX`). The current stable version is 1.1.4, though the package has not seen updates for approximately six years, indicating an abandoned or extremely low-maintenance status. A key differentiator is its robust handling of various octal escape sequence nuances, which was significantly improved in earlier versions to prevent misinterpretation of single, double, and three-digit octal codes, including those starting with `\0` and sequences with non-octal digits.

Common errors

Warnings

Install

Imports

Quickstart

Demonstrates how to import and use `unescapeJs` to convert various JavaScript and Python-style escape sequences into their literal characters, including newlines, tabs, and different Unicode formats.

const unescapeJs = require('unescape-js');

// Basic string with a newline escape
console.log(unescapeJs('Hello,\nworld!'));
// Expected: Hello,
//           world!

// Unicode character escape
console.log(unescapeJs('Copyright \u00A9 2024'));
// Expected: Copyright © 2024

// ES2015 Unicode code point escape (emoji)
console.log(unescapeJs('Smile: \u{1F604}'));
// Expected: Smile: 😄

// Python-style Unicode escape
console.log(unescapeJs('High five: \U0001F590'));
// Expected: High five: ✋

// Complex example with various escapes
const escapedString = 'This is a test.\tNew line after tab: \n\rAnd a carriage return.\u{1F4A9}';
console.log(unescapeJs(escapedString));
// Expected: This is a test. New line after tab: 
//           And a carriage return.💩

view raw JSON →