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

id-shorter

v0.1.2

Published

A little module that replaces a long ObjectId value with short one keeping uniqueness. A charset for conversion is fully configurable and does not depend on requirement of 64 symbols. So it is possible to use only letters, letters+digits, digits etc.

Downloads

1,777

Readme

Short MongoDB ObjectId

Generate short id's from MongoDB Object ID's for use in url's or other applications.

The module can be used in few modes. You can configure a generation of very short ids based on mongoDB ObjectIds using only timestamp + counter and dropping machine id and process id. In this case a reverse operation is not possible. There is also a way to generate absolute indentical ids that include machine id and process id. This is a reversible conversion.

You can use and configure any set of characters for generation. The most problem of similar modules is a requirement of charset with length of power of 2. This module is free from this limitation. It is very useful for generation short urls based on charset of only digits and letters.

Install

Use NPM:

$ npm install id-shorter

or Git:

$ git clone [email protected]:AHgPuK/id-shorter.git

Use as MongoDB ObjectId very short shorter (id made of [a-zA-Z0-9])

var ShortId = require('id-shorter');
var mongoDBShortId = ShortId();
var shortId = mongoDBShortId.encode('565ffd0edf3d990540b3134c');

Result: 48yD4jA45

Use as MongoDB ObjectId reversible shorter (id made of [a-zA-Z0-9])

var ShortId = require('id-shorter');
var mongoDBId = ShortId({
	isFullId: true
});
var shortId = mongoDBId.encode('565ffd0edf3d990540b3134c');

Result: cdNI0lgCZ0YJ3Z0Z2Bl

Use as decoder from reversible id (id made of [a-zA-Z0-9])

var ShortId = require('id-shorter');
var mongoDBId = ShortId({
	isFullId: true
});
var shortId = mongoDBId.decode('cdNI0lgCZ0YJ3Z0Z2Bl');

Result: 565ffd0edf3d990540b3134c

Use as BINARY to HEX converter (extreme usage :)

var ShortId = require('id-shorter');
var Bin2Hex = ShortId({
	base: '01',
	encoding: '0123456789abcdef',
	isInverse: false,
	isFullId: true,
});
var result = Bin2Hex.encode('0000000100100011010001010110011110001001101010111100110111101111');

Result: 0123456789abcdef

License

MIT (see License)