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

json-escaping

v2.0.0

Published

Fast JSON string escaping

Downloads

961

Readme

JSON-escape

Fast JSON string escaping in JS. The purpose is to have a very fast check for strings that do not need escaping while not being much slower than JSON.stringify() in case the input requires escaping.

escapeString(string)

  • string {string}
  • Returns {string}
const escapeString = require('fast-json-escape')

const input = 'Hello\r\nWorld\t!'

escapeString(input)
// '"Hello\\r\\nWorld\\t!"'
JSON.stringify(input)
// '"Hello\\r\\nWorld\\t!"'

Benchmarks

Running the benchmarks (npm run benchmark) show the benefits:

node ./benchmark

JSON short non escaped x 5,301,888 ops/sec ±2.78% (85 runs sampled)
this short non escaped x 11,970,051 ops/sec ±1.85% (89 runs sampled)
JSON short full escape 1 x 5,372,215 ops/sec ±2.62% (87 runs sampled)
this short full escape 1 x 4,486,695 ops/sec ±3.49% (88 runs sampled)
JSON short full escape 2 x 5,071,447 ops/sec ±3.86% (86 runs sampled)
this short full escape 2 x 4,244,429 ops/sec ±3.63% (87 runs sampled)
JSON short minimal escape x 5,206,647 ops/sec ±3.43% (87 runs sampled)
this short minimal escape x 4,452,424 ops/sec ±2.78% (90 runs sampled)
JSON longer non escape x 604,108 ops/sec ±2.32% (90 runs sampled)
this longer non escape x 910,685 ops/sec ±3.12% (92 runs sampled)
JSON longer full escape x 566,829 ops/sec ±2.07% (90 runs sampled)
this longer full escape x 554,156 ops/sec ±1.01% (91 runs sampled)
JSON longer minimal escape x 666,831 ops/sec ±1.61% (89 runs sampled)
this longer minimal escape x 606,863 ops/sec ±1.76% (90 runs sampled)

The benchmarks ran on Node.js 18.14.0 using a Dell Precision 5540, i7-9850H CPU @ 2.60GHz. The "longer" benchmarks are worst case benchmarks.