To create a random UUID...
1. Install
This is a javascript module available through the npm and yarn registry.
$ npm install @itxhamza/uuid
or
$ yarn add @itxhamza/uuid
2. Create a UUID (ES6 module syntax)
import { uuid, NILL } from "@itxhamza/uuid";
uuid(); // ⇨ '9b1deb4d-3b7d-4bad-9bdd-2b0d7b3dcb6d'
NILL; // ⇨ 'xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxx'
... or using CommonJS syntax:
const { uuid } = require("@itxhamza/uuid");
uuid(); // ⇨ '1b9d6bcd-bbfd-4b2d-9b5d-ab8dfbbd4bed'
3. Create a UUID with custom mask
import { uuid } from "@itxhamza/uuid";
uuid("xxxx-xxxx"); // ⇨ '9b1d-eb4d'
uuid("xx-xxxxxxxxxx"); // ⇨ '57-1801edd0ac'