PageSourceSearch

https://www.tpsportal.co.nz/assets/modules/core/plugins/array/array.js?v=1790155878

js tpsportal.co.nz collected 2026-10-07 01:14:43 UTC 29,801 bytes, 1,621 lines download raw bytes

vendor: 5,093 bytes, lines 1-268
1;(function(){
2
3/**
4 * Require the given path.
5 *
6 * @param {String} path
7 * @return {Object} exports
8 * @api public
9 */
10
11function require(path, parent, orig) {
12  var resolved = require.resolve(path);
13
14  // lookup failed
15  if (null == resolved) {
16    orig = orig || path;
17    parent = parent || 'root';
18    var err = new Error('Failed to require "' + orig + '" from "' + parent + '"');
19    err.path = orig;
20    err.parent = parent;
21    err.require = true;
22    throw err;
23  }
24
25  var module = require.modules[resolved];
26
27  // perform real require()
28  // by invoking the module's
29  // registered function
30  if (!module._resolving && !module.exports) {
31    var mod = {};
32    mod.exports = {};
33    mod.client = mod.component = true;
34    module._resolving = true;
35    module.call(this, mod.exports, require.relative(resolved), mod);
36    delete module._resolving;
37    module.exports = mod.exports;
38  }
39
40  return module.exports;
41}
42
43/**
44 * Registered modules.
45 */
46
47require.modules = {};
48
49/**
50 * Registered aliases.
51 */
52
53require.aliases = {};
54
55/**
56 * Resolve `path`.
57 *
58 * Lookup:
59 *
60 *   - PATH/index.js
61 *   - PATH.js
62 *   - PATH
63 *
64 * @param {String} path
65 * @return {String} path or null
66 * @api private
67 */
68
69require.resolve = function(path) {
70  if (path.charAt(0) === '/') path = path.slice(1);
71
72  var paths = [
73    path,
74    path + '.js',
75    path + '.json',
76    path + '/index.js',
77    path + '/index.json'
78  ];
79
80  for (var i = 0; i < paths.length; i++) {
81    var path = paths[i];
82    if (require.modules.hasOwnProperty(path)) return path;
83    if (require.aliases.hasOwnProperty(path)) return require.aliases[path];
84  }
85};
86
87/**
88 * Normalize `path` relative to the current path.
89 *
90 * @param {String} curr
91 * @param {String} path
92 * @return {String}
93 * @api private
94 */
95
96require.normalize = function(curr, path) {
97  var segs = [];
98
99  if ('.' != path.charAt(0)) return path;
100
101  curr = curr.split('/');
102  path = path.split('/');
103
104  for (var i = 0; i < path.length; ++i) {
105    if ('..' == path[i]) {
106      curr.pop();
107    } else if ('.' != path[i] && '' != path[i]) {
108      segs.push(path[i]);
109    }
110  }
111
112  return curr.concat(segs).join('/');
113};
114
115/**
116 * Register module at `path` with callback `definition`.
117 *
118 * @param {String} path
119 * @param {Function} definition
120 * @api private
121 */
122
123require.register = function(path, definition) {
124  require.modules[path] = definition;
125};
126
127/**
128 * Alias a module definition.
129 *
130 * @param {String} from
131 * @param {String} to
132 * @api private
133 */
134
135require.alias = function(from, to) {
136  if (!require.modules.hasOwnProperty(from)) {
137    throw new Error('Failed to alias "' + from + '", it does not exist');
138  }
139  require.aliases[to] = from;
140};
141
142/**
143 * Return a require function relative to the `parent` path.
144 *
145 * @param {String} parent
146 * @return {Function}
147 * @api private
148 */
149
150require.relative = function(parent) {
151  var p = require.normalize(parent, '..');
152
153  /**
154   * lastIndexOf helper.
155   */
156
157  function lastIndexOf(arr, obj) {
158    var i = arr.length;
159    while (i--) {
160      if (arr[i] === obj) return i;
161    }
162    return -1;
163  }
164
165  /**
166   * The relative require() itself.
167   */
168
169  function localRequire(path) {
170    var resolved = localRequire.resolve(path);
171    return require(resolved, parent, path);
172  }
173
174  /**
175   * Resolve relative to the parent.
176   */
177
178  localRequire.resolve = function(path) {
179    var c = path.charAt(0);
180    if ('/' == c) return path.slice(1);
181    if ('.' == c) return require.normalize(p, path);
182
183    // resolve deps by returning
184    // the dep in the nearest "deps"
185    // directory
186    var segs = parent.split('/');
187    var i = lastIndexOf(segs, 'deps') + 1;
188    if (!i) i = 0;
189    path = segs.slice(0, i + 1).join('/') + '/deps/' + path;
190    return path;
191  };
192
193  /**
194   * Check if module is defined at `path`.
195   */
196
197  localRequire.exists = function(path) {
198    return require.modules.hasOwnProperty(localRequire.resolve(path));
199  };
200
201  return localRequire;
202};
203require.register("component-indexof/index.js", function(exports, require, module){
204module.exports = function(arr, obj){
205  if (arr.indexOf) return arr.indexOf(obj);
206  for (var i = 0; i < arr.length; ++i) {
207    if (arr[i] === obj) return i;
208  }
209  return -1;
210};
211});
212require.register("component-emitter/index.js", function(exports, require, module){
213
214/**
215 * Module dependencies.
216 */
217
218var index = require('indexof');
219
220/**
221 * Expose `Emitter`.
222 */
223
224module.exports = Emitter;
225
226/**
227 * Initialize a new `Emitter`.
228 *
229 * @api public
230 */
231
232function Emitter(obj) {
233  if (obj) return mixin(obj);
234};
235
236/**
237 * Mixin the emitter properties.
238 *
239 * @param {Object} obj
240 * @return {Object}
241 * @api private
242 */
243
244function mixin(obj) {
245  for (var key in Emitter.prototype) {
246    obj[key] = Emitter.prototype[key];
247  }
248  return obj;
249}
250
251/**
252 * Listen on the given `event` with `fn`.
253 *
254 * @param {String} event
255 * @param {Function} fn
256 * @return {Emitter}
257 * @api public
258 */
259
260Emitter.prototype.on =
261Emitter.prototype.addEventListener = function(event, fn){
262  this._callbacks = this._callbacks || {};
263  (this._callbacks[event] = this._callbacks[event] || [])
264    .push(fn);
265  return this;
266};
267
268/**
269 * Adds an `event` listener that will be invoked a single
270 * time then automatically removed.
271 *
272 * @param {String} event
273 * @param {Function} fn
274 * @return {Emitter}
275 * @api public
276 */
277
278Emitter.prototype.once = function(event, fn){
279  var self = this;
280  this._callbacks = this._callbacks || {};
281
282  function on() {
283    self.off(event, on);
284    fn.apply(this, arguments);
285  }
286
287  fn._off = on;
288  this.on(event, on);
289  return this;
290};
291
292/**
293 * Remove the given callback for `event` or all
294 * registered callbacks.
295 *
296 * @param {String} event
297 * @param {Function} fn
298 * @return {Emitter}
299 * @api public
300 */
301
302Emitter.prototype.off =
303Emitter.prototype.removeListener =
304Emitter.prototype.removeAllListeners =
305Emitter.prototype.removeEventListener = function(event, fn){
306  this._callbacks = this._callbacks || {};
307
308  // all
309  if (0 == arguments.length) {
310    this._callbacks = {};
311    return this;
312  }
313
314  // specific event
315  var callbacks = this._callbacks[event];
316  if (!callbacks) return this;
317
318  // remove all handlers
319  if (1 == arguments.length) {
320    delete this._callbacks[event];
321    return this;
322  }
323
324  // remove specific handler
325  var i = index(callbacks, fn._off || fn);
326  if (~i) callbacks.splice(i, 1);
327  return this;
328};
329
330/**
331 * Emit `event` with the given args.
332 *
333 * @param {String} event
334 * @param {Mixed} ...
335 * @return {Emitter}
336 */
337
338Emitter.prototype.emit = function(event){
339  this._callbacks = this._callbacks || {};
340  var args = [].slice.call(arguments, 1)
341    , callbacks = this._callbacks[event];
342
343  if (callbacks) {
344    callbacks = callbacks.slice(0);
345    for (var i = 0, len = callbacks.length; i < len; ++i) {
346      callbacks[i].apply(this, args);
347    }
348  }
349
350  return this;
351};
352
353/**
354 * Return array of callbacks for `event`.
355 *
356 * @param {String} event
357 * @return {Array}
358 * @api public
359 */
360
361Emitter.prototype.listeners = function(event){
362  this._callbacks = this._callbacks || {};
363  return this._callbacks[event] || [];
364};
365
366/**
367 * Check if this emitter has `event` handlers.
368 *
369 * @param {String} event
370 * @return {Boolean}
371 * @api public
372 */
373
374Emitter.prototype.hasListeners = function(event){
375  return !! this.listeners(event).length;
376};
377
378});
379require.register("component-props/index.js", function(exports, require, module){
380/**
381 * Global Names
382 */
383
384var globals = /\b(Array|Date|Object|Math|JSON)\b/g;
385
386/**
387 * Return immediate identifiers parsed from `str`.
388 *
389 * @param {String} str
390 * @param {String|Function} map function or prefix
391 * @return {Array}
392 * @api public
393 */
394
395module.exports = function(str, fn){
396  var p = unique(props(str));
397  if (fn && 'string' == typeof fn) fn = prefixed(fn);
398  if (fn) return map(str, p, fn);
399  return p;
400};
401
402/**
403 * Return immediate identifiers in `str`.
404 *
405 * @param {String} str
406 * @return {Array}
407 * @api private
408 */
409
410function props(str) {
411  return str
412    .replace(/\.\w+|\w+ *\(|"[^"]*"|'[^']*'|\/([^/]+)\//g, '')
413    .replace(globals, '')
414    .match(/[a-zA-Z_]\w*/g)
415    || [];
416}
417
418/**
419 * Return `str` with `props` mapped with `fn`.
420 *
421 * @param {String} str
422 * @param {Array} props
423 * @param {Function} fn
424 * @return {String}
425 * @api private
426 */
427
428function map(str, props, fn) {
429  var re = /\.\w+|\w+ *\(|"[^"]*"|'[^']*'|\/([^/]+)\/|[a-zA-Z_]\w*/g;
430  return str.replace(re, function(_){
431    if ('(' == _[_.length - 1]) return fn(_);
432    if (!~props.indexOf(_)) return _;
433    return fn(_);
434  });
435}
436
437/**
438 * Return unique array.
439 *
440 * @param {Array} arr
441 * @return {Array}
442 * @api private
443 */
444
445function unique(arr) {
446  var ret = [];
447
448  for (var i = 0; i < arr.length; i++) {
449    if (~ret.indexOf(arr[i])) continue;
450    ret.push(arr[i]);
451  }
452
453  return ret;
454}
455
456/**
457 * Map with prefix `str`.
458 */
459
460function prefixed(str) {
461  return function(_){
462    return str + _;
463  };
464}
465
466});
467require.register("component-to-function/index.js", function(exports, require, module){
468/**
469 * Module Dependencies
470 */
471
472try {
473  var expr = require('props');
474} catch(e) {
475  var expr = require('props-component');
476}
477
478/**
479 * Expose `toFunction()`.
480 */
481
482module.exports = toFunction;
483
484/**
485 * Convert `obj` to a `Function`.
486 *
487 * @param {Mixed} obj
488 * @return {Function}
489 * @api private
490 */
491
492function toFunction(obj) {
493  switch ({}.toString.call(obj)) {
494    case '[object Object]':
495      return objectToFunction(obj);
496    case '[object Function]':
497      return obj;
498    case '[object String]':
499      return stringToFunction(obj);
500    case '[object RegExp]':
501      return regexpToFunction(obj);
502    default:
503      return defaultToFunction(obj);
504  }
505}
506
507/**
508 * Default to strict equality.
509 *
510 * @param {Mixed} val
511 * @return {Function}
512 * @api private
513 */
514
515function defaultToFunction(val) {
516  return function(obj){
517    return val === obj;
518  }
519}
520
521/**
522 * Convert `re` to a function.
523 *
524 * @param {RegExp} re
525 * @return {Function}
526 * @api private
527 */
528
529function regexpToFunction(re) {
530  return function(obj){
531    return re.test(obj);
532  }
533}
534
535/**
536 * Convert property `str` to a function.
537 *
538 * @param {String} str
539 * @return {Function}
540 * @api private
541 */
542
543function stringToFunction(str) {
544  // immediate such as "> 20"
545  if (/^ *\W+/.test(str)) return new Function('_', 'return _ ' + str);
546
547  // properties such as "name.first" or "age > 18" or "age > 18 && age < 36"
548  return new Function('_', 'return ' + get(str));
549}
550
551/**
552 * Convert `object` to a function.
553 *
554 * @param {Object} object
555 * @return {Function}
556 * @api private
557 */
558
559function objectToFunction(obj) {
560  var match = {};
561  for (var key in obj) {
562    match[key] = typeof obj[key] === 'string'
563      ? defaultToFunction(obj[key])
564      : toFunction(obj[key])
565  }
566  return function(val){
567    if (typeof val !== 'object') return false;
568    for (var key in match) {
569      if (!(key in val)) return false;
570      if (!match[key](val[key])) return false;
571    }
572    return true;
573  }
574}
575
576/**
577 * Built the getter function. Supports getter style functions
578 *
579 * @param {String} str
580 * @return {String}
581 * @api private
582 */
583
584function get(str) {
585  var props = expr(str);
586  if (!props.length) return '_.' + str;
587
588  var val;
589  for(var i = 0, prop; prop = props[i]; i++) {
590    val = '_.' + prop;
591    val = "('function' == typeof " + val + " ? " + val + "() : " + val + ")";
592    str = str.replace(new RegExp(prop, 'g'), val);
593  }
594
595  return str;
596}
597
598});
599require.register("yields-isArray/index.js", function(exports, require, module){
600
601/**
602 * isArray
603 */
604
605var isArray = Array.isArray;
606
607/**
608 * toString
609 */
610
611var str = Object.prototype.toString;
612
613/**
614 * Wether or not the given `val`
615 * is an array.
616 *
617 * example:
618 *
619 *        isArray([]);
620 *        // > true
621 *        isArray(arguments);
622 *        // > false
623 *        isArray('');
624 *        // > false
625 *
626 * @param {mixed} val
627 * @return {bool}
628 */
629
630module.exports = isArray || function (val) {
631  return !! val && '[object Array]' == str.call(val);
632};
633
634});
635require.register("array/index.js", function(exports, require, module){
636module.exports = require('./lib/array');
637
638});
639require.register("array/lib/array.js", function(exports, require, module){
640/**
641 * Module dependencies
642 */
643
644var Enumerable = require('./enumerable');
645var proto = Array.prototype;
646var isArray = Array.isArray || require('isArray');
647
648try {
649  var Emitter = require('emitter');
650} catch(e) {
651  var Emitter = require('emitter-component');
652}
653
654/*
655 * Expose `array`
656 */
657
658module.exports = array;
659
660/**
661 * Initialize `array`
662 *
663 * @param {Array|Object|Undefined} arr
664 * @return {array}
665 * @api public
666 */
667
668function array(arr) {
669  if(!(this instanceof array)) return new array(arr);
670  arr = arr || [];
671
672  if (isArray(arr)) {
673    // create array-like object
674    var len = this.length = arr.length;
675    for(var i = 0; i < len; i++) this[i] = arr[i];
676  } else if ('object' == typeof arr) {
677    if (isObjectLiteral(arr)) {
678      arr._ctx = this._ctx = JSON.parse(JSON.stringify(arr));
679    }
680
681    // mixin to another object
682    for(var key in array.prototype) arr[key] = array.prototype[key];
683    return arr;
684  }
685}
686
687/**
688 * Mixin `Emitter`
689 */
690
691Emitter(array.prototype);
692
693/**
694 * Mixin `Enumerable`
695 */
696
697Enumerable(array.prototype);
698
699/**
700 * Removes the last element from an array and returns that element
701 *
702 * @return {Mixed} removed element
703 * @api public
704 */
705
706array.prototype.pop = function() {
707  var ret = proto.pop.apply(this, arguments);
708  this.emit('remove', ret, this.length);
709  return ret;
710};
711
712/**
713 * Push a value onto the end of the array,
714 * returning the length of the array
715 *
716 * @param {Mixed, ...} elements
717 * @return {Number}
718 * @api public
719 */
720
721array.prototype.push = function() {
722  var ret = proto.push.apply(this, arguments),
723      args = [].slice.call(arguments);
724  for(var i = 0, len = args.length; i < len; i++) this.emit('add', args[i], ret - len + i);
725  return ret;
726};
727
728/**
729 * Removes the first element from an array and returns that element.
730 *
731 * @return {Mixed}
732 * @api public
733 */
734
735array.prototype.shift = function() {
736  var ret = proto.shift.apply(this, arguments);
737  this.emit('remove', ret, 0);
738  return ret;
739};
740
741/**
742 * Adds and/or removes elements from an array.
743 *
744 * @param {Number} index
745 * @param {Number} howMany
746 * @param {Mixed, ...} elements
747 * @return {Array} removed elements
748 * @api public
749 */
750
751array.prototype.splice = function(index) {
752  var ret = proto.splice.apply(this, arguments),
753      added = [].slice.call(arguments, 2);
754  for(var i = 0, len = ret.length; i < len; i++) this.emit('remove', ret[i], index);
755  for(    i = 0, len = added.length; i < len; i++) this.emit('add', added[i], index + i);
756  return ret;
757};
758
759/**
760 * Adds one or more elements to the front of an array
761 * and returns the new length of the array.
762 *
763 * @param {Mixed, ...} elements
764 * @return {Number} length
765 * @api public
766 */
767
768array.prototype.unshift = function() {
769  var ret = proto.unshift.apply(this, arguments),
770      args = [].slice.call(arguments);
771  for(var i = 0, len = args.length; i < len;
771 i++) this.emit('add', args[i], i);
772  return ret;
773};
774
775/**
776 * toJSON
777 *
778 * @return {Object}
779 * @api public
780 */
781
782array.prototype.toJSON = function() {
783  return this.map(function(obj) {
784    return (obj.toJSON) ? obj.toJSON() : obj;
785  }).toArray();
786};
787
788/**
789 * Convert the array-like object to an actual array
790 *
791 * @return {Array}
792 * @api public
793 */
794
795array.prototype.toArray  = function() {
796  return proto.slice.call(this);
797};
798
799/**
800 * Static: get the array item
801 *
802 * @param {Mixed} obj
803 * @return {Mixed}
804 * @api public
805 */
806
807array.get = function(obj) {
808  return obj;
809};
810
811/**
812 * Get the array item
813 *
814 * @param {Number} i
815 * @return {Mixed}
816 * @api public
817 */
818
819array.prototype.get = array.get;
820
821/**
822 * Attach the rest of the array methods
823 */
824
825var methods = ['toString', 'reverse', 'concat', 'join', 'slice'];
826
827methods.forEach(function(method) {
828  array.prototype[method] = function() {
829    return proto[method].apply(this, arguments);
830  };
831});
832
833/**
834 * Remake the array, emptying it, then adding values back in
835 *
836 * @api private
837 */
838
839array.prototype._remake = function(arr) {
840  var construct = this.constructor;
841  var clone = (this._ctx) ? new construct(this._ctx) : new construct();
842  proto.push.apply(clone, arr);
843  clone.get = this.get || array.get;
844  return clone;
845};
846
847/**
848 * Is object utility
849 *
850 * @param {Mixed} obj
851 * @return {Boolean}
852 * @api private
853 */
854
855function isObjectLiteral(obj) {
856  return obj.constructor == Object;
857}
858
859});
860require.register("array/lib/enumerable.js", function(exports, require, module){
861/**
862 * Module Dependencies
863 */
864
865var toFunction = require('to-function'),
866    proto = Array.prototype,
867    enumerable = {};
868
869/**
870 * Mixin to `obj`.
871 *
872 *    var Enumerable = require('enumerable');
873 *    Enumerable(Something.prototype);
874 *
875 * @param {Object} obj
876 * @return {Object} obj
877 * @api private
878 */
879
880module.exports = function(obj) {
881  for(var key in enumerable) obj[key] = enumerable[key];
882  return obj;
883};
884
885/**
886 * Iterate each value and invoke `fn(val, i)`.
887 *
888 *    users.each(function(val, i){
889 *
890 *    })
891 *
892 * @param {Function} fn
893 * @return {Object} self
894 * @api public
895 */
896
897enumerable.forEach =
898enumerable.each = function(fn){
899  var arr = this,
900      len = arr.length;
901
902  for (var i = 0; i < len; i++) {
903    fn(arr[i], i);
904  }
905
906  return this;
907};
908
909/**
910 * Map each return value from `fn(val, i)`.
911 *
912 * Passing a callback function:
913 *
914 *    users.map(function(user){
915 *      return user.name.first
916 *    })
917 *
918 * Passing a property string:
919 *
920 *    users.map('name.first')
921 *
922 * @param {Function} fn
923 * @return {Enumerable}
924 * @api public
925 */
926
927enumerable.map = function(fn){
928  fn = toFunction(fn);
929  var arr = this,
930      len = arr.length;
931
932  for (var i = 0; i < len; ++i) {
933    arr[i] = fn(arr.get(arr[i]), i);
934  }
935
936  return this;
937};
938
939/**
940 * Select all values that return a truthy value of `fn(val, i)`.
941 *
942 *    users.select(function(user){
943 *      return user.age > 20
944 *    })
945 *
946 *  With a property:
947 *
948 *    items.select('complete')
949 *
950 * @param {Function|String} fn
951 * @return {Enumerable}
952 * @api public
953 */
954
955enumerable.filter =
956enumerable.select = function(fn){
957  fn = toFunction(fn);
958  var out = [],
959      arr = this,
960      len = arr.length,
961      val;
962
963  for (var i = 0; i < len; ++i) {
964    val = arr.get(arr[i]);
965    if (fn(val, i)) out.push(arr[i]);
966  }
967
968  return this._remake(out);
969};
970
971/**
972 * Select all unique values.
973 *
974 *    nums.unique()
975 *
976 * @param {Function|String} fn
977 * @return {Enumerable}
978 * @api public
979 */
980
981enumerable.unique = function(fn){
982  var out = [],
983      vals = [],
984      arr = this,
985      len = arr.length,
986      val;
987
988  fn = (fn) ? toFunction(fn) : function(o) { return o; };
989
990  for (var i = 0; i < len; ++i) {
991    val = fn(arr.get(arr[i]));
992    if (~vals.indexOf(val)) continue;
993    vals.push(val);
994    out.push(arr[i]);
995  }
996
997  return this._remake(out);
998};
999
1000/**
1001 * Reject all values that return a truthy value of `fn(val, i)`.
1002 *
1003 * Rejecting using a callback:
1004 *
1005 *    users.reject(function(user){
1006 *      return user.age < 20
1007 *    })
1008 *
1009 * Rejecting with a property:
1010 *
1011 *    items.reject('complete')
1012 *
1013 * Rejecting values via `==`:
1014 *
1015 *    data.reject(null)
1016 *    users.reject(tobi)
1017 *
1018 * @param {Function|String|Mixed} fn
1019 * @return {Enumerable}
1020 * @api public
1021 */
1022
1023enumerable.reject = function(fn){
1024  var out = [],
1025      arr = this,
1026      len = arr.length,
1027      val, i;
1028
1029  if ('string' == typeof fn) fn = toFunction(fn);
1030  if (fn) {
1031    for (i = 0; i < len; ++i) {
1032      val = arr.get(arr[i]);
1033      if (!fn(val, i)) out.push(arr[i]);
1034    }
1035  } else {
1036    for (i = 0; i < len; ++i) {
1037      val = arr.get(arr[i]);
1038      if (val != fn) out.push(arr[i]);
1039    }
1040  }
1041
1042  return this._remake(out);
1043};
1044
1045/**
1046 * Reject `null` and `undefined`.
1047 *
1048 *    [1, null, 5, undefined].compact()
1049 *    // => [1,5]
1050 *
1051 * @return {Enumerable}
1052 * @api public
1053 */
1054
1055
1056enumerable.compact = function(){
1057  return this.reject(null);
1058};
1059
1060/**
1061 * Return the first value when `fn(val, i)` is truthy,
1062 * otherwise return `undefined`.
1063 *
1064 *    users.find(function(user){
1065 *      return user.role == 'admin'
1066 *    })
1067 *
1068 * With a property string:
1069 *
1070 *    users.find('age > 20')
1071 *
1072 * @param {Function|String} fn
1073 * @return {Mixed}
1074 * @api public
1075 */
1076
1077enumerable.find = function(fn){
1078  fn = toFunction(fn);
1079  var arr = this,
1080      len = arr.length,
1081      val;
1082
1083  for (var i = 0; i < len; ++i) {
1084    val = arr.get(arr[i]);
1085    if (fn(val, i)) return arr[i];
1086  }
1087};
1088
1089/**
1090 * Return the last value when `fn(val, i)` is truthy,
1091 * otherwise return `undefined`.
1092 *
1093 *    users.findLast(function(user){
1094 *      return user.role == 'admin'
1095 *    })
1096 *
1097 * @param {Function} fn
1098 * @return {Mixed}
1099 * @api public
1100 */
1101
1102enumerable.findLast = function (fn) {
1103    fn = toFunction(fn);
1104  var arr = this,
1105  i = arr.length;
1106
1107  while(i--) if (fn(arr.get(arr[i]), i)) return arr[i];
1108};
1109
1110/**
1111 * Assert that all invocations of `fn(val, i)` are truthy.
1112 *
1113 * For example ensuring that all pets are ferrets:
1114 *
1115 *    pets.all(function(pet){
1116 *      return pet.species == 'ferret'
1117 *    })
1118 *
1119 *    users.all('admin')
1120 *
1121 * @param {Function|String} fn
1122 * @return {Boolean}
1123 * @api public
1124 */
1125
1126enumerable.every = function(fn){
1127  fn = toFunction(fn);
1128  var arr = this,
1129      len = arr.length,
1130      val;
1131
1132  for (var i = 0; i < len; ++i) {
1133    val = arr.get(arr[i]);
1134    if (!fn(val, i)) return false;
1135  }
1136
1137  return true;
1138};
1139
1140/**
1141 * Assert that none of the invocations of `fn(val, i)` are truthy.
1142 *
1143 * For example ensuring that no pets are admins:
1144 *
1145 *    pets.none(function(p){ return p.admin })
1146 *    pets.none('admin')
1147 *
1148 * @param {Function|String} fn
1149 * @return {Boolean}
1150 * @api public
1151 */
1152
1153enumerable.none = function(fn){
1154  fn = toFunction(fn);
1155  var arr = this,
1156      len = arr.length,
1157      val;
1158
1159  for (var i = 0; i < len; ++i) {
1160    val = arr.get(arr[i]);
1161    if (fn(val, i)) return false;
1162  }
1163  return true;
1164};
1165
1166/**
1167 * Assert that at least one invocation of `fn(val, i)` is truthy.
1168 *
1169 * For example checking to see if any pets are ferrets:
1170 *
1171 *    pets.any(function(pet){
1172 *      return pet.species == 'ferret'
1173 *    })
1174 *
1175 * @param {Function} fn
1176 * @return {Boolean}
1177 * @api public
1178 */
1179
1180enumerable.any = function(fn){
1181  fn = toFunction(fn);
1182  var arr = this,
1183      len = arr.length,
1184      val;
1185
1186  for (var i = 0; i < len; ++i) {
1187    val = arr.get(arr[i]);
1188    if (fn(val, i)) return true;
1189  }
1190  return false;
1191};
1192
1193/**
1194 * Count the number of times `fn(val, i)` returns true.
1195 *
1196 *    var n = pets.count(function(pet){
1197 *      return pet.species == 'ferret'
1198 *    })
1199 *
1200 * @param {Function} fn
1201 * @return {Number}
1202 * @api public
1203 */
1204
1205enumerable.count = function(fn){
1206  fn = toFunction(fn);
1207  var n = 0,
1208      arr = this,
1209      len = arr.length,
1210      val;
1211
1212  if(!fn) return len;
1213
1214  for (var i = 0; i < len; ++i) {
1215    val = arr.get(arr[i]);
1216    if (fn(val, i)) ++n;
1217  }
1218  return n;
1219};
1220
1221/**
1222 * Determine the indexof `obj` or return `-1`.
1223 *
1224 * @param {Mixed} obj
1225 * @return {Number}
1226 * @api public
1227 */
1228
1229enumerable.indexOf = function(obj) {
1230  var arr = this,
1231      len = arr.length,
1232      val;
1233
1234  for (var i = 0; i < len; ++i) {
1235    val = arr.get(arr[i]);
1236    if (val === obj) return i;
1237  }
1238
1239  return -1;
1240};
1241
1242/**
1243 * Determine the last indexof `obj` or return `-1`.
1244 *
1245 * @param {Mixed} obj
1246 * @return {Number}
1247 * @api public
1248 */
1249
1250enumerable.lastIndexOf = function(obj) {
1251  var arr = this,
1252      len = arr.length,
1253      val;
1254
1255  for (var i = --len; i >= 0; --i) {
1256    val = arr.get(arr[i]);
1257    if (val === obj) return i;
1258  }
1259
1260  return -1;
1261};
1262
1263/**
1264 * Check if `obj` is present in this enumerable.
1265 *
1266 * @param {Mixed} obj
1267 * @return {Boolean}
1268 * @api public
1269 */
1270
1271enumerable.has = function(obj) {
1272  return !! ~this.indexOf(obj);
1273};
1274
1275/**
1276 * Reduce with `fn(accumulator, val, i)` using
1277 * optional `init` value defaulting to the first
1278 * enumerable value.
1279 *
1280 * @param {Function} fn
1281 * @param {Mixed} [val]
1282 * @return {Mixed}
1283 * @api public
1284 */
1285
1286enumerable.reduce = function(fn, init){
1287  var arr = this,
1288      len = arr.length,
1289      i = 0,
1290      val;
1291
1292  val = null == init
1293    ? arr.get(i++)
1294    : init;
1295
1296  for (; i < len; ++i) {
1297    val = fn(val, arr.get(arr[i]), i);
1298  }
1299
1300  return val;
1301};
1302
1303
1304/**
1305 * Determine the max value.
1306 *
1307 * With a callback function:
1308 *
1309 *    pets.max(function(pet){
1310 *      return pet.age
1311 *    })
1312 *
1313 * With property strings:
1314 *
1315 *    pets.max('age')
1316 *
1317 * With immediate values:
1318 *
1319 *    nums.max()
1320 *
1321 * @param {Function|String} fn
1322 * @return {Number}
1323 * @api public
1324 */
1325
1326enumerable.max = function(fn){
1327  var arr = this,
1328      len = arr.length,
1329      max = -Infinity,
1330      n = 0,
1331      val, i;
1332
1333  if (fn) {
1334    fn = toFunction(fn);
1335    for (i = 0; i < len; ++i) {
1336      n = fn(arr.get(arr[i]), i);
1337      max = n > max ? n : max;
1338    }
1339  } else {
1340    for (i = 0; i < len; ++i) {
1341      n = arr.get(arr[i]);
1342      max = n > max ? n : max;
1343    }
1344  }
1345
1346  return max;
1347};
1348
1349/**
1350 * Determine the min value.
1351 *
1352 * With a callback function:
1353 *
1354 *    pets.min(function(pet){
1355 *      return pet.age
1356 *    })
1357 *
1358 * With property strings:
1359 *
1360 *    pets.min('age')
1361 *
1362 * With immediate values:
1363 *
1364 *    nums.min()
1365 *
1366 * @param {Function|String} fn
1367 * @return {Number}
1368 * @api public
1369 */
1370
1371enumerable.min = function(fn){
1372  var arr = this,
1373      len = arr.length,
1374      min = Infinity,
1375      n = 0,
1376      val, i;
1377
1378  if (fn) {
1379    fn = toFunction(fn);
1380    for (i = 0; i < len; ++i) {
1381      n = fn(arr.get(arr[i]), i);
1382      min = n < min ? n : min;
1383    }
1384  } else {
1385    for (i = 0; i < len; ++i) {
1386      n = arr.get(arr[i]);
1387      min = n < min ? n : min;
1388    }
1389  }
1390
1391  return min;
1392};
1393
1394/**
1395 * Determine the sum.
1396 *
1397 * With a callback function:
1398 *
1399 *    pets.sum(function(pet){
1400 *      return pet.age
1401 *    })
1402 *
1403 * With property strings:
1404 *
1405 *    pets.sum('age')
1406 *
1407 * With immediate values:
1408 *
1409 *    nums.sum()
1410 *
1411 * @param {Function|String} fn
1412 * @return {Number}
1413 * @api public
1414 */
1415
1416enumerable.sum = function(fn){
1417  var arr = this,
1418      len = arr.length,
1419      n = 0,
1420      val, i;
1421
1422  if (fn) {
1423    fn = toFunction(fn);
1424    for (i = 0; i < len; ++i) {
1425      n += fn(arr.get(arr[i]), i);
1426    }
1427  } else {
1428    for (i = 0; i < len; ++i) {
1429      n += arr.get(arr[i]);
1430    }
1431  }
1432
1433  return n;
1434};
1435
1436/**
1437 * Determine the average value.
1438 *
1439 * With a callback function:
1440 *
1441 *    pets.avg(function(pet){
1442 *      return pet.age
1443 *    })
1444 *
1445 * With property strings:
1446 *
1447 *    pets.avg('age')
1448 *
1449 * With immediate values:
1450 *
1451 *    nums.avg()
1452 *
1453 * @param {Function|String} fn
1454 * @return {Number}
1455 * @api public
1456 */
1457
1458enumerable.avg =
1459enumerable.mean = function(fn){
1460  var arr = this,
1461      len = arr.length,
1462      n = 0,
1463      val, i;
1464
1465  if (fn) {
1466    fn = toFunction(fn);
1467    for (i = 0; i < len; ++i) {
1468      n += fn(arr.get(arr[i]), i);
1469    }
1470  } else {
1471    for (i = 0; i < len; ++i) {
1472      n += arr.get(arr[i]);
1473    }
1474  }
1475
1476  return n / len;
1477};
1478
1479/**
1480 * Return the first value, or first `n` values.
1481 *
1482 * @param {Number|Function} [n]
1483 * @return {Array|Mixed}
1484 * @api public
1485 */
1486
1487enumerable.first = function(n) {
1488  var arr = this;
1489
1490  if(!n) return arr[0];
1491  else if ('number' !== typeof n) return this.find(n);
1492
1493  var len = Math.min(n, arr.length),
1494      out = new Array(len);
1495
1496  for (var i = 0; i < len; ++i) {
1497    out[i] = arr[i];
1498  }
1499
1500  return out;
1501
1502};
1503
1504/**
1505 * Return the last value, or last `n` values.
1506 *
1507 * @param {Number|Function} [n]
1508 * @return {Array|Mixed}
1509 * @api public
1510 */
1511
1512enumerable.last = function(n){
1513  var arr = this,
1514      len = arr.length;
1515
1516  if(!n) return arr[len - 1];
1517  else if ('number' !== typeof n) return this.findLast(n);
1518
1519  var i = Math.max(0, len - n),
1520      out = [];
1521
1522  for (; i < len; ++i) {
1523    out.push(arr[i]);
1524  }
1525
1526  return out;
1527};
1528
1529/**
1530 * Create a hash from a given `key`
1531 *
1532 * @param {String} key
1533 * @return {Object}
1534 * @api public
1535 */
1536
1537enumerable.hash = function(str) {
1538  var arr = this,
1539      len = arr.length,
1540      out = {},
1541      key;
1542
1543  for (var i = 0, len = arr.length; i < len; i++) {
1544    key = arr.get(arr[i])[str];
1545    // TODO: assess, maybe we want out[i] = arr.get(i)
1546    if(!key) continue;
1547    out[key] = arr[i];
1548  };
1549
1550  return out;
1551};
1552
1553/**
1554 * Sort the array.
1555 *
1556 * With strings:
1557 *
1558 *   fruits.sort('calories')
1559 *
1560 * Descending sort:
1561 *
1562 *   fruits.sort('calories', 'desc')
1563 *
1564 * @param {undefined|Function|String} fn
1565 * @param {Nunber|String|Boolean} dir
1566 * @return {Array}
1567 * @api public
1568 */
1569
1570enumerable.sort = function(fn, dir) {
1571  dir = (dir !== undefined) ? dir : 1;
1572  var sort = proto.sort;
1573  if(!fn) return sort.apply(this);
1574  else if('function' == typeof fn) return sort.apply(this, arguments);
1575
1576  var self = this;
1577  fn = toFunction(fn);
1578
1579  // support ascending and descending directions
1580  if('string' == typeof dir) {
1581    if(/asc/.test(dir)) dir = 1;
1582    else if(/des/.test(dir)) dir = -1;
1583  } else if('boolean' == typeof dir) {
1584    dir = (dir) ? 1 : -1;
1585  }
1586
1587  function compare(a, b) {
1588    a = fn(self.get(a)), b = fn(self.get(b));
1589    if(a < b) return -(dir);
1590    else if(a > b) return dir;
1591    return 0
1592  };
1593
1594  return sort.call(this, compare);
1595};
1596
1597});
1598
1599
1600
1601
1602
1603
1604require.alias("component-emitter/index.js", "array/deps/emitter/index.js");
1605require.alias("component-emitter/index.js", "emitter/index.js");
1606require.alias("component-indexof/index.js", "component-emitter/deps/indexof/index.js");
1607
1608require.alias("component-to-function/index.js", "array/deps/to-function/index.js");
1609require.alias("component-to-function/index.js", "to-function/index.js");
1610require.alias("component-props/index.js", "component-to-function/deps/props/index.js");
1611require.alias("component-props/index.js", "component-to-function/deps/props/index.js");
1612require.alias("component-props/index.js", "component-props/index.js");
1613require.alias("yields-isArray/index.js", "array/deps/isArray/index.js");
1614require.alias("yields-isArray/index.js", "isArray/index.js");
1615if (typeof exports == "object") {
1616  module.exports = require("array");
1617} else if (typeof define == "function" && define.amd) {
1618  define(function(){ return require("array"); });
1619} else {
1620  this["array"] = require("array");
1621}})();

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.