Registry / serialization / node-stringify

node-stringify

JSON →
library0.2.1jsnpmunverified

node-stringify is a JavaScript utility for serializing objects into a string representation that can be directly re-evaluated using JavaScript's `eval()` function. Unlike `JSON.stringify`, it aims to preserve more JavaScript-specific constructs like `Date` objects, `RegExp`, and `function` definitions, making the output directly executable. The current stable version is 0.2.1. Given its low version number and the inherent security risks associated with `eval`, this library is not intended for general-purpose data serialization or secure environments. It explicitly warns against its use as a `JSON.stringify` replacement and does not support circular references or deeply nested objects due to its recursive implementation.

npm install node-stringify
INSTALL
IMPORT
SIG · NODE-STRINGIFY
N
node-stringify
serializationjavascriptv0.2.1
Install
Import
Disk
Pass rate
0/ 6
Env Coverage0 / 6
glibc
1822
musl
1822
Install & Compatibility
Where this runs
tested against v? · npm install
Install × environment matrix
Each cell = how many times install + import succeeded across repeated harness runs. Partial = flaky.
glibc = Debian/Ubuntu slim · musl = Alpine Linux
musl
node 18226 runs
build_error
glibc
node 18226 runs
build_error
Code
Verified usage

Verified import paths — ran on the pinned version, not inferred.

stringify
const stringify = require('node-stringify');
This package is primarily designed for CommonJS environments.

Demonstrates stringifying various JavaScript data types, including numbers, strings, null, undefined, dates, functions, arrays, and objects, showing output with and without optional parentheses.

const stringify = require('node-stringify'); // Basic types console.log(`Stringifying 123: ${stringify(123)}`); console.log(`Stringifying 'abc': ${stringify('abc')}`); console.log(`Stringifying null: ${stringify(null)}`); console.log(`Stringifying undefined: ${stringify(undefined)}`); // Complex types const myDate = new Date(1000); console.log(`Stringifying new Date(1000): ${stringify(myDate)}`); const myFunction = function (a,b,c) {}; console.log(`Stringifying a function: ${stringify(myFunction)}`); const myArray = [1, 2, 3]; console.log(`Stringifying an array: ${stringify(myArray)}`); const myObject = {a: 1, b: 2}; console.log(`Stringifying an object: ${stringify(myObject)}`); // Object with array, with custom options const complexObject = {a: 1, b: [2, 3]}; console.log(`Stringifying complex object (with parenthesis): ${stringify(complexObject)}`); console.log(`Stringifying complex object (without parenthesis): ${stringify(complexObject, {parenthesis: false})}`);
Debug
Known issues
breakingThis library is explicitly NOT designed to replace `JSON.stringify`. It produces output intended for `eval()`, which has significant security implications if the input string is not absolutely trusted. Using `eval()` with untrusted input can lead to arbitrary code execution.
fix
For general data serialization, always use `JSON.stringify()` and `JSON.parse()`. If you must re-evaluate code, ensure the source is entirely trusted and controlled.
affects: >=0.1.0
gotchaThe library does not support objects with circular references. Attempting to stringify an object containing a direct or indirect reference to itself will likely result in an infinite loop or a stack overflow.
fix
Ensure that objects passed to `stringify` do not contain circular references. Manual pre-processing to remove or replace circular references might be necessary, or consider alternatives that handle them (e.g., `flatted` or custom JSON replacers).
affects: >=0.1.0
gotchaThe default behavior for objects wraps the output in parentheses (e.g., `({a:1})`). This is to ensure the result is a valid expression when passed to `eval()`. However, this might be unexpected if you intend to get a plain object literal string.
fix
If you need the object literal without parentheses, pass `{ parenthesis: false }` as the second argument: `stringify(obj, { parenthesis: false })`.
affects: >=0.1.0
deprecatedThis package appears to be unmaintained. Its last update was in 2015, and it is at version 0.2.1. Relying on an unmaintained package for production systems introduces risks related to security vulnerabilities, compatibility issues with newer Node.js versions, and lack of bug fixes.
fix
Evaluate if this specific functionality is critical. If so, consider porting the necessary logic into your own codebase or finding a more actively maintained alternative if one exists for `eval`-targeted serialization. Otherwise, migrate to standard serialization methods.
affects: >=0.1.0
Errors
Common errors & fixes
RangeError: Maximum call stack size exceeded
Attempting to stringify an object with circular references or an excessively deep nesting level.
fix
Refactor your object structure to avoid circular dependencies, or manually remove/replace offending properties before stringifying. The library is not designed to handle these cases.
ReferenceError: require is not defined (when using 'import stringify from "node-stringify"')
The package is an older CommonJS module and does not natively support ES Modules `import` syntax.
fix
Use the CommonJS `require` syntax: `const stringify = require('node-stringify');`
Upgrade
Version history
0.2.1latest on npm
Audit
Dependencies

No dependency data recorded yet.

Agent activity
2 hits · last 30 days
node
2
Resources
node-stringify — npm install node-stringify · libregistry