{"name":"bson","description":"A bson parser for node.js and the browser","keywords":["mongodb","bson","parser"],"version":"1.1.3","author":{"name":"Christian Amor Kvalheim","email":"christkv@gmail.com"},"contributors":[],"repository":{"type":"git","url":"git+https://github.com/mongodb/js-bson.git"},"bugs":{"url":"https://github.com/mongodb/js-bson/issues"},"devDependencies":{"benchmark":"1.0.0","colors":"1.1.0","nodeunit":"0.9.0","babel-core":"^6.14.0","babel-loader":"^6.2.5","babel-polyfill":"^6.13.0","babel-preset-es2015":"^6.14.0","babel-preset-stage-0":"^6.5.0","babel-register":"^6.14.0","conventional-changelog-cli":"^1.3.5","webpack":"^1.13.2","webpack-polyfills-plugin":"0.0.9"},"config":{"native":false},"main":"./index","directories":{"lib":"./lib/bson"},"engines":{"node":">=0.6.19"},"scripts":{"test":"nodeunit ./test/node","build":"webpack --config ./webpack.dist.config.js","changelog":"conventional-changelog -p angular -i HISTORY.md -s","lint":"eslint lib test","format":"prettier --print-width 100 --tab-width 2 --single-quote --write 'test/**/*.js' 'lib/**/*.js'"},"browser":"lib/bson/bson.js","license":"Apache-2.0","readme":"# BSON parser\n\nBSON is short for Bin­ary JSON and is the bin­ary-en­coded seri­al­iz­a­tion of JSON-like doc­u­ments. You can learn more about it in [the specification](http://bsonspec.org).\n\nThis browser version of the BSON parser is compiled using [webpack](https://webpack.js.org/) and the current version is pre-compiled in the `browser_build` directory.\n\nThis is the default BSON parser, however, there is a C++ Node.js addon version as well that does not support the browser. It can be found at [mongod-js/bson-ext](https://github.com/mongodb-js/bson-ext).\n\n## Usage\n\nTo build a new version perform the following operations:\n\n```\nnpm install\nnpm run build\n```\n\nA simple example of how to use BSON in the browser:\n\n```html\n<script src=\"./browser_build/bson.js\"></script>\n\n<script>\n  function start() {\n    // Get the Long type\n    var Long = BSON.Long;\n    // Create a bson parser instance\n    var bson = new BSON();\n\n    // Serialize document\n    var doc = { long: Long.fromNumber(100) }\n\n    // Serialize a document\n    var data = bson.serialize(doc)\n    // De serialize it again\n    var doc_2 = bson.deserialize(data)\n  }\n</script>\n```\n\nA simple example of how to use BSON in `Node.js`:\n\n```js\n// Get BSON parser class\nvar BSON = require('bson')\n// Get the Long type\nvar Long = BSON.Long;\n// Create a bson parser instance\nvar bson = new BSON();\n\n// Serialize document\nvar doc = { long: Long.fromNumber(100) }\n\n// Serialize a document\nvar data = bson.serialize(doc)\nconsole.log('data:', data)\n\n// Deserialize the resulting Buffer\nvar doc_2 = bson.deserialize(data)\nconsole.log('doc_2:', doc_2)\n```\n\n## Installation\n\n`npm install bson`\n\n## API\n\n### BSON types\n\nFor all BSON types documentation, please refer to the following sources:\n  * [MongoDB BSON Type Reference](https://docs.mongodb.com/manual/reference/bson-types/)\n  * [BSON Spec](https://bsonspec.org/)\n\n### BSON serialization and deserialiation\n\n**`new BSON()`** - Creates a new BSON serializer/deserializer you can use to serialize and deserialize BSON.\n\n#### BSON.serialize\n\nThe BSON `serialize` method takes a JavaScript object and an optional options object and returns a Node.js Buffer.\n\n  * `BSON.serialize(object, options)`\n    * @param {Object} object the JavaScript object to serialize.\n    * @param {Boolean} [options.checkKeys=false] the serializer will check if keys are valid.\n    * @param {Boolean} [options.serializeFunctions=false] serialize the JavaScript functions.\n    * @param {Boolean} [options.ignoreUndefined=true]\n    * @return {Buffer} returns a Buffer instance.\n\n#### BSON.serializeWithBufferAndIndex\n\nThe BSON `serializeWithBufferAndIndex` method takes an object, a target buffer instance and an optional options object and returns the end serialization index in the final buffer.\n\n  * `BSON.serializeWithBufferAndIndex(object, buffer, options)`\n    * @param {Object} object the JavaScript object to serialize.\n    * @param {Buffer} buffer the Buffer you pre-allocated to store the serialized BSON object.\n    * @param {Boolean} [options.checkKeys=false] the serializer will check if keys are valid.\n    * @param {Boolean} [options.serializeFunctions=false] serialize the JavaScript functions.\n    * @param {Boolean} [options.ignoreUndefined=true] ignore undefined fields.\n    * @param {Number} [options.index=0] the index in the buffer where we wish to start serializing into.\n    * @return {Number} returns the index pointing to the last written byte in the buffer.\n\n#### BSON.calculateObjectSize\n\nThe BSON `calculateObjectSize` method takes a JavaScript object and an optional options object and returns the size of the BSON object.\n\n  * `BSON.calculateObjectSize(object, options)`\n    * @param {Object} object the JavaScript object to serialize.\n    * @param {Boolean} [options.serializeFunctions=false] serialize the JavaScript functions.\n    * @param {Boolean} [options.ignoreUndefined=true]\n    * @return {Buffer} returns a Buffer instance.\n\n#### BSON.deserialize\n\nThe BSON `deserialize` method takes a Node.js Buffer and an optional options object and returns a deserialized JavaScript object.\n\n  * `BSON.deserialize(buffer, options)`\n    * @param {Object} [options.evalFunctions=false] evaluate functions in the BSON document scoped to the object deserialized.\n    * @param {Object} [options.cacheFunctions=false] cache evaluated functions for reuse.\n    * @param {Object} [options.cacheFunctionsCrc32=false] use a crc32 code for caching, otherwise use the string of the function.\n    * @param {Object} [options.promoteLongs=true] when deserializing a Long will fit it into a Number if it's smaller than 53 bits\n    * @param {Object} [options.promoteBuffers=false] when deserializing a Binary will return it as a Node.js Buffer instance.\n    * @param {Object} [options.promoteValues=false] when deserializing will promote BSON values to their Node.js closest equivalent types.\n    * @param {Object} [options.fieldsAsRaw=null] allow to specify if there what fields we wish to return as unserialized raw buffer.\n    * @param {Object} [options.bsonRegExp=false] return BSON regular expressions as BSONRegExp instances.\n    * @return {Object} returns the deserialized Javascript Object.\n\n#### BSON.deserializeStream\n\nThe BSON `deserializeStream` method takes a Node.js Buffer, `startIndex` and allow more control over deserialization of a Buffer containing concatenated BSON documents.\n\n  * `BSON.deserializeStream(buffer, startIndex, numberOfDocuments, documents, docStartIndex, options)`\n    * @param {Buffer} buffer the buffer containing the serialized set of BSON documents.\n    * @param {Number} startIndex the start index in the data Buffer where the deserialization is to start.\n    * @param {Number} numberOfDocuments number of documents to deserialize.\n    * @param {Array} documents an array where to store the deserialized documents.\n    * @param {Number} docStartIndex the index in the documents array from where to start inserting documents.\n    * @param {Object} [options.evalFunctions=false] evaluate functions in the BSON document scoped to the object deserialized.\n    * @param {Object} [options.cacheFunctions=false] cache evaluated functions for reuse.\n    * @param {Object} [options.cacheFunctionsCrc32=false] use a crc32 code for caching, otherwise use the string of the function.\n    * @param {Object} [options.promoteLongs=true] when deserializing a Long will fit it into a Number if it's smaller than 53 bits\n    * @param {Object} [options.promoteBuffers=false] when deserializing a Binary will return it as a Node.js Buffer instance.\n    * @param {Object} [options.promoteValues=false] when deserializing will promote BSON values to their Node.js closest equivalent types.\n    * @param {Object} [options.fieldsAsRaw=null] allow to specify if there what fields we wish to return as unserialized raw buffer.\n    * @param {Object} [options.bsonRegExp=false] return BSON regular expressions as BSONRegExp instances.\n    * @return {Number} returns the next index in the buffer after deserialization **x** numbers of documents.\n\n## FAQ\n\n#### Why does `undefined` get converted to `null`?\n\nThe `undefined` BSON type has been [deprecated for many years](http://bsonspec.org/spec.html), so this library has dropped support for it. Use the `ignoreUndefined` option (for example, from the [driver](http://mongodb.github.io/node-mongodb-native/2.2/api/MongoClient.html#connect) ) to instead remove `undefined` keys.\n\n#### How do I add custom serialization logic?\n\nThis library looks for `toBSON()` functions on every path, and calls the `toBSON()` function to get the value to serialize.\n\n```javascript\nvar bson = new BSON();\n\nclass CustomSerialize {\n  toBSON() {\n    return 42;\n  }\n}\n\nconst obj = { answer: new CustomSerialize() };\n// \"{ answer: 42 }\"\nconsole.log(bson.deserialize(bson.serialize(obj)));\n```\n","readmeFilename":"README.md","gitHead":"e4de7b565a4278b63d4fc04b1955644827c70cbb","homepage":"https://github.com/mongodb/js-bson#readme","_id":"bson@1.1.3","_nodeVersion":"10.16.3","_npmVersion":"6.9.0","dist":{"integrity":"sha512-TdiJxMVnodVS7r0BdL42y/pqC9cL2iKynVwA0Ho3qbsQYr428veL3l7BQyuqiw+Q5SqqoT0m4srSY/BlZ9AxXg==","shasum":"aa82cb91f9a453aaa060d6209d0675114a8154d3","tarball":"http://registry-npm.ywwl.com/bson/download/bson-1.1.3.tgz","fileCount":28,"unpackedSize":771926,"npm-signature":"-----BEGIN PGP SIGNATURE-----\r\nVersion: OpenPGP.js v3.0.4\r\nComment: https://openpgpjs.org\r\n\r\nwsFcBAEBCAAQBQJdxtT+CRA9TVsSAnZWagAANu8P/Rmn8nM9Ll1nkNxQd2b1\nqroQCtJCr8QYtqXfb5KEaEbH97xz+lWPhM7om8fMSw3aE+v5wpKSoU0ApNvu\nOZdzX2R0cVXbA1rxcJzB2aT+4jMgB06Er+cGpAFeG48vBtChYW+jVusF1d75\n2CosnTzer/UYgY0Cyq1mHVxJBTwW0GIpQmxBtptc1qoZfj3YZWG2H8glhRA6\nQAbiIF/tJyNsQ7VFx8wfZOk1d5E1Z2nwvG6jUgcOWytgERDUj+YbdrtJQnzM\nnqKZQTV6S27yQaRIcA/oCjIACIKfo+m8Y4Bpajf6r7o+czYnDseS/rhegsZv\nMwI9wquOhgkltvNTf/AqcF/9g51U4zCMB6oVO3GEoSrFY9mWoozdOKG8Iau3\nOMuZODX0k22+wzwEzCzRpR53l8y6YLAgJAqjax+ZfOoRU+mNwfEGNk71DbDw\nXEuQb6ew3ZkCk/+jKzTUzikbtpawaET4XlE3omTwRK+P4Y94/Et93rtb/U8g\nOP3jkBT3pTgoQkIys80cVjkTJfikMdxpNGSFVXn/D6YC7WcYgf/0zm6onLQI\nud+Ek6LTqI6YK1pyF1Kv6sl0WMAyM+u88U6tH1jQhYTUBb1tIhVTj9n9EqUU\n8ldHC1gawaRroutPWAuwhjsCB++f/p4YB9RKVzlvwUT8Ol/B4eSqrivdd6Yz\nHDUa\r\n=EOia\r\n-----END PGP SIGNATURE-----\r\n","signatures":[{"keyid":"SHA256:jl3bwswu80PjjokCgh0o2w5c2U4LhQAE57gj9cz1kzA","sig":"MEMCH3z0txPHlgVKYlqCrp/WrgS9G3JLuSAgqB1p1irpUUkCIC1CNS5SDDALA2/btpvT8gSNUZkLR0ml5Ad0fstALBLN"}],"size":162159,"noattachment":false,"key":"/bson/-/bson-1.1.3.tgz"},"maintainers":[{"email":"dan.aprahamian@gmail.com","name":"daprahamian"},{"email":"mbroadst@gmail.com","name":"mbroadst"}],"_npmUser":{"name":"daprahamian","email":"dan.aprahamian@gmail.com"},"_npmOperationalInternal":{"host":"s3://npm-registry-packages","tmp":"tmp/bson_1.1.3_1573311741813_0.5816017561788467"},"_hasShrinkwrap":false,"deprecated":"Fixed a critical issue with BSON serialization documented in CVE-2019-2391, see https://bit.ly/2KcpXdo for more details","publish_time":1573311742575,"_cnpm_publish_time":1573311742575,"dist-tags":{"5x":"5.5.1","alpha":"7.0.0-alpha.2","latest":"7.3.4","legacy":"6.9.1"}}