Something went wrong. Try again.
[READ-ONLY] Mirror of https://github.com/samualtnorman/lib. A collection of common utilities I need. www.npmjs.com/package/@samual/lib
Something went wrong. Try again.
1234567891011export function positionToLine(positionIndex: number, string: string): number { for (const [ lineNumber, { length } ] of string.split(`\n`).entries()) { positionIndex -= length + 1
if (positionIndex < 0) return lineNumber + 1 }
throw Error(`\`positionIndex\` must be smaller than \`string\`'s length`)}