From 815daa38c6ed3e4bf1782ca8844c34063b238118 Mon Sep 17 00:00:00 2001 From: Robert Kieffer Date: Sun, 1 Oct 2017 17:13:23 -0700 Subject: [PATCH] eslint (#224) --- lib/md5.js | 18 ++++++++++++------ lib/sha1.js | 18 ++++++++++++------ lib/v35.js | 2 -- test/test.js | 15 ++++++--------- 4 files changed, 30 insertions(+), 23 deletions(-) diff --git a/lib/md5.js b/lib/md5.js index d336ee9b5..7044b872f 100644 --- a/lib/md5.js +++ b/lib/md5.js @@ -4,13 +4,19 @@ var crypto = require('crypto'); function md5(bytes) { if (typeof Buffer.from === 'function') { - // Support modern Buffer API - if (Array.isArray(bytes)) bytes = Buffer.from(bytes); - else if (typeof bytes === 'string') bytes = Buffer.from(bytes, 'utf8'); + // Modern Buffer API + if (Array.isArray(bytes)) { + bytes = Buffer.from(bytes); + } else if (typeof bytes === 'string') { + bytes = Buffer.from(bytes, 'utf8'); + } } else { - // Support pre-v4 Buffer API - if (Array.isArray(bytes)) bytes = new Buffer(bytes); - else if (typeof bytes === 'string') bytes = new Buffer(bytes, 'utf8'); + // Pre-v4 Buffer API + if (Array.isArray(bytes)) { + bytes = new Buffer(bytes); + } else if (typeof bytes === 'string') { + bytes = new Buffer(bytes, 'utf8'); + } } return crypto.createHash('md5').update(bytes).digest(); diff --git a/lib/sha1.js b/lib/sha1.js index 926fef39e..0b54b2507 100644 --- a/lib/sha1.js +++ b/lib/sha1.js @@ -4,13 +4,19 @@ var crypto = require('crypto'); function sha1(bytes) { if (typeof Buffer.from === 'function') { - // Support modern Buffer API - if (Array.isArray(bytes)) bytes = Buffer.from(bytes); - else if (typeof bytes === 'string') bytes = Buffer.from(bytes, 'utf8'); + // Modern Buffer API + if (Array.isArray(bytes)) { + bytes = Buffer.from(bytes); + } else if (typeof bytes === 'string') { + bytes = Buffer.from(bytes, 'utf8'); + } } else { - // Support pre-v4 Buffer API - if (Array.isArray(bytes)) bytes = new Buffer(bytes); - else if (typeof bytes === 'string') bytes = new Buffer(bytes, 'utf8'); + // Pre-v4 Buffer API + if (Array.isArray(bytes)) { + bytes = new Buffer(bytes); + } else if (typeof bytes === 'string') { + bytes = new Buffer(bytes, 'utf8'); + } } return crypto.createHash('sha1').update(bytes).digest(); diff --git a/lib/v35.js b/lib/v35.js index a0cb9a521..842c60ea2 100644 --- a/lib/v35.js +++ b/lib/v35.js @@ -19,8 +19,6 @@ function stringToBytes(str) { return bytes; } - - module.exports = function(name, version, hashfunc) { var generateUUID = function(value, namespace, buf, offset) { var off = buf && offset || 0; diff --git a/test/test.js b/test/test.js index 97072ad23..d15df3e71 100644 --- a/test/test.js +++ b/test/test.js @@ -1,4 +1,5 @@ var assert = require('assert'); +var crypto = require('crypto'); var uuid = require('../'); var crypto = require('crypto'); @@ -72,8 +73,11 @@ test('mathRNG', function() { }); test('cryptoRNG', function() { - // Clear require cache so we can monkey with it, below - delete require.cache[require.resolve('../lib/rng-browser')]; + var randomFillSync = crypto.randomFillSync; + + Object.keys(require.cache).forEach(function(path) { + if (/rng-browser/.test(path)) delete require.cache[path]; + }); // We shim the web crypto API to trigger cryptoRNG code path in rng module, // then unshim once we've required it @@ -90,13 +94,6 @@ test('cryptoRNG', function() { delete global.crypto; assert.equal(rng.name, 'whatwgRNG'); - - var bytes = rng(); - assert.equal(bytes.length, 16); - - for (var i = 0; i < bytes.length; i++) { - assert.equal(typeof(bytes[i]), 'number'); - } }); test('sha1 node', function() {