Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/junosuarez/objectid
node module: generate and validate mongodb objectId strings without dependencies
https://github.com/junosuarez/objectid
Last synced: 6 days ago
JSON representation
node module: generate and validate mongodb objectId strings without dependencies
- Host: GitHub
- URL: https://github.com/junosuarez/objectid
- Owner: junosuarez
- License: mit
- Created: 2013-02-05T04:04:44.000Z (almost 12 years ago)
- Default Branch: master
- Last Pushed: 2021-04-20T19:18:17.000Z (over 3 years ago)
- Last Synced: 2024-04-28T03:54:59.206Z (7 months ago)
- Language: JavaScript
- Size: 154 KB
- Stars: 22
- Watchers: 7
- Forks: 9
- Open Issues: 5
-
Metadata Files:
- Readme: README.md
- License: LICENSE.md
Awesome Lists containing this project
README
# objectid
mongodb objectid utilities## about
1.x is probably the version you want to use in a browser. 3.x focuses on compatibility with the npm `mongodb` driver.
## installation
$ npm install objectid
## usage
var objectid = require('objectid')
var id = objectid()
objectid.isValid(id)
// => trueobjectid.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
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## contributors
jden @leJDen
## license
MIT. (c) 2013 Agile Diagnosis See LICENSE.md