Socket
Socket
Sign inDemoInstall

scuid

Package Overview
Dependencies
0
Maintainers
1
Versions
3
Alerts
File Explorer

Advanced tools

Install Socket

Detect and block malicious and high-risk dependencies

Install

    scuid

Collision-resistant IDs optimized for horizontal scaling and performance


Version published
Weekly downloads
2.3M
decreased by-0.04%
Maintainers
1
Install size
9.64 kB
Created
Weekly downloads
 

Package description

What is scuid?

The scuid npm package is designed to generate short, collision-resistant, URL-friendly unique identifiers. These identifiers are suitable for use where a unique string is necessary, such as database keys, component ids, or any other unique element identifier in a distributed system.

What are scuid's main functionalities?

Generating a unique identifier

This feature allows the generation of a unique identifier string that is URL-friendly and highly unlikely to collide with other generated identifiers.

"const scuid = require('scuid');
const id = scuid();
console.log(id); // Outputs a unique identifier string"

Generating a unique identifier with a custom prefix

This feature allows the generation of a unique identifier with a custom prefix, which can be useful for namespacing or categorizing identifiers.

"const scuid = require('scuid');
const idWithPrefix = scuid('usr_');
console.log(idWithPrefix); // Outputs a unique identifier string with 'usr_' prefix"

Other packages similar to scuid

Readme

Source

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

Keywords

FAQs

Last updated on 04 Feb 2018

Did you know?

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

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc