{"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.0.5","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 documentation for the [MongoDB Node.js driver](https://github.com/mongodb/node-mongodb-native).\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 {Number} returns the next index in the buffer after deserialization **x** numbers of documents.\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 {Object} returns the deserialized JavaScript Object.\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","readmeFilename":"README.md","gitHead":"0ea96bd7177839f652393deea69f992136c86f67","homepage":"https://github.com/mongodb/js-bson#readme","_id":"bson@1.0.5","_npmVersion":"5.6.0","_nodeVersion":"8.9.4","_npmUser":{"name":"mbroadst","email":"mbroadst@gmail.com"},"dist":{"integrity":"sha512-D4SCtud6mlEb48kXdTHU31DRU0bsgOJ+4St1Dcx30uYNnf/aGc+hC9gHB/z0Eth8HYYs/hr0SFdyZViht19SwA==","shasum":"34563b73ff1fde9387c1b9fb5afd845ecc4ba623","tarball":"http://registry-npm.ywwl.com/bson/download/bson-1.0.5.tgz","fileCount":27,"unpackedSize":777918,"signatures":[{"keyid":"SHA256:jl3bwswu80PjjokCgh0o2w5c2U4LhQAE57gj9cz1kzA","sig":"MEQCIHDYTPEbS2FL6DpcH8RW60j9zPkOyJc1jnFurQuIZNfDAiAbu63gozZsjteyq5pFxfgIgYerk3CFyuhpc4iqqk9Vog=="}],"size":157331,"noattachment":false,"key":"/bson/-/bson-1.0.5.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.0.5_1519676598907_0.8047262649671723"},"_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":1519676599015,"_cnpm_publish_time":1519676599015,"dist-tags":{"5x":"5.5.1","alpha":"7.0.0-alpha.2","latest":"7.3.4","legacy":"6.9.1"}}