bson-objectid
Advanced tools
Comparing version 2.0.3 to 2.0.4
@@ -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 [![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; | ||
}); | ||
}); |
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
New author
Supply chain riskA new npm collaborator published a version of the package for the first time. New collaborators are usually benign additions to a project, but do indicate a change to the security surface area of a package.
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
35248
524
1