mirror of https://git.lenooby09.tech/LeNooby09/social-app.git
at profile-init 34 lines 932 B view raw
1export function pluralize(n: number, base: string, plural?: string): string { 2 if (n === 1) { 3 return base 4 } 5 if (plural) { 6 return plural 7 } 8 return base + 's' 9} 10 11export function enforceLen(str: string, len: number, ellipsis = false): string { 12 str = str || '' 13 if (str.length > len) { 14 return str.slice(0, len) + (ellipsis ? '...' : '') 15 } 16 return str 17} 18 19// https://stackoverflow.com/a/52171480 20export function toHashCode(str: string, seed = 0): number { 21 let h1 = 0xdeadbeef ^ seed, 22 h2 = 0x41c6ce57 ^ seed 23 for (let i = 0, ch; i < str.length; i++) { 24 ch = str.charCodeAt(i) 25 h1 = Math.imul(h1 ^ ch, 2654435761) 26 h2 = Math.imul(h2 ^ ch, 1597334677) 27 } 28 h1 = Math.imul(h1 ^ (h1 >>> 16), 2246822507) 29 h1 ^= Math.imul(h2 ^ (h2 >>> 13), 3266489909) 30 h2 = Math.imul(h2 ^ (h2 >>> 16), 2246822507) 31 h2 ^= Math.imul(h1 ^ (h1 >>> 13), 3266489909) 32 33 return 4294967296 * (2097151 & h2) + (h1 >>> 0) 34}