Generate Random Or Sequential UUIDs With Short Unique ID Library

Category: Javascript | September 24, 2023
Author:simplyhexagonal
Views Total:47 views
Official Page:Go to website
Last Update:September 24, 2023
License:MIT

Preview:

Generate Random Or Sequential UUIDs With Short Unique ID Library

Description:

Short Unique ID is a lightweight and efficient JavaScript library for generating unique, collision-resistant, random or sequential IDs.

Useful for generating UUIDs for databases, objects, DOM elements, tracking, URLs, and many other applications.

How to use it:

1. Install & download.

# NPM
$ npm i short-unique-id

2. There are several ways to import short-unique-id into your project depending on your environment.

// ES Module
import ShortUniqueId from 'short-unique-id';
// Node.js
const ShortUniqueId = require('short-unique-id');
// Browser
<script src="/dist/short-unique-id.min.js"></script>

3. Initialize the ShortUniqueId.

const uid = new ShortUniqueId();

4. Generate random ID.

uid.rnd();
// OR
const { randomUUID } = new ShortUniqueId();
randomUUID();

5. Generate sequential ID.

uid.seq();
// OR
const { sequentialUUID } = new ShortUniqueId();
sequentialUUID();

6. Available options.

const uid = new ShortUniqueId({
      // User-defined character dictionary
      dictionary: ['z', 'a', 'p', 'h', 'o', 'd', ...],
      // If true, sequentialUUID use the dictionary in the given order
      shuffle: false,
      // Shows debug info
      debug: false,
      // ID length
      length: 6,
      
});

Changelog:

v5.0.3 (09/24/2023)

  • fix: add rnd to suid cli

You Might Be Interested In:


Leave a Reply