-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
12 changed files
with
975 additions
and
1,768 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -2,5 +2,4 @@ dist/ | |
node_modules/ | ||
.nyc_ouput/ | ||
coverage/ | ||
lib/ | ||
environment/ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,85 @@ | ||
/** | ||
* UUID generator | ||
* | ||
* This is a modified version of Robert Kieffer's Math.uuid | ||
* from http://www.broofa.com/2008/09/javascript-uuid-function/ | ||
* | ||
* It differs in three ways from the original work: | ||
* - uuid is no longer attached to the Math object | ||
* - script is now written in require.js style | ||
* - alternative implementations have been removed | ||
* | ||
* Additionally the usage examples have been adapted to reflect these changes. | ||
* | ||
* Original credits: | ||
* Math.uuid.js (v1.4) | ||
* http://www.broofa.com | ||
* mailto:robert@broofa.com | ||
* | ||
* Copyright (c) 2010 Robert Kieffer | ||
* Dual licensed under the MIT and GPL licenses. | ||
* | ||
*/ | ||
|
||
// Private array of chars to use | ||
const CHARS = '0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz'.split(''); | ||
|
||
/** | ||
* Generate a random uuid | ||
* | ||
* USAGE: uuid(length, radix) | ||
* length - the desired number of characters | ||
* radix - the number of allowable values for each character. | ||
* | ||
* EXAMPLES: | ||
* // No arguments - returns RFC4122, version 4 ID | ||
* >>> uuid() | ||
* "92329D39-6F5C-4520-ABFC-AAB64544E172" | ||
* | ||
* // One argument - returns ID of the specified length | ||
* >>> uuid(15) // 15 character ID (default base=62) | ||
* "VcydxgltxrVZSTV" | ||
* | ||
* // Two arguments - returns ID of the specified length, and radix. (Radix must be <= 62) | ||
* >>> uuid(8, 2) // 8 character ID (base=2) | ||
* "01001010" | ||
* >>> uuid(8, 10) // 8 character ID (base=10) | ||
* "47473046" | ||
* >>> uuid(8, 16) // 8 character ID (base=16) | ||
* "098F4D35" | ||
* | ||
* @param {number} len | ||
* @param {number} radix | ||
* @returns {*} | ||
* @private | ||
*/ | ||
function uuid(len, radix) { | ||
const chars = CHARS; | ||
const id = []; | ||
radix = radix || chars.length; | ||
|
||
// Compact form | ||
if (len) { | ||
for (let i = 0; i < len; i++) { | ||
id[i] = chars[0 | (Math.random() * radix)]; | ||
} | ||
// rfc4122 form | ||
} else { | ||
// rfc4122 requires these characters | ||
// eslint-disable-next-line | ||
id[8] = id[13] = id[18] = id[23] = '-'; | ||
id[14] = '4'; | ||
|
||
// Fill in random data. At i === 19 set the high bits of clock sequence as | ||
// per rfc4122, sec. 4.1.5 | ||
for (let i = 0; i < 36; i++) { | ||
if (!id[i]) { | ||
const r = 0 | (Math.random() * 16); | ||
id[i] = chars[i === 19 ? (r & 0x3) | 0x8 : r]; | ||
} | ||
} | ||
} | ||
|
||
return id.join(''); | ||
} | ||
export default uuid; |