{"name":"safe-stringify","version":"1.2.0","keywords":["json","stringify","safe","circular","destroy","serialize","encode","cyclic","object"],"author":{"url":"https://sindresorhus.com","name":"Sindre Sorhus","email":"sindresorhus@gmail.com"},"license":"MIT","_id":"safe-stringify@1.2.0","maintainers":[{"name":"sindresorhus","email":"sindresorhus@gmail.com"}],"homepage":"https://github.com/sindresorhus/safe-stringify#readme","bugs":{"url":"https://github.com/sindresorhus/safe-stringify/issues"},"dist":{"shasum":"d9f8122dc087774182123d45ba65c91fb8603770","tarball":"http://registry-npm.ywwl.com/safe-stringify/download/safe-stringify-1.2.0.tgz","fileCount":5,"integrity":"sha512-C+LbapLbyGhP/WeMTrnYhIPjUoNTXZ/A3Znli8D5iF+IZXrDlgvfruykOq/bZ/5ncGy/K6RsavHlkirgWDFNdA==","signatures":[{"sig":"MEUCIB9yNTZYdVCm6wGi3lXfOp7ec1dVGbUoKJihxl1zUPflAiEAn0zh4nK8ccOoXnepqWJbOSCAGJ/k9zaFfjts6lmCGio=","keyid":"SHA256:DhQ8wR5APBvFHLF/+Tc+AYvPOdTpcIDqOhxsBHRwC7U"}],"unpackedSize":4741,"size":2297,"noattachment":false,"key":"/safe-stringify/-/safe-stringify-1.2.0.tgz"},"type":"module","types":"./index.d.ts","engines":{"node":">=16"},"exports":{"types":"./index.d.ts","default":"./index.js"},"funding":"https://github.com/sponsors/sindresorhus","gitHead":"d0512ee503d6109ec6d48f145be51eeff86c7ee5","scripts":{"test":"xo && ava && tsd"},"_npmUser":{"name":"sindresorhus","email":"sindresorhus@gmail.com"},"repository":{"url":"git+https://github.com/sindresorhus/safe-stringify.git","type":"git"},"_npmVersion":"10.9.2","description":"Serialize objects to JSON with handling for circular references","directories":{},"sideEffects":false,"_nodeVersion":"20.19.1","_hasShrinkwrap":false,"devDependencies":{"xo":"^0.58.0","ava":"^6.1.3","tsd":"^0.31.1"},"_npmOperationalInternal":{"tmp":"tmp/safe-stringify_1.2.0_1748607943631_0.4082747363852346","host":"s3://npm-registry-packages-npm-production"},"readme":"# safe-stringify\n\n> Serialize objects to JSON with handling for circular references\n\n`JSON.stringify()` throws an error if the object contains circular references. This package replaces circular references with `\"[Circular]\"`.\n\n## Install\n\n```sh\nnpm install safe-stringify\n```\n\n## Usage\n\n```js\nimport safeStringify from 'safe-stringify';\n\nconst foo = {a: true};\nfoo.b = foo;\n\nconsole.log(safeStringify(foo));\n//=> '{\"a\":true,\"b\":\"[Circular]\"}'\n\nconsole.log(JSON.stringify(foo));\n//=> TypeError: Converting circular structure to JSON\n\n```\n\n## API\n\n### safeStringify(value, options?)\n\nReturns a string.\n\n*Note: There is no `replacer` option as I didn't need that, but “pull request welcome” if you need it.*\n\n#### value\n\nType: `unknown`\n\nThe value to convert to a JSON string.\n\n#### options\n\nType: `object`\n\n##### indentation\n\nType: `'string' | 'number'`\n\nThe indentation of the JSON.\n\nBy default, the JSON is not indented. Set it to `'\\t'` for tab indentation or the number of spaces you want.\n\n##### trace\n\nType: `boolean`\n\nInclude the full object path in circular reference markers, like `[Circular *a.b]`.\n\n```js\nimport safeStringify from 'safe-stringify';\n\nconst bar = {a: {b: {}}};\nbar.a.b.c = bar.a;\n\nconsole.log(safeStringify(bar, {trace: true}));\n//=> '{\"a\":{\"b\":{\"c\":\"[Circular *a]\"}}}'\n```\n\n## FAQ\n\n### Why another safe stringify package?\n\nThe existing ones either did too much, did it incorrectly, or used inefficient code (not using `WeakSet`). For example, many packages incorrectly replaced all duplicate objects, not just circular references, and did not handle circular arrays.\n\n## Related\n\n- [decircular](https://github.com/sindresorhus/decircular) - Remove circular references from objects\n","publish_time":1748607943836,"_cnpm_publish_time":1748607943836,"dist-tags":{"latest":"1.3.0"}}