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

@levihub/uuid

v1.0.2

Published

Lightweight UUID generator.

Downloads

3

Readme

Welcome to UUID 👋

UUID.js is a simple and lightweight JavaScript library for generating universally unique identifiers (UUIDs).

It provides an easy and efficient way to create unique identifiers for various applications.

Whether you're working in a Node.js environment or embedding it directly in your HTML with a script tag, UUID.js is a straightforward solution for generating UUIDs.

Table of Contents

Features

  • Generate UUIDs
  • If needed, recycle or reuse any UUID
  • Set the character set for your UUIDs
  • Limit the maximum amount of UUIDs to generate
  • Check how many UUIDs are you using or available
  • Check the UUIDs available
  • Simple and lightweight
  • Easy to install and use

Installation

Installing the UUID generator in your application is as simple as it should be.

Depending on what you work with or what you need, we have different installation methods.

Install with npm

npm i @levihub/uuid

As an inline script (browser)

<script src="https://uuid.levihub.dev/dist/uuid.js"></script>

As a module (browser)

import UUID from "https://uuid.levihub.dev/dist/uuid.mjs";

Usage/Examples

Import (Node only)

Once installed with npm package manager, you need to import the package in order to use it.

const UUID = require("@levihub/uuid"); // Common JS
// or 
import UUID from "@levihub/uuid"; // ES Modules

Create a new instance

For using the UUID class, you have to create an instance of it first.

const generator = new UUID();

Generate new UUID

var userId = generator.newUUID();

Recycle/Reuse an existing UUID

From the moment you pass the generated UUID back to the generator to reuse it again, the generator push it into a list of unused UUIDs.

This list will have priority over creating new UUIDs.

generator.reuse(uuidToReuse);

A more detailed example:

const generator = new UUID();

var first = generator.newUUID(); // returns 0
var second = generator.newUUID(); // returns 1

// we push an UUID to a list of unused UUIDs
generator.reuse(first); // tells the generator that "first" UUID is available

// we generate a "new" one (the recycled one comes first)
var reused = generator.newUUID(); // returns 0 (the "first" UUID)

// we generate another one (the unused list is empty)
var next = generator.newUUID(); // returns 2 (we get the next one)

Check total used and unused UUIDs

You can check how many UUIDs do you have in use by the generator or how many are available to reuse. You can check too the UUIDs that are waiting to be reused. (If there is any)

generator.totalUsed; // returns total UUIDs used
generator.totalUnused; // returns total UUIDs available to reuse
generator.unusedUUIDs; // returns the list of reusable UUIDs

Changing the character set and limit for generating UUIDs

You can specify the set of characters for generating UUIDs.

generator.charSet = [ "A", "B", "C" ];

You can also set a limit to how many UUIDs you want to generate.

generator.limit = 50;

A more detailed example:

generator.charSet = [ "A", "k" ]; // UUIDs will have only "A" and "k" characters
generator.limit = 50; // it will not generate more than 50 UUIDs

for (let i = 0; i < 100; i++) { // we try to generate 100 UUIDs
  let id = generator.newUUID(); // returns string or false 

  if (id) { // if it is NOT false (an UUID has been generated)
    console.log(`The UUID '${id}' has been generated.`);
  } else { // if it is false (UUID has not been generated)
    console.log(`${generator.totalUsed} UUIDs generated. Limit reached.`);
    break;
  }
}