{"name":"clarinet","description":"SAX based evented streaming JSON parser in JavaScript (browser and node)","author":{"name":"Nuno Job","email":"nunojobpinto@gmail.com","url":"http://nunojob.com/"},"contributors":[{"name":"Jann Horn","url":"https://github.com/thejh"},{"name":"Justin Makeig","email":"jmpublic+github@makeig.com","url":"http://www.audiblepop.com"},{"name":"Roly Fentanes","url":"http://about.me/roly"},{"name":"John Lancaster","url":"http://jlank.com"}],"version":"0.12.5","main":"./clarinet.js","homepage":"https://github.com/dscape/clarinet","repository":{"type":"git","url":"git+ssh://git@github.com/dscape/clarinet.git"},"bugs":{"url":"http://github.com/dscape/clarinet/issues"},"runkitExampleFilename":"example.js","keywords":["sax","json","parser","stream","streaming","event","events","emitter","async","streamer","browser"],"devDependencies":{"mocha":"^6.1.4","should":"1.0.x","underscore":"1.2.3"},"scripts":{"test":"mocha -r should -t 10000 -s 2000 test/parser.spec.js test/clarinet.js test/npm.js test/utf8-chunks.js test/position.js","bench":"cd benchmark && npm test","prebench":"cd benchmark && test -e node_modules || npm i --ignore-scripts"},"engines":{"node":">=0.3.6","firefox":">=0.8.0","chrome":">=16.0.912"},"directories":{"test":"test"},"license":"BSD-2-Clause","gitHead":"a9d21ca1efd2adb988d30ff739e3e4481675944e","_id":"clarinet@0.12.5","_nodeVersion":"12.22.6","_npmVersion":"6.14.15","dist":{"integrity":"sha512-4833ySquSUW91fnPaYI94LX3OdnyfwD8/NrMi6a4Kt6EmOsphLWmEzx9bZPqO9+DtQzSv2s3WSYNLsrXt59FKg==","shasum":"7ee9c3984620592e370063022d3d2982fc527228","tarball":"http://registry-npm.ywwl.com/clarinet/download/clarinet-0.12.5.tgz","fileCount":7,"unpackedSize":34640,"npm-signature":"-----BEGIN PGP SIGNATURE-----\r\nVersion: OpenPGP.js v3.0.13\r\nComment: https://openpgpjs.org\r\n\r\nwsFcBAEBCAAQBQJh2HQlCRA9TVsSAnZWagAAHQsP/2aUf2CTmQuRlFEWNZhK\nQRUc7vQbBWz8GVpuGR5uGZNMbnZsYhay39DeqDtqJQVH8ErgcoV5YCJUA12E\nTA54MFMyich48ksjjzPyltQP4VRlB6GVvvHiqgZ+42hhS4USzsl9ioWY0/GM\nkV0PgslDcvo2OhtoRlY36FswkTfQaE1LLjcah4KogCUzKt1zPdAYB7UY7lyL\npO49cGou0ShZbY6GC10r1sXU1gH/UP/ntnV4Id32du99jkj83T1W/NpHXzZu\n+S/4iS8KZ/MrfzhwMJPfKryMAIgoY9HKiMSloN6PnCuFrea61x6DxTSWay/s\ns7zw7oWbsU/Ei0ynp2uK2h9E8NZYQy957KYa6MBJVcGiK1SKhRvtGTmhc4Qx\n2FrbnYGcGOe0SWdMtBhhECcEq+wToNGZgtTnjnTcPrPcxbOjZwjuXe02HtTV\ngXgFzQvzQXndCAREIea/mtacd3EXXBVosBLdWCNpxGC5mRgI11w2su4RsU6R\nVXT24apndaatZRTOm8BLcTU3R5udWeXcTDJ5Ny7uFD+66uHt37G1hlL99L3U\nPChYs9nzwF1NcpO+U/vHWiB5zn2o4CdkZRLkHLvP8iEwAZjuYJbQe5zkqrR1\nbBnXVgSETWzsDvZbQRuQJe1QWQInTTyntu6gN6GQZD8l4IXT4YQl2zgybc9s\nVB4q\r\n=EkHI\r\n-----END PGP SIGNATURE-----\r\n","signatures":[{"keyid":"SHA256:jl3bwswu80PjjokCgh0o2w5c2U4LhQAE57gj9cz1kzA","sig":"MEQCIAIOIerJBwJ3SJteuWzEqaZp8bR3ZUbj6iGXTgb1L//uAiB9N7JAYXf2kYF8sx0z8HELbzZrqMRSy+Vg4Zr+5qMZrA=="}],"size":10692,"noattachment":false,"key":"/clarinet/-/clarinet-0.12.5.tgz"},"_npmUser":{"name":"evan-king","email":"HonoredSoft@gmail.com"},"maintainers":[{"name":"thejh","email":"jannhorn@googlemail.com"},{"name":"dscape","email":"nunojobpinto@gmail.com"},{"name":"evan-king","email":"HonoredSoft@gmail.com"}],"_npmOperationalInternal":{"host":"s3://npm-registry-packages","tmp":"tmp/clarinet_0.12.5_1641575461385_0.5518005354438229"},"_hasShrinkwrap":false,"readme":"# clarinet\n\n![NPM Downloads](http://img.shields.io/npm/dm/clarinet.svg?style=flat) ![NPM Version](http://img.shields.io/npm/v/clarinet.svg?style=flat) [![CDNJS](https://img.shields.io/cdnjs/v/clarinet.svg)](https://cdnjs.com/libraries/clarinet)\n\n`clarinet` is a sax-like streaming parser for JSON. works in the browser and node.js. `clarinet` is inspired (and forked) from [sax-js][saxjs]. just like you shouldn't use `sax` when you need `dom` you shouldn't use `clarinet` when you need `JSON.parse`. for a more detailed introduction and a performance study please refer to this [article][blog]. \n\n# design goals\n\n`clarinet` is very much like [yajl] but written in javascript:\n\n* written in javascript\n* portable\n* robust (~110 tests pass before even announcing the project)\n* data representation independent\n* fast\n* generates verbose, useful error messages including context of where\n   the error occurs in the input text.\n* can parse json data off a stream, incrementally\n* simple to use\n* tiny\n\n# motivation\n\nthe reason behind this work was to create better full text support in node. creating indexes out of large (or many) json files doesn't require a full understanding of the json file, but it does require something like `clarinet`.\n\n# installation\n\n## node.js\n\n1. install [npm]\n2. `npm install clarinet`\n3. `var clarinet = require('clarinet');`\n\n## browser\n\n1. minimize clarinet.js\n2. load it into your webpage\n\n# usage\n\n## basics\n\n``` js\nvar clarinet = require(\"clarinet\")\n  , parser = clarinet.parser()\n  ;\n\nparser.onerror = function (e) {\n  // an error happened. e is the error.\n};\nparser.onvalue = function (v) {\n  // got some value.  v is the value. can be string, double, bool, or null.\n};\nparser.onopenobject = function (key) {\n  // opened an object. key is the first key.\n};\nparser.onkey = function (key) {\n  // got a subsequent key in an object.\n};\nparser.oncloseobject = function () {\n  // closed an object.\n};\nparser.onopenarray = function () {\n  // opened an array.\n};\nparser.onclosearray = function () {\n  // closed an array.\n};\nparser.onend = function () {\n  // parser stream is done, and ready to have more stuff written to it.\n};\n\nparser.write('{\"foo\": \"bar\"}').close();\n```\n\n``` js\n// stream usage\n// takes the same options as the parser\nvar stream = require(\"clarinet\").createStream(options);\nstream.on(\"error\", function (e) {\n  // unhandled errors will throw, since this is a proper node\n  // event emitter.\n  console.error(\"error!\", e)\n  // clear the error\n  this._parser.error = null\n  this._parser.resume()\n})\nstream.on(\"openobject\", function (node) {\n  // same object as above\n})\n// pipe is supported, and it's readable/writable\n// same chunks coming in also go out.\nfs.createReadStream(\"file.json\")\n  .pipe(stream)\n  .pipe(fs.createReadStream(\"file-altered.json\"))\n```\n\n## arguments\n\npass the following arguments to the parser function.  all are optional.\n\n`opt` - object bag of settings regarding string formatting.  all default to `false`.\n\nsettings supported:\n\n* `trim` - boolean. whether or not to trim text and comment nodes.\n* `normalize` - boolean. if true, then turn any whitespace into a single\n  space.\n\n## methods\n\n`write` - write bytes onto the stream. you don't have to do this all at\nonce. you can keep writing as much as you want.\n\n`close` - close the stream. once closed, no more data may be written until\nit is done processing the buffer, which is signaled by the `end` event.\n\n`resume` - to gracefully handle errors, assign a listener to the `error`\nevent. then, when the error is taken care of, you can call `resume` to\ncontinue parsing. otherwise, the parser will not continue while in an error\nstate.\n\n## members\n\nat all times, the parser object will have the following members:\n\n`line`, `column`, `position` - indications of the position in the json\ndocument where the parser currently is looking.\n\n`closed` - boolean indicating whether or not the parser can be written to.\nif it's `true`, then wait for the `ready` event to write again.\n\n`opt` - any options passed into the constructor.\n\nand a bunch of other stuff that you probably shouldn't touch.\n\n## events\n\nall events emit with a single argument. to listen to an event, assign a\nfunction to `on<eventname>`. functions get executed in the this-context of\nthe parser object. the list of supported events are also in the exported\n`EVENTS` array.\n\nwhen using the stream interface, assign handlers using the `EventEmitter`\n`on` function in the normal fashion.\n\n`error` - indication that something bad happened. the error will be hanging\nout on `parser.error`, and must be deleted before parsing can continue. by\nlistening to this event, you can keep an eye on that kind of stuff. note:\nthis happens *much* more in strict mode. argument: instance of `Error`.\n\n`value` - a json value. argument: value, can be a bool, null, string on number\n\n`openobject` - object was opened. argument: key, a string with the first key of the object (if any)\n\n`key` - an object key: argument: key, a string with the current key. Not called for first key (use `openobject` for that).\n\n`closeobject` - indication that an object was closed\n\n`openarray` - indication that an array was opened\n\n`closearray` - indication that an array was closed\n\n`end` - indication that the closed stream has ended.\n\n`ready` - indication that the stream has reset, and is ready to be written\nto.\n\n## samples\n\nsome [samples] are available to help you get started. one that creates a list of top npm contributors, and another that gets a bunch of data from twitter and generates valid json.\n\n# roadmap\n\ncheck [issues]\n\n# contribute\n\neveryone is welcome to contribute. patches, bug-fixes, new features\n\n1. create an [issue][issues] so the community can comment on your idea\n2. fork `clarinet`\n3. create a new branch `git checkout -b my_branch`\n4. create tests for the changes you made\n5. make sure you pass both existing and newly inserted tests\n6. commit your changes\n7. push to your branch `git push origin my_branch`\n8. create an pull request\n\nhelpful tips:\n\ncheck `index.html`. there's two env vars you can set, `CRECORD` and `CDEBUG`. \n\n* `CRECORD` allows you to `record` the event sequence from a new json test so you don't have to write everything. \n* `CDEBUG` can be set to `info` or `debug`. `info` will `console.log` all emits, `debug` will `console.log` what happens to each char. \n\nin `test/clarinet.js` there's two lines you might want to change. `#8` where you define `seps`, if you are isolating a test you probably just want to run one sep, so change this array to `[undefined]`. `#718` which says `for (var key in docs) {` is where you can change the docs you want to run. e.g. to run `foobar` i would do something like `for (var key in {foobar:''}) {`.\n\n# meta\n\n* code: `git clone git://github.com/dscape/clarinet.git`\n* home: <http://github.com/dscape/clarinet>\n* bugs: <http://github.com/dscape/clarinet/issues>\n* build: [![build status](https://secure.travis-ci.org/dscape/clarinet.png)](http://travis-ci.org/dscape/clarinet)\n\n`(oO)--',-` in [caos]\n\n[npm]: http://npmjs.org\n[issues]: http://github.com/dscape/clarinet/issues\n[caos]: http://caos.di.uminho.pt/\n[saxjs]: http://github.com/isaacs/sax-js\n[yajl]: https://github.com/lloyd/yajl\n[samples]: https://github.com/dscape/clarinet/tree/master/samples\n[blog]: http://writings.nunojob.com/2011/12/clarinet-sax-based-evented-streaming-json-parser-in-javascript-for-the-browser-and-nodejs.html\n","publish_time":1641575461632,"_cnpm_publish_time":1641575461632,"dist-tags":{"latest":"0.12.6"}}