prettier/src/utils/line-column-to-index.js

14 lines
303 B
JavaScript

"use strict";
// Super inefficient, needs to be cached.
module.exports = function(lineColumn, text) {
let index = 0;
for (let i = 0; i < lineColumn.line - 1; ++i) {
index = text.indexOf("\n", index) + 1;
if (index === -1) {
return -1;
}
}
return index + lineColumn.column;
};