'use strict'; function createCommonjsModule(fn) { var module = { exports: {} }; return fn(module, module.exports), module.exports; } function RetryOperation(timeouts, options) { // Compatibility for the old (timeouts, retryForever) signature if (typeof options === 'boolean') { options = { forever: options }; } this._originalTimeouts = JSON.parse(JSON.stringify(timeouts)); this._timeouts = timeouts; this._options = options || {}; this._maxRetryTime = options && options.maxRetryTime || Infinity; this._fn = null; this._errors = []; this._attempts = 1; this._operationTimeout = null; this._operationTimeoutCb = null; this._timeout = null; this._operationStart = null; if (this._options.forever) { this._cachedTimeouts = this._timeouts.slice(0); } } var retry_operation = RetryOperation; RetryOperation.prototype.reset = function() { this._attempts = 1; this._timeouts = this._originalTimeouts; }; RetryOperation.prototype.stop = function() { if (this._timeout) { clearTimeout(this._timeout); } this._timeouts = []; this._cachedTimeouts = null; }; RetryOperation.prototype.retry = function(err) { if (this._timeout) { clearTimeout(this._timeout); } if (!err) { return false; } var currentTime = new Date().getTime(); if (err && currentTime - this._operationStart >= this._maxRetryTime) { this._errors.unshift(new Error('RetryOperation timeout occurred')); return false; } this._errors.push(err); var timeout = this._timeouts.shift(); if (timeout === undefined) { if (this._cachedTimeouts) { // retry forever, only keep last error this._errors.splice(this._errors.length - 1, this._errors.length); this._timeouts = this._cachedTimeouts.slice(0); timeout = this._timeouts.shift(); } else { return false; } } var self = this; var timer = setTimeout(function() { self._attempts++; if (self._operationTimeoutCb) { self._timeout = setTimeout(function() { self._operationTimeoutCb(self._attempts); }, self._operationTimeout); if (self._options.unref) { self._timeout.unref(); } } self._fn(self._attempts); }, timeout); if (this._options.unref) { timer.unref(); } return true; }; RetryOperation.prototype.attempt = function(fn, timeoutOps) { this._fn = fn; if (timeoutOps) { if (timeoutOps.timeout) { this._operationTimeout = timeoutOps.timeout; } if (timeoutOps.cb) { this._operationTimeoutCb = timeoutOps.cb; } } var self = this; if (this._operationTimeoutCb) { this._timeout = setTimeout(function() { self._operationTimeoutCb(); }, self._operationTimeout); } this._operationStart = new Date().getTime(); this._fn(this._attempts); }; RetryOperation.prototype.try = function(fn) { console.log('Using RetryOperation.try() is deprecated'); this.attempt(fn); }; RetryOperation.prototype.start = function(fn) { console.log('Using RetryOperation.start() is deprecated'); this.attempt(fn); }; RetryOperation.prototype.start = RetryOperation.prototype.try; RetryOperation.prototype.errors = function() { return this._errors; }; RetryOperation.prototype.attempts = function() { return this._attempts; }; RetryOperation.prototype.mainError = function() { if (this._errors.length === 0) { return null; } var counts = {}; var mainError = null; var mainErrorCount = 0; for (var i = 0; i < this._errors.length; i++) { var error = this._errors[i]; var message = error.message; var count = (counts[message] || 0) + 1; counts[message] = count; if (count >= mainErrorCount) { mainError = error; mainErrorCount = count; } } return mainError; }; var retry = createCommonjsModule(function (module, exports) { exports.operation = function(options) { var timeouts = exports.timeouts(options); return new retry_operation(timeouts, { forever: options && options.forever, unref: options && options.unref, maxRetryTime: options && options.maxRetryTime }); }; exports.timeouts = function(options) { if (options instanceof Array) { return [].concat(options); } var opts = { retries: 10, factor: 2, minTimeout: 1 * 1000, maxTimeout: Infinity, randomize: false }; for (var key in options) { opts[key] = options[key]; } if (opts.minTimeout > opts.maxTimeout) { throw new Error('minTimeout is greater than maxTimeout'); } var timeouts = []; for (var i = 0; i < opts.retries; i++) { timeouts.push(this.createTimeout(i, opts)); } if (options && options.forever && !timeouts.length) { timeouts.push(this.createTimeout(i, opts)); } // sort the array numerically ascending timeouts.sort(function(a,b) { return a - b; }); return timeouts; }; exports.createTimeout = function(attempt, opts) { var random = (opts.randomize) ? (Math.random() + 1) : 1; var timeout = Math.round(random * opts.minTimeout * Math.pow(opts.factor, attempt)); timeout = Math.min(timeout, opts.maxTimeout); return timeout; }; exports.wrap = function(obj, options, methods) { if (options instanceof Array) { methods = options; options = null; } if (!methods) { methods = []; for (var key in obj) { if (typeof obj[key] === 'function') { methods.push(key); } } } for (var i = 0; i < methods.length; i++) { var method = methods[i]; var original = obj[method]; obj[method] = function retryWrapper(original) { var op = exports.operation(options); var args = Array.prototype.slice.call(arguments, 1); var callback = args.pop(); args.push(function(err) { if (op.retry(err)) { return; } if (err) { arguments[0] = op.mainError(); } callback.apply(this, arguments); }); op.attempt(function() { original.apply(obj, args); }); }.bind(obj, original); obj[method].options = options; } }; }); var retry$1 = retry; // Packages function retry$2(fn, opts) { function run(resolve, reject) { var options = opts || {}; // Default `randomize` to true if (!('randomize' in options)) { options.randomize = true; } var op = retry$1.operation(options); // We allow the user to abort retrying // this makes sense in the cases where // knowledge is obtained that retrying // would be futile (e.g.: auth errors) function bail(err) { reject(err || new Error('Aborted')); } function onError(err, num) { if (err.bail) { bail(err); return; } if (!op.retry(err)) { reject(op.mainError()); } else if (options.onRetry) { options.onRetry(err, num); } } function runAttempt(num) { var val; try { val = fn(bail, num); } catch (err) { onError(err, num); return; } Promise.resolve(val) .then(resolve) .catch(function catchIt(err) { onError(err, num); }); } op.attempt(runAttempt); } return new Promise(run); } var lib = retry$2; function _isPlaceholder(a) { return a != null && typeof a === 'object' && a['@@functional/placeholder'] === true; } var _isPlaceholder_1 = _isPlaceholder; /** * Optimized internal one-arity curry function. * * @private * @category Function * @param {Function} fn The function to curry. * @return {Function} The curried function. */ function _curry1(fn) { return function f1(a) { if (arguments.length === 0 || _isPlaceholder_1(a)) { return f1; } else { return fn.apply(this, arguments); } }; } var _curry1_1 = _curry1; function _arity(n, fn) { /* eslint-disable no-unused-vars */ switch (n) { case 0: return function () { return fn.apply(this, arguments); }; case 1: return function (a0) { return fn.apply(this, arguments); }; case 2: return function (a0, a1) { return fn.apply(this, arguments); }; case 3: return function (a0, a1, a2) { return fn.apply(this, arguments); }; case 4: return function (a0, a1, a2, a3) { return fn.apply(this, arguments); }; case 5: return function (a0, a1, a2, a3, a4) { return fn.apply(this, arguments); }; case 6: return function (a0, a1, a2, a3, a4, a5) { return fn.apply(this, arguments); }; case 7: return function (a0, a1, a2, a3, a4, a5, a6) { return fn.apply(this, arguments); }; case 8: return function (a0, a1, a2, a3, a4, a5, a6, a7) { return fn.apply(this, arguments); }; case 9: return function (a0, a1, a2, a3, a4, a5, a6, a7, a8) { return fn.apply(this, arguments); }; case 10: return function (a0, a1, a2, a3, a4, a5, a6, a7, a8, a9) { return fn.apply(this, arguments); }; default: throw new Error('First argument to _arity must be a non-negative integer no greater than ten'); } } var _arity_1 = _arity; /** * Optimized internal two-arity curry function. * * @private * @category Function * @param {Function} fn The function to curry. * @return {Function} The curried function. */ function _curry2(fn) { return function f2(a, b) { switch (arguments.length) { case 0: return f2; case 1: return _isPlaceholder_1(a) ? f2 : _curry1_1(function (_b) { return fn(a, _b); }); default: return _isPlaceholder_1(a) && _isPlaceholder_1(b) ? f2 : _isPlaceholder_1(a) ? _curry1_1(function (_a) { return fn(_a, b); }) : _isPlaceholder_1(b) ? _curry1_1(function (_b) { return fn(a, _b); }) : fn(a, b); } }; } var _curry2_1 = _curry2; /** * Internal curryN function. * * @private * @category Function * @param {Number} length The arity of the curried function. * @param {Array} received An array of arguments received thus far. * @param {Function} fn The function to curry. * @return {Function} The curried function. */ function _curryN(length, received, fn) { return function () { var combined = []; var argsIdx = 0; var left = length; var combinedIdx = 0; while (combinedIdx < received.length || argsIdx < arguments.length) { var result; if (combinedIdx < received.length && (!_isPlaceholder_1(received[combinedIdx]) || argsIdx >= arguments.length)) { result = received[combinedIdx]; } else { result = arguments[argsIdx]; argsIdx += 1; } combined[combinedIdx] = result; if (!_isPlaceholder_1(result)) { left -= 1; } combinedIdx += 1; } return left <= 0 ? fn.apply(this, combined) : _arity_1(left, _curryN(length, combined, fn)); }; } var _curryN_1 = _curryN; /** * Returns a curried equivalent of the provided function, with the specified * arity. The curried function has two unusual capabilities. First, its * arguments needn't be provided one at a time. If `g` is `R.curryN(3, f)`, the * following are equivalent: * * - `g(1)(2)(3)` * - `g(1)(2, 3)` * - `g(1, 2)(3)` * - `g(1, 2, 3)` * * Secondly, the special placeholder value [`R.__`](#__) may be used to specify * "gaps", allowing partial application of any combination of arguments, * regardless of their positions. If `g` is as above and `_` is [`R.__`](#__), * the following are equivalent: * * - `g(1, 2, 3)` * - `g(_, 2, 3)(1)` * - `g(_, _, 3)(1)(2)` * - `g(_, _, 3)(1, 2)` * - `g(_, 2)(1)(3)` * - `g(_, 2)(1, 3)` * - `g(_, 2)(_, 3)(1)` * * @func * @memberOf R * @since v0.5.0 * @category Function * @sig Number -> (* -> a) -> (* -> a) * @param {Number} length The arity for the returned function. * @param {Function} fn The function to curry. * @return {Function} A new, curried function. * @see R.curry * @example * * const sumArgs = (...args) => R.sum(args); * * const curriedAddFourNumbers = R.curryN(4, sumArgs); * const f = curriedAddFourNumbers(1, 2); * const g = f(3); * g(4); //=> 10 */ var curryN = /*#__PURE__*/ _curry2_1(function curryN(length, fn) { if (length === 1) { return _curry1_1(fn); } return _arity_1(length, _curryN_1(length, [], fn)); }); var curryN_1 = curryN; /** * Returns the larger of its two arguments. * * @func * @memberOf R * @since v0.1.0 * @category Relation * @sig Ord a => a -> a -> a * @param {*} a * @param {*} b * @return {*} * @see R.maxBy, R.min * @example * * R.max(789, 123); //=> 789 * R.max('a', 'b'); //=> 'b' */ var max = /*#__PURE__*/ _curry2_1(function max(a, b) { return b > a ? b : a; }); var max_1 = max; /** * Tests whether or not an object is an array. * * @private * @param {*} val The object to test. * @return {Boolean} `true` if `val` is an array, `false` otherwise. * @example * * _isArray([]); //=> true * _isArray(null); //=> false * _isArray({}); //=> false */ var _isArray = Array.isArray || function _isArray(val) { return val != null && val.length >= 0 && Object.prototype.toString.call(val) === '[object Array]'; }; function _isTransformer(obj) { return obj != null && typeof obj['@@transducer/step'] === 'function'; } var _isTransformer_1 = _isTransformer; /** * Returns a function that dispatches with different strategies based on the * object in list position (last argument). If it is an array, executes [fn]. * Otherwise, if it has a function with one of the given method names, it will * execute that function (functor case). Otherwise, if it is a transformer, * uses transducer [xf] to return a new transformer (transducer case). * Otherwise, it will default to executing [fn]. * * @private * @param {Array} methodNames properties to check for a custom implementation * @param {Function} xf transducer to initialize if object is transformer * @param {Function} fn default ramda implementation * @return {Function} A function that dispatches on object in list position */ function _dispatchable(methodNames, xf, fn) { return function () { if (arguments.length === 0) { return fn(); } var args = Array.prototype.slice.call(arguments, 0); var obj = args.pop(); if (!_isArray(obj)) { var idx = 0; while (idx < methodNames.length) { if (typeof obj[methodNames[idx]] === 'function') { return obj[methodNames[idx]].apply(obj, args); } idx += 1; } if (_isTransformer_1(obj)) { var transducer = xf.apply(null, args); return transducer(obj); } } return fn.apply(this, arguments); }; } var _dispatchable_1 = _dispatchable; function _map(fn, functor) { var idx = 0; var len = functor.length; var result = Array(len); while (idx < len) { result[idx] = fn(functor[idx]); idx += 1; } return result; } var _map_1 = _map; function _isString(x) { return Object.prototype.toString.call(x) === '[object String]'; } var _isString_1 = _isString; /** * Tests whether or not an object is similar to an array. * * @private * @category Type * @category List * @sig * -> Boolean * @param {*} x The object to test. * @return {Boolean} `true` if `x` has a numeric length property and extreme indices defined; `false` otherwise. * @example * * _isArrayLike([]); //=> true * _isArrayLike(true); //=> false * _isArrayLike({}); //=> false * _isArrayLike({length: 10}); //=> false * _isArrayLike({0: 'zero', 9: 'nine', length: 10}); //=> true */ var _isArrayLike = /*#__PURE__*/ _curry1_1(function isArrayLike(x) { if (_isArray(x)) { return true; } if (!x) { return false; } if (typeof x !== 'object') { return false; } if (_isString_1(x)) { return false; } if (x.nodeType === 1) { return !!x.length; } if (x.length === 0) { return true; } if (x.length > 0) { return x.hasOwnProperty(0) && x.hasOwnProperty(x.length - 1); } return false; }); var _isArrayLike_1 = _isArrayLike; var XWrap = /*#__PURE__*/ function () { function XWrap(fn) { this.f = fn; } XWrap.prototype['@@transducer/init'] = function () { throw new Error('init not implemented on XWrap'); }; XWrap.prototype['@@transducer/result'] = function (acc) { return acc; }; XWrap.prototype['@@transducer/step'] = function (acc, x) { return this.f(acc, x); }; return XWrap; }(); function _xwrap(fn) { return new XWrap(fn); } var _xwrap_1 = _xwrap; /** * Creates a function that is bound to a context. * Note: `R.bind` does not provide the additional argument-binding capabilities of * [Function.prototype.bind](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Function/bind). * * @func * @memberOf R * @since v0.6.0 * @category Function * @category Object * @sig (* -> *) -> {*} -> (* -> *) * @param {Function} fn The function to bind to context * @param {Object} thisObj The context to bind `fn` to * @return {Function} A function that will execute in the context of `thisObj`. * @see R.partial * @example * * const log = R.bind(console.log, console); * R.pipe(R.assoc('a', 2), R.tap(log), R.assoc('a', 3))({a: 1}); //=> {a: 3} * // logs {a: 2} * @symb R.bind(f, o)(a, b) = f.call(o, a, b) */ var bind = /*#__PURE__*/ _curry2_1(function bind(fn, thisObj) { return _arity_1(fn.length, function () { return fn.apply(thisObj, arguments); }); }); var bind_1 = bind; function _arrayReduce(xf, acc, list) { var idx = 0; var len = list.length; while (idx < len) { acc = xf['@@transducer/step'](acc, list[idx]); if (acc && acc['@@transducer/reduced']) { acc = acc['@@transducer/value']; break; } idx += 1; } return xf['@@transducer/result'](acc); } function _iterableReduce(xf, acc, iter) { var step = iter.next(); while (!step.done) { acc = xf['@@transducer/step'](acc, step.value); if (acc && acc['@@transducer/reduced']) { acc = acc['@@transducer/value']; break; } step = iter.next(); } return xf['@@transducer/result'](acc); } function _methodReduce(xf, acc, obj, methodName) { return xf['@@transducer/result'](obj[methodName](bind_1(xf['@@transducer/step'], xf), acc)); } var symIterator = typeof Symbol !== 'undefined' ? Symbol.iterator : '@@iterator'; function _reduce(fn, acc, list) { if (typeof fn === 'function') { fn = _xwrap_1(fn); } if (_isArrayLike_1(list)) { return _arrayReduce(fn, acc, list); } if (typeof list['fantasy-land/reduce'] === 'function') { return _methodReduce(fn, acc, list, 'fantasy-land/reduce'); } if (list[symIterator] != null) { return _iterableReduce(fn, acc, list[symIterator]()); } if (typeof list.next === 'function') { return _iterableReduce(fn, acc, list); } if (typeof list.reduce === 'function') { return _methodReduce(fn, acc, list, 'reduce'); } throw new TypeError('reduce: list must be array or iterable'); } var _reduce_1 = _reduce; var _xfBase = { init: function () { return this.xf['@@transducer/init'](); }, result: function (result) { return this.xf['@@transducer/result'](result); } }; var XMap = /*#__PURE__*/ function () { function XMap(f, xf) { this.xf = xf; this.f = f; } XMap.prototype['@@transducer/init'] = _xfBase.init; XMap.prototype['@@transducer/result'] = _xfBase.result; XMap.prototype['@@transducer/step'] = function (result, input) { return this.xf['@@transducer/step'](result, this.f(input)); }; return XMap; }(); var _xmap = /*#__PURE__*/ _curry2_1(function _xmap(f, xf) { return new XMap(f, xf); }); var _xmap_1 = _xmap; function _has(prop, obj) { return Object.prototype.hasOwnProperty.call(obj, prop); } var _has_1 = _has; var toString = Object.prototype.toString; var _isArguments = /*#__PURE__*/ function () { return toString.call(arguments) === '[object Arguments]' ? function _isArguments(x) { return toString.call(x) === '[object Arguments]'; } : function _isArguments(x) { return _has_1('callee', x); }; }(); var _isArguments_1 = _isArguments; // cover IE < 9 keys issues var hasEnumBug = ! /*#__PURE__*/ { toString: null }.propertyIsEnumerable('toString'); var nonEnumerableProps = ['constructor', 'valueOf', 'isPrototypeOf', 'toString', 'propertyIsEnumerable', 'hasOwnProperty', 'toLocaleString']; // Safari bug var hasArgsEnumBug = /*#__PURE__*/ function () { return arguments.propertyIsEnumerable('length'); }(); var contains = function contains(list, item) { var idx = 0; while (idx < list.length) { if (list[idx] === item) { return true; } idx += 1; } return false; }; /** * Returns a list containing the names of all the enumerable own properties of * the supplied object. * Note that the order of the output array is not guaranteed to be consistent * across different JS platforms. * * @func * @memberOf R * @since v0.1.0 * @category Object * @sig {k: v} -> [k] * @param {Object} obj The object to extract properties from * @return {Array} An array of the object's own properties. * @see R.keysIn, R.values * @example * * R.keys({a: 1, b: 2, c: 3}); //=> ['a', 'b', 'c'] */ var keys = typeof Object.keys === 'function' && !hasArgsEnumBug ? /*#__PURE__*/ _curry1_1(function keys(obj) { return Object(obj) !== obj ? [] : Object.keys(obj); }) : /*#__PURE__*/ _curry1_1(function keys(obj) { if (Object(obj) !== obj) { return []; } var prop, nIdx; var ks = []; var checkArgsLength = hasArgsEnumBug && _isArguments_1(obj); for (prop in obj) { if (_has_1(prop, obj) && (!checkArgsLength || prop !== 'length')) { ks[ks.length] = prop; } } if (hasEnumBug) { nIdx = nonEnumerableProps.length - 1; while (nIdx >= 0) { prop = nonEnumerableProps[nIdx]; if (_has_1(prop, obj) && !contains(ks, prop)) { ks[ks.length] = prop; } nIdx -= 1; } } return ks; }); var keys_1 = keys; /** * Takes a function and * a [functor](https://github.com/fantasyland/fantasy-land#functor), * applies the function to each of the functor's values, and returns * a functor of the same shape. * * Ramda provides suitable `map` implementations for `Array` and `Object`, * so this function may be applied to `[1, 2, 3]` or `{x: 1, y: 2, z: 3}`. * * Dispatches to the `map` method of the second argument, if present. * * Acts as a transducer if a transformer is given in list position. * * Also treats functions as functors and will compose them together. * * @func * @memberOf R * @since v0.1.0 * @category List * @sig Functor f => (a -> b) -> f a -> f b * @param {Function} fn The function to be called on every element of the input `list`. * @param {Array} list The list to be iterated over. * @return {Array} The new list. * @see R.transduce, R.addIndex * @example * * const double = x => x * 2; * * R.map(double, [1, 2, 3]); //=> [2, 4, 6] * * R.map(double, {x: 1, y: 2, z: 3}); //=> {x: 2, y: 4, z: 6} * @symb R.map(f, [a, b]) = [f(a), f(b)] * @symb R.map(f, { x: a, y: b }) = { x: f(a), y: f(b) } * @symb R.map(f, functor_o) = functor_o.map(f) */ var map = /*#__PURE__*/ _curry2_1( /*#__PURE__*/ _dispatchable_1(['fantasy-land/map', 'map'], _xmap_1, function map(fn, functor) { switch (Object.prototype.toString.call(functor)) { case '[object Function]': return curryN_1(functor.length, function () { return fn.call(this, functor.apply(this, arguments)); }); case '[object Object]': return _reduce_1(function (acc, key) { acc[key] = fn(functor[key]); return acc; }, {}, keys_1(functor)); default: return _map_1(fn, functor); } })); var map_1 = map; /** * Determine if the passed argument is an integer. * * @private * @param {*} n * @category Type * @return {Boolean} */ var _isInteger = Number.isInteger || function _isInteger(n) { return n << 0 === n; }; /** * Returns the nth element of the given list or string. If n is negative the * element at index length + n is returned. * * @func * @memberOf R * @since v0.1.0 * @category List * @sig Number -> [a] -> a | Undefined * @sig Number -> String -> String * @param {Number} offset * @param {*} list * @return {*} * @example * * const list = ['foo', 'bar', 'baz', 'quux']; * R.nth(1, list); //=> 'bar' * R.nth(-1, list); //=> 'quux' * R.nth(-99, list); //=> undefined * * R.nth(2, 'abc'); //=> 'c' * R.nth(3, 'abc'); //=> '' * @symb R.nth(-1, [a, b, c]) = c * @symb R.nth(0, [a, b, c]) = a * @symb R.nth(1, [a, b, c]) = b */ var nth = /*#__PURE__*/ _curry2_1(function nth(offset, list) { var idx = offset < 0 ? list.length + offset : offset; return _isString_1(list) ? list.charAt(idx) : list[idx]; }); var nth_1 = nth; /** * Retrieves the values at given paths of an object. * * @func * @memberOf R * @since v0.27.1 * @category Object * @typedefn Idx = [String | Int] * @sig [Idx] -> {a} -> [a | Undefined] * @param {Array} pathsArray The array of paths to be fetched. * @param {Object} obj The object to retrieve the nested properties from. * @return {Array} A list consisting of values at paths specified by "pathsArray". * @see R.path * @example * * R.paths([['a', 'b'], ['p', 0, 'q']], {a: {b: 2}, p: [{q: 3}]}); //=> [2, 3] * R.paths([['a', 'b'], ['p', 'r']], {a: {b: 2}, p: [{q: 3}]}); //=> [2, undefined] */ var paths = /*#__PURE__*/ _curry2_1(function paths(pathsArray, obj) { return pathsArray.map(function (paths) { var val = obj; var idx = 0; var p; while (idx < paths.length) { if (val == null) { return; } p = paths[idx]; val = _isInteger(p) ? nth_1(p, val) : val[p]; idx += 1; } return val; }); }); var paths_1 = paths; /** * Retrieve the value at a given path. * * @func * @memberOf R * @since v0.2.0 * @category Object * @typedefn Idx = String | Int * @sig [Idx] -> {a} -> a | Undefined * @param {Array} path The path to use. * @param {Object} obj The object to retrieve the nested property from. * @return {*} The data at `path`. * @see R.prop, R.nth * @example * * R.path(['a', 'b'], {a: {b: 2}}); //=> 2 * R.path(['a', 'b'], {c: {b: 2}}); //=> undefined * R.path(['a', 'b', 0], {a: {b: [1, 2, 3]}}); //=> 1 * R.path(['a', 'b', -2], {a: {b: [1, 2, 3]}}); //=> 2 */ var path = /*#__PURE__*/ _curry2_1(function path(pathAr, obj) { return paths_1([pathAr], obj)[0]; }); var path_1 = path; /** * Returns a function that when supplied an object returns the indicated * property of that object, if it exists. * * @func * @memberOf R * @since v0.1.0 * @category Object * @typedefn Idx = String | Int * @sig Idx -> {s: a} -> a | Undefined * @param {String|Number} p The property name or array index * @param {Object} obj The object to query * @return {*} The value at `obj.p`. * @see R.path, R.nth * @example * * R.prop('x', {x: 100}); //=> 100 * R.prop('x', {}); //=> undefined * R.prop(0, [100]); //=> 100 * R.compose(R.inc, R.prop('x'))({ x: 3 }) //=> 4 */ var prop = /*#__PURE__*/ _curry2_1(function prop(p, obj) { return path_1([p], obj); }); var prop_1 = prop; /** * Returns a new list by plucking the same named property off all objects in * the list supplied. * * `pluck` will work on * any [functor](https://github.com/fantasyland/fantasy-land#functor) in * addition to arrays, as it is equivalent to `R.map(R.prop(k), f)`. * * @func * @memberOf R * @since v0.1.0 * @category List * @sig Functor f => k -> f {k: v} -> f v * @param {Number|String} key The key name to pluck off of each object. * @param {Array} f The array or functor to consider. * @return {Array} The list of values for the given key. * @see R.props * @example * * var getAges = R.pluck('age'); * getAges([{name: 'fred', age: 29}, {name: 'wilma', age: 27}]); //=> [29, 27] * * R.pluck(0, [[1, 2], [3, 4]]); //=> [1, 3] * R.pluck('val', {a: {val: 3}, b: {val: 5}}); //=> {a: 3, b: 5} * @symb R.pluck('x', [{x: 1, y: 2}, {x: 3, y: 4}, {x: 5, y: 6}]) = [1, 3, 5] * @symb R.pluck(0, [[1, 2], [3, 4], [5, 6]]) = [1, 3, 5] */ var pluck = /*#__PURE__*/ _curry2_1(function pluck(p, list) { return map_1(prop_1(p), list); }); var pluck_1 = pluck; /** * Optimized internal three-arity curry function. * * @private * @category Function * @param {Function} fn The function to curry. * @return {Function} The curried function. */ function _curry3(fn) { return function f3(a, b, c) { switch (arguments.length) { case 0: return f3; case 1: return _isPlaceholder_1(a) ? f3 : _curry2_1(function (_b, _c) { return fn(a, _b, _c); }); case 2: return _isPlaceholder_1(a) && _isPlaceholder_1(b) ? f3 : _isPlaceholder_1(a) ? _curry2_1(function (_a, _c) { return fn(_a, b, _c); }) : _isPlaceholder_1(b) ? _curry2_1(function (_b, _c) { return fn(a, _b, _c); }) : _curry1_1(function (_c) { return fn(a, b, _c); }); default: return _isPlaceholder_1(a) && _isPlaceholder_1(b) && _isPlaceholder_1(c) ? f3 : _isPlaceholder_1(a) && _isPlaceholder_1(b) ? _curry2_1(function (_a, _b) { return fn(_a, _b, c); }) : _isPlaceholder_1(a) && _isPlaceholder_1(c) ? _curry2_1(function (_a, _c) { return fn(_a, b, _c); }) : _isPlaceholder_1(b) && _isPlaceholder_1(c) ? _curry2_1(function (_b, _c) { return fn(a, _b, _c); }) : _isPlaceholder_1(a) ? _curry1_1(function (_a) { return fn(_a, b, c); }) : _isPlaceholder_1(b) ? _curry1_1(function (_b) { return fn(a, _b, c); }) : _isPlaceholder_1(c) ? _curry1_1(function (_c) { return fn(a, b, _c); }) : fn(a, b, c); } }; } var _curry3_1 = _curry3; /** * Returns a single item by iterating through the list, successively calling * the iterator function and passing it an accumulator value and the current * value from the array, and then passing the result to the next call. * * The iterator function receives two values: *(acc, value)*. It may use * [`R.reduced`](#reduced) to shortcut the iteration. * * The arguments' order of [`reduceRight`](#reduceRight)'s iterator function * is *(value, acc)*. * * Note: `R.reduce` does not skip deleted or unassigned indices (sparse * arrays), unlike the native `Array.prototype.reduce` method. For more details * on this behavior, see: * https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/reduce#Description * * Dispatches to the `reduce` method of the third argument, if present. When * doing so, it is up to the user to handle the [`R.reduced`](#reduced) * shortcuting, as this is not implemented by `reduce`. * * @func * @memberOf R * @since v0.1.0 * @category List * @sig ((a, b) -> a) -> a -> [b] -> a * @param {Function} fn The iterator function. Receives two values, the accumulator and the * current element from the array. * @param {*} acc The accumulator value. * @param {Array} list The list to iterate over. * @return {*} The final, accumulated value. * @see R.reduced, R.addIndex, R.reduceRight * @example * * R.reduce(R.subtract, 0, [1, 2, 3, 4]) // => ((((0 - 1) - 2) - 3) - 4) = -10 * // - -10 * // / \ / \ * // - 4 -6 4 * // / \ / \ * // - 3 ==> -3 3 * // / \ / \ * // - 2 -1 2 * // / \ / \ * // 0 1 0 1 * * @symb R.reduce(f, a, [b, c, d]) = f(f(f(a, b), c), d) */ var reduce = /*#__PURE__*/ _curry3_1(_reduce_1); var reduce_1 = reduce; /** * Takes a list of predicates and returns a predicate that returns true for a * given list of arguments if at least one of the provided predicates is * satisfied by those arguments. * * The function returned is a curried function whose arity matches that of the * highest-arity predicate. * * @func * @memberOf R * @since v0.9.0 * @category Logic * @sig [(*... -> Boolean)] -> (*... -> Boolean) * @param {Array} predicates An array of predicates to check * @return {Function} The combined predicate * @see R.allPass * @example * * const isClub = R.propEq('suit', '♣'); * const isSpade = R.propEq('suit', '♠'); * const isBlackCard = R.anyPass([isClub, isSpade]); * * isBlackCard({rank: '10', suit: '♣'}); //=> true * isBlackCard({rank: 'Q', suit: '♠'}); //=> true * isBlackCard({rank: 'Q', suit: '♦'}); //=> false */ var anyPass = /*#__PURE__*/ _curry1_1(function anyPass(preds) { return curryN_1(reduce_1(max_1, 0, pluck_1('length', preds)), function () { var idx = 0; var len = preds.length; while (idx < len) { if (preds[idx].apply(this, arguments)) { return true; } idx += 1; } return false; }); }); var anyPass_1 = anyPass; function _isFunction(x) { var type = Object.prototype.toString.call(x); return type === '[object Function]' || type === '[object AsyncFunction]' || type === '[object GeneratorFunction]' || type === '[object AsyncGeneratorFunction]'; } var _isFunction_1 = _isFunction; /** * Returns `true` if both arguments are `true`; `false` otherwise. * * @func * @memberOf R * @since v0.1.0 * @category Logic * @sig a -> b -> a | b * @param {Any} a * @param {Any} b * @return {Any} the first argument if it is falsy, otherwise the second argument. * @see R.both, R.xor * @example * * R.and(true, true); //=> true * R.and(true, false); //=> false * R.and(false, true); //=> false * R.and(false, false); //=> false */ var and = /*#__PURE__*/ _curry2_1(function and(a, b) { return a && b; }); var and_1 = and; /** * Private `concat` function to merge two array-like objects. * * @private * @param {Array|Arguments} [set1=[]] An array-like object. * @param {Array|Arguments} [set2=[]] An array-like object. * @return {Array} A new, merged array. * @example * * _concat([4, 5, 6], [1, 2, 3]); //=> [4, 5, 6, 1, 2, 3] */ function _concat(set1, set2) { set1 = set1 || []; set2 = set2 || []; var idx; var len1 = set1.length; var len2 = set2.length; var result = []; idx = 0; while (idx < len1) { result[result.length] = set1[idx]; idx += 1; } idx = 0; while (idx < len2) { result[result.length] = set2[idx]; idx += 1; } return result; } var _concat_1 = _concat; /** * ap applies a list of functions to a list of values. * * Dispatches to the `ap` method of the second argument, if present. Also * treats curried functions as applicatives. * * @func * @memberOf R * @since v0.3.0 * @category Function * @sig [a -> b] -> [a] -> [b] * @sig Apply f => f (a -> b) -> f a -> f b * @sig (r -> a -> b) -> (r -> a) -> (r -> b) * @param {*} applyF * @param {*} applyX * @return {*} * @example * * R.ap([R.multiply(2), R.add(3)], [1,2,3]); //=> [2, 4, 6, 4, 5, 6] * R.ap([R.concat('tasty '), R.toUpper], ['pizza', 'salad']); //=> ["tasty pizza", "tasty salad", "PIZZA", "SALAD"] * * // R.ap can also be used as S combinator * // when only two functions are passed * R.ap(R.concat, R.toUpper)('Ramda') //=> 'RamdaRAMDA' * @symb R.ap([f, g], [a, b]) = [f(a), f(b), g(a), g(b)] */ var ap = /*#__PURE__*/ _curry2_1(function ap(applyF, applyX) { return typeof applyX['fantasy-land/ap'] === 'function' ? applyX['fantasy-land/ap'](applyF) : typeof applyF.ap === 'function' ? applyF.ap(applyX) : typeof applyF === 'function' ? function (x) { return applyF(x)(applyX(x)); } : _reduce_1(function (acc, f) { return _concat_1(acc, map_1(f, applyX)); }, [], applyF); }); var ap_1 = ap; /** * "lifts" a function to be the specified arity, so that it may "map over" that * many lists, Functions or other objects that satisfy the [FantasyLand Apply spec](https://github.com/fantasyland/fantasy-land#apply). * * @func * @memberOf R * @since v0.7.0 * @category Function * @sig Number -> (*... -> *) -> ([*]... -> [*]) * @param {Function} fn The function to lift into higher context * @return {Function} The lifted function. * @see R.lift, R.ap * @example * * const madd3 = R.liftN(3, (...args) => R.sum(args)); * madd3([1,2,3], [1,2,3], [1]); //=> [3, 4, 5, 4, 5, 6, 5, 6, 7] */ var liftN = /*#__PURE__*/ _curry2_1(function liftN(arity, fn) { var lifted = curryN_1(arity, fn); return curryN_1(arity, function () { return _reduce_1(ap_1, map_1(lifted, arguments[0]), Array.prototype.slice.call(arguments, 1)); }); }); var liftN_1 = liftN; /** * "lifts" a function of arity > 1 so that it may "map over" a list, Function or other * object that satisfies the [FantasyLand Apply spec](https://github.com/fantasyland/fantasy-land#apply). * * @func * @memberOf R * @since v0.7.0 * @category Function * @sig (*... -> *) -> ([*]... -> [*]) * @param {Function} fn The function to lift into higher context * @return {Function} The lifted function. * @see R.liftN * @example * * const madd3 = R.lift((a, b, c) => a + b + c); * * madd3([1,2,3], [1,2,3], [1]); //=> [3, 4, 5, 4, 5, 6, 5, 6, 7] * * const madd5 = R.lift((a, b, c, d, e) => a + b + c + d + e); * * madd5([1,2], [3], [4, 5], [6], [7, 8]); //=> [21, 22, 22, 23, 22, 23, 23, 24] */ var lift = /*#__PURE__*/ _curry1_1(function lift(fn) { return liftN_1(fn.length, fn); }); var lift_1 = lift; /** * A function which calls the two provided functions and returns the `&&` * of the results. * It returns the result of the first function if it is false-y and the result * of the second function otherwise. Note that this is short-circuited, * meaning that the second function will not be invoked if the first returns a * false-y value. * * In addition to functions, `R.both` also accepts any fantasy-land compatible * applicative functor. * * @func * @memberOf R * @since v0.12.0 * @category Logic * @sig (*... -> Boolean) -> (*... -> Boolean) -> (*... -> Boolean) * @param {Function} f A predicate * @param {Function} g Another predicate * @return {Function} a function that applies its arguments to `f` and `g` and `&&`s their outputs together. * @see R.and * @example * * const gt10 = R.gt(R.__, 10) * const lt20 = R.lt(R.__, 20) * const f = R.both(gt10, lt20); * f(15); //=> true * f(30); //=> false * * R.both(Maybe.Just(false), Maybe.Just(55)); // => Maybe.Just(false) * R.both([false, false, 'a'], [11]); //=> [false, false, 11] */ var both = /*#__PURE__*/ _curry2_1(function both(f, g) { return _isFunction_1(f) ? function _both() { return f.apply(this, arguments) && g.apply(this, arguments); } : lift_1(and_1)(f, g); }); var both_1 = both; /** * A function that returns the `!` of its argument. It will return `true` when * passed false-y value, and `false` when passed a truth-y one. * * @func * @memberOf R * @since v0.1.0 * @category Logic * @sig * -> Boolean * @param {*} a any value * @return {Boolean} the logical inverse of passed argument. * @see R.complement * @example * * R.not(true); //=> false * R.not(false); //=> true * R.not(0); //=> true * R.not(1); //=> false */ var not = /*#__PURE__*/ _curry1_1(function not(a) { return !a; }); var not_1 = not; /** * Takes a function `f` and returns a function `g` such that if called with the same arguments * when `f` returns a "truthy" value, `g` returns `false` and when `f` returns a "falsy" value `g` returns `true`. * * `R.complement` may be applied to any functor * * @func * @memberOf R * @since v0.12.0 * @category Logic * @sig (*... -> *) -> (*... -> Boolean) * @param {Function} f * @return {Function} * @see R.not * @example * * const isNotNil = R.complement(R.isNil); * isNil(null); //=> true * isNotNil(null); //=> false * isNil(7); //=> false * isNotNil(7); //=> true */ var complement = /*#__PURE__*/ lift_1(not_1); var complement_1 = complement; function _pipe(f, g) { return function () { return g.call(this, f.apply(this, arguments)); }; } var _pipe_1 = _pipe; /** * This checks whether a function has a [methodname] function. If it isn't an * array it will execute that function otherwise it will default to the ramda * implementation. * * @private * @param {Function} fn ramda implemtation * @param {String} methodname property to check for a custom implementation * @return {Object} Whatever the return value of the method is. */ function _checkForMethod(methodname, fn) { return function () { var length = arguments.length; if (length === 0) { return fn(); } var obj = arguments[length - 1]; return _isArray(obj) || typeof obj[methodname] !== 'function' ? fn.apply(this, arguments) : obj[methodname].apply(obj, Array.prototype.slice.call(arguments, 0, length - 1)); }; } var _checkForMethod_1 = _checkForMethod; /** * Returns the elements of the given list or string (or object with a `slice` * method) from `fromIndex` (inclusive) to `toIndex` (exclusive). * * Dispatches to the `slice` method of the third argument, if present. * * @func * @memberOf R * @since v0.1.4 * @category List * @sig Number -> Number -> [a] -> [a] * @sig Number -> Number -> String -> String * @param {Number} fromIndex The start index (inclusive). * @param {Number} toIndex The end index (exclusive). * @param {*} list * @return {*} * @example * * R.slice(1, 3, ['a', 'b', 'c', 'd']); //=> ['b', 'c'] * R.slice(1, Infinity, ['a', 'b', 'c', 'd']); //=> ['b', 'c', 'd'] * R.slice(0, -1, ['a', 'b', 'c', 'd']); //=> ['a', 'b', 'c'] * R.slice(-3, -1, ['a', 'b', 'c', 'd']); //=> ['b', 'c'] * R.slice(0, 3, 'ramda'); //=> 'ram' */ var slice = /*#__PURE__*/ _curry3_1( /*#__PURE__*/ _checkForMethod_1('slice', function slice(fromIndex, toIndex, list) { return Array.prototype.slice.call(list, fromIndex, toIndex); })); var slice_1 = slice; /** * Returns all but the first element of the given list or string (or object * with a `tail` method). * * Dispatches to the `slice` method of the first argument, if present. * * @func * @memberOf R * @since v0.1.0 * @category List * @sig [a] -> [a] * @sig String -> String * @param {*} list * @return {*} * @see R.head, R.init, R.last * @example * * R.tail([1, 2, 3]); //=> [2, 3] * R.tail([1, 2]); //=> [2] * R.tail([1]); //=> [] * R.tail([]); //=> [] * * R.tail('abc'); //=> 'bc' * R.tail('ab'); //=> 'b' * R.tail('a'); //=> '' * R.tail(''); //=> '' */ var tail = /*#__PURE__*/ _curry1_1( /*#__PURE__*/ _checkForMethod_1('tail', /*#__PURE__*/ slice_1(1, Infinity))); var tail_1 = tail; /** * Performs left-to-right function composition. The first argument may have * any arity; the remaining arguments must be unary. * * In some libraries this function is named `sequence`. * * **Note:** The result of pipe is not automatically curried. * * @func * @memberOf R * @since v0.1.0 * @category Function * @sig (((a, b, ..., n) -> o), (o -> p), ..., (x -> y), (y -> z)) -> ((a, b, ..., n) -> z) * @param {...Function} functions * @return {Function} * @see R.compose * @example * * const f = R.pipe(Math.pow, R.negate, R.inc); * * f(3, 4); // -(3^4) + 1 * @symb R.pipe(f, g, h)(a, b) = h(g(f(a, b))) */ function pipe() { if (arguments.length === 0) { throw new Error('pipe requires at least one argument'); } return _arity_1(arguments[0].length, reduce_1(_pipe_1, arguments[0], tail_1(arguments))); } var pipe_1 = pipe; /** * Returns a new list or string with the elements or characters in reverse * order. * * @func * @memberOf R * @since v0.1.0 * @category List * @sig [a] -> [a] * @sig String -> String * @param {Array|String} list * @return {Array|String} * @example * * R.reverse([1, 2, 3]); //=> [3, 2, 1] * R.reverse([1, 2]); //=> [2, 1] * R.reverse([1]); //=> [1] * R.reverse([]); //=> [] * * R.reverse('abc'); //=> 'cba' * R.reverse('ab'); //=> 'ba' * R.reverse('a'); //=> 'a' * R.reverse(''); //=> '' */ var reverse = /*#__PURE__*/ _curry1_1(function reverse(list) { return _isString_1(list) ? list.split('').reverse().join('') : Array.prototype.slice.call(list, 0).reverse(); }); var reverse_1 = reverse; /** * Performs right-to-left function composition. The last argument may have * any arity; the remaining arguments must be unary. * * **Note:** The result of compose is not automatically curried. * * @func * @memberOf R * @since v0.1.0 * @category Function * @sig ((y -> z), (x -> y), ..., (o -> p), ((a, b, ..., n) -> o)) -> ((a, b, ..., n) -> z) * @param {...Function} ...functions The functions to compose * @return {Function} * @see R.pipe * @example * * const classyGreeting = (firstName, lastName) => "The name's " + lastName + ", " + firstName + " " + lastName * const yellGreeting = R.compose(R.toUpper, classyGreeting); * yellGreeting('James', 'Bond'); //=> "THE NAME'S BOND, JAMES BOND" * * R.compose(Math.abs, R.add(1), R.multiply(2))(-4) //=> 7 * * @symb R.compose(f, g, h)(a, b) = f(g(h(a, b))) */ function compose() { if (arguments.length === 0) { throw new Error('compose requires at least one argument'); } return pipe_1.apply(this, reverse_1(arguments)); } var compose_1 = compose; /** * Returns a curried equivalent of the provided function. The curried function * has two unusual capabilities. First, its arguments needn't be provided one * at a time. If `f` is a ternary function and `g` is `R.curry(f)`, the * following are equivalent: * * - `g(1)(2)(3)` * - `g(1)(2, 3)` * - `g(1, 2)(3)` * - `g(1, 2, 3)` * * Secondly, the special placeholder value [`R.__`](#__) may be used to specify * "gaps", allowing partial application of any combination of arguments, * regardless of their positions. If `g` is as above and `_` is [`R.__`](#__), * the following are equivalent: * * - `g(1, 2, 3)` * - `g(_, 2, 3)(1)` * - `g(_, _, 3)(1)(2)` * - `g(_, _, 3)(1, 2)` * - `g(_, 2)(1)(3)` * - `g(_, 2)(1, 3)` * - `g(_, 2)(_, 3)(1)` * * @func * @memberOf R * @since v0.1.0 * @category Function * @sig (* -> a) -> (* -> a) * @param {Function} fn The function to curry. * @return {Function} A new, curried function. * @see R.curryN, R.partial * @example * * const addFourNumbers = (a, b, c, d) => a + b + c + d; * * const curriedAddFourNumbers = R.curry(addFourNumbers); * const f = curriedAddFourNumbers(1, 2); * const g = f(3); * g(4); //=> 10 */ var curry = /*#__PURE__*/ _curry1_1(function curry(fn) { return curryN_1(fn.length, fn); }); var curry_1 = curry; /** * Wraps a function of any arity (including nullary) in a function that accepts * exactly `n` parameters. Any extraneous parameters will not be passed to the * supplied function. * * @func * @memberOf R * @since v0.1.0 * @category Function * @sig Number -> (* -> a) -> (* -> a) * @param {Number} n The desired arity of the new function. * @param {Function} fn The function to wrap. * @return {Function} A new function wrapping `fn`. The new function is guaranteed to be of * arity `n`. * @see R.binary, R.unary * @example * * const takesTwoArgs = (a, b) => [a, b]; * * takesTwoArgs.length; //=> 2 * takesTwoArgs(1, 2); //=> [1, 2] * * const takesOneArg = R.nAry(1, takesTwoArgs); * takesOneArg.length; //=> 1 * // Only `n` arguments are passed to the wrapped function * takesOneArg(1, 2); //=> [1, undefined] * @symb R.nAry(0, f)(a, b) = f() * @symb R.nAry(1, f)(a, b) = f(a) * @symb R.nAry(2, f)(a, b) = f(a, b) */ var nAry = /*#__PURE__*/ _curry2_1(function nAry(n, fn) { switch (n) { case 0: return function () { return fn.call(this); }; case 1: return function (a0) { return fn.call(this, a0); }; case 2: return function (a0, a1) { return fn.call(this, a0, a1); }; case 3: return function (a0, a1, a2) { return fn.call(this, a0, a1, a2); }; case 4: return function (a0, a1, a2, a3) { return fn.call(this, a0, a1, a2, a3); }; case 5: return function (a0, a1, a2, a3, a4) { return fn.call(this, a0, a1, a2, a3, a4); }; case 6: return function (a0, a1, a2, a3, a4, a5) { return fn.call(this, a0, a1, a2, a3, a4, a5); }; case 7: return function (a0, a1, a2, a3, a4, a5, a6) { return fn.call(this, a0, a1, a2, a3, a4, a5, a6); }; case 8: return function (a0, a1, a2, a3, a4, a5, a6, a7) { return fn.call(this, a0, a1, a2, a3, a4, a5, a6, a7); }; case 9: return function (a0, a1, a2, a3, a4, a5, a6, a7, a8) { return fn.call(this, a0, a1, a2, a3, a4, a5, a6, a7, a8); }; case 10: return function (a0, a1, a2, a3, a4, a5, a6, a7, a8, a9) { return fn.call(this, a0, a1, a2, a3, a4, a5, a6, a7, a8, a9); }; default: throw new Error('First argument to nAry must be a non-negative integer no greater than ten'); } }); var nAry_1 = nAry; /** * Wraps a constructor function inside a curried function that can be called * with the same arguments and returns the same type. The arity of the function * returned is specified to allow using variadic constructor functions. * * @func * @memberOf R * @since v0.4.0 * @category Function * @sig Number -> (* -> {*}) -> (* -> {*}) * @param {Number} n The arity of the constructor function. * @param {Function} Fn The constructor function to wrap. * @return {Function} A wrapped, curried constructor function. * @example * * // Variadic Constructor function * function Salad() { * this.ingredients = arguments; * } * * Salad.prototype.recipe = function() { * const instructions = R.map(ingredient => 'Add a dollop of ' + ingredient, this.ingredients); * return R.join('\n', instructions); * }; * * const ThreeLayerSalad = R.constructN(3, Salad); * * // Notice we no longer need the 'new' keyword, and the constructor is curried for 3 arguments. * const salad = ThreeLayerSalad('Mayonnaise')('Potato Chips')('Ketchup'); * * console.log(salad.recipe()); * // Add a dollop of Mayonnaise * // Add a dollop of Potato Chips * // Add a dollop of Ketchup */ var constructN = /*#__PURE__*/ _curry2_1(function constructN(n, Fn) { if (n > 10) { throw new Error('Constructor with greater than ten arguments'); } if (n === 0) { return function () { return new Fn(); }; } return curry_1(nAry_1(n, function ($0, $1, $2, $3, $4, $5, $6, $7, $8, $9) { switch (arguments.length) { case 1: return new Fn($0); case 2: return new Fn($0, $1); case 3: return new Fn($0, $1, $2); case 4: return new Fn($0, $1, $2, $3); case 5: return new Fn($0, $1, $2, $3, $4); case 6: return new Fn($0, $1, $2, $3, $4, $5); case 7: return new Fn($0, $1, $2, $3, $4, $5, $6); case 8: return new Fn($0, $1, $2, $3, $4, $5, $6, $7); case 9: return new Fn($0, $1, $2, $3, $4, $5, $6, $7, $8); case 10: return new Fn($0, $1, $2, $3, $4, $5, $6, $7, $8, $9); } })); }); var constructN_1 = constructN; /** * See if an object (`val`) is an instance of the supplied constructor. This * function will check up the inheritance chain, if any. * * @func * @memberOf R * @since v0.3.0 * @category Type * @sig (* -> {*}) -> a -> Boolean * @param {Object} ctor A constructor * @param {*} val The value to test * @return {Boolean} * @example * * R.is(Object, {}); //=> true * R.is(Number, 1); //=> true * R.is(Object, 1); //=> false * R.is(String, 's'); //=> true * R.is(String, new String('')); //=> true * R.is(Object, new String('')); //=> true * R.is(Object, 's'); //=> false * R.is(Number, {}); //=> false */ var is = /*#__PURE__*/ _curry2_1(function is(Ctor, val) { return val != null && val.constructor === Ctor || val instanceof Ctor; }); var is_1 = is; /** * Creates a function that will process either the `onTrue` or the `onFalse` * function depending upon the result of the `condition` predicate. * * @func * @memberOf R * @since v0.8.0 * @category Logic * @sig (*... -> Boolean) -> (*... -> *) -> (*... -> *) -> (*... -> *) * @param {Function} condition A predicate function * @param {Function} onTrue A function to invoke when the `condition` evaluates to a truthy value. * @param {Function} onFalse A function to invoke when the `condition` evaluates to a falsy value. * @return {Function} A new function that will process either the `onTrue` or the `onFalse` * function depending upon the result of the `condition` predicate. * @see R.unless, R.when, R.cond * @example * * const incCount = R.ifElse( * R.has('count'), * R.over(R.lensProp('count'), R.inc), * R.assoc('count', 1) * ); * incCount({}); //=> { count: 1 } * incCount({ count: 1 }); //=> { count: 2 } */ var ifElse = /*#__PURE__*/ _curry3_1(function ifElse(condition, onTrue, onFalse) { return curryN_1(Math.max(condition.length, onTrue.length, onFalse.length), function _ifElse() { return condition.apply(this, arguments) ? onTrue.apply(this, arguments) : onFalse.apply(this, arguments); }); }); var ifElse_1 = ifElse; function _arrayFromIterator(iter) { var list = []; var next; while (!(next = iter.next()).done) { list.push(next.value); } return list; } var _arrayFromIterator_1 = _arrayFromIterator; function _includesWith(pred, x, list) { var idx = 0; var len = list.length; while (idx < len) { if (pred(x, list[idx])) { return true; } idx += 1; } return false; } var _includesWith_1 = _includesWith; function _functionName(f) { // String(x => x) evaluates to "x => x", so the pattern may not match. var match = String(f).match(/^function (\w*)/); return match == null ? '' : match[1]; } var _functionName_1 = _functionName; // Based on https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Object/is function _objectIs(a, b) { // SameValue algorithm if (a === b) { // Steps 1-5, 7-10 // Steps 6.b-6.e: +0 != -0 return a !== 0 || 1 / a === 1 / b; } else { // Step 6.a: NaN == NaN return a !== a && b !== b; } } var _objectIs_1 = typeof Object.is === 'function' ? Object.is : _objectIs; /** * Gives a single-word string description of the (native) type of a value, * returning such answers as 'Object', 'Number', 'Array', or 'Null'. Does not * attempt to distinguish user Object types any further, reporting them all as * 'Object'. * * @func * @memberOf R * @since v0.8.0 * @category Type * @sig (* -> {*}) -> String * @param {*} val The value to test * @return {String} * @example * * R.type({}); //=> "Object" * R.type(1); //=> "Number" * R.type(false); //=> "Boolean" * R.type('s'); //=> "String" * R.type(null); //=> "Null" * R.type([]); //=> "Array" * R.type(/[A-z]/); //=> "RegExp" * R.type(() => {}); //=> "Function" * R.type(undefined); //=> "Undefined" */ var type = /*#__PURE__*/ _curry1_1(function type(val) { return val === null ? 'Null' : val === undefined ? 'Undefined' : Object.prototype.toString.call(val).slice(8, -1); }); var type_1 = type; /** * private _uniqContentEquals function. * That function is checking equality of 2 iterator contents with 2 assumptions * - iterators lengths are the same * - iterators values are unique * * false-positive result will be returned for comparision of, e.g. * - [1,2,3] and [1,2,3,4] * - [1,1,1] and [1,2,3] * */ function _uniqContentEquals(aIterator, bIterator, stackA, stackB) { var a = _arrayFromIterator_1(aIterator); var b = _arrayFromIterator_1(bIterator); function eq(_a, _b) { return _equals(_a, _b, stackA.slice(), stackB.slice()); } // if *a* array contains any element that is not included in *b* return !_includesWith_1(function (b, aItem) { return !_includesWith_1(eq, aItem, b); }, b, a); } function _equals(a, b, stackA, stackB) { if (_objectIs_1(a, b)) { return true; } var typeA = type_1(a); if (typeA !== type_1(b)) { return false; } if (a == null || b == null) { return false; } if (typeof a['fantasy-land/equals'] === 'function' || typeof b['fantasy-land/equals'] === 'function') { return typeof a['fantasy-land/equals'] === 'function' && a['fantasy-land/equals'](b) && typeof b['fantasy-land/equals'] === 'function' && b['fantasy-land/equals'](a); } if (typeof a.equals === 'function' || typeof b.equals === 'function') { return typeof a.equals === 'function' && a.equals(b) && typeof b.equals === 'function' && b.equals(a); } switch (typeA) { case 'Arguments': case 'Array': case 'Object': if (typeof a.constructor === 'function' && _functionName_1(a.constructor) === 'Promise') { return a === b; } break; case 'Boolean': case 'Number': case 'String': if (!(typeof a === typeof b && _objectIs_1(a.valueOf(), b.valueOf()))) { return false; } break; case 'Date': if (!_objectIs_1(a.valueOf(), b.valueOf())) { return false; } break; case 'Error': return a.name === b.name && a.message === b.message; case 'RegExp': if (!(a.source === b.source && a.global === b.global && a.ignoreCase === b.ignoreCase && a.multiline === b.multiline && a.sticky === b.sticky && a.unicode === b.unicode)) { return false; } break; } var idx = stackA.length - 1; while (idx >= 0) { if (stackA[idx] === a) { return stackB[idx] === b; } idx -= 1; } switch (typeA) { case 'Map': if (a.size !== b.size) { return false; } return _uniqContentEquals(a.entries(), b.entries(), stackA.concat([a]), stackB.concat([b])); case 'Set': if (a.size !== b.size) { return false; } return _uniqContentEquals(a.values(), b.values(), stackA.concat([a]), stackB.concat([b])); case 'Arguments': case 'Array': case 'Object': case 'Boolean': case 'Number': case 'String': case 'Date': case 'Error': case 'RegExp': case 'Int8Array': case 'Uint8Array': case 'Uint8ClampedArray': case 'Int16Array': case 'Uint16Array': case 'Int32Array': case 'Uint32Array': case 'Float32Array': case 'Float64Array': case 'ArrayBuffer': break; default: // Values of other types are only equal if identical. return false; } var keysA = keys_1(a); if (keysA.length !== keys_1(b).length) { return false; } var extendedStackA = stackA.concat([a]); var extendedStackB = stackB.concat([b]); idx = keysA.length - 1; while (idx >= 0) { var key = keysA[idx]; if (!(_has_1(key, b) && _equals(b[key], a[key], extendedStackA, extendedStackB))) { return false; } idx -= 1; } return true; } var _equals_1 = _equals; /** * Returns `true` if its arguments are equivalent, `false` otherwise. Handles * cyclical data structures. * * Dispatches symmetrically to the `equals` methods of both arguments, if * present. * * @func * @memberOf R * @since v0.15.0 * @category Relation * @sig a -> b -> Boolean * @param {*} a * @param {*} b * @return {Boolean} * @example * * R.equals(1, 1); //=> true * R.equals(1, '1'); //=> false * R.equals([1, 2, 3], [1, 2, 3]); //=> true * * const a = {}; a.v = a; * const b = {}; b.v = b; * R.equals(a, b); //=> true */ var equals = /*#__PURE__*/ _curry2_1(function equals(a, b) { return _equals_1(a, b, [], []); }); var equals_1 = equals; function _indexOf(list, a, idx) { var inf, item; // Array.prototype.indexOf doesn't exist below IE9 if (typeof list.indexOf === 'function') { switch (typeof a) { case 'number': if (a === 0) { // manually crawl the list to distinguish between +0 and -0 inf = 1 / a; while (idx < list.length) { item = list[idx]; if (item === 0 && 1 / item === inf) { return idx; } idx += 1; } return -1; } else if (a !== a) { // NaN while (idx < list.length) { item = list[idx]; if (typeof item === 'number' && item !== item) { return idx; } idx += 1; } return -1; } // non-zero numbers can utilise Set return list.indexOf(a, idx); // all these types can utilise Set case 'string': case 'boolean': case 'function': case 'undefined': return list.indexOf(a, idx); case 'object': if (a === null) { // null can utilise Set return list.indexOf(a, idx); } } } // anything else not covered above, defer to R.equals while (idx < list.length) { if (equals_1(list[idx], a)) { return idx; } idx += 1; } return -1; } var _indexOf_1 = _indexOf; function _includes(a, list) { return _indexOf_1(list, a, 0) >= 0; } var _includes_1 = _includes; function _quote(s) { var escaped = s.replace(/\\/g, '\\\\').replace(/[\b]/g, '\\b') // \b matches word boundary; [\b] matches backspace .replace(/\f/g, '\\f').replace(/\n/g, '\\n').replace(/\r/g, '\\r').replace(/\t/g, '\\t').replace(/\v/g, '\\v').replace(/\0/g, '\\0'); return '"' + escaped.replace(/"/g, '\\"') + '"'; } var _quote_1 = _quote; /** * Polyfill from . */ var pad = function pad(n) { return (n < 10 ? '0' : '') + n; }; var _toISOString = typeof Date.prototype.toISOString === 'function' ? function _toISOString(d) { return d.toISOString(); } : function _toISOString(d) { return d.getUTCFullYear() + '-' + pad(d.getUTCMonth() + 1) + '-' + pad(d.getUTCDate()) + 'T' + pad(d.getUTCHours()) + ':' + pad(d.getUTCMinutes()) + ':' + pad(d.getUTCSeconds()) + '.' + (d.getUTCMilliseconds() / 1000).toFixed(3).slice(2, 5) + 'Z'; }; var _toISOString_1 = _toISOString; function _complement(f) { return function () { return !f.apply(this, arguments); }; } var _complement_1 = _complement; function _filter(fn, list) { var idx = 0; var len = list.length; var result = []; while (idx < len) { if (fn(list[idx])) { result[result.length] = list[idx]; } idx += 1; } return result; } var _filter_1 = _filter; function _isObject(x) { return Object.prototype.toString.call(x) === '[object Object]'; } var _isObject_1 = _isObject; var XFilter = /*#__PURE__*/ function () { function XFilter(f, xf) { this.xf = xf; this.f = f; } XFilter.prototype['@@transducer/init'] = _xfBase.init; XFilter.prototype['@@transducer/result'] = _xfBase.result; XFilter.prototype['@@transducer/step'] = function (result, input) { return this.f(input) ? this.xf['@@transducer/step'](result, input) : result; }; return XFilter; }(); var _xfilter = /*#__PURE__*/ _curry2_1(function _xfilter(f, xf) { return new XFilter(f, xf); }); var _xfilter_1 = _xfilter; /** * Takes a predicate and a `Filterable`, and returns a new filterable of the * same type containing the members of the given filterable which satisfy the * given predicate. Filterable objects include plain objects or any object * that has a filter method such as `Array`. * * Dispatches to the `filter` method of the second argument, if present. * * Acts as a transducer if a transformer is given in list position. * * @func * @memberOf R * @since v0.1.0 * @category List * @sig Filterable f => (a -> Boolean) -> f a -> f a * @param {Function} pred * @param {Array} filterable * @return {Array} Filterable * @see R.reject, R.transduce, R.addIndex * @example * * const isEven = n => n % 2 === 0; * * R.filter(isEven, [1, 2, 3, 4]); //=> [2, 4] * * R.filter(isEven, {a: 1, b: 2, c: 3, d: 4}); //=> {b: 2, d: 4} */ var filter = /*#__PURE__*/ _curry2_1( /*#__PURE__*/ _dispatchable_1(['filter'], _xfilter_1, function (pred, filterable) { return _isObject_1(filterable) ? _reduce_1(function (acc, key) { if (pred(filterable[key])) { acc[key] = filterable[key]; } return acc; }, {}, keys_1(filterable)) : // else _filter_1(pred, filterable); })); var filter_1 = filter; /** * The complement of [`filter`](#filter). * * Acts as a transducer if a transformer is given in list position. Filterable * objects include plain objects or any object that has a filter method such * as `Array`. * * @func * @memberOf R * @since v0.1.0 * @category List * @sig Filterable f => (a -> Boolean) -> f a -> f a * @param {Function} pred * @param {Array} filterable * @return {Array} * @see R.filter, R.transduce, R.addIndex * @example * * const isOdd = (n) => n % 2 === 1; * * R.reject(isOdd, [1, 2, 3, 4]); //=> [2, 4] * * R.reject(isOdd, {a: 1, b: 2, c: 3, d: 4}); //=> {b: 2, d: 4} */ var reject = /*#__PURE__*/ _curry2_1(function reject(pred, filterable) { return filter_1(_complement_1(pred), filterable); }); var reject_1 = reject; function _toString(x, seen) { var recur = function recur(y) { var xs = seen.concat([x]); return _includes_1(y, xs) ? '' : _toString(y, xs); }; // mapPairs :: (Object, [String]) -> [String] var mapPairs = function (obj, keys) { return _map_1(function (k) { return _quote_1(k) + ': ' + recur(obj[k]); }, keys.slice().sort()); }; switch (Object.prototype.toString.call(x)) { case '[object Arguments]': return '(function() { return arguments; }(' + _map_1(recur, x).join(', ') + '))'; case '[object Array]': return '[' + _map_1(recur, x).concat(mapPairs(x, reject_1(function (k) { return /^\d+$/.test(k); }, keys_1(x)))).join(', ') + ']'; case '[object Boolean]': return typeof x === 'object' ? 'new Boolean(' + recur(x.valueOf()) + ')' : x.toString(); case '[object Date]': return 'new Date(' + (isNaN(x.valueOf()) ? recur(NaN) : _quote_1(_toISOString_1(x))) + ')'; case '[object Null]': return 'null'; case '[object Number]': return typeof x === 'object' ? 'new Number(' + recur(x.valueOf()) + ')' : 1 / x === -Infinity ? '-0' : x.toString(10); case '[object String]': return typeof x === 'object' ? 'new String(' + recur(x.valueOf()) + ')' : _quote_1(x); case '[object Undefined]': return 'undefined'; default: if (typeof x.toString === 'function') { var repr = x.toString(); if (repr !== '[object Object]') { return repr; } } return '{' + mapPairs(x, keys_1(x)).join(', ') + '}'; } } var _toString_1 = _toString; /** * Returns the string representation of the given value. `eval`'ing the output * should result in a value equivalent to the input value. Many of the built-in * `toString` methods do not satisfy this requirement. * * If the given value is an `[object Object]` with a `toString` method other * than `Object.prototype.toString`, this method is invoked with no arguments * to produce the return value. This means user-defined constructor functions * can provide a suitable `toString` method. For example: * * function Point(x, y) { * this.x = x; * this.y = y; * } * * Point.prototype.toString = function() { * return 'new Point(' + this.x + ', ' + this.y + ')'; * }; * * R.toString(new Point(1, 2)); //=> 'new Point(1, 2)' * * @func * @memberOf R * @since v0.14.0 * @category String * @sig * -> String * @param {*} val * @return {String} * @example * * R.toString(42); //=> '42' * R.toString('abc'); //=> '"abc"' * R.toString([1, 2, 3]); //=> '[1, 2, 3]' * R.toString({foo: 1, bar: 2, baz: 3}); //=> '{"bar": 2, "baz": 3, "foo": 1}' * R.toString(new Date('2001-02-03T04:05:06Z')); //=> 'new Date("2001-02-03T04:05:06.000Z")' */ var toString$1 = /*#__PURE__*/ _curry1_1(function toString(val) { return _toString_1(val, []); }); var toString_1 = toString$1; /** * Turns a named method with a specified arity into a function that can be * called directly supplied with arguments and a target object. * * The returned function is curried and accepts `arity + 1` parameters where * the final parameter is the target object. * * @func * @memberOf R * @since v0.1.0 * @category Function * @sig Number -> String -> (a -> b -> ... -> n -> Object -> *) * @param {Number} arity Number of arguments the returned function should take * before the target object. * @param {String} method Name of any of the target object's methods to call. * @return {Function} A new curried function. * @see R.construct * @example * * const sliceFrom = R.invoker(1, 'slice'); * sliceFrom(6, 'abcdefghijklm'); //=> 'ghijklm' * const sliceFrom6 = R.invoker(2, 'slice')(6); * sliceFrom6(8, 'abcdefghijklm'); //=> 'gh' * * const dog = { * speak: async () => 'Woof!' * }; * const speak = R.invoker(0, 'speak'); * speak(dog).then(console.log) //~> 'Woof!' * * @symb R.invoker(0, 'method')(o) = o['method']() * @symb R.invoker(1, 'method')(a, o) = o['method'](a) * @symb R.invoker(2, 'method')(a, b, o) = o['method'](a, b) */ var invoker = /*#__PURE__*/ _curry2_1(function invoker(arity, method) { return curryN_1(arity + 1, function () { var target = arguments[arity]; if (target != null && _isFunction_1(target[method])) { return target[method].apply(target, Array.prototype.slice.call(arguments, 0, arity)); } throw new TypeError(toString_1(target) + ' does not have a method named "' + method + '"'); }); }); var invoker_1 = invoker; /** * Returns `true` if the specified object property is equal, in * [`R.equals`](#equals) terms, to the given value; `false` otherwise. * You can test multiple properties with [`R.whereEq`](#whereEq). * * @func * @memberOf R * @since v0.1.0 * @category Relation * @sig String -> a -> Object -> Boolean * @param {String} name * @param {*} val * @param {*} obj * @return {Boolean} * @see R.whereEq, R.propSatisfies, R.equals * @example * * const abby = {name: 'Abby', age: 7, hair: 'blond'}; * const fred = {name: 'Fred', age: 12, hair: 'brown'}; * const rusty = {name: 'Rusty', age: 10, hair: 'brown'}; * const alois = {name: 'Alois', age: 15, disposition: 'surly'}; * const kids = [abby, fred, rusty, alois]; * const hasBrownHair = R.propEq('hair', 'brown'); * R.filter(hasBrownHair, kids); //=> [fred, rusty] */ var propEq = /*#__PURE__*/ _curry3_1(function propEq(name, val, obj) { return equals_1(val, obj[name]); }); var propEq_1 = propEq; /** * Tests the final argument by passing it to the given predicate function. If * the predicate is satisfied, the function will return the result of calling * the `whenTrueFn` function with the same argument. If the predicate is not * satisfied, the argument is returned as is. * * @func * @memberOf R * @since v0.18.0 * @category Logic * @sig (a -> Boolean) -> (a -> a) -> a -> a * @param {Function} pred A predicate function * @param {Function} whenTrueFn A function to invoke when the `condition` * evaluates to a truthy value. * @param {*} x An object to test with the `pred` function and * pass to `whenTrueFn` if necessary. * @return {*} Either `x` or the result of applying `x` to `whenTrueFn`. * @see R.ifElse, R.unless, R.cond * @example * * // truncate :: String -> String * const truncate = R.when( * R.propSatisfies(R.gt(R.__, 10), 'length'), * R.pipe(R.take(10), R.append('…'), R.join('')) * ); * truncate('12345'); //=> '12345' * truncate('0123456789ABC'); //=> '0123456789…' */ var when = /*#__PURE__*/ _curry3_1(function when(pred, whenTrueFn, x) { return pred(x) ? whenTrueFn(x) : x; }); var when_1 = when; const raise = err => { throw err }; const instanceOf = propEq_1('name'); const wait = ms => new Promise(resolve => setTimeout(resolve, ms)); const until = timestampMs => timestampMs - Date.now(); const typeEq = curry_1((string, thing) => type_1(thing) === string); const isDeltaSeconds = compose_1(both_1(typeEq('Number'), complement_1(Number.isNaN)), parseInt); const getHeader = curry_1((header, response) => response.headers.get(header)); const getRateLimitReset = getHeader('RateLimit-Reset'); class RetryableError extends Error { constructor(message) { super(message); this.name = 'RetryableError'; if (Error.captureStackTrace) { Error.captureStackTrace(this, RetryableError); } } } const knownErrors = ['RetryableError', 'FetchError', 'AbortError']; const isRetryableError = both_1( is_1(Error), anyPass_1(map_1(instanceOf, knownErrors)) ); const isRetryableStatus = anyPass_1([ status => status >= 500 && status < 600, status => status === 429 ]); const forceRetry = () => raise(new RetryableError('Retrying...')); /** * Retries up to `max` attempts only if `fetch`: * - returns a `Response` with `status` 429 or 500–599 * - throws a `FetchError` or `AbortError` * If retries exceed `max`, then the original response * or thrown error is passed along. * Use retry behavior before handling bad statuses. * @async * @param {number} max * @param {(url: RequestInfo, opts?: RequestInit) => Promise} fetch function that returns a Response * @returns {(url: RequestInfo, opts?: RequestInit) => Promise} function that returns a Response * @example * const firstUser = await retry(3, fetch)('/users/1'); */ const retry$3 = curry_1((max, fetch) => (...args) => lib(async (bail, tries) => { const canRetry = tries < (max + 1); return fetch(...args) .then(async res => { const resetHeader = getRateLimitReset(res); if (resetHeader && res.status === 429) { isDeltaSeconds(resetHeader) ? await compose_1(wait, sec => sec * 1000, parseInt)(resetHeader) : await compose_1(wait, until, invoker_1(0, 'getTime'), constructN_1(1, Date))(resetHeader); } return res; }) .then(when_1(res => isRetryableStatus(res.status) && canRetry, forceRetry)) .catch(ifElse_1(isRetryableError, raise, bail)); }, { retries: max, minTimeout: 10, factor: 5 })); module.exports = retry$3;