Skip to content

Commit b59b5c5

Browse files
authored
feat: remove support for pre Node.js v4 Buffer API (#356)
BREAKING CHANGE: Remove support for generating v3 and v5 UUIDs in Node.js<4.x
1 parent 4acaea4 commit b59b5c5

2 files changed

Lines changed: 8 additions & 28 deletions

File tree

src/md5.js

Lines changed: 4 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,20 +1,10 @@
11
import crypto from 'crypto';
22

33
function md5(bytes) {
4-
if (typeof Buffer.from === 'function') {
5-
// Modern Buffer API
6-
if (Array.isArray(bytes)) {
7-
bytes = Buffer.from(bytes);
8-
} else if (typeof bytes === 'string') {
9-
bytes = Buffer.from(bytes, 'utf8');
10-
}
11-
} else {
12-
// Pre-v4 Buffer API
13-
if (Array.isArray(bytes)) {
14-
bytes = new Buffer(bytes);
15-
} else if (typeof bytes === 'string') {
16-
bytes = new Buffer(bytes, 'utf8');
17-
}
4+
if (Array.isArray(bytes)) {
5+
bytes = Buffer.from(bytes);
6+
} else if (typeof bytes === 'string') {
7+
bytes = Buffer.from(bytes, 'utf8');
188
}
199

2010
return crypto

src/sha1.js

Lines changed: 4 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,20 +1,10 @@
11
import crypto from 'crypto';
22

33
function sha1(bytes) {
4-
if (typeof Buffer.from === 'function') {
5-
// Modern Buffer API
6-
if (Array.isArray(bytes)) {
7-
bytes = Buffer.from(bytes);
8-
} else if (typeof bytes === 'string') {
9-
bytes = Buffer.from(bytes, 'utf8');
10-
}
11-
} else {
12-
// Pre-v4 Buffer API
13-
if (Array.isArray(bytes)) {
14-
bytes = new Buffer(bytes);
15-
} else if (typeof bytes === 'string') {
16-
bytes = new Buffer(bytes, 'utf8');
17-
}
4+
if (Array.isArray(bytes)) {
5+
bytes = Buffer.from(bytes);
6+
} else if (typeof bytes === 'string') {
7+
bytes = Buffer.from(bytes, 'utf8');
188
}
199

2010
return crypto

0 commit comments

Comments
 (0)