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 🙏

© 2024 – Pkg Stats / Ryan Hefner

js-name-escape

v1.0.1

Published

Escape strings to be used as javascript names.

Downloads

156

Readme

js-name-escape

Escape strings to be used as javascript names.

Installation

npm i js-name-escape

Format

All characters except a-z, A-Z and _ are replaced with $x_ where x is the hexadecimal unicode code point.

Usage

import {escape, unescape} from 'js-name-escape'

escape('Hello World!') // -> Hello$20_World$21_

unescape('Hello$20_World$21_') // -> Hello World!

Inversion

Please note that unescape is not the full inverse of escape since invalid or partial escape codes are ignored when unescaping.

// For any given string, the following is true:
unescape(escape(x)) === x
// Example: foo! --> foo$21_ --> foo!

// but the following may be false:
escape(unescape(x)) === x
// Example: $bar --> $bar --> $21_bar

Benchmarks

The following are the latest benchmark results:

Node 10.9 (Windows 10 / 4.8GHz)
	escape 32 chars x 314,639 ops/sec ±4.75% (93 runs sampled)
	unescape 32 chars x 609,117 ops/sec ±1.19% (96 runs sampled)

Node 10.9 (Ubuntu 18 / 4.8GHz)
	escape 32 chars x 472,569 ops/sec ±4.84% (93 runs sampled)
	unescape 32 chars x 687,177 ops/sec ±1.01% (99 runs sampled)