```ts
/** A word-to-line index for a plain-text note. */

export function wordsOfLine(line: string): string[] {
  const runs = line.toLowerCase().match(/[a-z0-9]+/g);
  if (runs === null) {
    return [];
  }
  return runs;
}

export function buildWordIndex(text: string): Record<string, number[]> {
  if (typeof text !== 'string') {
    throw new Error('Input must be a string');
  }

  const index: Record<string, number[]> = {};
  const rows = text.split("\n");
  for (let row = 1; row <= rows.length; row++) {
    for (const word of wordsOfLine(rows[row - 1])) {
      if (!index[word]) {
        index[word] = [];
      }
      // Use a Set to ensure each line number is unique per word
      const uniqueLines = new Set(index[word]);
      uniqueLines.add(row);
      index[word] = Array.from(uniqueLines);
    }
  }
  return index;
}
```