uuidv4
uuidv4 creates v4 UUIDs.
Last updated 9 days ago by thenativeweb-admin .
MIT · Repository · Bugs · Original npm · Tarball · package.json
$ cnpm install uuidv4 
SYNC missed versions from official npm registry.

uuidv4

uuidv4 creates v4 UUIDs.

Status

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

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'

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

Current Tags

  • 6.1.1                                ...           latest (9 days ago)

25 Versions

  • 6.1.1                                ...           9 days ago
  • 6.1.0                                ...           a month ago
  • 6.0.9                                ...           a month ago
  • 6.0.8                                ...           2 months ago
  • 6.0.7                                ...           3 months ago
  • 6.0.6                                ...           4 months ago
  • 6.0.5                                ...           4 months ago
  • 6.0.4                                ...           4 months ago
  • 6.0.3                                ...           4 months ago
  • 6.0.2                                ...           5 months ago
  • 6.0.1                                ...           6 months ago
  • 6.0.0                                ...           8 months ago
  • 5.0.1                                ...           10 months ago
  • 5.0.0                                ...           10 months ago
  • 4.0.0                                ...           a year ago
  • 3.0.1                                ...           a year ago
  • 3.0.0                                ...           a year ago
  • 2.0.0                                ...           2 years ago
  • 1.0.1                                ...           2 years ago
  • 1.0.0                                ...           2 years ago
  • 0.5.0                                ...           3 years ago
  • 0.4.1                                ...           3 years ago
  • 0.4.0                                ...           4 years ago
  • 0.3.1                                ...           5 years ago
  • 0.3.0                                ...           6 years ago
Downloads
Today 45
This Week 181
This Month 126
Last Day 32
Last Week 145
Last Month 670
Dependencies (2)
Dev Dependencies (3)
Dependents (229)

Copyright 2014 - 2016 © taobao.org |