- support for web worker. #11

Changed
- throw error if input type is incorrect.
- prevent webpack to require dependencies.
This commit is contained in:
Chen, Yi-Cyuan
2017-07-14 13:10:27 +08:00
parent 8b9a23ce32
commit c00df3af37
15 changed files with 275 additions and 82 deletions
+9 -9
View File
@@ -91,7 +91,7 @@
<dt class="tag-source">Source:</dt>
<dd class="tag-source"><ul class="dummy"><li>
<a href="md5.js.html">md5.js</a>, <a href="md5.js.html#line141">line 141</a>
<a href="md5.js.html">md5.js</a>, <a href="md5.js.html#line162">line 162</a>
</li></ul></dd>
@@ -198,7 +198,7 @@
<dt class="tag-source">Source:</dt>
<dd class="tag-source"><ul class="dummy"><li>
<a href="md5.js.html">md5.js</a>, <a href="md5.js.html#line523">line 523</a>
<a href="md5.js.html">md5.js</a>, <a href="md5.js.html#line556">line 556</a>
</li></ul></dd>
@@ -314,7 +314,7 @@
<dt class="tag-source">Source:</dt>
<dd class="tag-source"><ul class="dummy"><li>
<a href="md5.js.html">md5.js</a>, <a href="md5.js.html#line535">line 535</a>
<a href="md5.js.html">md5.js</a>, <a href="md5.js.html#line568">line 568</a>
</li></ul></dd>
@@ -432,7 +432,7 @@
<dt class="tag-source">Source:</dt>
<dd class="tag-source"><ul class="dummy"><li>
<a href="md5.js.html">md5.js</a>, <a href="md5.js.html#line557">line 557</a>
<a href="md5.js.html">md5.js</a>, <a href="md5.js.html#line590">line 590</a>
</li></ul></dd>
@@ -548,7 +548,7 @@
<dt class="tag-source">Source:</dt>
<dd class="tag-source"><ul class="dummy"><li>
<a href="md5.js.html">md5.js</a>, <a href="md5.js.html#line501">line 501</a>
<a href="md5.js.html">md5.js</a>, <a href="md5.js.html#line534">line 534</a>
</li></ul></dd>
@@ -664,7 +664,7 @@
<dt class="tag-source">Source:</dt>
<dd class="tag-source"><ul class="dummy"><li>
<a href="md5.js.html">md5.js</a>, <a href="md5.js.html#line456">line 456</a>
<a href="md5.js.html">md5.js</a>, <a href="md5.js.html#line489">line 489</a>
</li></ul></dd>
@@ -780,7 +780,7 @@
<dt class="tag-source">Source:</dt>
<dd class="tag-source"><ul class="dummy"><li>
<a href="md5.js.html">md5.js</a>, <a href="md5.js.html#line489">line 489</a>
<a href="md5.js.html">md5.js</a>, <a href="md5.js.html#line522">line 522</a>
</li></ul></dd>
@@ -954,7 +954,7 @@
<dt class="tag-source">Source:</dt>
<dd class="tag-source"><ul class="dummy"><li>
<a href="md5.js.html">md5.js</a>, <a href="md5.js.html#line169">line 169</a>
<a href="md5.js.html">md5.js</a>, <a href="md5.js.html#line190">line 190</a>
</li></ul></dd>
@@ -1031,7 +1031,7 @@
<br class="clear">
<footer>
Documentation generated by <a href="https://github.com/jsdoc3/jsdoc">JSDoc 3.4.3</a> on Wed Jan 18 2017 09:43:27 GMT+0800 (CST)
Documentation generated by <a href="https://github.com/jsdoc3/jsdoc">JSDoc 3.4.3</a> on Fri Jul 14 2017 12:58:59 GMT+0800 (CST)
</footer>
<script> prettyPrint(); </script>
+2 -2
View File
@@ -210,7 +210,7 @@
<dt class="tag-source">Source:</dt>
<dd class="tag-source"><ul class="dummy"><li>
<a href="md5.js.html">md5.js</a>, <a href="md5.js.html#line575">line 575</a>
<a href="md5.js.html">md5.js</a>, <a href="md5.js.html#line608">line 608</a>
</li></ul></dd>
@@ -285,7 +285,7 @@
</div>
</div>
<nav>
<h2><a href="index.html">Home</a></h2><h3>Classes</h3><ul><li><a href="Md5_.html">Md5</a></li></ul><h3>Namespaces</h3><ul><li><a href="md5.html">md5</a></li></ul><h3>Global</h3><ul><li><a href="global.html#md5%2508">md5</a></li></ul>
+1 -1
View File
@@ -95,7 +95,7 @@ md5.buffer(''); // ArrayBuffer, deprecated, This maybe confuse with Buffer in no
<br class="clear">
<footer>
Documentation generated by <a href="https://github.com/jsdoc3/jsdoc">JSDoc 3.4.3</a> on Wed Jan 18 2017 09:43:27 GMT+0800 (CST)
Documentation generated by <a href="https://github.com/jsdoc3/jsdoc">JSDoc 3.4.3</a> on Fri Jul 14 2017 12:58:59 GMT+0800 (CST)
</footer>
<script> prettyPrint(); </script>
+9 -9
View File
@@ -47,7 +47,7 @@
<dt class="tag-version">Version:</dt>
<dd class="tag-version"><ul class="dummy"><li>0.4.2</li></ul></dd>
<dd class="tag-version"><ul class="dummy"><li>0.5.0</li></ul></dd>
@@ -233,7 +233,7 @@
<dt class="tag-source">Source:</dt>
<dd class="tag-source"><ul class="dummy"><li>
<a href="md5.js.html">md5.js</a>, <a href="md5.js.html#line53">line 53</a>
<a href="md5.js.html">md5.js</a>, <a href="md5.js.html#line67">line 67</a>
</li></ul></dd>
@@ -400,7 +400,7 @@
<dt class="tag-source">Source:</dt>
<dd class="tag-source"><ul class="dummy"><li>
<a href="md5.js.html">md5.js</a>, <a href="md5.js.html#line62">line 62</a>
<a href="md5.js.html">md5.js</a>, <a href="md5.js.html#line76">line 76</a>
</li></ul></dd>
@@ -569,7 +569,7 @@
<dt class="tag-source">Source:</dt>
<dd class="tag-source"><ul class="dummy"><li>
<a href="md5.js.html">md5.js</a>, <a href="md5.js.html#line71">line 71</a>
<a href="md5.js.html">md5.js</a>, <a href="md5.js.html#line85">line 85</a>
</li></ul></dd>
@@ -678,7 +678,7 @@
<dt class="tag-source">Source:</dt>
<dd class="tag-source"><ul class="dummy"><li>
<a href="md5.js.html">md5.js</a>, <a href="md5.js.html#line87">line 87</a>
<a href="md5.js.html">md5.js</a>, <a href="md5.js.html#line101">line 101</a>
</li></ul></dd>
@@ -845,7 +845,7 @@
<dt class="tag-source">Source:</dt>
<dd class="tag-source"><ul class="dummy"><li>
<a href="md5.js.html">md5.js</a>, <a href="md5.js.html#line44">line 44</a>
<a href="md5.js.html">md5.js</a>, <a href="md5.js.html#line58">line 58</a>
</li></ul></dd>
@@ -1012,7 +1012,7 @@
<dt class="tag-source">Source:</dt>
<dd class="tag-source"><ul class="dummy"><li>
<a href="md5.js.html">md5.js</a>, <a href="md5.js.html#line33">line 33</a>
<a href="md5.js.html">md5.js</a>, <a href="md5.js.html#line47">line 47</a>
</li></ul></dd>
@@ -1179,7 +1179,7 @@
<dt class="tag-source">Source:</dt>
<dt class="tag-source">Source:</dt>
<dd class="tag-source"><ul class="dummy"><li>
<a href="md5.js.html">md5.js</a>, <a href="md5.js.html#line109">line 109</a>
</li></ul></dd>
@@ -1254,7 +1254,7 @@
<nav>
<h2><a href="index.html">Home</a></h2><h3>Classes</h3><ul><li><a href="Md5_.html">Md5</a></li></ul><h3>Namespaces</h3><ul><li><a href="md5.html">md5</a></li></ul><h3>Global</h3><ul><li><a href="global.html#md5%2508">md5</a></li></ul>
</nav>
</nav>
<br class="clear">
+45 -12
View File
@@ -30,7 +30,7 @@
* [js-md5]{@link https://github.com/emn178/js-md5}
*
* @namespace md5
* @version 0.4.2
* @version 0.5.0
* @author Chen, Yi-Cyuan [emn178@gmail.com]
* @copyright Chen, Yi-Cyuan 2014-2017
* @license MIT
@@ -38,10 +38,18 @@
(function () {
'use strict';
var root = typeof window === 'object' ? window : {};
var ERROR = 'input is invalid type';
var WINDOW = typeof window === 'object';
var root = WINDOW ? window : {};
if (root.JS_MD5_NO_WINDOW) {
WINDOW = false;
}
var WEB_WORKER = !WINDOW &amp;&amp; typeof self === 'object';
var NODE_JS = !root.JS_MD5_NO_NODE_JS &amp;&amp; typeof process === 'object' &amp;&amp; process.versions &amp;&amp; process.versions.node;
if (NODE_JS) {
root = global;
} else if (WEB_WORKER) {
root = self;
}
var COMMON_JS = !root.JS_MD5_NO_COMMON_JS &amp;&amp; typeof module === 'object' &amp;&amp; module.exports;
var AMD = typeof define === 'function' &amp;&amp; define.amd;
@@ -58,6 +66,12 @@
blocks = new Uint32Array(buffer);
}
if (root.JS_MD5_NO_NODE_JS || !Array.isArray) {
Array.isArray = function (obj) {
return Object.prototype.toString.call(obj) === '[object Array]';
};
}
/**
* @method hex
* @memberof md5
@@ -151,17 +165,24 @@
};
var nodeWrap = function (method) {
var crypto = require('crypto');
var Buffer = require('buffer').Buffer;
var crypto = eval("require('crypto')");
var Buffer = eval("require('buffer').Buffer");
var nodeMethod = function (message) {
if (typeof message === 'string') {
return crypto.createHash('md5').update(message, 'utf8').digest('hex');
} else if (message.constructor === ArrayBuffer) {
message = new Uint8Array(message);
} else if (message.length === undefined) {
} else {
if (message === null || message === undefined) {
throw ERROR;
} else if (message.constructor === ArrayBuffer) {
message = new Uint8Array(message);
}
}
if (Array.isArray(message) || ArrayBuffer.isView(message) ||
message.constructor === Buffer) {
return crypto.createHash('md5').update(new Buffer(message)).digest('hex');
} else {
return method(message);
}
return crypto.createHash('md5').update(new Buffer(message)).digest('hex');
};
return nodeMethod;
};
@@ -208,10 +229,22 @@
return;
}
var notString = typeof(message) != 'string';
if (notString &amp;&amp; message.constructor == root.ArrayBuffer) {
message = new Uint8Array(message);
if (notString) {
if (message === null || message === undefined) {
throw ERROR;
} else if (message.constructor === root.ArrayBuffer) {
message = new Uint8Array(message);
}
}
var code, index = 0, i, length = message.length || 0, blocks = this.blocks;
var length = message.length;
if (notString) {
if (typeof length !== 'number' ||
!Array.isArray(message) &amp;&amp;
!(ARRAY_BUFFER &amp;&amp; ArrayBuffer.isView(message))) {
throw ERROR;
}
}
var code, index = 0, i, blocks = this.blocks;
var buffer8 = this.buffer8;
while (index &lt; length) {
@@ -641,7 +674,7 @@
<br class="clear">
<footer>
Documentation generated by <a href="https://github.com/jsdoc3/jsdoc">JSDoc 3.4.3</a> on Wed Jan 18 2017 09:43:27 GMT+0800 (CST)
Documentation generated by <a href="https://github.com/jsdoc3/jsdoc">JSDoc 3.4.3</a> on Fri Jul 14 2017 12:58:59 GMT+0800 (CST)
</footer>
<script> prettyPrint(); </script>