Comparing version 1.0.6 to 1.0.7
@@ -0,1 +1,14 @@ | ||
<a name="1.0.7"></a> | ||
## [1.0.7](https://github.com/mongodb/js-bson/compare/v1.0.6...v1.0.7) (2018-06-06) | ||
### Bug Fixes | ||
* **binary:** add type checking for buffer ([26b05b5](https://github.com/mongodb/js-bson/commit/26b05b5)) | ||
* **bson:** fix custom inspect property ([080323b](https://github.com/mongodb/js-bson/commit/080323b)) | ||
* **readme:** clarify documentation about deserialize methods ([20f764c](https://github.com/mongodb/js-bson/commit/20f764c)) | ||
* **serialization:** normalize function stringification ([1320c10](https://github.com/mongodb/js-bson/commit/1320c10)) | ||
<a name="1.0.6"></a> | ||
@@ -2,0 +15,0 @@ ## [1.0.6](https://github.com/mongodb/js-bson/compare/v1.0.5...v1.0.6) (2018-03-12) |
@@ -31,2 +31,12 @@ /** | ||
if ( | ||
buffer != null && | ||
!(typeof buffer === 'string') && | ||
!Buffer.isBuffer(buffer) && | ||
!(buffer instanceof Uint8Array) && | ||
!Array.isArray(buffer) | ||
) { | ||
throw new Error('only String, Buffer, Uint8Array or Array accepted'); | ||
} | ||
this._bsontype = 'Binary'; | ||
@@ -33,0 +43,0 @@ |
@@ -0,1 +1,4 @@ | ||
// Custom inspect property name / symbol. | ||
var inspect = 'inspect'; | ||
/** | ||
@@ -16,3 +19,6 @@ * Machine id. | ||
try { | ||
if (Buffer && Buffer.from) var hasBufferType = true; | ||
if (Buffer && Buffer.from) { | ||
var hasBufferType = true; | ||
inspect = require('util').inspect.custom || 'inspect'; | ||
} | ||
} catch (err) { | ||
@@ -200,3 +206,3 @@ hasBufferType = false; | ||
*/ | ||
ObjectID.prototype.inspect = ObjectID.prototype.toString; | ||
ObjectID.prototype[inspect] = ObjectID.prototype.toString; | ||
@@ -203,0 +209,0 @@ /** |
@@ -16,2 +16,4 @@ 'use strict'; | ||
var normalizedFunctionString = require('./utils').normalizedFunctionString; | ||
// To ensure that 0.4 of node works correctly | ||
@@ -225,3 +227,3 @@ var isDate = function isDate(d) { | ||
4 + | ||
Buffer.byteLength(value.toString(), 'utf8') + | ||
Buffer.byteLength(normalizedFunctionString(value), 'utf8') + | ||
1 + | ||
@@ -235,3 +237,3 @@ calculateObjectSize(value.scope, serializeFunctions, ignoreUndefined) | ||
4 + | ||
Buffer.byteLength(value.toString(), 'utf8') + | ||
Buffer.byteLength(normalizedFunctionString(value), 'utf8') + | ||
1 | ||
@@ -238,0 +240,0 @@ ); |
@@ -9,2 +9,4 @@ 'use strict'; | ||
const normalizedFunctionString = require('./utils').normalizedFunctionString; | ||
// try { | ||
@@ -447,3 +449,4 @@ // var _Buffer = Uint8Array; | ||
// Function string | ||
var functionString = value.toString(); | ||
var functionString = normalizedFunctionString(value); | ||
// Write the string | ||
@@ -450,0 +453,0 @@ var size = buffer.write(functionString, index + 4, 'utf8') + 1; |
@@ -0,1 +1,4 @@ | ||
// Custom inspect property name / symbol. | ||
var inspect = Buffer ? require('util').inspect.custom || 'inspect' : 'inspect'; | ||
/** | ||
@@ -35,3 +38,3 @@ * A class representation of the BSON Symbol type. | ||
*/ | ||
Symbol.prototype.inspect = function() { | ||
Symbol.prototype[inspect] = function() { | ||
return this.value; | ||
@@ -38,0 +41,0 @@ }; |
{ | ||
"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.6", | ||
"keywords": [ | ||
"mongodb", | ||
"bson", | ||
"parser" | ||
], | ||
"files": [ | ||
"lib", | ||
"index.js", | ||
"browser_build", | ||
"bower.json" | ||
], | ||
"version": "1.0.7", | ||
"author": "Christian Amor Kvalheim <christkv@gmail.com>", | ||
@@ -43,4 +52,3 @@ "contributors": [], | ||
"lint": "eslint lib test", | ||
"format": | ||
"prettier --print-width 100 --tab-width 2 --single-quote --write 'test/**/*.js' 'lib/**/*.js'" | ||
"format": "prettier --print-width 100 --tab-width 2 --single-quote --write 'test/**/*.js' 'lib/**/*.js'" | ||
}, | ||
@@ -47,0 +55,0 @@ "browser": "lib/bson/bson.js", |
@@ -126,3 +126,3 @@ # BSON parser | ||
* @param {Object} [options.bsonRegExp=false] return BSON regular expressions as BSONRegExp instances. | ||
* @return {Number} returns the next index in the buffer after deserialization **x** numbers of documents. | ||
* @return {Object} returns the deserialized Javascript Object. | ||
@@ -147,3 +147,3 @@ #### BSON.deserializeStream | ||
* @param {Object} [options.bsonRegExp=false] return BSON regular expressions as BSONRegExp instances. | ||
* @return {Object} returns the deserialized JavaScript Object. | ||
* @return {Number} returns the next index in the buffer after deserialization **x** numbers of documents. | ||
@@ -155,1 +155,19 @@ ## FAQ | ||
The `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. | ||
#### How do I add custom serialization logic? | ||
This library looks for `toBSON()` functions on every path, and calls the `toBSON()` function to get the value to serialize. | ||
```javascript | ||
var bson = new BSON(); | ||
class CustomSerialize { | ||
toBSON() { | ||
return 42; | ||
} | ||
} | ||
const obj = { answer: new CustomSerialize() }; | ||
// "{ answer: 42 }" | ||
console.log(bson.deserialize(bson.serialize(obj))); | ||
``` |
Sorry, the diff of this file is too big to display
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
754552
28
21086
171