npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

node-time-uuid

v0.1.5

Published

Node module to generate globally unique, time sortable indentifiers that can be used as database unique IDs. The identifiers are time sortable and you can recover the time stamp of when they were created down to micro-second resolution. Time sortable iden

Downloads

233

Readme

node-time-uuid

Node module to generate globally unique, time sortable indentifiers that can be used as database unique IDs. The identifiers are time sortable and you can recover the time stamp of when they were created down to micro-second resolution. Time sortable identifiers can very useful in situations where you want to sort your objects by time, for instance messages in a user's inbox.

This module generates 15 byte IDs with the following format:

  • 32 bit time
  • 24 bit micro time
  • 24 bit machine id
  • 16 bit pid
  • 24 bit increment

Please note that the generated IDs are not standard UUID, or GUID.

Install

Simple installation with NPM

npm install node-time-uuid

Usage

var ObjectId = require("node-time-uuid");

var id = new ObjectId();

// get date from Id
var date = id.getDate();

// get timestamp from Id
var timestamp =  id.getTimestamp();

// get timestamp and microsecond time
var [timestamp, microseconds] = id.getTimeOfDay();

API

New Instance

ObjectId can be instanciated in several different ways:

var ObjectId = require("node-time-uuid");

// Create a new ID
var id = new ObjectId();

// Create an Object Id instance from existing Id encoded as a Hex string
var id = new ObjectId("512055ac09b8979d8fa1511f000002");

// Create an Object Id instance from existing Id encoded as base64 string
var id = new ObjectId("USBVrAm4l52PoVEfAAAC");

// Create an Object Id instance from existing Node buffer
var id = new ObjectId(buffer);

Supported encodings are hex, base64 and base64url

get()

Returns a 15 byte Node.js Buffer object with the Id.

var buffer = id.get();

toString(encoding)

Returns a string representation of ObjectId, according to the specified enconding. Supported encodings are hex, base64, base64url, pretty.

  • hex: 512055ac09b8979d8fa1511f000002
  • base64: USBVrAm4l52PoVEfAAAC
  • base64url: USBVrAm4l52PoVEfAAA-
  • pretty: 512055ac-09b897-9d8fa1-511f-000002

getTimestamp()

Get the unix timestamp from the ObjectId

var timestamp =  id.getTimestamp();

getTimeOfDay()

Get timestamp of the ObjectId in seconds and microseconds

var [timestamp, microseconds] = id.getTimeOfDay();

getDate()

Return Javascript Date() object from the ObjectId.

Testing

Tests require Node mocha and istanbul modules to be installed .

npm install mocha istanbul -g

To run all module tests simply run:

npm test

or

make test

To obtain a test coverage report run

npm cover

Then open ./html-report/index.html in your browser

#License

MIT License