2010-07-25 03:15:12 -04:00
|
|
|
(function() {
|
2010-10-19 22:04:38 -04:00
|
|
|
var extend, flatten;
|
2010-09-24 20:29:44 -04:00
|
|
|
exports.starts = function(string, literal, start) {
|
2010-09-24 20:18:47 -04:00
|
|
|
return literal === string.substr(start, literal.length);
|
|
|
|
};
|
2010-09-24 20:29:44 -04:00
|
|
|
exports.ends = function(string, literal, back) {
|
2010-09-26 10:28:48 -04:00
|
|
|
var len;
|
|
|
|
len = literal.length;
|
|
|
|
return literal === string.substr(string.length - len - (back || 0), len);
|
2010-09-24 20:18:47 -04:00
|
|
|
};
|
2010-09-24 20:29:44 -04:00
|
|
|
exports.compact = function(array) {
|
2010-10-19 11:07:10 -04:00
|
|
|
var _i, _len, _result, item;
|
2010-10-01 18:26:37 -04:00
|
|
|
_result = [];
|
|
|
|
for (_i = 0, _len = array.length; _i < _len; _i++) {
|
|
|
|
item = array[_i];
|
2010-08-11 00:40:15 -04:00
|
|
|
if (item) {
|
2010-09-19 08:29:15 -04:00
|
|
|
_result.push(item);
|
2010-08-14 11:42:19 -04:00
|
|
|
}
|
2010-03-09 21:24:30 -05:00
|
|
|
}
|
2010-09-19 08:29:15 -04:00
|
|
|
return _result;
|
2010-09-24 20:18:47 -04:00
|
|
|
};
|
2010-09-24 20:29:44 -04:00
|
|
|
exports.count = function(string, letter) {
|
2010-03-09 21:24:30 -05:00
|
|
|
var num, pos;
|
2010-10-20 13:29:06 -04:00
|
|
|
num = pos = 0;
|
2010-09-28 08:52:51 -04:00
|
|
|
while (pos = 1 + string.indexOf(letter, pos)) {
|
2010-09-24 20:18:47 -04:00
|
|
|
num++;
|
2010-03-09 21:24:30 -05:00
|
|
|
}
|
|
|
|
return num;
|
2010-09-24 20:18:47 -04:00
|
|
|
};
|
2010-09-24 20:29:44 -04:00
|
|
|
exports.merge = function(options, overrides) {
|
2010-09-24 20:18:47 -04:00
|
|
|
return extend(extend({}, options), overrides);
|
|
|
|
};
|
2010-10-20 13:29:06 -04:00
|
|
|
extend = exports.extend = function(object, properties) {
|
2010-10-19 11:07:10 -04:00
|
|
|
var key, val;
|
2010-10-01 18:26:37 -04:00
|
|
|
for (key in properties) {
|
|
|
|
val = properties[key];
|
2010-09-26 10:28:48 -04:00
|
|
|
object[key] = val;
|
2010-03-09 21:24:30 -05:00
|
|
|
}
|
2010-09-24 20:18:47 -04:00
|
|
|
return object;
|
2010-10-20 13:29:06 -04:00
|
|
|
};
|
|
|
|
exports.flatten = flatten = function(array) {
|
2010-10-19 11:07:10 -04:00
|
|
|
var _i, _len, element, flattened;
|
2010-09-28 14:28:05 -04:00
|
|
|
flattened = [];
|
2010-10-01 18:26:37 -04:00
|
|
|
for (_i = 0, _len = array.length; _i < _len; _i++) {
|
|
|
|
element = array[_i];
|
2010-09-28 20:12:37 -04:00
|
|
|
if (element instanceof Array) {
|
2010-09-28 14:28:05 -04:00
|
|
|
flattened = flattened.concat(flatten(element));
|
|
|
|
} else {
|
|
|
|
flattened.push(element);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return flattened;
|
2010-10-20 13:29:06 -04:00
|
|
|
};
|
2010-09-24 20:29:44 -04:00
|
|
|
exports.del = function(obj, key) {
|
2010-03-09 21:24:30 -05:00
|
|
|
var val;
|
|
|
|
val = obj[key];
|
|
|
|
delete obj[key];
|
|
|
|
return val;
|
2010-09-24 20:18:47 -04:00
|
|
|
};
|
2010-09-28 08:52:51 -04:00
|
|
|
exports.last = function(array, back) {
|
|
|
|
return array[array.length - (back || 0) - 1];
|
|
|
|
};
|
2010-09-21 03:53:58 -04:00
|
|
|
}).call(this);
|