[Pkg-javascript-commits] [node-hash-base] 04/13: Typecheck as function

Bastien Roucariès rouca at moszumanska.debian.org
Sat Aug 12 22:00:33 UTC 2017


This is an automated email from the git hooks/post-receive script.

rouca pushed a commit to branch upstream
in repository node-hash-base.

commit 867095d2d7d369d1c24a44d64bdf403ecb1dd653
Author: Kirill Fomichev <fanatid at ya.ru>
Date:   Wed Nov 2 14:17:58 2016 +0300

    Typecheck as function
---
 index.js | 8 +++++++-
 1 file changed, 7 insertions(+), 1 deletion(-)

diff --git a/index.js b/index.js
index 01371cd..de9e700 100644
--- a/index.js
+++ b/index.js
@@ -2,6 +2,12 @@
 var Transform = require('stream').Transform
 var inherits = require('inherits')
 
+function throwIfNotStringOrBuffer (val, prefix) {
+  if (!Buffer.isBuffer(val) && typeof val !== 'string') {
+    throw new TypeError(prefix + ' must be a string or a buffer')
+  }
+}
+
 function HashBase (blockSize) {
   Transform.call(this)
 
@@ -38,7 +44,7 @@ HashBase.prototype._flush = function (callback) {
 }
 
 HashBase.prototype.update = function (data, encoding) {
-  if (!Buffer.isBuffer(data) && typeof data !== 'string') throw new TypeError('Data must be a string or a buffer')
+  throwIfNotStringOrBuffer(data, 'Data')
   if (this._finalized) throw new Error('Digest already called')
   if (!Buffer.isBuffer(data)) data = new Buffer(data, encoding)
 

-- 
Alioth's /usr/local/bin/git-commit-notice on /srv/git.debian.org/git/pkg-javascript/node-hash-base.git



More information about the Pkg-javascript-commits mailing list