Current File : //home/tradevaly/www/node_modules/contra/dist/contra.js
(function(f){if(typeof exports==="object"&&typeof module!=="undefined"){module.exports=f()}else if(typeof define==="function"&&define.amd){define([],f)}else{var g;if(typeof window!=="undefined"){g=window}else if(typeof global!=="undefined"){g=global}else if(typeof self!=="undefined"){g=self}else{g=this}g.contra = f()}})(function(){var define,module,exports;return (function e(t,n,r){function s(o,u){if(!n[o]){if(!t[o]){var a=typeof require=="function"&&require;if(!u&&a)return a(o,!0);if(i)return i(o,!0);var f=new Error("Cannot find module '"+o+"'");throw f.code="MODULE_NOT_FOUND",f}var l=n[o]={exports:{}};t[o][0].call(l.exports,function(e){var n=t[o][1][e];return s(n?n:e)},l,l.exports,e,t,n,r)}return n[o].exports}var i=typeof require=="function"&&require;for(var o=0;o<r.length;o++)s(r[o]);return s})({1:[function(require,module,exports){
module.exports = Infinity;

},{}],2:[function(require,module,exports){
module.exports = 1;

},{}],3:[function(require,module,exports){
'use strict';

var _map = require('./_map');

module.exports = function each (concurrency) {
  return _map(concurrency, then);
  function then (collection, done) {
    return function mask (err) {
      done(err); // only return the error, no more arguments
    };
  }
};

},{"./_map":5}],4:[function(require,module,exports){
'use strict';

var a = require('./a');
var _map = require('./_map');

module.exports = function filter (concurrency) {
  return _map(concurrency, then);
  function then (collection, done) {
    return function filter (err, results) {
      function exists (item, key) {
        return !!results[key];
      }
      function ofilter () {
        var filtered = {};
        Object.keys(collection).forEach(function omapper (key) {
          if (exists(null, key)) { filtered[key] = collection[key]; }
        });
        return filtered;
      }
      if (err) { done(err); return; }
      done(null, a(results) ? collection.filter(exists) : ofilter());
    };
  }
};

},{"./_map":5,"./a":6}],5:[function(require,module,exports){
'use strict';

var a = require('./a');
var once = require('./once');
var concurrent = require('./concurrent');
var CONCURRENTLY = require('./CONCURRENTLY');
var SERIAL = require('./SERIAL');

module.exports = function _map (cap, then, attached) {
  function api (collection, concurrency, iterator, done) {
    var args = arguments;
    if (args.length === 2) { iterator = concurrency; concurrency = CONCURRENTLY; }
    if (args.length === 3 && typeof concurrency !== 'number') { done = iterator; iterator = concurrency; concurrency = CONCURRENTLY; }
    var keys = Object.keys(collection);
    var tasks = a(collection) ? [] : {};
    keys.forEach(function insert (key) {
      tasks[key] = function iterate (cb) {
        if (iterator.length === 3) {
          iterator(collection[key], key, cb);
        } else {
          iterator(collection[key], cb);
        }
      };
    });
    concurrent(tasks, cap || concurrency, then ? then(collection, once(done)) : done);
  }
  if (!attached) { api.series = _map(SERIAL, then, true); }
  return api;
};

},{"./CONCURRENTLY":1,"./SERIAL":2,"./a":6,"./concurrent":7,"./once":19}],6:[function(require,module,exports){
'use strict';

module.exports = function a (o) { return Object.prototype.toString.call(o) === '[object Array]'; };

},{}],7:[function(require,module,exports){
'use strict';

var atoa = require('atoa');
var a = require('./a');
var once = require('./once');
var queue = require('./queue');
var errored = require('./errored');
var debounce = require('./debounce');
var CONCURRENTLY = require('./CONCURRENTLY');

module.exports = function concurrent (tasks, concurrency, done) {
  if (typeof concurrency === 'function') { done = concurrency; concurrency = CONCURRENTLY; }
  var d = once(done);
  var q = queue(worker, concurrency);
  var keys = Object.keys(tasks);
  var results = a(tasks) ? [] : {};
  q.unshift(keys);
  q.on('drain', function completed () { d(null, results); });
  function worker (key, next) {
    debounce(tasks[key], [proceed]);
    function proceed () {
      var args = atoa(arguments);
      if (errored(args, d)) { return; }
      results[key] = args.shift();
      next();
    }
  }
};

},{"./CONCURRENTLY":1,"./a":6,"./debounce":10,"./errored":13,"./once":19,"./queue":20,"atoa":16}],8:[function(require,module,exports){
'use strict';

module.exports = {
  curry: require('./curry'),
  concurrent: require('./concurrent'),
  series: require('./series'),
  waterfall: require('./waterfall'),
  each: require('./each'),
  map: require('./map'),
  filter: require('./filter'),
  queue: require('./queue'),
  emitter: require('./emitter')
};

},{"./concurrent":7,"./curry":9,"./each":11,"./emitter":12,"./filter":14,"./map":15,"./queue":20,"./series":21,"./waterfall":22}],9:[function(require,module,exports){
'use strict';

var atoa = require('atoa');

module.exports = function curry () {
  var args = atoa(arguments);
  var method = args.shift();
  return function curried () {
    var more = atoa(arguments);
    method.apply(method, args.concat(more));
  };
};

},{"atoa":16}],10:[function(require,module,exports){
'use strict';

var ticky = require('ticky');

module.exports = function debounce (fn, args, ctx) {
  if (!fn) { return; }
  ticky(function run () {
    fn.apply(ctx || null, args || []);
  });
};

},{"ticky":17}],11:[function(require,module,exports){
'use strict';

module.exports = require('./_each')();

},{"./_each":3}],12:[function(require,module,exports){
'use strict';

var atoa = require('atoa');
var debounce = require('./debounce');

module.exports = function emitter (thing, options) {
  var opts = options || {};
  var evt = {};
  if (thing === undefined) { thing = {}; }
  thing.on = function (type, fn) {
    if (!evt[type]) {
      evt[type] = [fn];
    } else {
      evt[type].push(fn);
    }
    return thing;
  };
  thing.once = function (type, fn) {
    fn._once = true; // thing.off(fn) still works!
    thing.on(type, fn);
    return thing;
  };
  thing.off = function (type, fn) {
    var c = arguments.length;
    if (c === 1) {
      delete evt[type];
    } else if (c === 0) {
      evt = {};
    } else {
      var et = evt[type];
      if (!et) { return thing; }
      et.splice(et.indexOf(fn), 1);
    }
    return thing;
  };
  thing.emit = function () {
    var args = atoa(arguments);
    return thing.emitterSnapshot(args.shift()).apply(this, args);
  };
  thing.emitterSnapshot = function (type) {
    var et = (evt[type] || []).slice(0);
    return function () {
      var args = atoa(arguments);
      var ctx = this || thing;
      if (type === 'error' && opts.throws !== false && !et.length) { throw args.length === 1 ? args[0] : args; }
      et.forEach(function emitter (listen) {
        if (opts.async) { debounce(listen, args, ctx); } else { listen.apply(ctx, args); }
        if (listen._once) { thing.off(type, listen); }
      });
      return thing;
    };
  };
  return thing;
};

},{"./debounce":10,"atoa":16}],13:[function(require,module,exports){
'use strict';

var debounce = require('./debounce');

module.exports = function errored (args, done, disposable) {
  var err = args.shift();
  if (err) { if (disposable) { disposable.discard(); } debounce(done, [err]); return true; }
};

},{"./debounce":10}],14:[function(require,module,exports){
'use strict';

module.exports = require('./_filter')();

},{"./_filter":4}],15:[function(require,module,exports){
'use strict';

module.exports = require('./_map')();

},{"./_map":5}],16:[function(require,module,exports){
module.exports = function atoa (a, n) { return Array.prototype.slice.call(a, n); }

},{}],17:[function(require,module,exports){
var si = typeof setImmediate === 'function', tick;
if (si) {
  tick = function (fn) { setImmediate(fn); };
} else {
  tick = function (fn) { setTimeout(fn, 0); };
}

module.exports = tick;
},{}],18:[function(require,module,exports){
'use strict';

module.exports = function noop () {};

},{}],19:[function(require,module,exports){
'use strict';

var noop = require('./noop');

module.exports = function once (fn) {
  var disposed;
  function disposable () {
    if (disposed) { return; }
    disposed = true;
    (fn || noop).apply(null, arguments);
  }
  disposable.discard = function () { disposed = true; };
  return disposable;
};

},{"./noop":18}],20:[function(require,module,exports){
'use strict';

var atoa = require('atoa');
var a = require('./a');
var once = require('./once');
var emitter = require('./emitter');
var debounce = require('./debounce');

module.exports = function queue (worker, concurrency) {
  var q = [], load = 0, max = concurrency || 1, paused;
  var qq = emitter({
    push: manipulate.bind(null, 'push'),
    unshift: manipulate.bind(null, 'unshift'),
    pause: function pause () { paused = true; },
    resume: function resume () { paused = false; debounce(labor); },
    pending: q
  });
  if (Object.defineProperty && !Object.definePropertyPartial) {
    Object.defineProperty(qq, 'length', { get: function getter () { return q.length; } });
  }
  function manipulate (how, task, done) {
    var tasks = a(task) ? task : [task];
    tasks.forEach(function insert (t) { q[how]({ t: t, done: done }); });
    debounce(labor);
  }
  function labor () {
    if (paused || load >= max) { return; }
    if (!q.length) { if (load === 0) { qq.emit('drain'); } return; }
    load++;
    var job = q.pop();
    worker(job.t, once(complete.bind(null, job)));
    debounce(labor);
  }
  function complete (job) {
    load--;
    debounce(job.done, atoa(arguments, 1));
    debounce(labor);
  }
  return qq;
};

},{"./a":6,"./debounce":10,"./emitter":12,"./once":19,"atoa":16}],21:[function(require,module,exports){
'use strict';

var concurrent = require('./concurrent');
var SERIAL = require('./SERIAL');

module.exports = function series (tasks, done) {
  concurrent(tasks, SERIAL, done);
};

},{"./SERIAL":2,"./concurrent":7}],22:[function(require,module,exports){
'use strict';

var atoa = require('atoa');
var once = require('./once');
var errored = require('./errored');
var debounce = require('./debounce');

module.exports = function waterfall (steps, done) {
  var d = once(done);
  function next () {
    var args = atoa(arguments);
    var step = steps.shift();
    if (step) {
      if (errored(args, d)) { return; }
      args.push(once(next));
      debounce(step, args);
    } else {
      debounce(d, arguments);
    }
  }
  next();
};

},{"./debounce":10,"./errored":13,"./once":19,"atoa":16}]},{},[8])(8)
});
//# sourceMappingURL=data:application/json;charset:utf-8;base64,eyJ2ZXJzaW9uIjozLCJzb3VyY2VzIjpbIm5vZGVfbW9kdWxlcy9icm93c2VyLXBhY2svX3ByZWx1ZGUuanMiLCJDT05DVVJSRU5UTFkuanMiLCJTRVJJQUwuanMiLCJfZWFjaC5qcyIsIl9maWx0ZXIuanMiLCJfbWFwLmpzIiwiYS5qcyIsImNvbmN1cnJlbnQuanMiLCJjb250cmEuanMiLCJjdXJyeS5qcyIsImRlYm91bmNlLmpzIiwiZWFjaC5qcyIsImVtaXR0ZXIuanMiLCJlcnJvcmVkLmpzIiwiZmlsdGVyLmpzIiwibWFwLmpzIiwibm9kZV9tb2R1bGVzL2F0b2EvYXRvYS5qcyIsIm5vZGVfbW9kdWxlcy90aWNreS90aWNreS1icm93c2VyLmpzIiwibm9vcC5qcyIsIm9uY2UuanMiLCJxdWV1ZS5qcyIsInNlcmllcy5qcyIsIndhdGVyZmFsbC5qcyJdLCJuYW1lcyI6W10sIm1hcHBpbmdzIjoiQUFBQTtBQ0FBO0FBQ0E7O0FDREE7QUFDQTs7QUNEQTtBQUNBO0FBQ0E7QUFDQTtBQUNBO0FBQ0E7QUFDQTtBQUNBO0FBQ0E7QUFDQTtBQUNBO0FBQ0E7QUFDQTs7QUNaQTtBQUNBO0FBQ0E7QUFDQTtBQUNBO0FBQ0E7QUFDQTtBQUNBO0FBQ0E7QUFDQTtBQUNBO0FBQ0E7QUFDQTtBQUNBO0FBQ0E7QUFDQTtBQUNBO0FBQ0E7QUFDQT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