From b59b5c5ecad271c5453f1a156f011671f6d35627 Mon Sep 17 00:00:00 2001 From: Christoph Tavan Date: Thu, 23 Jan 2020 13:12:51 +0100 Subject: [PATCH] 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 --- src/md5.js | 18 ++++-------------- src/sha1.js | 18 ++++-------------- 2 files changed, 8 insertions(+), 28 deletions(-) diff --git a/src/md5.js b/src/md5.js index 5f4f5ef2..81d7e301 100644 --- a/src/md5.js +++ b/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 diff --git a/src/sha1.js b/src/sha1.js index dfcb3089..779d79dc 100644 --- a/src/sha1.js +++ b/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