UNPKG

@alwatr/hash-string

Version:
5 lines (4 loc) 1.64 kB
/** 📦 @alwatr/hash-string v5.2.17 */ __dev_mode__: console.debug("📦 @alwatr/hash-string v5.2.17"); "use strict";var __defProp=Object.defineProperty;var __getOwnPropDesc=Object.getOwnPropertyDescriptor;var __getOwnPropNames=Object.getOwnPropertyNames;var __hasOwnProp=Object.prototype.hasOwnProperty;var __export=(target,all)=>{for(var name in all)__defProp(target,name,{get:all[name],enumerable:true})};var __copyProps=(to,from,except,desc)=>{if(from&&typeof from==="object"||typeof from==="function"){for(let key of __getOwnPropNames(from))if(!__hasOwnProp.call(to,key)&&key!==except)__defProp(to,key,{get:()=>from[key],enumerable:!(desc=__getOwnPropDesc(from,key))||desc.enumerable})}return to};var __toCommonJS=mod=>__copyProps(__defProp({},"__esModule",{value:true}),mod);var main_exports={};__export(main_exports,{nanoHash:()=>nanoHash});module.exports=__toCommonJS(main_exports);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)}}0&&(module.exports={nanoHash}); //# sourceMappingURL=main.cjs.map