Socket
Socket
Sign inDemoInstall

di-short-mongo-id

Package Overview
Dependencies
1
Maintainers
1
Versions
2
Alerts
File Explorer

Advanced tools

Install Socket

Detect and block malicious and high-risk dependencies

Install

di-short-mongo-id

Short id generation from MongoDB ObjectId's


Version published
Maintainers
1
Weekly downloads
208
increased by13.04%
Bundle size
14.2 kB
Minified + gzipped

Weekly downloads

Readme

Source

Short Mongo Id

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

Id's are generated from the timestamp and counter of the MongoDB Id, with some slight variation. They should be reasonably unique.

This is, unfortunately, a one-way function. It will reliably produce the same short id for the same MongoDB Id, but the operation can't be reversed (it is missing information about the machine id, process id, and most of the counter).

Install

Use NPM:

$ npm i -S di-short-mongo-id

Use

Pass a MongoDB ObjectId (or a string that can be converted to one) and it will return a reasonably unique short id.

const shortId = require('di-short-mongo-id');

shortId("597b3ae1bca3cc7f2c33128e"); // returns "wrxtm4nb"
shortId("597b3afabca3cc7f2c331290"); // returns "87qum4nb"
shortId("597b3afabca3cc7f2c331290", true); // returns "87QUM4NB"

License

MIT (see License)

Keywords

FAQs

Last updated on 28 Jul 2017

Did you know?

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

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc