Registry / serialization / unescape-js

unescape-js

JSON →
library1.1.4jsnpmunverified

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.

npm install unescape-js
INSTALL
IMPORT
SIG · UNESCAPE-JS
U
unescape-js
serializationjavascriptv1.1.4
Install
Import
Disk
Pass rate
0/ 6
Env Coverage0 / 6
glibc
1822
musl
1822
Install & Compatibility
Where this runs
tested against v? · npm install
Install × environment matrix
Each cell = how many times install + import succeeded across repeated harness runs. Partial = flaky.
glibc = Debian/Ubuntu slim · musl = Alpine Linux
musl
node 18226 runs
build_error
glibc
node 18226 runs
build_error
Code
Verified usage

Verified import paths — ran on the pinned version, not inferred.

unescapeJs
const unescapeJs = require('unescape-js');
import unescapeJs from 'unescape-js';
The library primarily exposes a CommonJS default export. Direct ESM import via `import ... from 'pkg'` may lead to undefined behavior or require specific bundler configurations for interoperability. TypeScript definitions confirm a CommonJS default export.

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.💩
Debug
Known issues
gotchaPrior to version 1.0.8, the library improperly parsed several forms of octal escape sequences, leading to incorrect unescaping results for `\017`, `\5`, `\72`, and octal sequences containing non-octal digits like `\019`.
fix
Upgrade to `unescape-js@1.0.8` or newer to ensure correct handling of octal escape sequences.
affects: <1.0.8
gotchaVersion 1.1.3 of the package incorrectly listed `@babel` packages as regular `dependencies` instead of `devDependencies`, leading to unnecessary package bloat upon installation.
fix
Upgrade to `unescape-js@1.1.4` or later to avoid installing superfluous `@babel` dependencies.
affects: 1.1.3
gotchaThe `unescape-js` package has not been updated in approximately six years (since v1.1.4 was published). This indicates the project is likely abandoned. While it remains functional for its core purpose, users should be aware that it may not receive updates for new JavaScript features, bug fixes, or security vulnerabilities.
fix
No direct fix; proceed with caution. Consider if the lack of ongoing maintenance poses a risk for your application, or if alternative, actively maintained libraries are available that serve similar needs.
affects: >=1.1.4
Errors
Common errors & fixes
ReferenceError: require is not defined
Attempting to use `require()` in an ECMAScript Module (ESM) context (e.g., in a file with `"type": "module"` in `package.json` or a `.mjs` file).
fix
Ensure your project is configured for CommonJS (e.g., omit `"type": "module"` from `package.json` and use `.js` files) or use dynamic import `import('unescape-js').then(mod => mod.default('...')` if strictly in ESM.
TypeError: unescapeJs is not a function
Attempting to import `unescapeJs` as a named export (`import { unescapeJs } from 'unescape-js';`) when the library provides a CommonJS default export.
fix
For CommonJS, use `const unescapeJs = require('unescape-js');`. If using a bundler that transpiles CJS to ESM, `import unescapeJs from 'unescape-js';` might work, but the canonical CJS import is recommended.
Upgrade
Version history
1.1.4latest on npm
Audit
Dependencies

No dependency data recorded yet.

Agent activity
7 hits · last 30 days
node
6
OpenAI (training)
1
Resources
unescape-js — npm install unescape-js · libregistry