2012-10-23 20:45:31 +00:00
|
|
|
// Generated by CoffeeScript 1.4.0
|
2010-07-25 07:15:12 +00:00
|
|
|
(function() {
|
2012-11-15 20:35:01 +00:00
|
|
|
var buildLocationData, extend, flatten, _ref;
|
2011-09-18 22:16:39 +00:00
|
|
|
|
2010-09-25 00:29:44 +00:00
|
|
|
exports.starts = function(string, literal, start) {
|
2010-09-25 00:18:47 +00:00
|
|
|
return literal === string.substr(start, literal.length);
|
|
|
|
};
|
2011-09-18 22:16:39 +00:00
|
|
|
|
2010-09-25 00:29:44 +00:00
|
|
|
exports.ends = function(string, literal, back) {
|
2010-09-26 14:28:48 +00:00
|
|
|
var len;
|
|
|
|
len = literal.length;
|
|
|
|
return literal === string.substr(string.length - len - (back || 0), len);
|
2010-09-25 00:18:47 +00:00
|
|
|
};
|
2011-09-18 22:16:39 +00:00
|
|
|
|
2010-09-25 00:29:44 +00:00
|
|
|
exports.compact = function(array) {
|
2010-11-09 05:17:08 +00:00
|
|
|
var item, _i, _len, _results;
|
|
|
|
_results = [];
|
2010-10-22 01:51:06 +00:00
|
|
|
for (_i = 0, _len = array.length; _i < _len; _i++) {
|
2010-10-01 22:26:37 +00:00
|
|
|
item = array[_i];
|
2012-04-10 18:57:45 +00:00
|
|
|
if (item) {
|
|
|
|
_results.push(item);
|
|
|
|
}
|
2010-03-10 02:24:30 +00:00
|
|
|
}
|
2010-11-09 05:17:08 +00:00
|
|
|
return _results;
|
2010-09-25 00:18:47 +00:00
|
|
|
};
|
2011-09-18 22:16:39 +00:00
|
|
|
|
2010-12-13 10:51:57 +00:00
|
|
|
exports.count = function(string, substr) {
|
2010-03-10 02:24:30 +00:00
|
|
|
var num, pos;
|
2010-10-20 17:29:06 +00:00
|
|
|
num = pos = 0;
|
2012-04-10 18:57:45 +00:00
|
|
|
if (!substr.length) {
|
|
|
|
return 1 / 0;
|
|
|
|
}
|
2010-12-13 10:51:57 +00:00
|
|
|
while (pos = 1 + string.indexOf(substr, pos)) {
|
2010-09-25 00:18:47 +00:00
|
|
|
num++;
|
2010-03-10 02:24:30 +00:00
|
|
|
}
|
|
|
|
return num;
|
2010-09-25 00:18:47 +00:00
|
|
|
};
|
2011-09-18 22:16:39 +00:00
|
|
|
|
2010-09-25 00:29:44 +00:00
|
|
|
exports.merge = function(options, overrides) {
|
2010-09-25 00:18:47 +00:00
|
|
|
return extend(extend({}, options), overrides);
|
|
|
|
};
|
2011-09-18 22:16:39 +00:00
|
|
|
|
2010-10-20 17:29:06 +00:00
|
|
|
extend = exports.extend = function(object, properties) {
|
2010-10-19 15:07:10 +00:00
|
|
|
var key, val;
|
2010-10-01 22:26:37 +00:00
|
|
|
for (key in properties) {
|
|
|
|
val = properties[key];
|
2010-09-26 14:28:48 +00:00
|
|
|
object[key] = val;
|
2010-03-10 02:24:30 +00:00
|
|
|
}
|
2010-09-25 00:18:47 +00:00
|
|
|
return object;
|
2010-10-20 17:29:06 +00:00
|
|
|
};
|
2011-09-18 22:16:39 +00:00
|
|
|
|
2010-10-20 17:29:06 +00:00
|
|
|
exports.flatten = flatten = function(array) {
|
2010-11-02 03:58:03 +00:00
|
|
|
var element, flattened, _i, _len;
|
2010-09-28 18:28:05 +00:00
|
|
|
flattened = [];
|
2010-10-22 01:51:06 +00:00
|
|
|
for (_i = 0, _len = array.length; _i < _len; _i++) {
|
2010-10-01 22:26:37 +00:00
|
|
|
element = array[_i];
|
2010-09-29 00:12:37 +00:00
|
|
|
if (element instanceof Array) {
|
2010-09-28 18:28:05 +00:00
|
|
|
flattened = flattened.concat(flatten(element));
|
|
|
|
} else {
|
|
|
|
flattened.push(element);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return flattened;
|
2010-10-20 17:29:06 +00:00
|
|
|
};
|
2011-09-18 22:16:39 +00:00
|
|
|
|
2010-09-25 00:29:44 +00:00
|
|
|
exports.del = function(obj, key) {
|
2010-03-10 02:24:30 +00:00
|
|
|
var val;
|
|
|
|
val = obj[key];
|
|
|
|
delete obj[key];
|
|
|
|
return val;
|
2010-09-25 00:18:47 +00:00
|
|
|
};
|
2011-09-18 22:16:39 +00:00
|
|
|
|
2010-09-28 12:52:51 +00:00
|
|
|
exports.last = function(array, back) {
|
|
|
|
return array[array.length - (back || 0) - 1];
|
|
|
|
};
|
2011-12-14 15:39:20 +00:00
|
|
|
|
2012-05-16 19:50:34 +00:00
|
|
|
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;
|
|
|
|
};
|
|
|
|
|
2012-11-15 20:35:01 +00:00
|
|
|
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;
|
|
|
|
};
|
|
|
|
};
|
|
|
|
|
2012-11-17 00:09:56 +00:00
|
|
|
exports.locationDataToString = function(obj) {
|
|
|
|
var locationData;
|
|
|
|
if ("locationData" in obj) {
|
|
|
|
locationData = obj.locationData;
|
|
|
|
} 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";
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
2010-09-21 07:53:58 +00:00
|
|
|
}).call(this);
|