Important: This documentation covers Yarn 1 (Classic).
For Yarn 2+ docs and migration guide, see yarnpkg.com.

Package detail

generate-random-id

ravvis5ISC0.0.3

A random id generator function

random-id, nodejs, random-number

readme

generate-random-id

A random ID generator function.

Usage

import generateRandomId from "generate-random-id";

const options = {
  length: 12,
  set: "123456789"
}

const user = {
  name: "John Doe",
  userId: generateRandomId(options),
  isActive: true
}

DatabaseService.saveUser(user);

Params

generateRandomId accepts one param options an object with all the configurable options.

options

Range of options that can be passed to the generator function.

length

Definition: An integer signifying the length of the ID to produce.

Default: 7

set

Definition: A string of all the characters to use to produce an ID.

Default: "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789"