Skip to content
This repository has been archived by the owner on Dec 19, 2023. It is now read-only.

Fixed issue #30 #1

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
24 changes: 12 additions & 12 deletions objectid.js
Original file line number Diff line number Diff line change
Expand Up @@ -26,24 +26,24 @@ var isBuffer = function (obj) {
* @param {String|Number} arg Can be a 24 byte hex string, 12 byte binary string or a Number.
* @return {Object} instance of ObjectID.
*/
function ObjectID(arg) {
if(!(this instanceof ObjectID)) return new ObjectID(arg);
if(arg && ((arg instanceof ObjectID) || arg._bsontype==="ObjectID"))
return arg;

function ObjectID(id) {
if(!(this instanceof ObjectID)) return new ObjectID(id);
if(id && (id instanceof ObjectID))
return id;
var buf;

if(isBuffer(arg) || (Array.isArray(arg) && arg.length===12)) {
buf = Array.prototype.slice.call(arg);
if(isBuffer(id) || (Array.isArray(id) && id.length===12)) {
buf = Array.prototype.slice.call(id);
}
else if(typeof arg === "string") {
if(arg.length!==12 && !ObjectID.isValid(arg))
else if(typeof id === "string") {
if(id.length!==12 && !ObjectID.isValid(id))
throw new Error("Argument passed in must be a single String of 12 bytes or a string of 24 hex characters");

buf = buffer(arg);
buf = buffer(id);
}
else if(/number|undefined/.test(typeof arg)) {
buf = buffer(generate(arg));
else if(/number|undefined/.test(typeof id)) {
buf = buffer(generate(id));
}

Object.defineProperty(this, "id", {
Expand Down
24 changes: 12 additions & 12 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.