shortid 0.1.1

  • Readme
  • Changelog
  • Example
  • Installing
  • 77

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

  • By default 7-14 url-friendly characters: A-Z, a-z, 0-9, _-
  • Supports custom seeds, custom alphabet.
  • Can generate any number of ids without duplicates, even millions per day.
  • Good replacement for Mongo ID/Mongoose ID.
  • Includes tests.

ShortId does not generate cryptographically secure ids, so don't rely on it to make IDs which are impossible to guess.

Usage #

import 'package:shortid/shortid.dart';

// PPBqWA9


Returns string non-sequential unique id.


  _id: shortid.generate(),
  name: '...',
  email: '...'


Default: '0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ-_'

Returns new alphabet as a string

Recommendation: If you don't like _ or -, you can to set new characters to use.


Change the characters used.

You must provide a string of all 64 unique characters. Order is not important.

The default characters provided were selected because they are url safe.


// use $ and @ instead of - and _
// any 64 unicode characters work, but I wouldn't recommend this.


Default: 1

Recommendation: You typically won't want to change this.


Choose a unique value that will seed the random number generator so users won't be able to figure out the pattern of the unique ids. Call it just once in your application before using shortId and always use the same value in your application.

Most developers won't need to use this, it's mainly for testing ShortId.

If you are worried about users somehow decrypting the id then use it as a secret value for increased encryption.




  • corrected formatting
  • migrated library fron javascript


  • corrected formatting


import 'package:shortid/shortid.dart';

void main () {
  final id = shortid.generate();

Use this package as a library

1. Depend on it

Add this to your package's pubspec.yaml file:

  shortid: ^0.1.1

2. Install it

You can install packages from the command line:

with pub:

$ pub get

with Flutter:

$ flutter pub get

Alternatively, your editor might support pub get or flutter pub get. Check the docs for your editor to learn more.

3. Import it

Now in your Dart code, you can use:

import 'package:shortid/shortid.dart';
Describes how popular the package is relative to other packages. [more]
Code health derived from static analysis. [more]
Reflects how tidy and up-to-date the package is. [more]
Weighted score of the above. [more]
Learn more about scoring.

We analyzed this package on Mar 31, 2020, and provided a score, details, and suggestions below. Analysis was completed with status completed using:

  • Dart: 2.7.1
  • pana: 0.13.6

Health issues and suggestions

Document public APIs. (-1 points)

2 out of 2 API elements have no dartdoc comment.Providing good documentation for libraries, classes, functions, and other API elements improves code readability and helps developers find and use your API.

Fix lib/shortid.dart. (-0.50 points)

Analysis of lib/shortid.dart reported 1 hint:

line 41 col 20: Unnecessary new keyword.

Fix lib/src/alphabet.dart. (-0.50 points)

Analysis of lib/src/alphabet.dart reported 1 hint:

line 55 col 11: Unnecessary new keyword.

Fix lib/src/generate.dart. (-0.50 points)

Analysis of lib/src/generate.dart reported 1 hint:

line 10 col 15: Unnecessary new keyword.

Fix lib/src/random/random-byte.dart. (-0.50 points)

Analysis of lib/src/random/random-byte.dart reported 1 hint:

line 6 col 16: Unnecessary new keyword.

Maintenance suggestions

Package is getting outdated. (-42.74 points)

The package was last published 74 weeks ago.


Package Constraint Resolved Available
Direct dependencies
Dart SDK >=2.0.0 <3.0.0
Dev dependencies
test ^1.2.0