access-sniff
Version:
A node/iojs library & CLI for HTML_Codesniffer
33 lines (24 loc) • 840 B
JavaScript
Object.defineProperty(exports, "__esModule", {
value: true
});
var startOfLineIndex = function startOfLineIndex(lines, line) {
var x = lines.slice(0);
x.splice(line - 1);
return x.join('\n').length + (x.length > 0);
};
var getLineFromPos = function getLineFromPos(content, index) {
var lines = content.split('\n');
var lineNumber = content.substr(0, index).split('\n').length;
var columnNumber = index - startOfLineIndex(lines, lineNumber);
if (columnNumber < 0) {
columnNumber = 0;
}
return { lineNumber: lineNumber, columnNumber: columnNumber };
};
var getElementPosition = function getElementPosition(htmlString, fileContents) {
var index = fileContents.indexOf(htmlString);
var position = getLineFromPos(fileContents, index);
return position;
};
exports.default = getElementPosition;
;