Comparing version 1.0.0 to 1.1.0
40
index.js
@@ -7,23 +7,15 @@ 'use strict'; | ||
exports = module.exports = generateUuid; | ||
exports.async = generateUuidAsync; | ||
exports.sync = generateUuidSync; | ||
exports.valid = generateUuid; | ||
exports = module.exports = genUUID; | ||
exports.valid = isUUID; | ||
function isUUID(uuid) { | ||
return uuidPattern.test(uuid); | ||
} | ||
function generateUuidSync() { | ||
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('-'); | ||
} | ||
function generateUuidAsync(callback) { | ||
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) { | ||
@@ -34,9 +26,9 @@ rnd[6] = (rnd[6] & 0x0f) | 0x40; | ||
rnd.shift(); | ||
callback(null, rnd.join('-')); | ||
return rnd.join('-'); | ||
}); | ||
} | ||
function generateUuid(callback) { | ||
if (typeof callback !== 'function') return generateUuidSync(); | ||
return generateUuidAsync(callback); | ||
} | ||
function isUUID(uuid) { | ||
return uuidPattern.test(uuid); | ||
} |
{ | ||
"name": "uuid4", | ||
"version": "1.0.0", | ||
"version": "1.1.0", | ||
"description": "Node UUID v4 Generator", | ||
"main": "index.js", | ||
"browser": "browser.js", | ||
"scripts": { | ||
@@ -7,0 +8,0 @@ "test": "echo \"Error: no test specified\" && exit 1" |
@@ -5,2 +5,4 @@ # uuid4 | ||
Note v1.1 adds a browser entry for use in browsers, `crypto` api for rng in modern browser, fallback to `Math.random()` | ||
## Install | ||
@@ -15,12 +17,12 @@ | ||
```javascript | ||
var uuid = require('uuid4'); | ||
var uuid4 = require('uuid4'); | ||
// Generate a new UUID | ||
var id = uuid(); | ||
var id = uuid4(); | ||
// Validate a UUID as proper V4 format | ||
uuid.valid(id); // true | ||
uuid4.valid(id); // true | ||
// Generate a new UUID Asyncronously | ||
uuid(function(err, id){ | ||
// NODE ONLY: Generate a new UUID Asynchronously | ||
uuid4(function(err, id){ | ||
//if (err) ...; | ||
@@ -27,0 +29,0 @@ |
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
3892
75
32