{"name":"bson","description":"A bson parser for node.js and the browser","keywords":["mongodb","bson","parser"],"files":["lib","index.js","browser_build","bower.json"],"version":"1.1.0","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":"39215f038b6787d015bdd1525e4b9db060603350","homepage":"https://github.com/mongodb/js-bson#readme","_id":"bson@1.1.0","_npmVersion":"5.6.0","_nodeVersion":"8.11.3","_npmUser":{"name":"mbroadst","email":"mbroadst@gmail.com"},"dist":{"integrity":"sha512-9Aeai9TacfNtWXOYarkFJRW2CWo+dRon+fuLZYJmvLV3+MiUp0bEI6IAZfXEIg7/Pl/7IWlLaDnhzTsD81etQA==","shasum":"bee57d1fb6a87713471af4e32bcae36de814b5b0","tarball":"http://registry-npm.ywwl.com/bson/download/bson-1.1.0.tgz","fileCount":28,"unpackedSize":755155,"npm-signature":"-----BEGIN PGP SIGNATURE-----\r\nVersion: OpenPGP.js v3.0.4\r\nComment: https://openpgpjs.org\r\n\r\nwsFcBAEBCAAQBQJbcaTKCRA9TVsSAnZWagAAVVUQAIE4L99uDdW0YvzxkYLy\nkRadaW4t9wjT44xQe0y+lYePZE9DVXKlwdq4wJUHLtL2zeZk8e/3IfQp4tZK\ng0rZ12VJFOvZ7JvIcyQC2npJTaPzvwtJmihNWp2RM5rzBQHgLNRNe8UpqIC3\nA5UTPgoAMIN/OCDOrix9A3pdp1V51M8C5zrs8xsS2kK+iwxYe/zwJIi9X9rY\nZGg/fpD+XeBFvZuO3Tcz9HuB2Vo+BV2wvF4/FbDeYBJ9SlJ0ojFHbtP/av2k\nZ+RRJPukl6ODenzwMnIKMX4wSqV2bobqwE8iQpKAXGjGnYw23ZaZ81joFS7m\ngSsWdmTpAtUKbri9B6+l+qfjgJ+Jygs4Xh4lTzle+zOPeoDBmigJwWm4UV7I\nmlsMEifCITkEyambPgnT04lRIpWps5vmcUuJiRZml8rd3ik2zq7tIUQ0hs1c\nJguDACTigsoTidmeF3QPrzJ6mwKSE54OXlmmANIZ2WQ7p9D7obAO/U+qOAaK\nGdRs904u+YwBMHd7R8tcgKj93y/3wXRso1gI9dnzZnM0nChLYo+H3xG0Ham8\n69eBwDg+5PQ5QEXdecoWo2N0sw4LLFVAUcU5YSxLV7drGDRDULYWRFtuMzMW\n5J7FoazJwuEnOh93VHLQEXb7YAde3BakvZHMoKvLfLc/AaSn8KammzjxfxPb\naI7T\r\n=6+1t\r\n-----END PGP SIGNATURE-----\r\n","signatures":[{"keyid":"SHA256:jl3bwswu80PjjokCgh0o2w5c2U4LhQAE57gj9cz1kzA","sig":"MEUCIQDOrwee3WfZmAJFldbUOX8aYjOmvLnsOb7w1fBlpXutUgIgPW4bsHsgwMy25S9dceIuiCJ6pNhBbecyOn544WeZ4u0="}],"size":158112,"noattachment":false,"key":"/bson/-/bson-1.1.0.tgz"},"maintainers":[{"name":"christkv","email":"christkv@gmail.com"},{"name":"daprahamian","email":"dan.aprahamian@gmail.com"},{"name":"mbroadst","email":"mbroadst@gmail.com"},{"name":"octave","email":"chinsay@gmail.com"}],"_npmOperationalInternal":{"host":"s3://npm-registry-packages","tmp":"tmp/bson_1.1.0_1534174410289_0.38470476348971694"},"_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":1534174410409,"_cnpm_publish_time":1534174410409,"dist-tags":{"5x":"5.5.1","alpha":"7.0.0-alpha.2","latest":"7.3.4","legacy":"6.9.1"}}