2017-05-28 00:38:50 +02:00
|
|
|
'use strict';
|
2017-08-14 05:01:11 +02:00
|
|
|
const crypto = require('crypto');
|
2017-05-28 00:38:50 +02:00
|
|
|
|
|
|
|
module.exports = function (input) {
|
2017-08-14 05:01:11 +02:00
|
|
|
const hash = crypto.createHash('md5');
|
2017-05-28 00:38:50 +02:00
|
|
|
|
2017-08-14 05:01:11 +02:00
|
|
|
const update = buf => {
|
|
|
|
const inputEncoding = typeof buf === 'string' ? 'utf8' : undefined;
|
2017-05-28 00:38:50 +02:00
|
|
|
hash.update(buf, inputEncoding);
|
|
|
|
};
|
|
|
|
|
|
|
|
if (arguments.length > 1) {
|
|
|
|
throw new Error('Too many arguments. Try specifying an array.');
|
|
|
|
}
|
|
|
|
|
|
|
|
if (Array.isArray(input)) {
|
|
|
|
input.forEach(update);
|
|
|
|
} else {
|
|
|
|
update(input);
|
|
|
|
}
|
|
|
|
|
|
|
|
return hash.digest('hex');
|
|
|
|
};
|