uuid-generator

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:

Validating UUIDs

const uuid = '6a365c44-e127-11eb-b95f-cb258f9664de';
const isValid = UuidGenerator.validate(uuid);
console.log(isValid); // Output: true

Bulk Generation

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

const uuid = '6a365c44-e127-11eb-b95f-cb258f9664de';
const timestamp = UuidGenerator.extractTimestampV1(uuid);
console.log(timestamp); // Output: 1625765020000

Short UUID

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.