From 8be061d9dca5cb2f8e17f489e92ecb3f8cf5b052 Mon Sep 17 00:00:00 2001 From: Curtis Liu Date: Mon, 10 Aug 2015 15:50:37 -0700 Subject: [PATCH 1/2] Add component.json --- component.json | 22 ++++++++++++++++++++++ 1 file changed, 22 insertions(+) create mode 100644 component.json diff --git a/component.json b/component.json new file mode 100644 index 0000000..40223ce --- /dev/null +++ b/component.json @@ -0,0 +1,22 @@ +{ + "name": "JavaScript-MD5", + "version": "1.1.1", + "description": "JavaScript MD5 implementation.", + "keywords": [ + "javascript", + "md5" + ], + "scripts": [ + "js/md5.js" + ], + "main": "js/md5.js", + "license": "MIT", + "development": { + "grunt": "~0.4.1", + "grunt-contrib-uglify": "~0.2.7", + "grunt-contrib-jshint": "~0.7.1", + "grunt-bump-build-git": "~1.0.0", + "grunt-simple-mocha": "~0.4.0", + "expect.js": "0.2.0" + } +} From 2350ea9b26dccf31b73c479fea13cab4cb9b0855 Mon Sep 17 00:00:00 2001 From: Curtis Liu Date: Mon, 10 Aug 2015 17:03:03 -0700 Subject: [PATCH 2/2] Support node environments --- js/md5.js | 21 ++++++++++++++++----- 1 file changed, 16 insertions(+), 5 deletions(-) diff --git a/js/md5.js b/js/md5.js index f92ba37..2ed6f4c 100644 --- a/js/md5.js +++ b/js/md5.js @@ -264,11 +264,22 @@ return raw_hmac_md5(key, string); } - if (typeof define === 'function' && define.amd) { - define(function () { - return md5; - }); + // check js environment + if (typeof(exports) !== 'undefined') { + // nodejs env + if (typeof module !== 'undefined' && module.exports) { + exports = module.exports = md5; + } + exports.md5 = md5; } else { - $.md5 = md5; + // requirejs env (optional) + if (typeof(define) === 'function' && define.amd) { + define(function () { + return md5; + }); + } else { + // browser env + $.md5 = md5; + } } }(this));