Support AMD.

This commit is contained in:
Chen Yi-Cyuan
2015-04-03 19:40:27 +08:00
parent e5c451015b
commit d125d5a40a
11 changed files with 74 additions and 14 deletions
+12 -5
View File
@@ -1,5 +1,5 @@
/*
* js-md5 v0.2.0
* js-md5 v0.2.1
* https://github.com/emn178/js-md2
*
* Copyright 2014-2015, emn178@gmail.com
@@ -10,10 +10,12 @@
;(function(root, undefined) {
'use strict';
var NODE_JS = typeof(module) != 'undefined';
var NODE_JS = typeof process == 'object' && process.versions && process.versions.node;
if(NODE_JS) {
root = global;
}
var COMMON_JS = !root.JS_MD2_TEST && typeof module == 'object' && module.exports;
var AMD = typeof define == 'function' && define.amd;
var HEX_CHARS = '0123456789abcdef'.split('');
var S = [ 0x29, 0x2E, 0x43, 0xC9, 0xA2, 0xD8, 0x7C, 0x01, 0x3D, 0x36, 0x54, 0xA1, 0xEC, 0xF0, 0x06, 0x13,
@@ -35,7 +37,7 @@
var M = [], X = [], C = [];
var md2 = function(message, asciiOnly) {
var md2 = function(message) {
var code, i, j, k, t, L = 0, loop = 1, B,
index = 0, start = 0, bytes = 0, length = message.length;
@@ -140,9 +142,14 @@
return hex;
};
if(!root.JS_MD2_TEST && NODE_JS) {
if(COMMON_JS) {
module.exports = md2;
} else if(root) {
} else {
if(AMD) {
define(function() {
return md2;
});
}
root.md2 = md2;
}
}(this));