@alwatr/hash-string
Version:
A simple utility to generate a hash string.
5 lines (4 loc) • 835 B
JavaScript
/** 📦 @alwatr/hash-string v5.2.17 */
__dev_mode__: console.debug("📦 @alwatr/hash-string v5.2.17");
function nanoHash(str,prefix,repeat=1){if(repeat<1){throw new Error("The repeat parameter must be greater than or equal to 1")}let hash1=3735928559;let hash2=1103547991;if(typeof str==="number"){str=str.toString()}const len=str.length;for(let i=0;i<len;i++){const char=str.charCodeAt(i);hash1=Math.imul(hash1^char,2654435761);hash2=Math.imul(hash2^char,1597334677)}hash1=Math.imul(hash1^hash1>>>16,2246822507)^Math.imul(hash2^hash2>>>13,3266489909);hash2=Math.imul(hash2^hash2>>>16,2246822507)^Math.imul(hash1^hash1>>>13,3266489909);const result=prefix+(hash1>>>0).toString(36)+(hash2>>>0).toString(36);if(repeat===1){return result}else{return nanoHash(result,prefix,repeat-1)}}export{nanoHash};
//# sourceMappingURL=main.mjs.map