Comparing version 3.4.0 to 3.5.0
/* | ||
Version: v3.4.0 | ||
Version: v3.5.0 | ||
The MIT License: Copyright (c) 2010-2017 LiosK. | ||
*/ | ||
var UUID;UUID=function(f){function b(){}function c(d){return 0>d?NaN:30>=d?0|Math.random()*(1<<d):53>=d?(0|1073741824*Math.random())+1073741824*(0|Math.random()*(1<<d-30)):NaN}function a(d,c){for(var a=d.toString(16),b=c-a.length,e="0";0<b;b>>>=1,e+=e)b&1&&(a=e+a);return a}b.generate=function(){return a(c(32),8)+"-"+a(c(16),4)+"-"+a(16384|c(12),4)+"-"+a(32768|c(14),4)+"-"+a(c(48),12)};b.overwrittenUUID=f;"undefined"!==typeof module&&module&&module.exports&&(module.exports=b);return b}(UUID); | ||
var UUID; | ||
UUID=function(f){function a(){}a.generate=function(){var b=a._getRandomInt,c=a._hexAligner;return c(b(32),8)+"-"+c(b(16),4)+"-"+c(16384|b(12),4)+"-"+c(32768|b(14),4)+"-"+c(b(48),12)};a._getRandomInt=function(b){if(0>b||53<b)return NaN;var c=0|1073741824*Math.random();return 30<b?c+1073741824*(0|Math.random()*(1<<b-30)):c>>>30-b};a._hexAligner=function(b,c){for(var a=b.toString(16),d=c-a.length,e="0";0<d;d>>>=1,e+=e)d&1&&(a=e+a);return a};a.overwrittenUUID=f;"undefined"!==typeof module&&module&&module.exports&& | ||
(module.exports=a);return a}(UUID); |
{ | ||
"name": "uuidjs", | ||
"version": "3.4.0", | ||
"version": "3.5.0", | ||
"title": "UUID.js", | ||
@@ -12,3 +12,4 @@ "description": "The RFC-compliant UUID generator for JavaScript.", | ||
"scripts": { | ||
"test": "qunit test/test.nodejs.js" | ||
"test": "qunit test/test.nodejs.js", | ||
"jsdoc": "jsdoc -R ./README.md -d ./doc src/uuid.js" | ||
}, | ||
@@ -37,4 +38,5 @@ "repository": { | ||
"devDependencies": { | ||
"jsdoc": "^3.4.3", | ||
"qunitjs": "^1.23.1" | ||
} | ||
} |
@@ -29,3 +29,3 @@ # NAME | ||
Load `src/uuid.js` to get full functionality. If you only need `UUID.generate()` method, load `dist/uuid.core.js`. | ||
Load `src/uuid.js` or `require("uuidjs")`. | ||
@@ -112,5 +112,4 @@ ```javascript | ||
* [RFC 4122](http://www.ietf.org/rfc/rfc4122.txt) | ||
* [API Document](http://liosk.github.io/UUID.js/doc/symbols/UUID.html) | ||
* [Test cases: uuid.js](http://liosk.github.io/UUID.js/test/test.uuid.js.html) | ||
* [Test cases: uuid.core.js](http://liosk.github.io/UUID.js/test/test.uuid.core.js.html) | ||
* [RFC 4122](https://www.ietf.org/rfc/rfc4122.txt) | ||
* [API Document](https://liosk.github.io/UUID.js/doc/) | ||
* [Test cases: uuid.js](https://liosk.github.io/UUID.js/test/test.uuid.js.html) |
/** | ||
* UUID.core.js: A small subset of UUID.js, the RFC-compliant UUID generator for JavaScript. | ||
* | ||
* @fileOverview | ||
* @file | ||
* @author LiosK | ||
* @version v3.4.0 | ||
* @version v3.5.0 | ||
* @license The MIT License: Copyright (c) 2010-2017 LiosK. | ||
*/ | ||
/** @constructor */ | ||
/** @namespace */ | ||
var UUID; | ||
@@ -16,4 +16,3 @@ | ||
/** @lends UUID */ | ||
function UUID() {} | ||
// Core Component {{{ | ||
@@ -25,2 +24,3 @@ /** | ||
UUID.generate = function() { | ||
var rand = UUID._getRandomInt, hex = UUID._hexAligner; | ||
return hex(rand(32), 8) // time_low | ||
@@ -39,15 +39,15 @@ + "-" | ||
* Returns an unsigned x-bit random integer. | ||
* @private | ||
* @param {int} x A positive integer ranging from 0 to 53, inclusive. | ||
* @returns {int} An unsigned x-bit random integer (0 <= f(x) < 2^x). | ||
*/ | ||
function rand(x) { // _getRandomInt | ||
if (x < 0) return NaN; | ||
if (x <= 30) return (0 | Math.random() * (1 << x)); | ||
if (x <= 53) return (0 | Math.random() * (1 << 30)) | ||
+ (0 | Math.random() * (1 << x - 30)) * (1 << 30); | ||
return NaN; | ||
} | ||
UUID._getRandomInt = function(x) { | ||
if (x < 0 || x > 53) { return NaN; } | ||
var n = 0 | Math.random() * 0x40000000; // 1 << 30 | ||
return x > 30 ? n + (0 | Math.random() * (1 << x - 30)) * 0x40000000 : n >>> 30 - x; | ||
}; | ||
/** | ||
* Converts an integer to a zero-filled hexadecimal string. | ||
* @private | ||
* @param {int} num | ||
@@ -57,11 +57,11 @@ * @param {int} length | ||
*/ | ||
function hex(num, length) { // _hexAligner | ||
UUID._hexAligner = function(num, length) { | ||
var str = num.toString(16), i = length - str.length, z = "0"; | ||
for (; i > 0; i >>>= 1, z += z) { if (i & 1) { str = z + str; } } | ||
return str; | ||
} | ||
}; | ||
/** | ||
* Preserves the value of 'UUID' global variable set before the load of UUID.js. | ||
* @since core-1.1 | ||
* @since 3.2 | ||
* @type object | ||
@@ -71,3 +71,8 @@ */ | ||
// For nodejs | ||
// }}} | ||
// create local namespace | ||
function UUID() {} | ||
// for nodejs | ||
if (typeof module !== "undefined" && module && module.exports) { | ||
@@ -81,2 +86,2 @@ module.exports = UUID; | ||
// vim: et ts=2 sw=2 | ||
// vim: et ts=2 sw=2 fdm=marker fmr& |
137
src/uuid.js
/** | ||
* UUID.js: The RFC-compliant UUID generator for JavaScript. | ||
* | ||
* @fileOverview | ||
* @file | ||
* @author LiosK | ||
* @version v3.4.0 | ||
* @version v3.5.0 | ||
* @license The MIT License: Copyright (c) 2010-2017 LiosK. | ||
*/ | ||
/** @constructor */ | ||
/** @namespace */ | ||
var UUID; | ||
@@ -18,5 +18,2 @@ | ||
/** @lends UUID */ | ||
function UUID() {} | ||
/** | ||
@@ -41,2 +38,3 @@ * The simplest function to get an UUID string. | ||
* Returns an unsigned x-bit random integer. | ||
* @private | ||
* @param {int} x A positive integer ranging from 0 to 53, inclusive. | ||
@@ -46,26 +44,70 @@ * @returns {int} An unsigned x-bit random integer (0 <= f(x) < 2^x). | ||
UUID._getRandomInt = function(x) { | ||
if (x < 0) return NaN; | ||
if (x <= 30) return (0 | Math.random() * (1 << x)); | ||
if (x <= 53) return (0 | Math.random() * (1 << 30)) | ||
+ (0 | Math.random() * (1 << x - 30)) * (1 << 30); | ||
return NaN; | ||
if (x < 0 || x > 53) { return NaN; } | ||
var n = 0 | Math.random() * 0x40000000; // 1 << 30 | ||
return x > 30 ? n + (0 | Math.random() * (1 << x - 30)) * 0x40000000 : n >>> 30 - x; | ||
}; | ||
/** | ||
* Returns a function that converts an integer to a zero-filled string. | ||
* @param {int} radix | ||
* @returns {function(num, length)} | ||
* Converts an integer to a zero-filled hexadecimal string. | ||
* @private | ||
* @param {int} num | ||
* @param {int} length | ||
* @returns {string} | ||
*/ | ||
UUID._getIntAligner = function(radix) { | ||
return function(num, length) { | ||
var str = num.toString(radix), i = length - str.length, z = "0"; | ||
for (; i > 0; i >>>= 1, z += z) { if (i & 1) { str = z + str; } } | ||
return str; | ||
}; | ||
UUID._hexAligner = function(num, length) { | ||
var str = num.toString(16), i = length - str.length, z = "0"; | ||
for (; i > 0; i >>>= 1, z += z) { if (i & 1) { str = z + str; } } | ||
return str; | ||
}; | ||
UUID._hexAligner = UUID._getIntAligner(16); | ||
/** | ||
* Preserves the value of 'UUID' global variable set before the load of UUID.js. | ||
* @since 3.2 | ||
* @type object | ||
*/ | ||
UUID.overwrittenUUID = overwrittenUUID; | ||
// }}} | ||
// Advanced Random Number Generator Component {{{ | ||
(function() { | ||
var mathPRNG = UUID._getRandomInt; | ||
/** | ||
* Enables Math.random()-based pseudorandom number generator instead of cryptographically safer options. | ||
* @since v3.5.0 | ||
* @deprecated This method is provided only to work around performance drawbacks of the safer algorithms. | ||
*/ | ||
UUID.useMathRandom = function() { | ||
UUID._getRandomInt = mathPRNG; | ||
}; | ||
var crypto = null, cryptoPRNG = mathPRNG; | ||
if (typeof window !== "undefined" && (crypto = window.crypto || window.msCrypto)) { | ||
if (crypto.getRandomValues && typeof Uint32Array !== "undefined") { | ||
// Web Cryptography API | ||
cryptoPRNG = function(x) { | ||
if (x < 0 || x > 53) { return NaN; } | ||
var ns = crypto.getRandomValues(new Uint32Array(x > 32 ? 2 : 1)); | ||
return x > 32 ? ns[0] + (ns[1] >>> 64 - x) * 0x100000000 : ns[0] >>> 32 - x; | ||
}; | ||
} | ||
} else if (typeof require !== "undefined" && (crypto = require("crypto"))) { | ||
if (crypto.randomBytes) { | ||
// nodejs | ||
cryptoPRNG = function(x) { | ||
if (x < 0 || x > 53) { return NaN; } | ||
var buf = crypto.randomBytes(x > 32 ? 8 : 4), n = buf.readUInt32BE(0); | ||
return x > 32 ? n + (buf.readUInt32BE(4) >>> 64 - x) * 0x100000000 : n >>> 32 - x; | ||
}; | ||
} | ||
} | ||
UUID._getRandomInt = cryptoPRNG; | ||
})(); | ||
// }}} | ||
// UUID Object Component {{{ | ||
@@ -126,2 +168,3 @@ | ||
* Initializes {@link UUID} object. | ||
* @private | ||
* @param {uint32} [timeLow=0] time_low field (octet 0-3). | ||
@@ -134,2 +177,3 @@ * @param {uint16} [timeMid=0] time_mid field (octet 4-5). | ||
* @returns {UUID} this. | ||
* @constructs UUID | ||
*/ | ||
@@ -200,3 +244,14 @@ UUID.prototype._init = function() { | ||
UUID._binAligner = UUID._getIntAligner(2); | ||
/** | ||
* Converts an integer to a zero-filled binary string. | ||
* @private | ||
* @param {int} num | ||
* @param {int} length | ||
* @returns {string} | ||
*/ | ||
UUID._binAligner = function(num, length) { | ||
var str = num.toString(2), i = length - str.length, z = "0"; | ||
for (; i > 0; i >>>= 1, z += z) { if (i & 1) { str = z + str; } } | ||
return str; | ||
}; | ||
@@ -240,2 +295,3 @@ /** | ||
UUID.genV1 = function() { | ||
if (UUID._state == null) { UUID.resetState(); } | ||
var now = new Date().getTime(), st = UUID._state; | ||
@@ -272,7 +328,16 @@ if (now != st.timestamp) { | ||
UUID.resetState = function() { | ||
UUID._state = new UUID._state.constructor(); | ||
UUID._state = new UUIDState(); | ||
}; | ||
function UUIDState() { | ||
var rand = UUID._getRandomInt; | ||
this.timestamp = 0; | ||
this.sequence = rand(14); | ||
this.node = (rand(8) | 1) * 0x10000000000 + rand(40); // set multicast bit '1' | ||
this.tick = rand(4); // timestamp fraction smaller than a millisecond | ||
} | ||
/** | ||
* Probability to advance the timestamp fraction: the ratio of tick movements to sequence increments. | ||
* @private | ||
* @type float | ||
@@ -284,13 +349,9 @@ */ | ||
* Persistent state for UUID version 1. | ||
* @private | ||
* @type UUIDState | ||
*/ | ||
UUID._state = new function UUIDState() { | ||
var rand = UUID._getRandomInt; | ||
this.timestamp = 0; | ||
this.sequence = rand(14); | ||
this.node = (rand(8) | 1) * 0x10000000000 + rand(40); // set multicast bit '1' | ||
this.tick = rand(4); // timestamp fraction smaller than a millisecond | ||
}; | ||
UUID._state = null; | ||
/** | ||
* @private | ||
* @param {Date|int} time ECMAScript Date Object or milliseconds from 1970-01-01. | ||
@@ -308,3 +369,3 @@ * @returns {object} | ||
// Misc. Component {{{ | ||
// Backward Compatibility Component {{{ | ||
@@ -324,10 +385,8 @@ /** | ||
/** | ||
* Preserves the value of 'UUID' global variable set before the load of UUID.js. | ||
* @since 3.2 | ||
* @type object | ||
*/ | ||
UUID.overwrittenUUID = overwrittenUUID; | ||
// }}} | ||
// For nodejs | ||
// create local namespace | ||
function UUID() {} | ||
// for nodejs | ||
if (typeof module !== "undefined" && module && module.exports) { | ||
@@ -337,4 +396,2 @@ module.exports = UUID; | ||
// }}} | ||
return UUID; | ||
@@ -341,0 +398,0 @@ |
@@ -10,3 +10,4 @@ var UUID = require("uuidjs"); | ||
eval("" + fs.readFileSync("test/uuid.nil.js")); | ||
eval("" + fs.readFileSync("test/uuid.useMathRandom.js")); | ||
// vim: et ts=2 sw=2 |
Sorry, the diff of this file is not supported yet
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
Native code
Supply chain riskContains native code (e.g., compiled binaries or shared libraries). Including native code can obscure malicious behavior.
Found 12 instances in 1 package
Mixed license
License(Experimental) Package contains multiple licenses.
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
1379148
59
9845
2
9319
1
114
19