Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

uuidv4

Package Overview
Dependencies
Maintainers
5
Versions
39
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

uuidv4

uuid creates UUIDs.

  • 6.0.0
  • Source
  • npm
  • Socket score

Version published
Weekly downloads
457K
increased by3.54%
Maintainers
5
Weekly downloads
 
Created
Source

uuid

uuid creates v4 UUIDs.

Status

CategoryStatus
Versionnpm
DependenciesDavid
Dev dependenciesDavid
BuildCircleCI
LicenseGitHub

Installation

$ npm install uuidv4

Quick start

First you need to integrate uuidv4 into your project by using the require function:

const { uuid } = require('uuidv4');

If you use TypeScript, use the following code instead:

import { uuid } from 'uuidv4';

Then you can create UUIDs. To do so simply call the uuid function:

console.log(uuid());
// => '11bf5b37-e0b8-42e0-8dcf-dc8c4aefc000'

Verifying a UUID

To verify whether a given value is a UUID, use the isUuid function:

import { isUuid } from 'uuidv4';

console.log(isUuid('75442486-0878-440c-9db1-a7006c25a39f'));
// => true

Please note that the isUuid function returns true for both, v4 and v5 UUIDs. In addition, isUuid returns true for empty().

If you want to perform the verification on your own, use the regex property, and access its v4 or v5 property, depending on what you need:

import { regex } from 'uuidv4';

console.log(regex.v4);
console.log(regex.v5);

Please note that the regular expressions also consider empty() to be a valid UUID.

Getting a UUID from a string

From time to time you need an identifier that looks like a UUID, but is actually inferred from a string. For that, use the fromString function, which returns a UUID v5:

import { fromString } from 'uuidv4';

console.log(fromString('the native web'));
// => 'cdb63720-9628-5ef6-bbca-2e5ce6094f3c'

Getting the empty UUID

If you need a UUID that consists only of zeros, use the empty function:

import { empty } from 'uuidv4';

console.log(empty());
// => '00000000-0000-0000-0000-000000000000'

Running the build

To build this module use roboter.

$ npx roboter

Keywords

FAQs

Package last updated on 15 Nov 2019

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc