async-af
Version:
The asynciest of async libs there ever was or ever will be...AsyncAF!?
1,292 lines (1,088 loc) • 104 kB
JavaScript
/*!
* async-af/legacy v7.0.39
*
* AsyncAF (The asynciest of async libs there ever was or ever will be...AsyncAF!?)
* (https://async-af.js.org/AsyncAF)
*
* Copyright (c) 2017-present, Scott Rudiger (https://github.com/ScottRudiger)
*
* This source code is licensed under the MIT license found in this library's
* GitHub repository (https://github.com/AsyncAF/AsyncAF/blob/master/LICENSE).
*/
(function webpackUniversalModuleDefinition(root, factory) {
if(typeof exports === 'object' && typeof module === 'object')
module.exports = factory();
else if(typeof define === 'function' && define.amd)
define("AsyncAF", [], factory);
else if(typeof exports === 'object')
exports["AsyncAF"] = factory();
else
root["AsyncAF"] = factory();
})(typeof self !== 'undefined' ? self : this, function() {
return /******/ (function(modules) { // webpackBootstrap
/******/ // The module cache
/******/ var installedModules = {};
/******/
/******/ // The require function
/******/ function __webpack_require__(moduleId) {
/******/
/******/ // Check if module is in cache
/******/ if(installedModules[moduleId]) {
/******/ return installedModules[moduleId].exports;
/******/ }
/******/ // Create a new module (and put it into the cache)
/******/ var module = installedModules[moduleId] = {
/******/ i: moduleId,
/******/ l: false,
/******/ exports: {}
/******/ };
/******/
/******/ // Execute the module function
/******/ modules[moduleId].call(module.exports, module, module.exports, __webpack_require__);
/******/
/******/ // Flag the module as loaded
/******/ module.l = true;
/******/
/******/ // Return the exports of the module
/******/ return module.exports;
/******/ }
/******/
/******/
/******/ // expose the modules object (__webpack_modules__)
/******/ __webpack_require__.m = modules;
/******/
/******/ // expose the module cache
/******/ __webpack_require__.c = installedModules;
/******/
/******/ // define getter function for harmony exports
/******/ __webpack_require__.d = function(exports, name, getter) {
/******/ if(!__webpack_require__.o(exports, name)) {
/******/ Object.defineProperty(exports, name, { enumerable: true, get: getter });
/******/ }
/******/ };
/******/
/******/ // define __esModule on exports
/******/ __webpack_require__.r = function(exports) {
/******/ if(typeof Symbol !== 'undefined' && Symbol.toStringTag) {
/******/ Object.defineProperty(exports, Symbol.toStringTag, { value: 'Module' });
/******/ }
/******/ Object.defineProperty(exports, '__esModule', { value: true });
/******/ };
/******/
/******/ // create a fake namespace object
/******/ // mode & 1: value is a module id, require it
/******/ // mode & 2: merge all properties of value into the ns
/******/ // mode & 4: return value when already ns object
/******/ // mode & 8|1: behave like require
/******/ __webpack_require__.t = function(value, mode) {
/******/ if(mode & 1) value = __webpack_require__(value);
/******/ if(mode & 8) return value;
/******/ if((mode & 4) && typeof value === 'object' && value && value.__esModule) return value;
/******/ var ns = Object.create(null);
/******/ __webpack_require__.r(ns);
/******/ Object.defineProperty(ns, 'default', { enumerable: true, value: value });
/******/ if(mode & 2 && typeof value != 'string') for(var key in value) __webpack_require__.d(ns, key, function(key) { return value[key]; }.bind(null, key));
/******/ return ns;
/******/ };
/******/
/******/ // getDefaultExport function for compatibility with non-harmony modules
/******/ __webpack_require__.n = function(module) {
/******/ var getter = module && module.__esModule ?
/******/ function getDefault() { return module['default']; } :
/******/ function getModuleExports() { return module; };
/******/ __webpack_require__.d(getter, 'a', getter);
/******/ return getter;
/******/ };
/******/
/******/ // Object.prototype.hasOwnProperty.call
/******/ __webpack_require__.o = function(object, property) { return Object.prototype.hasOwnProperty.call(object, property); };
/******/
/******/ // __webpack_public_path__
/******/ __webpack_require__.p = "";
/******/
/******/
/******/ // Load entry module and return exports
/******/ return __webpack_require__(__webpack_require__.s = "./lib/classes/AsyncAF.js");
/******/ })
/************************************************************************/
/******/ ({
/***/ "./lib/classes/AsyncAF.js":
/***/ (function(module, __webpack_exports__, __webpack_require__) {
"use strict";
// EXTERNAL MODULE: ./node_modules/@babel/runtime/helpers/defineProperty.js
var defineProperty = __webpack_require__("./node_modules/@babel/runtime/helpers/defineProperty.js");
var defineProperty_default = /*#__PURE__*/__webpack_require__.n(defineProperty);
// EXTERNAL MODULE: ./node_modules/@babel/runtime/helpers/taggedTemplateLiteral.js
var taggedTemplateLiteral = __webpack_require__("./node_modules/@babel/runtime/helpers/taggedTemplateLiteral.js");
var taggedTemplateLiteral_default = /*#__PURE__*/__webpack_require__.n(taggedTemplateLiteral);
// EXTERNAL MODULE: ./node_modules/@babel/runtime/helpers/slicedToArray.js
var slicedToArray = __webpack_require__("./node_modules/@babel/runtime/helpers/slicedToArray.js");
var slicedToArray_default = /*#__PURE__*/__webpack_require__.n(slicedToArray);
// EXTERNAL MODULE: ./node_modules/@babel/runtime/helpers/classCallCheck.js
var classCallCheck = __webpack_require__("./node_modules/@babel/runtime/helpers/classCallCheck.js");
var classCallCheck_default = /*#__PURE__*/__webpack_require__.n(classCallCheck);
// EXTERNAL MODULE: ./node_modules/@babel/runtime/helpers/possibleConstructorReturn.js
var possibleConstructorReturn = __webpack_require__("./node_modules/@babel/runtime/helpers/possibleConstructorReturn.js");
var possibleConstructorReturn_default = /*#__PURE__*/__webpack_require__.n(possibleConstructorReturn);
// EXTERNAL MODULE: ./node_modules/@babel/runtime/helpers/getPrototypeOf.js
var getPrototypeOf = __webpack_require__("./node_modules/@babel/runtime/helpers/getPrototypeOf.js");
var getPrototypeOf_default = /*#__PURE__*/__webpack_require__.n(getPrototypeOf);
// EXTERNAL MODULE: ./node_modules/@babel/runtime/helpers/inherits.js
var inherits = __webpack_require__("./node_modules/@babel/runtime/helpers/inherits.js");
var inherits_default = /*#__PURE__*/__webpack_require__.n(inherits);
// EXTERNAL MODULE: ./lib/methods/_internal/createNewlessClass.js
var createNewlessClass = __webpack_require__("./lib/methods/_internal/createNewlessClass.js");
// EXTERNAL MODULE: ./lib/classes/AsyncAfWrapper.js + 2 modules
var AsyncAfWrapper = __webpack_require__("./lib/classes/AsyncAfWrapper.js");
// EXTERNAL MODULE: ./node_modules/@babel/runtime/helpers/toConsumableArray.js
var toConsumableArray = __webpack_require__("./node_modules/@babel/runtime/helpers/toConsumableArray.js");
var toConsumableArray_default = /*#__PURE__*/__webpack_require__.n(toConsumableArray);
// EXTERNAL MODULE: ./lib/methods/_internal/nameFunction.js
var nameFunction = __webpack_require__("./lib/methods/_internal/nameFunction.js");
// EXTERNAL MODULE: ./lib/methods/other/logAF.js + 4 modules
var logAF = __webpack_require__("./lib/methods/other/logAF.js");
// EXTERNAL MODULE: ./lib/methods/arrays/mapAF.js
var mapAF = __webpack_require__("./lib/methods/arrays/mapAF.js");
// EXTERNAL MODULE: ./lib/methods/arrays/forEachAF.js
var forEachAF = __webpack_require__("./lib/methods/arrays/forEachAF.js");
// EXTERNAL MODULE: ./lib/methods/arrays/filterAF.js
var filterAF = __webpack_require__("./lib/methods/arrays/filterAF.js");
// EXTERNAL MODULE: ./lib/methods/arrays/reduceAF.js + 1 modules
var reduceAF = __webpack_require__("./lib/methods/arrays/reduceAF.js");
// EXTERNAL MODULE: ./lib/methods/arrays/everyAF.js
var everyAF = __webpack_require__("./lib/methods/arrays/everyAF.js");
// EXTERNAL MODULE: ./lib/methods/arrays/someAF.js
var someAF = __webpack_require__("./lib/methods/arrays/someAF.js");
// EXTERNAL MODULE: ./lib/methods/arrays/includesAF.js
var includesAF = __webpack_require__("./lib/methods/arrays/includesAF.js");
// EXTERNAL MODULE: ./lib/methods/arrays/findAF.js
var findAF = __webpack_require__("./lib/methods/arrays/findAF.js");
// EXTERNAL MODULE: ./lib/methods/arrays/findIndexAF.js
var findIndexAF = __webpack_require__("./lib/methods/arrays/findIndexAF.js");
// EXTERNAL MODULE: ./lib/methods/arrays/indexOfAF.js
var indexOfAF = __webpack_require__("./lib/methods/arrays/indexOfAF.js");
// EXTERNAL MODULE: ./lib/methods/arrays/lastIndexOfAF.js
var lastIndexOfAF = __webpack_require__("./lib/methods/arrays/lastIndexOfAF.js");
// EXTERNAL MODULE: ./lib/methods/arrays/joinAF.js
var joinAF = __webpack_require__("./lib/methods/arrays/joinAF.js");
// EXTERNAL MODULE: ./lib/methods/arrays/concatAF.js
var concatAF = __webpack_require__("./lib/methods/arrays/concatAF.js");
// EXTERNAL MODULE: ./lib/methods/strings/splitAF.js
var splitAF = __webpack_require__("./lib/methods/strings/splitAF.js");
// CONCATENATED MODULE: ./packageList.js
/* eslint-disable import/first */
var libName = 'async-af';
var libPath = './lib/';
var makeScoped = function makeScoped(name) {
return "@".concat(libName, "/").concat(name.replace(/AsyncAf|AF/g, '').toLowerCase());
};
/* ____________________________
| CLASSES |
|____________________________| */
var classPath = "".concat(libPath, "classes/");
var classes = [[{
name: 'AsyncAF'
}, "".concat(classPath, "AsyncAF"), libName], [{
name: 'AsyncAfWrapper'
}, "".concat(classPath, "AsyncAfWrapper"), makeScoped('AsyncAfWrapper')]];
/* ____________________________
| STATIC METHODS |
|____________________________| */
var staticMethods = [Object(nameFunction["default"])(logAF["default"], 'logAF')].map(function (method) {
return [method, "".concat(libPath, "methods/other/").concat(method.name), makeScoped(method.name)];
});
/* ____________________________
| PROTOTYPE METHODS |
|____________________________| */
// Arrays
var arrayMethods = [Object(nameFunction["default"])(mapAF["default"], 'mapAF'), Object(nameFunction["default"])(forEachAF["default"], 'forEachAF'), Object(nameFunction["default"])(filterAF["default"], 'filterAF'), Object(nameFunction["default"])(reduceAF["default"], 'reduceAF'), Object(nameFunction["default"])(everyAF["default"], 'everyAF'), Object(nameFunction["default"])(someAF["default"], 'someAF'), Object(nameFunction["default"])(includesAF["default"], 'includesAF'), Object(nameFunction["default"])(findAF["default"], 'findAF'), Object(nameFunction["default"])(findIndexAF["default"], 'findIndexAF'), Object(nameFunction["default"])(indexOfAF["default"], 'indexOfAF'), Object(nameFunction["default"])(lastIndexOfAF["default"], 'lastIndexOfAF'), Object(nameFunction["default"])(joinAF["default"], 'joinAF'), Object(nameFunction["default"])(concatAF["default"], 'concatAF')].map(function (method) {
return [method, "".concat(libPath, "methods/arrays/").concat(method.name), makeScoped(method.name)];
}); // strings
var stringMethods = [Object(nameFunction["default"])(splitAF["default"], 'splitAF')].map(function (method) {
return [method, "".concat(libPath, "methods/strings/").concat(method.name), makeScoped(method.name)];
});
var prototypeMethods = [].concat(toConsumableArray_default()(arrayMethods), toConsumableArray_default()(stringMethods));
/* ____________________________
| COLLECTIONS |
|____________________________| */
// import arrays from './lib/collections/arrays';
var collections = [// arrays,
];
/* harmony default export */ var packageList = ([].concat(classes, toConsumableArray_default()(staticMethods), toConsumableArray_default()(prototypeMethods), collections));
var packageList_pluckMethods = function pluckMethods(packages) {
return packages.map(function (_ref) {
var _ref2 = slicedToArray_default()(_ref, 1),
method = _ref2[0];
return method;
});
};
var staticMethodsOnly = packageList_pluckMethods(staticMethods);
var prototypeMethodsOnly = packageList_pluckMethods(prototypeMethods);
// CONCATENATED MODULE: ./lib/classes/AsyncAF.js
function _templateObject() {
var data = taggedTemplateLiteral_default()(["AF"]);
_templateObject = function _templateObject() {
return data;
};
return data;
}
/**
* class that holds all the AsyncAF methods
*
* while AsyncAF is a class, it can create instances with or without the `new` keyword
* @param {any} data the data to be wrapped by the AsyncAF class; can be promises or non-promises
* @returns {Object} returns an instance of AsyncAF wrapping the passed in data
* @example
*
* const promises = [1, 2, 3].map(n => Promise.resolve(n));
*
*
* AsyncAF(promises).mapAF(n => n * 2).filterAF(n => n !== 4).forEachAF(n => console.log(n));
* // logs 2 then 6
* @since 3.0.0
* @see AsyncAfWrapper
* @class AsyncAF
*/
var AsyncAF_AsyncAF = Object(createNewlessClass["default"])(
/*#__PURE__*/
function (_AsyncAfProto) {
inherits_default()(AsyncAF, _AsyncAfProto);
function AsyncAF() {
classCallCheck_default()(this, AsyncAF);
return possibleConstructorReturn_default()(this, getPrototypeOf_default()(AsyncAF).apply(this, arguments));
}
return AsyncAF;
}(AsyncAfWrapper["AsyncAfWrapperProto"]));
var AsyncAF_prepForDefine = function prepForDefine(methods) {
return methods.reduce(function (methods, method) {
// add all '*AF' methods and add 'AF-less' aliases (e.g., mapAF -> map)
var _ref = method.name.split(_templateObject()) ||
/* istanbul ignore next */
[method.name],
_ref2 = slicedToArray_default()(_ref, 1),
alias = _ref2[0];
return Object.assign(methods, defineProperty_default()({}, method.name, {
value: method
}), defineProperty_default()({}, alias, {
value: method
}));
}, {});
};
Object.defineProperties(AsyncAfWrapper["AsyncAfWrapperProto"], AsyncAF_prepForDefine(staticMethodsOnly));
Object.defineProperties(AsyncAfWrapper["AsyncAfWrapperProto"].prototype, AsyncAF_prepForDefine(prototypeMethodsOnly));
/* harmony default export */ var classes_AsyncAF = __webpack_exports__["default"] = (AsyncAF_AsyncAF);
/***/ }),
/***/ "./lib/classes/AsyncAfWrapper.js":
/***/ (function(module, __webpack_exports__, __webpack_require__) {
"use strict";
// EXTERNAL MODULE: ./node_modules/@babel/runtime/helpers/possibleConstructorReturn.js
var possibleConstructorReturn = __webpack_require__("./node_modules/@babel/runtime/helpers/possibleConstructorReturn.js");
var possibleConstructorReturn_default = /*#__PURE__*/__webpack_require__.n(possibleConstructorReturn);
// EXTERNAL MODULE: ./node_modules/@babel/runtime/helpers/getPrototypeOf.js
var getPrototypeOf = __webpack_require__("./node_modules/@babel/runtime/helpers/getPrototypeOf.js");
var getPrototypeOf_default = /*#__PURE__*/__webpack_require__.n(getPrototypeOf);
// EXTERNAL MODULE: ./node_modules/@babel/runtime/helpers/inherits.js
var inherits = __webpack_require__("./node_modules/@babel/runtime/helpers/inherits.js");
var inherits_default = /*#__PURE__*/__webpack_require__.n(inherits);
// EXTERNAL MODULE: ./node_modules/@babel/runtime/helpers/defineProperty.js
var defineProperty = __webpack_require__("./node_modules/@babel/runtime/helpers/defineProperty.js");
var defineProperty_default = /*#__PURE__*/__webpack_require__.n(defineProperty);
// EXTERNAL MODULE: ./node_modules/@babel/runtime/helpers/objectSpread.js
var objectSpread = __webpack_require__("./node_modules/@babel/runtime/helpers/objectSpread.js");
var objectSpread_default = /*#__PURE__*/__webpack_require__.n(objectSpread);
// EXTERNAL MODULE: ./node_modules/@babel/runtime/helpers/classCallCheck.js
var classCallCheck = __webpack_require__("./node_modules/@babel/runtime/helpers/classCallCheck.js");
var classCallCheck_default = /*#__PURE__*/__webpack_require__.n(classCallCheck);
// EXTERNAL MODULE: ./node_modules/@babel/runtime/helpers/createClass.js
var createClass = __webpack_require__("./node_modules/@babel/runtime/helpers/createClass.js");
var createClass_default = /*#__PURE__*/__webpack_require__.n(createClass);
// EXTERNAL MODULE: ./lib/methods/_internal/createNewlessClass.js
var createNewlessClass = __webpack_require__("./lib/methods/_internal/createNewlessClass.js");
// EXTERNAL MODULE: ./node_modules/@babel/runtime/helpers/typeof.js
var helpers_typeof = __webpack_require__("./node_modules/@babel/runtime/helpers/typeof.js");
var typeof_default = /*#__PURE__*/__webpack_require__.n(helpers_typeof);
// CONCATENATED MODULE: ./lib/methods/other/use.js
/**
* adds prototype/static methods to AsyncAF or AsyncAfWrapper
*
* see {@link AsyncAfWrapper AsyncAfWrapper} for an example of how to cherry-pick AsyncAF methods you'd like to use rather than pulling in the entire AsyncAF library;
*
* for something different, the following shows how to add custom methods to AsyncAF & AsyncAfWrapper
*
* **Example**
*
* say you want to extend AsyncAF with your own prototype method that acts on an array of numbers or promises that resolve to numbers and naively adds them up
*
* let's call it sumAF; here's some code:
*
* ```js
* // sumAF.js
*
* const sumAF = function () {
* return this.then(nums => Promise.all(nums))
* .then(nums => nums.reduce((sum, num) => sum + num));
* };
*
* export default sumAF;
* ```
*
* pull in {@link AsyncAF AsyncAF} or {@link AsyncAfWrapper AsyncAfWrapper} and `sumAF` to the file you'd like to use it in:
*
* ```js
* // otherFile.js
*
* import AsyncAF from 'async-af'; // or import AsyncAF from '@async-af/wrapper';
* import sumAF from './sumAF';
* ```
*
* then, call `use` on `AsyncAF` and pass in `sumAF` wrapped in an object to the first parameter, `prototypeMethods`:
*
* ```js
* // otherFile.js
* // ...
*
* AsyncAF.use({sumAF});
* ```
*
* ready! now your custom prototype method will be available on AsyncAF
*
* ```js
* // otherFile.js
* // ...
*
* const promises = [1, 2, 3].map(n => Promise.resolve(n));
*
* const sum = AsyncAF(promises).sumAF()
*
* AsyncAF.logAF(sum);
* // @otherFile.js:10:9:
* // 6
* // in 0.001 secs
* ```
*
* if you'd like to add a static method to AsyncAF, `use` accepts a second optional argument `staticMethods`; for example:
*
* ```js
* const staticNoop = () => {};
*
* AsyncAF.use({}, {staticNoop});
*
* AsyncAF.staticNoop(); // noop
* ```
*
* @static
* @param {Object} prototypeMethods an Object containing the prototype methods you'd like to use
* @param {Object=} staticMethods an Object containing the static methods you'd like to use
* @returns {undefined} adds prototype/static methods to AsyncAF or AsyncAfWrapper
* @since 3.0.0
* @see AsyncAF
* @see AsyncAfWrapper
* @see {@tutorial TOO_MANY_IMPORTS}
* @memberof AsyncAfWrapper
* @alias AsyncAfWrapper#use
*/
var use_use = function use(prototypeMethods) {
var staticMethods = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {};
if (typeof_default()(prototypeMethods) !== 'object') throw TypeError('prototypeMethods param accepts an Object containing the prototypeMethods you\'d like to add to the AsyncAF prototype, or an empty Object');
if (typeof_default()(staticMethods) !== 'object') throw TypeError('staticMethods param accepts an Object containing the staticMethods you\'d like to add to AsyncAF');
Object.assign(this.prototype, prototypeMethods);
Object.assign(this, staticMethods);
};
/* harmony default export */ var other_use = (use_use);
// CONCATENATED MODULE: ./lib/methods/other/series.js
var inSeries = new WeakMap();
var series = {
inSeries: {
get: function get() {
return inSeries.get(this);
}
},
/**
* indicates that the next method invoked should be performed in series
*
* when you need to perform a method in series rather than in parallel, prepend the method with `series`; e.g.:
* ```js
* AsyncAF(promises).series.forEachAF(callback)
* ```
*
* `series` can currently be chained with:
* - {@link AsyncAF#everyAF everyAF}
* - {@link AsyncAF#filterAF filterAF}
* - {@link AsyncAF#findAF findAF}
* - {@link AsyncAF#findIndexAF findIndexAF}
* - {@link AsyncAF#forEachAF forEachAF}
* - {@link AsyncAF#includesAF includesAF}
* - {@link AsyncAF#indexOfAF indexOfAF}
* - {@link AsyncAF#lastIndexOfAF lastIndexOfAF}
* - {@link AsyncAF#mapAF mapAF}
* - {@link AsyncAF#reduceAF reduceAF}
* - {@link AsyncAF#someAF someAF}
*
* @example
* import delay from 'delay'; // {@link https://www.npmjs.com/package/delay}
*
* const nums = [2, 1];
*
* // perform a serial forEach by chaining {@link AsyncAF#series series} and {@link AsyncAF#forEachAF forEachAF}
* (async () => {
* const start = Date.now();
*
* await AsyncAF(nums).series.forEachAF(async num => {
* await delay(num * 1000);
* console.log(num, `at ~${Date.now() - start} ms`);
* });
*
* console.log(`total: ~${Date.now() - start} ms`);
* })();
*
* // logs:
* // 2 'at ~2000 ms'
* // 1 'at ~3000 ms'
* // total: ~3000 ms
*
*
* // perform a parallel forEach by omitting {@link AsyncAF#series series}
* (async () => {
* const start = Date.now();
*
* await AsyncAF(nums).forEachAF(async num => {
* await delay(num * 1000);
* console.log(num, `at ~${Date.now() - start} ms`);
* });
*
* console.log(`total: ~${Date.now() - start} ms`);
* })();
*
* // logs:
* // 1 'at ~1000 ms'
* // 2 'at ~2000 ms'
* // total: ~2000 ms
*
* @function series
* @returns {AsyncAF.<any>} returns an instance of AsyncAF that will perform the next method invocation serially
* @since 7.0.0
* @see {@link AsyncAF#io io} (alias)
* @memberof AsyncAF#
*/
series: {
get: function get() {
inSeries.set(this, !this.inSeries);
return this;
}
},
/**
* `io` (in order) indicates that the next method invoked should be performed in series
*
* when you need to perform a method in series rather than in parallel, prepend the method with `io`; e.g.:
* ```js
* AsyncAF(promises).io.forEachAF(callback)
* ```
*
* `io` is an alias for `series`; see {@link AsyncAF#series series's documentation} for more
* @function io
* @returns {AsyncAF.<any>} returns an instance of AsyncAF that will perform the next method invocation serially
* @since 7.0.0
* @see {@link AsyncAF#series series} (alias)
* @memberof AsyncAF#
*/
io: {
get: function get() {
return this.series;
}
}
};
/* harmony default export */ var other_series = (series);
// CONCATENATED MODULE: ./lib/classes/AsyncAfWrapper.js
/* harmony export (binding) */ __webpack_require__.d(__webpack_exports__, "AsyncAfWrapperProto", function() { return AsyncAfWrapper_AsyncAfWrapperProto; });
var dataStore = new WeakMap();
var AsyncAfWrapper_AsyncAfWrapperProto =
/*#__PURE__*/
function () {
function AsyncAfWrapperProto(data) {
classCallCheck_default()(this, AsyncAfWrapperProto);
dataStore.set(this, Promise.resolve(data));
}
createClass_default()(AsyncAfWrapperProto, [{
key: "then",
value: function then(resolve, reject) {
return this.constructor(dataStore.get(this).then(resolve, reject));
}
}, {
key: "catch",
value: function _catch(reject) {
return this.then(null, reject);
}
}, {
key: "finally",
value: function _finally(onFinally) {
return dataStore.get(this).finally(onFinally);
}
}]);
return AsyncAfWrapperProto;
}();
AsyncAfWrapper_AsyncAfWrapperProto.use = other_use;
Object.defineProperties(AsyncAfWrapper_AsyncAfWrapperProto.prototype, objectSpread_default()({}, other_series, defineProperty_default()({}, Symbol.toStringTag, {
value: 'AsyncAF'
})));
/**
* empty AsyncAF class wrapper
*
* AsyncAfWrapper is one option for cherry-picking only the methods you'd like to use in your code; {@link AsyncAfWrapper#use use}, {@link AsyncAF#series series}, and {@link AsyncAF#io io} are the only methods initially available on AsyncAfWrapper; see example below
*
* **Note:** while AsyncAfWrapper is a class, it can create instances with or without the `new` keyword
*
* **Example**
*
* say you only want to use {@link AsyncAF#mapAF mapAF}, {@link AsyncAF#filterAF filterAF}, {@link AsyncAF#forEachAF forEachAF}, and {@link AsyncAF#logAF logAF} instead of pulling in the entire AsyncAF library
*
* first, install the separate packages (e.g., for npm):
*
* `$ npm install --save @async-af/{wrapper,map,filter,foreach,log}`
*
* or, if on Windows:
*
* `$ npm install --save @async-af/wrapper @async-af/map @async-af/filter @async-af/foreach @async-af/log`
*
* then import the packages
* ```js
* import AsyncAF from '@async-af/wrapper'; // aliasing 'AsyncAfWrapper' as 'AsyncAF'
* import mapAF from '@async-af/map';
* import filterAF from '@async-af/filter';
* import forEachAF from '@async-af/foreach';
* import logAF from '@async-af/log';
* ```
*
* _if you'd like to save some vertical screen real estate and cut the imports down to one line, see_ {@tutorial TOO_MANY_IMPORTS}
*
* then call {@link AsyncAfWrapper#use use}, including all prototype methods you'd like to add to AsyncAfWrapper's prototype in the first argument, `prototypeMethods` and all static methods you'd like to add to AsyncAfWrapper in the second optional argument, `staticMethods`
* ```js
* AsyncAF.use({ // prototype methods go in the first argument
* mapAF,
* filterAF,
* forEachAF
* }, { // static methods go in the second argument
* logAF
* });
* ```
*
* ready to go!
* ```js
* const promises = [1, 2, 3].map(n => Promise.resolve(n));
*
* AsyncAF(promises).mapAF(n => n * 2).filterAF(n => n !== 4).forEachAF(n => console.log(n));
* // logs 2 then 6
*
* AsyncAF.logAF(promises);
* // @filename.js:24:9:
* // [ 1, 2, 3 ]
* // in 0.003 secs
* ```
*
* **protip:** you can use the same technique to add your own custom prototype or static methods to AsyncAfWrapper or even to the main AsyncAF class; see {@link AsyncAfWrapper#use use} for an example
* @param {any} data the data to be wrapped by the AsyncAF class; can be promises or non-promises
* @returns {Object} returns an instance of AsyncAfWrapper wrapping the passed in data
* @since 3.0.0
* @see AsyncAF
* @see {@link AsyncAfWrapper#use use}
* @see {@tutorial TOO_MANY_IMPORTS}
* @class AsyncAfWrapper
*/
var AsyncAfWrapper_AsyncAfWrapper = Object(createNewlessClass["default"])(
/*#__PURE__*/
function (_AsyncAfWrapperProto) {
inherits_default()(AsyncAfWrapper, _AsyncAfWrapperProto);
function AsyncAfWrapper() {
classCallCheck_default()(this, AsyncAfWrapper);
return possibleConstructorReturn_default()(this, getPrototypeOf_default()(AsyncAfWrapper).apply(this, arguments));
}
return AsyncAfWrapper;
}(AsyncAfWrapper_AsyncAfWrapperProto));
/* harmony default export */ var classes_AsyncAfWrapper = __webpack_exports__["default"] = (AsyncAfWrapper_AsyncAfWrapper);
/***/ }),
/***/ "./lib/methods/_internal/commonCallback.js":
/***/ (function(module, __webpack_exports__, __webpack_require__) {
"use strict";
__webpack_require__.r(__webpack_exports__);
/* eslint-disable no-unused-vars, valid-jsdoc */
/**
* @typedef {callback} _
* @param {?} currentValue
* @param {Number=} index
* @param {[]=} array
* @returns {any}
*/
function callback(currentValue, index, array) {}
/* harmony default export */ __webpack_exports__["default"] = (callback);
/***/ }),
/***/ "./lib/methods/_internal/createNewlessClass.js":
/***/ (function(module, __webpack_exports__, __webpack_require__) {
"use strict";
__webpack_require__.r(__webpack_exports__);
/* harmony import */ var _babel_runtime_helpers_construct__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__("./node_modules/@babel/runtime/helpers/construct.js");
/* harmony import */ var _babel_runtime_helpers_construct__WEBPACK_IMPORTED_MODULE_0___default = /*#__PURE__*/__webpack_require__.n(_babel_runtime_helpers_construct__WEBPACK_IMPORTED_MODULE_0__);
/* harmony import */ var _nameFunction__WEBPACK_IMPORTED_MODULE_1__ = __webpack_require__("./lib/methods/_internal/nameFunction.js");
var createNewlessClass = function createNewlessClass(Class) {
var name = Class.name;
var Newless = function Newless() {
for (var _len = arguments.length, args = new Array(_len), _key = 0; _key < _len; _key++) {
args[_key] = arguments[_key];
}
return _babel_runtime_helpers_construct__WEBPACK_IMPORTED_MODULE_0___default()(Class, args);
};
Newless.prototype = Class.prototype;
Object.setPrototypeOf(Newless, Class);
Newless.prototype.constructor = Newless;
return Object(_nameFunction__WEBPACK_IMPORTED_MODULE_1__["default"])(Newless, name);
};
/* harmony default export */ __webpack_exports__["default"] = (createNewlessClass);
/***/ }),
/***/ "./lib/methods/_internal/nameFunction.js":
/***/ (function(module, __webpack_exports__, __webpack_require__) {
"use strict";
__webpack_require__.r(__webpack_exports__);
var nameFunction = function nameFunction(fn, name) {
return Object.defineProperty(fn, 'name', {
value: name,
configurable: true
});
};
/* harmony default export */ __webpack_exports__["default"] = (nameFunction);
/***/ }),
/***/ "./lib/methods/_internal/permissiveIsArrayLike.js":
/***/ (function(module, __webpack_exports__, __webpack_require__) {
"use strict";
__webpack_require__.r(__webpack_exports__);
var permissiveIsArrayLike = function permissiveIsArrayLike(obj) {
return Array.isArray(obj) || obj != null && obj.length != null;
};
/* harmony default export */ __webpack_exports__["default"] = (permissiveIsArrayLike);
/***/ }),
/***/ "./lib/methods/_internal/promiseAllWithHoles.js":
/***/ (function(module, __webpack_exports__, __webpack_require__) {
"use strict";
__webpack_require__.r(__webpack_exports__);
var promiseAllWithHoles = function promiseAllWithHoles(promises) {
return new Promise(function (resolve, reject) {
var length = promises.length >>> 0;
var result = Array(length);
var pending = length;
var i = length;
if (!length) return resolve(result);
var settlePromise = function settlePromise(i) {
return Promise.resolve(promises[i]).then(function (value) {
if (i in promises) result[i] = value;
if (! --pending) resolve(result);
}, reject);
};
while (i--) {
settlePromise(i);
}
});
};
/* harmony default export */ __webpack_exports__["default"] = (promiseAllWithHoles);
/***/ }),
/***/ "./lib/methods/_internal/resolve.js":
/***/ (function(module, __webpack_exports__, __webpack_require__) {
"use strict";
__webpack_require__.r(__webpack_exports__);
/* harmony export (binding) */ __webpack_require__.d(__webpack_exports__, "serial", function() { return serial; });
/* harmony export (binding) */ __webpack_require__.d(__webpack_exports__, "parallel", function() { return parallel; });
/* harmony import */ var _promiseAllWithHoles__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__("./lib/methods/_internal/promiseAllWithHoles.js");
var serial = function serial(arr) {
return function resolveSerially(resolved, i) {
var length = resolved.length;
if (!length) return Promise.resolve(resolved);
var hole = !(i in arr);
return Promise.resolve(arr[i]).then(function (el) {
if (!hole) resolved[i] = el;
if (i === length - 1) return resolved;
return resolveSerially(resolved, i + 1);
});
}(Array(arr.length >>> 0), 0);
};
var parallel = function parallel(arr, mapper) {
var thisArg = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : undefined;
return Object(_promiseAllWithHoles__WEBPACK_IMPORTED_MODULE_0__["default"])(arr, function (el) {
return el;
}).then(!mapper ? undefined : function (arr) {
return Object(_promiseAllWithHoles__WEBPACK_IMPORTED_MODULE_0__["default"])(Array.prototype.map.call(arr, mapper, thisArg));
});
};
/***/ }),
/***/ "./lib/methods/arrays/concatAF.js":
/***/ (function(module, __webpack_exports__, __webpack_require__) {
"use strict";
__webpack_require__.r(__webpack_exports__);
var resolveByType = function resolveByType(data) {
return Promise[Array.isArray(data) ? 'all' : 'resolve'](data);
};
/**
* merges an array or string with one or more arrays, strings, or other values, and resolves to a new array or string;
*
* concatAF flexibly accepts arrays, strings, promises, other values, or other instances of AsyncAF; see examples
*
* @param {any} values arrays, strings, or values to concatenate into a new array or string
* - if any values are a Promise, they'll first be resolved then concatenated
* - if any values are an instance of AsyncAF, they'll be merged into one instance
* @returns {Promise.<Array>|Promise.<String>} `Promise` that resolves to a newly merged array or string
* @example
*
* // arrays
* const arr = Promise.resolve([1, 2]);
* AsyncAF(arr).concatAF([3, 4]); // Promise that resolves to [1, 2, 3, 4]
* AsyncAF(arr).concatAF([3, 4], [5, 6]); // Promise that resolves to [1, 2, 3, 4, 5, 6]
*
* // nested arrays
* const arr1 = Promise.resolve([1, 2]);
* const arr2 = [3, [4, 5]];
* AsyncAF(arr1).concatAF(arr2); // Promise that resolves to [1, 2, 3, [4, 5]]
*
* // strings
* const str = Promise.resolve('str');
* AsyncAF(str).concatAF('ing'); // Promise that resolves to 'string'
* AsyncAF(str).concatAF('ing', 'y'); // Promise that resolves to 'stringy'
*
* // other instances of AsyncAF
* const aaf1 = AsyncAF([1, 2]);
* const aaf2 = AsyncAF(3);
*
* aaf1.concatAF(aaf2); // Promise that resolves to [1, 2, 3];
*
* const aaf3 = AsyncAF('stringy');
* const aaf4 = AsyncAF('AF');
*
* aaf3.concatAF(aaf4); // Promise that resolves to 'stringyAF'
*
* // promises
* const [p1, p2, p3] = [[1, 2], 3, [4, [5, 6]]].map(v => Promise.resolve(v));
*
* AsyncAF(p1).concatAF(p2); // Promise that resolves to [1, 2, 3]
* AsyncAF(p1).concatAF(p2, p3) // Promise that resolves to [1, 2, 3, 4, [5, 6]]
*
* const pStr1 = Promise.resolve('str');
* const pStr2 = Promise.resolve('ing');
* const pStr3 = Promise.resolve('y');
*
* AsyncAF(pStr1).concatAF(pStr2); // Promise that resolves to 'string'
* AsyncAF(pStr1).concatAF(pStr2, pStr3); // Promise that resolves to 'stringy'
*
* // Note: concatAF will not resolve deeply nested promises; if you need this behavior, concatAF can be used in a
* // function; for example, this function recursively flattens an array of promises
*
* const flattenAsync = arr => AsyncAF(arr).reduceAF(async (acc, val) => {
* return Array.isArray(await val)
* ? AsyncAF(acc).concatAF(flattenAsync(val))
* : AsyncAF(acc).concatAF(val), []);
* };
*
* @since 5.3.0
* @see concat (alias)
* @memberof AsyncAF#
*/
var concatAF = function concatAF() {
var _this = this;
for (var _len = arguments.length, values = new Array(_len), _key = 0; _key < _len; _key++) {
values[_key] = arguments[_key];
}
var isThenable = function isThenable(value) {
return [Promise, _this.constructor].some(function (thenable) {
return value instanceof thenable;
});
};
var concat = function concat(arrOrStr, value) {
return isThenable(value) && value.then(resolveByType).then(function (value) {
return arrOrStr.concat(value);
}) || arrOrStr.concat(value);
};
return this.then(function (arrOrStr) {
if (!(typeof arrOrStr === 'string' || Array.isArray(arrOrStr))) throw TypeError("concatAF cannot be called on ".concat(arrOrStr, ", only on an Array or String"));
return resolveByType(arrOrStr).then(function (arrOrStr) {
return values.reduce(function (arrOrStr, value) {
return isThenable(arrOrStr) ? arrOrStr.then(function (arrOrStr) {
return concat(arrOrStr, value);
}) : concat(arrOrStr, value);
}, arrOrStr);
});
});
};
/* harmony default export */ __webpack_exports__["default"] = (concatAF);
/***/ }),
/***/ "./lib/methods/arrays/everyAF.js":
/***/ (function(module, __webpack_exports__, __webpack_require__) {
"use strict";
__webpack_require__.r(__webpack_exports__);
/* harmony import */ var _internal_commonCallback__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__("./lib/methods/_internal/commonCallback.js");
/* harmony import */ var _internal_permissiveIsArrayLike__WEBPACK_IMPORTED_MODULE_1__ = __webpack_require__("./lib/methods/_internal/permissiveIsArrayLike.js");
/* harmony import */ var _internal_resolve__WEBPACK_IMPORTED_MODULE_2__ = __webpack_require__("./lib/methods/_internal/resolve.js");
// eslint-disable-line no-unused-vars
/**
* tests whether all elements in the array pass the test implemented by the provided callback function
*
* if any elements are a `Promise`, they will first be resolved in parallel and then tested
*
* *Note*: since `everyAF` is run in parallel, `callback` will be run on all elements even if one of the first few elements fails the test; if this behavior is not desireable, consider using `series.everyAF` or its alias, `io.everyAF`
*
* @param {callback} callback function that tests each element of the array
*
* `callback` accepts three arguments:
* - `currentValue` value of the current element being processed in the array
* - `index`*`(optional)`* index of `currentValue` in the array
* - `array`*`(optional)`* the array that `everyAF` is being applied to
* @param {Object=} thisArg value to use as `this` when executing `callback`
* @returns {Promise.<Boolean>} `Promise` that resolves to `true` if the callback function returns a truthy value for every array element; otherwise, `false`
* @example
*
* const promises = [1, 2, 3].map(n => Promise.resolve(n));
*
*
* // basic usage
* const allAreOdd = AsyncAF(promises).everyAF(n => n % 2);
*
* console.log(allAreOdd); // Promise that resolves to false
*
* AsyncAF.logAF(allAreOdd); // logs false
*
*
* // using .then
* AsyncAF(promises).everyAF(n => n % 2).then(allAreOdd => {
* console.log(allAreOdd); // logs false
* });
*
*
* // inside an async function
* (async () => {
* const allAreNums = await AsyncAF(promises).everyAF(
* n => typeof n === 'number'
* );
* console.log(allAreNums); // logs true
* })();
* @since 3.2.0
* @see every (alias)
* @see {@link AsyncAF#series series.everyAF}
* @memberof AsyncAF#
*/
var everyAF = function everyAF(callback) {
var _this = this;
var thisArg = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : undefined;
return this.then(function (arr) {
if (!Object(_internal_permissiveIsArrayLike__WEBPACK_IMPORTED_MODULE_1__["default"])(arr)) throw TypeError("everyAF cannot be called on ".concat(arr, ", only on an Array or array-like Object"));
if (typeof callback !== 'function') throw TypeError("".concat(callback, " is not a function"));
var length = arr.length >>> 0;
return _this.inSeries ? !length && true || function seriesEveryAF(arr, i) {
var hole = !(i in arr);
return Promise.resolve(arr[i]).then(function (el) {
arr[i] = el;
return Promise.resolve(!hole && callback.call(thisArg, el, i, arr)).then(function (bool) {
if (!bool && !hole) return false;
if (i === length - 1) return true;
return seriesEveryAF(arr, i + 1);
});
});
}(Array.prototype.slice.call(arr), 0) : Object(_internal_resolve__WEBPACK_IMPORTED_MODULE_2__["parallel"])(arr, callback, thisArg).then(function (bools) {
return bools.every(Boolean);
});
});
};
/* harmony default export */ __webpack_exports__["default"] = (everyAF);
/***/ }),
/***/ "./lib/methods/arrays/filterAF.js":
/***/ (function(module, __webpack_exports__, __webpack_require__) {
"use strict";
__webpack_require__.r(__webpack_exports__);
/* harmony import */ var _internal_commonCallback__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__("./lib/methods/_internal/commonCallback.js");
/* harmony import */ var _internal_permissiveIsArrayLike__WEBPACK_IMPORTED_MODULE_1__ = __webpack_require__("./lib/methods/_internal/permissiveIsArrayLike.js");
/* harmony import */ var _internal_resolve__WEBPACK_IMPORTED_MODULE_2__ = __webpack_require__("./lib/methods/_internal/resolve.js");
// eslint-disable-line no-unused-vars
/**
* creates a new `Array` with all elements that pass the test implemented by the provided callback function
*
* if any elements are a `Promise`, they will first be resolved in parallel and then tested
*
* *Note*: if you'd rather resolve and test elements in series, consider using `series.filterAF` or its alias, `io.filterAF`
*
* @param {callback} callback function that tests each element of the array; return `true` to keep the element, `false` to filter it out
*
* `callback` accepts three arguments:
* - `currentValue` value of the current element being processed in the array
* - `index`*`(optional)`* index of `currentValue` in the array
* - `array`*`(optional)`* the array that `filterAF` is being applied to
* @param {Object=} thisArg value to use as `this` when executing `callback`
* @returns {Promise.<Array>} `Promise` that resolves to a new `Array` with the elements that pass the test; if no elements pass the test, the promise will resolve to an empty array
* @example
*
* const promises = [1, 2, 3].map(n => Promise.resolve(n));
*
*
* // basic usage
* const odds = AsyncAF(promises).filterAF(n => n % 2);
*
* console.log(odds); // Promise that resolves to [1, 3]
*
* AsyncAF.logAF(odds); // logs [1, 3]
*
*
* // using .then
* AsyncAF(promises).filterAF(n => n % 2).then(odds => {
* console.log(odds); // logs [1, 3]
* });
*
*
* // inside an async function
* (async () => {
* const odds = await AsyncAF(promises).filterAF(
* n => n % 2
* );
* console.log(odds); // logs [1, 3]
* })();
* @since 3.0.0
* @see filter (alias)
* @see {@link AsyncAF#series series.filterAF}
* @memberof AsyncAF#
*/
var filterAF = function filterAF(callback) {
var _this = this;
var thisArg = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : undefined;
return this.then(function (arr) {
if (!Object(_internal_permissiveIsArrayLike__WEBPACK_IMPORTED_MODULE_1__["default"])(arr)) throw TypeError("filterAF cannot be called on ".concat(arr, ", only on an Array or array-like Object"));
if (typeof callback !== 'function') throw TypeError("".concat(callback, " is not a function"));
return (_this.inSeries ? _internal_resolve__WEBPACK_IMPORTED_MODULE_2__["serial"] : _internal_resolve__WEBPACK_IMPORTED_MODULE_2__["parallel"])(arr).then(function (arr) {
return (_this.inSeries ? arr.reduce(function (bools, el, i, arr) {
return bools.then(function (bools) {
bools[i] = callback.call(thisArg, el, i, arr);
return Promise.all(bools);
});
}, Promise.all([])) : Object(_internal_resolve__WEBPACK_IMPORTED_MODULE_2__["parallel"])(arr, callback, thisArg)).then(function (bools) {
return arr.filter(function (_, i) {
return bools[i];
});
});
});
});
};
/* harmony default export */ __webpack_exports__["default"] = (filterAF);
/***/ }),
/***/ "./lib/methods/arrays/findAF.js":
/***/ (function(module, __webpack_exports__, __webpack_require__) {
"use strict";
__webpack_require__.r(__webpack_exports__);
/* harmony import */ var _internal_commonCallback__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__("./lib/methods/_internal/commonCallback.js");
/* harmony import */ var _internal_permissiveIsArrayLike__WEBPACK_IMPORTED_MODULE_1__ = __webpack_require__("./lib/methods/_internal/permissiveIsArrayLike.js");
/* harmony import */ var _internal_resolve__WEBPACK_IMPORTED_MODULE_2__ = __webpack_require__("./lib/methods/_internal/resolve.js");
// eslint-disable-line no-unused-vars
/**
* resolves to the value of the first element in the array that satisfies the provided callback function; otherwise, `undefined`
*
* *Note*: since `findAF` is run in parallel, `callback` will be run on all elements even if one of the first few elements passes the test; if this behavior is not desireable, consider using `series.findAF` or its alias, `io.findAF`
*
* @param {callback} callback function to test each element in the array
*
* `callback` accepts three arguments:
* - `currentValue` value of the current element being processed in the array
* - `index`*`(optional)`* index of `currentValue` in the array
* - `array`*`(optional)`* the array that findAF is being applied to
* @param {Object=} thisArg value to use as `this` when executing `callback`
* @returns {Promise.<any>} `Promise` that resolves to the first element in the array that passes the test; otherwise, undefined
* @example
*
* const inventory = [
* {name: 'nuts', quantity: 2000},
* {name: 'bolts', quantity: 5000},
* {name: 'screws', quantity: 9001}
* ].map(part => Promise.resolve(part));
*
* AsyncAF(inventory).findAF(part => part.name === 'screws');
* // Promise that resolves to {name: 'screws', quantity: 9001}
* @since 3.5.0
* @see find (alias)
* @see {@link AsyncAF#series series.findAF}
* @memberof AsyncAF#
*/
var findAF = function findAF(callback) {
var _this = this;
var thisArg = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : undefined;
return this.then(function (arr) {
if (!Object(_internal_permissiveIsArrayLike__WEBPACK_IMPORTED_MODULE_1__["default"])(arr)) throw TypeError("findAF cannot be called on ".concat(arr, ", only on an Array or array-like Object"));
if (typeof callback !== 'function') throw TypeError("".concat(callback, " is not a function"));
var filled = Array.from(arr);
var length = filled.length >>> 0;
return _this.inSeries ? (length || undefined) && function seriesFindAF(arr, i) {
return Promise.resolve(arr[i]).then(function (el) {
arr[i] = el;
return Promise.resolve(callback.call(thisArg, el, i, arr)).then(function (bool) {
if (bool) return el;
if (i === length - 1) return;
return seriesFindAF(arr, i + 1);
});
});
}(filled, 0) : Object(_internal_resolve__WEBPACK_IMPORTED_MODULE_2__["parallel"])(filled, callback, thisArg).then(function (bools) {
return arr[bools.indexOf(true)];
});
});
};
/* harmony default export */ __webpack_exports__["default"] = (findAF);
/***/ }),
/***/ "./lib/methods/arrays/findIndexAF.js":
/***/ (function(module, __webpack_exports__, __webpack_require__) {
"use strict";
__webpack_require__.r(__webpack_exports__);
/* harmony import */ var _internal_commonCallback__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__("./lib/methods/_internal/commonCallback.js");
/* harmony import */ var _internal_permissiveIsArrayLike__WEBPACK_IMPORTED_MODULE_1__ = __webpack_require__("./lib/methods/_internal/permissiveIsArrayLike.js");
/* harmony import */ var _internal_resolve__WEBPACK_IMPORTED_MODULE_2__ = __webpack_require__("./lib/methods/_internal/resolve.js");
// eslint-disable-line no-unused-vars
/**
* resolves to the index of the first element in the array that satisfies the provided callback function; otherwise, `-1`
*
* *Note*: since `findIndexAF` is run in parallel, `callback` will be run on all indices even if one of the first few indices passes the test; if this behavior is not desireable, consider using `series.findIndexAF` or its alias, `io.findIndexAF`
*
* @param {callback} callback function to test each element in the array
*
* `callback` accepts three arguments:
* - `currentValue` value of the current element being processed in the array
* - `index`*`(optional)`* index of `currentValue` in the array
* - `array`*`(optional)`* the array that findIndexAF is being applied to
* @param {Object=} thisArg value to use as `this` when executing `callback`
* @returns {Promise.<Number>} `Promise` that resolves to the index of the first element in the array that passes the test; otherwise, `-1`
* @example
*
* const inventory = [
* {name: 'nuts', quantity: 2000},
* {name: 'bolts', quantity: 5000},
* {name: 'screws', quantity: 9001}
* ].map(part => Promise.resolve(part));
*
* AsyncAF(inventory).findIndexAF(part => part.name === 'screws');
* // Promise that resolves to 2
* @since 3.5.0
* @see findIndex (alias)
* @see {@link AsyncAF#series series.findIndexAF}
* @memberof AsyncAF#
*/
var findIndexAF = function findIndexAF(callback) {
var _this = this;
var thisArg = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : undefined;
return this.then(function (arr) {
if (!Object(_internal_permissiveIsArrayLike__WEBPACK_IMPORTED_MODULE_1__["default"])(arr)) throw TypeError("findIndexAF cannot be called on ".concat(arr, ", only on an Array or array-like Object"));
if (typeof callback !== 'function') throw TypeError("".concat(callback, " is not a function"));
var filled = Array.from(arr);
var length = filled.length >>> 0;
return _this.inSeries ? !length && -1 || function seriesFindIndexAF(arr, i) {
return Promise.resolve(arr[i]).then(function (el) {
arr[i] = el;
return Promise.resolve(callback.call(thisArg, el, i, arr)).then(function (bool) {
if (bool) return i;
if (i === length - 1) return -1;
return seriesFindIndexAF(arr, i + 1);
});
});
}(filled, 0) : Object(_internal_resolve__WEBPACK_IMPORTED_MODULE_2__["parallel"])(filled, callback, thisArg).then(function (bools) {
return bools.indexOf(true);
});
});
};
/* harmony default export */ __webpack_exports__["default"] = (findIndexAF);
/***/ }),
/***/ "./lib/methods/arrays/forEachAF.js":
/***/ (function(module, __webpack_exports__, __webpack_require__) {
"use strict";
__webpack_require__.r(__webpack_exports__);
/* harmony import */ var _internal_commonCallback__WEBPACK_IMPORTE