Comparing version 1.1.4 to 2.0.0
@@ -1,57 +0,16 @@ | ||
(function() { | ||
function getBytes() { | ||
try { | ||
// Modern Browser | ||
return Array.from( | ||
(window.crypto || window.msCrypto).getRandomValues(new Uint8Array(16)) | ||
); | ||
} catch (error) { | ||
// Legacy Browser, fallback to Math.random | ||
var ret = []; | ||
while (ret.length < 16) ret.push((Math.random() * 256) & 0xff); | ||
return ret; | ||
} | ||
} | ||
const uuidPattern = /^[0-9a-f]{8}-[0-9a-f]{4}-4[0-9a-f]{3}-[89ab][0-9a-f]{3}-[0-9a-f]{12}$/i; | ||
function valid(uuid) { | ||
return uuidPattern.test(uuid); | ||
} | ||
function m(v) { | ||
v = v.toString(16); | ||
if (v.length < 2) v = "0" + v; | ||
return v; | ||
} | ||
// Based on https://abhishekdutta.org/blog/standalone_uuid_generator_in_javascript.html | ||
// IE11 and Modern Browsers Only | ||
function uuid4() { | ||
var temp_url = URL.createObjectURL(new Blob()); | ||
var uuid = temp_url.toString(); | ||
URL.revokeObjectURL(temp_url); | ||
return uuid.split(/[:\/]/g).pop().toLowerCase(); // remove prefixes | ||
} | ||
uuid4.valid = valid; | ||
function genUUID() { | ||
var rnd = getBytes(); | ||
rnd[6] = (rnd[6] & 0x0f) | 0x40; | ||
rnd[8] = (rnd[8] & 0x3f) | 0x80; | ||
rnd = rnd | ||
.map(m) | ||
.join("") | ||
.match(/(.{8})(.{4})(.{4})(.{4})(.{12})/); | ||
rnd.shift(); | ||
return rnd.join("-"); | ||
} | ||
var uuidPattern = /^[0-9a-f]{8}-[0-9a-f]{4}-4[0-9a-f]{3}-[89ab][0-9a-f]{3}-[0-9a-f]{12}$/; | ||
function isUUID(uuid) { | ||
return uuidPattern.test(uuid); | ||
} | ||
genUUID.valid = isUUID; | ||
// global | ||
if (window) { | ||
window.uuid4 = genUUID; | ||
} | ||
// Node-style CJS | ||
if (typeof module !== "undefined" && module.exports) { | ||
module.exports = genUUID; | ||
} | ||
// AMD - legacy | ||
if (typeof define === "function" && define.amd) { | ||
define([], function() { | ||
return genUUID; | ||
}); | ||
} | ||
})(); | ||
module.exports = uuid4; |
44
index.js
@@ -1,34 +0,18 @@ | ||
"use strict"; | ||
const crypto = require("crypto"); | ||
var crypto = require("crypto"), | ||
uuidPattern = /^[0-9a-f]{8}-[0-9a-f]{4}-4[0-9a-f]{3}-[89ab][0-9a-f]{3}-[0-9a-f]{12}$/; | ||
const uuidPattern = /^[0-9a-f]{8}-[0-9a-f]{4}-4[0-9a-f]{3}-[89ab][0-9a-f]{3}-[0-9a-f]{12}$/i; | ||
function valid(uuid) { | ||
return uuidPattern.test(uuid); | ||
} | ||
exports = module.exports = genUUID; | ||
exports.valid = isUUID; | ||
function genUUID(callback) { | ||
if (typeof callback !== "function") { | ||
var rnd = crypto.randomBytes(16); | ||
rnd[6] = (rnd[6] & 0x0f) | 0x40; | ||
rnd[8] = (rnd[8] & 0x3f) | 0x80; | ||
rnd = rnd.toString("hex").match(/(.{8})(.{4})(.{4})(.{4})(.{12})/); | ||
rnd.shift(); | ||
return rnd.join("-"); | ||
} | ||
crypto.randomBytes(16, function(err, rnd) { | ||
if (err) return callback(err); | ||
try { | ||
rnd[6] = (rnd[6] & 0x0f) | 0x40; | ||
rnd[8] = (rnd[8] & 0x3f) | 0x80; | ||
rnd = rnd.toString("hex").match(/(.{8})(.{4})(.{4})(.{4})(.{12})/); | ||
rnd.shift(); | ||
return callback(null, rnd.join("-")); | ||
} catch (err2) { | ||
return callback(err2); | ||
} | ||
}); | ||
function uuid4() { | ||
var rnd = crypto.randomBytes(16); | ||
rnd[6] = (rnd[6] & 0x0f) | 0x40; | ||
rnd[8] = (rnd[8] & 0x3f) | 0x80; | ||
rnd = rnd.toString("hex").match(/(.{8})(.{4})(.{4})(.{4})(.{12})/); | ||
rnd.shift(); | ||
return rnd.join("-"); | ||
} | ||
uuid4.valid = valid; | ||
function isUUID(uuid) { | ||
return uuidPattern.test(uuid); | ||
} | ||
module.exports = uuid4; |
{ | ||
"name": "uuid4", | ||
"version": "1.1.4", | ||
"version": "2.0.0", | ||
"description": "Node UUID v4 Generator", | ||
"main": "index.js", | ||
"browser": "browser.js", | ||
"module": "index.mjs", | ||
"browser": { | ||
"./index.js": "browser.js", | ||
"./index.mjs": "browser.mjs" | ||
}, | ||
"repository": { | ||
@@ -8,0 +12,0 @@ "type": "git", |
@@ -5,2 +5,5 @@ # uuid4 | ||
NOTE: as of Version 2, legacy browsers are no longer supported, you can keep using 1.x if you need | ||
to support modern and legacy browsers. | ||
## Install | ||
@@ -15,3 +18,3 @@ | ||
```javascript | ||
var uuid4 = require('uuid4'); | ||
var uuid4 = require("uuid4"); | ||
@@ -22,3 +25,3 @@ // Generate a new UUID | ||
// Validate a UUID as proper V4 format | ||
uuid4.valid(id); // true | ||
uuid4.valid(id); // true | ||
``` | ||
@@ -28,2 +31,2 @@ | ||
ISC License | ||
ISC License |
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
Deprecated
MaintenanceThe maintainer of the package marked it as deprecated. This could indicate that a single version should not be used, or that the package is no longer maintained and any new vulnerabilities will not be fixed.
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
3807
7
29
60
1