npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

uuidv4

v6.2.13

Published

uuidv4 creates v4 UUIDs.

Downloads

1,659,183

Readme

uuidv4

uuidv4 creates v4 UUIDs.

Status

| Category | Status | | ---------------- | --------------------------------------------------------------------------------------------------- | | Version | npm | | Dependencies | David | | Dev dependencies | David | | Build | GitHub Actions | | License | GitHub |

Please note

This module will be deprecated in the future in favour of module uuid. Most of the functionality of this module is already included in uuid since version 8.3.0, so most of the functions of this module have already been marked as deprecated.

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().

Using a regular expression

If you want to perform the verification on your own using a regular expression, 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.

Using a JSON schema

If you want to perform the verification on your own using a JSON schema, use the jsonSchema property, and access its v4 or v5 property, depending on what you need:

import { jsonSchema } from 'uuidv4';

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

Please note that the JSON schemas 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'

By default, the fromString function uses a pre-configured namespace. If you want to use your own namespace, provide a UUID as second parameter:

import { fromString } from 'uuidv4';

console.log(fromString('the native web', '004aadf4-8e1a-4450-905b-6039179f52da'));
// => 'b1c4a89e-4905-5e3c-b57f-dc92627d011e'

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 quality assurance

To run quality assurance for this module use roboter:

$ npx roboter