coffee-coverage
Version:
Istanbul and JSCoverage-style instrumentation for CoffeeScript files.
42 lines (38 loc) • 1.17 kB
JavaScript
// Generated by CoffeeScript 2.3.2
(function() {
// Takes the contents of a file and returns an array of lines.
// `source` is a string containing an entire file.
exports.fileToLines = function(source) {
var dataWithFixedLfs;
dataWithFixedLfs = source.replace(/\r\n/g, '\n').replace(/\r/g, '\n');
return dataWithFixedLfs.split("\n");
};
// Where `a` and `b` are `{line, column}` objects, return -1 if a < b, 0 if a == b, 1 is a > b.
exports.compareLocations = function(a, b) {
if (a.line < b.line) {
return -1;
} else if (a.line > b.line) {
return 1;
} else if (a.column < b.column) {
return -1;
} else if (a.column > b.column) {
return 1;
} else {
return 0;
}
};
// Given an array of `{line, column}` objects, returns the one that occurs earliest in the document.
exports.minLocation = function(locations) {
var min;
if (!locations || locations.length === 0) {
return null;
}
min = locations[0];
locations.forEach(function(loc) {
if (exports.compareLocations(loc, min) < 0) {
return min = loc;
}
});
return min;
};
}).call(this);