ChemPal Documentation - v0.0.13-beta.5
    Preparing search index...

    Function generateSimpleHash

    • Generates a simple hash from a string using the djb2 algorithm. This is a non-cryptographic hash function suitable for request identification.

      Parameters

      • str: string

        The string to hash

      Returns string

      A hexadecimal string representing the hash

      const hash = generateSimpleHash("test string");
      console.log(hash); // "a5d7d2a9"
      export function generateSimpleHash(str: string): string {
      let hash = 0;
      for (let i = 0; i < str.length; i++) {
      const char = str.charCodeAt(i);
      hash = (hash << 5) - hash + char;
      hash = hash & hash; // Convert to 32bit integer
      }
      return Math.abs(hash).toString(16);
      }