New Research: Supply Chain Attack on Axios Pulls Malicious Dependency from npm.Details →
Socket
Book a DemoSign in
Socket

mongo-objectid

Package Overview
Dependencies
Maintainers
1
Versions
5
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

mongo-objectid

A MongoDB specification based implementation of ObjectID

latest
Source
npmnpm
Version
1.2.2
Version published
Weekly downloads
689
25.05%
Maintainers
1
Weekly downloads
 
Created
Source

Mongo-ObjectID

NPM Version Build Status

A MongoDB specification based implementation of ObjectID

Goal is to provide a correct MongoDB ObjectID implementation, in order to ensure impossibility to create similar entries on fast generation (as saw on other open source package)

Table of Contents

Installation

npm install mongo-objectid

Usage

mkdir myproject
cd myproject
npm init
npm install mongo-objectid
touch index.js

And there just use that snipets to start playing ! :

const ObjectId = require('mongo-objectid');
const id = new ObjectId();

Documentation

API

constructor([hexid])

toString()

Returns the ID

.isValid()

Validate the ID against specification.

.setMachineId([machineId])

This will set a new machine id and regenerate new id (careful, timevalue also change with this process).

  • machineId : optional - Allow to pass a specific machine id value;

.generateNew([time])

Allow to generate a new ID

  • time : default : Date.now() - Allow to pass a specific time value

.getDate()

Return the Date object corresponding to the time of the ObjectID creation

.getTimestamp()

Return the timestamp in ms corresponding to the time of ObjectID creation

FAQ :

Why node engine v.12 limitation

For development purpose, I decided that being able to console view the object without all the nested parent thing was handy a clean.
That's the only reason. But Node V.12 is old enough already, no point sticking to the past.

Keywords

mongodb

FAQs

Package last updated on 23 Jan 2021

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