solutaaliquid
Version:
common utils for javascript. Utils to get the global scope (browser, webworker & co.). Customizable string escaper. Utilitize for objects. Extension at base javascript api (usefull extention like String.hashcode()).
14 lines (13 loc) • 331 B
JavaScript
if (!String.prototype.hashcode)
String.prototype.hashcode = function() {
if (this.length === 0)
return 0;
let hash = 0;
const length = this.length;
for (let i = 0; i < length; i++) {
const c = this.charCodeAt(i);
hash = ((hash << 5) - hash) + c;
hash |= 0; // Convert to 32bit integer
}
return hash;
};