UNPKG

mist

Version:
50 lines (47 loc) 1.23 kB
var slice = [].slice; module.exports.install = function() { Array.prototype.unique = function() { var a, i, l; a = []; i = 0; l = this.length; while (i < l) { if (a.indexOf(this[i]) === -1) { a.push(this[i]); } ++i; } return a; }; Array.prototype.flatten = function() { return this.reduce(function(a, b) { return a.concat((b instanceof Array ? b : [b])); }, []); }; Array.prototype.compile = function() { return this.flatten().unique(); }; Array.prototype.pushAll = function() { var arr, arrs, j, len, results; arrs = 1 <= arguments.length ? slice.call(arguments, 0) : []; results = []; for (j = 0, len = arrs.length; j < len; j++) { arr = arrs[j]; if (arr instanceof Array) { results.push(Array.prototype.push.apply(this, arr)); } else { results.push(this.push(arr)); } } return results; }; Array.prototype.linearize = function() { return this.compile().join(' '); }; return String.prototype.applyDictionary = function(regex, dict) { return this.replace(regex, function(m, name) { return dict[name] || m; }); }; }; //# sourceMappingURL=utils.js.map