PageSourceSearch

https://app.myboxman.com/packages/underscore.js?hash=a29c47e75bce51635cf7f8fcc19c4884c10291d3

js myboxman.com collected 2026-09-24 11:24:40 UTC 48,128 bytes, 1,379 lines download raw bytes

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

Line numbers count LF bytes from the start of the resource, as the search results do. Vendor segments are library code the classifier recognised; they are stored but not indexed. Bytes are shown as Latin1 characters, one per byte.