@amplitude/ampli
Version:
Amplitude CLI
21 lines (20 loc) • 748 B
JavaScript
;
Object.defineProperty(exports, "__esModule", { value: true });
const lodash_1 = require("lodash");
const newRowRegExp = /(\r\n)|\n/g;
class RowColumnInfo {
constructor(text) {
this.rowStartIndexes = [0];
while (newRowRegExp.exec(text) !== null) {
this.rowStartIndexes.push(newRowRegExp.lastIndex);
}
}
atIndex(charIndex) {
const index = lodash_1.sortedIndex(this.rowStartIndexes, charIndex);
if (index <= this.rowStartIndexes.length && this.rowStartIndexes[index] === charIndex) {
return { row: index + 1, column: 1 };
}
return { row: index, column: charIndex - this.rowStartIndexes[index - 1] + 1 };
}
}
exports.default = RowColumnInfo;