1. scuid
Collision-resistant IDs optimized for horizontal scaling and performance
scuid
Package: scuid
Created by: jhermsmeier
Last modified: Sun, 26 Jun 2022 16:59:07 GMT
Version: 1.1.0
License: MIT
Downloads: 10,141,471
Repository: https://github.com/jhermsmeier/node-scuid

Install

npm install scuid
yarn add scuid

scuid

npm
npm license
npm downloads
build status

Collision-resistant IDs optimized for horizontal scaling and performance.

A slim, alternative, and compatible implementation of cuid for node,
also featuring a wide range of options, as well as custom random number generator support.
It can serve as a drop-in replacement, and is also faster than cuid.

Install via npm

 $ npm install --save scuid

Usage

 var scuid = require( 'scuid' )

Generate an ID

 var id = scuid()
> 'ciux3hs0x0000io10cusdm8r2'

Generate a slug

 var slug = scuid.slug()
> '6x1i0r0'

Get the process' fingerprint

 var fingerprint = scuid.fingerprint()
> 'io10'

Use a custom (P)RNG

 // Create a random number generator;
// It has to have a method called `random`
var generator = {
  random: function() {
    return 5 // chosen by fair dice roll
  }
}

// Create a custom scuid instance
var scuid = require( 'scuid' ).create({
  rng: generator
})

Use other custom options

Note that fiddeling with these might make your IDs incompatible with cuid's guarantees.

 var scuid = require( 'scuid' ).create({
  prefix: 'c', // the ID's prefix
  base: 36, // radix used in .toString() calls (2-36)
  blockSize: 4, // block size to pad and trim to
  fill: '0', // block padding character
  pid: process.pid, // process ID
  fingerprint: scuid.createFingerprint( [pid], [hostname] ), // Machine fingerprint
  rng: Math, // Random number generator
})

Tests

Just like cuid, collision resistance for both – slugs and IDs – is tested
over 1 million and 2 million iterations respectively.
To run the tests, run:

$ npm test

Benchmarks

$ npm run benchmark
scuid
  id ............................................. 573,618 op/s
  slug ........................................... 673,732 op/s
  fingerprint .................................... 131,156,394 op/s

cuid
  id ............................................. 445,260 op/s
  slug ........................................... 531,770 op/s
  fingerprint .................................... 125,159,685 op/s

RELATED POST

Enhancing Vue.js Development: Harnessing the Potential of Vue-Loader

Enhancing Vue.js Development: Harnessing the Potential of Vue-Loader

Simplify Data Validation in Vue.js: A Step-by-Step Guide to Using Regex

Simplify Data Validation in Vue.js: A Step-by-Step Guide to Using Regex

Troubleshooting Made Easy: Common Issues and Solutions with vue-loader Without vue-cli

Troubleshooting Made Easy: Common Issues and Solutions with vue-loader Without vue-cli

Optimizing Webpack 4 with Vue CLI 3: Disabling the Cache-Loader

Optimizing Webpack 4 with Vue CLI 3: Disabling the Cache-Loader

Step-by-Step Guide: How to Add a Function to Your Vuex Plugin

Step-by-Step Guide: How to Add a Function to Your Vuex Plugin