{"name":"bson","description":"A bson parser for node.js and the browser","keywords":["mongodb","bson","parser"],"version":"4.0.0-rc1","author":{"name":"Christian Amor Kvalheim","email":"christkv@gmail.com"},"license":"Apache-2.0","contributors":[],"repository":{"type":"git","url":"git+https://github.com/mongodb/js-bson.git"},"bugs":{"url":"https://github.com/mongodb/js-bson/issues"},"devDependencies":{"babel-core":"^6.26.0","babel-plugin-external-helpers":"^6.22.0","babel-preset-env":"^1.6.1","benchmark":"^2.1.4","chai":"^4.1.2","conventional-changelog-cli":"^1.3.5","dmd-clear":"^0.1.2","eslint":"^4.7.2","eslint-plugin-prettier":"^2.3.1","istanbul":"^0.4.5","jsdoc-to-markdown":"^4.0.1","karma":"^2.0.4","karma-chrome-launcher":"^2.2.0","karma-mocha":"^1.3.0","karma-mocha-reporter":"^2.2.5","karma-rollup-preprocessor":"^6.0.0","mocha":"^3.5.3","prettier":"~1.12.0","rollup":"^0.56.2","rollup-plugin-babel":"^3.0.3","rollup-plugin-commonjs":"^8.3.0","rollup-plugin-json":"^3.0.0","rollup-plugin-node-builtins":"^2.1.2","rollup-plugin-node-globals":"^1.2.1","rollup-plugin-node-resolve":"^3.0.3"},"config":{"native":false},"main":"lib/bson.js","module":"dist/bson.esm.js","browser":{"./index.js":"./dist/bson.browser.umd.js","./dist/bson.esm.js":"./dist/bson.browser.esm.js"},"engines":{"node":">=4.0.0"},"scripts":{"docs":"jsdoc2md --heading-depth 3 --template tools/README.hbs --plugin dmd-clear --files lib/bson.js > README.md","test":"npm run-script test-node && npm run-script test-browser","test-node":"mocha ./test/node","test-browser":"karma start","build":"rollup -c","lint":"eslint lib test","format":"prettier --print-width 100 --tab-width 2 --single-quote --write 'test/**/*.js' 'lib/**/*.js'","changelog":"conventional-changelog -p angular -i HISTORY.md -s","coverage":"istanbul cover _mocha -- --recursive --ui tdd test/node","prepublishOnly":"npm run build"},"dependencies":{"buffer":"^5.1.0","long":"^4.0.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 [rollup](https://rollupjs.org/) and the current version is pre-compiled in the `dist` 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=\"./dist/bson.js\"></script>\n\n<script>\n  function start() {\n    // Get the Long type\n    const Long = BSON.Long;\n\n    // Serialize document\n    const doc = { long: Long.fromNumber(100) }\n\n    // Serialize a document\n    const data = BSON.serialize(doc)\n    // De serialize it again\n    const doc_2 = BSON.deserialize(data)\n  }\n</script>\n```\n\nA simple example of how to use BSON in `Node.js`:\n\n```js\nconst BSON = require('bson');\nconst Long = BSON.Long;\n\nconst doc = { long: Long.fromNumber(100) };\n\n// Serialize a document\nconst data = BSON.serialize(doc);\nconsole.log('data:', data);\n\n// Deserialize the resulting Buffer\nconst doc_2 = BSON.deserialize(data);\nconsole.log('doc_2:', doc_2);\n```\n\n## Installation\n\n`npm install bson`\n\n## Documentation\n\n### Functions\n\n<dl>\n<dt><a href=\"#setInternalBufferSize\">setInternalBufferSize(size)</a></dt>\n<dd><p>Sets the size of the internal serialization buffer.</p>\n</dd>\n<dt><a href=\"#serialize\">serialize(object)</a> ⇒ <code>Buffer</code></dt>\n<dd><p>Serialize a Javascript object.</p>\n</dd>\n<dt><a href=\"#serializeWithBufferAndIndex\">serializeWithBufferAndIndex(object, buffer)</a> ⇒ <code>Number</code></dt>\n<dd><p>Serialize a Javascript object using a predefined Buffer and index into the buffer, useful when pre-allocating the space for serialization.</p>\n</dd>\n<dt><a href=\"#deserialize\">deserialize(buffer)</a> ⇒ <code>Object</code></dt>\n<dd><p>Deserialize data as BSON.</p>\n</dd>\n<dt><a href=\"#calculateObjectSize\">calculateObjectSize(object)</a> ⇒ <code>Number</code></dt>\n<dd><p>Calculate the bson size for a passed in Javascript object.</p>\n</dd>\n<dt><a href=\"#deserializeStream\">deserializeStream(data, startIndex, numberOfDocuments, documents, docStartIndex, [options])</a> ⇒ <code>Number</code></dt>\n<dd><p>Deserialize stream data as BSON documents.</p>\n</dd>\n</dl>\n\n<a name=\"setInternalBufferSize\"></a>\n\n### setInternalBufferSize(size)\n\n| Param | Type | Description |\n| --- | --- | --- |\n| size | <code>number</code> | The desired size for the internal serialization buffer |\n\nSets the size of the internal serialization buffer.\n\n<a name=\"serialize\"></a>\n\n### serialize(object)\n\n| Param | Type | Default | Description |\n| --- | --- | --- | --- |\n| object | <code>Object</code> |  | the Javascript object to serialize. |\n| [options.checkKeys] | <code>Boolean</code> |  | the serializer will check if keys are valid. |\n| [options.serializeFunctions] | <code>Boolean</code> | <code>false</code> | serialize the javascript functions **(default:false)**. |\n| [options.ignoreUndefined] | <code>Boolean</code> | <code>true</code> | ignore undefined fields **(default:true)**. |\n\nSerialize a Javascript object.\n\n**Returns**: <code>Buffer</code> - returns the Buffer object containing the serialized object.  \n<a name=\"serializeWithBufferAndIndex\"></a>\n\n### serializeWithBufferAndIndex(object, buffer)\n\n| Param | Type | Default | Description |\n| --- | --- | --- | --- |\n| object | <code>Object</code> |  | the Javascript object to serialize. |\n| buffer | <code>Buffer</code> |  | the Buffer you pre-allocated to store the serialized BSON object. |\n| [options.checkKeys] | <code>Boolean</code> |  | the serializer will check if keys are valid. |\n| [options.serializeFunctions] | <code>Boolean</code> | <code>false</code> | serialize the javascript functions **(default:false)**. |\n| [options.ignoreUndefined] | <code>Boolean</code> | <code>true</code> | ignore undefined fields **(default:true)**. |\n| [options.index] | <code>Number</code> |  | the index in the buffer where we wish to start serializing into. |\n\nSerialize a Javascript object using a predefined Buffer and index into the buffer, useful when pre-allocating the space for serialization.\n\n**Returns**: <code>Number</code> - returns the index pointing to the last written byte in the buffer.  \n<a name=\"deserialize\"></a>\n\n### deserialize(buffer)\n\n| Param | Type | Default | Description |\n| --- | --- | --- | --- |\n| buffer | <code>Buffer</code> |  | the buffer containing the serialized set of BSON documents. |\n| [options.evalFunctions] | <code>Object</code> | <code>false</code> | evaluate functions in the BSON document scoped to the object deserialized. |\n| [options.cacheFunctions] | <code>Object</code> | <code>false</code> | cache evaluated functions for reuse. |\n| [options.cacheFunctionsCrc32] | <code>Object</code> | <code>false</code> | use a crc32 code for caching, otherwise use the string of the function. |\n| [options.promoteLongs] | <code>Object</code> | <code>true</code> | when deserializing a Long will fit it into a Number if it's smaller than 53 bits |\n| [options.promoteBuffers] | <code>Object</code> | <code>false</code> | when deserializing a Binary will return it as a node.js Buffer instance. |\n| [options.promoteValues] | <code>Object</code> | <code>false</code> | when deserializing will promote BSON values to their Node.js closest equivalent types. |\n| [options.fieldsAsRaw] | <code>Object</code> | <code></code> | allow to specify if there what fields we wish to return as unserialized raw buffer. |\n| [options.bsonRegExp] | <code>Object</code> | <code>false</code> | return BSON regular expressions as BSONRegExp instances. |\n| [options.allowObjectSmallerThanBufferSize] | <code>boolean</code> | <code>false</code> | allows the buffer to be larger than the parsed BSON object |\n\nDeserialize data as BSON.\n\n**Returns**: <code>Object</code> - returns the deserialized Javascript Object.  \n<a name=\"calculateObjectSize\"></a>\n\n### calculateObjectSize(object)\n\n| Param | Type | Default | Description |\n| --- | --- | --- | --- |\n| object | <code>Object</code> |  | the Javascript object to calculate the BSON byte size for. |\n| [options.serializeFunctions] | <code>Boolean</code> | <code>false</code> | serialize the javascript functions **(default:false)**. |\n| [options.ignoreUndefined] | <code>Boolean</code> | <code>true</code> | ignore undefined fields **(default:true)**. |\n\nCalculate the bson size for a passed in Javascript object.\n\n**Returns**: <code>Number</code> - returns the number of bytes the BSON object will take up.  \n<a name=\"deserializeStream\"></a>\n\n### deserializeStream(data, startIndex, numberOfDocuments, documents, docStartIndex, [options])\n\n| Param | Type | Default | Description |\n| --- | --- | --- | --- |\n| data | <code>Buffer</code> |  | the buffer containing the serialized set of BSON documents. |\n| startIndex | <code>Number</code> |  | the start index in the data Buffer where the deserialization is to start. |\n| numberOfDocuments | <code>Number</code> |  | number of documents to deserialize. |\n| documents | <code>Array</code> |  | an array where to store the deserialized documents. |\n| docStartIndex | <code>Number</code> |  | the index in the documents array from where to start inserting documents. |\n| [options] | <code>Object</code> |  | additional options used for the deserialization. |\n| [options.evalFunctions] | <code>Object</code> | <code>false</code> | evaluate functions in the BSON document scoped to the object deserialized. |\n| [options.cacheFunctions] | <code>Object</code> | <code>false</code> | cache evaluated functions for reuse. |\n| [options.cacheFunctionsCrc32] | <code>Object</code> | <code>false</code> | use a crc32 code for caching, otherwise use the string of the function. |\n| [options.promoteLongs] | <code>Object</code> | <code>true</code> | when deserializing a Long will fit it into a Number if it's smaller than 53 bits |\n| [options.promoteBuffers] | <code>Object</code> | <code>false</code> | when deserializing a Binary will return it as a node.js Buffer instance. |\n| [options.promoteValues] | <code>Object</code> | <code>false</code> | when deserializing will promote BSON values to their Node.js closest equivalent types. |\n| [options.fieldsAsRaw] | <code>Object</code> | <code></code> | allow to specify if there what fields we wish to return as unserialized raw buffer. |\n| [options.bsonRegExp] | <code>Object</code> | <code>false</code> | return BSON regular expressions as BSONRegExp instances. |\n\nDeserialize stream data as BSON documents.\n\n**Returns**: <code>Number</code> - 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\nconst BSON = require('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":"23811c7ac258458f9d977f621afe073f5c9d5ffb","homepage":"https://github.com/mongodb/js-bson#readme","_id":"bson@4.0.0-rc1","_npmVersion":"6.4.1","_nodeVersion":"8.12.0","_npmUser":{"name":"mbroadst","email":"mbroadst@gmail.com"},"dist":{"integrity":"sha512-8xyZGoD4ejfTygNLFAts3ZvxDutgUFvodaq4mKOpKz/0ipwt5uycdupEHD1RY0HTAmzGudOTYdMkfq1OCtGxKA==","shasum":"9b35d5bb2f09444d9728c0ddb150a24c69d3cb5f","tarball":"http://registry-npm.ywwl.com/bson/download/bson-4.0.0-rc1.tgz","fileCount":32,"unpackedSize":829162,"npm-signature":"-----BEGIN PGP SIGNATURE-----\r\nVersion: OpenPGP.js v3.0.4\r\nComment: https://openpgpjs.org\r\n\r\nwsFcBAEBCAAQBQJbrTCdCRA9TVsSAnZWagAApvkQAI6BP8yF7MqBP5m7+6MT\n4EC5MKVINnyDxb9EpIrzbQM+ZBrRvR66jfQyGvyxH6qzhxHqhS4kDj7VbW/c\nLoSMkPo7iVUYcXxNGlOhLwuvnVrMFQGzhJoADmHQ9zccOdDHzVMvMBbAtShT\nbC6e8P6hF+yFhXNDgDp17raXwSezs7+lBnhmECDWl28Dtf7O7q+J0eObMrJI\niYQfz7N8nj++85qpCjsn2AL2QoxkmWCTgluWBHOK191q+B+KXLB/t45kcCTT\nT6qWFRtnwtbM6rT3BIVprS/aGhlmTIef5Myy4fUbR4zSLG8JB/FNJNR2/JqV\n0NCnBPWxaZ56HVQiRaWX7w7StFnPKKuvz1uvUZpoQo+ebG9sjNKowPTmD4sp\nmx7QNOTyrJpr7gaW6uWvS3gk7LUrclcur2nunsdG3sQSUYluiYlThHNhLEVX\nvkGvNXkH26iCr66Zi9Nf7W3PvVswOrTy4bvjIIBrTvMszecOiTRYMTGF60Sp\n8BGfGU6kLKtlP67ZbrufdWEEMCflfTF8pBJeWhlSw2Kk0nzGzomCw7yytJMu\nKe4mE3QzXDWPWCFUZmw0KaND54x+8oW3p6LQsbgcso0+VHnZLWhpAZ9DOQwH\ntbbiQgz+AdTW6MBJw5G4muHzMmd1mqpALPqRe++q2EKDUZva/GGcb58Id5SJ\nSYf+\r\n=szoO\r\n-----END PGP SIGNATURE-----\r\n","signatures":[{"keyid":"SHA256:jl3bwswu80PjjokCgh0o2w5c2U4LhQAE57gj9cz1kzA","sig":"MEYCIQDwqjkrmRDq+12iHQ/gEp0BDHxxu3uShFx/X0DSQbR4YAIhAKZX/hkWSTKop5Yi9PSSzSSFC8VlX26qlrLZz4lBEEU+"}],"size":169839,"noattachment":false,"key":"/bson/-/bson-4.0.0-rc1.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"}],"directories":{},"_npmOperationalInternal":{"host":"s3://npm-registry-packages","tmp":"tmp/bson_4.0.0-rc1_1538076828354_0.878685574711763"},"_hasShrinkwrap":false,"publish_time":1538076828566,"_cnpm_publish_time":1538076828566,"dist-tags":{"5x":"5.5.1","alpha":"7.0.0-alpha.2","latest":"7.3.4","legacy":"6.9.1"}}