npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2026 – Pkg Stats / Ryan Hefner

unescape-unicode

v0.3.0

Published

Library to unescape Unicode characters

Readme

unescape-unicode

Build Status Downloads Release License

unescape-unicode is a Node.js package for converting Unicode escapes ("\uxxxx" notation) into their corresponding Unicode characters.

Install

Install using npm:

npm install --save unescape-unicode

Usage

unescapeUnicode(input[, options])

Converts Unicode escapes within input to their corresponding characters.

Characters that are not part of Unicode escapes are included in the returned string as-is. This includes invalid or incomplete Unicode escapes (e.g. \uxxxx) and any other unrelated escape sequences (e.g. \t). This can be controlled by specifying the replacer option.

Characters within the Basic Multilingual Plane (BMP) as well as surrogate pairs for characters outside BMP are supported.

Options

| Option | Type | Default | Description | |------------|------------|---------|---------------------------------------------------------------------------------------------------------------------------------------| | replacer | Replacer | None | A function that returns a replacement string for an individual escape character represented by a specific Unicode code point, if any. |

Examples

import { replaceChars, unescapeUnicode } from "unescape-unicode";

unescapeUnicode("I \\u2665 Unicode!");
//=> "I ♥ Unicode!"
unescapeUnicode("I\\t\\u2665\tUnicode!", { replacer: replaceChars({ f: "\f", n: "\n", r: "\r", t: "\t" }) });
//=> "I	♥	Unicode!"
unescapeUnicode("\\ud842\\udfb7\\ud842\\udfbe");
//=> "𠮷𠮾"

Replacer(code, char)

A function that returns a replacement string for an individual escape character (i.e. the character immediately following a backslash character) represented by the specified Unicode code point, if any.

If an empty string is returned, the escape sequence will be removed from the returned string. If either null or undefined are returned, the escape sequence will be included in the returned string as-is.

This function is only passed u if not part of a valid Unicode escape sequence.

There are a several built-in Replacer functions provided.

composeReplacer(...replacers)

Returns a Replacer composed of the specified replacers that returns the replacement string returned from the first Replacer to return a string, where possible.

import { composeReplacer, replaceChars, replaceUnescaped, unescapeUnicode } from "unescape-unicode";

const replacer = composeReplacer(
  replaceChars({ f: "\f", n: "\n", r: "\r", t: "\t" }),
  replaceUnescaped(),
);
unescapeUnicode("I\\t\\u2665\\tUnicode\\\\!", { replacer });
//=> "I	♥	Unicode\\!"

replaceConstant(replacement)

Returns a Replacer that always returns the specified replacement.

import { replaceConstant, unescapeUnicode } from "unescape-unicode";

unescapeUnicode("I\\t\\u2665\\tUnicode!", { replacer: replaceConstant("?") });
//=> "I?♥?Unicode!"

replaceChar(char, replacement)

Returns a Replacer that returns the specified replacement string for the individual escape character (i.e. the character immediately following a backslash character) provided.

import { replaceChar, unescapeUnicode } from "unescape-unicode";

unescapeUnicode("I\\t\\u2665\\tUnicode!", { replacer: replaceChar("t", "\t") });
//=> "I	♥	Unicode!"

replaceChars(replacements)

Returns a Replacer that returns replacement strings looked up from the specified replacements, where possible.

The keys within replacements are expected to be the individual escape characters (i.e. the character immediately following a backslash character). It can either be provided as a Map or an object.

import { replaceChars, unescapeUnicode } from "unescape-unicode";

const replacements = {
  f: "\f",
  n: "\n",
  r: "\r",
  t: "\t",
};
unescapeUnicode("I\\t\\u2665\\tUnicode!", { replacer: replaceChars(replacements) });
//=> "I	♥	Unicode!"

replaceCode(code, replacement)

Returns a Replacer that returns the specified replacement string for the Unicode code point representing the individual escape character (i.e. the character immediately following a backslash character) provided.

import { replaceCode, unescapeUnicode } from "unescape-unicode";

unescapeUnicode("I\\t\\u2665\\tUnicode!", { replacer: replaceCode(0x0074, "\t") });
//=> "I	♥	Unicode!"

replaceCodes(replacements)

Returns a Replacer that returns replacement strings looked up from the specified replacements, where possible.

The keys within replacements are expected to be Unicode code points representing the individual escape characters (i.e. the character immediately following a backslash character). It can either be provided as a Map or an object.

import { replaceCodes, unescapeUnicode } from "unescape-unicode";

const replacements = new Map([
  [0x0066, "\f"],
  [0x006e, "\n"],
  [0x0072, "\r"],
  [0x0074, "\t"],
]);
unescapeUnicode("I\\t\\u2665\\tUnicode!", { replacer: replaceCodes(replacements) });
//=> "I	♥	Unicode!"

replaceUnescaped()

Returns a Replacer that always returns the individual escape character (i.e. the character immediately following a backslash character) as the replacement string.

import { replaceUnescaped, unescapeUnicode } from "unescape-unicode";

unescapeUnicode("I\\t\\u2665\\tUnicode!", { replacer: replaceUnescaped() });
//=> "It♥tUnicode!"

Related

Bugs

If you have any problems with this package or would like to see changes currently in development, you can do so here.

Contributors

If you want to contribute, you're a legend! Information on how you can do so can be found in CONTRIBUTING.md. We want your suggestions and pull requests!

A list of all contributors can be found in AUTHORS.md.

License

Copyright © 2025 neocotic

See LICENSE.md for more information on our MIT license.