Files
lodash/underscore-min.js

3 lines
7.3 KiB
JavaScript

(function(){var j=this;var k=j._;var m=function(a){this._wrapped=a};var o=typeof StopIteration!=='undefined'?StopIteration:'__break__';var _=j._=function(a){return new m(a)};if(typeof exports!=='undefined')exports._=_;_.VERSION='0.4.5';_.range=function(a,b,c){if(!b){var b=a;a=0}if(!c)var c=1;var d=Math.ceil((b-a)/c);if(d<0){return[]}var e=new Array(d);var f=0;for(var i=a;(a<=b?b-i>0:i-b>0);i+=c){e[f++]=i}return e};_.each=function(a,b,c){var d=0;try{if(a.forEach){a.forEach(b,c)}else if(a.length){for(var i=0,l=a.length;i<l;i++)b.call(c,a[i],i,a)}else{for(var f in a)if(Object.prototype.hasOwnProperty.call(a,f)){b.call(c,a[f],f,a)}}}catch(e){if(e!=o)throw e;}return a};_.map=function(d,e,f){if(d&&d.map)return d.map(e,f);var g=[];_.each(d,function(a,b,c){g.push(e.call(f,a,b,c))});return g};_.reduce=function(d,e,f,g){if(d&&d.reduce)return d.reduce(_.bind(f,g),e);_.each(d,function(a,b,c){e=f.call(g,e,a,b,c)});return e};_.reduceRight=function(c,d,e,f){if(c&&c.reduceRight)return c.reduceRight(_.bind(e,f),d);var g=_.clone(_.toArray(c)).reverse();_.each(g,function(a,b){d=e.call(f,d,a,b,c)});return d};_.detect=function(d,e,f){var g;_.each(d,function(a,b,c){if(e.call(f,a,b,c)){g=a;_.breakLoop()}});return g};_.select=function(d,e,f){if(d.filter)return d.filter(e,f);var g=[];_.each(d,function(a,b,c){e.call(f,a,b,c)&&g.push(a)});return g};_.reject=function(d,e,f){var g=[];_.each(d,function(a,b,c){!e.call(f,a,b,c)&&g.push(a)});return g};_.all=function(d,e,f){e=e||_.identity;if(d.every)return d.every(e,f);var g=true;_.each(d,function(a,b,c){if(!(g=g&&e.call(f,a,b,c)))_.breakLoop()});return g};_.any=function(d,e,f){e=e||_.identity;if(d.some)return d.some(e,f);var g=false;_.each(d,function(a,b,c){if(g=e.call(f,a,b,c))_.breakLoop()});return g};_.include=function(b,c){if(_.isArray(b))return _.indexOf(b,c)!=-1;var d=false;_.each(b,function(a){if(d=a===c)_.breakLoop()});return d};_.invoke=function(b,c){var d=_.rest(arguments,2);return _.map(b,function(a){return(c?a[c]:a).apply(a,d)})};_.pluck=function(b,c){return _.map(b,function(a){return a[c]})};_.max=function(e,f,g){if(!f&&_.isArray(e))return Math.max.apply(Math,e);var h={computed:-Infinity};_.each(e,function(a,b,c){var d=f?f.call(g,a,b,c):a;d>=h.computed&&(h={value:a,computed:d})});return h.value};_.min=function(e,f,g){if(!f&&_.isArray(e))return Math.min.apply(Math,e);var h={computed:Infinity};_.each(e,function(a,b,c){var d=f?f.call(g,a,b,c):a;d<h.computed&&(h={value:a,computed:d})});return h.value};_.sortBy=function(e,f,g){return _.pluck(_.map(e,function(a,b,c){return{value:a,criteria:f.call(g,a,b,c)}}).sort(function(c,d){var a=c.criteria,b=d.criteria;return a<b?-1:a>b?1:0}),'value')};_.sortedIndex=function(a,b,c){c=c||_.identity;var d=0,high=a.length;while(d<high){var e=(d+high)>>1;c(a[e])<c(b)?d=e+1:high=e}return d};_.toArray=function(b){if(!b)return[];if(b.toArray)return b.toArray();if(_.isArray(b))return b;return _.map(b,function(a){return a})};_.size=function(a){return _.toArray(a).length};_.first=function(a,n){return n?Array.prototype.slice.call(a,0,n):a[0]};_.rest=function(a,b){return Array.prototype.slice.call(a,_.isUndefined(b)?1:b)};_.last=function(a){return a[a.length-1]};_.compact=function(b){return _.select(b,function(a){return!!a})};_.flatten=function(c){return _.reduce(c,[],function(a,b){if(_.isArray(b))return a.concat(_.flatten(b));a.push(b);return a})};_.without=function(b){var c=_.rest(arguments);return _.select(b,function(a){return!_.include(c,a)})};_.uniq=function(c,d){return _.reduce(c,[],function(a,b,i){if(0==i||(d?_.last(a)!=b:!_.include(a,b)))a.push(b);return a})};_.intersect=function(c){var d=_.rest(arguments);return _.select(_.uniq(c),function(b){return _.all(d,function(a){return _.indexOf(a,b)>=0})})};_.zip=function(){var a=_.toArray(arguments);var b=_.max(_.pluck(a,'length'));var c=new Array(b);for(var i=0;i<b;i++)c[i]=_.pluck(a,String(i));return c};_.indexOf=function(a,b){if(a.indexOf)return a.indexOf(b);for(var i=0,l=a.length;i<l;i++)if(a[i]===b)return i;return-1};_.lastIndexOf=function(a,b){if(a.lastIndexOf)return a.lastIndexOf(b);var i=a.length;while(i--)if(a[i]===b)return i;return-1};_.bind=function(a,b){var c=_.rest(arguments,2);return function(){return a.apply(b||j,c.concat(_.toArray(arguments)))}};_.bindAll=function(){var b=Array.prototype.pop.call(arguments);_.each(arguments,function(a){b[a]=_.bind(b[a],b)})};_.delay=function(a,b){var c=_.rest(arguments,2);return setTimeout(function(){return a.apply(a,c)},b)};_.defer=function(a){return _.delay.apply(_,[a,1].concat(_.rest(arguments)))};_.wrap=function(b,c){return function(){var a=[b].concat(_.toArray(arguments));return c.apply(c,a)}};_.compose=function(){var a=_.toArray(arguments);return function(){for(var i=a.length-1;i>=0;i--){arguments=[a[i].apply(this,arguments)]}return arguments[0]}};_.keys=function(c){return _.map(c,function(a,b){return b})};_.values=function(a){return _.map(a,_.identity)};_.extend=function(a,b){for(var c in b)a[c]=b[c];return a};_.clone=function(a){if(_.isArray(a))return a.slice(0);return _.extend({},a)};_.isEqual=function(a,b){if(a===b)return true;var c=typeof(a),btype=typeof(b);if(c!=btype)return false;if(a==b)return true;if(a.isEqual)return a.isEqual(b);if(_.isNumber(a)&&_.isNumber(b)&&isNaN(a)&&isNaN(b))return true;if(c!=='object')return false;var d=_.keys(a),bKeys=_.keys(b);if(d.length!=bKeys.length)return false;for(var e in a)if(!_.isEqual(a[e],b[e]))return false;return true};_.isEmpty=function(a){return(_.isArray(a)?a:_.values(a)).length==0};_.isElement=function(a){return!!(a&&a.nodeType==1)};_.isArray=function(a){return Object.prototype.toString.call(a)=='[object Array]'};_.isFunction=function(a){return Object.prototype.toString.call(a)=='[object Function]'};_.isString=function(a){return Object.prototype.toString.call(a)=='[object String]'};_.isNumber=function(a){return Object.prototype.toString.call(a)=='[object Number]'};_.isUndefined=function(a){return typeof a=='undefined'};_.noConflict=function(){j._=k;return this};_.identity=function(a){return a};_.breakLoop=function(){throw o;};var p=0;_.uniqueId=function(a){var b=p++;return a?a+b:b};_.functions=function(){var a=[];for(var b in _)if(Object.prototype.hasOwnProperty.call(_,b))a.push(b);return _.without(a,'VERSION','prototype','noConflict').sort()};_.template=function(a,b){var c=new Function('obj','var p=[],print=function(){p.push.apply(p,arguments);};'+'with(obj){p.push(\''+a.replace(/[\r\t\n]/g," ").split("<%").join("\t").replace(/((^|%>)[^\t]*)'/g,"$1\r").replace(/\t=(.*?)%>/g,"',$1,'").split("\t").join("');").split("%>").join("p.push('").split("\r").join("\\'")+"');}return p.join('');");return b?c(b):c};_.forEach=_.each;_.foldl=_.inject=_.reduce;_.foldr=_.reduceRight;_.filter=_.select;_.every=_.all;_.some=_.any;_.head=_.first;_.tail=_.rest;_.methods=_.functions;var q=function(a,b){return b?_(a).chain():a};_.each(_.functions(),function(a){m.prototype[a]=function(){Array.prototype.unshift.call(arguments,this._wrapped);return q(_[a].apply(_,arguments),this._chain)}});_.each(['pop','push','reverse','shift','sort','splice','unshift'],function(a){m.prototype[a]=function(){Array.prototype[a].apply(this._wrapped,arguments);return q(this._wrapped,this._chain)}});_.each(['concat','join','slice'],function(a){m.prototype[a]=function(){return q(Array.prototype[a].apply(this._wrapped,arguments),this._chain)}});m.prototype.chain=function(){this._chain=true;return this};m.prototype.value=function(){return this._wrapped}})();