npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

rand-uid

v1.0.2

Published

Generate Random ID's. Also Modify as You Like.

Downloads

34

Readme

Random ID Generator

npm version license NPM Downloads NPM Unpacked Size NPM Collaborators

A simple and lightweight library to generate random IDs.

Installation

You can install the rand-uid package via npm:

npm install rand-uid

Imports

import { randomUid } from "rand-uid";

Basic Usage

// Generate a random ID
const id = randomUid();
console.log(id); // 4WbMU-hWwwL-6ygny-ryd9v-pFNgn

// Others
console.log(randomUid({ variant: "number" })); // 98966-20008-31150-43572-53051
console.log(randomUid({ variant: "character" })); // UHbOK-UIlPy-lrlhV-hUuRb-TVzfd
console.log(randomUid({ charCase: "upper" })); // 9X1WV-OEQ99-COC7P-TY4IH-5MMGS
console.log(randomUid({ charCase: "lower" })); // wxczs-5nndb-foqxg-wb0qe-lrj72
console.log(randomUid({ prefix: "UID-" })); // UID-Tvh55-bm1t1-uRdjg-HBjEq-yI4Eu

Custom Usages

randomUid(options): string - options are Optional

Options

The function accepts the following options:

  • separator: The character used to separate parts of the UID (default: "-").

  • sectionLength: The length of each section/part of the UID (default: 5).

  • totalSection: The total number of section/parts in the UID (default: 5).

  • prefix: A string to prepend to the generated UID (default: "").

  • variant: The type of characters to include in the UID. Options are "number", "character", or "mixed" (default: "mixed").

  • charCase: The case of characters in the UID. Options are "lower", "upper", or "mixed" (default: "mixed").


Options {}

const options = {
    separator = "-",
    sectionLength = 5,
    totalSection = 5,
    prefix = "",
    variant = "mixed",
    charCase = "mixed",
  }

Example:

separator

const uid_1 = randomUid({ separator: "_" });
console.log(uid_1); // Gk3IS_9E9Su_6EDgP_rcvGR_PTRiX

const uid_2 = randomUid({ separator: "___" });
console.log(uid_2); // iUZSl___7iyZM___2hc4l___7plX0___cq0q0

const uid_3 = randomUid({ separator: "_", variant: "number" });
console.log(uid_3); // 37961_59202_78555_73383_28752

sectionLength

const uid_1 = randomUid({ separator: "_", sectionLength: 8 });
console.log(uid_1); // 7Fqt565l_mDCyja3F_SdIKc58f_fmAhw8aU_3eE5t7Sz

const uid_2 = randomUid({ sectionLength: 4, variant: "number" });
console.log(uid_2); // 9189-9363-0056-5744-1965

const uid_3 = randomUid({ sectionLength: 8, variant: "character" });
console.log(uid_3); // jEfYCpAK-HccEBOnz-FhTYyfrH-lzTkSHVP-dAEIeRqG

totalSection

const uid = randomUid({ totalSection: 8 });
console.log(uid); // E3djC-N7OWe-b153F-bXrK1-UPyCG-SX2f4-4Ix6A-V877H

prefix

const uid = randomUid({ prefix: "ID-" });
console.log(uid); // ID-X1opz-qv2pz-GYvy4-4iNuu-bSu6i

variant

// variant: 'number' - only number
const numberId = randomUid({ variant: "number" });
console.log(numberId); // 71274-43697-36242-77585-38443

// variant: 'character' - only character
const characterId = randomUid({ variant: "character" });
console.log(characterId); // QlupI-YZFcZ-HOfIx-OgdpL-oamML

// variant: 'mixed' - default
const mixedId = randomUid({ variant: "mixed" });
console.log(mixedId); // WDIEd-o3Imp-ksb5Z-gb6zG-KfdRb

charCase

// charCase: 'upper' - all uppercase
const upperUid = randomUid({ charCase: "upper" });
console.log(upperUid); // MBXIM-DG7OI-M17SS-TX2FT-DSDJM

// charCase: 'lower' - all lowercase
const lowerUid = randomUid({ charCase: "lower" });
console.log(lowerUid); // 6ens0-pvqvo-weipp-rqk8n-3sd1p

// charCase: 'mixed' - default
const mixedUid = randomUid({ charCase: "mixed" });
console.log(mixedUid); // nWYmq-YWwVQ-7Gkup-FpO30-rQrAz

short-id

// way - 1
const shortId_1 = randomUid({ sectionLength: 16, totalSection: 1 });
console.log(shortId_1); // mdO4p0aJJag8U5Ao

// another
const shortId_2 = randomUid({ sectionLength: 8, totalSection: 1 });
console.log(shortId_2); // g7MZ3llc

// way - 2
const shortId_3 = randomUid({
  sectionLength: 1,
  totalSection: 16,
  separator: "",
});
console.log(shortId_3); // H6r9IDnpU7Vsvj3Q

// way - 3
const shortId_4 = randomUid({ separator: "" });
console.log(shortId_4); // WOVL4UlrLlo1Pzra68gIihbdY

// way - 4 : number
const shortId_5 = randomUid({
  sectionLength: 10,
  totalSection: 1,
  variant: "number",
});
console.log(shortId_5); // 7948612351

The options args: object [property]:[value]

| Property | Description | Value | Default Value | | ------------------------------- | -------------------------------------------------------- | --------------------------------------- | ------------- | | separator | The character used to separate sections/parts of the UID | string | "-" | | sectionLength | The length of each section/part of the UID | number | 5 | | totalSection | The total number of sections/parts in the UID | number | 5 | | prefix | A string to prepend to the generated UID | string | "" | | variant | The type of characters to include in the UID | "number", "character" and "mixed" | "mixed" | | charCase | The case of characters in the UID | "upper", "lower" and "mixed" | "mixed" |

Follow on GitHub