{"name":"bson","description":"A bson parser for node.js and the browser","keywords":["mongodb","bson","parser"],"version":"1.1.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","standard-version":"^7.1.0","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'","release":"standard-version -i HISTORY.md"},"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":"290dd6a313e19c521a99a1b4d5e4e87483b9245f","homepage":"https://github.com/mongodb/js-bson#readme","_id":"bson@1.1.5","_nodeVersion":"12.18.1","_npmVersion":"6.14.5","dist":{"integrity":"sha512-kDuEzldR21lHciPQAIulLs1LZlCXdLziXI6Mb/TDkwXhb//UORJNPXgcRs2CuO4H0DcMkpfT3/ySsP3unoZjBg==","shasum":"2aaae98fcdf6750c0848b0cba1ddec3c73060a34","tarball":"http://registry-npm.ywwl.com/bson/download/bson-1.1.5.tgz","fileCount":28,"unpackedSize":773490,"npm-signature":"-----BEGIN PGP SIGNATURE-----\r\nVersion: OpenPGP.js v3.0.4\r\nComment: https://openpgpjs.org\r\n\r\nwsFcBAEBCAAQBQJfMVxVCRA9TVsSAnZWagAAJN0P/3ltvgwrLqRK1Imo6Ubm\nPuRFgaUSgFMs6pDhsUNyR68XautPxKov5yNADeI0JDeh+GBYUL2/RA13+jT9\nTbu7H0Kp4PFXh9gIEoaiJnr9EXfX5tk9nPyEXdoQawbngNzGzDRAKK25ElEV\nJHaVwnrFNSN2mbFQ8epv6Vi89L9t3/amyd7vH4Omz5AV7tOoLdl25gonyVD6\nmdgyzGzETuyauirfwsVGAdyUtYNt8a6Qcm9/UH2IDiU33jyasf5I2nbrThH2\nmWtWVcu/F4gaeWnMlH3mKbwi1SNPUa17O+aOPspZ+vXhwqLtwPRDgwUGHl5v\nljTwRDGjBE76CtmenNN9XFtVM62Dvq1kOl2lgOIaAWH36gj/dGp/bfsXw9QJ\nntOkADLbURERFHghui/EAUaddWZWFiNHIx7m7ngByhfcNi9z6FlGGscEU2EX\nJyI7NMh5M2wgxxbHckBf0SO1R/Pjcl4Znfc655Fl/dhaM3U7m+xj69MxPFYg\n9A2tF9LTp6zER6aTIvBU5WoD1nnmvCWqS+lEt/p8T2A9kqUFuzOikOha/hWE\nlEPgo172a8UaN5Nin+lq+BJzvFPZKgCVVoTs8z9f0kXhPGvFuk+pNJvOiCcy\nSUa4r2PSAHVxr5cHULrgsqtlBfJlRLGk1K2MCTIsiWN/+nstZFTJj4J9egiA\n3zA1\r\n=WE/+\r\n-----END PGP SIGNATURE-----\r\n","signatures":[{"keyid":"SHA256:jl3bwswu80PjjokCgh0o2w5c2U4LhQAE57gj9cz1kzA","sig":"MEUCIQCvCYOuCMv7GeDGhJy0P8xlpDmOu14gsrb0bMyDUP4lKAIgTKlG9Gp4hwlBresKUb4kQrdJSDGcr5Gc8FUSRTkkyqo="}],"size":161973,"noattachment":false,"key":"/bson/-/bson-1.1.5.tgz"},"maintainers":[{"email":"dan.aprahamian@gmail.com","name":"daprahamian"},{"email":"mbroadst@gmail.com","name":"mbroadst"}],"_npmUser":{"name":"mbroadst","email":"mbroadst@gmail.com"},"_npmOperationalInternal":{"host":"s3://npm-registry-packages","tmp":"tmp/bson_1.1.5_1597070421301_0.745925129432836"},"_hasShrinkwrap":false,"publish_time":1597070421467,"_cnpm_publish_time":1597070421467,"dist-tags":{"5x":"5.5.1","alpha":"7.0.0-alpha.2","latest":"7.3.4","legacy":"6.9.1"}}