Socket
Socket
Sign inDemoInstall

bson

Package Overview
Dependencies
Maintainers
2
Versions
162
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

bson - npm Package Compare versions

Comparing version 0.2.15 to 0.2.16

testcases.js

1

ext/index.js

@@ -17,2 +17,3 @@ var bson = null;

} catch (err) {
console.dir(err)
console.error("js-bson: Failed to load c++ bson extension, using pure JS version");

@@ -19,0 +20,0 @@ bson = require('../lib/bson/bson');

101

lib/bson/binary.js
/**
* Module dependencies.
* @ignore
*/

@@ -8,35 +9,3 @@ if(typeof window === 'undefined') {

// Binary default subtype
var BSON_BINARY_SUBTYPE_DEFAULT = 0;
/**
* @ignore
* @api private
*/
var writeStringToArray = function(data) {
// Create a buffer
var buffer = typeof Uint8Array != 'undefined' ? new Uint8Array(new ArrayBuffer(data.length)) : new Array(data.length);
// Write the content to the buffer
for(var i = 0; i < data.length; i++) {
buffer[i] = data.charCodeAt(i);
}
// Write the string to the buffer
return buffer;
}
/**
* Convert Array ot Uint8Array to Binary String
*
* @ignore
* @api private
*/
var convertArraytoUtf8BinaryString = function(byteArray, startIndex, endIndex) {
var result = "";
for(var i = startIndex; i < endIndex; i++) {
result = result + String.fromCharCode(byteArray[i]);
}
return result;
};
/**
* A class representation of the BSON Binary type.

@@ -52,6 +21,6 @@ *

*
* @class Represents the Binary BSON type.
* @class Represents a BSON Binary type.
* @param {Buffer} buffer a buffer object containing the binary data.
* @param {Number} [subType] the option binary type.
* @return {Grid}
* @return {Binary}
*/

@@ -102,4 +71,4 @@ function Binary(buffer, subType) {

*
* @param {Character} byte_value a single byte we wish to write.
* @api public
* @method
* @param {string} byte_value a single byte we wish to write.
*/

@@ -156,5 +125,6 @@ Binary.prototype.put = function put(byte_value) {

*
* @param {Buffer|String} string a string or buffer to be written to the Binary BSON object.
* @param {Number} offset specify the binary of where to write the content.
* @api public
* @method
* @param {(Buffer|string)} string a string or buffer to be written to the Binary BSON object.
* @param {number} offset specify the binary of where to write the content.
* @return {null}
*/

@@ -211,6 +181,6 @@ Binary.prototype.write = function write(string, offset) {

*
* @param {Number} position read from the given position in the Binary.
* @param {Number} length the number of bytes to read.
* @method
* @param {number} position read from the given position in the Binary.
* @param {number} length the number of bytes to read.
* @return {Buffer}
* @api public
*/

@@ -239,4 +209,4 @@ Binary.prototype.read = function read(position, length) {

*
* @return {String}
* @api public
* @method
* @return {string}
*/

@@ -277,4 +247,4 @@ Binary.prototype.value = function value(asRaw) {

*
* @return {Number} the length of the binary.
* @api public
* @method
* @return {number} the length of the binary.
*/

@@ -287,3 +257,2 @@ Binary.prototype.length = function length() {

* @ignore
* @api private
*/

@@ -296,3 +265,2 @@ Binary.prototype.toJSON = function() {

* @ignore
* @api private
*/

@@ -303,2 +271,35 @@ Binary.prototype.toString = function(format) {

/**
* Binary default subtype
* @ignore
*/
var BSON_BINARY_SUBTYPE_DEFAULT = 0;
/**
* @ignore
*/
var writeStringToArray = function(data) {
// Create a buffer
var buffer = typeof Uint8Array != 'undefined' ? new Uint8Array(new ArrayBuffer(data.length)) : new Array(data.length);
// Write the content to the buffer
for(var i = 0; i < data.length; i++) {
buffer[i] = data.charCodeAt(i);
}
// Write the string to the buffer
return buffer;
}
/**
* Convert Array ot Uint8Array to Binary String
*
* @ignore
*/
var convertArraytoUtf8BinaryString = function(byteArray, startIndex, endIndex) {
var result = "";
for(var i = startIndex; i < endIndex; i++) {
result = result + String.fromCharCode(byteArray[i]);
}
return result;
};
Binary.BUFFER_SIZE = 256;

@@ -352,3 +353,3 @@

*/
exports.Binary = Binary;
module.exports = Binary;
module.exports.Binary = Binary;
/**
* A class representation of the BSON Code type.
*
* @class Represents the BSON Code type.
* @param {String|Function} code a string or function.
* @class Represents a BSON Code and Code with scope type.
* @param {(string|function)} code a string or function.
* @param {Object} [scope] an optional scope for the function.

@@ -18,3 +18,2 @@ * @return {Code}

* @ignore
* @api private
*/

@@ -25,2 +24,3 @@ Code.prototype.toJSON = function() {

exports.Code = Code;
module.exports = Code;
module.exports.Code = Code;
/**
* A class representation of the BSON DBRef type.
*
* @class Represents the BSON DBRef type.
* @param {String} namespace the collection name.
* @class Represents a BSON DbRef type.
* @param {string} namespace the collection name.
* @param {ObjectID} oid the reference ObjectID.
* @param {String} [db] optional db name, if omitted the reference is local to the current db.
* @param {string} [db] optional db name, if omitted the reference is local to the current db.
* @return {DBRef}

@@ -31,2 +31,3 @@ */

exports.DBRef = DBRef;
module.exports = DBRef;
module.exports.DBRef = DBRef;
/**
* A class representation of the BSON Double type.
*
* @class Represents the BSON Double type.
* @param {Number} value the number we want to represent as a double.
* @class Represents a BSON Double type.
* @param {number} value the number we want to represent as a double.
* @return {Double}

@@ -18,4 +18,4 @@ */

*
* @return {Number} returns the wrapped double number.
* @api public
* @method
* @return {number} returns the wrapped double number.
*/

@@ -28,3 +28,2 @@ Double.prototype.valueOf = function() {

* @ignore
* @api private
*/

@@ -35,2 +34,3 @@ Double.prototype.toJSON = function() {

exports.Double = Double;
module.exports = Double;
module.exports.Double = Double;

@@ -39,4 +39,5 @@ // Licensed under the Apache License, Version 2.0 (the "License");

* @class Represents the BSON Long type.
* @param {Number} low the low (signed) 32 bits of the Long.
* @param {Number} high the high (signed) 32 bits of the Long.
* @param {number} low the low (signed) 32 bits of the Long.
* @param {number} high the high (signed) 32 bits of the Long.
* @return {Long}
*/

@@ -49,3 +50,3 @@ function Long(low, high) {

* @type {number}
* @api private
* @ignore
*/

@@ -56,3 +57,3 @@ this.low_ = low | 0; // force into 32 signed bits.

* @type {number}
* @api private
* @ignore
*/

@@ -65,4 +66,4 @@ this.high_ = high | 0; // force into 32 signed bits.

*
* @return {Number} the value, assuming it is a 32-bit integer.
* @api public
* @method
* @return {number} the value, assuming it is a 32-bit integer.
*/

@@ -76,4 +77,4 @@ Long.prototype.toInt = function() {

*
* @return {Number} the closest floating-point representation to this value.
* @api public
* @method
* @return {number} the closest floating-point representation to this value.
*/

@@ -88,4 +89,4 @@ Long.prototype.toNumber = function() {

*
* @return {String} the JSON representation.
* @api public
* @method
* @return {string} the JSON representation.
*/

@@ -99,5 +100,5 @@ Long.prototype.toJSON = function() {

*
* @param {Number} [opt_radix] the radix in which the text should be written.
* @return {String} the textual representation of this value.
* @api public
* @method
* @param {number} [opt_radix] the radix in which the text should be written.
* @return {string} the textual representation of this value.
*/

@@ -153,4 +154,4 @@ Long.prototype.toString = function(opt_radix) {

*
* @return {Number} the high 32-bits as a signed value.
* @api public
* @method
* @return {number} the high 32-bits as a signed value.
*/

@@ -164,4 +165,4 @@ Long.prototype.getHighBits = function() {

*
* @return {Number} the low 32-bits as a signed value.
* @api public
* @method
* @return {number} the low 32-bits as a signed value.
*/

@@ -175,4 +176,4 @@ Long.prototype.getLowBits = function() {

*
* @return {Number} the low 32-bits as an unsigned value.
* @api public
* @method
* @return {number} the low 32-bits as an unsigned value.
*/

@@ -187,4 +188,4 @@ Long.prototype.getLowBitsUnsigned = function() {

*
* @return {Number} Returns the number of bits needed to represent the absolute value of this Long.
* @api public
* @method
* @return {number} Returns the number of bits needed to represent the absolute value of this Long.
*/

@@ -212,4 +213,4 @@ Long.prototype.getNumBitsAbs = function() {

*
* @return {Boolean} whether this value is zero.
* @api public
* @method
* @return {boolean} whether this value is zero.
*/

@@ -223,4 +224,4 @@ Long.prototype.isZero = function() {

*
* @return {Boolean} whether this value is negative.
* @api public
* @method
* @return {boolean} whether this value is negative.
*/

@@ -234,4 +235,4 @@ Long.prototype.isNegative = function() {

*
* @return {Boolean} whether this value is odd.
* @api public
* @method
* @return {boolean} whether this value is odd.
*/

@@ -245,5 +246,5 @@ Long.prototype.isOdd = function() {

*
* @method
* @param {Long} other Long to compare against.
* @return {Boolean} whether this Long equals the other
* @api public
* @return {boolean} whether this Long equals the other
*/

@@ -257,5 +258,5 @@ Long.prototype.equals = function(other) {

*
* @method
* @param {Long} other Long to compare against.
* @return {Boolean} whether this Long does not equal the other.
* @api public
* @return {boolean} whether this Long does not equal the other.
*/

@@ -269,5 +270,5 @@ Long.prototype.notEquals = function(other) {

*
* @method
* @param {Long} other Long to compare against.
* @return {Boolean} whether this Long is less than the other.
* @api public
* @return {boolean} whether this Long is less than the other.
*/

@@ -281,5 +282,5 @@ Long.prototype.lessThan = function(other) {

*
* @method
* @param {Long} other Long to compare against.
* @return {Boolean} whether this Long is less than or equal to the other.
* @api public
* @return {boolean} whether this Long is less than or equal to the other.
*/

@@ -293,5 +294,5 @@ Long.prototype.lessThanOrEqual = function(other) {

*
* @method
* @param {Long} other Long to compare against.
* @return {Boolean} whether this Long is greater than the other.
* @api public
* @return {boolean} whether this Long is greater than the other.
*/

@@ -305,5 +306,5 @@ Long.prototype.greaterThan = function(other) {

*
* @method
* @param {Long} other Long to compare against.
* @return {Boolean} whether this Long is greater than or equal to the other.
* @api public
* @return {boolean} whether this Long is greater than or equal to the other.
*/

@@ -317,5 +318,5 @@ Long.prototype.greaterThanOrEqual = function(other) {

*
* @method
* @param {Long} other Long to compare against.
* @return {Boolean} 0 if they are the same, 1 if the this is greater, and -1 if the given one is greater.
* @api public
* @return {boolean} 0 if they are the same, 1 if the this is greater, and -1 if the given one is greater.
*/

@@ -347,4 +348,4 @@ Long.prototype.compare = function(other) {

*
* @method
* @return {Long} the negation of this value.
* @api public
*/

@@ -362,5 +363,5 @@ Long.prototype.negate = function() {

*
* @method
* @param {Long} other Long to add to this one.
* @return {Long} the sum of this and the given Long.
* @api public
*/

@@ -398,5 +399,5 @@ Long.prototype.add = function(other) {

*
* @method
* @param {Long} other Long to subtract from this.
* @return {Long} the difference of this and the given Long.
* @api public
*/

@@ -410,5 +411,5 @@ Long.prototype.subtract = function(other) {

*
* @method
* @param {Long} other Long to multiply with this.
* @return {Long} the product of this and the other.
* @api public
*/

@@ -484,5 +485,5 @@ Long.prototype.multiply = function(other) {

*
* @method
* @param {Long} other Long by which to divide.
* @return {Long} this Long divided by the given one.
* @api public
*/

@@ -570,5 +571,5 @@ Long.prototype.div = function(other) {

*
* @method
* @param {Long} other Long by which to mod.
* @return {Long} this Long modulo the given one.
* @api public
*/

@@ -582,4 +583,4 @@ Long.prototype.modulo = function(other) {

*
* @method
* @return {Long} the bitwise-NOT of this value.
* @api public
*/

@@ -593,5 +594,5 @@ Long.prototype.not = function() {

*
* @method
* @param {Long} other the Long with which to AND.
* @return {Long} the bitwise-AND of this and the other.
* @api public
*/

@@ -605,5 +606,5 @@ Long.prototype.and = function(other) {

*
* @method
* @param {Long} other the Long with which to OR.
* @return {Long} the bitwise-OR of this and the other.
* @api public
*/

@@ -617,5 +618,5 @@ Long.prototype.or = function(other) {

*
* @method
* @param {Long} other the Long with which to XOR.
* @return {Long} the bitwise-XOR of this and the other.
* @api public
*/

@@ -629,5 +630,5 @@ Long.prototype.xor = function(other) {

*
* @param {Number} numBits the number of bits by which to shift.
* @method
* @param {number} numBits the number of bits by which to shift.
* @return {Long} this shifted to the left by the given amount.
* @api public
*/

@@ -654,5 +655,5 @@ Long.prototype.shiftLeft = function(numBits) {

*
* @param {Number} numBits the number of bits by which to shift.
* @method
* @param {number} numBits the number of bits by which to shift.
* @return {Long} this shifted to the right by the given amount.
* @api public
*/

@@ -681,5 +682,5 @@ Long.prototype.shiftRight = function(numBits) {

*
* @param {Number} numBits the number of bits by which to shift.
* @method
* @param {number} numBits the number of bits by which to shift.
* @return {Long} this shifted to the right by the given amount, with zeros placed into the new leading bits.
* @api public
*/

@@ -708,5 +709,5 @@ Long.prototype.shiftRightUnsigned = function(numBits) {

*
* @param {Number} value the 32-bit integer in question.
* @method
* @param {number} value the 32-bit integer in question.
* @return {Long} the corresponding Long value.
* @api public
*/

@@ -731,5 +732,5 @@ Long.fromInt = function(value) {

*
* @param {Number} value the number in question.
* @method
* @param {number} value the number in question.
* @return {Long} the corresponding Long value.
* @api public
*/

@@ -755,6 +756,6 @@ Long.fromNumber = function(value) {

*
* @param {Number} lowBits the low 32-bits.
* @param {Number} highBits the high 32-bits.
* @method
* @param {number} lowBits the low 32-bits.
* @param {number} highBits the high 32-bits.
* @return {Long} the corresponding Long value.
* @api public
*/

@@ -768,6 +769,6 @@ Long.fromBits = function(lowBits, highBits) {

*
* @param {String} str the textual representation of the Long.
* @param {Number} opt_radix the radix in which the text is written.
* @method
* @param {string} str the textual representation of the Long.
* @param {number} opt_radix the radix in which the text is written.
* @return {Long} the corresponding Long value.
* @api public
*/

@@ -816,3 +817,3 @@ Long.fromString = function(str, opt_radix) {

* @type {Object}
* @api private
* @ignore
*/

@@ -828,3 +829,3 @@ Long.INT_CACHE_ = {};

* @type {number}
* @api private
* @ignore
*/

@@ -835,3 +836,3 @@ Long.TWO_PWR_16_DBL_ = 1 << 16;

* @type {number}
* @api private
* @ignore
*/

@@ -842,3 +843,3 @@ Long.TWO_PWR_24_DBL_ = 1 << 24;

* @type {number}
* @api private
* @ignore
*/

@@ -849,3 +850,3 @@ Long.TWO_PWR_32_DBL_ = Long.TWO_PWR_16_DBL_ * Long.TWO_PWR_16_DBL_;

* @type {number}
* @api private
* @ignore
*/

@@ -856,3 +857,3 @@ Long.TWO_PWR_31_DBL_ = Long.TWO_PWR_32_DBL_ / 2;

* @type {number}
* @api private
* @ignore
*/

@@ -863,3 +864,3 @@ Long.TWO_PWR_48_DBL_ = Long.TWO_PWR_32_DBL_ * Long.TWO_PWR_16_DBL_;

* @type {number}
* @api private
* @ignore
*/

@@ -870,3 +871,3 @@ Long.TWO_PWR_64_DBL_ = Long.TWO_PWR_32_DBL_ * Long.TWO_PWR_32_DBL_;

* @type {number}
* @api private
* @ignore
*/

@@ -893,3 +894,3 @@ Long.TWO_PWR_63_DBL_ = Long.TWO_PWR_64_DBL_ / 2;

* @type {Long}
* @api private
* @ignore
*/

@@ -901,2 +902,3 @@ Long.TWO_PWR_24_ = Long.fromInt(1 << 24);

*/
exports.Long = Long;
module.exports = Long;
module.exports.Long = Long;
/**
* A class representation of the BSON MaxKey type.
*
* @class Represents the BSON MaxKey type.
* @return {MaxKey}
* @class Represents a BSON MaxKey type.
* @return {MaxKey} A MaxKey instance
*/

@@ -13,2 +13,3 @@ function MaxKey() {

exports.MaxKey = MaxKey;
module.exports = MaxKey;
module.exports.MaxKey = MaxKey;
/**
* A class representation of the BSON MinKey type.
*
* @class Represents the BSON MinKey type.
* @return {MinKey}
* @class Represents a BSON MinKey type.
* @return {MinKey} A MinKey instance
*/

@@ -13,2 +13,3 @@ function MinKey() {

exports.MinKey = MinKey;
module.exports = MinKey;
module.exports.MinKey = MinKey;
/**
* Module dependencies.
* @ignore
*/

@@ -12,2 +13,3 @@ var BinaryParser = require('./binary_parser').BinaryParser;

* that would mean an asyc call to gethostname, so we don't bother.
* @ignore
*/

@@ -22,5 +24,6 @@ var MACHINE_ID = parseInt(Math.random() * 0xFFFFFF, 10);

*
* @class Represents the BSON ObjectID type
* @param {String|Number} id Can be a 24 byte hex string, 12 byte binary string or a Number.
* @return {Object} instance of ObjectID.
* @class Represents a BSON ObjectId type.
* @param {(string|number)} id Can be a 24 byte hex string, 12 byte binary string or a Number.
* @property {number} generationTime The generation time of this ObjectId instance
* @return {ObjectID} instance of ObjectID.
*/

@@ -63,4 +66,4 @@ var ObjectID = function ObjectID(id) {

*
* @return {String} return the 24 byte hex string representation.
* @api public
* @method
* @return {string} return the 24 byte hex string representation.
*/

@@ -83,4 +86,5 @@ ObjectID.prototype.toHexString = function() {

*
* @return {Number} returns next index value.
* @api private
* @method
* @return {number} returns next index value.
* @ignore
*/

@@ -94,4 +98,5 @@ ObjectID.prototype.get_inc = function() {

*
* @return {Number} returns next index value.
* @api private
* @method
* @return {number} returns next index value.
* @ignore
*/

@@ -105,5 +110,5 @@ ObjectID.prototype.getInc = function() {

*
* @param {Number} [time] optional parameter allowing to pass in a second based timestamp.
* @return {String} return the 12 byte id binary string.
* @api private
* @method
* @param {number} [time] optional parameter allowing to pass in a second based timestamp.
* @return {string} return the 12 byte id binary string.
*/

@@ -118,3 +123,3 @@ ObjectID.prototype.generate = function(time) {

var machine3Bytes = BinaryParser.encodeInt(MACHINE_ID, 24, false);
var pid2Bytes = BinaryParser.fromShort(typeof process === 'undefined' ? Math.floor(Math.random() * 100000) : process.pid);
var pid2Bytes = BinaryParser.fromShort(typeof process === 'undefined' ? Math.floor(Math.random() * 100000) : process.pid % 0xFFFF);
var index3Bytes = BinaryParser.encodeInt(this.get_inc(), 24, false, true);

@@ -129,3 +134,3 @@

* @return {String} return the 24 byte hex string representation.
* @api private
* @ignore
*/

@@ -140,3 +145,3 @@ ObjectID.prototype.toString = function() {

* @return {String} return the 24 byte hex string representation.
* @api private
* @ignore
*/

@@ -149,3 +154,3 @@ ObjectID.prototype.inspect = ObjectID.prototype.toString;

* @return {String} return the 24 byte hex string representation.
* @api private
* @ignore
*/

@@ -159,5 +164,5 @@ ObjectID.prototype.toJSON = function() {

*
* @param {Object} otherID ObjectID instance to compare against.
* @return {Bool} the result of comparing two ObjectID's
* @api public
* @method
* @param {object} otherID ObjectID instance to compare against.
* @return {boolean} the result of comparing two ObjectID's
*/

@@ -176,4 +181,4 @@ ObjectID.prototype.equals = function equals (otherID) {

*
* @return {Date} the generation date
* @api public
* @method
* @return {date} the generation date
*/

@@ -188,6 +193,8 @@ ObjectID.prototype.getTimestamp = function() {

* @ignore
* @api private
*/
ObjectID.index = parseInt(Math.random() * 0xFFFFFF, 10);
/**
* @ignore
*/
ObjectID.createPk = function createPk () {

@@ -200,5 +207,5 @@ return new ObjectID();

*
* @param {Number} time an integer number representing a number of seconds.
* @method
* @param {number} time an integer number representing a number of seconds.
* @return {ObjectID} return the created ObjectID
* @api public
*/

@@ -214,5 +221,5 @@ ObjectID.createFromTime = function createFromTime (time) {

*
* @param {String} hexString create a ObjectID from a passed in 24 byte hexstring.
* @method
* @param {string} hexString create a ObjectID from a passed in 24 byte hexstring.
* @return {ObjectID} return the created ObjectID
* @api public
*/

@@ -246,4 +253,4 @@ ObjectID.createFromHexString = function createFromHexString (hexString) {

*
* @return {Boolean} return true if the value is a valid bson ObjectId, return false otherwise.
* @api public
* @method
* @return {boolean} return true if the value is a valid bson ObjectId, return false otherwise.
*/

@@ -281,3 +288,4 @@ ObjectID.isValid = function isValid(id) {

*/
exports.ObjectID = ObjectID;
exports.ObjectId = ObjectID;
module.exports = ObjectID;
module.exports.ObjectID = ObjectID;
module.exports.ObjectId = ObjectID;
/**
* A class representation of the BSON Symbol type.
*
* @class Represents the BSON Symbol type.
* @param {String} value the string representing the symbol.
* @class Represents a BSON Symbol type.
* @deprecated
* @param {string} value the string representing the symbol.
* @return {Symbol}

@@ -17,4 +18,4 @@ */

*
* @method
* @return {String} returns the wrapped string.
* @api public
*/

@@ -27,3 +28,2 @@ Symbol.prototype.valueOf = function() {

* @ignore
* @api private
*/

@@ -36,3 +36,2 @@ Symbol.prototype.toString = function() {

* @ignore
* @api private
*/

@@ -45,3 +44,2 @@ Symbol.prototype.inspect = function() {

* @ignore
* @api private
*/

@@ -52,2 +50,3 @@ Symbol.prototype.toJSON = function() {

exports.Symbol = Symbol;
module.exports = Symbol;
module.exports.Symbol = Symbol;

@@ -39,4 +39,4 @@ // Licensed under the Apache License, Version 2.0 (the "License");

* @class Represents the BSON Timestamp type.
* @param {Number} low the low (signed) 32 bits of the Timestamp.
* @param {Number} high the high (signed) 32 bits of the Timestamp.
* @param {number} low the low (signed) 32 bits of the Timestamp.
* @param {number} high the high (signed) 32 bits of the Timestamp.
*/

@@ -48,3 +48,3 @@ function Timestamp(low, high) {

* @type {number}
* @api private
* @ignore
*/

@@ -55,3 +55,3 @@ this.low_ = low | 0; // force into 32 signed bits.

* @type {number}
* @api private
* @ignore
*/

@@ -64,4 +64,3 @@ this.high_ = high | 0; // force into 32 signed bits.

*
* @return {Number} the value, assuming it is a 32-bit integer.
* @api public
* @return {number} the value, assuming it is a 32-bit integer.
*/

@@ -75,4 +74,4 @@ Timestamp.prototype.toInt = function() {

*
* @return {Number} the closest floating-point representation to this value.
* @api public
* @method
* @return {number} the closest floating-point representation to this value.
*/

@@ -87,4 +86,4 @@ Timestamp.prototype.toNumber = function() {

*
* @return {String} the JSON representation.
* @api public
* @method
* @return {string} the JSON representation.
*/

@@ -98,5 +97,5 @@ Timestamp.prototype.toJSON = function() {

*
* @param {Number} [opt_radix] the radix in which the text should be written.
* @return {String} the textual representation of this value.
* @api public
* @method
* @param {number} [opt_radix] the radix in which the text should be written.
* @return {string} the textual representation of this value.
*/

@@ -152,4 +151,4 @@ Timestamp.prototype.toString = function(opt_radix) {

*
* @return {Number} the high 32-bits as a signed value.
* @api public
* @method
* @return {number} the high 32-bits as a signed value.
*/

@@ -163,4 +162,4 @@ Timestamp.prototype.getHighBits = function() {

*
* @return {Number} the low 32-bits as a signed value.
* @api public
* @method
* @return {number} the low 32-bits as a signed value.
*/

@@ -174,4 +173,4 @@ Timestamp.prototype.getLowBits = function() {

*
* @return {Number} the low 32-bits as an unsigned value.
* @api public
* @method
* @return {number} the low 32-bits as an unsigned value.
*/

@@ -186,4 +185,4 @@ Timestamp.prototype.getLowBitsUnsigned = function() {

*
* @return {Number} Returns the number of bits needed to represent the absolute value of this Timestamp.
* @api public
* @method
* @return {number} Returns the number of bits needed to represent the absolute value of this Timestamp.
*/

@@ -211,4 +210,4 @@ Timestamp.prototype.getNumBitsAbs = function() {

*
* @return {Boolean} whether this value is zero.
* @api public
* @method
* @return {boolean} whether this value is zero.
*/

@@ -222,4 +221,4 @@ Timestamp.prototype.isZero = function() {

*
* @return {Boolean} whether this value is negative.
* @api public
* @method
* @return {boolean} whether this value is negative.
*/

@@ -233,4 +232,4 @@ Timestamp.prototype.isNegative = function() {

*
* @return {Boolean} whether this value is odd.
* @api public
* @method
* @return {boolean} whether this value is odd.
*/

@@ -244,5 +243,5 @@ Timestamp.prototype.isOdd = function() {

*
* @method
* @param {Timestamp} other Timestamp to compare against.
* @return {Boolean} whether this Timestamp equals the other
* @api public
* @return {boolean} whether this Timestamp equals the other
*/

@@ -256,5 +255,5 @@ Timestamp.prototype.equals = function(other) {

*
* @method
* @param {Timestamp} other Timestamp to compare against.
* @return {Boolean} whether this Timestamp does not equal the other.
* @api public
* @return {boolean} whether this Timestamp does not equal the other.
*/

@@ -268,5 +267,5 @@ Timestamp.prototype.notEquals = function(other) {

*
* @method
* @param {Timestamp} other Timestamp to compare against.
* @return {Boolean} whether this Timestamp is less than the other.
* @api public
* @return {boolean} whether this Timestamp is less than the other.
*/

@@ -280,5 +279,5 @@ Timestamp.prototype.lessThan = function(other) {

*
* @method
* @param {Timestamp} other Timestamp to compare against.
* @return {Boolean} whether this Timestamp is less than or equal to the other.
* @api public
* @return {boolean} whether this Timestamp is less than or equal to the other.
*/

@@ -292,5 +291,5 @@ Timestamp.prototype.lessThanOrEqual = function(other) {

*
* @method
* @param {Timestamp} other Timestamp to compare against.
* @return {Boolean} whether this Timestamp is greater than the other.
* @api public
* @return {boolean} whether this Timestamp is greater than the other.
*/

@@ -304,5 +303,5 @@ Timestamp.prototype.greaterThan = function(other) {

*
* @method
* @param {Timestamp} other Timestamp to compare against.
* @return {Boolean} whether this Timestamp is greater than or equal to the other.
* @api public
* @return {boolean} whether this Timestamp is greater than or equal to the other.
*/

@@ -316,5 +315,5 @@ Timestamp.prototype.greaterThanOrEqual = function(other) {

*
* @method
* @param {Timestamp} other Timestamp to compare against.
* @return {Boolean} 0 if they are the same, 1 if the this is greater, and -1 if the given one is greater.
* @api public
* @return {boolean} 0 if they are the same, 1 if the this is greater, and -1 if the given one is greater.
*/

@@ -346,4 +345,4 @@ Timestamp.prototype.compare = function(other) {

*
* @method
* @return {Timestamp} the negation of this value.
* @api public
*/

@@ -361,5 +360,5 @@ Timestamp.prototype.negate = function() {

*
* @method
* @param {Timestamp} other Timestamp to add to this one.
* @return {Timestamp} the sum of this and the given Timestamp.
* @api public
*/

@@ -397,5 +396,5 @@ Timestamp.prototype.add = function(other) {

*
* @method
* @param {Timestamp} other Timestamp to subtract from this.
* @return {Timestamp} the difference of this and the given Timestamp.
* @api public
*/

@@ -409,5 +408,5 @@ Timestamp.prototype.subtract = function(other) {

*
* @method
* @param {Timestamp} other Timestamp to multiply with this.
* @return {Timestamp} the product of this and the other.
* @api public
*/

@@ -483,5 +482,5 @@ Timestamp.prototype.multiply = function(other) {

*
* @method
* @param {Timestamp} other Timestamp by which to divide.
* @return {Timestamp} this Timestamp divided by the given one.
* @api public
*/

@@ -569,5 +568,5 @@ Timestamp.prototype.div = function(other) {

*
* @method
* @param {Timestamp} other Timestamp by which to mod.
* @return {Timestamp} this Timestamp modulo the given one.
* @api public
*/

@@ -581,4 +580,4 @@ Timestamp.prototype.modulo = function(other) {

*
* @method
* @return {Timestamp} the bitwise-NOT of this value.
* @api public
*/

@@ -592,5 +591,5 @@ Timestamp.prototype.not = function() {

*
* @method
* @param {Timestamp} other the Timestamp with which to AND.
* @return {Timestamp} the bitwise-AND of this and the other.
* @api public
*/

@@ -604,5 +603,5 @@ Timestamp.prototype.and = function(other) {

*
* @method
* @param {Timestamp} other the Timestamp with which to OR.
* @return {Timestamp} the bitwise-OR of this and the other.
* @api public
*/

@@ -616,5 +615,5 @@ Timestamp.prototype.or = function(other) {

*
* @method
* @param {Timestamp} other the Timestamp with which to XOR.
* @return {Timestamp} the bitwise-XOR of this and the other.
* @api public
*/

@@ -628,5 +627,5 @@ Timestamp.prototype.xor = function(other) {

*
* @param {Number} numBits the number of bits by which to shift.
* @method
* @param {number} numBits the number of bits by which to shift.
* @return {Timestamp} this shifted to the left by the given amount.
* @api public
*/

@@ -653,5 +652,5 @@ Timestamp.prototype.shiftLeft = function(numBits) {

*
* @param {Number} numBits the number of bits by which to shift.
* @method
* @param {number} numBits the number of bits by which to shift.
* @return {Timestamp} this shifted to the right by the given amount.
* @api public
*/

@@ -680,5 +679,5 @@ Timestamp.prototype.shiftRight = function(numBits) {

*
* @param {Number} numBits the number of bits by which to shift.
* @method
* @param {number} numBits the number of bits by which to shift.
* @return {Timestamp} this shifted to the right by the given amount, with zeros placed into the new leading bits.
* @api public
*/

@@ -707,5 +706,5 @@ Timestamp.prototype.shiftRightUnsigned = function(numBits) {

*
* @param {Number} value the 32-bit integer in question.
* @method
* @param {number} value the 32-bit integer in question.
* @return {Timestamp} the corresponding Timestamp value.
* @api public
*/

@@ -730,5 +729,5 @@ Timestamp.fromInt = function(value) {

*
* @param {Number} value the number in question.
* @method
* @param {number} value the number in question.
* @return {Timestamp} the corresponding Timestamp value.
* @api public
*/

@@ -754,6 +753,6 @@ Timestamp.fromNumber = function(value) {

*
* @param {Number} lowBits the low 32-bits.
* @param {Number} highBits the high 32-bits.
* @method
* @param {number} lowBits the low 32-bits.
* @param {number} highBits the high 32-bits.
* @return {Timestamp} the corresponding Timestamp value.
* @api public
*/

@@ -767,6 +766,6 @@ Timestamp.fromBits = function(lowBits, highBits) {

*
* @param {String} str the textual representation of the Timestamp.
* @param {Number} opt_radix the radix in which the text is written.
* @method
* @param {string} str the textual representation of the Timestamp.
* @param {number} opt_radix the radix in which the text is written.
* @return {Timestamp} the corresponding Timestamp value.
* @api public
*/

@@ -815,3 +814,3 @@ Timestamp.fromString = function(str, opt_radix) {

* @type {Object}
* @api private
* @ignore
*/

@@ -827,3 +826,3 @@ Timestamp.INT_CACHE_ = {};

* @type {number}
* @api private
* @ignore
*/

@@ -834,3 +833,3 @@ Timestamp.TWO_PWR_16_DBL_ = 1 << 16;

* @type {number}
* @api private
* @ignore
*/

@@ -841,3 +840,3 @@ Timestamp.TWO_PWR_24_DBL_ = 1 << 24;

* @type {number}
* @api private
* @ignore
*/

@@ -848,3 +847,3 @@ Timestamp.TWO_PWR_32_DBL_ = Timestamp.TWO_PWR_16_DBL_ * Timestamp.TWO_PWR_16_DBL_;

* @type {number}
* @api private
* @ignore
*/

@@ -855,3 +854,3 @@ Timestamp.TWO_PWR_31_DBL_ = Timestamp.TWO_PWR_32_DBL_ / 2;

* @type {number}
* @api private
* @ignore
*/

@@ -862,3 +861,3 @@ Timestamp.TWO_PWR_48_DBL_ = Timestamp.TWO_PWR_32_DBL_ * Timestamp.TWO_PWR_16_DBL_;

* @type {number}
* @api private
* @ignore
*/

@@ -869,3 +868,3 @@ Timestamp.TWO_PWR_64_DBL_ = Timestamp.TWO_PWR_32_DBL_ * Timestamp.TWO_PWR_32_DBL_;

* @type {number}
* @api private
* @ignore
*/

@@ -892,3 +891,3 @@ Timestamp.TWO_PWR_63_DBL_ = Timestamp.TWO_PWR_64_DBL_ / 2;

* @type {Timestamp}
* @api private
* @ignore
*/

@@ -900,2 +899,3 @@ Timestamp.TWO_PWR_24_ = Timestamp.fromInt(1 << 24);

*/
exports.Timestamp = Timestamp;
module.exports = Timestamp;
module.exports.Timestamp = Timestamp;
{ "name" : "bson"
, "description" : "A bson parser for node.js and the browser"
, "keywords" : ["mongodb", "bson", "parser"]
, "version" : "0.2.15"
, "version" : "0.2.16"
, "author" : "Christian Amor Kvalheim <christkv@gmail.com>"

@@ -6,0 +6,0 @@ , "contributors" : []

Javascript + C++ BSON parser
============================
This BSON parser is primarily meant for usage with the `mongodb` node.js driver. However thanks to such wonderful tools at `onejs` we are able to package up a BSON parser that will work in the browser aswell. The current build is located in the `browser_build/bson.js` file.
This BSON parser is primarily meant to be used with the `mongodb` node.js driver.
However, wonderful tools such as `onejs` can package up a BSON parser that will work in the browser.
The current build is located in the `browser_build/bson.js` file.
A simple example on how to use it
A simple example of how to use BSON in the browser:
<head>
<script src="https://raw.github.com/mongodb/js-bson/master/browser_build/bson.js">
</script>
</head>
<body onload="start();">
<script>
function start() {
var BSON = bson().BSON;
var Long = bson().Long;
```html
<html>
<head>
<script src="https://raw.github.com/mongodb/js-bson/master/browser_build/bson.js">
</script>
</head>
<body onload="start();">
<script>
function start() {
var BSON = bson().BSON;
var Long = bson().Long;
var doc = {long: Long.fromNumber(100)}
var doc = {long: Long.fromNumber(100)}
// Serialize a document
var data = BSON.serialize(doc, false, true, false);
// De serialize it again
var doc_2 = BSON.deserialize(data);
}
</script>
</body>
// Serialize a document
var data = BSON.serialize(doc, false, true, false);
// De serialize it again
var doc_2 = BSON.deserialize(data);
}
</script>
</body>
</html>
```
It's got two simple methods to use in your application.
A simple example of how to use BSON in `node.js`:
```javascript
var bson = require("bson");
var BSON = bson.BSONPure.BSON;
var Long = bson.BSONPure.Long;
var doc = {long: Long.fromNumber(100)}
// Serialize a document
var data = BSON.serialize(doc, false, true, false);
console.log("data:", data);
// Deserialize the resulting Buffer
var doc_2 = BSON.deserialize(data);
console.log("doc_2:", doc_2);
```
The API consists of two simple methods to serialize/deserialize objects to/from BSON format:
* BSON.serialize(object, checkKeys, asBuffer, serializeFunctions)

@@ -31,0 +55,0 @@ * @param {Object} object the Javascript object to serialize.

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc