Fixed `root` is undefined in some special environment. #7

pull/7/merge v0.4.2
Chen, Yi-Cyuan 9 years ago
parent da009f933f
commit 8b9a23ce32

@ -1,2 +1,2 @@
/node_modules/
/tests/
node_modules/

4
.gitignore vendored

@ -1,2 +1,2 @@
covreporter
node_modules
/node_modules/
/covreporter/

@ -1,10 +1,8 @@
language: node_js
node_js:
- "4.1"
- "4.0"
- "0.12"
- "0.11"
- "0.10"
- "0.12.15"
- "4.5"
- "6.5.0"
before_install:
- npm install coveralls
- npm install mocha-lcov-reporter

@ -1,54 +1,66 @@
# v0.4.1 / 2016-03-31
* Removed length detection in node.js.
* Deprecated `buffer` and replace by `arrayBuffer`.
# v0.4.0 / 2015-12-28
* Added support for update hash.
* Added support for bytes array output.
* Added support for ArrayBuffer output.
* Added support for AMD.
# v0.3.0 / 2015-03-07
* Support byte Array, Uint8Array and ArrayBuffer input.
# v0.2.2 / 2015-02-01
* Fixed bug when special length.
* Improve performance for node.js.
# v0.2.1 / 2015-01-13
* Improve performance.
# v0.2.0 / 2015-01-12
* Remove ascii parameter.
* Improve performance.
# v0.1.4 / 2015-01-11
* Improve performance.
* Add test case.
# v0.1.3 / 2015-01-05
* Improve performance.
* Add bower package.
* Fixed JSHint warnings.
* Add travis.
* Add coveralls.
# v0.1.2 / 2014-07-27
Fixed accents bug
# v0.1.1 / 2014-01-05
Update license
# v0.1.0 / 2014-01-04
Initial release
# Change Log
## v0.4.2 / 2017-01-18
### Fixed
- `root` is undefined in some special environment. #7
## v0.4.1 / 2016-03-31
### Removed
- length detection in node.js.
### Deprecated
- `buffer` and replace by `arrayBuffer`.
## v0.4.0 / 2015-12-28
### Added
- support for update hash.
- support for bytes array output.
- support for ArrayBuffer output.
- support for AMD.
## v0.3.0 / 2015-03-07
### Added
- support byte Array, Uint8Array and ArrayBuffer input.
## v0.2.2 / 2015-02-01
### Fixed
- bug when special length.
### Improve
- performance for node.js.
## v0.2.1 / 2015-01-13
### Improve
- performance.
## v0.2.0 / 2015-01-12
### Removed
- ascii parameter.
### Improve
- performance.
## v0.1.4 / 2015-01-11
### Improve
- performance.
### Added
- test cases.
## v0.1.3 / 2015-01-05
### Added
- bower package.
- travis.
- coveralls.
### Improved
- performance.
### Fixed
- JSHint warnings.
## v0.1.2 / 2014-07-27
### Fixed
- accents bug
## v0.1.1 / 2014-01-05
### Changed
- license
## v0.1.0 / 2014-01-04
### Added
- initial release

