Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

fast-stringify

Package Overview
Dependencies
Maintainers
1
Versions
9
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

fast-stringify

A blazing fast stringifier that safely handles circular objects

  • 1.0.1
  • Source
  • npm
  • Socket score

Version published
Maintainers
1
Created
Source

fast-stringify

A blazing fast stringifier that safely handles circular objects

Table of contents

Usage

import stringify from "fast-stringify";

const object = {
  foo: "bar",
  deeply: {
    recursive: {
      object: {}
    }
  }
};

object.deeply.recursive.object = object;

console.log(stringify(object));
// {"foo":"bar","deeply":{"recursive":{"object":"[ref-0]"}}}
stringify

stringify(object: any, replacer: ?function, indent: ?number, circularReplacer: ?function): string

Stringifies the object passed based on the parameters you pass. The only required value is the object. The additional parameters passed will customize how the string is compiled.

  • replacer => function to customize how the value for each key is stringified (see the documentation for JSON.stringify for more details)
  • indent => number of spaces to indent the stringified object for pretty-printing (see the documentation for JSON.stringify for more details)
  • circularReplacer => function to customize how the circular reference is stringified (defaults to [ref-##] where ## is the reference count)

Benchmarks

Simple objects

Small number of properties, all values are primitives

Operations / secondRelative margin of error
fast-stringify633,7490.85%
fast-json-stable-stringify349,3510.58%
json-stringify-safe292,4560.75%
json-stable-stringify267,3590.57%
json-cycle193,8630.71%
decircularize121,9320.70%
Complex objects

Large number of properties, values are a combination of primitives and complex objects

Operations / secondRelative margin of error
fast-stringify116,1550.67%
fast-json-stable-stringify57,4840.68%
json-cycle52,7580.71%
json-stringify-safe52,5750.72%
json-stable-stringify41,7610.60%
decircularize21,7840.88%
Circular objects

Objects that deeply reference themselves

Operations / secondRelative margin of error
fast-stringify105,9320.84%
json-stringify-safe49,3661.07%
json-cycle49,1520.67%
decircularize20,6260.81%
fast-json-stable-stringify (not supported)00.00%
json-stable-stringify (not supported)00.00%
Special objects

Custom constructors, React components, etc

Operations / secondRelative margin of error
fast-stringify35,3910.67%
json-cycle20,4130.63%
fast-json-stable-stringify17,9080.52%
json-stringify-safe16,9880.85%
json-stable-stringify13,9840.85%
decircularize7,2230.65%

Development

Standard practice, clone the repo and npm i to get the dependencies. The following npm scripts are available:

  • benchmark => run benchmark tests against other equality libraries
  • build => build dist files with rollup
  • clean => run clean:dist, clean:es, and clean:lib scripts
  • clean:dist => run rimraf on the dist folder
  • clean:es => run rimraf on the es folder
  • clean:lib => run rimraf on the lib folder
  • dev => start webpack playground App
  • dist => run build and build:minified scripts
  • lint => run ESLint on all files in src folder (also runs on dev script)
  • lint:fix => run lint script, but with auto-fixer
  • prepublish:compile => run lint, test:coverage, transpile:lib, transpile:es, and dist scripts
  • start => run dev
  • test => run AVA with NODE_ENV=test on all files in test folder
  • test:coverage => run same script as test with code coverage calculation via nyc
  • test:watch => run same script as test but keep persistent watcher
  • transpile:es => run Babel on all files in src folder (transpiled to es folder without transpilation of ES2015 export syntax)
  • transpile:lib => run Babel on all files in src folder (transpiled to lib folder)

Keywords

FAQs

Package last updated on 04 Jun 2018

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc