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

uuid-wand

v1.0.3

Published

A UUID generator library for TypeScript

Downloads

157

Readme

UUID Wand

UUID Wand is a TypeScript library that provides functionality to generate and validate UUIDs (Universally Unique Identifiers).

Docs

Table of Contents

Installation

To use this library in your project, make sure you have Node.js installed. Follow the steps below to install and use the library:

  1. Clone the repository or download the source code files.

  2. Install the required dependencies by running the following command in the project directory:

    npm install uuid-wand
    yarn add uuid-wand
    pnpm add uuid-wand
  3. Import the UuidGenerator class into your TypeScript file:

    import UuidGenerator from 'uuid-wand';

Usage

Generating UUIDs

The UuidGenerator class provides four methods for generating UUIDs:

  • v1(): Generates a version 1 UUID using the current timestamp, clock sequence, and node ID.

    const uuidV1 = UuidGenerator.v1();
    console.log(uuidV1); // Output: e.g., '6a365c44-e127-11eb-b95f-cb258f9664de'
  • v3(namespace: string, name: string): Generates a version 3 UUID using the provided namespace and name.

    const uuidV3 = UuidGenerator.v3(
      '6ba7b810-9dad-11d1-80b4-00c04fd430c8',
      'Hello, World!',
    );
    console.log(uuidV3); // Output: e.g., '2ed6657d-e927-568b-95e1-2665a8aea6a2'
  • v4(): Generates a version 4 UUID using random values.

    const uuidV4 = UuidGenerator.v4();
    console.log(uuidV4); // Output: e.g., 'd6e3c7b6-8e47-4a3c-a31c-78168d0b96cd'
  • v5(namespace: string, name: string): Generates a version 5 UUID using the provided namespace and name.

    const uuidV5 = UuidGenerator.v5(
      '6ba7b811-9dad-11d1-80b4-00c04fd430c8',
      'Hello, World!',
    );
    console.log(uuidV5); // Output: e.g., '886313e1-3b8a-5372-9b90-0c9aee199e5d'

Validating UUIDs

  • The validate() method can be used to check if a given string is a valid UUID.
const uuid = '6a365c44-e127-11eb-b95f-cb258f9664de';
const isValid = UuidGenerator.validate(uuid);
console.log(isValid); // Output: true

Bulk Generation

  • The method bulkGenerateV4 takes an integer count as an argument and returns an array of version 4 UUIDs.
const uuids = UuidGenerator.bulkGenerateV4(5);
console.log(uuids);
// Output:
// [
//   'd6e3c7h6-8e47-4a3c-a31c-78168d0b96jd',
//   'd6e3c7b6-8h47-4a3c-a31c-78168d0b96ca',
//   'd6e3c7b6-8347-4g3c-a31c-78168d0b96cq',
//   'd6e3c7b6-8e47-4d3c-a31c-78168d0b96cj',
//   'd6e3c7b6-8e47-4a3c-b31c-78168d0b96cl'

Timestamp Retrieval

  • The method extractTimestampV1 extracts the timestamp from a version 1 UUID string. It returns the timestamp as a number or null if the UUID is not valid or not a version 1 UUID. The extraction logic relies on bit manipulation and should be fairly efficient.
const uuid = '6a365c44-e127-11eb-b95f-cb258f9664de';
const timestamp = UuidGenerator.extractTimestampV1(uuid);
console.log(timestamp); // Output: 1625765020000

Short UUID

  • The method shortUuid creates a shorter, URL-friendly UUID by generating a version 4 UUID, hashing it with MD5, and then encoding it using base64. Any characters not safe for URLs are replaced.
const shortUuid = UuidGenerator.shortUuid();
console.log(shortUuid); // Output: '1b9d6bcd-bbfd-4b2d-9b5d-ab8dfbbd4bed'

License

This library is released under the MIT License. Feel free to modify and use it in your projects.