textConvert
    Preparing search index...

    Function wordFrequency

    • Counts how many times each word appears in a piece of text. Case-insensitive by default -- "The" and "the" count as the same word, since this reuses clear()'s existing lowercasing/punctuation-stripping split rather than a separate tokenizer.

      Parameters

      • text: string

        Text to count word frequency in.

      Returns Record<string, number>

      A map of each distinct word to how many times it appears, in the order each word first appeared.

      wordFrequency('the cat sat on the mat');
      // { the: 2, cat: 1, sat: 1, on: 1, mat: 1 }