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" + } +} 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));