Sudoo-UUID

Continuous Integration codecov npm version downloads

UUID for JS

Install

yarn add @sudoo/uuid
# Or
npm install @sudoo/uuid --save

Usage

Generate Version 1 UUID

import { UUID, UUIDVersion1 } from "@sudoo/uuid";

const stringUUID: string = UUIDVersion1.generateString(); // xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx
const stringUUID: string = UUIDVersion1.generateString(new Date()); // Override time stamp

const uuid: UUID = UUIDVersion1.generate(); // Instance
const uuid: UUID = UUIDVersion1.generate(new Date()); // Override time stamp
uuid.toString(); // xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx
uuid.toBraceString(): // {xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx}
uuid.toUnifiedResourceString(): // urn:uuid:xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx

Generate Version 4 UUID

import { UUID, UUIDVersion4 } from "@sudoo/uuid";

const stringUUID: string = UUIDVersion4.generateString(); // xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx

const uuid: UUID = UUIDVersion4.generate(); // Instance
uuid.toString(); // xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx
uuid.toBraceString(): // {xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx}
uuid.toUnifiedResourceString(): // urn:uuid:xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx