charNgrams function

Last updated: 2026-02-24T19:46:21.733Z

Metrics

LOC: 15 Complexity: 2 Params: 1

Signature

charNgrams(text: string): : string[]

Source Code

function charNgrams(text: string): string[] {
  const normalized = text
    .toLowerCase()
    .normalize("NFD")
    .replace(/[\u0300-\u036f]/g, "")
    .replace(/[_\-/.]+/g, " ")
    .replace(/\s+/g, " ")
    .trim();
  const padded = `_${normalized}_`;
  const result: string[] = [];
  for (let i = 0; i <= padded.length - NGRAM_SIZE; i++) {
    result.push(padded.slice(i, i + NGRAM_SIZE));
  }
  return result;
}

No outgoing dependencies.

No incoming dependencies.