mirror of
https://github.com/penpot/penpot.git
synced 2025-07-19 01:37:19 +02:00
Add uuid generation functions that uses high quality RNG.
This commit is contained in:
parent
5f86df81ec
commit
6e4d243897
3 changed files with 116 additions and 0 deletions
47
vendor/uuid/impl.js
vendored
Normal file
47
vendor/uuid/impl.js
vendored
Normal file
|
@ -0,0 +1,47 @@
|
|||
/*
|
||||
* This Source Code Form is subject to the terms of the Mozilla Public
|
||||
* License, v. 2.0. If a copy of the MPL was not distributed with this
|
||||
* file, You can obtain one at http://mozilla.org/MPL/2.0/.
|
||||
*
|
||||
* Copyright (c) 2016 Andrey Antukh <niwi@niwi.nz>
|
||||
*/
|
||||
"use strict";
|
||||
|
||||
goog.provide("uuid.impl");
|
||||
goog.require("uuid.rng");
|
||||
|
||||
goog.scope(function() {
|
||||
const rng = uuid.rng;
|
||||
const hexMap = [];
|
||||
|
||||
for (let i = 0; i < 256; i++) {
|
||||
hexMap[i] = (i + 0x100).toString(16).substr(1);
|
||||
}
|
||||
|
||||
function toHexString(buf) {
|
||||
let i = 0;
|
||||
return (hexMap[buf[i++]] +
|
||||
hexMap[buf[i++]] +
|
||||
hexMap[buf[i++]] +
|
||||
hexMap[buf[i++]] + '-' +
|
||||
hexMap[buf[i++]] +
|
||||
hexMap[buf[i++]] + '-' +
|
||||
hexMap[buf[i++]] +
|
||||
hexMap[buf[i++]] + '-' +
|
||||
hexMap[buf[i++]] +
|
||||
hexMap[buf[i++]] + '-' +
|
||||
hexMap[buf[i++]] +
|
||||
hexMap[buf[i++]] +
|
||||
hexMap[buf[i++]] +
|
||||
hexMap[buf[i++]] +
|
||||
hexMap[buf[i++]] +
|
||||
hexMap[buf[i++]]);
|
||||
}
|
||||
|
||||
uuid.impl.v4 = function() {
|
||||
const buf = rng.getBytes(16);
|
||||
buf[6] = (buf[6] & 0x0f) | 0x40;
|
||||
buf[8] = (buf[8] & 0x3f) | 0x80;
|
||||
return cljs.core.uuid(toHexString(buf));
|
||||
};
|
||||
})
|
Loading…
Add table
Add a link
Reference in a new issue