The `javascript-stringify` library provides a function, `stringify`, that converts JavaScript values into a string representation that can be safely `eval`'d back into JavaScript, in contrast to `JSON.stringify` which outputs JSON. It supports serializing a wider range of JavaScript types, including regular expressions, `Date` objects, `Number` objects, `Error`, `Map`, `Set`, and most notably, functions (including ES methods, async, and generator functions). It also handles circular references by default omitting them or, with an option, restoring them via an IIFE. The current stable version is 2.1.0. Releases appear driven by bug fixes and feature enhancements rather than a strict cadence, with significant changes like TypeScript rewrite and ESM transition occurring in major versions. Its primary differentiator is the ability to produce evaluable JavaScript code, making it useful for scenarios like code generation or transmitting configuration that includes functional logic.
npm install javascript-stringifyVerified import paths — ran on the pinned version, not inferred.
Demonstrates `stringify` with various data types, including functions, dates, regex, and options like `references` for circular handling and `maxDepth`.
Update your import statements: For ESM, use `import { stringify } from 'javascript-stringify';`. For CommonJS, use `const { stringify } = require('javascript-stringify');`.Replace usages of `new Buffer()` with `Buffer.from()` or `Buffer.alloc()` in your application code, consistent with Node.js best practices.
Pass `{ references: true }` in the options object to `stringify` if you intend for circular/repeated references to be restored as an IIFE.Adjust the `maxDepth` (default: 100) and `maxValues` (default: 100000) options in the `stringify` call if you are stringifying very large or deeply nested objects and require the full output.
Ensure you are using `import { stringify } from 'javascript-stringify';` for ESM or `const { stringify } = require('javascript-stringify');` for CommonJS.Ensure you are correctly calling `javascript-stringify`'s `stringify` function. If you need circular references restored, use the `references: true` option with `javascript-stringify`.
No dependency data recorded yet.