{"name":"bson","description":"A bson parser for node.js and the browser","keywords":["mongodb","bson","parser"],"version":"4.0.0-rc6","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":{"./lib/bson.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 lib/extended_json.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### Objects\n\n<dl>\n<dt><a href=\"#EJSON\">EJSON</a> : <code>object</code></dt>\n<dd></dd>\n</dl>\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=\"EJSON\"></a>\n\n### EJSON\n\n* [EJSON](#EJSON)\n\n    * [.parse(text, [options])](#EJSON.parse)\n\n    * [.stringify(value, [replacer], [space], [options])](#EJSON.stringify)\n\n    * [.serialize(bson, [options])](#EJSON.serialize)\n\n    * [.deserialize(ejson, [options])](#EJSON.deserialize)\n\n\n<a name=\"EJSON.parse\"></a>\n\n#### *EJSON*.parse(text, [options])\n\n| Param | Type | Default | Description |\n| --- | --- | --- | --- |\n| text | <code>string</code> |  |  |\n| [options] | <code>object</code> |  | Optional settings |\n| [options.relaxed] | <code>boolean</code> | <code>true</code> | Attempt to return native JS types where possible, rather than BSON types (if true) |\n\nParse an Extended JSON string, constructing the JavaScript value or object described by that\nstring.\n\n**Example**  \n```js\nconst { EJSON } = require('bson');\nconst text = '{ \"int32\": { \"$numberInt\": \"10\" } }';\n\n// prints { int32: { [String: '10'] _bsontype: 'Int32', value: '10' } }\nconsole.log(EJSON.parse(text, { relaxed: false }));\n\n// prints { int32: 10 }\nconsole.log(EJSON.parse(text));\n```\n<a name=\"EJSON.stringify\"></a>\n\n#### *EJSON*.stringify(value, [replacer], [space], [options])\n\n| Param | Type | Default | Description |\n| --- | --- | --- | --- |\n| value | <code>object</code> |  | The value to convert to extended JSON |\n| [replacer] | <code>function</code> \\| <code>array</code> |  | A function that alters the behavior of the stringification process, or an array of String and Number objects that serve as a whitelist for selecting/filtering the properties of the value object to be included in the JSON string. If this value is null or not provided, all properties of the object are included in the resulting JSON string |\n| [space] | <code>string</code> \\| <code>number</code> |  | A String or Number object that's used to insert white space into the output JSON string for readability purposes. |\n| [options] | <code>object</code> |  | Optional settings |\n| [options.relaxed] | <code>boolean</code> | <code>true</code> | Enabled Extended JSON's `relaxed` mode |\n\nConverts a BSON document to an Extended JSON string, optionally replacing values if a replacer\nfunction is specified or optionally including only the specified properties if a replacer array\nis specified.\n\n**Example**  \n```js\nconst { EJSON } = require('bson');\nconst Int32 = require('mongodb').Int32;\nconst doc = { int32: new Int32(10) };\n\n// prints '{\"int32\":{\"$numberInt\":\"10\"}}'\nconsole.log(EJSON.stringify(doc, { relaxed: false }));\n\n// prints '{\"int32\":10}'\nconsole.log(EJSON.stringify(doc));\n```\n<a name=\"EJSON.serialize\"></a>\n\n#### *EJSON*.serialize(bson, [options])\n\n| Param | Type | Description |\n| --- | --- | --- |\n| bson | <code>object</code> | The object to serialize |\n| [options] | <code>object</code> | Optional settings passed to the `stringify` function |\n\nSerializes an object to an Extended JSON string, and reparse it as a JavaScript object.\n\n<a name=\"EJSON.deserialize\"></a>\n\n#### *EJSON*.deserialize(ejson, [options])\n\n| Param | Type | Description |\n| --- | --- | --- |\n| ejson | <code>object</code> | The Extended JSON object to deserialize |\n| [options] | <code>object</code> | Optional settings passed to the parse method |\n\nDeserializes an Extended JSON object into a plain JavaScript object with native/BSON types\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":"c210a695d585ac5340c3434e7699f73fbd771b04","homepage":"https://github.com/mongodb/js-bson#readme","_id":"bson@4.0.0-rc6","_npmVersion":"6.4.1","_nodeVersion":"8.12.0","_npmUser":{"name":"mbroadst","email":"mbroadst@gmail.com"},"dist":{"integrity":"sha512-pMR0qqnc+9XyktF6M1Rhnx2YXmrOhldC42/Gxftt+tpW4Bd5U7KScWwJwP7ymNx/elb1hn6DReIIsyuxSXxdrQ==","shasum":"a03bdf4e627abefe477b7aaef533eb8fa7d42f9f","tarball":"http://registry-npm.ywwl.com/bson/download/bson-4.0.0-rc6.tgz","fileCount":33,"unpackedSize":917084,"npm-signature":"-----BEGIN PGP SIGNATURE-----\r\nVersion: OpenPGP.js v3.0.4\r\nComment: https://openpgpjs.org\r\n\r\nwsFcBAEBCAAQBQJbz1eKCRA9TVsSAnZWagAAUkMQAIjCNLoayVvZpFyTBti8\n04Tr0q62yMAo3TRKbHf8u51A5l3gWBl+Kr+FEHZ3S2OhvbI9I0mVtYJyhU7z\nvsT4HwPvot6jeIALQO9+AHMgOWGzctbFB2Yla5GvreEA7e7XrgSfxOr9CtBd\nupVUq7Vd7t6Xu8vy+EdGO2I8E+RUc3B5BSKScfq4iT/waS+STYgjfUEqGLZe\nIim1uQhW/QZvQBgCr7aBECMxYv3JKJrl6ro1GBgDTUXqc23mCTTEKhNbSXLR\n3JBzN8IYOV0qNBGjzhluHrtZvL/TyujVHW15zlZ2lrc14wmcG9c5G6bB8wXY\n2ooXwA02MwhXaHhW6pJkDmIRVLEv3lIUGHxJycd5g0MO0AXD2nYe3lvcr6u8\nEpALC+ywtdoksg+ZWnhwFzaIfOcBp91VarILRTC9BrMPfXkkqSxber61Vk4h\nMpmfYig1FhIBkWABuD7Cp5/gz4WAjFwqxgaZGORO8rxWFGfvqFP+6b2FyWFq\n639V8+PUtFmehRVoMQJKglNtCB2cExvT3UfT8GDpN1oy36rjEJkbuVPWtHLG\nOvsA2U4y/xtAg90UQPYPHjAWkm/RAw6wunv1hQmGsPz0bfEI/lAMWz7p6pX4\nHlLBdu0JEew/FgjMnRzgIkbtCiKGgIRg+Aqwkj7WmMQ6/OfFeGUNEhmW5us1\nXa+9\r\n=1rnW\r\n-----END PGP SIGNATURE-----\r\n","signatures":[{"keyid":"SHA256:jl3bwswu80PjjokCgh0o2w5c2U4LhQAE57gj9cz1kzA","sig":"MEYCIQDWl6zWp0HFc76l48yi+uMV3vrS/O/Gr14Tf42kOMOAOwIhAM4YMh6Fzklb5qGrzybBPkgxv1LmbMkJKOLOsRqdjQI2"}],"size":186106,"noattachment":false,"key":"/bson/-/bson-4.0.0-rc6.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-rc6_1540315017818_0.7870699777134655"},"_hasShrinkwrap":false,"publish_time":1540315017968,"_cnpm_publish_time":1540315017968,"dist-tags":{"5x":"5.5.1","alpha":"7.0.0-alpha.2","latest":"7.3.4","legacy":"6.9.1"}}