forked from gwenaelp/vue-diagrams
-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(id): produce UUID with
generateId
. move to /utils/Identifier.js
This is the replace the much simpler but prone to problem simple (and small) random Integer generation. And moved the function to its own `/utils/Identifier.js` file for ease of maintenance. Close gwenaelp#14
- Loading branch information
Showing
4 changed files
with
20 additions
and
14 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
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,15 @@ | ||
/** | ||
* Generate a UUID (v1) | ||
* @param {Integer} c clock-seq-and-reserved clock-seq-low | ||
* @return {String} The UUID | ||
* http://www.rfcreader.com/#rfc4122_line385 allows random instead of MAC address | ||
* https://www.famkruithof.net/uuid/uuidgen | ||
* https://realityripple.com/Tools/UnUUID/ | ||
*/ | ||
export function generateId(c = 9999) { | ||
const t = ((Date.now() + 12219292800000) * 1e4).toString(16); | ||
const n = crypto.getRandomValues(new Uint8Array(6)).reduce((sum, x, i) => { | ||
return sum + (i === 0 ? x | 1 : x).toString(16).padStart(2, "0"); | ||
}, ""); | ||
return `${t.slice(-8)}-${t.slice(-12, -8)}-1${t.slice(0, 3)}-${c}-${n}`; | ||
} |