Skip to content

Commit c9e076c

Browse files
authored
feat: use native crypto.randomUUID when available (#600)
1 parent cf49e8b commit c9e076c

File tree

6 files changed

+26
-4
lines changed

6 files changed

+26
-4
lines changed

bundlewatch.config.json

+4-4
Original file line numberDiff line numberDiff line change
@@ -5,9 +5,9 @@
55
{ "path": "./examples/browser-rollup/dist/v4-size.js", "maxSize": "0.7 kB" },
66
{ "path": "./examples/browser-rollup/dist/v5-size.js", "maxSize": "1.5 kB" },
77

8-
{ "path": "./examples/browser-webpack/dist/v1-size.js", "maxSize": "1.3 kB" },
9-
{ "path": "./examples/browser-webpack/dist/v3-size.js", "maxSize": "2.5 kB" },
10-
{ "path": "./examples/browser-webpack/dist/v4-size.js", "maxSize": "1.0 kB" },
11-
{ "path": "./examples/browser-webpack/dist/v5-size.js", "maxSize": "1.9 kB" }
8+
{ "path": "./examples/browser-webpack/dist/v1-size.js", "maxSize": "1.0 kB" },
9+
{ "path": "./examples/browser-webpack/dist/v3-size.js", "maxSize": "2.1 kB" },
10+
{ "path": "./examples/browser-webpack/dist/v4-size.js", "maxSize": "0.7 kB" },
11+
{ "path": "./examples/browser-webpack/dist/v5-size.js", "maxSize": "1.5 kB" }
1212
]
1313
}

package.json

+1
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,7 @@
3232
"module": "./dist/esm-node/index.js",
3333
"browser": {
3434
"./dist/md5.js": "./dist/md5-browser.js",
35+
"./dist/native.js": "./dist/native-browser.js",
3536
"./dist/rng.js": "./dist/rng-browser.js",
3637
"./dist/sha1.js": "./dist/sha1-browser.js",
3738
"./dist/esm-node/index.js": "./dist/esm-browser/index.js"

src/native-browser.js

+4
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
const randomUUID =
2+
typeof crypto !== 'undefined' && crypto.randomUUID && crypto.randomUUID.bind(crypto);
3+
4+
export default { randomUUID };

src/native.js

+3
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
import crypto from 'crypto';
2+
3+
export default { randomUUID: crypto.randomUUID };

src/v4.js

+5
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,12 @@
1+
import native from './native.js';
12
import rng from './rng.js';
23
import stringify from './stringify.js';
34

45
function v4(options, buf, offset) {
6+
if (native.randomUUID && !buf && !options) {
7+
return native.randomUUID();
8+
}
9+
510
options = options || {};
611

712
const rnds = options.random || (options.rng || rng)();

wdio.conf.js

+9
Original file line numberDiff line numberDiff line change
@@ -34,13 +34,22 @@ const capabilities = [
3434
},
3535

3636
// Chrome
37+
// Chrome 92 introduced native support for crypto.randomUUID
38+
{
39+
...commonCapabilities,
40+
browserName: 'Chrome',
41+
browser_version: '92.0',
42+
os: 'Windows',
43+
os_version: '10',
44+
},
3745
{
3846
...commonCapabilities,
3947
browserName: 'Chrome',
4048
browser_version: '81.0',
4149
os: 'Windows',
4250
os_version: '10',
4351
},
52+
// Chrome 49 released on 2016-03-02 was the last version supported on Windows XP, Windows Vista, Mac OS X 10.6, 10.7, and 10.8
4453
{
4554
...commonCapabilities,
4655
browserName: 'Chrome',

0 commit comments

Comments
 (0)