{"name":"json-stream-stringify","version":"3.1.6","author":{"url":"https://github.com/faleij","name":"Faleij","email":"faleij@gmail.com"},"license":"MIT","_id":"json-stream-stringify@3.1.6","maintainers":[{"name":"faleij","email":"faleij@live.se"}],"homepage":"https://github.com/Faleij/json-stream-stringify#readme","bugs":{"url":"https://github.com/faleij/json-stream-stringify/issues"},"nyc":{"exclude":["**/*.d.ts","test-src/**/*"],"reporter":["lcov","text"],"extension":[".ts"],"sourceMap":true,"instrument":true},"dist":{"shasum":"ebe32193876fb99d4ec9f612389a8d8e2b5d54d4","tarball":"http://registry-npm.ywwl.com/json-stream-stringify/download/json-stream-stringify-3.1.6.tgz","fileCount":17,"integrity":"sha512-x7fpwxOkbhFCaJDJ8vb1fBY3DdSa4AlITaz+HHILQJzdPMnHEFjxPwVUi1ALIbcIxDE0PNe/0i7frnY8QnBQog==","signatures":[{"sig":"MEUCIBIlBygcZWAcTls/mPCM7x+oQgHJ8axc8iKtLl7cX6PJAiEAoq1p/h/ZmjaSxLpuJSBBGR9jCQ5XwEmM0WcxcevZcfg=","keyid":"SHA256:jl3bwswu80PjjokCgh0o2w5c2U4LhQAE57gj9cz1kzA"}],"unpackedSize":343315,"size":77845,"noattachment":false,"key":"/json-stream-stringify/-/json-stream-stringify-3.1.6.tgz"},"main":"./lib/cjs/index.js","types":"./lib/types/index.d.ts","volta":{"node":"18.20.4"},"module":"./lib/esm/index.mjs","browser":"./lib/umd/index.js","engines":{"node":">=7.10.1"},"exports":{".":{"types":"./lib/types/index.d.ts","import":"./lib/esm/index.mjs","require":"./lib/umd/index.js"},"./cjs":{"types":"./lib/types/index.d.ts","import":"./lib/cjs/index.js","require":"./lib/cjs/index.js"},"./esm":{"types":"./lib/types/index.d.ts","import":"./lib/esm/index.mjs","require":"./lib/esm/index.mjs"},"./umd":{"types":"./lib/types/index.d.ts","import":"./lib/umd/index.js","require":"./lib/umd/index.js"},"./polyfill":{"types":"./lib/types/index.d.ts","import":"./lib/esm/index.polyfill.mjs","require":"./lib/umd/polyfill.js"},"./cjs/polyfill":{"types":"./lib/types/index.d.ts","import":"./lib/cjs/polyfill.js","require":"./lib/cjs/polyfill.js"},"./esm/polyfill":{"types":"./lib/types/index.d.ts","import":"./lib/esm/index.polyfill.mjs","require":"./lib/esm/index.polyfill.mjs"},"./umd/polyfill":{"types":"./lib/types/index.d.ts","import":"./lib/umd/polyfill.js","require":"./lib/umd/polyfill.js"}},"scripts":{"lint":"eslint \"src/**/*.ts\" && echo ✅ eslint passed","test":"node node_modules/mocha/bin/mocha --require source-map-support/register -R spec -b \"test/*.spec.js\"","build":"node --max-old-space-size=8192 node_modules/rollup/dist/bin/rollup -c rollup.config.js","coverage":"node node_modules/nyc/bin/nyc.js npm test","build:watch":"npm run build -- --watch"},"_npmUser":{"name":"faleij","email":"faleij@live.se"},"umd:main":"./lib/umd/index.js","repository":{"url":"git+https://github.com/Faleij/json-stream-stringify.git","type":"git"},"_npmVersion":"10.7.0","description":"JSON.Stringify as a readable stream","directories":{},"_nodeVersion":"18.20.4","_hasShrinkwrap":false,"devDependencies":{"nyc":"15.1.0","mocha":"^10.2.0","eslint":"^8.20.0","rollup":"2.77.0","core-js":"^3.24.0","es-check":"^7.0.0","coveralls":"3.1.1","expect.js":"0.3.1","@babel/cli":"^7.18.9","typescript":"^4.7.4","@babel/core":"^7.18.9","@types/mocha":"^9.1.1","@types/expect.js":"^0.3.29","@babel/preset-env":"^7.18.9","rollup-plugin-dts":"^4.2.2","source-map-support":"^0.5.21","@rollup/plugin-babel":"^5.3.1","eslint-config-airbnb":"^19.0.4","eslint-plugin-import":"^2.26.0","@types/readable-stream":"^2.3.14","@babel/preset-typescript":"^7.18.6","rollup-plugin-typescript2":"^0.32.1","@rollup/plugin-node-resolve":"^13.3.0","@babel/plugin-transform-runtime":"^7.18.9","@typescript-eslint/eslint-plugin":"^5.31.0","@babel/plugin-transform-typescript":"^7.18.8","@babel/plugin-syntax-dynamic-import":"^7.8.3"},"_npmOperationalInternal":{"tmp":"tmp/json-stream-stringify_3.1.6_1728139901488_0.505734377340979","host":"s3://npm-registry-packages"},"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":1728139901676,"_cnpm_publish_time":1728139901676,"dist-tags":{"latest":"3.1.7"}}