locate

tcmts.cli.lint.locate · #vvkfjxkb · term · runs anywhere

line:col of an offset in text (1-based), and the line itself.

export function locate(text: string, offset: number): { line: number; col: number; source: string } {
  const before = text.slice(0, offset).split("\n");
  const line = before.length;
  return { line, col: before.at(-1)!.length + 1, source: text.split("\n")[line - 1] ?? "" };
}

used by