@utilify/crypto
Version:
These functions are useful for ensuring data security and integrity in web and back-end applications.
2 lines (1 loc) • 695 B
JavaScript
function e(e){let n=5381;for(let t=0;t<e.length;t++)n=33*n^e.charCodeAt(t);return String(n>>>0)}function n(){return"undefined"!=typeof global&&"undefined"!=typeof process||"object"==typeof Deno&&Object.hasOwn(Deno,"version")||"object"==typeof Bun&&Object.hasOwn(Bun,"version")||"undefined"==typeof window}async function t(e,t,r="buffer"){if(n())return;const o="string"==typeof e?(new TextEncoder).encode(e):e,i=await crypto.subtle.digest(t,o);return"base64"===r?btoa(String.fromCharCode(...new Uint8Array(i))):"hex"===r?Array.from(new Uint8Array(i)).map((e=>e.toString(16).padStart(2,"0"))).join(""):i}function r(){if(!n())return crypto.randomUUID()}export{e as djb2,t as hash,r as randomUUID};