Sign Up for Free

RunKit +

Try any Node.js package right in your browser

This is a playground to test code. It runs a full Node.js environment and already has all of npm’s 400,000 packages pre-installed, including objectid with all npm packages installed. Try it out:

var objectid = require("objectid")

This service is provided by RunKit and is not affiliated with npm, Inc or the package authors.

objectid v3.2.1

mongodb objectid utilities


mongodb objectid utilities


1.x is probably the version you want to use in a browser. 3.x focuses on compatibility with the npm mongodb driver.


$ npm install objectid


var objectid = require('objectid')

var id = objectid()

// => true

// => false

objectid.isValid returns true for mongodb native driver ObjectID objects, or any other representations with a .toString method which returns the hex string encoding of a valid objectid.

Calling objectid with an existing objectid - whether a string, an object created by this module, an objectid created by another driver (such as the result of a query) - will cast the value to an instanceof this module. It will throw if the argument is not a valid ObjectId.

Static Methods

ObjectId.equals(oidA, oidB) => Boolean

Curried to support creating equality predicates.

ObjectId.tryParse(oid, out, as) => Boolean

ObjectId.isValid(oid) => Boolean

Instance Methods

ObjectId#equals(oidB) => Boolean

ObjectId#toString() => String

ObjectId#toJSON() => String

running the tests

From package root:

$ npm install
$ npm test


jden @leJDen


MIT. (c) 2013 Agile Diagnosis See


RunKit is a free, in-browser JavaScript dev environment for prototyping Node.js code, with every npm package installed. Sign up to share your code.
Sign Up for Free