New Case Study:See how Anthropic automated 95% of dependency reviews with Socket.Learn More
Socket
Sign inDemoInstall
Socket

objectid

Package Overview
Dependencies
Maintainers
1
Versions
11
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

objectid

generate and validate mongodb objectId strings without dependencies

  • 2.2.0
  • Source
  • npm
  • Socket score

Version published
Weekly downloads
3.8K
increased by24.5%
Maintainers
1
Weekly downloads
 
Created
Source

objectid

generate and validate mongodb objectId strings without dependencies

about

one of the best parts about using objectIds in mongodb is being able to generate them at object creation time, rather than at database insert time. This module is super convenient for code when you don't want the full mongodb driver as a dependency, for example, for use with browserify.

New in 2.x, this module returns objects with the _bsontype property set properly to be treated as BSON ObjectIDs, eg, for use in the native driver.

installation

$ npm install objectid

usage

var objectid = require('objectid')

var id = objectid()

objectid.isValid(id)
// => true

objectid.isValid('4frsdef43wzx')
// => 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

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

contributors

jden jason@denizac.org @leJDen

license

MIT. (c) 2013 Agile Diagnosis hello@agilediagnosis.com See LICENSE.md

Keywords

FAQs

Package last updated on 26 Mar 2013

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

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