Repository URL to install this package:
|
Version:
5.0.0-rc.15 ▾
|
<!doctype html>
<html lang="en">
<head>
<title>Code coverage report for src/containers/I18NProvider/hash.js</title>
<meta charset="utf-8" />
<link rel="stylesheet" href="../../../prettify.css" />
<link rel="stylesheet" href="../../../base.css" />
<meta name="viewport" content="width=device-width, initial-scale=1">
<style type='text/css'>
.coverage-summary .sorter {
background-image: url(../../../sort-arrow-sprite.png);
}
</style>
</head>
<body>
<div class='wrapper'>
<div class='pad1'>
<h1>
<a href="../../../index.html">All files</a> / <a href="index.html">src/containers/I18NProvider</a> hash.js
</h1>
<div class='clearfix'>
</div>
</div>
<div class='status-line low'></div>
<pre><table class="coverage">
<tr><td class="line-count quiet">1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23</td><td class="line-coverage quiet"><span class="cline-any cline-neutral"> </span>
<span class="cline-any cline-neutral"> </span>
<span class="cline-any cline-neutral"> </span>
<span class="cline-any cline-neutral"> </span>
<span class="cline-any cline-neutral"> </span>
<span class="cline-any cline-neutral"> </span>
<span class="cline-any cline-neutral"> </span>
<span class="cline-any cline-neutral"> </span>
<span class="cline-any cline-neutral"> </span>
<span class="cline-any cline-no"> </span>
<span class="cline-any cline-no"> </span>
<span class="cline-any cline-neutral"> </span>
<span class="cline-any cline-no"> </span>
<span class="cline-any cline-no"> </span>
<span class="cline-any cline-neutral"> </span>
<span class="cline-any cline-no"> </span>
<span class="cline-any cline-neutral"> </span>
<span class="cline-any cline-no"> </span>
<span class="cline-any cline-neutral"> </span>
<span class="cline-any cline-neutral"> </span>
<span class="cline-any cline-no"> </span>
<span class="cline-any cline-neutral"> </span>
<span class="cline-any cline-neutral"> </span></td><td class="text"><pre class="prettyprint lang-js">/**
* Generate a 32bit integer hash for a given string
* Sources:
* - http://werxltd.com/wp/2010/05/13/javascript-implementation-of-javas-string-hashcode-method/
* - https://stackoverflow.com/questions/194846/is-there-any-kind-of-hash-code-function-in-javascript/8076436#8076436
* - https://gist.github.com/hyamamoto/fd435505d29ebfa3d9716fd2be8d42f0
* - https://en.wikipedia.org/wiki/Java_hashCode()
*/
export default str => {
let hash = <span class="cstat-no" title="statement not covered" >0;</span>
<span class="cstat-no" title="statement not covered" > if (str.length === 0) <span class="cstat-no" title="statement not covered" >r</span>eturn hash;</span>
<span class="cstat-no" title="statement not covered" > for (let i = 0; i < str.length; i += 1) {</span>
const char = <span class="cstat-no" title="statement not covered" >str.charCodeAt(i);</span>
// eslint-disable-next-line no-bitwise
<span class="cstat-no" title="statement not covered" > hash = (hash << 5) - hash + char;</span>
// eslint-disable-next-line no-bitwise
<span class="cstat-no" title="statement not covered" > hash &= hash; // Convert to 32bit integer</span>
}
<span class="cstat-no" title="statement not covered" > return hash;</span>
};
</pre></td></tr>
</table></pre>
<div class='push'></div><!-- for sticky footer -->
</div><!-- /wrapper -->
<div class='footer quiet pad2 space-top1 center small'>
Code coverage
generated by <a href="https://istanbul.js.org/" target="_blank">istanbul</a> at Tue Jul 28 2020 14:07:09 GMT+0200 (Central European Summer Time)
</div>
</div>
<script src="../../../prettify.js"></script>
<script>
window.onload = function () {
if (typeof prettyPrint === 'function') {
prettyPrint();
}
};
</script>
<script src="../../../sorter.js"></script>
</body>
</html>