@ -1,4 +1,4 @@
Copyright 2014-2016 Chen, Yi-Cyuan
Copyright 2014-2017 Chen, Yi-Cyuan
Permission is hereby granted, free of charge, to any person obtaining
a copy of this software and associated documentation files (the

@ -67,10 +67,6 @@ md5.arrayBuffer(''); // ArrayBuffer
md5.buffer(''); // ArrayBuffer, deprecated, This maybe confuse with Buffer in node.js. Please use arrayBuffer instead.
```
## Benchmark
[UTF8](http://jsperf.com/md5-shootout/81)
[ASCII](http://jsperf.com/md5-shootout/82)
## License
The project is released under the [MIT license](http://www.opensource.org/licenses/MIT).

@ -1,6 +1,6 @@
{
"name": "js-md5",
"version": "0.4.1",
"version": "0.4.2",
"main": ["src/md5.js"],
"ignore": [
"tests"

6
build/md5.min.js vendored

File diff suppressed because one or more lines are too long

@ -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#line149">line 149</a>
<a href="md5.js.html">md5.js</a>, <a href="md5.js.html#line141">line 141</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#line531">line 531</a>
<a href="md5.js.html">md5.js</a>, <a href="md5.js.html#line523">line 523</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#line543">line 543</a>
<a href="md5.js.html">md5.js</a>, <a href="md5.js.html#line535">line 535</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#line565">line 565</a>
<a href="md5.js.html">md5.js</a>, <a href="md5.js.html#line557">line 557</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#line509">line 509</a>
<a href="md5.js.html">md5.js</a>, <a href="md5.js.html#line501">line 501</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#line464">line 464</a>
<a href="md5.js.html">md5.js</a>, <a href="md5.js.html#line456">line 456</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#line497">line 497</a>
<a href="md5.js.html">md5.js</a>, <a href="md5.js.html#line489">line 489</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#line177">line 177</a>
<a href="md5.js.html">md5.js</a>, <a href="md5.js.html#line169">line 169</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.0</a> on Thu Mar 31 2016 16:24:21 GMT+0800 (CST)
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)
</footer>
<script> prettyPrint(); </script>

@ -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#line583">line 583</a>
<a href="md5.js.html">md5.js</a>, <a href="md5.js.html#line575">line 575</a>
</li></ul></dd>
@ -285,7 +285,7 @@
<br class="clear">
<footer>
Documentation generated by <a href="https://github.com/jsdoc3/jsdoc">JSDoc 3.4.0</a> on Thu Mar 31 2016 16:24:21 GMT+0800 (CST)
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)
</footer>
<script> prettyPrint(); </script>

@ -77,8 +77,7 @@ md5.hex(''); // d41d8cd98f00b204e9800998ecf8427e
md5.array(''); // [212, 29, 140, 217, 143, 0, 178, 4, 233, 128, 9, 152, 236, 248, 66, 126]
md5.digest(''); // [212, 29, 140, 217, 143, 0, 178, 4, 233, 128, 9, 152, 236, 248, 66, 126]
md5.arrayBuffer(''); // ArrayBuffer
md5.buffer(''); // ArrayBuffer, deprecated, This maybe confuse with Buffer in node.js. Please use arrayBuffer instead.</code></pre><h2>Benchmark</h2><p><a href="http://jsperf.com/md5-shootout/81">UTF8</a><br><a href="http://jsperf.com/md5-shootout/82">ASCII</a></p>
<h2>License</h2><p>The project is released under the <a href="http://www.opensource.org/licenses/MIT">MIT license</a>.</p>
md5.buffer(''); // ArrayBuffer, deprecated, This maybe confuse with Buffer in node.js. Please use arrayBuffer instead.</code></pre><h2>License</h2><p>The project is released under the <a href="http://www.opensource.org/licenses/MIT">MIT license</a>.</p>
<h2>Contact</h2><p>The project's website is located at https://github.com/emn178/js-md5<br>Author: Chen, Yi-Cyuan (emn178@gmail.com)</p></article>
</section>
@ -96,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.0</a> on Thu Mar 31 2016 16:24:21 GMT+0800 (CST)
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)
</footer>
<script> prettyPrint(); </script>

@ -47,7 +47,7 @@
<dt class="tag-version">Version:</dt>
<dd class="tag-version"><ul class="dummy"><li>0.4.0</li></ul></dd>
<dd class="tag-version"><ul class="dummy"><li>0.4.2</li></ul></dd>
@ -75,7 +75,7 @@
<dt class="tag-copyright">Copyright:</dt>
<dd class="tag-copyright"><ul class="dummy"><li>Chen, Yi-Cyuan 2014-2016</li></ul></dd>
<dd class="tag-copyright"><ul class="dummy"><li>Chen, Yi-Cyuan 2014-2017</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#line52">line 52</a>
<a href="md5.js.html">md5.js</a>, <a href="md5.js.html#line53">line 53</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#line61">line 61</a>
<a href="md5.js.html">md5.js</a>, <a href="md5.js.html#line62">line 62</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#line70">line 70</a>
<a href="md5.js.html">md5.js</a>, <a href="md5.js.html#line71">line 71</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#line86">line 86</a>
<a href="md5.js.html">md5.js</a>, <a href="md5.js.html#line87">line 87</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#line43">line 43</a>
<a href="md5.js.html">md5.js</a>, <a href="md5.js.html#line44">line 44</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#line32">line 32</a>
<a href="md5.js.html">md5.js</a>, <a href="md5.js.html#line33">line 33</a>
</li></ul></dd>
@ -1179,7 +1179,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#line94">line 94</a>
<a href="md5.js.html">md5.js</a>, <a href="md5.js.html#line95">line 95</a>
</li></ul></dd>
@ -1254,7 +1254,7 @@
<br class="clear">
<footer>
Documentation generated by <a href="https://github.com/jsdoc3/jsdoc">JSDoc 3.4.0</a> on Thu Mar 31 2016 16:24:21 GMT+0800 (CST)
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)
</footer>
<script> prettyPrint(); </script>

@ -30,21 +30,22 @@
* [js-md5]{@link https://github.com/emn178/js-md5}
*
* @namespace md5
* @version 0.4.0
* @version 0.4.2
* @author Chen, Yi-Cyuan [emn178@gmail.com]
* @copyright Chen, Yi-Cyuan 2014-2016
* @copyright Chen, Yi-Cyuan 2014-2017
* @license MIT
*/
(function (root) {
(function () {
'use strict';
var NODE_JS = typeof process == 'object' &amp;&amp; process.versions &amp;&amp; process.versions.node;
var root = typeof window === 'object' ? window : {};
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;
}
var COMMON_JS = !root.JS_MD5_TEST &amp;&amp; typeof module == 'object' &amp;&amp; module.exports;
var AMD = typeof define == 'function' &amp;&amp; define.amd;
var ARRAY_BUFFER = !root.JS_MD5_TEST &amp;&amp; typeof ArrayBuffer != 'undefined';
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;
var ARRAY_BUFFER = !root.JS_MD5_NO_ARRAY_BUFFER &amp;&amp; typeof ArrayBuffer !== 'undefined';
var HEX_CHARS = '0123456789abcdef'.split('');
var EXTRA = [128, 32768, 8388608, -2147483648];
var SHIFT = [0, 8, 16, 24];
@ -150,21 +151,12 @@
};
var nodeWrap = function (method) {
var crypto, Buffer;
try {
if (root.JS_MD5_TEST) {
throw 'JS_MD5_TEST';
}
crypto = require('crypto');
Buffer = require('buffer').Buffer;
} catch (e) {
console.log(e);
return method;
}
var crypto = require('crypto');
var Buffer = require('buffer').Buffer;
var nodeMethod = function (message) {
if (typeof message == 'string') {
if (typeof message === 'string') {
return crypto.createHash('md5').update(message, 'utf8').digest('hex');
} else if (message.constructor == ArrayBuffer) {
} else if (message.constructor === ArrayBuffer) {
message = new Uint8Array(message);
} else if (message.length === undefined) {
return method(message);
@ -632,7 +624,7 @@
});
}
}
}(this));
})();
</code></pre>
</article>
</section>
@ -649,7 +641,7 @@
<br class="clear">
<footer>
Documentation generated by <a href="https://github.com/jsdoc3/jsdoc">JSDoc 3.4.0</a> on Thu Mar 31 2016 16:24:20 GMT+0800 (CST)
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)
</footer>
<script> prettyPrint(); </script>

@ -153,7 +153,7 @@ h1
margin: 12px 24px 20px;
}
h2, h3
h2, h3.subsection-title
{
font-size: 30px;
font-weight: 700;
@ -161,6 +161,13 @@ h2, h3
margin-bottom: 12px;
}
h3
{
font-size: 24px;
letter-spacing: -0.5px;
margin-bottom: 12px;
}
h4
{
font-size: 18px;
@ -185,6 +192,32 @@ h6
font-style: italic;
}
table
{
border-spacing: 0;
border: 0;
border-collapse: collapse;
}
td, th
{
border: 1px solid #ddd;
margin: 0px;
text-align: left;
vertical-align: top;
padding: 4px 6px;
display: table-cell;
}
thead tr
{
background-color: #ddd;
font-weight: bold;
}
th { border-right: 1px solid #aaa; }
tr > th:last-child { border-right: 1px solid #ddd; }
.ancestors { color: #999; }
.ancestors a
{
@ -296,44 +329,12 @@ h6
user-select: text;
}
.params, .props
{
border-spacing: 0;
border: 0;
border-collapse: collapse;
}
.params .name, .props .name, .name code {
color: #4D4E53;
font-family: Consolas, Monaco, 'Andale Mono', monospace;
font-size: 100%;
}
.params td, .params th, .props td, .props th
{
border: 1px solid #ddd;
margin: 0px;
text-align: left;
vertical-align: top;
padding: 4px 6px;
display: table-cell;
}
.params thead tr, .props thead tr
{
background-color: #ddd;
font-weight: bold;
}
.params .params thead tr, .props .props thead tr
{
background-color: #fff;
font-weight: bold;
}
.params th, .props th { border-right: 1px solid #aaa; }
.params thead .last, .props thead .last { border-right: 1px solid #ddd; }
.params td.description > p:first-child,
.props td.description > p:first-child
{

@ -1,6 +1,6 @@
{
"name": "js-md5",
"version": "0.4.1",
"version": "0.4.2",
"description": "A simple MD5 hash function for JavaScript supports UTF-8 encoding.",
"main": "src/md5.js",
"devDependencies": {

@ -2,21 +2,22 @@
* [js-md5]{@link https://github.com/emn178/js-md5}
*
* @namespace md5
* @version 0.4.1
* @version 0.4.2
* @author Chen, Yi-Cyuan [emn178@gmail.com]
* @copyright Chen, Yi-Cyuan 2014-2016
* @copyright Chen, Yi-Cyuan 2014-2017
* @license MIT
*/
(function (root) {
(function () {
'use strict';
var NODE_JS = typeof process == 'object' && process.versions && process.versions.node;
var root = typeof window === 'object' ? window : {};
var NODE_JS = !root.JS_MD5_NO_NODE_JS && typeof process === 'object' && process.versions && process.versions.node;
if (NODE_JS) {
root = global;
}
var COMMON_JS = !root.JS_MD5_TEST && typeof module == 'object' && module.exports;
var AMD = typeof define == 'function' && define.amd;
var ARRAY_BUFFER = !root.JS_MD5_TEST && typeof ArrayBuffer != 'undefined';
var COMMON_JS = !root.JS_MD5_NO_COMMON_JS && typeof module === 'object' && module.exports;
var AMD = typeof define === 'function' && define.amd;
var ARRAY_BUFFER = !root.JS_MD5_NO_ARRAY_BUFFER && typeof ArrayBuffer !== 'undefined';
var HEX_CHARS = '0123456789abcdef'.split('');
var EXTRA = [128, 32768, 8388608, -2147483648];
var SHIFT = [0, 8, 16, 24];
@ -122,21 +123,12 @@
};
var nodeWrap = function (method) {
var crypto, Buffer;
try {
if (root.JS_MD5_TEST) {
throw 'JS_MD5_TEST';
}
crypto = require('crypto');
Buffer = require('buffer').Buffer;
} catch (e) {
console.log(e);
return method;
}
var crypto = require('crypto');
var Buffer = require('buffer').Buffer;
var nodeMethod = function (message) {
if (typeof message == 'string') {
if (typeof message === 'string') {
return crypto.createHash('md5').update(message, 'utf8').digest('hex');
} else if (message.constructor == ArrayBuffer) {
} else if (message.constructor === ArrayBuffer) {
message = new Uint8Array(message);
} else if (message.length === undefined) {
return method(message);
@ -604,4 +596,4 @@
});
}
}
}(this));
})();

@ -1,12 +1,38 @@
md5 = require('../src/md5.js');
// Node.js env
expect = require('expect.js');
md5 = require('../src/md5.js');
require('./test.js');
delete require.cache[require.resolve('../src/md5.js')]
delete require.cache[require.resolve('./test.js')]
md5 = null
JS_MD5_TEST = true;
// Webpack browser env
JS_MD5_NO_NODE_JS = true;
window = global;
md5 = require('../src/md5.js');
require('./test.js');
delete require.cache[require.resolve('../src/md5.js')];
delete require.cache[require.resolve('./test.js')];
md5 = null;
// browser env
JS_MD5_NO_NODE_JS = true;
JS_MD5_NO_COMMON_JS = true;
window = global;
require('../src/md5.js');
require('./test.js');
delete require.cache[require.resolve('../src/md5.js')];
delete require.cache[require.resolve('./test.js')];
md5 = null;
// browser env and no array buffer
JS_MD5_NO_NODE_JS = true;
JS_MD5_NO_COMMON_JS = true;
JS_MD5_NO_ARRAY_BUFFER = true;
window = global;
require('../src/md5.js');
require('./test.js');
@ -14,6 +40,11 @@ delete require.cache[require.resolve('../src/md5.js')];
delete require.cache[require.resolve('./test.js')];
md5 = null;
// browser AMD
JS_MD5_NO_NODE_JS = true;
JS_MD5_NO_COMMON_JS = true;
JS_MD5_NO_ARRAY_BUFFER = false;
window = global;
define = function (func) {
md5 = func();
require('./test.js');

Loading…
Cancel
Save