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

@types/json-stable-stringify

Package Overview
Dependencies
Maintainers
1
Versions
19
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

  • 1.1.0
  • ts4.8
  • ts4.9
  • ts5.0
  • ts5.1
  • ts5.2
  • ts5.3
  • ts5.4
  • ts5.5
  • ts5.6
  • ts5.7
  • ts5.8
  • latest
  • Source
  • npm
  • Socket score

Version published
Maintainers
1
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 24 Oct 2024

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