0
Fork 0
mirror of https://github.com/penpot/penpot.git synced 2025-01-09 00:10:11 -05:00

Fix rng def in nodejs environment.

This commit is contained in:
Andrey Antukh 2016-04-24 22:53:31 +03:00
parent f0ed85e53f
commit ac3d44601a
No known key found for this signature in database
GPG key ID: 4DFEBCB8316A8B95

12
vendor/uuid/rng.js vendored
View file

@ -9,23 +9,25 @@
"use strict";
goog.provide("uuid.rng");
goog.require("cljs.core");
goog.scope(function() {
uuid.rng.getBytes = null;
const global = goog.global;
// Check if nodejs rng is available (high quality);
if (goog.global.require !== undefined) {
const crypto = goog.global.require("crypto");
if (cljs.core._STAR_target_STAR_ === "nodejs") {
const crypto = require("crypto");
uuid.rng.getBytes = function(n) {
return crypto.randomBytes(n);
};
}
// Check if whatwg rng is available (high quality);
else if (goog.global.crypto.getRandomValues !== undefined) {
else if (global.crypto !== undefined &&
global.crypto.getRandomValues !== undefined) {
uuid.rng.getBytes = function(n) {
const buf = new Uint8Array(16);
goog.global.crypto.getRandomValues(buf);
global.crypto.getRandomValues(buf);
return buf;
};
}