• Stars
    star
    104
  • Rank 330,604 (Top 7 %)
  • Language
    JavaScript
  • License
    MIT License
  • Created almost 9 years ago
  • Updated over 1 year ago

Reviews

There are no reviews yet. Be the first to send feedback to the community and the maintainers!

Repository Details

Tiny, fast UUID v4 with cryptographic PRNG

uuid-random

MIT Licence Stable

Generate RFC-4122 compliant random UUIDs (version 4) with better statistical dispersion than Math.random().

Install

npm i uuid-random

Or download the latest release.

Features

Compatibility

Compatible with almost all versions of:

  • Node
  • Babel
  • TypeScript
  • Web browsers

Performance

The included benchmark.js as well as independent benchmarks rank this library as the fastest pure JS UUID v4 generator available with cryptographically secure PRNGβ€” almost 20x faster than the most popular library (using latest NodeJS).

npm package performance
portable-uuid 354k ops/sec
uuid 474k ops/sec
id128 6.0M ops/sec
uuid-random (this) 9.7M ops/sec

Results above generated on a 4.20GHz Intel i7-7700K with Node v12.18.0

Why use UUID?

Universally Unique IDentifiers transcend many constraints of traditional incremental integer IDs, especially in distributed systems. In UUID version 4, we essentially generate a random 128-bit value.

We do trade guaranteed uniqueness for extremely probable uniqueness (you would need to do-loop uuid() at max speed for 73,067 years for a 50% chance of one collision). But for that slight cost, we may now generate valid, unique, persistent IDs on any node of a distributed system (e.g. intermittently offline or high-latency clients).

Note, if you plan to use UUIDs for a new project, depending on your requirements, you may consider a more recent standard that addresses some of the shortcomings of UUID, such as flake-id, nanoid, cuid, or ulid.

Example Usage

Babel

import uuid from 'uuid-random';
uuid(); // 'f32dc9ae-7ca8-44ca-8f25-f258f7331c55'

Node

var uuid = require('uuid-random');
uuid(); // '0b99b82f-62cf-4275-88b3-de039020f14e'

Browser

<script src="uuid-random.min.js"></script>
<script>
  uuid(); // 'b96ab5e6-f1e8-4653-ab08-4dd82ea65778'
</script>

Validate a UUID v4 String

uuid.test('0b99b82f-62cf-4275-88b3-de039020f14e'); // true

Generate Binary UUIDs

uuid.bin(); // <Buffer 41 db 10 54 b3 61 48 50 87 f1 2f 7b 08 a5 0f 06>

Contributing

Feel free to open an issue or submit a pull request.

License

MIT.

More Repositories

1

ranger-zoxide

Easily jump between common directories in ranger
Python
106
star
2

emoji-menu

πŸ” Easily find and copy emojis on Linux
Shell
29
star
3

virtual-dom-handlebars

Compile Handlebars to Virtual DOM templates
JavaScript
13
star
4

wordseg

Fast word segmentation with a focus on splitting #hashtags
Python
13
star
5

phpunit-assert-throws

Exception testing assertions for PHPUnit
PHP
10
star
6

babel-plugin-transform-h-jsx

Transform JSX into virtual-hyperscript
JavaScript
8
star
7

uuid-v4

Fast, Secure UUID v4 in PHP
PHP
8
star
8

mime-php

Parse, render, and validate MIME in PHP
PHP
5
star
9

activeredis

PHP Relational Model Abstraction for Redis
PHP
4
star
10

cloudapp-linux

Unofficial CloudApp scripts for Linux
Shell
4
star
11

dotenv-to-php

Convert dotenv files to PHP
Shell
3
star
12

kohya-trainer-docker

Train Dreambooth models and LoRAs locally with nvidia-docker
Jupyter Notebook
3
star
13

iprev

Reverse IP utility (IPv4 and IPv6)
Rust
2
star
14

traits.js

Horizontal inheritance pattern for JavaScript
JavaScript
2
star
15

twitter-crawler

Crawl Twitter URLs using Chrome or Firefox
TypeScript
2
star
16

s3-upload

Upload files to S3 via command line
Shell
2
star
17

stega

Hide secret messages in PNG image files
TypeScript
2
star
18

house

Super-minimal pure PHP MVC toolkit
PHP
2
star
19

stable-diffusion-webui-docker

Dockerized version of Automatic1111's Stable Diffusion Web UI
Dockerfile
2
star
20

rewait

Wait for resources to become available -- http, https, tcp, sockets, files, and custom functions.
JavaScript
2
star
21

docker-spf-milter

SPF Milter for Docker
Dockerfile
1
star
22

hasura-expo-apollo-typescript

Example mobile app - Offline-first, GraphQL, TypeScript, Push Notifications
TypeScript
1
star
23

php-include-directive

Support for #include directives in PHP templates
PHP
1
star
24

itunes-playlist-exporter

Export song files from an iTunes playlist
PHP
1
star
25

tappable-php

A plugin framework for PHP
PHP
1
star
26

hello-world-c

Simple hello world program in C used for testing package manager tooling.
Makefile
1
star
27

yijing

Yijing readings from the command line.
PHP
1
star
28

bangs

Use DuckDuckGo bangs, but default to Google search
JavaScript
1
star
29

php-redux

Redux in PHP
1
star