interface Config { useUnicode?: boolean } const styleMap: Record = {} let index = 0 const generateUniqueStyleHash = ( value: string, config: Config = { useUnicode: false } ) => { if (styleMap[value]) return styleMap[value] let { useUnicode } = config let hash = '' let localindex = index let genDivisor = () => 52 ** hash.length let genDecrement = () => 52 ** (hash.length + 1) if (useUnicode) { // Skip single and double quotation let pointer = parseInt( `0x${28 + Object.getOwnPropertyNames(styleMap).length}` ) hash = String.fromCodePoint(pointer) } else { while (localindex >= 0) { let charCode = Math.floor(localindex / genDivisor()) % 52 localindex = localindex - genDecrement() // a-z and A-Z otherwise start new className if (charCode < 26) hash += String.fromCharCode(97 + charCode) else hash += String.fromCharCode(65 + charCode - 26) } hash = hash.split('').reverse().join('') } styleMap[value] = hash index++ return hash } const generateUnicode = (value: string) => generateUniqueStyleHash(value, { useUnicode: true }) // @ts-ignore export = generateUniqueStyleHash export default generateUniqueStyleHash