Skip to content

Commit

Permalink
feat: remove support for pre Node.js v4 Buffer API (#356)
Browse files Browse the repository at this point in the history
BREAKING CHANGE: Remove support for generating v3 and v5 UUIDs in
Node.js<4.x
  • Loading branch information
ctavan committed Jan 23, 2020
1 parent 4acaea4 commit b59b5c5
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 28 deletions.
18 changes: 4 additions & 14 deletions src/md5.js
@@ -1,20 +1,10 @@
import crypto from 'crypto';

function md5(bytes) {
if (typeof Buffer.from === 'function') {
// Modern Buffer API
if (Array.isArray(bytes)) {
bytes = Buffer.from(bytes);
} else if (typeof bytes === 'string') {
bytes = Buffer.from(bytes, 'utf8');
}
} else {
// Pre-v4 Buffer API
if (Array.isArray(bytes)) {
bytes = new Buffer(bytes);
} else if (typeof bytes === 'string') {
bytes = new Buffer(bytes, 'utf8');
}
if (Array.isArray(bytes)) {
bytes = Buffer.from(bytes);
} else if (typeof bytes === 'string') {
bytes = Buffer.from(bytes, 'utf8');
}

return crypto
Expand Down
18 changes: 4 additions & 14 deletions src/sha1.js
@@ -1,20 +1,10 @@
import crypto from 'crypto';

function sha1(bytes) {
if (typeof Buffer.from === 'function') {
// Modern Buffer API
if (Array.isArray(bytes)) {
bytes = Buffer.from(bytes);
} else if (typeof bytes === 'string') {
bytes = Buffer.from(bytes, 'utf8');
}
} else {
// Pre-v4 Buffer API
if (Array.isArray(bytes)) {
bytes = new Buffer(bytes);
} else if (typeof bytes === 'string') {
bytes = new Buffer(bytes, 'utf8');
}
if (Array.isArray(bytes)) {
bytes = Buffer.from(bytes);
} else if (typeof bytes === 'string') {
bytes = Buffer.from(bytes, 'utf8');
}

return crypto
Expand Down

0 comments on commit b59b5c5

Please sign in to comment.