Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

shortid

Package Overview
Dependencies
Maintainers
1
Versions
31
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

shortid

Amazingly short non-sequential url-friendly unique id generator.

  • 1.0.9
  • Source
  • npm
  • Socket score

Version published
Weekly downloads
467K
decreased by-44.81%
Maintainers
1
Weekly downloads
 
Created
Source

ShortId Build Status

ShortId creates amazingly short non-sequential url-friendly unique ids. Perfect for url shorteners, MongoDB and Reddis ids, and any other id users might see.

  • 7-12 url-friendly characters: A-Za-z_-
  • Non-sequential so they are not predictable.
  • Shuffled alphabet based on an optional seed you provide so others can't decrypt your ids.
  • Includes version in case you want to change how you encode your id.
  • Includes cluster worker id so you can use on node instances running using Cluster.
  • Includes tests that run on Mocha.
  • Requires Node 0.6 because it uses Node's new crypto functions.

Example

    var ShortId = require('../index');
    var i = 10;
    while (i--) {
        console.log(ShortId.generate());
    }
    
    // Resulting ids:
    PPBqWA9
    PefBO4A
    eV9B94A
    eemGO4d
    PPGBqhd
    VPyX9hw
    eeDX94w
    PT7GOWA
    PP4XqWA
    PTxG9hD

API

ShortId.generate()

Returns an amazingly short non-sequential unique id.

Other functions

(Full docs coming soon.)

  • ShortId.version(int) sets version, returns ShortId module.
  • ShortId.worker(int) sets cluster worker, returns ShortId module.

See the tests for more examples.

Created for Node Knockout 2011 winner Doodle Or Die.

Note

Tests current disabled:

"scripts":{
    "test": "make test"
},

Keywords

FAQs

Package last updated on 07 Aug 2012

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

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc