Inital Commit
[oweals/finalsclub.git] / node_modules / jade / support / coffee-script / lib / helpers.js
1 (function() {
2   var extend, flatten, indexOf;
3   indexOf = (exports.indexOf = Array.indexOf || (Array.prototype.indexOf ? function(array, item, from) {
4     return array.indexOf(item, from);
5   } : function(array, item, from) {
6     var _len, index, other;
7     for (index = 0, _len = array.length; index < _len; index++) {
8       other = array[index];
9       if (other === item && (!from || (from <= index))) {
10         return index;
11       }
12     }
13     return -1;
14   }));
15   exports.include = function(list, value) {
16     return indexOf(list, value) >= 0;
17   };
18   exports.starts = function(string, literal, start) {
19     return literal === string.substr(start, literal.length);
20   };
21   exports.ends = function(string, literal, back) {
22     var len;
23     len = literal.length;
24     return literal === string.substr(string.length - len - (back || 0), len);
25   };
26   exports.compact = function(array) {
27     var _i, _len, _result, item;
28     _result = [];
29     for (_i = 0, _len = array.length; _i < _len; _i++) {
30       item = array[_i];
31       if (item) {
32         _result.push(item);
33       }
34     }
35     return _result;
36   };
37   exports.count = function(string, letter) {
38     var num, pos;
39     num = (pos = 0);
40     while (pos = 1 + string.indexOf(letter, pos)) {
41       num++;
42     }
43     return num;
44   };
45   exports.merge = function(options, overrides) {
46     return extend(extend({}, options), overrides);
47   };
48   extend = (exports.extend = function(object, properties) {
49     var key, val;
50     for (key in properties) {
51       val = properties[key];
52       object[key] = val;
53     }
54     return object;
55   });
56   exports.flatten = (flatten = function(array) {
57     var _i, _len, element, flattened;
58     flattened = [];
59     for (_i = 0, _len = array.length; _i < _len; _i++) {
60       element = array[_i];
61       if (element instanceof Array) {
62         flattened = flattened.concat(flatten(element));
63       } else {
64         flattened.push(element);
65       }
66     }
67     return flattened;
68   });
69   exports.del = function(obj, key) {
70     var val;
71     val = obj[key];
72     delete obj[key];
73     return val;
74   };
75   exports.last = function(array, back) {
76     return array[array.length - (back || 0) - 1];
77   };
78 }).call(this);