Socket
Socket
Sign inDemoInstall

@types/json-stable-stringify

Package Overview
Dependencies
Maintainers
1
Versions
18
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@types/json-stable-stringify

TypeScript definitions for json-stable-stringify


Version published
Weekly downloads
2.2M
decreased by-1.4%
Maintainers
1
Weekly downloads
 
Created

What is @types/json-stable-stringify?

@types/json-stable-stringify is a TypeScript type definition package for the json-stable-stringify library. This library provides a way to stringify JavaScript objects in a consistent and stable order, which is useful for tasks like comparing JSON objects or generating consistent hash values.

What are @types/json-stable-stringify's main functionalities?

Stable Stringification

This feature allows you to stringify a JavaScript object in a stable order. The keys in the resulting JSON string are sorted, ensuring consistent output for the same input object.

{"typescript":"import stringify from 'json-stable-stringify';\n\nconst obj = { b: 1, a: 2 };\nconst stableString = stringify(obj);\nconsole.log(stableString); // Output: '{\"a\":2,\"b\":1}'"}

Custom Comparator

This feature allows you to provide a custom comparator function to control the order of keys in the resulting JSON string. In this example, the keys are sorted in reverse order.

{"typescript":"import stringify from 'json-stable-stringify';\n\nconst obj = { b: 1, a: 2 };\nconst stableString = stringify(obj, { cmp: (a, b) => a.key < b.key ? 1 : -1 });\nconsole.log(stableString); // Output: '{\"b\":1,\"a\":2}'"}

Custom Replacer

This feature allows you to provide a custom replacer function to filter or modify values during the stringification process. In this example, the key 'b' is excluded from the resulting JSON string.

{"typescript":"import stringify from 'json-stable-stringify';\n\nconst obj = { b: 1, a: 2, c: 3 };\nconst stableString = stringify(obj, { replacer: (key, value) => key === 'b' ? undefined : value });\nconsole.log(stableString); // Output: '{\"a\":2,\"c\":3}'"}

Other packages similar to @types/json-stable-stringify

FAQs

Package last updated on 06 Jul 2021

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