Home
Docs
GitHub
Pricing
Blog
Log In

Run Sandworm Audit for your App

Get started
Generated on May 27, 2024 via pnpm

shortid 2.2.16

Amazingly short non-sequential url-friendly unique id generator.
Package summary
Share
0
issues
1
license
2
MIT
Package created
19 Dec 2011
Version published
21 Oct 2020
Maintainers
2
Total deps
2
Direct deps
1
License
MIT

Issues

0
This package has no issues

Licenses

MIT License

Permissive
OSI Approved
This is a human-readable summary of (and not a substitute for) the license. Disclaimer.
Can
commercial-use
modify
distribute
sublicense
private-use
Cannot
hold-liable
Must
include-copyright
include-license
2 Packages, Including:
nanoid@2.1.11
shortid@2.2.16
Disclaimer

This deed highlights only some of the key features and terms of the actual license. It is not a license and has no legal value. You should carefully review all of the terms and conditions of the actual license before using the licensed material.

Sandworm is not a law firm and does not provide legal services. Distributing, displaying, or linking to this deed or the license that it summarizes does not create a lawyer-client or any other relationship.

Direct Dependencies

1
All Dependencies CSV
β“˜ This is a list of shortid 's direct dependencies. Data on all dependencies, including transitive ones, is available via CSV download.
NameVersionSizeLicenseTypeVulnerabilities
nanoid2.1.119.95 kBMIT
prod

Visualizations

Frequently Asked Questions

What does shortid do?

Shortid is an intrusive, non-sequential, and URL-friendly unique id generator optimized for Node.js. It promises to create IDs that are perfect for URL shorteners, MongoDB and Redis IDs, as well as any other ID users might encounter. The URI-friendly IDs generated usually consist of 7-14 characters, including the ranges 'A-Z', 'a-z', '0-9', and '_-'. While its architecture may not be fit for generating cryptographically secure IDs, it does an excellent job in most use cases, namely when creating game IDs, where predictability would foster cheating.

How do you use shortid?

To use Shortid in a JavaScript application, you simply import it using Node's require function, after which you can easily call the generate function to produce new unique IDs. Below are examples on how to use it:

// Importing shortid
const shortid = require('shortid');

// Generating a new id
console.log(shortid.generate()); // Outputs a short non-sequential url-friendly unique id e.g 'PPBqWA9'

Also, you can use it in conjunction with a popular ODM (Object Document Mapper) known as Mongoose to generate unique IDs for your documents like so:

_id: {
  'type': String,
  'default': shortid.generate
},

Further still, you can customize the characters used by Shortid by calling the characters function with a 64 unique character string parameter. For example:

shortid.characters('0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ$@');

Where are the shortid docs?

The Shortid documentation can be found directly on the package's GitHub page at https://github.com/dylang/shortid. You'll find a comprehensive rundown of the API and its functions, which will provide all you need to maximize the utility of the Shortid package.