mirror of
https://github.com/jashkenas/coffeescript.git
synced 2022-11-09 12:23:24 -05:00
128 lines
3.1 KiB
JavaScript
128 lines
3.1 KiB
JavaScript
// Generated by CoffeeScript 1.5.0
|
|
(function() {
|
|
var buildLocationData, extend, flatten, _ref;
|
|
|
|
exports.starts = function(string, literal, start) {
|
|
return literal === string.substr(start, literal.length);
|
|
};
|
|
|
|
exports.ends = function(string, literal, back) {
|
|
var len;
|
|
len = literal.length;
|
|
return literal === string.substr(string.length - len - (back || 0), len);
|
|
};
|
|
|
|
exports.repeat = function(string, n) {
|
|
return (Array(n + 1)).join(string);
|
|
};
|
|
|
|
exports.compact = function(array) {
|
|
var item, _i, _len, _results;
|
|
_results = [];
|
|
for (_i = 0, _len = array.length; _i < _len; _i++) {
|
|
item = array[_i];
|
|
if (item) {
|
|
_results.push(item);
|
|
}
|
|
}
|
|
return _results;
|
|
};
|
|
|
|
exports.count = function(string, substr) {
|
|
var num, pos;
|
|
num = pos = 0;
|
|
if (!substr.length) {
|
|
return 1 / 0;
|
|
}
|
|
while (pos = 1 + string.indexOf(substr, pos)) {
|
|
num++;
|
|
}
|
|
return num;
|
|
};
|
|
|
|
exports.merge = function(options, overrides) {
|
|
return extend(extend({}, options), overrides);
|
|
};
|
|
|
|
extend = exports.extend = function(object, properties) {
|
|
var key, val;
|
|
for (key in properties) {
|
|
val = properties[key];
|
|
object[key] = val;
|
|
}
|
|
return object;
|
|
};
|
|
|
|
exports.flatten = flatten = function(array) {
|
|
var element, flattened, _i, _len;
|
|
flattened = [];
|
|
for (_i = 0, _len = array.length; _i < _len; _i++) {
|
|
element = array[_i];
|
|
if (element instanceof Array) {
|
|
flattened = flattened.concat(flatten(element));
|
|
} else {
|
|
flattened.push(element);
|
|
}
|
|
}
|
|
return flattened;
|
|
};
|
|
|
|
exports.del = function(obj, key) {
|
|
var val;
|
|
val = obj[key];
|
|
delete obj[key];
|
|
return val;
|
|
};
|
|
|
|
exports.last = function(array, back) {
|
|
return array[array.length - (back || 0) - 1];
|
|
};
|
|
|
|
exports.some = (_ref = Array.prototype.some) != null ? _ref : function(fn) {
|
|
var e, _i, _len;
|
|
for (_i = 0, _len = this.length; _i < _len; _i++) {
|
|
e = this[_i];
|
|
if (fn(e)) {
|
|
return true;
|
|
}
|
|
}
|
|
return false;
|
|
};
|
|
|
|
buildLocationData = function(first, last) {
|
|
if (!last) {
|
|
return first;
|
|
} else {
|
|
return {
|
|
first_line: first.first_line,
|
|
first_column: first.first_column,
|
|
last_line: last.last_line,
|
|
last_column: last.last_column
|
|
};
|
|
}
|
|
};
|
|
|
|
exports.addLocationDataFn = function(first, last) {
|
|
return function(obj) {
|
|
if (((typeof obj) === 'object') && (!!obj['updateLocationDataIfMissing'])) {
|
|
obj.updateLocationDataIfMissing(buildLocationData(first, last));
|
|
}
|
|
return obj;
|
|
};
|
|
};
|
|
|
|
exports.locationDataToString = function(obj) {
|
|
var locationData;
|
|
if (("2" in obj) && ("first_line" in obj[2])) {
|
|
locationData = obj[2];
|
|
} else if ("first_line" in obj) {
|
|
locationData = obj;
|
|
}
|
|
if (locationData) {
|
|
return ("" + (locationData.first_line + 1) + ":" + (locationData.first_column + 1) + "-") + ("" + (locationData.last_line + 1) + ":" + (locationData.last_column + 1));
|
|
} else {
|
|
return "No location data";
|
|
}
|
|
};
|
|
|
|
}).call(this);
|