[Pkg-javascript-commits] [node-create-hash] 11/40: browser: consistent formatting

Bastien Roucariès rouca at moszumanska.debian.org
Sat May 27 14:10:34 UTC 2017


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

rouca pushed a commit to branch master
in repository node-create-hash.

commit 98def752bb97a06184443b62b8e7cb8e3b0078de
Author: Daniel Cousens <github at dcousens.com>
Date:   Thu Jan 29 01:43:21 2015 +1100

    browser: consistent formatting
    
    Still not sure if we are doing exports top or bottom.  Happy with
    either.
---
 browser.js | 48 ++++++++++++++++++++++++++----------------------
 1 file changed, 26 insertions(+), 22 deletions(-)

diff --git a/browser.js b/browser.js
index 3240de8..3e904f7 100644
--- a/browser.js
+++ b/browser.js
@@ -1,36 +1,33 @@
 'use strict';
 var sha = require('sha.js')
-
 var md5 = require('./md5')
 var rmd160 = require('ripemd160')
 var Transform = require('stream').Transform;
 var inherits = require('inherits')
 
-module.exports = function createHash (alg) {
-  if('md5' === alg) return new HashNoConstructor(md5)
-  if('rmd160' === alg) return new HashNoConstructor(rmd160)
-  return new Hash(sha(alg))
-}
-inherits(HashNoConstructor, Transform)
-
 function HashNoConstructor(hash) {
   Transform.call(this);
   this._hash = hash
   this.buffers = []
 }
 
+inherits(HashNoConstructor, Transform)
+
 HashNoConstructor.prototype._transform = function (data, _, done) {
   this.buffers.push(data)
   done()
 }
+
 HashNoConstructor.prototype._flush = function (done) {
   this.push(this.digest())
   done()
 }
+
 HashNoConstructor.prototype.update = function (data, enc) {
   if (typeof data === 'string') {
     data = new Buffer(data, enc)
   }
+
   this.buffers.push(data)
   return this
 }
@@ -39,42 +36,49 @@ HashNoConstructor.prototype.digest = function (enc) {
   var buf = Buffer.concat(this.buffers)
   var r = this._hash(buf)
   this.buffers = null
-  if (enc) {
-    r = r.toString(enc)
-  }
-  return r
-}
 
-inherits(Hash, Transform)
+  return enc ? r.toString(enc) : r
+}
 
 function Hash(hash) {
   Transform.call(this)
   this._hash = hash
 }
+
+inherits(Hash, Transform)
+
 Hash.prototype._transform = function (data, enc, done) {
-  if (enc) {
-    data = new Buffer(data, enc)
-  }
+  if (enc) data = new Buffer(data, enc)
+
   this._hash.update(data)
+
   done()
 }
+
 Hash.prototype._flush = function (done) {
   this.push(this._hash.digest())
   this._hash = null
+
   done()
 }
+
 Hash.prototype.update = function (data, enc) {
   if (typeof data === 'string') {
     data = new Buffer(data, enc)
   }
+
   this._hash.update(data)
   return this
 }
 
 Hash.prototype.digest = function (enc) {
   var outData = this._hash.digest()
-  if (enc) {
-    outData = outData.toString(enc)
-  }
-  return outData
-}
\ No newline at end of file
+
+  return enc ? outData.toString(enc) : outData
+}
+
+module.exports = function createHash (alg) {
+  if ('md5' === alg) return new HashNoConstructor(md5)
+  if ('rmd160' === alg) return new HashNoConstructor(rmd160)
+  return new Hash(sha(alg))
+}

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



More information about the Pkg-javascript-commits mailing list