[Pkg-javascript-commits] [node-shasum] 13/23: Use sha.js instead of crypto-browserify

Bastien Roucariès rouca at moszumanska.debian.org
Fri May 5 09:06:24 UTC 2017


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

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

commit 990c3e72e19d755d28226219effa9bc9899f398b
Author: Forbes Lindesay <forbes at lindesay.co.uk>
Date:   Fri Jan 9 05:02:33 2015 +0000

    Use sha.js instead of crypto-browserify
    
    This still passes all the tests and makes the library about 14KB
    minified and Gzipped (including all dependencies) rather than about
    200KB minified and Gzipped.  Without this change, the library is
    practically unusable for anyone who doesn’t expect to need a
    significant proportion of the rest of crypto-browserify.
---
 README.md     |  3 +--
 browser.js    | 13 +++++++++++++
 package.json  |  8 ++++++--
 test/index.js |  2 +-
 4 files changed, 21 insertions(+), 5 deletions(-)

diff --git a/README.md b/README.md
index 4fbd077..e0a187d 100644
--- a/README.md
+++ b/README.md
@@ -8,8 +8,7 @@ var shasum = require('shasum')
 shasum(string || buffer || object)
 ```
 
-Oh yeah, it works in the browser too, with 
-[crypto-browserify](https://npmjs.org/package/crypto-browserify)
+Oh yeah, it works in the browser too, with [browserify](https://npmjs.org/package/browserify)
 
 ## License
 
diff --git a/browser.js b/browser.js
new file mode 100644
index 0000000..848a1dd
--- /dev/null
+++ b/browser.js
@@ -0,0 +1,13 @@
+
+var createHash = require('sha.js')
+var Buffer = require('buffer').Buffer
+var stringify = require('json-stable-stringify')
+
+module.exports = function hash (str, alg, format) {
+  str = 'string' === typeof str ? str
+    : Buffer.isBuffer(str) ? str
+    : stringify(str)
+  return createHash(alg || 'sha1')
+    .update(str, Buffer.isBuffer(str) ? null : 'utf8').digest(format || 'hex')
+}
+
diff --git a/package.json b/package.json
index 16fff76..ee664a5 100644
--- a/package.json
+++ b/package.json
@@ -7,12 +7,16 @@
     "url": "git://github.com/dominictarr/shasum.git"
   },
   "dependencies": {
-    "json-stable-stringify": "~0.0.0"
+    "json-stable-stringify": "~0.0.0",
+    "sha.js": "~2.3.0"
   },
   "devDependencies": {
   },
+  "browser": {
+    "./index.js": "./browser.js"
+  },
   "scripts": {
-    "test": "set -e; for t in test/*.js; do node $t; done"
+    "test": "node test/index.js && node test/index.js browser"
   },
   "author": "'Dominic Tarr' <dominic.tarr at gmail.com> (http://dominictarr.com)",
   "license": "MIT"  
diff --git a/test/index.js b/test/index.js
index 0c804ef..990e7b2 100644
--- a/test/index.js
+++ b/test/index.js
@@ -1,5 +1,5 @@
 var equal = require('assert').equal
-var hash = require('..')
+var hash = require(process.argv[2] === 'browser' ? '../browser.js' : '..')
 
 
 equal(hash('abc'),  'a9993e364706816aba3e25717850c26c9cd0d89d')

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



More information about the Pkg-javascript-commits mailing list