{"name":"safe-stringify","version":"1.1.1","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.1.1","homepage":"https://github.com/sindresorhus/safe-stringify#readme","bugs":{"url":"https://github.com/sindresorhus/safe-stringify/issues"},"dist":{"shasum":"f4240f506d041f58374d6106e2a5850f6b1ce576","tarball":"http://registry-npm.ywwl.com/safe-stringify/download/safe-stringify-1.1.1.tgz","fileCount":5,"integrity":"sha512-YSzQLuwp06fuvJD1h6+vVNFYZoXmDs5UUNPUbTvQK7Ap+L0qD4Vp+sN434C+pdS3prVVlUfQdNeiEIgxox/kUQ==","signatures":[{"sig":"MEQCIE9P1nQLzHTi4SyYNtypLrU4Mh4h3fXRCD0UcSbBlO9tAiBb78ahLEBWWuwVa+k1DVEKf0E8u8lWAgN0raVqjArc2w==","keyid":"SHA256:jl3bwswu80PjjokCgh0o2w5c2U4LhQAE57gj9cz1kzA"}],"unpackedSize":4731,"size":2291,"noattachment":false,"key":"/safe-stringify/-/safe-stringify-1.1.1.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":"0a6cf54c667172c01d2fb8205354ac3ed06f7116","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.6.0","description":"Serialize objects to JSON with handling for circular references","directories":{},"sideEffects":false,"_nodeVersion":"22.2.0","_hasShrinkwrap":false,"devDependencies":{"xo":"^0.58.0","ava":"^6.1.3","tsd":"^0.31.1"},"_npmOperationalInternal":{"tmp":"tmp/safe-stringify_1.1.1_1719148505765_0.9781362227733819","host":"s3://npm-registry-packages"},"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":1719148505912,"maintainers":[{"name":"sindresorhus","email":"sindresorhus@gmail.com"}],"_cnpm_publish_time":1719148505912,"dist-tags":{"latest":"1.3.0"}}