line-counter.d.ts 733 B

12345678910111213141516171819202122
  1. /**
  2. * Tracks newlines during parsing in order to provide an efficient API for
  3. * determining the one-indexed `{ line, col }` position for any offset
  4. * within the input.
  5. */
  6. export declare class LineCounter {
  7. lineStarts: number[];
  8. /**
  9. * Should be called in ascending order. Otherwise, call
  10. * `lineCounter.lineStarts.sort()` before calling `linePos()`.
  11. */
  12. addNewLine: (offset: number) => number;
  13. /**
  14. * Performs a binary search and returns the 1-indexed { line, col }
  15. * position of `offset`. If `line === 0`, `addNewLine` has never been
  16. * called or `offset` is before the first known newline.
  17. */
  18. linePos: (offset: number) => {
  19. line: number;
  20. col: number;
  21. };
  22. }