Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

bson-objectid

Package Overview
Dependencies
Maintainers
3
Versions
23
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

bson-objectid - npm Package Compare versions

Comparing version 2.0.3 to 2.0.4

20

objectid.js

@@ -5,2 +5,6 @@

var pid = (typeof process === 'undefined' || typeof process.pid !== 'number' ? Math.floor(Math.random() * 100000) : process.pid) % 0xFFFF;
// <https://github.com/williamkapke/bson-objectid/pull/51>
// Attempt to fallback Buffer if _Buffer is undefined (e.g. for Node.js).
// Worst case fallback to null and handle with null checking before using.
var BufferCtr = (() => { try { return _Buffer; }catch(_){ try{ return Buffer; }catch(_){ return null; } } })();

@@ -148,12 +152,16 @@ /**

// <https://github.com/williamkapke/bson-objectid/issues/53>
if (isBuffer(id)) {
return true;
return ObjectID.isValid(id.toString('hex'));
}
// Duck-Typing detection of ObjectId like objects
if (
typeof id.toHexString === 'function' &&
(id.id instanceof _Buffer || typeof id.id === 'string')
) {
return id.id.length === 12 || (id.id.length === 24 && checkForHexRegExp.test(id.id));
// <https://github.com/williamkapke/bson-objectid/pull/51>
if (typeof id.toHexString === 'function') {
if(
BufferCtr &&
(id.id instanceof BufferCtr || typeof id.id === 'string')
) {
return id.id.length === 12 || (id.id.length === 24 && checkForHexRegExp.test(id.id));
}
}

@@ -160,0 +168,0 @@

{
"name": "bson-objectid",
"version": "2.0.3",
"version": "2.0.4",
"description": "Construct ObjectIDs without the mongodb driver or bson module",

@@ -5,0 +5,0 @@ "main": "objectid.js",

@@ -9,3 +9,3 @@ BSON ObjectID &nbsp;[![Build Status](https://travis-ci.org/williamkapke/bson-objectid.svg?branch=master)](https://travis-ci.org/williamkapke/bson-objectid)

The goal is to be 100% compatable with all [bson](https://github.com/mongodb/js-bson)'s
public API implementation (found here: https://github.com/mongodb/js-bson/blob/master/lib/objectid.js).
public API implementation (found here: https://github.com/mongodb/js-bson/blob/main/src/objectid.ts).

@@ -12,0 +12,0 @@ ## Install

@@ -33,2 +33,7 @@

it("should not be valid with invalid buffer", function() {
var buffer = Buffer.from('hello');
ObjectID.isValid(buffer).should.not.be.ok;
});
it("should construct with a `hexString` argument", function() {

@@ -133,2 +138,7 @@ var hexString = "54495ad94c934721ede76d90";

});
it("should use Buffer when _Buffer is undefined", function() {
var obj = { id: Buffer.from("54495ad94c934721ede76d90"), toHexString: () => "" };
ObjectID.isValid(obj).should.be.true;
});
});
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