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

canonical-json

v0.0.4

Published

a canonical json implementation

Downloads

107,680

Readme

#Canonical JSON

The goal of this module is to implement a version of JSON.stringify that returns a canonical JSON format.

Canonical JSON means that the same object should always be stringified to the exact same string.
JavaScripts native JSON.stringify does not guarantee any order for object keys when serializing:

Properties of non-array objects are not guaranteed to be stringified in any particular order. Do not rely on ordering of properties within the same object within the stringification.

Source: https://developer.mozilla.org/en-US/docs/JavaScript/Reference/Global_Objects/JSON/stringify

This module implements two alternative solutions to this problem:

  • index.js is based on Douglas Crockford's json2.js. I modified it to serialize object keys sorted on the fly.
  • index2.js recursively creates a copy of the object to sort its keys. The copy is then simply passed to native JSON.stringify

It currently exports the index.js version.

##Performance comparison I compared the performance of native JSON.stringify and the two alternative implementations that output keys sorted:

  • native JSON.stringify: 75 ms
  • js JSON.stringify with sorted keys (implementation): 308 ms
  • copy and native JSON.stringify with sorted keys (implementation: 291 ms

The tests were run in Node.js on a 2011 MacBook Pro.
Performance test source: test/performance.js