Skip to content
SMAKSSPublic

Latest commit

 

History

88 Commits

Folders and files

NameName
Last commit message
Last commit date
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

UUID

npm NPM npm npm unpacked size

In order to create a unique identifier, it's common to use a UUID (Universally Unique Identifier). This package generates a version 4 UUID compliant with RFC 4122 standards using pure JavaScript. The codebase for this project is inspired by the collective wisdom of the StackOverflow community.

UUIDs use the Web Crypto API by default. If secure randomness is unavailable, generation throws instead of silently falling back to predictable values. Passing false to uuid(false) opts into Math.random() and should only be used for non-security-sensitive identifiers.

Node.js 20 or later is required. In browsers, the Web Crypto API must be available.

Demo

Check out the working demo on CodeSandbox:

View @smakss/uuid

How it works?

Install the package using npm or pnpm:

npm install @smakss/uuid
# or
pnpm add @smakss/uuid

For CommonJS modules, include it like this:

const { default: uuid } = require('@smakss/uuid');

For ECMAScript modules, import it as follows:

import uuid from '@smakss/uuid';

Then, you can use it within your application like this:

// Generate a new UUID using cryptographic randomness
const uniqueID = uuid();
console.log(uniqueID); // Outputs: '123e4567-e89b-12d3-a456-426614174000' (example output)

NOTE: Each call to uuid() generates a new UUID. Secure randomness requires the Web Crypto API.

Contributing

Interested in contributing to this project? Please see CONTRIBUTING.md for guidelines and details.

Code of Conduct

To ensure a welcoming and positive experience for all contributors and users, we adhere to a Code of Conduct. Your cooperation is appreciated.

Local playground

This repository includes a Vite playground linked to the package through the pnpm workspace. Try the current local build without publishing a package version:

pnpm install
pnpm run dev:playground

To build the playground app, run this from the package root:

pnpm run build:playground

Releases

Packages

Used by

Contributors

Languages