INNER CODE UNIT · TypeScript
getLineFromPos
pgilad/leasot · src/lib/utils/index.ts:7
export const getLineFromPos = (str: string, pos: number) => {
if (pos === 0) {
return 1;
}
//adjust for negative pos
if (pos < 0) {
pos = str.length + pos;
}
const lines = eol.split(str.substr(0, pos));
return lines.length;
};