{"name":"json-stream-stringify","description":"JSON.Stringify as a readable stream","version":"3.1.7","license":"MIT","author":{"name":"Faleij","email":"faleij@gmail.com","url":"https://github.com/faleij"},"repository":{"type":"git","url":"git+https://github.com/Faleij/json-stream-stringify.git"},"bugs":{"url":"https://github.com/faleij/json-stream-stringify/issues"},"main":"./lib/cjs/index.js","module":"./lib/esm/index.mjs","umd:main":"./lib/umd/index.js","browser":"./lib/umd/index.js","types":"./lib/types/index.d.ts","nyc":{"sourceMap":true,"instrument":true,"reporter":["lcov","text"],"extension":[".ts"],"exclude":["**/*.d.ts","test-src/**/*"]},"scripts":{"lint":"eslint \"src/**/*.ts\" && echo ✅ eslint passed","build":"node --max-old-space-size=8192 node_modules/rollup/dist/bin/rollup -c rollup.config.js","build:watch":"npm run build -- --watch","test":"node node_modules/mocha/bin/mocha --require source-map-support/register -R spec -b \"test/*.spec.js\"","coverage":"node node_modules/nyc/bin/nyc.js npm test"},"devDependencies":{"@babel/cli":"^7.18.9","@babel/core":"^7.18.9","@babel/plugin-syntax-dynamic-import":"^7.8.3","@babel/plugin-transform-runtime":"^7.18.9","@babel/runtime":"^7.18.9","@babel/plugin-transform-typescript":"^7.18.8","@babel/preset-env":"^7.18.9","@babel/preset-typescript":"^7.18.6","@rollup/plugin-babel":"^5.3.1","@rollup/plugin-node-resolve":"^13.3.0","@types/expect.js":"^0.3.29","@types/mocha":"^9.1.1","@types/readable-stream":"^2.3.14","@typescript-eslint/eslint-plugin":"^5.31.0","@typescript-eslint/parser":"^5.31.0","core-js":"^3.24.0","coveralls":"3.1.1","es-check":"^7.0.0","eslint":"^8.20.0","eslint-config-airbnb":"^19.0.4","eslint-plugin-import":"^2.26.0","eslint-plugin-jsx-a11y":"^6.5.1","eslint-plugin-react":"^7.28.0","eslint-plugin-react-hooks":"^4.3.0","expect.js":"0.3.1","mocha":"^10.2.0","nyc":"15.1.0","rollup":"2.77.0","rollup-plugin-dts":"^4.2.2","rollup-plugin-typescript2":"^0.32.1","source-map-support":"^0.5.21","typescript":"^4.9.5"},"volta":{"node":"22.23.0","npm":"11.16.0"},"engines":{"node":">=7.10.1"},"overrides":{"@types/node":"^18.19.0"},"exports":{".":{"types":"./lib/types/index.d.ts","import":"./lib/esm/index.mjs","require":"./lib/umd/index.js"},"./polyfill":{"types":"./lib/types/index.d.ts","import":"./lib/esm/index.polyfill.mjs","require":"./lib/umd/polyfill.js"},"./esm/polyfill":{"types":"./lib/types/index.d.ts","import":"./lib/esm/index.polyfill.mjs","require":"./lib/esm/index.polyfill.mjs"},"./esm":{"types":"./lib/types/index.d.ts","import":"./lib/esm/index.mjs","require":"./lib/esm/index.mjs"},"./umd/polyfill":{"types":"./lib/types/index.d.ts","import":"./lib/umd/polyfill.js","require":"./lib/umd/polyfill.js"},"./umd":{"types":"./lib/types/index.d.ts","import":"./lib/umd/index.js","require":"./lib/umd/index.js"},"./cjs/polyfill":{"types":"./lib/types/index.d.ts","import":"./lib/cjs/polyfill.js","require":"./lib/cjs/polyfill.js"},"./cjs":{"types":"./lib/types/index.d.ts","import":"./lib/cjs/index.js","require":"./lib/cjs/index.js"}},"_id":"json-stream-stringify@3.1.7","homepage":"https://github.com/Faleij/json-stream-stringify#readme","_nodeVersion":"24.16.0","_npmVersion":"11.13.0","dist":{"integrity":"sha512-F4MWetLtY42YMaAKw5cV4e47zMD5aOT+tjjQWjX18ACtdkQ5Y/vrcfbcQ107Rh+MXjOCIx4KhW0wPmOvG8iQ5w==","shasum":"80a29711b43b1d9e4d9eccd4f6873df3f68da22a","tarball":"http://registry-npm.ywwl.com/json-stream-stringify/download/json-stream-stringify-3.1.7.tgz","fileCount":17,"unpackedSize":342478,"attestations":{"url":"https://registry.npmjs.org/-/npm/v1/attestations/json-stream-stringify@3.1.7","provenance":{"predicateType":"https://slsa.dev/provenance/v1"}},"signatures":[{"keyid":"SHA256:DhQ8wR5APBvFHLF/+Tc+AYvPOdTpcIDqOhxsBHRwC7U","sig":"MEUCIEup8jOP30IVz11V3/PWmB3u+mX75ODoP0KT/ThomntmAiEA5CohpttrHSpgfyP6oC9H1/Cj8by0sOc7BQWUw77Ijkw="}],"size":72654,"noattachment":false,"key":"/json-stream-stringify/-/json-stream-stringify-3.1.7.tgz"},"_npmUser":{"name":"GitHub Actions","email":"npm-oidc-no-reply@github.com","trustedPublisher":{"id":"github","oidcConfigId":"oidc:5081af76-6405-4984-9137-911ac897a6fe"}},"directories":{},"maintainers":[{"name":"faleij","email":"faleij@live.se"}],"_npmOperationalInternal":{"host":"s3://npm-registry-packages-npm-production","tmp":"tmp/json-stream-stringify_3.1.7_1782040122154_0.6962430146425183"},"_hasShrinkwrap":false,"readme":"# JSON Stream Stringify\n\n[![NPM version][npm-image]][npm-url]\n[![NPM Downloads][downloads-image]][downloads-url]\n[![Build Status][travis-image]][travis-url]\n[![Coverage Status][coveralls-image]][coveralls-url]\n[![License][license-image]](LICENSE)\n[![Donate][donate-image]][donate-url]\n\nJSON Stringify as a Readable Stream with rescursive resolving of any readable streams and Promises.\n\n## Important and Breaking Changes in v3.1.0\n\n- Completely rewritten from scratch - again\n- Buffer argument added (Stream will not output data untill buffer size is reached - improves speed)\n- Dropped support for node <7.10.1 - async supporting environment now required\n\n## Main Features\n\n- Promises are rescursively resolved and the result is piped through JsonStreamStringify\n- Streams (Object mode) are recursively read and output as arrays\n- Streams (Non-Object mode) are output as a single string\n- Output is streamed optimally with as small chunks as possible\n- Cycling of cyclical structures and dags using [Douglas Crockfords cycle algorithm](https://github.com/douglascrockford/JSON-js)*\n- Great memory management with reference release after processing and WeakMap/Set reference handling\n- Optimal stream pressure handling\n- Tested and runs on ES5**, ES2015**, ES2016 and later\n- Bundled as UMD and Module\n\n\\* Off by default since v2  \n\\** With [polyfills](#usage)  \n\n## Install\n\n```bash\nnpm install --save json-stream-stringify\n\n# Optional if you need polyfills\n# Make sure to include these if you target NodeJS <=v6 or browsers\nnpm install --save @babel/polyfill @babel/runtime\n```\n\n## Usage\n\nUsing Node v8 or later with ESM / Webpack / Browserify / Rollup\n\n### No Polyfills, TS / ESM\n\n```javascript\nimport { JsonStreamStringify } from 'json-stream-stringify';\n```\n\n### Polyfilled, TS / ESM\n\ninstall @babel/runtime-corejs3 and corejs@3\n\n```javascript\nimport { JsonStreamStringify }  from 'json-stream-stringify/polyfill';\nimport { JsonStreamStringify }  from 'json-stream-stringify/module.polyfill'; // force ESM\n```\n\n### Using Node >=8 / Other ES2015 UMD/CommonJS environments\n\n```javascript\nconst { JsonStreamStringify } = require('json-stream-stringify'); // let module resolution decide UMD or CJS\nconst { JsonStreamStringify } = require('json-stream-stringify/umd'); // force UMD\nconst { JsonStreamStringify } = require('json-stream-stringify/cjs'); // force CJS\n```\n\n### Using Node <=6 / Other ES5 UMD/CommonJS environments\n\n```javascript\nconst { JsonStreamStringify } = require('json-stream-stringify/polyfill');\nconst { JsonStreamStringify } = require('json-stream-stringify/umd/polyfill');\nconst { JsonStreamStringify } = require('json-stream-stringify/cjs/polyfill');\n```\n\n**Note:** This library is primarily written for LTS versions of NodeJS. Other environments are not tested.  \n**Note on non-NodeJS usage:** This module depends on node streams library. Any Streams3 compatible implementation should work - as long as it exports a `Readable` class, with instances that looks like readable streams.  \n**Note on Polyfills:** I have taken measures to minify global pollution of polyfills but this library **does not load polyfills by default** because the polyfills modify native object prototypes and it goes against the [W3C recommendations](https://www.w3.org/2001/tag/doc/polyfills/#advice-for-library-and-framework-authors).\n\n## API\n\n### `new JsonStreamStringify(value[, replacer[, spaces[, cycle[, bufferSize=512]]]])`  \n\nStreaming conversion of ``value`` to JSON string.\n\n#### Parameters\n\n- ``value`` ``Any``  \n  Data to convert to JSON.\n\n- ``replacer`` Optional ``Function(key, value)`` or ``Array``  \n  As a function the returned value replaces the value associated with the key. [Details](https://developer.mozilla.org/en/docs/Web/JavaScript/Reference/Global_Objects/JSON/stringify#The_replacer_parameter)  \n As an array all other keys are filtered. [Details](https://developer.mozilla.org/en/docs/Web/JavaScript/Reference/Global_Objects/JSON/stringify#Example_with_an_array)\n\n- ``spaces`` Optional ``String`` or ``Number``  \n  A String or Number object that's used to insert white space into the output JSON string for readability purposes. If this is a Number, it indicates the number of space characters to use as white space. If this is a String, the string is used as white space. If this parameter is not recognized as a finite number or valid string, no white space is used.\n\n- ``cycle`` Optional ``Boolean``  \n  ``true`` enables cycling of cyclical structures and dags.  \n  To restore cyclical structures; use [Crockfords Retrocycle method](https://github.com/douglascrockford/JSON-js) on the parsed object (not included in this module).\n\n#### Returns\n\n- ``JsonStreamStringify`` object that exposes a [Streams3 interface](https://nodejs.org/api/stream.html#stream_class_stream_readable).\n\n### jsonStreamStringify#path\n\nGet current path begin serialized.\n\n#### Returns\n\n- ``Array[String, Number]``  \n  Array of path Strings (keys of objects) and Numbers (index into arrays).  \n  Can be transformed into an mpath with ``.join('.')``.  \n  Useful in conjunction with ``.on('error', ...)``, for figuring out what path may have caused the error.\n\n## Complete Example\n\n```javascript\nconst { JsonStreamStringify } = require('json-stream-stringify');\n\nconst jsonStream = new JsonStreamStringify({\n    // Promises and Streams may resolve more promises and/or streams which will be consumed and processed into json output\n    aPromise: Promise.resolve(Promise.resolve(\"text\")),\n    aStream: ReadableObjectStream({a:1}, 'str'),\n    arr: [1, 2, Promise.resolve(3), Promise.resolve([4, 5]), ReadableStream('a', 'b', 'c')],\n    date: new Date(2016, 0, 2)\n});\njsonStream.once('error', () => console.log('Error at path', jsonStream.stack.join('.')));\njsonStream.pipe(process.stdout);\n```\n\nOutput (each line represents a write from jsonStreamStringify)\n\n```text\n{\n\"aPromise\":\n\"text\"\n\"aStream\":\n[\n{\n\"a\":\n1\n}\n,\n\"str\"\n]\n\"arr\":\n[\n1\n,\n2\n,\n3\n,\n[\n4\n,\n5\n]\n,\n\"\na\nb\nc\n\"\n],\n\"date\":\n\"2016-01-01T23:00:00.000Z\"\n}\n```\n\n## Practical Example with Express + Mongoose\n\n```javascript\napp.get('/api/users', (req, res, next) => {\n  res.type('json'); // Required for proper handling by test frameworks and some clients\n  new JsonStreamStringify(Users.find().stream()).pipe(res);\n});\n```\n\n### Why do I not get proper typings? (Missing .on(...), etc.)\n\ninstall ``@types/readable-stream`` or ``@types/node`` or create your own ``stream.d.ts`` that exports a ``Readable`` class.\n\n## License\n\n[MIT](LICENSE)\n\nCopyright (c) 2016 Faleij [faleij@gmail.com](mailto:faleij@gmail.com)\n\n[npm-image]: http://img.shields.io/npm/v/json-stream-stringify.svg\n[npm-url]: https://npmjs.org/package/json-stream-stringify\n[downloads-image]: https://img.shields.io/npm/dm/json-stream-stringify.svg\n[downloads-url]: https://npmjs.org/package/json-stream-stringify\n[travis-image]: https://travis-ci.org/Faleij/json-stream-stringify.svg?branch=master\n[travis-url]: https://travis-ci.org/Faleij/json-stream-stringify\n[coveralls-image]: https://coveralls.io/repos/Faleij/json-stream-stringify/badge.svg?branch=master&service=github\n[coveralls-url]: https://coveralls.io/github/Faleij/json-stream-stringify?branch=master\n[license-image]: https://img.shields.io/badge/license-MIT-blue.svg\n[donate-image]: https://img.shields.io/badge/Donate-PayPal-green.svg\n[donate-url]: https://www.paypal.com/cgi-bin/webscr?cmd=_donations&business=faleij%40gmail%2ecom&lc=GB&item_name=faleij&item_number=jsonStreamStringify&currency_code=SEK&bn=PP%2dDonationsBF%3abtn_donate_SM%2egif%3aNonHosted\n","publish_time":1782040122324,"_cnpm_publish_time":1782040122324,"dist-tags":{"latest":"3.1.7"}}