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

stringifyit

v0.2.1

Published

Fast object stringifier

Readme

stringifyit

Fast node.js stringify library with sorting and typing. Provides Stringifier class. Stringifier provides stringify Symbol to allow you customize stringifying your own classes.

See benchmarks for compare to other libs.

Install

npm i stringifyit --save

Features

  • Supports node.js >= 4.0.0
  • Supports Map/WeakMap, Set/WeakSet and typed arrays
  • Supports sort Set, Map, object keys and optional sort arrays
  • Supports custom stringify rules for user-defined classes
  • Useful for browsers
  • Very fast stringify library

API

Classes

Members

Functions

Stringifier

Provides interface to stringify any value Sort Map, Set and object keys by default without ability to avoid it

Kind: global class

new Stringifier([options])

| Param | Type | | --- | --- | | [options] | options |

stringifier.string : string

Accumulator string

Kind: instance property of Stringifier
Access: public

stringifier.update(value)

Stringifies value and append it to current accumulator string

Kind: instance method of Stringifier

| Param | Type | | --- | --- | | value | * |

Stringifier~stringifyCallback : function

Custom stringify callback declared with stringify Symbol

Kind: inner typedef of Stringifier

| Param | Type | Description | | --- | --- | --- | | stringifier | Stringifier | Stringifier instance |

Example

const {stringify} = require('stringifyit');
CustomType.prototype[stringify] = function (stringifier) {
    stringifier.string += 'start';

    stringifier.update(this.someProp);
    stringifier.update(['use', 'any', 'type']);

    stringifier.string += 'end';
}

Stringifier~stringify : Symbol

Symbol to add custom stringify rules for user types

Kind: inner typedef of Stringifier

Stringifier~options : Object

Stringifier options

Kind: inner typedef of Stringifier
Properties

| Name | Type | Description | | --- | --- | --- | | sortArrays | boolean | Sort arrays before stringify | | includePrimitiveTypes | boolean | Stringify primitive values (and functions) types | | includeConstructorNames | boolean | Stringify non-primitive values constructor names |

stringify : stringify

Kind: global variable

stringifyit(value, [options]) ⇒ string

Helper for simple stringify single value

Kind: global function

| Param | Type | | --- | --- | | value | * | | [options] | options |

Example

const {stringifyit} = require('stringifyit');

stringifyit({key: 'value', value: 'key'}) === stringifyit({value: 'key', key: 'value'}); // true
stringifyit(new Set(['value1', 'value2'])) === stringifyit(new Set(['value2', 'value1'])); // true
stringifyit(new Map([['key', 'value'], ['value', 'key']])) === stringifyit(new Map([['value', 'key'], ['key', 'value']])); // true
stringifyit([1, 2, 3]) === stringifyit([1, 2, 3]); // true
stringifyit([1, 2, 3], {sortArrays: true}) === stringifyit([1, 3, 2], {sortArrays: true}); // true

stringifyit([1, 2, 3]) === stringifyit([1, 3, 2]); // false
stringifyit(5) === stringifyit('5'); // false

Custom stringifiers source

Object.prototype[stringify] : stringifyCallback

Array.prototype[stringify] : stringifyCallback

TypedArray.prototype[stringify] : stringifyCallback

Map.prototype[stringify] : stringifyCallback

WeakMap.prototype[stringify] : stringifyCallback

Set.prototype[stringify] : stringifyCallback

WeakSet.prototype[stringify] : stringifyCallback

Date.prototype[stringify] : stringifyCallback

Benchmarks

Benchmarked with Node.js v6.9.5

Usage

  • npm run bench to run benchmarking stringifyit operations/second for different cases

Results

array x 1,947,707 ops/sec ±1.60% (85 runs sampled)
object x 2,366,530 ops/sec ±1.30% (89 runs sampled)
nestedObject x 29,384 ops/sec ±1.48% (87 runs sampled)
complexObject_5items x 35,847 ops/sec ±1.87% (87 runs sampled)
complexObject_10items x 18,407 ops/sec ±2.03% (87 runs sampled)
complexObject_100items x 1,682 ops/sec ±2.09% (85 runs sampled)
set x 215,921 ops/sec ±2.52% (84 runs sampled)
map x 190,451 ops/sec ±2.57% (84 runs sampled)

License

MIT