UNPKG

@1771technologies/lytenyte-pro

Version:

Blazingly fast headless React data grid with 100s of features.

18 lines (17 loc) 485 B
import { clampOffset } from "./clamp-offset.js"; const NEWLINE_CODE = 10; export function offsetToPosition(source, offset) { const safeOffset = clampOffset(source, offset); let line = 1; let column = 1; for (let index = 0; index < safeOffset; index++) { if (source.charCodeAt(index) === NEWLINE_CODE) { line++; column = 1; } else { column++; } } return { line, column, offset: safeOffset }; }