uuid-random
Advanced tools
Comparing version 1.0.4 to 1.0.5
@@ -7,3 +7,3 @@ /* | ||
npm install an-uiid node-uuid portable-uuid pure-uuid simply-uuid uuid | ||
npm install an-uiid node-uuid portable-uuid pure-uuid simply-uuid uuid uuid-v4 | ||
@@ -48,4 +48,6 @@ | ||
// global | ||
var i, start, seconds, ops = 5000000; | ||
// Test ours here | ||
var i, start, seconds, ops = 5000000; | ||
var uuidRandom = require('./index'); | ||
@@ -52,0 +54,0 @@ start = + new Date; |
11
index.js
@@ -15,2 +15,5 @@ (function(){ | ||
// Test for uuidness | ||
uuid.test = isUUID; | ||
// Cache toString(16) | ||
@@ -30,2 +33,6 @@ // This is massively impactful on performance | ||
function isUUID(uuid) { | ||
return /^[0-9a-f]{8}-[0-9a-f]{4}-4[0-9a-f]{3}-[89ab][0-9a-f]{3}-[0-9a-f]{12}$/.test(uuid); | ||
} | ||
// From MDN docs | ||
@@ -38,3 +45,3 @@ function getRandomInt(min, max) { | ||
function randomBytes(n) { | ||
if (crypto) { | ||
if (typeof crypto !== 'undefined') { | ||
if ((typeof buf === 'undefined') || ((bufIdx + n) > uuid.BUFFER_SIZE)) { | ||
@@ -60,3 +67,3 @@ bufIdx = 0; | ||
} | ||
function uuidbin() { | ||
@@ -63,0 +70,0 @@ var b = randomBytes(16); |
{ | ||
"name": "uuid-random", | ||
"version": "1.0.4", | ||
"version": "1.0.5", | ||
"description": "Fastest UUIDv4 with good RNG", | ||
@@ -5,0 +5,0 @@ "main": "index.js", |
# uuid-random | ||
Generate RFC-4122 compliant | ||
[random UUIDv4](https://en.wikipedia.org/wiki/Universally_unique_identifier#Version_4_.28random.29) | ||
[random UUIDs](https://en.wikipedia.org/wiki/Universally_unique_identifier#Version_4_.28random.29) | ||
with better | ||
@@ -15,13 +15,19 @@ [statistical dispersion](https://en.wikipedia.org/wiki/Statistical_dispersion) | ||
## Features | ||
* 0.3k minified + gzipped | ||
* Uses [better RNG](http://caniuse.com/#feat=getrandomvalues) when possible | ||
* Works in browser or node with zero external dependencies | ||
* Very fast! | ||
## Performance | ||
This is the fastest pure javascript UUIDv4 generator I have found, almost **5x | ||
faster** than comparable libraries. | ||
This is the fastest pure javascript UUID v4 generator I have found, | ||
over **5x faster** than comparable libraries. | ||
| npm package | performance | | ||
|-----------------|-----------------| | ||
| an-uuid | 330k ops/sec | | ||
| node-uuid | 370k ops/sec | | ||
| portable-uuid | 260k ops/sec | | ||
| simply-uuid | 25k ops/sec | | ||
| uuid | 370k ops/sec | | ||
@@ -31,10 +37,2 @@ | **uuid-random** | **2M ops/sec** | | ||
## Features | ||
* 0.3k minified + gzipped | ||
* Uses [better RNG](http://caniuse.com/#feat=getrandomvalues) when possible | ||
* Works in browser or node with zero external dependencies | ||
* Very fast! | ||
## Example Usage | ||
@@ -58,13 +56,25 @@ | ||
### Is UUID? | ||
```javascript | ||
uuid.test(uuid()); // true | ||
``` | ||
## Rationale | ||
`Math.random()` sucks for uuid generation. | ||
Random (v4) UUIDs are often | ||
[better](https://blogs.msdn.microsoft.com/oldnewthing/20160114-00/?p=92851) than | ||
clock-based (v1), but `Math.random()` | ||
[sucks](https://medium.com/@betable/tifu-by-using-math-random-f1c308c4fd9d) | ||
[for](http://devoluk.com/google-chrome-math-random-issue.html) | ||
[uuid generation](http://stackoverflow.com/questions/6906916/collisions-when-generating-uuids-in-javascript). | ||
After digging through [npm](https://www.npmjs.com/search?q=uuid) and | ||
[stackoverflow](http://stackoverflow.com/questions/105034/create-guid-uuid-in-javascript/2117523#2117523), | ||
After digging through [npm](https://www.npmjs.com/search?q=uuid) | ||
I settled on using [node-uuid](https://github.com/broofa/node-uuid) to take | ||
advantage of better RNG when possible. It's a great lib, but overkill for me. | ||
So, I combined code from the best libs and | ||
advantage of better RNG when possible. It's a great lib, but seemed too large | ||
and featured after using that neat [oneliner-ish solution](http://stackoverflow.com/questions/105034/create-guid-uuid-in-javascript/2117523#2117523). | ||
So, I combined ideas from the better implementations and | ||
[researched](https://gist.github.com/jed/982883) a *much* faster, more focused | ||
uuid generator that still used the best RNG available to the platform. | ||
and compact uuid generator that used the best RNG available. | ||
@@ -71,0 +81,0 @@ This library does one thing very well: generate UUID version 4. |
Sorry, the diff of this file is not supported yet
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
8758
124
84