backaid 0.1.9 → 0.2.0

Sign up to get free protection for your applications and to get access to all the features.
@@ -1,6 +1,1491 @@
1
- // Underscore.js 1.5.2
1
+ // Underscore.js 1.7.0
2
2
  // http://underscorejs.org
3
- // (c) 2009-2013 Jeremy Ashkenas, DocumentCloud and Investigative Reporters & Editors
3
+ // (c) 2009-2014 Jeremy Ashkenas, DocumentCloud and Investigative Reporters & Editors
4
4
  // Underscore may be freely distributed under the MIT license.
5
- (function(){var n=this,t=n._,r={},e=Array.prototype,u=Object.prototype,i=Function.prototype,a=e.push,o=e.slice,c=e.concat,l=u.toString,f=u.hasOwnProperty,s=e.forEach,p=e.map,h=e.reduce,v=e.reduceRight,g=e.filter,d=e.every,m=e.some,y=e.indexOf,b=e.lastIndexOf,x=Array.isArray,w=Object.keys,_=i.bind,j=function(n){return n instanceof j?n:this instanceof j?(this._wrapped=n,void 0):new j(n)};"undefined"!=typeof exports?("undefined"!=typeof module&&module.exports&&(exports=module.exports=j),exports._=j):n._=j,j.VERSION="1.5.2";var A=j.each=j.forEach=function(n,t,e){if(null!=n)if(s&&n.forEach===s)n.forEach(t,e);else if(n.length===+n.length){for(var u=0,i=n.length;i>u;u++)if(t.call(e,n[u],u,n)===r)return}else for(var a=j.keys(n),u=0,i=a.length;i>u;u++)if(t.call(e,n[a[u]],a[u],n)===r)return};j.map=j.collect=function(n,t,r){var e=[];return null==n?e:p&&n.map===p?n.map(t,r):(A(n,function(n,u,i){e.push(t.call(r,n,u,i))}),e)};var E="Reduce of empty array with no initial value";j.reduce=j.foldl=j.inject=function(n,t,r,e){var u=arguments.length>2;if(null==n&&(n=[]),h&&n.reduce===h)return e&&(t=j.bind(t,e)),u?n.reduce(t,r):n.reduce(t);if(A(n,function(n,i,a){u?r=t.call(e,r,n,i,a):(r=n,u=!0)}),!u)throw new TypeError(E);return r},j.reduceRight=j.foldr=function(n,t,r,e){var u=arguments.length>2;if(null==n&&(n=[]),v&&n.reduceRight===v)return e&&(t=j.bind(t,e)),u?n.reduceRight(t,r):n.reduceRight(t);var i=n.length;if(i!==+i){var a=j.keys(n);i=a.length}if(A(n,function(o,c,l){c=a?a[--i]:--i,u?r=t.call(e,r,n[c],c,l):(r=n[c],u=!0)}),!u)throw new TypeError(E);return r},j.find=j.detect=function(n,t,r){var e;return O(n,function(n,u,i){return t.call(r,n,u,i)?(e=n,!0):void 0}),e},j.filter=j.select=function(n,t,r){var e=[];return null==n?e:g&&n.filter===g?n.filter(t,r):(A(n,function(n,u,i){t.call(r,n,u,i)&&e.push(n)}),e)},j.reject=function(n,t,r){return j.filter(n,function(n,e,u){return!t.call(r,n,e,u)},r)},j.every=j.all=function(n,t,e){t||(t=j.identity);var u=!0;return null==n?u:d&&n.every===d?n.every(t,e):(A(n,function(n,i,a){return(u=u&&t.call(e,n,i,a))?void 0:r}),!!u)};var O=j.some=j.any=function(n,t,e){t||(t=j.identity);var u=!1;return null==n?u:m&&n.some===m?n.some(t,e):(A(n,function(n,i,a){return u||(u=t.call(e,n,i,a))?r:void 0}),!!u)};j.contains=j.include=function(n,t){return null==n?!1:y&&n.indexOf===y?n.indexOf(t)!=-1:O(n,function(n){return n===t})},j.invoke=function(n,t){var r=o.call(arguments,2),e=j.isFunction(t);return j.map(n,function(n){return(e?t:n[t]).apply(n,r)})},j.pluck=function(n,t){return j.map(n,function(n){return n[t]})},j.where=function(n,t,r){return j.isEmpty(t)?r?void 0:[]:j[r?"find":"filter"](n,function(n){for(var r in t)if(t[r]!==n[r])return!1;return!0})},j.findWhere=function(n,t){return j.where(n,t,!0)},j.max=function(n,t,r){if(!t&&j.isArray(n)&&n[0]===+n[0]&&n.length<65535)return Math.max.apply(Math,n);if(!t&&j.isEmpty(n))return-1/0;var e={computed:-1/0,value:-1/0};return A(n,function(n,u,i){var a=t?t.call(r,n,u,i):n;a>e.computed&&(e={value:n,computed:a})}),e.value},j.min=function(n,t,r){if(!t&&j.isArray(n)&&n[0]===+n[0]&&n.length<65535)return Math.min.apply(Math,n);if(!t&&j.isEmpty(n))return 1/0;var e={computed:1/0,value:1/0};return A(n,function(n,u,i){var a=t?t.call(r,n,u,i):n;a<e.computed&&(e={value:n,computed:a})}),e.value},j.shuffle=function(n){var t,r=0,e=[];return A(n,function(n){t=j.random(r++),e[r-1]=e[t],e[t]=n}),e},j.sample=function(n,t,r){return arguments.length<2||r?n[j.random(n.length-1)]:j.shuffle(n).slice(0,Math.max(0,t))};var k=function(n){return j.isFunction(n)?n:function(t){return t[n]}};j.sortBy=function(n,t,r){var e=k(t);return j.pluck(j.map(n,function(n,t,u){return{value:n,index:t,criteria:e.call(r,n,t,u)}}).sort(function(n,t){var r=n.criteria,e=t.criteria;if(r!==e){if(r>e||r===void 0)return 1;if(e>r||e===void 0)return-1}return n.index-t.index}),"value")};var F=function(n){return function(t,r,e){var u={},i=null==r?j.identity:k(r);return A(t,function(r,a){var o=i.call(e,r,a,t);n(u,o,r)}),u}};j.groupBy=F(function(n,t,r){(j.has(n,t)?n[t]:n[t]=[]).push(r)}),j.indexBy=F(function(n,t,r){n[t]=r}),j.countBy=F(function(n,t){j.has(n,t)?n[t]++:n[t]=1}),j.sortedIndex=function(n,t,r,e){r=null==r?j.identity:k(r);for(var u=r.call(e,t),i=0,a=n.length;a>i;){var o=i+a>>>1;r.call(e,n[o])<u?i=o+1:a=o}return i},j.toArray=function(n){return n?j.isArray(n)?o.call(n):n.length===+n.length?j.map(n,j.identity):j.values(n):[]},j.size=function(n){return null==n?0:n.length===+n.length?n.length:j.keys(n).length},j.first=j.head=j.take=function(n,t,r){return null==n?void 0:null==t||r?n[0]:o.call(n,0,t)},j.initial=function(n,t,r){return o.call(n,0,n.length-(null==t||r?1:t))},j.last=function(n,t,r){return null==n?void 0:null==t||r?n[n.length-1]:o.call(n,Math.max(n.length-t,0))},j.rest=j.tail=j.drop=function(n,t,r){return o.call(n,null==t||r?1:t)},j.compact=function(n){return j.filter(n,j.identity)};var M=function(n,t,r){return t&&j.every(n,j.isArray)?c.apply(r,n):(A(n,function(n){j.isArray(n)||j.isArguments(n)?t?a.apply(r,n):M(n,t,r):r.push(n)}),r)};j.flatten=function(n,t){return M(n,t,[])},j.without=function(n){return j.difference(n,o.call(arguments,1))},j.uniq=j.unique=function(n,t,r,e){j.isFunction(t)&&(e=r,r=t,t=!1);var u=r?j.map(n,r,e):n,i=[],a=[];return A(u,function(r,e){(t?e&&a[a.length-1]===r:j.contains(a,r))||(a.push(r),i.push(n[e]))}),i},j.union=function(){return j.uniq(j.flatten(arguments,!0))},j.intersection=function(n){var t=o.call(arguments,1);return j.filter(j.uniq(n),function(n){return j.every(t,function(t){return j.indexOf(t,n)>=0})})},j.difference=function(n){var t=c.apply(e,o.call(arguments,1));return j.filter(n,function(n){return!j.contains(t,n)})},j.zip=function(){for(var n=j.max(j.pluck(arguments,"length").concat(0)),t=new Array(n),r=0;n>r;r++)t[r]=j.pluck(arguments,""+r);return t},j.object=function(n,t){if(null==n)return{};for(var r={},e=0,u=n.length;u>e;e++)t?r[n[e]]=t[e]:r[n[e][0]]=n[e][1];return r},j.indexOf=function(n,t,r){if(null==n)return-1;var e=0,u=n.length;if(r){if("number"!=typeof r)return e=j.sortedIndex(n,t),n[e]===t?e:-1;e=0>r?Math.max(0,u+r):r}if(y&&n.indexOf===y)return n.indexOf(t,r);for(;u>e;e++)if(n[e]===t)return e;return-1},j.lastIndexOf=function(n,t,r){if(null==n)return-1;var e=null!=r;if(b&&n.lastIndexOf===b)return e?n.lastIndexOf(t,r):n.lastIndexOf(t);for(var u=e?r:n.length;u--;)if(n[u]===t)return u;return-1},j.range=function(n,t,r){arguments.length<=1&&(t=n||0,n=0),r=arguments[2]||1;for(var e=Math.max(Math.ceil((t-n)/r),0),u=0,i=new Array(e);e>u;)i[u++]=n,n+=r;return i};var R=function(){};j.bind=function(n,t){var r,e;if(_&&n.bind===_)return _.apply(n,o.call(arguments,1));if(!j.isFunction(n))throw new TypeError;return r=o.call(arguments,2),e=function(){if(!(this instanceof e))return n.apply(t,r.concat(o.call(arguments)));R.prototype=n.prototype;var u=new R;R.prototype=null;var i=n.apply(u,r.concat(o.call(arguments)));return Object(i)===i?i:u}},j.partial=function(n){var t=o.call(arguments,1);return function(){return n.apply(this,t.concat(o.call(arguments)))}},j.bindAll=function(n){var t=o.call(arguments,1);if(0===t.length)throw new Error("bindAll must be passed function names");return A(t,function(t){n[t]=j.bind(n[t],n)}),n},j.memoize=function(n,t){var r={};return t||(t=j.identity),function(){var e=t.apply(this,arguments);return j.has(r,e)?r[e]:r[e]=n.apply(this,arguments)}},j.delay=function(n,t){var r=o.call(arguments,2);return setTimeout(function(){return n.apply(null,r)},t)},j.defer=function(n){return j.delay.apply(j,[n,1].concat(o.call(arguments,1)))},j.throttle=function(n,t,r){var e,u,i,a=null,o=0;r||(r={});var c=function(){o=r.leading===!1?0:new Date,a=null,i=n.apply(e,u)};return function(){var l=new Date;o||r.leading!==!1||(o=l);var f=t-(l-o);return e=this,u=arguments,0>=f?(clearTimeout(a),a=null,o=l,i=n.apply(e,u)):a||r.trailing===!1||(a=setTimeout(c,f)),i}},j.debounce=function(n,t,r){var e,u,i,a,o;return function(){i=this,u=arguments,a=new Date;var c=function(){var l=new Date-a;t>l?e=setTimeout(c,t-l):(e=null,r||(o=n.apply(i,u)))},l=r&&!e;return e||(e=setTimeout(c,t)),l&&(o=n.apply(i,u)),o}},j.once=function(n){var t,r=!1;return function(){return r?t:(r=!0,t=n.apply(this,arguments),n=null,t)}},j.wrap=function(n,t){return function(){var r=[n];return a.apply(r,arguments),t.apply(this,r)}},j.compose=function(){var n=arguments;return function(){for(var t=arguments,r=n.length-1;r>=0;r--)t=[n[r].apply(this,t)];return t[0]}},j.after=function(n,t){return function(){return--n<1?t.apply(this,arguments):void 0}},j.keys=w||function(n){if(n!==Object(n))throw new TypeError("Invalid object");var t=[];for(var r in n)j.has(n,r)&&t.push(r);return t},j.values=function(n){for(var t=j.keys(n),r=t.length,e=new Array(r),u=0;r>u;u++)e[u]=n[t[u]];return e},j.pairs=function(n){for(var t=j.keys(n),r=t.length,e=new Array(r),u=0;r>u;u++)e[u]=[t[u],n[t[u]]];return e},j.invert=function(n){for(var t={},r=j.keys(n),e=0,u=r.length;u>e;e++)t[n[r[e]]]=r[e];return t},j.functions=j.methods=function(n){var t=[];for(var r in n)j.isFunction(n[r])&&t.push(r);return t.sort()},j.extend=function(n){return A(o.call(arguments,1),function(t){if(t)for(var r in t)n[r]=t[r]}),n},j.pick=function(n){var t={},r=c.apply(e,o.call(arguments,1));return A(r,function(r){r in n&&(t[r]=n[r])}),t},j.omit=function(n){var t={},r=c.apply(e,o.call(arguments,1));for(var u in n)j.contains(r,u)||(t[u]=n[u]);return t},j.defaults=function(n){return A(o.call(arguments,1),function(t){if(t)for(var r in t)n[r]===void 0&&(n[r]=t[r])}),n},j.clone=function(n){return j.isObject(n)?j.isArray(n)?n.slice():j.extend({},n):n},j.tap=function(n,t){return t(n),n};var S=function(n,t,r,e){if(n===t)return 0!==n||1/n==1/t;if(null==n||null==t)return n===t;n instanceof j&&(n=n._wrapped),t instanceof j&&(t=t._wrapped);var u=l.call(n);if(u!=l.call(t))return!1;switch(u){case"[object String]":return n==String(t);case"[object Number]":return n!=+n?t!=+t:0==n?1/n==1/t:n==+t;case"[object Date]":case"[object Boolean]":return+n==+t;case"[object RegExp]":return n.source==t.source&&n.global==t.global&&n.multiline==t.multiline&&n.ignoreCase==t.ignoreCase}if("object"!=typeof n||"object"!=typeof t)return!1;for(var i=r.length;i--;)if(r[i]==n)return e[i]==t;var a=n.constructor,o=t.constructor;if(a!==o&&!(j.isFunction(a)&&a instanceof a&&j.isFunction(o)&&o instanceof o))return!1;r.push(n),e.push(t);var c=0,f=!0;if("[object Array]"==u){if(c=n.length,f=c==t.length)for(;c--&&(f=S(n[c],t[c],r,e)););}else{for(var s in n)if(j.has(n,s)&&(c++,!(f=j.has(t,s)&&S(n[s],t[s],r,e))))break;if(f){for(s in t)if(j.has(t,s)&&!c--)break;f=!c}}return r.pop(),e.pop(),f};j.isEqual=function(n,t){return S(n,t,[],[])},j.isEmpty=function(n){if(null==n)return!0;if(j.isArray(n)||j.isString(n))return 0===n.length;for(var t in n)if(j.has(n,t))return!1;return!0},j.isElement=function(n){return!(!n||1!==n.nodeType)},j.isArray=x||function(n){return"[object Array]"==l.call(n)},j.isObject=function(n){return n===Object(n)},A(["Arguments","Function","String","Number","Date","RegExp"],function(n){j["is"+n]=function(t){return l.call(t)=="[object "+n+"]"}}),j.isArguments(arguments)||(j.isArguments=function(n){return!(!n||!j.has(n,"callee"))}),"function"!=typeof/./&&(j.isFunction=function(n){return"function"==typeof n}),j.isFinite=function(n){return isFinite(n)&&!isNaN(parseFloat(n))},j.isNaN=function(n){return j.isNumber(n)&&n!=+n},j.isBoolean=function(n){return n===!0||n===!1||"[object Boolean]"==l.call(n)},j.isNull=function(n){return null===n},j.isUndefined=function(n){return n===void 0},j.has=function(n,t){return f.call(n,t)},j.noConflict=function(){return n._=t,this},j.identity=function(n){return n},j.times=function(n,t,r){for(var e=Array(Math.max(0,n)),u=0;n>u;u++)e[u]=t.call(r,u);return e},j.random=function(n,t){return null==t&&(t=n,n=0),n+Math.floor(Math.random()*(t-n+1))};var I={escape:{"&":"&amp;","<":"&lt;",">":"&gt;",'"':"&quot;","'":"&#x27;"}};I.unescape=j.invert(I.escape);var T={escape:new RegExp("["+j.keys(I.escape).join("")+"]","g"),unescape:new RegExp("("+j.keys(I.unescape).join("|")+")","g")};j.each(["escape","unescape"],function(n){j[n]=function(t){return null==t?"":(""+t).replace(T[n],function(t){return I[n][t]})}}),j.result=function(n,t){if(null==n)return void 0;var r=n[t];return j.isFunction(r)?r.call(n):r},j.mixin=function(n){A(j.functions(n),function(t){var r=j[t]=n[t];j.prototype[t]=function(){var n=[this._wrapped];return a.apply(n,arguments),z.call(this,r.apply(j,n))}})};var N=0;j.uniqueId=function(n){var t=++N+"";return n?n+t:t},j.templateSettings={evaluate:/<%([\s\S]+?)%>/g,interpolate:/<%=([\s\S]+?)%>/g,escape:/<%-([\s\S]+?)%>/g};var q=/(.)^/,B={"'":"'","\\":"\\","\r":"r","\n":"n"," ":"t","\u2028":"u2028","\u2029":"u2029"},D=/\\|'|\r|\n|\t|\u2028|\u2029/g;j.template=function(n,t,r){var e;r=j.defaults({},r,j.templateSettings);var u=new RegExp([(r.escape||q).source,(r.interpolate||q).source,(r.evaluate||q).source].join("|")+"|$","g"),i=0,a="__p+='";n.replace(u,function(t,r,e,u,o){return a+=n.slice(i,o).replace(D,function(n){return"\\"+B[n]}),r&&(a+="'+\n((__t=("+r+"))==null?'':_.escape(__t))+\n'"),e&&(a+="'+\n((__t=("+e+"))==null?'':__t)+\n'"),u&&(a+="';\n"+u+"\n__p+='"),i=o+t.length,t}),a+="';\n",r.variable||(a="with(obj||{}){\n"+a+"}\n"),a="var __t,__p='',__j=Array.prototype.join,"+"print=function(){__p+=__j.call(arguments,'');};\n"+a+"return __p;\n";try{e=new Function(r.variable||"obj","_",a)}catch(o){throw o.source=a,o}if(t)return e(t,j);var c=function(n){return e.call(this,n,j)};return c.source="function("+(r.variable||"obj")+"){\n"+a+"}",c},j.chain=function(n){return j(n).chain()};var z=function(n){return this._chain?j(n).chain():n};j.mixin(j),A(["pop","push","reverse","shift","sort","splice","unshift"],function(n){var t=e[n];j.prototype[n]=function(){var r=this._wrapped;return t.apply(r,arguments),"shift"!=n&&"splice"!=n||0!==r.length||delete r[0],z.call(this,r)}}),A(["concat","join","slice"],function(n){var t=e[n];j.prototype[n]=function(){return z.call(this,t.apply(this._wrapped,arguments))}}),j.extend(j.prototype,{chain:function(){return this._chain=!0,this},value:function(){return this._wrapped}})}).call(this);
6
- //# sourceMappingURL=underscore-min.map
5
+
6
+ (function() {
7
+
8
+ // Baseline setup
9
+ // --------------
10
+
11
+ // Establish the root object, `window` in the browser, or `exports` on the server.
12
+ var root = this;
13
+
14
+ // Save the previous value of the `_` variable.
15
+ var previousUnderscore = root._;
16
+
17
+ // Save bytes in the minified (but not gzipped) version:
18
+ var ArrayProto = Array.prototype, ObjProto = Object.prototype, FuncProto = Function.prototype;
19
+
20
+ // Create quick reference variables for speed access to core prototypes.
21
+ var
22
+ push = ArrayProto.push,
23
+ slice = ArrayProto.slice,
24
+ toString = ObjProto.toString,
25
+ hasOwnProperty = ObjProto.hasOwnProperty;
26
+
27
+ // All **ECMAScript 5** native function implementations that we hope to use
28
+ // are declared here.
29
+ var
30
+ nativeIsArray = Array.isArray,
31
+ nativeKeys = Object.keys,
32
+ nativeBind = FuncProto.bind;
33
+
34
+ // Create a safe reference to the Underscore object for use below.
35
+ var _ = function(obj) {
36
+ if (obj instanceof _) return obj;
37
+ if (!(this instanceof _)) return new _(obj);
38
+ this._wrapped = obj;
39
+ };
40
+
41
+ // Export the Underscore object for **Node.js**, with
42
+ // backwards-compatibility for the old `require()` API. If we're in
43
+ // the browser, add `_` as a global object.
44
+ if (typeof exports !== 'undefined') {
45
+ if (typeof module !== 'undefined' && module.exports) {
46
+ exports = module.exports = _;
47
+ }
48
+ exports._ = _;
49
+ } else {
50
+ root._ = _;
51
+ }
52
+
53
+ // Current version.
54
+ _.VERSION = '1.7.0';
55
+
56
+ // Internal function that returns an efficient (for current engines) version
57
+ // of the passed-in callback, to be repeatedly applied in other Underscore
58
+ // functions.
59
+ var optimizeCb = function(func, context, argCount) {
60
+ if (context === void 0) return func;
61
+ switch (argCount == null ? 3 : argCount) {
62
+ case 1: return function(value) {
63
+ return func.call(context, value);
64
+ };
65
+ case 2: return function(value, other) {
66
+ return func.call(context, value, other);
67
+ };
68
+ case 3: return function(value, index, collection) {
69
+ return func.call(context, value, index, collection);
70
+ };
71
+ case 4: return function(accumulator, value, index, collection) {
72
+ return func.call(context, accumulator, value, index, collection);
73
+ };
74
+ }
75
+ return function() {
76
+ return func.apply(context, arguments);
77
+ };
78
+ };
79
+
80
+ // A mostly-internal function to generate callbacks that can be applied
81
+ // to each element in a collection, returning the desired result — either
82
+ // identity, an arbitrary callback, a property matcher, or a property accessor.
83
+ var cb = function(value, context, argCount) {
84
+ if (value == null) return _.identity;
85
+ if (_.isFunction(value)) return optimizeCb(value, context, argCount);
86
+ if (_.isObject(value)) return _.matches(value);
87
+ return _.property(value);
88
+ };
89
+ _.iteratee = function(value, context) {
90
+ return cb(value, context, Infinity);
91
+ };
92
+
93
+ // An internal function for creating assigner functions.
94
+ var createAssigner = function(keysFunc) {
95
+ return function(obj) {
96
+ var length = arguments.length;
97
+ if (length < 2 || obj == null) return obj;
98
+ for (var index = 0; index < length; index++) {
99
+ var source = arguments[index],
100
+ keys = keysFunc(source),
101
+ l = keys.length;
102
+ for (var i = 0; i < l; i++) {
103
+ var key = keys[i];
104
+ obj[key] = source[key];
105
+ }
106
+ }
107
+ return obj;
108
+ };
109
+ };
110
+
111
+ // Collection Functions
112
+ // --------------------
113
+
114
+ // The cornerstone, an `each` implementation, aka `forEach`.
115
+ // Handles raw objects in addition to array-likes. Treats all
116
+ // sparse array-likes as if they were dense.
117
+ _.each = _.forEach = function(obj, iteratee, context) {
118
+ if (obj == null) return obj;
119
+ iteratee = optimizeCb(iteratee, context);
120
+ var i, length = obj.length;
121
+ if (length === +length) {
122
+ for (i = 0; i < length; i++) {
123
+ iteratee(obj[i], i, obj);
124
+ }
125
+ } else {
126
+ var keys = _.keys(obj);
127
+ for (i = 0, length = keys.length; i < length; i++) {
128
+ iteratee(obj[keys[i]], keys[i], obj);
129
+ }
130
+ }
131
+ return obj;
132
+ };
133
+
134
+ // Return the results of applying the iteratee to each element.
135
+ _.map = _.collect = function(obj, iteratee, context) {
136
+ if (obj == null) return [];
137
+ iteratee = cb(iteratee, context);
138
+ var keys = obj.length !== +obj.length && _.keys(obj),
139
+ length = (keys || obj).length,
140
+ results = Array(length),
141
+ currentKey;
142
+ for (var index = 0; index < length; index++) {
143
+ currentKey = keys ? keys[index] : index;
144
+ results[index] = iteratee(obj[currentKey], currentKey, obj);
145
+ }
146
+ return results;
147
+ };
148
+
149
+ var reduceError = 'Reduce of empty array with no initial value';
150
+
151
+ // **Reduce** builds up a single result from a list of values, aka `inject`,
152
+ // or `foldl`.
153
+ _.reduce = _.foldl = _.inject = function(obj, iteratee, memo, context) {
154
+ if (obj == null) obj = [];
155
+ iteratee = optimizeCb(iteratee, context, 4);
156
+ var keys = obj.length !== +obj.length && _.keys(obj),
157
+ length = (keys || obj).length,
158
+ index = 0, currentKey;
159
+ if (arguments.length < 3) {
160
+ if (!length) throw new TypeError(reduceError);
161
+ memo = obj[keys ? keys[index++] : index++];
162
+ }
163
+ for (; index < length; index++) {
164
+ currentKey = keys ? keys[index] : index;
165
+ memo = iteratee(memo, obj[currentKey], currentKey, obj);
166
+ }
167
+ return memo;
168
+ };
169
+
170
+ // The right-associative version of reduce, also known as `foldr`.
171
+ _.reduceRight = _.foldr = function(obj, iteratee, memo, context) {
172
+ if (obj == null) obj = [];
173
+ iteratee = optimizeCb(iteratee, context, 4);
174
+ var keys = obj.length !== + obj.length && _.keys(obj),
175
+ index = (keys || obj).length,
176
+ currentKey;
177
+ if (arguments.length < 3) {
178
+ if (!index) throw new TypeError(reduceError);
179
+ memo = obj[keys ? keys[--index] : --index];
180
+ }
181
+ while (index--) {
182
+ currentKey = keys ? keys[index] : index;
183
+ memo = iteratee(memo, obj[currentKey], currentKey, obj);
184
+ }
185
+ return memo;
186
+ };
187
+
188
+ // Return the first value which passes a truth test. Aliased as `detect`.
189
+ _.find = _.detect = function(obj, predicate, context) {
190
+ var key;
191
+ if (obj.length === +obj.length) {
192
+ key = _.findIndex(obj, predicate, context);
193
+ } else {
194
+ key = _.findKey(obj, predicate, context);
195
+ }
196
+ if (key !== void 0 && key !== -1) return obj[key];
197
+ };
198
+
199
+ // Return all the elements that pass a truth test.
200
+ // Aliased as `select`.
201
+ _.filter = _.select = function(obj, predicate, context) {
202
+ var results = [];
203
+ if (obj == null) return results;
204
+ predicate = cb(predicate, context);
205
+ _.each(obj, function(value, index, list) {
206
+ if (predicate(value, index, list)) results.push(value);
207
+ });
208
+ return results;
209
+ };
210
+
211
+ // Return all the elements for which a truth test fails.
212
+ _.reject = function(obj, predicate, context) {
213
+ return _.filter(obj, _.negate(cb(predicate)), context);
214
+ };
215
+
216
+ // Determine whether all of the elements match a truth test.
217
+ // Aliased as `all`.
218
+ _.every = _.all = function(obj, predicate, context) {
219
+ if (obj == null) return true;
220
+ predicate = cb(predicate, context);
221
+ var keys = obj.length !== +obj.length && _.keys(obj),
222
+ length = (keys || obj).length,
223
+ index, currentKey;
224
+ for (index = 0; index < length; index++) {
225
+ currentKey = keys ? keys[index] : index;
226
+ if (!predicate(obj[currentKey], currentKey, obj)) return false;
227
+ }
228
+ return true;
229
+ };
230
+
231
+ // Determine if at least one element in the object matches a truth test.
232
+ // Aliased as `any`.
233
+ _.some = _.any = function(obj, predicate, context) {
234
+ if (obj == null) return false;
235
+ predicate = cb(predicate, context);
236
+ var keys = obj.length !== +obj.length && _.keys(obj),
237
+ length = (keys || obj).length,
238
+ index, currentKey;
239
+ for (index = 0; index < length; index++) {
240
+ currentKey = keys ? keys[index] : index;
241
+ if (predicate(obj[currentKey], currentKey, obj)) return true;
242
+ }
243
+ return false;
244
+ };
245
+
246
+ // Determine if the array or object contains a given value (using `===`).
247
+ // Aliased as `include`.
248
+ _.contains = _.include = function(obj, target) {
249
+ if (obj == null) return false;
250
+ if (obj.length !== +obj.length) obj = _.values(obj);
251
+ return _.indexOf(obj, target) >= 0;
252
+ };
253
+
254
+ // Invoke a method (with arguments) on every item in a collection.
255
+ _.invoke = function(obj, method) {
256
+ var args = slice.call(arguments, 2);
257
+ var isFunc = _.isFunction(method);
258
+ return _.map(obj, function(value) {
259
+ return (isFunc ? method : value[method]).apply(value, args);
260
+ });
261
+ };
262
+
263
+ // Convenience version of a common use case of `map`: fetching a property.
264
+ _.pluck = function(obj, key) {
265
+ return _.map(obj, _.property(key));
266
+ };
267
+
268
+ // Convenience version of a common use case of `filter`: selecting only objects
269
+ // containing specific `key:value` pairs.
270
+ _.where = function(obj, attrs) {
271
+ return _.filter(obj, _.matches(attrs));
272
+ };
273
+
274
+ // Convenience version of a common use case of `find`: getting the first object
275
+ // containing specific `key:value` pairs.
276
+ _.findWhere = function(obj, attrs) {
277
+ return _.find(obj, _.matches(attrs));
278
+ };
279
+
280
+ // Return the maximum element (or element-based computation).
281
+ _.max = function(obj, iteratee, context) {
282
+ var result = -Infinity, lastComputed = -Infinity,
283
+ value, computed;
284
+ if (iteratee == null && obj != null) {
285
+ obj = obj.length === +obj.length ? obj : _.values(obj);
286
+ for (var i = 0, length = obj.length; i < length; i++) {
287
+ value = obj[i];
288
+ if (value > result) {
289
+ result = value;
290
+ }
291
+ }
292
+ } else {
293
+ iteratee = cb(iteratee, context);
294
+ _.each(obj, function(value, index, list) {
295
+ computed = iteratee(value, index, list);
296
+ if (computed > lastComputed || computed === -Infinity && result === -Infinity) {
297
+ result = value;
298
+ lastComputed = computed;
299
+ }
300
+ });
301
+ }
302
+ return result;
303
+ };
304
+
305
+ // Return the minimum element (or element-based computation).
306
+ _.min = function(obj, iteratee, context) {
307
+ var result = Infinity, lastComputed = Infinity,
308
+ value, computed;
309
+ if (iteratee == null && obj != null) {
310
+ obj = obj.length === +obj.length ? obj : _.values(obj);
311
+ for (var i = 0, length = obj.length; i < length; i++) {
312
+ value = obj[i];
313
+ if (value < result) {
314
+ result = value;
315
+ }
316
+ }
317
+ } else {
318
+ iteratee = cb(iteratee, context);
319
+ _.each(obj, function(value, index, list) {
320
+ computed = iteratee(value, index, list);
321
+ if (computed < lastComputed || computed === Infinity && result === Infinity) {
322
+ result = value;
323
+ lastComputed = computed;
324
+ }
325
+ });
326
+ }
327
+ return result;
328
+ };
329
+
330
+ // Shuffle a collection, using the modern version of the
331
+ // [Fisher-Yates shuffle](http://en.wikipedia.org/wiki/Fisher–Yates_shuffle).
332
+ _.shuffle = function(obj) {
333
+ var set = obj && obj.length === +obj.length ? obj : _.values(obj);
334
+ var length = set.length;
335
+ var shuffled = Array(length);
336
+ for (var index = 0, rand; index < length; index++) {
337
+ rand = _.random(0, index);
338
+ if (rand !== index) shuffled[index] = shuffled[rand];
339
+ shuffled[rand] = set[index];
340
+ }
341
+ return shuffled;
342
+ };
343
+
344
+ // Sample **n** random values from a collection.
345
+ // If **n** is not specified, returns a single random element.
346
+ // The internal `guard` argument allows it to work with `map`.
347
+ _.sample = function(obj, n, guard) {
348
+ if (n == null || guard) {
349
+ if (obj.length !== +obj.length) obj = _.values(obj);
350
+ return obj[_.random(obj.length - 1)];
351
+ }
352
+ return _.shuffle(obj).slice(0, Math.max(0, n));
353
+ };
354
+
355
+ // Sort the object's values by a criterion produced by an iteratee.
356
+ _.sortBy = function(obj, iteratee, context) {
357
+ iteratee = cb(iteratee, context);
358
+ return _.pluck(_.map(obj, function(value, index, list) {
359
+ return {
360
+ value: value,
361
+ index: index,
362
+ criteria: iteratee(value, index, list)
363
+ };
364
+ }).sort(function(left, right) {
365
+ var a = left.criteria;
366
+ var b = right.criteria;
367
+ if (a !== b) {
368
+ if (a > b || a === void 0) return 1;
369
+ if (a < b || b === void 0) return -1;
370
+ }
371
+ return left.index - right.index;
372
+ }), 'value');
373
+ };
374
+
375
+ // An internal function used for aggregate "group by" operations.
376
+ var group = function(behavior) {
377
+ return function(obj, iteratee, context) {
378
+ var result = {};
379
+ iteratee = cb(iteratee, context);
380
+ _.each(obj, function(value, index) {
381
+ var key = iteratee(value, index, obj);
382
+ behavior(result, value, key);
383
+ });
384
+ return result;
385
+ };
386
+ };
387
+
388
+ // Groups the object's values by a criterion. Pass either a string attribute
389
+ // to group by, or a function that returns the criterion.
390
+ _.groupBy = group(function(result, value, key) {
391
+ if (_.has(result, key)) result[key].push(value); else result[key] = [value];
392
+ });
393
+
394
+ // Indexes the object's values by a criterion, similar to `groupBy`, but for
395
+ // when you know that your index values will be unique.
396
+ _.indexBy = group(function(result, value, key) {
397
+ result[key] = value;
398
+ });
399
+
400
+ // Counts instances of an object that group by a certain criterion. Pass
401
+ // either a string attribute to count by, or a function that returns the
402
+ // criterion.
403
+ _.countBy = group(function(result, value, key) {
404
+ if (_.has(result, key)) result[key]++; else result[key] = 1;
405
+ });
406
+
407
+ // Use a comparator function to figure out the smallest index at which
408
+ // an object should be inserted so as to maintain order. Uses binary search.
409
+ _.sortedIndex = function(array, obj, iteratee, context) {
410
+ iteratee = cb(iteratee, context, 1);
411
+ var value = iteratee(obj);
412
+ var low = 0, high = array.length;
413
+ while (low < high) {
414
+ var mid = low + high >>> 1;
415
+ if (iteratee(array[mid]) < value) low = mid + 1; else high = mid;
416
+ }
417
+ return low;
418
+ };
419
+
420
+ // Safely create a real, live array from anything iterable.
421
+ _.toArray = function(obj) {
422
+ if (!obj) return [];
423
+ if (_.isArray(obj)) return slice.call(obj);
424
+ if (obj.length === +obj.length) return _.map(obj, _.identity);
425
+ return _.values(obj);
426
+ };
427
+
428
+ // Return the number of elements in an object.
429
+ _.size = function(obj) {
430
+ if (obj == null) return 0;
431
+ return obj.length === +obj.length ? obj.length : _.keys(obj).length;
432
+ };
433
+
434
+ // Split a collection into two arrays: one whose elements all satisfy the given
435
+ // predicate, and one whose elements all do not satisfy the predicate.
436
+ _.partition = function(obj, predicate, context) {
437
+ predicate = cb(predicate, context);
438
+ var pass = [], fail = [];
439
+ _.each(obj, function(value, key, obj) {
440
+ (predicate(value, key, obj) ? pass : fail).push(value);
441
+ });
442
+ return [pass, fail];
443
+ };
444
+
445
+ // Array Functions
446
+ // ---------------
447
+
448
+ // Get the first element of an array. Passing **n** will return the first N
449
+ // values in the array. Aliased as `head` and `take`. The **guard** check
450
+ // allows it to work with `_.map`.
451
+ _.first = _.head = _.take = function(array, n, guard) {
452
+ if (array == null) return void 0;
453
+ if (n == null || guard) return array[0];
454
+ return _.initial(array, array.length - n);
455
+ };
456
+
457
+ // Returns everything but the last entry of the array. Especially useful on
458
+ // the arguments object. Passing **n** will return all the values in
459
+ // the array, excluding the last N. The **guard** check allows it to work with
460
+ // `_.map`.
461
+ _.initial = function(array, n, guard) {
462
+ return slice.call(array, 0, Math.max(0, array.length - (n == null || guard ? 1 : n)));
463
+ };
464
+
465
+ // Get the last element of an array. Passing **n** will return the last N
466
+ // values in the array. The **guard** check allows it to work with `_.map`.
467
+ _.last = function(array, n, guard) {
468
+ if (array == null) return void 0;
469
+ if (n == null || guard) return array[array.length - 1];
470
+ return _.rest(array, Math.max(0, array.length - n));
471
+ };
472
+
473
+ // Returns everything but the first entry of the array. Aliased as `tail` and `drop`.
474
+ // Especially useful on the arguments object. Passing an **n** will return
475
+ // the rest N values in the array. The **guard**
476
+ // check allows it to work with `_.map`.
477
+ _.rest = _.tail = _.drop = function(array, n, guard) {
478
+ return slice.call(array, n == null || guard ? 1 : n);
479
+ };
480
+
481
+ // Trim out all falsy values from an array.
482
+ _.compact = function(array) {
483
+ return _.filter(array, _.identity);
484
+ };
485
+
486
+ // Internal implementation of a recursive `flatten` function.
487
+ var flatten = function(input, shallow, strict, startIndex) {
488
+ var output = [], idx = 0, value;
489
+ for (var i = startIndex || 0, length = input && input.length; i < length; i++) {
490
+ value = input[i];
491
+ if (value && value.length >= 0 && (_.isArray(value) || _.isArguments(value))) {
492
+ //flatten current level of array or arguments object
493
+ if (!shallow) value = flatten(value, shallow, strict);
494
+ var j = 0, len = value.length;
495
+ output.length += len;
496
+ while (j < len) {
497
+ output[idx++] = value[j++];
498
+ }
499
+ } else if (!strict) {
500
+ output[idx++] = value;
501
+ }
502
+ }
503
+ return output;
504
+ };
505
+
506
+ // Flatten out an array, either recursively (by default), or just one level.
507
+ _.flatten = function(array, shallow) {
508
+ return flatten(array, shallow, false);
509
+ };
510
+
511
+ // Return a version of the array that does not contain the specified value(s).
512
+ _.without = function(array) {
513
+ return _.difference(array, slice.call(arguments, 1));
514
+ };
515
+
516
+ // Produce a duplicate-free version of the array. If the array has already
517
+ // been sorted, you have the option of using a faster algorithm.
518
+ // Aliased as `unique`.
519
+ _.uniq = _.unique = function(array, isSorted, iteratee, context) {
520
+ if (array == null) return [];
521
+ if (!_.isBoolean(isSorted)) {
522
+ context = iteratee;
523
+ iteratee = isSorted;
524
+ isSorted = false;
525
+ }
526
+ if (iteratee != null) iteratee = cb(iteratee, context);
527
+ var result = [];
528
+ var seen = [];
529
+ for (var i = 0, length = array.length; i < length; i++) {
530
+ var value = array[i],
531
+ computed = iteratee ? iteratee(value, i, array) : value;
532
+ if (isSorted) {
533
+ if (!i || seen !== computed) result.push(value);
534
+ seen = computed;
535
+ } else if (iteratee) {
536
+ if (!_.contains(seen, computed)) {
537
+ seen.push(computed);
538
+ result.push(value);
539
+ }
540
+ } else if (!_.contains(result, value)) {
541
+ result.push(value);
542
+ }
543
+ }
544
+ return result;
545
+ };
546
+
547
+ // Produce an array that contains the union: each distinct element from all of
548
+ // the passed-in arrays.
549
+ _.union = function() {
550
+ return _.uniq(flatten(arguments, true, true));
551
+ };
552
+
553
+ // Produce an array that contains every item shared between all the
554
+ // passed-in arrays.
555
+ _.intersection = function(array) {
556
+ if (array == null) return [];
557
+ var result = [];
558
+ var argsLength = arguments.length;
559
+ for (var i = 0, length = array.length; i < length; i++) {
560
+ var item = array[i];
561
+ if (_.contains(result, item)) continue;
562
+ for (var j = 1; j < argsLength; j++) {
563
+ if (!_.contains(arguments[j], item)) break;
564
+ }
565
+ if (j === argsLength) result.push(item);
566
+ }
567
+ return result;
568
+ };
569
+
570
+ // Take the difference between one array and a number of other arrays.
571
+ // Only the elements present in just the first array will remain.
572
+ _.difference = function(array) {
573
+ var rest = flatten(arguments, true, true, 1);
574
+ return _.filter(array, function(value){
575
+ return !_.contains(rest, value);
576
+ });
577
+ };
578
+
579
+ // Zip together multiple lists into a single array -- elements that share
580
+ // an index go together.
581
+ _.zip = function(array) {
582
+ if (array == null) return [];
583
+ var length = _.max(arguments, 'length').length;
584
+ var results = Array(length);
585
+ while (length-- > 0) {
586
+ results[length] = _.pluck(arguments, length);
587
+ }
588
+ return results;
589
+ };
590
+
591
+ // Complement of _.zip. Unzip accepts an array of arrays and groups
592
+ // each array's elements on shared indices
593
+ _.unzip = function(array) {
594
+ return _.zip.apply(null, array);
595
+ };
596
+
597
+ // Converts lists into objects. Pass either a single array of `[key, value]`
598
+ // pairs, or two parallel arrays of the same length -- one of keys, and one of
599
+ // the corresponding values.
600
+ _.object = function(list, values) {
601
+ if (list == null) return {};
602
+ var result = {};
603
+ for (var i = 0, length = list.length; i < length; i++) {
604
+ if (values) {
605
+ result[list[i]] = values[i];
606
+ } else {
607
+ result[list[i][0]] = list[i][1];
608
+ }
609
+ }
610
+ return result;
611
+ };
612
+
613
+ // Return the position of the first occurrence of an item in an array,
614
+ // or -1 if the item is not included in the array.
615
+ // If the array is large and already in sort order, pass `true`
616
+ // for **isSorted** to use binary search.
617
+ _.indexOf = function(array, item, isSorted) {
618
+ var i = 0, length = array && array.length;
619
+ if (typeof isSorted == 'number') {
620
+ i = isSorted < 0 ? Math.max(0, length + isSorted) : isSorted;
621
+ } else if (isSorted && length) {
622
+ i = _.sortedIndex(array, item);
623
+ return array[i] === item ? i : -1;
624
+ }
625
+ for (; i < length; i++) if (array[i] === item) return i;
626
+ return -1;
627
+ };
628
+
629
+ _.lastIndexOf = function(array, item, from) {
630
+ var idx = array ? array.length : 0;
631
+ if (typeof from == 'number') {
632
+ idx = from < 0 ? idx + from + 1 : Math.min(idx, from + 1);
633
+ }
634
+ while (--idx >= 0) if (array[idx] === item) return idx;
635
+ return -1;
636
+ };
637
+
638
+ // Returns the first index on an array-like that passes a predicate test
639
+ _.findIndex = function(array, predicate, context) {
640
+ predicate = cb(predicate, context);
641
+ var length = array != null ? array.length : 0;
642
+ for (var i = 0; i < length; i++) {
643
+ if (predicate(array[i], i, array)) return i;
644
+ }
645
+ return -1;
646
+ };
647
+
648
+ // Generate an integer Array containing an arithmetic progression. A port of
649
+ // the native Python `range()` function. See
650
+ // [the Python documentation](http://docs.python.org/library/functions.html#range).
651
+ _.range = function(start, stop, step) {
652
+ if (arguments.length <= 1) {
653
+ stop = start || 0;
654
+ start = 0;
655
+ }
656
+ step = step || 1;
657
+
658
+ var length = Math.max(Math.ceil((stop - start) / step), 0);
659
+ var range = Array(length);
660
+
661
+ for (var idx = 0; idx < length; idx++, start += step) {
662
+ range[idx] = start;
663
+ }
664
+
665
+ return range;
666
+ };
667
+
668
+ // Function (ahem) Functions
669
+ // ------------------
670
+
671
+ // Reusable constructor function for prototype setting.
672
+ var Ctor = function(){};
673
+
674
+ // Determines whether to execute a function as a constructor
675
+ // or a normal function with the provided arguments
676
+ var executeBound = function(sourceFunc, boundFunc, context, callingContext, args) {
677
+ if (!(callingContext instanceof boundFunc)) return sourceFunc.apply(context, args);
678
+ Ctor.prototype = sourceFunc.prototype;
679
+ var self = new Ctor;
680
+ Ctor.prototype = null;
681
+ var result = sourceFunc.apply(self, args);
682
+ if (_.isObject(result)) return result;
683
+ return self;
684
+ };
685
+
686
+ // Create a function bound to a given object (assigning `this`, and arguments,
687
+ // optionally). Delegates to **ECMAScript 5**'s native `Function.bind` if
688
+ // available.
689
+ _.bind = function(func, context) {
690
+ if (nativeBind && func.bind === nativeBind) return nativeBind.apply(func, slice.call(arguments, 1));
691
+ if (!_.isFunction(func)) throw new TypeError('Bind must be called on a function');
692
+ var args = slice.call(arguments, 2);
693
+ return function bound() {
694
+ return executeBound(func, bound, context, this, args.concat(slice.call(arguments)));
695
+ };
696
+ };
697
+
698
+ // Partially apply a function by creating a version that has had some of its
699
+ // arguments pre-filled, without changing its dynamic `this` context. _ acts
700
+ // as a placeholder, allowing any combination of arguments to be pre-filled.
701
+ _.partial = function(func) {
702
+ var boundArgs = slice.call(arguments, 1);
703
+ return function bound() {
704
+ var position = 0;
705
+ var args = boundArgs.slice();
706
+ for (var i = 0, length = args.length; i < length; i++) {
707
+ if (args[i] === _) args[i] = arguments[position++];
708
+ }
709
+ while (position < arguments.length) args.push(arguments[position++]);
710
+ return executeBound(func, bound, this, this, args);
711
+ };
712
+ };
713
+
714
+ // Bind a number of an object's methods to that object. Remaining arguments
715
+ // are the method names to be bound. Useful for ensuring that all callbacks
716
+ // defined on an object belong to it.
717
+ _.bindAll = function(obj) {
718
+ var i, length = arguments.length, key;
719
+ if (length <= 1) throw new Error('bindAll must be passed function names');
720
+ for (i = 1; i < length; i++) {
721
+ key = arguments[i];
722
+ obj[key] = _.bind(obj[key], obj);
723
+ }
724
+ return obj;
725
+ };
726
+
727
+ // Memoize an expensive function by storing its results.
728
+ _.memoize = function(func, hasher) {
729
+ var memoize = function(key) {
730
+ var cache = memoize.cache;
731
+ var address = '' + (hasher ? hasher.apply(this, arguments) : key);
732
+ if (!_.has(cache, address)) cache[address] = func.apply(this, arguments);
733
+ return cache[address];
734
+ };
735
+ memoize.cache = {};
736
+ return memoize;
737
+ };
738
+
739
+ // Delays a function for the given number of milliseconds, and then calls
740
+ // it with the arguments supplied.
741
+ _.delay = function(func, wait) {
742
+ var args = slice.call(arguments, 2);
743
+ return setTimeout(function(){
744
+ return func.apply(null, args);
745
+ }, wait);
746
+ };
747
+
748
+ // Defers a function, scheduling it to run after the current call stack has
749
+ // cleared.
750
+ _.defer = function(func) {
751
+ return _.delay.apply(_, [func, 1].concat(slice.call(arguments, 1)));
752
+ };
753
+
754
+ // Returns a function, that, when invoked, will only be triggered at most once
755
+ // during a given window of time. Normally, the throttled function will run
756
+ // as much as it can, without ever going more than once per `wait` duration;
757
+ // but if you'd like to disable the execution on the leading edge, pass
758
+ // `{leading: false}`. To disable execution on the trailing edge, ditto.
759
+ _.throttle = function(func, wait, options) {
760
+ var context, args, result;
761
+ var timeout = null;
762
+ var previous = 0;
763
+ if (!options) options = {};
764
+ var later = function() {
765
+ previous = options.leading === false ? 0 : _.now();
766
+ timeout = null;
767
+ result = func.apply(context, args);
768
+ if (!timeout) context = args = null;
769
+ };
770
+ return function() {
771
+ var now = _.now();
772
+ if (!previous && options.leading === false) previous = now;
773
+ var remaining = wait - (now - previous);
774
+ context = this;
775
+ args = arguments;
776
+ if (remaining <= 0 || remaining > wait) {
777
+ if (timeout) {
778
+ clearTimeout(timeout);
779
+ timeout = null;
780
+ }
781
+ previous = now;
782
+ result = func.apply(context, args);
783
+ if (!timeout) context = args = null;
784
+ } else if (!timeout && options.trailing !== false) {
785
+ timeout = setTimeout(later, remaining);
786
+ }
787
+ return result;
788
+ };
789
+ };
790
+
791
+ // Returns a function, that, as long as it continues to be invoked, will not
792
+ // be triggered. The function will be called after it stops being called for
793
+ // N milliseconds. If `immediate` is passed, trigger the function on the
794
+ // leading edge, instead of the trailing.
795
+ _.debounce = function(func, wait, immediate) {
796
+ var timeout, args, context, timestamp, result;
797
+
798
+ var later = function() {
799
+ var last = _.now() - timestamp;
800
+
801
+ if (last < wait && last >= 0) {
802
+ timeout = setTimeout(later, wait - last);
803
+ } else {
804
+ timeout = null;
805
+ if (!immediate) {
806
+ result = func.apply(context, args);
807
+ if (!timeout) context = args = null;
808
+ }
809
+ }
810
+ };
811
+
812
+ return function() {
813
+ context = this;
814
+ args = arguments;
815
+ timestamp = _.now();
816
+ var callNow = immediate && !timeout;
817
+ if (!timeout) timeout = setTimeout(later, wait);
818
+ if (callNow) {
819
+ result = func.apply(context, args);
820
+ context = args = null;
821
+ }
822
+
823
+ return result;
824
+ };
825
+ };
826
+
827
+ // Returns the first function passed as an argument to the second,
828
+ // allowing you to adjust arguments, run code before and after, and
829
+ // conditionally execute the original function.
830
+ _.wrap = function(func, wrapper) {
831
+ return _.partial(wrapper, func);
832
+ };
833
+
834
+ // Returns a negated version of the passed-in predicate.
835
+ _.negate = function(predicate) {
836
+ return function() {
837
+ return !predicate.apply(this, arguments);
838
+ };
839
+ };
840
+
841
+ // Returns a function that is the composition of a list of functions, each
842
+ // consuming the return value of the function that follows.
843
+ _.compose = function() {
844
+ var args = arguments;
845
+ var start = args.length - 1;
846
+ return function() {
847
+ var i = start;
848
+ var result = args[start].apply(this, arguments);
849
+ while (i--) result = args[i].call(this, result);
850
+ return result;
851
+ };
852
+ };
853
+
854
+ // Returns a function that will only be executed after being called N times.
855
+ _.after = function(times, func) {
856
+ return function() {
857
+ if (--times < 1) {
858
+ return func.apply(this, arguments);
859
+ }
860
+ };
861
+ };
862
+
863
+ // Returns a function that will only be executed before being called N times.
864
+ _.before = function(times, func) {
865
+ var memo;
866
+ return function() {
867
+ if (--times > 0) {
868
+ memo = func.apply(this, arguments);
869
+ }
870
+ if (times <= 1) func = null;
871
+ return memo;
872
+ };
873
+ };
874
+
875
+ // Returns a function that will be executed at most one time, no matter how
876
+ // often you call it. Useful for lazy initialization.
877
+ _.once = _.partial(_.before, 2);
878
+
879
+ // Object Functions
880
+ // ----------------
881
+
882
+ // Keys in IE < 9 that won't be iterated by `for key in ...` and thus missed.
883
+ var hasEnumBug = !({toString: null}).propertyIsEnumerable('toString');
884
+ var nonEnumerableProps = ['constructor', 'valueOf', 'isPrototypeOf', 'toString',
885
+ 'propertyIsEnumerable', 'hasOwnProperty', 'toLocaleString'];
886
+
887
+ function collectNonEnumProps(obj, keys) {
888
+ var nonEnumIdx = nonEnumerableProps.length;
889
+ var proto = typeof obj.constructor === 'function' ? FuncProto : ObjProto;
890
+
891
+ while (nonEnumIdx--) {
892
+ var prop = nonEnumerableProps[nonEnumIdx];
893
+ if (prop === 'constructor' ? _.has(obj, prop) : prop in obj &&
894
+ obj[prop] !== proto[prop] && !_.contains(keys, prop)) {
895
+ keys.push(prop);
896
+ }
897
+ }
898
+ }
899
+
900
+ // Retrieve the names of an object's own properties.
901
+ // Delegates to **ECMAScript 5**'s native `Object.keys`
902
+ _.keys = function(obj) {
903
+ if (!_.isObject(obj)) return [];
904
+ if (nativeKeys) return nativeKeys(obj);
905
+ var keys = [];
906
+ for (var key in obj) if (_.has(obj, key)) keys.push(key);
907
+ // Ahem, IE < 9.
908
+ if (hasEnumBug) collectNonEnumProps(obj, keys);
909
+ return keys;
910
+ };
911
+
912
+ // Retrieve all the property names of an object.
913
+ _.keysIn = function(obj) {
914
+ if (!_.isObject(obj)) return [];
915
+ var keys = [];
916
+ for (var key in obj) keys.push(key);
917
+ // Ahem, IE < 9.
918
+ if (hasEnumBug) collectNonEnumProps(obj, keys);
919
+ return keys;
920
+ };
921
+
922
+ // Retrieve the values of an object's properties.
923
+ _.values = function(obj) {
924
+ var keys = _.keys(obj);
925
+ var length = keys.length;
926
+ var values = Array(length);
927
+ for (var i = 0; i < length; i++) {
928
+ values[i] = obj[keys[i]];
929
+ }
930
+ return values;
931
+ };
932
+
933
+ // Convert an object into a list of `[key, value]` pairs.
934
+ _.pairs = function(obj) {
935
+ var keys = _.keys(obj);
936
+ var length = keys.length;
937
+ var pairs = Array(length);
938
+ for (var i = 0; i < length; i++) {
939
+ pairs[i] = [keys[i], obj[keys[i]]];
940
+ }
941
+ return pairs;
942
+ };
943
+
944
+ // Invert the keys and values of an object. The values must be serializable.
945
+ _.invert = function(obj) {
946
+ var result = {};
947
+ var keys = _.keys(obj);
948
+ for (var i = 0, length = keys.length; i < length; i++) {
949
+ result[obj[keys[i]]] = keys[i];
950
+ }
951
+ return result;
952
+ };
953
+
954
+ // Return a sorted list of the function names available on the object.
955
+ // Aliased as `methods`
956
+ _.functions = _.methods = function(obj) {
957
+ var names = [];
958
+ for (var key in obj) {
959
+ if (_.isFunction(obj[key])) names.push(key);
960
+ }
961
+ return names.sort();
962
+ };
963
+
964
+ // Extend a given object with all the properties in passed-in object(s).
965
+ _.extend = createAssigner(_.keysIn);
966
+
967
+ // Assigns a given object with all the own properties in the passed-in object(s)
968
+ // (https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Object/assign)
969
+ _.assign = createAssigner(_.keys);
970
+
971
+ // Returns the first key on an object that passes a predicate test
972
+ _.findKey = function(obj, predicate, context) {
973
+ predicate = cb(predicate, context);
974
+ var keys = _.keys(obj), key;
975
+ for (var i = 0, length = keys.length; i < length; i++) {
976
+ key = keys[i];
977
+ if (predicate(obj[key], key, obj)) return key;
978
+ }
979
+ };
980
+
981
+ // Return a copy of the object only containing the whitelisted properties.
982
+ _.pick = function(obj, iteratee, context) {
983
+ var result = {}, key;
984
+ if (obj == null) return result;
985
+ if (_.isFunction(iteratee)) {
986
+ iteratee = optimizeCb(iteratee, context);
987
+ for (key in obj) {
988
+ var value = obj[key];
989
+ if (iteratee(value, key, obj)) result[key] = value;
990
+ }
991
+ } else {
992
+ var keys = flatten(arguments, false, false, 1);
993
+ obj = new Object(obj);
994
+ for (var i = 0, length = keys.length; i < length; i++) {
995
+ key = keys[i];
996
+ if (key in obj) result[key] = obj[key];
997
+ }
998
+ }
999
+ return result;
1000
+ };
1001
+
1002
+ // Return a copy of the object without the blacklisted properties.
1003
+ _.omit = function(obj, iteratee, context) {
1004
+ if (_.isFunction(iteratee)) {
1005
+ iteratee = _.negate(iteratee);
1006
+ } else {
1007
+ var keys = _.map(flatten(arguments, false, false, 1), String);
1008
+ iteratee = function(value, key) {
1009
+ return !_.contains(keys, key);
1010
+ };
1011
+ }
1012
+ return _.pick(obj, iteratee, context);
1013
+ };
1014
+
1015
+ // Fill in a given object with default properties.
1016
+ _.defaults = function(obj) {
1017
+ if (!_.isObject(obj)) return obj;
1018
+ for (var i = 1, length = arguments.length; i < length; i++) {
1019
+ var source = arguments[i];
1020
+ for (var prop in source) {
1021
+ if (obj[prop] === void 0) obj[prop] = source[prop];
1022
+ }
1023
+ }
1024
+ return obj;
1025
+ };
1026
+
1027
+ // Create a (shallow-cloned) duplicate of an object.
1028
+ _.clone = function(obj) {
1029
+ if (!_.isObject(obj)) return obj;
1030
+ return _.isArray(obj) ? obj.slice() : _.extend({}, obj);
1031
+ };
1032
+
1033
+ // Invokes interceptor with the obj, and then returns obj.
1034
+ // The primary purpose of this method is to "tap into" a method chain, in
1035
+ // order to perform operations on intermediate results within the chain.
1036
+ _.tap = function(obj, interceptor) {
1037
+ interceptor(obj);
1038
+ return obj;
1039
+ };
1040
+
1041
+ // Internal recursive comparison function for `isEqual`.
1042
+ var eq = function(a, b, aStack, bStack) {
1043
+ // Identical objects are equal. `0 === -0`, but they aren't identical.
1044
+ // See the [Harmony `egal` proposal](http://wiki.ecmascript.org/doku.php?id=harmony:egal).
1045
+ if (a === b) return a !== 0 || 1 / a === 1 / b;
1046
+ // A strict comparison is necessary because `null == undefined`.
1047
+ if (a == null || b == null) return a === b;
1048
+ // Unwrap any wrapped objects.
1049
+ if (a instanceof _) a = a._wrapped;
1050
+ if (b instanceof _) b = b._wrapped;
1051
+ // Compare `[[Class]]` names.
1052
+ var className = toString.call(a);
1053
+ if (className !== toString.call(b)) return false;
1054
+ switch (className) {
1055
+ // Strings, numbers, regular expressions, dates, and booleans are compared by value.
1056
+ case '[object RegExp]':
1057
+ // RegExps are coerced to strings for comparison (Note: '' + /a/i === '/a/i')
1058
+ case '[object String]':
1059
+ // Primitives and their corresponding object wrappers are equivalent; thus, `"5"` is
1060
+ // equivalent to `new String("5")`.
1061
+ return '' + a === '' + b;
1062
+ case '[object Number]':
1063
+ // `NaN`s are equivalent, but non-reflexive.
1064
+ // Object(NaN) is equivalent to NaN
1065
+ if (+a !== +a) return +b !== +b;
1066
+ // An `egal` comparison is performed for other numeric values.
1067
+ return +a === 0 ? 1 / +a === 1 / b : +a === +b;
1068
+ case '[object Date]':
1069
+ case '[object Boolean]':
1070
+ // Coerce dates and booleans to numeric primitive values. Dates are compared by their
1071
+ // millisecond representations. Note that invalid dates with millisecond representations
1072
+ // of `NaN` are not equivalent.
1073
+ return +a === +b;
1074
+ }
1075
+
1076
+ var areArrays = className === '[object Array]';
1077
+ if (!areArrays) {
1078
+ if (typeof a != 'object' || typeof b != 'object') return false;
1079
+
1080
+ // Objects with different constructors are not equivalent, but `Object`s or `Array`s
1081
+ // from different frames are.
1082
+ var aCtor = a.constructor, bCtor = b.constructor;
1083
+ if (aCtor !== bCtor && !(_.isFunction(aCtor) && aCtor instanceof aCtor &&
1084
+ _.isFunction(bCtor) && bCtor instanceof bCtor)
1085
+ && ('constructor' in a && 'constructor' in b)) {
1086
+ return false;
1087
+ }
1088
+ }
1089
+ // Assume equality for cyclic structures. The algorithm for detecting cyclic
1090
+ // structures is adapted from ES 5.1 section 15.12.3, abstract operation `JO`.
1091
+ var length = aStack.length;
1092
+ while (length--) {
1093
+ // Linear search. Performance is inversely proportional to the number of
1094
+ // unique nested structures.
1095
+ if (aStack[length] === a) return bStack[length] === b;
1096
+ }
1097
+
1098
+ // Add the first object to the stack of traversed objects.
1099
+ aStack.push(a);
1100
+ bStack.push(b);
1101
+
1102
+ // Recursively compare objects and arrays.
1103
+ if (areArrays) {
1104
+ // Compare array lengths to determine if a deep comparison is necessary.
1105
+ length = a.length;
1106
+ if (length !== b.length) return false;
1107
+ // Deep compare the contents, ignoring non-numeric properties.
1108
+ while (length--) {
1109
+ if (!(eq(a[length], b[length], aStack, bStack))) return false;
1110
+ }
1111
+ } else {
1112
+ // Deep compare objects.
1113
+ var keys = _.keys(a), key;
1114
+ length = keys.length;
1115
+ // Ensure that both objects contain the same number of properties before comparing deep equality.
1116
+ if (_.keys(b).length !== length) return false;
1117
+ while (length--) {
1118
+ // Deep compare each member
1119
+ key = keys[length];
1120
+ if (!(_.has(b, key) && eq(a[key], b[key], aStack, bStack))) return false;
1121
+ }
1122
+ }
1123
+ // Remove the first object from the stack of traversed objects.
1124
+ aStack.pop();
1125
+ bStack.pop();
1126
+ return true;
1127
+ };
1128
+
1129
+ // Perform a deep comparison to check if two objects are equal.
1130
+ _.isEqual = function(a, b) {
1131
+ return eq(a, b, [], []);
1132
+ };
1133
+
1134
+ // Is a given array, string, or object empty?
1135
+ // An "empty" object has no enumerable own-properties.
1136
+ _.isEmpty = function(obj) {
1137
+ if (obj == null) return true;
1138
+ if (_.isArray(obj) || _.isString(obj) || _.isArguments(obj)) return obj.length === 0;
1139
+ for (var key in obj) if (_.has(obj, key)) return false;
1140
+ return true;
1141
+ };
1142
+
1143
+ // Is a given value a DOM element?
1144
+ _.isElement = function(obj) {
1145
+ return !!(obj && obj.nodeType === 1);
1146
+ };
1147
+
1148
+ // Is a given value an array?
1149
+ // Delegates to ECMA5's native Array.isArray
1150
+ _.isArray = nativeIsArray || function(obj) {
1151
+ return toString.call(obj) === '[object Array]';
1152
+ };
1153
+
1154
+ // Is a given variable an object?
1155
+ _.isObject = function(obj) {
1156
+ var type = typeof obj;
1157
+ return type === 'function' || type === 'object' && !!obj;
1158
+ };
1159
+
1160
+ // Add some isType methods: isArguments, isFunction, isString, isNumber, isDate, isRegExp, isError.
1161
+ _.each(['Arguments', 'Function', 'String', 'Number', 'Date', 'RegExp', 'Error'], function(name) {
1162
+ _['is' + name] = function(obj) {
1163
+ return toString.call(obj) === '[object ' + name + ']';
1164
+ };
1165
+ });
1166
+
1167
+ // Define a fallback version of the method in browsers (ahem, IE < 9), where
1168
+ // there isn't any inspectable "Arguments" type.
1169
+ if (!_.isArguments(arguments)) {
1170
+ _.isArguments = function(obj) {
1171
+ return _.has(obj, 'callee');
1172
+ };
1173
+ }
1174
+
1175
+ // Optimize `isFunction` if appropriate. Work around an IE 11 bug.
1176
+ if (typeof /./ !== 'function') {
1177
+ _.isFunction = function(obj) {
1178
+ return typeof obj == 'function' || false;
1179
+ };
1180
+ }
1181
+
1182
+ // Is a given object a finite number?
1183
+ _.isFinite = function(obj) {
1184
+ return isFinite(obj) && !isNaN(parseFloat(obj));
1185
+ };
1186
+
1187
+ // Is the given value `NaN`? (NaN is the only number which does not equal itself).
1188
+ _.isNaN = function(obj) {
1189
+ return _.isNumber(obj) && obj !== +obj;
1190
+ };
1191
+
1192
+ // Is a given value a boolean?
1193
+ _.isBoolean = function(obj) {
1194
+ return obj === true || obj === false || toString.call(obj) === '[object Boolean]';
1195
+ };
1196
+
1197
+ // Is a given value equal to null?
1198
+ _.isNull = function(obj) {
1199
+ return obj === null;
1200
+ };
1201
+
1202
+ // Is a given variable undefined?
1203
+ _.isUndefined = function(obj) {
1204
+ return obj === void 0;
1205
+ };
1206
+
1207
+ // Shortcut function for checking if an object has a given property directly
1208
+ // on itself (in other words, not on a prototype).
1209
+ _.has = function(obj, key) {
1210
+ return obj != null && hasOwnProperty.call(obj, key);
1211
+ };
1212
+
1213
+ // Utility Functions
1214
+ // -----------------
1215
+
1216
+ // Run Underscore.js in *noConflict* mode, returning the `_` variable to its
1217
+ // previous owner. Returns a reference to the Underscore object.
1218
+ _.noConflict = function() {
1219
+ root._ = previousUnderscore;
1220
+ return this;
1221
+ };
1222
+
1223
+ // Keep the identity function around for default iteratees.
1224
+ _.identity = function(value) {
1225
+ return value;
1226
+ };
1227
+
1228
+ // Predicate-generating functions. Often useful outside of Underscore.
1229
+ _.constant = function(value) {
1230
+ return function() {
1231
+ return value;
1232
+ };
1233
+ };
1234
+
1235
+ _.noop = function(){};
1236
+
1237
+ _.property = function(key) {
1238
+ return function(obj) {
1239
+ return obj == null ? void 0 : obj[key];
1240
+ };
1241
+ };
1242
+
1243
+ // Generates a function for a given object that returns a given property (including those of ancestors)
1244
+ _.propertyOf = function(obj) {
1245
+ return obj == null ? function(){} : function(key) {
1246
+ return obj[key];
1247
+ };
1248
+ };
1249
+
1250
+ // Returns a predicate for checking whether an object has a given set of `key:value` pairs.
1251
+ _.matches = function(attrs) {
1252
+ var pairs = _.pairs(attrs), length = pairs.length;
1253
+ return function(obj) {
1254
+ if (obj == null) return !length;
1255
+ obj = new Object(obj);
1256
+ for (var i = 0; i < length; i++) {
1257
+ var pair = pairs[i], key = pair[0];
1258
+ if (pair[1] !== obj[key] || !(key in obj)) return false;
1259
+ }
1260
+ return true;
1261
+ };
1262
+ };
1263
+
1264
+ // Run a function **n** times.
1265
+ _.times = function(n, iteratee, context) {
1266
+ var accum = Array(Math.max(0, n));
1267
+ iteratee = optimizeCb(iteratee, context, 1);
1268
+ for (var i = 0; i < n; i++) accum[i] = iteratee(i);
1269
+ return accum;
1270
+ };
1271
+
1272
+ // Return a random integer between min and max (inclusive).
1273
+ _.random = function(min, max) {
1274
+ if (max == null) {
1275
+ max = min;
1276
+ min = 0;
1277
+ }
1278
+ return min + Math.floor(Math.random() * (max - min + 1));
1279
+ };
1280
+
1281
+ // A (possibly faster) way to get the current timestamp as an integer.
1282
+ _.now = Date.now || function() {
1283
+ return new Date().getTime();
1284
+ };
1285
+
1286
+ // List of HTML entities for escaping.
1287
+ var escapeMap = {
1288
+ '&': '&amp;',
1289
+ '<': '&lt;',
1290
+ '>': '&gt;',
1291
+ '"': '&quot;',
1292
+ "'": '&#x27;',
1293
+ '`': '&#x60;'
1294
+ };
1295
+ var unescapeMap = _.invert(escapeMap);
1296
+
1297
+ // Functions for escaping and unescaping strings to/from HTML interpolation.
1298
+ var createEscaper = function(map) {
1299
+ var escaper = function(match) {
1300
+ return map[match];
1301
+ };
1302
+ // Regexes for identifying a key that needs to be escaped
1303
+ var source = '(?:' + _.keys(map).join('|') + ')';
1304
+ var testRegexp = RegExp(source);
1305
+ var replaceRegexp = RegExp(source, 'g');
1306
+ return function(string) {
1307
+ string = string == null ? '' : '' + string;
1308
+ return testRegexp.test(string) ? string.replace(replaceRegexp, escaper) : string;
1309
+ };
1310
+ };
1311
+ _.escape = createEscaper(escapeMap);
1312
+ _.unescape = createEscaper(unescapeMap);
1313
+
1314
+ // If the value of the named `property` is a function then invoke it with the
1315
+ // `object` as context; otherwise, return it.
1316
+ _.result = function(object, property, fallback) {
1317
+ var value = object == null ? void 0 : object[property];
1318
+ if (value === void 0) {
1319
+ value = fallback;
1320
+ }
1321
+ return _.isFunction(value) ? value.call(object) : value;
1322
+ };
1323
+
1324
+ // Generate a unique integer id (unique within the entire client session).
1325
+ // Useful for temporary DOM ids.
1326
+ var idCounter = 0;
1327
+ _.uniqueId = function(prefix) {
1328
+ var id = ++idCounter + '';
1329
+ return prefix ? prefix + id : id;
1330
+ };
1331
+
1332
+ // By default, Underscore uses ERB-style template delimiters, change the
1333
+ // following template settings to use alternative delimiters.
1334
+ _.templateSettings = {
1335
+ evaluate : /<%([\s\S]+?)%>/g,
1336
+ interpolate : /<%=([\s\S]+?)%>/g,
1337
+ escape : /<%-([\s\S]+?)%>/g
1338
+ };
1339
+
1340
+ // When customizing `templateSettings`, if you don't want to define an
1341
+ // interpolation, evaluation or escaping regex, we need one that is
1342
+ // guaranteed not to match.
1343
+ var noMatch = /(.)^/;
1344
+
1345
+ // Certain characters need to be escaped so that they can be put into a
1346
+ // string literal.
1347
+ var escapes = {
1348
+ "'": "'",
1349
+ '\\': '\\',
1350
+ '\r': 'r',
1351
+ '\n': 'n',
1352
+ '\u2028': 'u2028',
1353
+ '\u2029': 'u2029'
1354
+ };
1355
+
1356
+ var escaper = /\\|'|\r|\n|\u2028|\u2029/g;
1357
+
1358
+ var escapeChar = function(match) {
1359
+ return '\\' + escapes[match];
1360
+ };
1361
+
1362
+ // JavaScript micro-templating, similar to John Resig's implementation.
1363
+ // Underscore templating handles arbitrary delimiters, preserves whitespace,
1364
+ // and correctly escapes quotes within interpolated code.
1365
+ // NB: `oldSettings` only exists for backwards compatibility.
1366
+ _.template = function(text, settings, oldSettings) {
1367
+ if (!settings && oldSettings) settings = oldSettings;
1368
+ settings = _.defaults({}, settings, _.templateSettings);
1369
+
1370
+ // Combine delimiters into one regular expression via alternation.
1371
+ var matcher = RegExp([
1372
+ (settings.escape || noMatch).source,
1373
+ (settings.interpolate || noMatch).source,
1374
+ (settings.evaluate || noMatch).source
1375
+ ].join('|') + '|$', 'g');
1376
+
1377
+ // Compile the template source, escaping string literals appropriately.
1378
+ var index = 0;
1379
+ var source = "__p+='";
1380
+ text.replace(matcher, function(match, escape, interpolate, evaluate, offset) {
1381
+ source += text.slice(index, offset).replace(escaper, escapeChar);
1382
+ index = offset + match.length;
1383
+
1384
+ if (escape) {
1385
+ source += "'+\n((__t=(" + escape + "))==null?'':_.escape(__t))+\n'";
1386
+ } else if (interpolate) {
1387
+ source += "'+\n((__t=(" + interpolate + "))==null?'':__t)+\n'";
1388
+ } else if (evaluate) {
1389
+ source += "';\n" + evaluate + "\n__p+='";
1390
+ }
1391
+
1392
+ // Adobe VMs need the match returned to produce the correct offest.
1393
+ return match;
1394
+ });
1395
+ source += "';\n";
1396
+
1397
+ // If a variable is not specified, place data values in local scope.
1398
+ if (!settings.variable) source = 'with(obj||{}){\n' + source + '}\n';
1399
+
1400
+ source = "var __t,__p='',__j=Array.prototype.join," +
1401
+ "print=function(){__p+=__j.call(arguments,'');};\n" +
1402
+ source + 'return __p;\n';
1403
+
1404
+ try {
1405
+ var render = new Function(settings.variable || 'obj', '_', source);
1406
+ } catch (e) {
1407
+ e.source = source;
1408
+ throw e;
1409
+ }
1410
+
1411
+ var template = function(data) {
1412
+ return render.call(this, data, _);
1413
+ };
1414
+
1415
+ // Provide the compiled source as a convenience for precompilation.
1416
+ var argument = settings.variable || 'obj';
1417
+ template.source = 'function(' + argument + '){\n' + source + '}';
1418
+
1419
+ return template;
1420
+ };
1421
+
1422
+ // Add a "chain" function. Start chaining a wrapped Underscore object.
1423
+ _.chain = function(obj) {
1424
+ var instance = _(obj);
1425
+ instance._chain = true;
1426
+ return instance;
1427
+ };
1428
+
1429
+ // OOP
1430
+ // ---------------
1431
+ // If Underscore is called as a function, it returns a wrapped object that
1432
+ // can be used OO-style. This wrapper holds altered versions of all the
1433
+ // underscore functions. Wrapped objects may be chained.
1434
+
1435
+ // Helper function to continue chaining intermediate results.
1436
+ var result = function(instance, obj) {
1437
+ return instance._chain ? _(obj).chain() : obj;
1438
+ };
1439
+
1440
+ // Add your own custom functions to the Underscore object.
1441
+ _.mixin = function(obj) {
1442
+ _.each(_.functions(obj), function(name) {
1443
+ var func = _[name] = obj[name];
1444
+ _.prototype[name] = function() {
1445
+ var args = [this._wrapped];
1446
+ push.apply(args, arguments);
1447
+ return result(this, func.apply(_, args));
1448
+ };
1449
+ });
1450
+ };
1451
+
1452
+ // Add all of the Underscore functions to the wrapper object.
1453
+ _.mixin(_);
1454
+
1455
+ // Add all mutator Array functions to the wrapper.
1456
+ _.each(['pop', 'push', 'reverse', 'shift', 'sort', 'splice', 'unshift'], function(name) {
1457
+ var method = ArrayProto[name];
1458
+ _.prototype[name] = function() {
1459
+ var obj = this._wrapped;
1460
+ method.apply(obj, arguments);
1461
+ if ((name === 'shift' || name === 'splice') && obj.length === 0) delete obj[0];
1462
+ return result(this, obj);
1463
+ };
1464
+ });
1465
+
1466
+ // Add all accessor Array functions to the wrapper.
1467
+ _.each(['concat', 'join', 'slice'], function(name) {
1468
+ var method = ArrayProto[name];
1469
+ _.prototype[name] = function() {
1470
+ return result(this, method.apply(this._wrapped, arguments));
1471
+ };
1472
+ });
1473
+
1474
+ // Extracts the result from a wrapped and chained object.
1475
+ _.prototype.value = function() {
1476
+ return this._wrapped;
1477
+ };
1478
+
1479
+ // AMD registration happens at the end for compatibility with AMD loaders
1480
+ // that may not enforce next-turn semantics on modules. Even though general
1481
+ // practice for AMD registration is to be anonymous, underscore registers
1482
+ // as a named module because, like jQuery, it is a base library that is
1483
+ // popular enough to be bundled in a third party lib, but not be part of
1484
+ // an AMD load request. Those cases could generate an error when an
1485
+ // anonymous define() is called outside of a loader request.
1486
+ if (typeof define === 'function' && define.amd) {
1487
+ define('underscore', [], function() {
1488
+ return _;
1489
+ });
1490
+ }
1491
+ }.call(this));