@jossmac/lil-libs
    Preparing search index...

    Function createDeterministicKeySelector

    • Creates a function that maps each input string to a key from keys using a stable hash, so the same input always selects the same key.

      Preserves literal key types (for as const arrays). Empty input strings are supported.

      • const T extends readonly string[]
      • keys: T

        Non-empty list of string keys to choose from. The same input string always maps to the same key via a stable hash.

      A function (value: string) => T[number] that picks a key from keys deterministically.

      const colors = ["red", "green", "blue"] as const;
      const getColor = createDeterministicKeySelector(colors);

      getColor("Albert"); // "blue"
      getColor("Barbara"); // "green"
      getColor("Charlie"); // "red"
      getColor("Albert"); // "blue" (stable across calls)

      If called with an empty keys array.