diff --git a/.gitignore b/.gitignore index 9daa824..7dd44db 100644 --- a/.gitignore +++ b/.gitignore @@ -1,2 +1,3 @@ .DS_Store node_modules +.idea \ No newline at end of file diff --git a/component.json b/component.json new file mode 100644 index 0000000..4f5ce0e --- /dev/null +++ b/component.json @@ -0,0 +1,14 @@ +{ + "name": "JavaScript-MD5", + "version": "1.0.0", + "description": "JavaScript MD5 implementation.", + "keywords": [ + "javascript", + "md5" + ], + "scripts": [ + "js/md5.js" + ], + "main": "js/md5.js", + "license": "MIT" +} \ No newline at end of file diff --git a/js/md5.js b/js/md5.js index a0d394c..9e1ca5a 100644 --- a/js/md5.js +++ b/js/md5.js @@ -269,13 +269,22 @@ return rawHMACMD5(key, string) } - if (typeof define === 'function' && define.amd) { - define(function () { - return md5 - }) - } else if (typeof module === 'object' && module.exports) { - module.exports = md5 - } else { - $.md5 = md5 - } + // check js environment + if (typeof(exports) !== 'undefined') { + // nodejs env + if (typeof module !== 'undefined' && module.exports) { + exports = module.exports = md5; + } + exports.md5 = md5; + } else { + // requirejs env (optional) + if (typeof(define) === 'function' && define.amd) { + define(function () { + return md5; + }); + } else { + // browser env + $.md5 = md5; + } + } }(this))