summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorBrian Turek <brian.turek@gmail.com>2013-12-15 10:24:56 -0500
committerBrian Turek <brian.turek@gmail.com>2013-12-15 11:19:35 -0500
commitd05524fd9f8246cc79c2a74654b19237f97b66ba (patch)
treeb1882c492787518281a383b0f86eb5651ad3208c
parentebe2edacd5679b937f89f49f98f9c9ff73f6db11 (diff)
downloadjsSHA-d05524fd9f8246cc79c2a74654b19237f97b66ba.zip
jsSHA-d05524fd9f8246cc79c2a74654b19237f97b66ba.tar.gz
jsSHA-d05524fd9f8246cc79c2a74654b19237f97b66ba.tar.bz2
Added support for Node.js and AMD
-rwxr-xr-xbuild/externs.js5
-rwxr-xr-xbuild/make-release2
-rwxr-xr-xsrc/sha_dev.js21
3 files changed, 25 insertions, 3 deletions
diff --git a/build/externs.js b/build/externs.js
new file mode 100755
index 0000000..cd26d0a
--- /dev/null
+++ b/build/externs.js
@@ -0,0 +1,5 @@
+/* This file is needed so that the Google Closure Compiler does not complain
+ * about the module, define, and exports variables being undefined */
+var module = null;
+var define = null;
+var exports = null;
diff --git a/build/make-release b/build/make-release
index 08d606d..27cdbb1 100755
--- a/build/make-release
+++ b/build/make-release
@@ -6,5 +6,5 @@ CLOSURE_COMPILER=${CLOSURE_COMPILER-"../compiler.jar"}
for i in "${!releases[@]}"
do
- java -jar ${CLOSURE_COMPILER} --define="SUPPORTED_ALGS=${releases[$i]}" --output_wrapper "(function(module) {%output%})(this);" --warning_level VERBOSE --compilation_level ADVANCED_OPTIMIZATIONS --js ../src/sha_dev.js --js_output_file ../src/$i.js
+ java -jar ${CLOSURE_COMPILER} --define="SUPPORTED_ALGS=${releases[$i]}" --externs externs.js --warning_level VERBOSE --compilation_level ADVANCED_OPTIMIZATIONS --js ../src/sha_dev.js --js_output_file ../src/$i.js
done
diff --git a/src/sha_dev.js b/src/sha_dev.js
index c906be8..0ba20da 100755
--- a/src/sha_dev.js
+++ b/src/sha_dev.js
@@ -20,7 +20,7 @@
*/
var SUPPORTED_ALGS = 4 | 2 | 1;
-(function (module)
+(function (global)
{
"use strict";
/**
@@ -1381,5 +1381,22 @@ var SUPPORTED_ALGS = 4 | 2 | 1;
};
};
- module['jsSHA'] = jsSHA;
+ if (("function" === typeof define) && (typeof define["amd"])) /* AMD Support */
+ {
+ define(function()
+ {
+ return jsSHA;
+ });
+ } else if ("undefined" !== typeof exports) /* Node Support */
+ {
+ if (("undefined" !== typeof module) && module["exports"])
+ {
+ module["exports"] = exports = jsSHA;
+ }
+ else {
+ exports = jsSHA;
+ }
+ } else { /* Browsers and Web Workers*/
+ global["jsSHA"] = jsSHA;
+ }
}(this));