|
Last change
on this file was 9af201e, checked in by MBK <marija.karapandzova@…>, 12 days ago |
|
Fix frontend appearance
|
-
Property mode
set to
100644
|
|
File size:
1.1 KB
|
| Line | |
|---|
| 1 | "use strict";
|
|---|
| 2 |
|
|---|
| 3 | Object.defineProperty(exports, "__esModule", {
|
|---|
| 4 | value: true
|
|---|
| 5 | });
|
|---|
| 6 | exports.default = rng;
|
|---|
| 7 | // Unique ID creation requires a high quality random # generator. In the browser we therefore
|
|---|
| 8 | // require the crypto API and do not support built-in fallback to lower quality random number
|
|---|
| 9 | // generators (like Math.random()).
|
|---|
| 10 | let getRandomValues;
|
|---|
| 11 | const rnds8 = new Uint8Array(16);
|
|---|
| 12 |
|
|---|
| 13 | function rng() {
|
|---|
| 14 | // lazy load so that environments that need to polyfill have a chance to do so
|
|---|
| 15 | if (!getRandomValues) {
|
|---|
| 16 | // getRandomValues needs to be invoked in a context where "this" is a Crypto implementation. Also,
|
|---|
| 17 | // find the complete implementation of crypto (msCrypto) on IE11.
|
|---|
| 18 | getRandomValues = typeof crypto !== 'undefined' && crypto.getRandomValues && crypto.getRandomValues.bind(crypto) || typeof msCrypto !== 'undefined' && typeof msCrypto.getRandomValues === 'function' && msCrypto.getRandomValues.bind(msCrypto);
|
|---|
| 19 |
|
|---|
| 20 | if (!getRandomValues) {
|
|---|
| 21 | throw new Error('crypto.getRandomValues() not supported. See https://github.com/uuidjs/uuid#getrandomvalues-not-supported');
|
|---|
| 22 | }
|
|---|
| 23 | }
|
|---|
| 24 |
|
|---|
| 25 | return getRandomValues(rnds8);
|
|---|
| 26 | } |
|---|
Note:
See
TracBrowser
for help on using the repository browser.