mirror of
https://github.com/penpot/penpot.git
synced 2025-04-05 19:41:27 -05:00
Rename uuid related namespaces.
This commit is contained in:
parent
4607d92c31
commit
f81542a792
3 changed files with 12 additions and 13 deletions
src/uxbox/util
|
@ -8,19 +8,18 @@
|
|||
|
||||
"use strict";
|
||||
|
||||
goog.provide("uxbox.util.uuid.rng");
|
||||
goog.provide("uxbox.util.rng_impl");
|
||||
goog.require("cljs.core");
|
||||
|
||||
goog.scope(function() {
|
||||
const self = uxbox.util.rng_impl;
|
||||
const global = goog.global;
|
||||
const rng = uxbox.util.uuid.rng;
|
||||
|
||||
|
||||
// Check if nodejs rng is available (high quality);
|
||||
if (cljs.core._STAR_target_STAR_ === "nodejs") {
|
||||
const crypto = require("crypto");
|
||||
|
||||
rng.getBytes = function(n) {
|
||||
self.getBytes = function(n) {
|
||||
return crypto.randomBytes(n);
|
||||
};
|
||||
}
|
||||
|
@ -28,7 +27,7 @@ goog.scope(function() {
|
|||
// Check if whatwg rng is available (high quality);
|
||||
else if (global.crypto !== undefined &&
|
||||
global.crypto.getRandomValues !== undefined) {
|
||||
rng.getBytes = function(n) {
|
||||
self.getBytes = function(n) {
|
||||
const buf = new Uint8Array(16);
|
||||
global.crypto.getRandomValues(buf);
|
||||
return buf;
|
||||
|
@ -38,7 +37,7 @@ goog.scope(function() {
|
|||
// Switch Back to the Math.random (low quality);
|
||||
else {
|
||||
console.warn("No high quality RNG available, switching back to Math.random.");
|
||||
rng.getBytes = function(n) {
|
||||
self.getBytes = function(n) {
|
||||
const buf = new Array(n);
|
||||
for (let i = 0, r; i < n; i++) {
|
||||
if ((i & 0x03) === 0) { r = Math.random() * 0x100000000; }
|
|
@ -13,7 +13,7 @@
|
|||
|
||||
If no high qualiry RNG, switches to the default Math based
|
||||
RNG with proper waring in the console."
|
||||
(:require [uxbox.util.uuid.impl :as impl]))
|
||||
(:require [uxbox.util.uuid-impl :as impl]))
|
||||
|
||||
(defn v4
|
||||
"Generate a v4 (random) UUID."
|
||||
|
|
|
@ -7,14 +7,14 @@
|
|||
*/
|
||||
"use strict";
|
||||
|
||||
goog.provide("uxbox.util.uuid.impl");
|
||||
goog.require("uxbox.util.uuid.rng");
|
||||
goog.provide("uxbox.util.uuid_impl");
|
||||
goog.require("uxbox.util.rng_impl");
|
||||
|
||||
goog.scope(function() {
|
||||
const impl = uxbox.util.uuid.impl;
|
||||
const rng = uxbox.util.uuid.rng;
|
||||
const hexMap = [];
|
||||
const self = uxbox.util.uuid_impl;
|
||||
const rng = uxbox.util.rng_impl;
|
||||
|
||||
const hexMap = [];
|
||||
for (let i = 0; i < 256; i++) {
|
||||
hexMap[i] = (i + 0x100).toString(16).substr(1);
|
||||
}
|
||||
|
@ -39,7 +39,7 @@ goog.scope(function() {
|
|||
hexMap[buf[i++]]);
|
||||
}
|
||||
|
||||
impl.v4 = function() {
|
||||
self.v4 = function() {
|
||||
const buf = rng.getBytes(16);
|
||||
buf[6] = (buf[6] & 0x0f) | 0x40;
|
||||
buf[8] = (buf[8] & 0x3f) | 0x80;
|
Loading…
Add table
Reference in a new issue