1 | /*!
|
2 | * async-af v7.0.39
|
3 | *
|
4 | * AsyncAF (The asynciest of async libs there ever was or ever will be...AsyncAF!?)
|
5 | * (https://async-af.js.org/AsyncAF)
|
6 | *
|
7 | * Copyright (c) 2017-present, Scott Rudiger (https://github.com/ScottRudiger)
|
8 | *
|
9 | * This source code is licensed under the MIT license found in this library's
|
10 | * GitHub repository (https://github.com/AsyncAF/AsyncAF/blob/master/LICENSE).
|
11 | */
|
12 | (function webpackUniversalModuleDefinition(root, factory) {
|
13 | if(typeof exports === 'object' && typeof module === 'object')
|
14 | module.exports = factory();
|
15 | else if(typeof define === 'function' && define.amd)
|
16 | define("AsyncAF", [], factory);
|
17 | else if(typeof exports === 'object')
|
18 | exports["AsyncAF"] = factory();
|
19 | else
|
20 | root["AsyncAF"] = factory();
|
21 | })(typeof self !== 'undefined' ? self : this, function() {
|
22 | return /******/ (function(modules) { // webpackBootstrap
|
23 | /******/ // The module cache
|
24 | /******/ var installedModules = {};
|
25 | /******/
|
26 | /******/ // The require function
|
27 | /******/ function __webpack_require__(moduleId) {
|
28 | /******/
|
29 | /******/ // Check if module is in cache
|
30 | /******/ if(installedModules[moduleId]) {
|
31 | /******/ return installedModules[moduleId].exports;
|
32 | /******/ }
|
33 | /******/ // Create a new module (and put it into the cache)
|
34 | /******/ var module = installedModules[moduleId] = {
|
35 | /******/ i: moduleId,
|
36 | /******/ l: false,
|
37 | /******/ exports: {}
|
38 | /******/ };
|
39 | /******/
|
40 | /******/ // Execute the module function
|
41 | /******/ modules[moduleId].call(module.exports, module, module.exports, __webpack_require__);
|
42 | /******/
|
43 | /******/ // Flag the module as loaded
|
44 | /******/ module.l = true;
|
45 | /******/
|
46 | /******/ // Return the exports of the module
|
47 | /******/ return module.exports;
|
48 | /******/ }
|
49 | /******/
|
50 | /******/
|
51 | /******/ // expose the modules object (__webpack_modules__)
|
52 | /******/ __webpack_require__.m = modules;
|
53 | /******/
|
54 | /******/ // expose the module cache
|
55 | /******/ __webpack_require__.c = installedModules;
|
56 | /******/
|
57 | /******/ // define getter function for harmony exports
|
58 | /******/ __webpack_require__.d = function(exports, name, getter) {
|
59 | /******/ if(!__webpack_require__.o(exports, name)) {
|
60 | /******/ Object.defineProperty(exports, name, { enumerable: true, get: getter });
|
61 | /******/ }
|
62 | /******/ };
|
63 | /******/
|
64 | /******/ // define __esModule on exports
|
65 | /******/ __webpack_require__.r = function(exports) {
|
66 | /******/ if(typeof Symbol !== 'undefined' && Symbol.toStringTag) {
|
67 | /******/ Object.defineProperty(exports, Symbol.toStringTag, { value: 'Module' });
|
68 | /******/ }
|
69 | /******/ Object.defineProperty(exports, '__esModule', { value: true });
|
70 | /******/ };
|
71 | /******/
|
72 | /******/ // create a fake namespace object
|
73 | /******/ // mode & 1: value is a module id, require it
|
74 | /******/ // mode & 2: merge all properties of value into the ns
|
75 | /******/ // mode & 4: return value when already ns object
|
76 | /******/ // mode & 8|1: behave like require
|
77 | /******/ __webpack_require__.t = function(value, mode) {
|
78 | /******/ if(mode & 1) value = __webpack_require__(value);
|
79 | /******/ if(mode & 8) return value;
|
80 | /******/ if((mode & 4) && typeof value === 'object' && value && value.__esModule) return value;
|
81 | /******/ var ns = Object.create(null);
|
82 | /******/ __webpack_require__.r(ns);
|
83 | /******/ Object.defineProperty(ns, 'default', { enumerable: true, value: value });
|
84 | /******/ if(mode & 2 && typeof value != 'string') for(var key in value) __webpack_require__.d(ns, key, function(key) { return value[key]; }.bind(null, key));
|
85 | /******/ return ns;
|
86 | /******/ };
|
87 | /******/
|
88 | /******/ // getDefaultExport function for compatibility with non-harmony modules
|
89 | /******/ __webpack_require__.n = function(module) {
|
90 | /******/ var getter = module && module.__esModule ?
|
91 | /******/ function getDefault() { return module['default']; } :
|
92 | /******/ function getModuleExports() { return module; };
|
93 | /******/ __webpack_require__.d(getter, 'a', getter);
|
94 | /******/ return getter;
|
95 | /******/ };
|
96 | /******/
|
97 | /******/ // Object.prototype.hasOwnProperty.call
|
98 | /******/ __webpack_require__.o = function(object, property) { return Object.prototype.hasOwnProperty.call(object, property); };
|
99 | /******/
|
100 | /******/ // __webpack_public_path__
|
101 | /******/ __webpack_require__.p = "";
|
102 | /******/
|
103 | /******/
|
104 | /******/ // Load entry module and return exports
|
105 | /******/ return __webpack_require__(__webpack_require__.s = "./lib/classes/AsyncAF.js");
|
106 | /******/ })
|
107 | /************************************************************************/
|
108 | /******/ ({
|
109 |
|
110 | /***/ "./lib/classes/AsyncAF.js":
|
111 | /***/ (function(module, __webpack_exports__, __webpack_require__) {
|
112 |
|
113 | ;
|
114 |
|
115 | // EXTERNAL MODULE: ./lib/methods/_internal/createNewlessClass.js
|
116 | var createNewlessClass = __webpack_require__("./lib/methods/_internal/createNewlessClass.js");
|
117 |
|
118 | // EXTERNAL MODULE: ./lib/classes/AsyncAfWrapper.js + 2 modules
|
119 | var AsyncAfWrapper = __webpack_require__("./lib/classes/AsyncAfWrapper.js");
|
120 |
|
121 | // EXTERNAL MODULE: ./lib/methods/_internal/nameFunction.js
|
122 | var nameFunction = __webpack_require__("./lib/methods/_internal/nameFunction.js");
|
123 |
|
124 | // EXTERNAL MODULE: ./lib/methods/other/logAF.js + 4 modules
|
125 | var logAF = __webpack_require__("./lib/methods/other/logAF.js");
|
126 |
|
127 | // EXTERNAL MODULE: ./lib/methods/arrays/mapAF.js
|
128 | var mapAF = __webpack_require__("./lib/methods/arrays/mapAF.js");
|
129 |
|
130 | // EXTERNAL MODULE: ./lib/methods/arrays/forEachAF.js
|
131 | var forEachAF = __webpack_require__("./lib/methods/arrays/forEachAF.js");
|
132 |
|
133 | // EXTERNAL MODULE: ./lib/methods/arrays/filterAF.js
|
134 | var filterAF = __webpack_require__("./lib/methods/arrays/filterAF.js");
|
135 |
|
136 | // EXTERNAL MODULE: ./lib/methods/arrays/reduceAF.js + 1 modules
|
137 | var reduceAF = __webpack_require__("./lib/methods/arrays/reduceAF.js");
|
138 |
|
139 | // EXTERNAL MODULE: ./lib/methods/arrays/everyAF.js
|
140 | var everyAF = __webpack_require__("./lib/methods/arrays/everyAF.js");
|
141 |
|
142 | // EXTERNAL MODULE: ./lib/methods/arrays/someAF.js
|
143 | var someAF = __webpack_require__("./lib/methods/arrays/someAF.js");
|
144 |
|
145 | // EXTERNAL MODULE: ./lib/methods/arrays/includesAF.js
|
146 | var includesAF = __webpack_require__("./lib/methods/arrays/includesAF.js");
|
147 |
|
148 | // EXTERNAL MODULE: ./lib/methods/arrays/findAF.js
|
149 | var findAF = __webpack_require__("./lib/methods/arrays/findAF.js");
|
150 |
|
151 | // EXTERNAL MODULE: ./lib/methods/arrays/findIndexAF.js
|
152 | var findIndexAF = __webpack_require__("./lib/methods/arrays/findIndexAF.js");
|
153 |
|
154 | // EXTERNAL MODULE: ./lib/methods/arrays/indexOfAF.js
|
155 | var indexOfAF = __webpack_require__("./lib/methods/arrays/indexOfAF.js");
|
156 |
|
157 | // EXTERNAL MODULE: ./lib/methods/arrays/lastIndexOfAF.js
|
158 | var lastIndexOfAF = __webpack_require__("./lib/methods/arrays/lastIndexOfAF.js");
|
159 |
|
160 | // EXTERNAL MODULE: ./lib/methods/arrays/joinAF.js
|
161 | var joinAF = __webpack_require__("./lib/methods/arrays/joinAF.js");
|
162 |
|
163 | // EXTERNAL MODULE: ./lib/methods/arrays/concatAF.js
|
164 | var concatAF = __webpack_require__("./lib/methods/arrays/concatAF.js");
|
165 |
|
166 | // EXTERNAL MODULE: ./lib/methods/strings/splitAF.js
|
167 | var splitAF = __webpack_require__("./lib/methods/strings/splitAF.js");
|
168 |
|
169 | // CONCATENATED MODULE: ./packageList.js
|
170 |
|
171 | /* eslint-disable import/first */
|
172 |
|
173 | const libName = 'async-af';
|
174 | const libPath = './lib/';
|
175 |
|
176 | const makeScoped = name => "@".concat(libName, "/").concat(name.replace(/AsyncAf|AF/g, '').toLowerCase());
|
177 | /* ____________________________
|
178 | | CLASSES |
|
179 | |____________________________| */
|
180 |
|
181 |
|
182 | const classPath = "".concat(libPath, "classes/");
|
183 | const classes = [[{
|
184 | name: 'AsyncAF'
|
185 | }, "".concat(classPath, "AsyncAF"), libName], [{
|
186 | name: 'AsyncAfWrapper'
|
187 | }, "".concat(classPath, "AsyncAfWrapper"), makeScoped('AsyncAfWrapper')]];
|
188 | /* ____________________________
|
189 | | STATIC METHODS |
|
190 | |____________________________| */
|
191 |
|
192 |
|
193 | const staticMethods = [Object(nameFunction["default"])(logAF["default"], 'logAF')].map(method => [method, "".concat(libPath, "methods/other/").concat(method.name), makeScoped(method.name)]);
|
194 | /* ____________________________
|
195 | | PROTOTYPE METHODS |
|
196 | |____________________________| */
|
197 | // Arrays
|
198 |
|
199 |
|
200 |
|
201 |
|
202 |
|
203 |
|
204 |
|
205 |
|
206 |
|
207 |
|
208 |
|
209 |
|
210 |
|
211 |
|
212 | const 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(method => [method, "".concat(libPath, "methods/arrays/").concat(method.name), makeScoped(method.name)]); // strings
|
213 |
|
214 |
|
215 | const stringMethods = [Object(nameFunction["default"])(splitAF["default"], 'splitAF')].map(method => [method, "".concat(libPath, "methods/strings/").concat(method.name), makeScoped(method.name)]);
|
216 | const prototypeMethods = [...arrayMethods, ...stringMethods];
|
217 | /* ____________________________
|
218 | | COLLECTIONS |
|
219 | |____________________________| */
|
220 | // import arrays from './lib/collections/arrays';
|
221 |
|
222 | const collections = [// arrays,
|
223 | ];
|
224 | /* harmony default export */ var packageList = ([...classes, ...staticMethods, ...prototypeMethods, ...collections]);
|
225 |
|
226 | const pluckMethods = packages => packages.map((_ref) => {
|
227 | let [method] = _ref;
|
228 | return method;
|
229 | });
|
230 |
|
231 | const staticMethodsOnly = pluckMethods(staticMethods);
|
232 | const prototypeMethodsOnly = pluckMethods(prototypeMethods);
|
233 |
|
234 | // CONCATENATED MODULE: ./lib/classes/AsyncAF.js
|
235 | function _templateObject() {
|
236 | const data = _taggedTemplateLiteral(["AF"]);
|
237 |
|
238 | _templateObject = function _templateObject() {
|
239 | return data;
|
240 | };
|
241 |
|
242 | return data;
|
243 | }
|
244 |
|
245 | function _taggedTemplateLiteral(strings, raw) { if (!raw) { raw = strings.slice(0); } return Object.freeze(Object.defineProperties(strings, { raw: { value: Object.freeze(raw) } })); }
|
246 |
|
247 |
|
248 |
|
249 |
|
250 | /**
|
251 | * class that holds all the AsyncAF methods
|
252 | *
|
253 | * while AsyncAF is a class, it can create instances with or without the `new` keyword
|
254 | * @param {any} data the data to be wrapped by the AsyncAF class; can be promises or non-promises
|
255 | * @returns {Object} returns an instance of AsyncAF wrapping the passed in data
|
256 | * @example
|
257 | *
|
258 | * const promises = [1, 2, 3].map(n => Promise.resolve(n));
|
259 | *
|
260 | *
|
261 | * AsyncAF(promises).mapAF(n => n * 2).filterAF(n => n !== 4).forEachAF(n => console.log(n));
|
262 | * // logs 2 then 6
|
263 | * @since 3.0.0
|
264 | * @see AsyncAfWrapper
|
265 | * @class AsyncAF
|
266 | */
|
267 |
|
268 | const AsyncAF_AsyncAF = Object(createNewlessClass["default"])(class AsyncAF extends AsyncAfWrapper["AsyncAfWrapperProto"] {});
|
269 |
|
270 | const prepForDefine = methods => methods.reduce((methods, method) => {
|
271 | // add all '*AF' methods and add 'AF-less' aliases (e.g., mapAF -> map)
|
272 | const [alias] = method.name.split(_templateObject()) ||
|
273 | /* istanbul ignore next */
|
274 | [method.name];
|
275 | return Object.assign(methods, {
|
276 | [method.name]: {
|
277 | value: method
|
278 | }
|
279 | }, {
|
280 | [alias]: {
|
281 | value: method
|
282 | }
|
283 | });
|
284 | }, {});
|
285 |
|
286 | Object.defineProperties(AsyncAfWrapper["AsyncAfWrapperProto"], prepForDefine(staticMethodsOnly));
|
287 | Object.defineProperties(AsyncAfWrapper["AsyncAfWrapperProto"].prototype, prepForDefine(prototypeMethodsOnly));
|
288 | /* harmony default export */ var classes_AsyncAF = __webpack_exports__["default"] = (AsyncAF_AsyncAF);
|
289 |
|
290 | /***/ }),
|
291 |
|
292 | /***/ "./lib/classes/AsyncAfWrapper.js":
|
293 | /***/ (function(module, __webpack_exports__, __webpack_require__) {
|
294 |
|
295 | ;
|
296 |
|
297 | // EXTERNAL MODULE: ./lib/methods/_internal/createNewlessClass.js
|
298 | var createNewlessClass = __webpack_require__("./lib/methods/_internal/createNewlessClass.js");
|
299 |
|
300 | // CONCATENATED MODULE: ./lib/methods/other/use.js
|
301 | /**
|
302 | * adds prototype/static methods to AsyncAF or AsyncAfWrapper
|
303 | *
|
304 | * 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;
|
305 | *
|
306 | * for something different, the following shows how to add custom methods to AsyncAF & AsyncAfWrapper
|
307 | *
|
308 | * **Example**
|
309 | *
|
310 | * 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
|
311 | *
|
312 | * let's call it sumAF; here's some code:
|
313 | *
|
314 | * ```js
|
315 | * // sumAF.js
|
316 | *
|
317 | * const sumAF = function () {
|
318 | * return this.then(nums => Promise.all(nums))
|
319 | * .then(nums => nums.reduce((sum, num) => sum + num));
|
320 | * };
|
321 | *
|
322 | * export default sumAF;
|
323 | * ```
|
324 | *
|
325 | * pull in {@link AsyncAF AsyncAF} or {@link AsyncAfWrapper AsyncAfWrapper} and `sumAF` to the file you'd like to use it in:
|
326 | *
|
327 | * ```js
|
328 | * // otherFile.js
|
329 | *
|
330 | * import AsyncAF from 'async-af'; // or import AsyncAF from '@async-af/wrapper';
|
331 | * import sumAF from './sumAF';
|
332 | * ```
|
333 | *
|
334 | * then, call `use` on `AsyncAF` and pass in `sumAF` wrapped in an object to the first parameter, `prototypeMethods`:
|
335 | *
|
336 | * ```js
|
337 | * // otherFile.js
|
338 | * // ...
|
339 | *
|
340 | * AsyncAF.use({sumAF});
|
341 | * ```
|
342 | *
|
343 | * ready! now your custom prototype method will be available on AsyncAF
|
344 | *
|
345 | * ```js
|
346 | * // otherFile.js
|
347 | * // ...
|
348 | *
|
349 | * const promises = [1, 2, 3].map(n => Promise.resolve(n));
|
350 | *
|
351 | * const sum = AsyncAF(promises).sumAF()
|
352 | *
|
353 | * AsyncAF.logAF(sum);
|
354 | * // @otherFile.js:10:9:
|
355 | * // 6
|
356 | * // in 0.001 secs
|
357 | * ```
|
358 | *
|
359 | * if you'd like to add a static method to AsyncAF, `use` accepts a second optional argument `staticMethods`; for example:
|
360 | *
|
361 | * ```js
|
362 | * const staticNoop = () => {};
|
363 | *
|
364 | * AsyncAF.use({}, {staticNoop});
|
365 | *
|
366 | * AsyncAF.staticNoop(); // noop
|
367 | * ```
|
368 | *
|
369 | * @static
|
370 | * @param {Object} prototypeMethods an Object containing the prototype methods you'd like to use
|
371 | * @param {Object=} staticMethods an Object containing the static methods you'd like to use
|
372 | * @returns {undefined} adds prototype/static methods to AsyncAF or AsyncAfWrapper
|
373 | * @since 3.0.0
|
374 | * @see AsyncAF
|
375 | * @see AsyncAfWrapper
|
376 | * @see {@tutorial TOO_MANY_IMPORTS}
|
377 | * @memberof AsyncAfWrapper
|
378 | * @alias AsyncAfWrapper#use
|
379 | */
|
380 | const use = function use(prototypeMethods) {
|
381 | let staticMethods = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {};
|
382 | if (typeof 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');
|
383 | if (typeof staticMethods !== 'object') throw TypeError('staticMethods param accepts an Object containing the staticMethods you\'d like to add to AsyncAF');
|
384 | Object.assign(this.prototype, prototypeMethods);
|
385 | Object.assign(this, staticMethods);
|
386 | };
|
387 |
|
388 | /* harmony default export */ var other_use = (use);
|
389 | // CONCATENATED MODULE: ./lib/methods/other/series.js
|
390 | const inSeries = new WeakMap();
|
391 | const series = {
|
392 | inSeries: {
|
393 | get() {
|
394 | return inSeries.get(this);
|
395 | }
|
396 |
|
397 | },
|
398 |
|
399 | /**
|
400 | * indicates that the next method invoked should be performed in series
|
401 | *
|
402 | * when you need to perform a method in series rather than in parallel, prepend the method with `series`; e.g.:
|
403 | * ```js
|
404 | * AsyncAF(promises).series.forEachAF(callback)
|
405 | * ```
|
406 | *
|
407 | * `series` can currently be chained with:
|
408 | * - {@link AsyncAF#everyAF everyAF}
|
409 | * - {@link AsyncAF#filterAF filterAF}
|
410 | * - {@link AsyncAF#findAF findAF}
|
411 | * - {@link AsyncAF#findIndexAF findIndexAF}
|
412 | * - {@link AsyncAF#forEachAF forEachAF}
|
413 | * - {@link AsyncAF#includesAF includesAF}
|
414 | * - {@link AsyncAF#indexOfAF indexOfAF}
|
415 | * - {@link AsyncAF#lastIndexOfAF lastIndexOfAF}
|
416 | * - {@link AsyncAF#mapAF mapAF}
|
417 | * - {@link AsyncAF#reduceAF reduceAF}
|
418 | * - {@link AsyncAF#someAF someAF}
|
419 | *
|
420 | * @example
|
421 | * import delay from 'delay'; // {@link https://www.npmjs.com/package/delay}
|
422 | *
|
423 | * const nums = [2, 1];
|
424 | *
|
425 | * // perform a serial forEach by chaining {@link AsyncAF#series series} and {@link AsyncAF#forEachAF forEachAF}
|
426 | * (async () => {
|
427 | * const start = Date.now();
|
428 | *
|
429 | * await AsyncAF(nums).series.forEachAF(async num => {
|
430 | * await delay(num * 1000);
|
431 | * console.log(num, `at ~${Date.now() - start} ms`);
|
432 | * });
|
433 | *
|
434 | * console.log(`total: ~${Date.now() - start} ms`);
|
435 | * })();
|
436 | *
|
437 | * // logs:
|
438 | * // 2 'at ~2000 ms'
|
439 | * // 1 'at ~3000 ms'
|
440 | * // total: ~3000 ms
|
441 | *
|
442 | *
|
443 | * // perform a parallel forEach by omitting {@link AsyncAF#series series}
|
444 | * (async () => {
|
445 | * const start = Date.now();
|
446 | *
|
447 | * await AsyncAF(nums).forEachAF(async num => {
|
448 | * await delay(num * 1000);
|
449 | * console.log(num, `at ~${Date.now() - start} ms`);
|
450 | * });
|
451 | *
|
452 | * console.log(`total: ~${Date.now() - start} ms`);
|
453 | * })();
|
454 | *
|
455 | * // logs:
|
456 | * // 1 'at ~1000 ms'
|
457 | * // 2 'at ~2000 ms'
|
458 | * // total: ~2000 ms
|
459 | *
|
460 | * @function series
|
461 | * @returns {AsyncAF.<any>} returns an instance of AsyncAF that will perform the next method invocation serially
|
462 | * @since 7.0.0
|
463 | * @see {@link AsyncAF#io io} (alias)
|
464 | * @memberof AsyncAF#
|
465 | */
|
466 | series: {
|
467 | get() {
|
468 | inSeries.set(this, !this.inSeries);
|
469 | return this;
|
470 | }
|
471 |
|
472 | },
|
473 |
|
474 | /**
|
475 | * `io` (in order) indicates that the next method invoked should be performed in series
|
476 | *
|
477 | * when you need to perform a method in series rather than in parallel, prepend the method with `io`; e.g.:
|
478 | * ```js
|
479 | * AsyncAF(promises).io.forEachAF(callback)
|
480 | * ```
|
481 | *
|
482 | * `io` is an alias for `series`; see {@link AsyncAF#series series's documentation} for more
|
483 | * @function io
|
484 | * @returns {AsyncAF.<any>} returns an instance of AsyncAF that will perform the next method invocation serially
|
485 | * @since 7.0.0
|
486 | * @see {@link AsyncAF#series series} (alias)
|
487 | * @memberof AsyncAF#
|
488 | */
|
489 | io: {
|
490 | get() {
|
491 | return this.series;
|
492 | }
|
493 |
|
494 | }
|
495 | };
|
496 | /* harmony default export */ var other_series = (series);
|
497 | // CONCATENATED MODULE: ./lib/classes/AsyncAfWrapper.js
|
498 | /* harmony export (binding) */ __webpack_require__.d(__webpack_exports__, "AsyncAfWrapperProto", function() { return AsyncAfWrapperProto; });
|
499 | function _objectSpread(target) { for (var i = 1; i < arguments.length; i++) { var source = arguments[i] != null ? arguments[i] : {}; var ownKeys = Object.keys(source); if (typeof Object.getOwnPropertySymbols === 'function') { ownKeys = ownKeys.concat(Object.getOwnPropertySymbols(source).filter(function (sym) { return Object.getOwnPropertyDescriptor(source, sym).enumerable; })); } ownKeys.forEach(function (key) { _defineProperty(target, key, source[key]); }); } return target; }
|
500 |
|
501 | function _defineProperty(obj, key, value) { if (key in obj) { Object.defineProperty(obj, key, { value: value, enumerable: true, configurable: true, writable: true }); } else { obj[key] = value; } return obj; }
|
502 |
|
503 |
|
504 |
|
505 |
|
506 | const dataStore = new WeakMap();
|
507 |
|
508 | class AsyncAfWrapperProto {
|
509 | constructor(data) {
|
510 | dataStore.set(this, Promise.resolve(data));
|
511 | }
|
512 |
|
513 | then(resolve, reject) {
|
514 | return this.constructor(dataStore.get(this).then(resolve, reject));
|
515 | }
|
516 |
|
517 | catch(reject) {
|
518 | return this.then(null, reject);
|
519 | }
|
520 |
|
521 | finally(onFinally) {
|
522 | return dataStore.get(this).finally(onFinally);
|
523 | }
|
524 |
|
525 | }
|
526 |
|
527 | AsyncAfWrapperProto.use = other_use;
|
528 | Object.defineProperties(AsyncAfWrapperProto.prototype, _objectSpread({}, other_series, {
|
529 | [Symbol.toStringTag]: {
|
530 | value: 'AsyncAF'
|
531 | }
|
532 | }));
|
533 | /**
|
534 | * empty AsyncAF class wrapper
|
535 | *
|
536 | * 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
|
537 | *
|
538 | * **Note:** while AsyncAfWrapper is a class, it can create instances with or without the `new` keyword
|
539 | *
|
540 | * **Example**
|
541 | *
|
542 | * 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
|
543 | *
|
544 | * first, install the separate packages (e.g., for npm):
|
545 | *
|
546 | * `$ npm install --save @async-af/{wrapper,map,filter,foreach,log}`
|
547 | *
|
548 | * or, if on Windows:
|
549 | *
|
550 | * `$ npm install --save @async-af/wrapper @async-af/map @async-af/filter @async-af/foreach @async-af/log`
|
551 | *
|
552 | * then import the packages
|
553 | * ```js
|
554 | * import AsyncAF from '@async-af/wrapper'; // aliasing 'AsyncAfWrapper' as 'AsyncAF'
|
555 | * import mapAF from '@async-af/map';
|
556 | * import filterAF from '@async-af/filter';
|
557 | * import forEachAF from '@async-af/foreach';
|
558 | * import logAF from '@async-af/log';
|
559 | * ```
|
560 | *
|
561 | * _if you'd like to save some vertical screen real estate and cut the imports down to one line, see_ {@tutorial TOO_MANY_IMPORTS}
|
562 | *
|
563 | * 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`
|
564 | * ```js
|
565 | * AsyncAF.use({ // prototype methods go in the first argument
|
566 | * mapAF,
|
567 | * filterAF,
|
568 | * forEachAF
|
569 | * }, { // static methods go in the second argument
|
570 | * logAF
|
571 | * });
|
572 | * ```
|
573 | *
|
574 | * ready to go!
|
575 | * ```js
|
576 | * const promises = [1, 2, 3].map(n => Promise.resolve(n));
|
577 | *
|
578 | * AsyncAF(promises).mapAF(n => n * 2).filterAF(n => n !== 4).forEachAF(n => console.log(n));
|
579 | * // logs 2 then 6
|
580 | *
|
581 | * AsyncAF.logAF(promises);
|
582 | * // @filename.js:24:9:
|
583 | * // [ 1, 2, 3 ]
|
584 | * // in 0.003 secs
|
585 | * ```
|
586 | *
|
587 | * **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
|
588 | * @param {any} data the data to be wrapped by the AsyncAF class; can be promises or non-promises
|
589 | * @returns {Object} returns an instance of AsyncAfWrapper wrapping the passed in data
|
590 | * @since 3.0.0
|
591 | * @see AsyncAF
|
592 | * @see {@link AsyncAfWrapper#use use}
|
593 | * @see {@tutorial TOO_MANY_IMPORTS}
|
594 | * @class AsyncAfWrapper
|
595 | */
|
596 |
|
597 | const AsyncAfWrapper = Object(createNewlessClass["default"])(class AsyncAfWrapper extends AsyncAfWrapperProto {});
|
598 |
|
599 | /* harmony default export */ var classes_AsyncAfWrapper = __webpack_exports__["default"] = (AsyncAfWrapper);
|
600 |
|
601 | /***/ }),
|
602 |
|
603 | /***/ "./lib/methods/_internal/commonCallback.js":
|
604 | /***/ (function(module, __webpack_exports__, __webpack_require__) {
|
605 |
|
606 | ;
|
607 | __webpack_require__.r(__webpack_exports__);
|
608 | /* eslint-disable no-unused-vars, valid-jsdoc */
|
609 |
|
610 | /**
|
611 | * @typedef {callback} _
|
612 | * @param {?} currentValue
|
613 | * @param {Number=} index
|
614 | * @param {[]=} array
|
615 | * @returns {any}
|
616 | */
|
617 | function callback(currentValue, index, array) {}
|
618 |
|
619 | /* harmony default export */ __webpack_exports__["default"] = (callback);
|
620 |
|
621 | /***/ }),
|
622 |
|
623 | /***/ "./lib/methods/_internal/createNewlessClass.js":
|
624 | /***/ (function(module, __webpack_exports__, __webpack_require__) {
|
625 |
|
626 | ;
|
627 | __webpack_require__.r(__webpack_exports__);
|
628 | /* harmony import */ var _nameFunction__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__("./lib/methods/_internal/nameFunction.js");
|
629 |
|
630 |
|
631 | const createNewlessClass = Class => {
|
632 | const {
|
633 | name
|
634 | } = Class;
|
635 |
|
636 | const Newless = function Newless() {
|
637 | for (var _len = arguments.length, args = new Array(_len), _key = 0; _key < _len; _key++) {
|
638 | args[_key] = arguments[_key];
|
639 | }
|
640 |
|
641 | return new Class(...args);
|
642 | };
|
643 |
|
644 | Newless.prototype = Class.prototype;
|
645 | Object.setPrototypeOf(Newless, Class);
|
646 | Newless.prototype.constructor = Newless;
|
647 | return Object(_nameFunction__WEBPACK_IMPORTED_MODULE_0__["default"])(Newless, name);
|
648 | };
|
649 |
|
650 | /* harmony default export */ __webpack_exports__["default"] = (createNewlessClass);
|
651 |
|
652 | /***/ }),
|
653 |
|
654 | /***/ "./lib/methods/_internal/nameFunction.js":
|
655 | /***/ (function(module, __webpack_exports__, __webpack_require__) {
|
656 |
|
657 | ;
|
658 | __webpack_require__.r(__webpack_exports__);
|
659 | const nameFunction = function nameFunction(fn, name) {
|
660 | return Object.defineProperty(fn, 'name', {
|
661 | value: name,
|
662 | configurable: true
|
663 | });
|
664 | };
|
665 |
|
666 | /* harmony default export */ __webpack_exports__["default"] = (nameFunction);
|
667 |
|
668 | /***/ }),
|
669 |
|
670 | /***/ "./lib/methods/_internal/permissiveIsArrayLike.js":
|
671 | /***/ (function(module, __webpack_exports__, __webpack_require__) {
|
672 |
|
673 | ;
|
674 | __webpack_require__.r(__webpack_exports__);
|
675 | const permissiveIsArrayLike = function permissiveIsArrayLike(obj) {
|
676 | return Array.isArray(obj) || obj != null && obj.length != null;
|
677 | };
|
678 |
|
679 | /* harmony default export */ __webpack_exports__["default"] = (permissiveIsArrayLike);
|
680 |
|
681 | /***/ }),
|
682 |
|
683 | /***/ "./lib/methods/_internal/promiseAllWithHoles.js":
|
684 | /***/ (function(module, __webpack_exports__, __webpack_require__) {
|
685 |
|
686 | ;
|
687 | __webpack_require__.r(__webpack_exports__);
|
688 | const promiseAllWithHoles = promises => new Promise((resolve, reject) => {
|
689 | const length = promises.length >>> 0;
|
690 | const result = Array(length);
|
691 | let pending = length;
|
692 | let i = length;
|
693 | if (!length) return resolve(result);
|
694 |
|
695 | const settlePromise = i => Promise.resolve(promises[i]).then(value => {
|
696 | if (i in promises) result[i] = value;
|
697 | if (! --pending) resolve(result);
|
698 | }, reject);
|
699 |
|
700 | while (i--) settlePromise(i);
|
701 | });
|
702 |
|
703 | /* harmony default export */ __webpack_exports__["default"] = (promiseAllWithHoles);
|
704 |
|
705 | /***/ }),
|
706 |
|
707 | /***/ "./lib/methods/_internal/resolve.js":
|
708 | /***/ (function(module, __webpack_exports__, __webpack_require__) {
|
709 |
|
710 | ;
|
711 | __webpack_require__.r(__webpack_exports__);
|
712 | /* harmony export (binding) */ __webpack_require__.d(__webpack_exports__, "serial", function() { return serial; });
|
713 | /* harmony export (binding) */ __webpack_require__.d(__webpack_exports__, "parallel", function() { return parallel; });
|
714 | /* harmony import */ var _promiseAllWithHoles__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__("./lib/methods/_internal/promiseAllWithHoles.js");
|
715 |
|
716 |
|
717 | const serial = arr => function resolveSerially(resolved, i) {
|
718 | const {
|
719 | length
|
720 | } = resolved;
|
721 | if (!length) return Promise.resolve(resolved);
|
722 | const hole = !(i in arr);
|
723 | return Promise.resolve(arr[i]).then(el => {
|
724 | if (!hole) resolved[i] = el;
|
725 | if (i === length - 1) return resolved;
|
726 | return resolveSerially(resolved, i + 1);
|
727 | });
|
728 | }(Array(arr.length >>> 0), 0);
|
729 |
|
730 | const parallel = function parallel(arr, mapper) {
|
731 | let thisArg = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : undefined;
|
732 | return Object(_promiseAllWithHoles__WEBPACK_IMPORTED_MODULE_0__["default"])(arr, el => el).then(!mapper ? undefined : arr => Object(_promiseAllWithHoles__WEBPACK_IMPORTED_MODULE_0__["default"])(Array.prototype.map.call(arr, mapper, thisArg)));
|
733 | };
|
734 |
|
735 |
|
736 |
|
737 | /***/ }),
|
738 |
|
739 | /***/ "./lib/methods/arrays/concatAF.js":
|
740 | /***/ (function(module, __webpack_exports__, __webpack_require__) {
|
741 |
|
742 | ;
|
743 | __webpack_require__.r(__webpack_exports__);
|
744 | const resolveByType = data => Promise[Array.isArray(data) ? 'all' : 'resolve'](data);
|
745 | /**
|
746 | * merges an array or string with one or more arrays, strings, or other values, and resolves to a new array or string;
|
747 | *
|
748 | * concatAF flexibly accepts arrays, strings, promises, other values, or other instances of AsyncAF; see examples
|
749 | *
|
750 | * @param {any} values arrays, strings, or values to concatenate into a new array or string
|
751 | * - if any values are a Promise, they'll first be resolved then concatenated
|
752 | * - if any values are an instance of AsyncAF, they'll be merged into one instance
|
753 | * @returns {Promise.<Array>|Promise.<String>} `Promise` that resolves to a newly merged array or string
|
754 | * @example
|
755 | *
|
756 | * // arrays
|
757 | * const arr = Promise.resolve([1, 2]);
|
758 | * AsyncAF(arr).concatAF([3, 4]); // Promise that resolves to [1, 2, 3, 4]
|
759 | * AsyncAF(arr).concatAF([3, 4], [5, 6]); // Promise that resolves to [1, 2, 3, 4, 5, 6]
|
760 | *
|
761 | * // nested arrays
|
762 | * const arr1 = Promise.resolve([1, 2]);
|
763 | * const arr2 = [3, [4, 5]];
|
764 | * AsyncAF(arr1).concatAF(arr2); // Promise that resolves to [1, 2, 3, [4, 5]]
|
765 | *
|
766 | * // strings
|
767 | * const str = Promise.resolve('str');
|
768 | * AsyncAF(str).concatAF('ing'); // Promise that resolves to 'string'
|
769 | * AsyncAF(str).concatAF('ing', 'y'); // Promise that resolves to 'stringy'
|
770 | *
|
771 | * // other instances of AsyncAF
|
772 | * const aaf1 = AsyncAF([1, 2]);
|
773 | * const aaf2 = AsyncAF(3);
|
774 | *
|
775 | * aaf1.concatAF(aaf2); // Promise that resolves to [1, 2, 3];
|
776 | *
|
777 | * const aaf3 = AsyncAF('stringy');
|
778 | * const aaf4 = AsyncAF('AF');
|
779 | *
|
780 | * aaf3.concatAF(aaf4); // Promise that resolves to 'stringyAF'
|
781 | *
|
782 | * // promises
|
783 | * const [p1, p2, p3] = [[1, 2], 3, [4, [5, 6]]].map(v => Promise.resolve(v));
|
784 | *
|
785 | * AsyncAF(p1).concatAF(p2); // Promise that resolves to [1, 2, 3]
|
786 | * AsyncAF(p1).concatAF(p2, p3) // Promise that resolves to [1, 2, 3, 4, [5, 6]]
|
787 | *
|
788 | * const pStr1 = Promise.resolve('str');
|
789 | * const pStr2 = Promise.resolve('ing');
|
790 | * const pStr3 = Promise.resolve('y');
|
791 | *
|
792 | * AsyncAF(pStr1).concatAF(pStr2); // Promise that resolves to 'string'
|
793 | * AsyncAF(pStr1).concatAF(pStr2, pStr3); // Promise that resolves to 'stringy'
|
794 | *
|
795 | * // Note: concatAF will not resolve deeply nested promises; if you need this behavior, concatAF can be used in a
|
796 | * // function; for example, this function recursively flattens an array of promises
|
797 | *
|
798 | * const flattenAsync = arr => AsyncAF(arr).reduceAF(async (acc, val) => {
|
799 | * return Array.isArray(await val)
|
800 | * ? AsyncAF(acc).concatAF(flattenAsync(val))
|
801 | * : AsyncAF(acc).concatAF(val), []);
|
802 | * };
|
803 | *
|
804 | * @since 5.3.0
|
805 | * @see concat (alias)
|
806 | * @memberof AsyncAF#
|
807 | */
|
808 |
|
809 |
|
810 | const concatAF = function concatAF() {
|
811 | for (var _len = arguments.length, values = new Array(_len), _key = 0; _key < _len; _key++) {
|
812 | values[_key] = arguments[_key];
|
813 | }
|
814 |
|
815 | const isThenable = value => [Promise, this.constructor].some(thenable => value instanceof thenable);
|
816 |
|
817 | const concat = (arrOrStr, value) => isThenable(value) && value.then(resolveByType).then(value => arrOrStr.concat(value)) || arrOrStr.concat(value);
|
818 |
|
819 | return this.then(arrOrStr => {
|
820 | if (!(typeof arrOrStr === 'string' || Array.isArray(arrOrStr))) throw TypeError("concatAF cannot be called on ".concat(arrOrStr, ", only on an Array or String"));
|
821 | return resolveByType(arrOrStr).then(arrOrStr => values.reduce((arrOrStr, value) => isThenable(arrOrStr) ? arrOrStr.then(arrOrStr => concat(arrOrStr, value)) : concat(arrOrStr, value), arrOrStr));
|
822 | });
|
823 | };
|
824 |
|
825 | /* harmony default export */ __webpack_exports__["default"] = (concatAF);
|
826 |
|
827 | /***/ }),
|
828 |
|
829 | /***/ "./lib/methods/arrays/everyAF.js":
|
830 | /***/ (function(module, __webpack_exports__, __webpack_require__) {
|
831 |
|
832 | ;
|
833 | __webpack_require__.r(__webpack_exports__);
|
834 | /* harmony import */ var _internal_commonCallback__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__("./lib/methods/_internal/commonCallback.js");
|
835 | /* harmony import */ var _internal_permissiveIsArrayLike__WEBPACK_IMPORTED_MODULE_1__ = __webpack_require__("./lib/methods/_internal/permissiveIsArrayLike.js");
|
836 | /* harmony import */ var _internal_resolve__WEBPACK_IMPORTED_MODULE_2__ = __webpack_require__("./lib/methods/_internal/resolve.js");
|
837 | // eslint-disable-line no-unused-vars
|
838 |
|
839 |
|
840 |
|
841 | /**
|
842 | * tests whether all elements in the array pass the test implemented by the provided callback function
|
843 | *
|
844 | * if any elements are a `Promise`, they will first be resolved in parallel and then tested
|
845 | *
|
846 | * *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`
|
847 | *
|
848 | * @param {callback} callback function that tests each element of the array
|
849 | *
|
850 | * `callback` accepts three arguments:
|
851 | * - `currentValue` value of the current element being processed in the array
|
852 | * - `index`*`(optional)`* index of `currentValue` in the array
|
853 | * - `array`*`(optional)`* the array that `everyAF` is being applied to
|
854 | * @param {Object=} thisArg value to use as `this` when executing `callback`
|
855 | * @returns {Promise.<Boolean>} `Promise` that resolves to `true` if the callback function returns a truthy value for every array element; otherwise, `false`
|
856 | * @example
|
857 | *
|
858 | * const promises = [1, 2, 3].map(n => Promise.resolve(n));
|
859 | *
|
860 | *
|
861 | * // basic usage
|
862 | * const allAreOdd = AsyncAF(promises).everyAF(n => n % 2);
|
863 | *
|
864 | * console.log(allAreOdd); // Promise that resolves to false
|
865 | *
|
866 | * AsyncAF.logAF(allAreOdd); // logs false
|
867 | *
|
868 | *
|
869 | * // using .then
|
870 | * AsyncAF(promises).everyAF(n => n % 2).then(allAreOdd => {
|
871 | * console.log(allAreOdd); // logs false
|
872 | * });
|
873 | *
|
874 | *
|
875 | * // inside an async function
|
876 | * (async () => {
|
877 | * const allAreNums = await AsyncAF(promises).everyAF(
|
878 | * n => typeof n === 'number'
|
879 | * );
|
880 | * console.log(allAreNums); // logs true
|
881 | * })();
|
882 | * @since 3.2.0
|
883 | * @see every (alias)
|
884 | * @see {@link AsyncAF#series series.everyAF}
|
885 | * @memberof AsyncAF#
|
886 | */
|
887 |
|
888 | const everyAF = function everyAF(callback) {
|
889 | let thisArg = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : undefined;
|
890 | return this.then(arr => {
|
891 | 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"));
|
892 | if (typeof callback !== 'function') throw TypeError("".concat(callback, " is not a function"));
|
893 | const length = arr.length >>> 0;
|
894 | return this.inSeries ? !length && true || function seriesEveryAF(arr, i) {
|
895 | const hole = !(i in arr);
|
896 | return Promise.resolve(arr[i]).then(el => {
|
897 | arr[i] = el;
|
898 | return Promise.resolve(!hole && callback.call(thisArg, el, i, arr)).then(bool => {
|
899 | if (!bool && !hole) return false;
|
900 | if (i === length - 1) return true;
|
901 | return seriesEveryAF(arr, i + 1);
|
902 | });
|
903 | });
|
904 | }(Array.prototype.slice.call(arr), 0) : Object(_internal_resolve__WEBPACK_IMPORTED_MODULE_2__["parallel"])(arr, callback, thisArg).then(bools => bools.every(Boolean));
|
905 | });
|
906 | };
|
907 |
|
908 | /* harmony default export */ __webpack_exports__["default"] = (everyAF);
|
909 |
|
910 | /***/ }),
|
911 |
|
912 | /***/ "./lib/methods/arrays/filterAF.js":
|
913 | /***/ (function(module, __webpack_exports__, __webpack_require__) {
|
914 |
|
915 | ;
|
916 | __webpack_require__.r(__webpack_exports__);
|
917 | /* harmony import */ var _internal_commonCallback__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__("./lib/methods/_internal/commonCallback.js");
|
918 | /* harmony import */ var _internal_permissiveIsArrayLike__WEBPACK_IMPORTED_MODULE_1__ = __webpack_require__("./lib/methods/_internal/permissiveIsArrayLike.js");
|
919 | /* harmony import */ var _internal_resolve__WEBPACK_IMPORTED_MODULE_2__ = __webpack_require__("./lib/methods/_internal/resolve.js");
|
920 | // eslint-disable-line no-unused-vars
|
921 |
|
922 |
|
923 |
|
924 | /**
|
925 | * creates a new `Array` with all elements that pass the test implemented by the provided callback function
|
926 | *
|
927 | * if any elements are a `Promise`, they will first be resolved in parallel and then tested
|
928 | *
|
929 | * *Note*: if you'd rather resolve and test elements in series, consider using `series.filterAF` or its alias, `io.filterAF`
|
930 | *
|
931 | * @param {callback} callback function that tests each element of the array; return `true` to keep the element, `false` to filter it out
|
932 | *
|
933 | * `callback` accepts three arguments:
|
934 | * - `currentValue` value of the current element being processed in the array
|
935 | * - `index`*`(optional)`* index of `currentValue` in the array
|
936 | * - `array`*`(optional)`* the array that `filterAF` is being applied to
|
937 | * @param {Object=} thisArg value to use as `this` when executing `callback`
|
938 | * @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
|
939 | * @example
|
940 | *
|
941 | * const promises = [1, 2, 3].map(n => Promise.resolve(n));
|
942 | *
|
943 | *
|
944 | * // basic usage
|
945 | * const odds = AsyncAF(promises).filterAF(n => n % 2);
|
946 | *
|
947 | * console.log(odds); // Promise that resolves to [1, 3]
|
948 | *
|
949 | * AsyncAF.logAF(odds); // logs [1, 3]
|
950 | *
|
951 | *
|
952 | * // using .then
|
953 | * AsyncAF(promises).filterAF(n => n % 2).then(odds => {
|
954 | * console.log(odds); // logs [1, 3]
|
955 | * });
|
956 | *
|
957 | *
|
958 | * // inside an async function
|
959 | * (async () => {
|
960 | * const odds = await AsyncAF(promises).filterAF(
|
961 | * n => n % 2
|
962 | * );
|
963 | * console.log(odds); // logs [1, 3]
|
964 | * })();
|
965 | * @since 3.0.0
|
966 | * @see filter (alias)
|
967 | * @see {@link AsyncAF#series series.filterAF}
|
968 | * @memberof AsyncAF#
|
969 | */
|
970 |
|
971 | const filterAF = function filterAF(callback) {
|
972 | let thisArg = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : undefined;
|
973 | return this.then(arr => {
|
974 | 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"));
|
975 | if (typeof callback !== 'function') throw TypeError("".concat(callback, " is not a function"));
|
976 | return (this.inSeries ? _internal_resolve__WEBPACK_IMPORTED_MODULE_2__["serial"] : _internal_resolve__WEBPACK_IMPORTED_MODULE_2__["parallel"])(arr).then(arr => (this.inSeries ? arr.reduce((bools, el, i, arr) => bools.then(bools => {
|
977 | bools[i] = callback.call(thisArg, el, i, arr);
|
978 | return Promise.all(bools);
|
979 | }), Promise.all([])) : Object(_internal_resolve__WEBPACK_IMPORTED_MODULE_2__["parallel"])(arr, callback, thisArg)).then(bools => arr.filter((_, i) => bools[i])));
|
980 | });
|
981 | };
|
982 |
|
983 | /* harmony default export */ __webpack_exports__["default"] = (filterAF);
|
984 |
|
985 | /***/ }),
|
986 |
|
987 | /***/ "./lib/methods/arrays/findAF.js":
|
988 | /***/ (function(module, __webpack_exports__, __webpack_require__) {
|
989 |
|
990 | ;
|
991 | __webpack_require__.r(__webpack_exports__);
|
992 | /* harmony import */ var _internal_commonCallback__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__("./lib/methods/_internal/commonCallback.js");
|
993 | /* harmony import */ var _internal_permissiveIsArrayLike__WEBPACK_IMPORTED_MODULE_1__ = __webpack_require__("./lib/methods/_internal/permissiveIsArrayLike.js");
|
994 | /* harmony import */ var _internal_resolve__WEBPACK_IMPORTED_MODULE_2__ = __webpack_require__("./lib/methods/_internal/resolve.js");
|
995 | // eslint-disable-line no-unused-vars
|
996 |
|
997 |
|
998 |
|
999 | /**
|
1000 | * resolves to the value of the first element in the array that satisfies the provided callback function; otherwise, `undefined`
|
1001 | *
|
1002 | * *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`
|
1003 | *
|
1004 | * @param {callback} callback function to test each element in the array
|
1005 | *
|
1006 | * `callback` accepts three arguments:
|
1007 | * - `currentValue` value of the current element being processed in the array
|
1008 | * - `index`*`(optional)`* index of `currentValue` in the array
|
1009 | * - `array`*`(optional)`* the array that findAF is being applied to
|
1010 | * @param {Object=} thisArg value to use as `this` when executing `callback`
|
1011 | * @returns {Promise.<any>} `Promise` that resolves to the first element in the array that passes the test; otherwise, undefined
|
1012 | * @example
|
1013 | *
|
1014 | * const inventory = [
|
1015 | * {name: 'nuts', quantity: 2000},
|
1016 | * {name: 'bolts', quantity: 5000},
|
1017 | * {name: 'screws', quantity: 9001}
|
1018 | * ].map(part => Promise.resolve(part));
|
1019 | *
|
1020 | * AsyncAF(inventory).findAF(part => part.name === 'screws');
|
1021 | * // Promise that resolves to {name: 'screws', quantity: 9001}
|
1022 | * @since 3.5.0
|
1023 | * @see find (alias)
|
1024 | * @see {@link AsyncAF#series series.findAF}
|
1025 | * @memberof AsyncAF#
|
1026 | */
|
1027 |
|
1028 | const findAF = function findAF(callback) {
|
1029 | let thisArg = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : undefined;
|
1030 | return this.then(arr => {
|
1031 | 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"));
|
1032 | if (typeof callback !== 'function') throw TypeError("".concat(callback, " is not a function"));
|
1033 | const filled = Array.from(arr);
|
1034 | const length = filled.length >>> 0;
|
1035 | return this.inSeries ? (length || undefined) && function seriesFindAF(arr, i) {
|
1036 | return Promise.resolve(arr[i]).then(el => {
|
1037 | arr[i] = el;
|
1038 | return Promise.resolve(callback.call(thisArg, el, i, arr)).then(bool => {
|
1039 | if (bool) return el;
|
1040 | if (i === length - 1) return;
|
1041 | return seriesFindAF(arr, i + 1);
|
1042 | });
|
1043 | });
|
1044 | }(filled, 0) : Object(_internal_resolve__WEBPACK_IMPORTED_MODULE_2__["parallel"])(filled, callback, thisArg).then(bools => arr[bools.indexOf(true)]);
|
1045 | });
|
1046 | };
|
1047 |
|
1048 | /* harmony default export */ __webpack_exports__["default"] = (findAF);
|
1049 |
|
1050 | /***/ }),
|
1051 |
|
1052 | /***/ "./lib/methods/arrays/findIndexAF.js":
|
1053 | /***/ (function(module, __webpack_exports__, __webpack_require__) {
|
1054 |
|
1055 | ;
|
1056 | __webpack_require__.r(__webpack_exports__);
|
1057 | /* harmony import */ var _internal_commonCallback__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__("./lib/methods/_internal/commonCallback.js");
|
1058 | /* harmony import */ var _internal_permissiveIsArrayLike__WEBPACK_IMPORTED_MODULE_1__ = __webpack_require__("./lib/methods/_internal/permissiveIsArrayLike.js");
|
1059 | /* harmony import */ var _internal_resolve__WEBPACK_IMPORTED_MODULE_2__ = __webpack_require__("./lib/methods/_internal/resolve.js");
|
1060 | // eslint-disable-line no-unused-vars
|
1061 |
|
1062 |
|
1063 |
|
1064 | /**
|
1065 | * resolves to the index of the first element in the array that satisfies the provided callback function; otherwise, `-1`
|
1066 | *
|
1067 | * *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`
|
1068 | *
|
1069 | * @param {callback} callback function to test each element in the array
|
1070 | *
|
1071 | * `callback` accepts three arguments:
|
1072 | * - `currentValue` value of the current element being processed in the array
|
1073 | * - `index`*`(optional)`* index of `currentValue` in the array
|
1074 | * - `array`*`(optional)`* the array that findIndexAF is being applied to
|
1075 | * @param {Object=} thisArg value to use as `this` when executing `callback`
|
1076 | * @returns {Promise.<Number>} `Promise` that resolves to the index of the first element in the array that passes the test; otherwise, `-1`
|
1077 | * @example
|
1078 | *
|
1079 | * const inventory = [
|
1080 | * {name: 'nuts', quantity: 2000},
|
1081 | * {name: 'bolts', quantity: 5000},
|
1082 | * {name: 'screws', quantity: 9001}
|
1083 | * ].map(part => Promise.resolve(part));
|
1084 | *
|
1085 | * AsyncAF(inventory).findIndexAF(part => part.name === 'screws');
|
1086 | * // Promise that resolves to 2
|
1087 | * @since 3.5.0
|
1088 | * @see findIndex (alias)
|
1089 | * @see {@link AsyncAF#series series.findIndexAF}
|
1090 | * @memberof AsyncAF#
|
1091 | */
|
1092 |
|
1093 | const findIndexAF = function findIndexAF(callback) {
|
1094 | let thisArg = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : undefined;
|
1095 | return this.then(arr => {
|
1096 | 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"));
|
1097 | if (typeof callback !== 'function') throw TypeError("".concat(callback, " is not a function"));
|
1098 | const filled = Array.from(arr);
|
1099 | const length = filled.length >>> 0;
|
1100 | return this.inSeries ? !length && -1 || function seriesFindIndexAF(arr, i) {
|
1101 | return Promise.resolve(arr[i]).then(el => {
|
1102 | arr[i] = el;
|
1103 | return Promise.resolve(callback.call(thisArg, el, i, arr)).then(bool => {
|
1104 | if (bool) return i;
|
1105 | if (i === length - 1) return -1;
|
1106 | return seriesFindIndexAF(arr, i + 1);
|
1107 | });
|
1108 | });
|
1109 | }(filled, 0) : Object(_internal_resolve__WEBPACK_IMPORTED_MODULE_2__["parallel"])(filled, callback, thisArg).then(bools => bools.indexOf(true));
|
1110 | });
|
1111 | };
|
1112 |
|
1113 | /* harmony default export */ __webpack_exports__["default"] = (findIndexAF);
|
1114 |
|
1115 | /***/ }),
|
1116 |
|
1117 | /***/ "./lib/methods/arrays/forEachAF.js":
|
1118 | /***/ (function(module, __webpack_exports__, __webpack_require__) {
|
1119 |
|
1120 | ;
|
1121 | __webpack_require__.r(__webpack_exports__);
|
1122 | /* harmony import */ var _internal_commonCallback__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__("./lib/methods/_internal/commonCallback.js");
|
1123 | /* harmony import */ var _internal_permissiveIsArrayLike__WEBPACK_IMPORTED_MODULE_1__ = __webpack_require__("./lib/methods/_internal/permissiveIsArrayLike.js");
|
1124 | /* harmony import */ var _internal_resolve__WEBPACK_IMPORTED_MODULE_2__ = __webpack_require__("./lib/methods/_internal/resolve.js");
|
1125 | // eslint-disable-line no-unused-vars
|
1126 |
|
1127 |
|
1128 |
|
1129 | /**
|
1130 | * executes a callback function on each element in an array
|
1131 | *
|
1132 | * if any elements are a `Promise`, they will first be resolved in parallel and then processed
|
1133 | *
|
1134 | * *Note*: if you'd rather resolve and process elements in series, consider using `series.forEachAF` or its alias, `io.forEachAF`
|
1135 | *
|
1136 | * @param {callback} callback function to execute for each element
|
1137 | *
|
1138 | * `callback` accepts three arguments:
|
1139 | * - `currentValue` value of the current element being processed in the array
|
1140 | * - `index`*`(optional)`* index of `currentValue` in the array
|
1141 | * - `array`*`(optional)`* the array that forEachAF is being applied to
|
1142 | * @param {Object=} thisArg value to use as `this` when executing `callback`
|
1143 | * @returns {Promise.<undefined>} `Promise` that resolves to `undefined`
|
1144 | * @example
|
1145 | *
|
1146 | * const promises = [1, 2].map(n => Promise.resolve(n));
|
1147 | *
|
1148 | *
|
1149 | * AsyncAF(promises).forEachAF(el => {
|
1150 | * console.log(el); // logs 1 then 2
|
1151 | * });
|
1152 | * @since 3.0.0
|
1153 | * @see forEach (alias)
|
1154 | * @see {@link AsyncAF#series series.forEachAF}
|
1155 | * @memberof AsyncAF#
|
1156 | */
|
1157 |
|
1158 | const forEachAF = function forEachAF(callback) {
|
1159 | let thisArg = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : undefined;
|
1160 | return this.then(arr => {
|
1161 | if (!Object(_internal_permissiveIsArrayLike__WEBPACK_IMPORTED_MODULE_1__["default"])(arr)) throw TypeError("forEachAF cannot be called on ".concat(arr, ", only on an Array or array-like Object"));
|
1162 | if (typeof callback !== 'function') throw TypeError("".concat(callback, " is not a function"));
|
1163 | return (this.inSeries ? Object(_internal_resolve__WEBPACK_IMPORTED_MODULE_2__["serial"])(arr).then(arr => arr.reduce((expr, el, i, arr) => expr.then(() => Promise.resolve(callback.call(thisArg, el, i, arr))), Promise.resolve())) : Object(_internal_resolve__WEBPACK_IMPORTED_MODULE_2__["parallel"])(arr, callback, thisArg)).then(() => {});
|
1164 | });
|
1165 | };
|
1166 |
|
1167 | /* harmony default export */ __webpack_exports__["default"] = (forEachAF);
|
1168 |
|
1169 | /***/ }),
|
1170 |
|
1171 | /***/ "./lib/methods/arrays/includesAF.js":
|
1172 | /***/ (function(module, __webpack_exports__, __webpack_require__) {
|
1173 |
|
1174 | ;
|
1175 | __webpack_require__.r(__webpack_exports__);
|
1176 | /* harmony import */ var _internal_permissiveIsArrayLike__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__("./lib/methods/_internal/permissiveIsArrayLike.js");
|
1177 | /* harmony import */ var _internal_resolve__WEBPACK_IMPORTED_MODULE_1__ = __webpack_require__("./lib/methods/_internal/resolve.js");
|
1178 |
|
1179 |
|
1180 |
|
1181 | const sameValueZero = (a, b) => a === b || Number.isNaN(a) && Number.isNaN(b);
|
1182 | /**
|
1183 | * determines whether an array, string, or array-like object includes a certain element or string, returning true or false as appropriate
|
1184 | *
|
1185 | * *Note*: when called on an array or array-like object, `includesAF` is run in parallel and all elements will be resolved even if one of the first few elements is a match; if this behavior is not desireable, consider using `series.includesAF` or its alias, `io.includesAF`
|
1186 | *
|
1187 | * @param {any} searchItem the element or string to search for
|
1188 | * @param {Number=} fromIndex the index at which to begin searching for `searchItem`; a negative value searches from the index of `array/string.length - fromIndex`; defaults to `0`
|
1189 | * @returns {Promise.<Boolean>} `Promise` that resolves to `true` if `searchItem` is found; otherwise, `false`
|
1190 | * @example
|
1191 | *
|
1192 | * // includesAF on an array of promises
|
1193 | * const nums = [1, 2, 3].map(n => Promise.resolve(n));
|
1194 | *
|
1195 | * AsyncAF(nums).includesAF(2); // Promise that resolves to true
|
1196 | *
|
1197 | * AsyncAF(nums).includesAF(5); // Promise that resolves to false
|
1198 | *
|
1199 | * AsyncAF(nums).includesAF(1, 1); // Promise that resolves to false
|
1200 | *
|
1201 | * AsyncAF(nums).includesAF(3, -1); // Promise that resolves to true
|
1202 | *
|
1203 | * // includesAF on a promise-wrapped string
|
1204 | * const string = Promise.resolve('test string');
|
1205 | *
|
1206 | * AsyncAF(string).includesAF('test'); // Promise that resolves to true
|
1207 | *
|
1208 | * AsyncAF(string).includesAF('nope'); // Promise that resolves to false
|
1209 | *
|
1210 | * AsyncAF(string).includesAF('test', 5); // Promise that resolves to false
|
1211 | *
|
1212 | * AsyncAF(string).includesAF('string', -6); // Promise that resolves to true
|
1213 | *
|
1214 | * // includesAF on an array-like object
|
1215 | * (async function () {
|
1216 | * if (await AsyncAF(arguments).includesAF(2)) {
|
1217 | * console.log('2 is included');
|
1218 | * }
|
1219 | * })(1, 2, 3); // logs '2 is included'
|
1220 | *
|
1221 | * @since 3.4.0
|
1222 | * @see includes (alias)
|
1223 | * @see {@link AsyncAF#series series.includesAF}
|
1224 | * @memberof AsyncAF#
|
1225 | */
|
1226 |
|
1227 |
|
1228 | const includesAF = function includesAF(searchItem) {
|
1229 | let fromIndex = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : 0;
|
1230 | return this.then(arrOrStr => {
|
1231 | if (!Object(_internal_permissiveIsArrayLike__WEBPACK_IMPORTED_MODULE_0__["default"])(arrOrStr)) throw TypeError("includesAF cannot be called on ".concat(arrOrStr, ", only on an Array, String, or array-like Object"));
|
1232 | const length = arrOrStr.length >>> 0;
|
1233 | const fromIdx = fromIndex | 0;
|
1234 | return typeof arrOrStr === 'string' ? arrOrStr.includes(searchItem, fromIdx) : this.inSeries ? (length || false) && function seriesIncludesAF(i) {
|
1235 | return Promise.resolve(arrOrStr[i]).then(el => {
|
1236 | if (sameValueZero(el, searchItem)) return true;
|
1237 | if (i >= length - 1) return false;
|
1238 | return seriesIncludesAF(i + 1);
|
1239 | });
|
1240 | }(Math.max(fromIdx >= 0 ? fromIdx : length - Math.abs(fromIdx), 0)) : Object(_internal_resolve__WEBPACK_IMPORTED_MODULE_1__["parallel"])(arrOrStr).then(arr => arr.includes(searchItem, fromIdx));
|
1241 | });
|
1242 | };
|
1243 |
|
1244 | /* harmony default export */ __webpack_exports__["default"] = (includesAF);
|
1245 |
|
1246 | /***/ }),
|
1247 |
|
1248 | /***/ "./lib/methods/arrays/indexOfAF.js":
|
1249 | /***/ (function(module, __webpack_exports__, __webpack_require__) {
|
1250 |
|
1251 | ;
|
1252 | __webpack_require__.r(__webpack_exports__);
|
1253 | /* harmony import */ var _internal_permissiveIsArrayLike__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__("./lib/methods/_internal/permissiveIsArrayLike.js");
|
1254 | /* harmony import */ var _internal_resolve__WEBPACK_IMPORTED_MODULE_1__ = __webpack_require__("./lib/methods/_internal/resolve.js");
|
1255 |
|
1256 |
|
1257 | /**
|
1258 | * resolves to the first index of the specified element or string in an array, string, or array-like object, starting the search at `fromIndex`; if the value is not found, resolves to `-1`
|
1259 | *
|
1260 | * *Note*: when called on an array or array-like object, `indexOfAF` is run in parallel and all elements will be resolved even if one of the first few indices is a match; if this behavior is not desireable, consider using `series.indexOfAF` or its alias, `io.indexOfAF`
|
1261 | *
|
1262 | * @param {any} searchItem the element or string to search for
|
1263 | * @param {Number=} fromIndex the index at which to begin searching for `searchItem`; a negative value searches from the index of `array/string.length - fromIndex`; defaults to `0`
|
1264 | * @returns {Promise.<Number>} `Promise` that resolves to the index of `searchItem` if found; otherwise, `-1`
|
1265 | * @example
|
1266 | *
|
1267 | * // indexOfAF on an array of promises
|
1268 | * const nums = [1, 2, 3].map(n => Promise.resolve(n));
|
1269 | *
|
1270 | * AsyncAF(nums).indexOfAF(2); // Promise that resolves to 1
|
1271 | *
|
1272 | * AsyncAF(nums).indexOfAF(5); // Promise that resolves to -1
|
1273 | *
|
1274 | * AsyncAF(nums).indexOfAF(1, 1); // Promise that resolves to -1
|
1275 | *
|
1276 | * AsyncAF(nums).indexOfAF(3, -1); // Promise that resolves to 2
|
1277 | *
|
1278 | * // indexOfAF on a promise-wrapped string
|
1279 | * const string = Promise.resolve('test string');
|
1280 | *
|
1281 | * AsyncAF(string).indexOfAF('test'); // Promise that resolves to 0
|
1282 | *
|
1283 | * AsyncAF(string).indexOfAF('nope'); // Promise that resolves to -1
|
1284 | *
|
1285 | * AsyncAF(string).indexOfAF('test', 5); // Promise that resolves to -1
|
1286 | *
|
1287 | * AsyncAF(string).indexOfAF('string', -6); // Promise that resolves to 5
|
1288 | *
|
1289 | * // indexOfAF on an array-like object
|
1290 | * (async function () {
|
1291 | * if (await AsyncAF(arguments).indexOfAF(2) > -1) {
|
1292 | * console.log('2 is included');
|
1293 | * }
|
1294 | * })(1, 2, 3); // logs '2 is included'
|
1295 | *
|
1296 | * @since 3.5.0
|
1297 | * @see indexOf (alias)
|
1298 | * @see {@link AsyncAF#series series.indexOfAF}
|
1299 | * @memberof AsyncAF#
|
1300 | */
|
1301 |
|
1302 | const indexOfAF = function indexOfAF(searchItem) {
|
1303 | let fromIndex = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : 0;
|
1304 | return this.then(arrOrStr => {
|
1305 | if (!Object(_internal_permissiveIsArrayLike__WEBPACK_IMPORTED_MODULE_0__["default"])(arrOrStr)) throw TypeError("indexOfAF cannot be called on ".concat(arrOrStr, ", only on an Array, String, or array-like Object"));
|
1306 | const length = arrOrStr.length >>> 0;
|
1307 | const fromIdx = fromIndex | 0;
|
1308 | return typeof arrOrStr === 'string' ? arrOrStr.indexOf(searchItem, fromIdx) : this.inSeries ? function seriesIndexOfAF(i) {
|
1309 | return Promise.resolve(arrOrStr[i]).then(el => {
|
1310 | if (i in arrOrStr && el === searchItem) return i;
|
1311 | if (i >= length - 1) return -1;
|
1312 | return seriesIndexOfAF(i + 1);
|
1313 | });
|
1314 | }(Math.max(fromIdx >= 0 ? fromIdx : length - Math.abs(fromIdx), 0)) : Object(_internal_resolve__WEBPACK_IMPORTED_MODULE_1__["parallel"])(arrOrStr).then(arr => arr.indexOf(searchItem, fromIdx));
|
1315 | });
|
1316 | };
|
1317 |
|
1318 | /* harmony default export */ __webpack_exports__["default"] = (indexOfAF);
|
1319 |
|
1320 | /***/ }),
|
1321 |
|
1322 | /***/ "./lib/methods/arrays/joinAF.js":
|
1323 | /***/ (function(module, __webpack_exports__, __webpack_require__) {
|
1324 |
|
1325 | ;
|
1326 | __webpack_require__.r(__webpack_exports__);
|
1327 | /* harmony import */ var _internal_permissiveIsArrayLike__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__("./lib/methods/_internal/permissiveIsArrayLike.js");
|
1328 | /* harmony import */ var _internal_resolve__WEBPACK_IMPORTED_MODULE_1__ = __webpack_require__("./lib/methods/_internal/resolve.js");
|
1329 |
|
1330 |
|
1331 | /**
|
1332 | * joins all elements of an array or array-like object into a string and resolves to that string
|
1333 | *
|
1334 | * @param {any} separator the string that separates each element in the resulting string; defaults to `','`; non-string separators will be converted to strings if necessary; if `separator` is an empty string `''`, the array elements are joined without any characters between them
|
1335 | * @returns {Promise.<String>} `Promise` that resolves to a string with all array elements joined; if array.length is `0`, an empty string `''` is returned
|
1336 | * @example
|
1337 | *
|
1338 | * const animals = ['cow', 'chicken', 'cat', 'dog'].map(a => Promise.resolve(a));
|
1339 | *
|
1340 | * // joinAF separator defaults to ','
|
1341 | * AsyncAF(animals).joinAF(); // Promise that resolves to 'cow,chicken,cat,dog'
|
1342 | *
|
1343 | * // specifying separator
|
1344 | * AsyncAF(animals).joinAF(' & '); // Promise that resolves to 'cow & chicken & cat & dog'
|
1345 | *
|
1346 | * // a non-string separator will be converted to a string
|
1347 | * AsyncAF(animals).joinAF(2); // Promise that resolves to 'cow2chicken2cat2dog'
|
1348 | *
|
1349 | * // empty string separator
|
1350 | * AsyncAF(animals).joinAF(''); // Promise that resolves to 'cowchickencatdog'
|
1351 | *
|
1352 | * // joining an empty array resolves to an empty string
|
1353 | * AsyncAF([]).joinAF('+'); // Promise that resolves to ''
|
1354 | *
|
1355 | * // joinAF on an array-like object
|
1356 | * (async function () {
|
1357 | * const list = await AsyncAF(arguments).joinAF(' - ');
|
1358 | * console.log(`Shopping List: ${list}`);
|
1359 | * })('eggs', 'milk', 'butter', 'pancake mix');
|
1360 | * // Shopping List: eggs - milk - butter - pancake mix
|
1361 | *
|
1362 | * @since 3.6.0
|
1363 | * @see join (alias)
|
1364 | * @memberof AsyncAF#
|
1365 | */
|
1366 |
|
1367 | const joinAF = function joinAF() {
|
1368 | let separator = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : ',';
|
1369 | return this.then(arr => {
|
1370 | if (!Object(_internal_permissiveIsArrayLike__WEBPACK_IMPORTED_MODULE_0__["default"])(arr)) throw TypeError("joinAF cannot be called on ".concat(arr, ", only on an Array or array-like Object"));
|
1371 | return Object(_internal_resolve__WEBPACK_IMPORTED_MODULE_1__["parallel"])(arr).then(arr => arr.join(separator));
|
1372 | });
|
1373 | };
|
1374 |
|
1375 | Object.defineProperty(joinAF, 'length', {
|
1376 | value: 1
|
1377 | });
|
1378 | /* harmony default export */ __webpack_exports__["default"] = (joinAF);
|
1379 |
|
1380 | /***/ }),
|
1381 |
|
1382 | /***/ "./lib/methods/arrays/lastIndexOfAF.js":
|
1383 | /***/ (function(module, __webpack_exports__, __webpack_require__) {
|
1384 |
|
1385 | ;
|
1386 | __webpack_require__.r(__webpack_exports__);
|
1387 | /* harmony import */ var _internal_permissiveIsArrayLike__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__("./lib/methods/_internal/permissiveIsArrayLike.js");
|
1388 | /* harmony import */ var _internal_resolve__WEBPACK_IMPORTED_MODULE_1__ = __webpack_require__("./lib/methods/_internal/resolve.js");
|
1389 |
|
1390 |
|
1391 | /**
|
1392 | * resolves to the last index of the specified element or string, searching backwards in an array, string, or array-like object; `fromIndex` offsets the start of the search; if the value is not found, resolves to `-1`
|
1393 | *
|
1394 | * *Note*: when called on an array or array-like object, `lastIndexOfAF` is run in parallel and all elements will be resolved even if one of the last few indices is a match; if this behavior is not desireable, consider using `series.lastIndexOfAF` or its alias, `io.lastIndexOfAF`
|
1395 | *
|
1396 | * @param {any} searchItem the element or string to search for
|
1397 | * @param {Number=} fromIndex the index at which to begin searching backwards for `searchItem`; a negative value searches from the index of `array/string.length - fromIndex`; defaults to `array/string.length - 1`
|
1398 | * @returns {Promise.<Number>} `Promise` that resolves to the last index of `searchItem` if found; otherwise, `-1`
|
1399 | * @example
|
1400 | *
|
1401 | * // lastIndexOfAF on an array of promises
|
1402 | * const nums = [1, 1, 2, 2, 3, 3].map(n => Promise.resolve(n));
|
1403 | *
|
1404 | * AsyncAF(nums).lastIndexOfAF(2); // Promise that resolves to 3
|
1405 | *
|
1406 | * AsyncAF(nums).lastIndexOfAF(5); // Promise that resolves to -1
|
1407 | *
|
1408 | * AsyncAF(nums).lastIndexOfAF(2, -4); // Promise that resolves to 2
|
1409 | *
|
1410 | * AsyncAF(nums).lastIndexOfAF(3, -3); // Promise that resolves to -1
|
1411 | *
|
1412 | * // lastIndexOfAF on a promise-wrapped string
|
1413 | * const string = Promise.resolve('test string to test');
|
1414 | *
|
1415 | * AsyncAF(string).lastIndexOfAF('test'); // Promise that resolves to 15
|
1416 | *
|
1417 | * AsyncAF(string).lastIndexOfAF('nope'); // Promise that resolves to -1
|
1418 | *
|
1419 | * AsyncAF(string).lastIndexOfAF('test', -5); // Promise that resolves to 0
|
1420 | *
|
1421 | * AsyncAF(string).lastIndexOfAF('to', -7); // Promise that resolves to -1
|
1422 | *
|
1423 | * // lastIndexOfAF on an array-like object
|
1424 | * (async function () {
|
1425 | * const lastIndexOf2 = await AsyncAF(arguments).lastIndexOfAF(2);
|
1426 | * console.log(`the last index of 2 in the arguments array-like object is ${lastIndexOf2}`)
|
1427 | * })(1, 1, 2, 2, 3, 3); // the last index of 2 in the arguments array-like object is 3
|
1428 | *
|
1429 | * @since 3.6.0
|
1430 | * @see lastIndexOf (alias)
|
1431 | * @see {@link AsyncAF#series series.lastIndexOfAF}
|
1432 | * @memberof AsyncAF#
|
1433 | */
|
1434 |
|
1435 | const lastIndexOfAF = function lastIndexOfAF(searchItem) {
|
1436 | let fromIndex = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : undefined;
|
1437 | return this.then(arrOrStr => {
|
1438 | if (!Object(_internal_permissiveIsArrayLike__WEBPACK_IMPORTED_MODULE_0__["default"])(arrOrStr)) throw TypeError("lastIndexOfAF cannot be called on ".concat(arrOrStr, ", only on an Array, String, or array-like Object"));
|
1439 | const len = arrOrStr.length >>> 0;
|
1440 | let fromIdx = Number(fromIndex);
|
1441 | if (Number.isNaN(fromIdx)) fromIdx = len - 1;
|
1442 | return typeof arrOrStr === 'string' ? arrOrStr.lastIndexOf(searchItem, fromIdx) : this.inSeries ? function seriesLastIndexOfAF(i) {
|
1443 | return Promise.resolve(arrOrStr[i]).then(el => {
|
1444 | if (i in arrOrStr && el === searchItem) return i;
|
1445 | if (i <= 0) return -1;
|
1446 | return seriesLastIndexOfAF(i - 1);
|
1447 | });
|
1448 | }(Math.min(fromIdx >= 0 ? fromIdx : Math.max(len - Math.abs(fromIdx), 0), len - 1)) : Object(_internal_resolve__WEBPACK_IMPORTED_MODULE_1__["parallel"])(arrOrStr).then(arr => arr.lastIndexOf(searchItem, fromIdx));
|
1449 | });
|
1450 | };
|
1451 |
|
1452 | /* harmony default export */ __webpack_exports__["default"] = (lastIndexOfAF);
|
1453 |
|
1454 | /***/ }),
|
1455 |
|
1456 | /***/ "./lib/methods/arrays/mapAF.js":
|
1457 | /***/ (function(module, __webpack_exports__, __webpack_require__) {
|
1458 |
|
1459 | ;
|
1460 | __webpack_require__.r(__webpack_exports__);
|
1461 | /* harmony import */ var _internal_commonCallback__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__("./lib/methods/_internal/commonCallback.js");
|
1462 | /* harmony import */ var _internal_permissiveIsArrayLike__WEBPACK_IMPORTED_MODULE_1__ = __webpack_require__("./lib/methods/_internal/permissiveIsArrayLike.js");
|
1463 | /* harmony import */ var _internal_promiseAllWithHoles__WEBPACK_IMPORTED_MODULE_2__ = __webpack_require__("./lib/methods/_internal/promiseAllWithHoles.js");
|
1464 | /* harmony import */ var _internal_resolve__WEBPACK_IMPORTED_MODULE_3__ = __webpack_require__("./lib/methods/_internal/resolve.js");
|
1465 | // eslint-disable-line no-unused-vars
|
1466 |
|
1467 |
|
1468 |
|
1469 |
|
1470 | /**
|
1471 | * creates a new `Array` with the results of calling a provided function on every element in the original array
|
1472 | *
|
1473 | * if any elements are a `Promise`, they will first be resolved in parallel and then processed
|
1474 | *
|
1475 | * *Note*: if you'd rather resolve and process elements in series, consider using `series.mapAF` or its alias, `io.mapAF`
|
1476 | *
|
1477 | * @param {callback} callback function that produces an element of the new `Array`
|
1478 | *
|
1479 | * `callback` accepts three arguments:
|
1480 | * - `currentValue` value of the current element being processed in the array
|
1481 | * - `index`*`(optional)`* index of `currentValue` in the array
|
1482 | * - `array`*`(optional)`* the array that mapAF is being applied to
|
1483 | * @param {Object=} thisArg value to use as `this` when executing `callback`
|
1484 | * @returns {Promise.<Array>} `Promise` that resolves to a new `Array` with each element being the result of calling `callback` on each original element
|
1485 | * @example
|
1486 | *
|
1487 | * const promises = [1, 2].map(n => Promise.resolve(n));
|
1488 | *
|
1489 | *
|
1490 | * // basic usage
|
1491 | * const doubled = AsyncAF(promises).mapAF(el => el * 2);
|
1492 | *
|
1493 | * console.log(doubled); // Promise that resolves to [2, 4]
|
1494 | *
|
1495 | * AsyncAF.logAF(doubled); // logs [2, 4]
|
1496 | *
|
1497 | *
|
1498 | * // using .then
|
1499 | * AsyncAF(promises).mapAF(el => el * 3).then(tripled => {
|
1500 | * console.log(tripled); // logs [3, 6]
|
1501 | * });
|
1502 | *
|
1503 | *
|
1504 | * // inside an async function
|
1505 | * (async () => {
|
1506 | * const quadrupled = await AsyncAF(promises).mapAF(
|
1507 | * el => el * 4
|
1508 | * );
|
1509 | * console.log(quadrupled); // logs [4, 8]
|
1510 | * })();
|
1511 | * @since 3.0.0
|
1512 | * @see map (alias)
|
1513 | * @see {@link AsyncAF#series series.mapAF}
|
1514 | * @memberof AsyncAF#
|
1515 | */
|
1516 |
|
1517 | const mapAF = function mapAF(callback) {
|
1518 | let thisArg = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : undefined;
|
1519 | return this.then(arr => {
|
1520 | if (!Object(_internal_permissiveIsArrayLike__WEBPACK_IMPORTED_MODULE_1__["default"])(arr)) throw TypeError("mapAF cannot be called on ".concat(arr, ", only on an Array or array-like Object"));
|
1521 | if (typeof callback !== 'function') throw TypeError("".concat(callback, " is not a function"));
|
1522 | return this.inSeries ? Object(_internal_resolve__WEBPACK_IMPORTED_MODULE_3__["serial"])(arr).then(arr => arr.reduce((map, el, i, arr) => map.then(map => {
|
1523 | map[i] = Promise.resolve(callback.call(thisArg, el, i, arr));
|
1524 | return Object(_internal_promiseAllWithHoles__WEBPACK_IMPORTED_MODULE_2__["default"])(map);
|
1525 | }), Promise.resolve(Array(arr.length >>> 0)))) : Object(_internal_resolve__WEBPACK_IMPORTED_MODULE_3__["parallel"])(arr, callback, thisArg);
|
1526 | });
|
1527 | };
|
1528 |
|
1529 | /* harmony default export */ __webpack_exports__["default"] = (mapAF);
|
1530 |
|
1531 | /***/ }),
|
1532 |
|
1533 | /***/ "./lib/methods/arrays/reduceAF.js":
|
1534 | /***/ (function(module, __webpack_exports__, __webpack_require__) {
|
1535 |
|
1536 | ;
|
1537 |
|
1538 | // CONCATENATED MODULE: ./lib/methods/_internal/reduceCallback.js
|
1539 | /* eslint-disable no-unused-vars, valid-jsdoc */
|
1540 |
|
1541 | /**
|
1542 | * @typedef {callback} _
|
1543 | * @param {?} accumulator
|
1544 | * @param {?} currentValue
|
1545 | * @param {Number=} index
|
1546 | * @param {[]=} array
|
1547 | */
|
1548 | function reduceCallback_callback(accumulator, currentValue, index, array) {}
|
1549 |
|
1550 | /* harmony default export */ var reduceCallback = (reduceCallback_callback);
|
1551 | // EXTERNAL MODULE: ./lib/methods/_internal/permissiveIsArrayLike.js
|
1552 | var permissiveIsArrayLike = __webpack_require__("./lib/methods/_internal/permissiveIsArrayLike.js");
|
1553 |
|
1554 | // EXTERNAL MODULE: ./lib/methods/_internal/resolve.js
|
1555 | var resolve = __webpack_require__("./lib/methods/_internal/resolve.js");
|
1556 |
|
1557 | // CONCATENATED MODULE: ./lib/methods/arrays/reduceAF.js
|
1558 | // eslint-disable-line no-unused-vars
|
1559 |
|
1560 |
|
1561 |
|
1562 | /* eslint-disable prefer-rest-params */
|
1563 |
|
1564 | /**
|
1565 | * applies a function against an accumulator and each element in an array (from left to right) to reduce it to a single value
|
1566 | *
|
1567 | * if any elements are a `Promise`, they will first be resolved in parallel and then processed in series
|
1568 | *
|
1569 | * *Note*: if this behavior is not desirable, consider using `series.reduceAF` or its alias, `io.reduceAF`; that way, if any elements are a `Promise`, they will both be resolved in series _and_ processed in series
|
1570 | *
|
1571 | * @param {callback} callback function to execute for each element
|
1572 | *
|
1573 | * `callback` accepts up to four arguments:
|
1574 | * - `accumulator` accumulates the callback's return values; the accumulated value previously returned in the last invocation of the callback, or initialValue, if supplied
|
1575 | * - `currentValue` value of the current element being processed in the array
|
1576 | * - `index`*`(optional)`* index of `currentValue` in the array
|
1577 | * - `array`*`(optional)`* the array that `reduceAF` is being applied to
|
1578 | * @param {any=} initialValue value to use as the first argument to the first call of the callback; if no initial value is supplied, the first element in the array will be used; note: calling reduceAF on an empty array with no initial value will throw an error
|
1579 | * @returns {Promise.<any>} `Promise` that resolves to the reduced value
|
1580 | * @example
|
1581 | *
|
1582 | * const promises = [1, 2, 3].map(n => Promise.resolve(n));
|
1583 | *
|
1584 | *
|
1585 | * // basic usage
|
1586 | * const sum = AsyncAF(promises).reduceAF((sum, num) => sum + num);
|
1587 | *
|
1588 | * console.log(sum); // Promise that resolves to 6
|
1589 | *
|
1590 | * AsyncAF.logAF(sum); // logs 6
|
1591 | *
|
1592 | *
|
1593 | * // using .then
|
1594 | * AsyncAF(promises).reduceAF((sum, num) => sum + num).then(sum => {
|
1595 | * console.log(sum); // logs 6
|
1596 | * });
|
1597 | *
|
1598 | *
|
1599 | * // inside an async function
|
1600 | * (async () => {
|
1601 | * const sum = await AsyncAF(promises).reduceAF((sum, num) => sum + num);
|
1602 | * console.log(sum); // logs 6
|
1603 | * })();
|
1604 | *
|
1605 | *
|
1606 | * // using an initial value
|
1607 | * AsyncAF(promises).reduceAF((sum, num) => sum + num, 12) // Promise that resolves to 18
|
1608 | * @since 3.1.0
|
1609 | * @see reduce (alias)
|
1610 | * @see {@link AsyncAF#series series.reduceAF}
|
1611 | * @memberof AsyncAF#
|
1612 | */
|
1613 |
|
1614 | const reduceAF_reduceAF = function reduceAF(callback
|
1615 | /* , initialValue */
|
1616 | ) {
|
1617 | return this.then(arr => {
|
1618 | if (!Object(permissiveIsArrayLike["default"])(arr)) throw TypeError("reduceAF cannot be called on ".concat(arr, ", only on an Array or array-like Object"));
|
1619 | if (typeof callback !== 'function') throw TypeError("".concat(callback, " is not a function"));
|
1620 | const length = arr.length >>> 0;
|
1621 | if (!length && arguments.length === 1) throw TypeError('reduceAF cannot be called on an empty array without an initial value');
|
1622 | if (!length) return arguments[1];
|
1623 |
|
1624 | const hole = i => !(i in arr);
|
1625 |
|
1626 | let i = 0;
|
1627 | let acc;
|
1628 |
|
1629 | if (arguments.length === 2) {
|
1630 | [, acc] = arguments;
|
1631 | } else {
|
1632 | while (hole(i)) i++;
|
1633 |
|
1634 | acc = arr[i++];
|
1635 | }
|
1636 |
|
1637 | return (this.inSeries ? resolve["serial"] : resolve["parallel"])(arr).then(arr => {
|
1638 | const reduceAF = (acc, i) => Promise.resolve(acc).then(acc => Promise.resolve(!hole(i) ? callback(acc, arr[i], i, arr) : acc).then(acc => i === length - 1 ? acc : reduceAF(acc, i + 1)));
|
1639 |
|
1640 | return reduceAF(acc, i);
|
1641 | });
|
1642 | });
|
1643 | };
|
1644 |
|
1645 | /* harmony default export */ var arrays_reduceAF = __webpack_exports__["default"] = (reduceAF_reduceAF);
|
1646 |
|
1647 | /***/ }),
|
1648 |
|
1649 | /***/ "./lib/methods/arrays/someAF.js":
|
1650 | /***/ (function(module, __webpack_exports__, __webpack_require__) {
|
1651 |
|
1652 | ;
|
1653 | __webpack_require__.r(__webpack_exports__);
|
1654 | /* harmony import */ var _internal_commonCallback__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__("./lib/methods/_internal/commonCallback.js");
|
1655 | /* harmony import */ var _internal_permissiveIsArrayLike__WEBPACK_IMPORTED_MODULE_1__ = __webpack_require__("./lib/methods/_internal/permissiveIsArrayLike.js");
|
1656 | /* harmony import */ var _internal_resolve__WEBPACK_IMPORTED_MODULE_2__ = __webpack_require__("./lib/methods/_internal/resolve.js");
|
1657 | // eslint-disable-line no-unused-vars
|
1658 |
|
1659 |
|
1660 |
|
1661 | /**
|
1662 | * tests whether at least one element in the array passes the test implemented by the provided callback function
|
1663 | *
|
1664 | * if any elements are a `Promise`, they will first be resolved in parallel and then tested
|
1665 | *
|
1666 | * *Note*: since `someAF` 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.someAF` or its alias, `io.someAF`
|
1667 | *
|
1668 | * @param {callback} callback function that tests each element of the array
|
1669 | *
|
1670 | * `callback` accepts three arguments:
|
1671 | * - `currentValue` value of the current element being processed in the array
|
1672 | * - `index`*`(optional)`* index of `currentValue` in the array
|
1673 | * - `array`*`(optional)`* the array that `someAF` is being applied to
|
1674 | * @param {Object=} thisArg value to use as `this` when executing `callback`
|
1675 | * @returns {Promise.<Boolean>} `Promise` that resolves to `true` if the callback function returns a truthy value for any array element; otherwise, `false`
|
1676 | * @example
|
1677 | *
|
1678 | * const promises = [1, 2, 3].map(n => Promise.resolve(n));
|
1679 | *
|
1680 | *
|
1681 | * // basic usage
|
1682 | * const someAreEven = AsyncAF(promises).someAF(n => n % 2 === 0);
|
1683 | *
|
1684 | * console.log(someAreEven); // Promise that resolves to true
|
1685 | *
|
1686 | * AsyncAF.logAF(someAreEven); // logs true
|
1687 | *
|
1688 | *
|
1689 | * // using .then
|
1690 | * AsyncAF(promises).someAF(n => n % 2 === 0).then(someAreEven => {
|
1691 | * console.log(someAreEven); // logs true
|
1692 | * });
|
1693 | *
|
1694 | *
|
1695 | * // inside an async function
|
1696 | * (async () => {
|
1697 | * const someAreStrings = await AsyncAF(promises).someAF(
|
1698 | * n => typeof n === 'string'
|
1699 | * );
|
1700 | * console.log(someAreStrings); // logs false
|
1701 | * })();
|
1702 | * @since 3.3.0
|
1703 | * @see some (alias)
|
1704 | * @see {@link AsyncAF#series series.someAF}
|
1705 | * @memberof AsyncAF#
|
1706 | */
|
1707 |
|
1708 | const someAF = function someAF(callback) {
|
1709 | let thisArg = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : undefined;
|
1710 | return this.then(arr => {
|
1711 | if (!Object(_internal_permissiveIsArrayLike__WEBPACK_IMPORTED_MODULE_1__["default"])(arr)) throw TypeError("someAF cannot be called on ".concat(arr, ", only on an Array or array-like Object"));
|
1712 | if (typeof callback !== 'function') throw TypeError("".concat(callback, " is not a function"));
|
1713 | const length = arr.length >>> 0;
|
1714 | return this.inSeries ? (length || false) && function seriesSomeAF(arr, i) {
|
1715 | const hole = !(i in arr);
|
1716 | return Promise.resolve(arr[i]).then(el => {
|
1717 | arr[i] = el;
|
1718 | return Promise.resolve(!hole && callback.call(thisArg, el, i, arr)).then(bool => {
|
1719 | if (bool && !hole) return true;
|
1720 | if (i === length - 1) return false;
|
1721 | return seriesSomeAF(arr, i + 1);
|
1722 | });
|
1723 | });
|
1724 | }(Array.prototype.slice.call(arr), 0) : Object(_internal_resolve__WEBPACK_IMPORTED_MODULE_2__["parallel"])(arr, callback, thisArg).then(bools => bools.some(Boolean));
|
1725 | });
|
1726 | };
|
1727 |
|
1728 | /* harmony default export */ __webpack_exports__["default"] = (someAF);
|
1729 |
|
1730 | /***/ }),
|
1731 |
|
1732 | /***/ "./lib/methods/other/logAF.js":
|
1733 | /***/ (function(module, __webpack_exports__, __webpack_require__) {
|
1734 |
|
1735 | ;
|
1736 |
|
1737 | // CONCATENATED MODULE: ./lib/methods/_internal/logging.js
|
1738 | /* eslint-disable no-console */
|
1739 | const wrappedLog = function wrappedLog() {
|
1740 | console && console.log && console.log(...arguments);
|
1741 | };
|
1742 |
|
1743 | const wrappedWarn = function wrappedWarn() {
|
1744 | console && console.warn && console.warn(...arguments);
|
1745 | };
|
1746 |
|
1747 |
|
1748 | // CONCATENATED MODULE: ./lib/methods/other/logAfHelpers/logAfOptions.js
|
1749 |
|
1750 | /**
|
1751 | * Sets logging options for {@link AsyncAF#logAF logAF}
|
1752 | *
|
1753 | * accepts an options object with the following optional properties:
|
1754 | * - label (`Boolean`) - set to `false` to disable logging the location of calls to logAF
|
1755 | * - duration (`Boolean`) - set to `false` to disable logging the time it takes (in secs) to complete each call to logAF
|
1756 | * - labelFormat (`String`|`Function`) - alters the format of logAF labels; choose between `file` (*default*), `path`, `parent`, `arrow`, or a custom string or function
|
1757 | *
|
1758 | * ```js
|
1759 | * const promise = new Promise(resolve => setTimeout(
|
1760 | * () => resolve(1), 1000)
|
1761 | * );
|
1762 | * ```
|
1763 | * **default logging**
|
1764 | * ```js
|
1765 | * logAF(promise, 2);
|
1766 | *
|
1767 | * // @filename.js:24:1:
|
1768 | * // 1 2
|
1769 | * // in 0.998 secs
|
1770 | * ```
|
1771 | * **turn off label**
|
1772 | * ```js
|
1773 | * logAF.options({ label: false });
|
1774 | * logAF(promise, 2);
|
1775 | *
|
1776 | * // 1 2
|
1777 | * // in 0.999 secs
|
1778 | * ```
|
1779 | * **turn off duration**
|
1780 | * ```js
|
1781 | * logAF.options({ duration: false });
|
1782 | * logAF(promise, 2);
|
1783 | *
|
1784 | * // @filename.js:24:1:
|
1785 | * // 1 2
|
1786 | * ```
|
1787 | * **change labelFormat**
|
1788 | *
|
1789 | * ● file (*default*)
|
1790 | *
|
1791 | * ```js
|
1792 | * logAF.options({ labelFormat: 'file' });
|
1793 | * logAF(promise, 2);
|
1794 | *
|
1795 | * // @filename.js:24:1:
|
1796 | * // 1 2
|
1797 | * // in 0.998 secs
|
1798 | * ```
|
1799 | * ● path
|
1800 | *
|
1801 | * ```js
|
1802 | * logAF.options({ labelFormat: 'path' });
|
1803 | * logAF(promise, 2);
|
1804 | *
|
1805 | * // @/Path/to/current/directory/filename.js:24:1:
|
1806 | * // 1 2
|
1807 | * // in 0.997 secs
|
1808 | * ```
|
1809 | * ● parent
|
1810 | *
|
1811 | * ```js
|
1812 | * logAF.options({ labelFormat: 'parent' });
|
1813 | * logAF(promise, 2);
|
1814 | *
|
1815 | * // @parentDirectory/filename.js:24:1:
|
1816 | * // 1 2
|
1817 | * // in 0.998 secs
|
1818 | * ```
|
1819 | * ● arrow
|
1820 | *
|
1821 | * ```js
|
1822 | * logAF.options({ labelFormat: 'arrow' });
|
1823 | * logAF(promise, 2);
|
1824 | *
|
1825 | * // ========================> 1 2
|
1826 | * // in 0.999 secs
|
1827 | * ```
|
1828 | *
|
1829 | * ● custom (create your own labelFormat)
|
1830 | * - to set a custom labelFormat, set it to any string other than the formats above
|
1831 | *
|
1832 | * ```js
|
1833 | * logAF.options({
|
1834 | * labelFormat: 'I logged this:'
|
1835 | * });
|
1836 | * logAF(promise, 2);
|
1837 | *
|
1838 | * // I logged this: 1 2
|
1839 | * // in 1.000 secs
|
1840 | * ```
|
1841 | *
|
1842 | * - labelFormat also accepts a function with access to an object containing the location variables `file`, `path`, `parent`, `arrow`, `line`, and `col`
|
1843 | *
|
1844 | * e.g., to set the labelFormat to `file:line:col =>`:
|
1845 | * ```js
|
1846 | * logAF.options({
|
1847 | * labelFormat: ({file, line, col}) => `${file}:${line}:${col} =>`
|
1848 | * });
|
1849 | * logAF(promise, 2);
|
1850 | *
|
1851 | * // filename.js:24:1 => 1 2
|
1852 | * // in 0.998 secs
|
1853 | * ```
|
1854 | *
|
1855 | * and just to demonstrate all the location variables in one custom format:
|
1856 | * ```js
|
1857 | * logAF.options({
|
1858 | * labelFormat: ({arrow, line, col, parent, file, path}) =>
|
1859 | * `${arrow}
|
1860 | * line: ${line}
|
1861 | * col: ${col}
|
1862 | * parent: ${parent}
|
1863 | * file: ${file}
|
1864 | * path: ${path}
|
1865 | * `
|
1866 | * });
|
1867 | * logAF(promise, 2);
|
1868 | *
|
1869 | * // ========================>
|
1870 | * // line: 24
|
1871 | * // col: 1
|
1872 | * // parent: parentDirectory/
|
1873 | * // file: filename.js
|
1874 | * // path: /Full/path/to/the/parentDirectory/
|
1875 | * // 1 2
|
1876 | * // in 0.998 secs
|
1877 | * ```
|
1878 | *
|
1879 | * to reset `logAF.options` to its default values, call `logAF.options.reset`
|
1880 | * ```js
|
1881 | * logAF.options.reset();
|
1882 | *
|
1883 | * // options are now:
|
1884 | * // label: true,
|
1885 | * // duration: true,
|
1886 | * // labelFormat: 'file'
|
1887 | * ```
|
1888 | *
|
1889 | * @static
|
1890 | * @param {Object} options the options for logAF
|
1891 | * @param {Boolean} [options.label=true] set to false to turn off the label
|
1892 | * @param {Boolean} [options.duration=true] set to false to turn off duration
|
1893 | * @param {String|Function} [options.labelFormat=file] see examples for sample label formats
|
1894 | * @returns {undefined} sets the options for logAF
|
1895 | * @see {@link AsyncAF#logAF logAF}
|
1896 | * @see logAF.options.reset to reset options to default
|
1897 | * @memberof AsyncAF
|
1898 | * @alias AsyncAF#logAF_options
|
1899 | */
|
1900 |
|
1901 | const logAfOptions_logAfOptions = function logAfOptions() {
|
1902 | let options = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {};
|
1903 | const {
|
1904 | label,
|
1905 | duration,
|
1906 | labelFormat
|
1907 | } = options;
|
1908 | if (typeof label === 'boolean') other_logAF.label = label;
|
1909 | if (typeof duration === 'boolean') other_logAF.duration = duration;
|
1910 | if (labelFormat) if (typeof labelFormat === 'string' || typeof labelFormat === 'function') other_logAF.labelFormat = labelFormat;else other_logAF.wrappedWarn('Warning: logAF labelFormat option must be set to \'file\' (default), \'path\', \'parent\', \'arrow\', or a custom string or function\n');
|
1911 | };
|
1912 |
|
1913 | /* harmony default export */ var logAfHelpers_logAfOptions = (logAfOptions_logAfOptions);
|
1914 | // CONCATENATED MODULE: ./lib/methods/other/logAfHelpers/customFormat.js
|
1915 | function _templateObject4() {
|
1916 | const data = _taggedTemplateLiteral(["/"]);
|
1917 |
|
1918 | _templateObject4 = function _templateObject4() {
|
1919 | return data;
|
1920 | };
|
1921 |
|
1922 | return data;
|
1923 | }
|
1924 |
|
1925 | function _templateObject3() {
|
1926 | const data = _taggedTemplateLiteral(["/"]);
|
1927 |
|
1928 | _templateObject3 = function _templateObject3() {
|
1929 | return data;
|
1930 | };
|
1931 |
|
1932 | return data;
|
1933 | }
|
1934 |
|
1935 | function _templateObject2() {
|
1936 | const data = _taggedTemplateLiteral(["/"]);
|
1937 |
|
1938 | _templateObject2 = function _templateObject2() {
|
1939 | return data;
|
1940 | };
|
1941 |
|
1942 | return data;
|
1943 | }
|
1944 |
|
1945 | function _templateObject() {
|
1946 | const data = _taggedTemplateLiteral([":"]);
|
1947 |
|
1948 | _templateObject = function _templateObject() {
|
1949 | return data;
|
1950 | };
|
1951 |
|
1952 | return data;
|
1953 | }
|
1954 |
|
1955 | function _taggedTemplateLiteral(strings, raw) { if (!raw) { raw = strings.slice(0); } return Object.freeze(Object.defineProperties(strings, { raw: { value: Object.freeze(raw) } })); }
|
1956 |
|
1957 | const custom = (format, fullPath, arrow) => {
|
1958 | if (typeof format === 'string') return format;
|
1959 | let [path, line, col] = fullPath.split(_templateObject()); // eslint-disable-line prefer-const
|
1960 |
|
1961 | path = path.split(_templateObject2());
|
1962 | const file = path.pop();
|
1963 | path = path.join(_templateObject3());
|
1964 | const parent = "".concat(path.split(_templateObject4()).pop(), "/");
|
1965 | path += '/';
|
1966 | return format({
|
1967 | path,
|
1968 | line,
|
1969 | col,
|
1970 | file,
|
1971 | parent,
|
1972 | arrow
|
1973 | });
|
1974 | };
|
1975 |
|
1976 | /* harmony default export */ var customFormat = (custom);
|
1977 | // CONCATENATED MODULE: ./lib/methods/other/logAfHelpers/setFormat.js
|
1978 | function setFormat_templateObject4() {
|
1979 | const data = setFormat_taggedTemplateLiteral(["/"]);
|
1980 |
|
1981 | setFormat_templateObject4 = function _templateObject4() {
|
1982 | return data;
|
1983 | };
|
1984 |
|
1985 | return data;
|
1986 | }
|
1987 |
|
1988 | function setFormat_templateObject3() {
|
1989 | const data = setFormat_taggedTemplateLiteral(["/"]);
|
1990 |
|
1991 | setFormat_templateObject3 = function _templateObject3() {
|
1992 | return data;
|
1993 | };
|
1994 |
|
1995 | return data;
|
1996 | }
|
1997 |
|
1998 | function setFormat_templateObject2() {
|
1999 | const data = setFormat_taggedTemplateLiteral(["/"]);
|
2000 |
|
2001 | setFormat_templateObject2 = function _templateObject2() {
|
2002 | return data;
|
2003 | };
|
2004 |
|
2005 | return data;
|
2006 | }
|
2007 |
|
2008 | function setFormat_templateObject() {
|
2009 | const data = setFormat_taggedTemplateLiteral(["\n"], ["\\n"]);
|
2010 |
|
2011 | setFormat_templateObject = function _templateObject() {
|
2012 | return data;
|
2013 | };
|
2014 |
|
2015 | return data;
|
2016 | }
|
2017 |
|
2018 | function setFormat_taggedTemplateLiteral(strings, raw) { if (!raw) { raw = strings.slice(0); } return Object.freeze(Object.defineProperties(strings, { raw: { value: Object.freeze(raw) } })); }
|
2019 |
|
2020 |
|
2021 |
|
2022 | const setFormat = labelFormat => {
|
2023 | const error = new Error();
|
2024 | /* istanbul ignore if */
|
2025 |
|
2026 | if (!error.stack) return '';
|
2027 | const [targetLine] = error.stack.split(setFormat_templateObject()).filter((_, i, lines) => /logAF(?:\s+|\s+\[.+\]\s+)\(/.test(lines[i ? i - 1 : i]) || /logAfStub(?:\s+|\s+\[.+\]\s+)\(/.test(lines[i]));
|
2028 | const fullPath = targetLine.slice(targetLine.indexOf(setFormat_templateObject2())).replace(')', '');
|
2029 | const target = fullPath.lastIndexOf(setFormat_templateObject3());
|
2030 | const formats = {
|
2031 | file() {
|
2032 | return "@".concat(fullPath.slice(target + 1), ":\n");
|
2033 | },
|
2034 |
|
2035 | path() {
|
2036 | return "@".concat(fullPath, ":\n");
|
2037 | },
|
2038 |
|
2039 | parent() {
|
2040 | const start = fullPath.slice(0, target).lastIndexOf(setFormat_templateObject4()) + 1;
|
2041 | return "@".concat(fullPath.slice(start), ":\n");
|
2042 | },
|
2043 |
|
2044 | arrow() {
|
2045 | return '========================>';
|
2046 | }
|
2047 |
|
2048 | };
|
2049 | return formats[labelFormat] ? formats[labelFormat]() : customFormat(labelFormat, fullPath, formats.arrow());
|
2050 | };
|
2051 |
|
2052 | /* harmony default export */ var logAfHelpers_setFormat = (setFormat);
|
2053 | // EXTERNAL MODULE: ./lib/methods/_internal/nameFunction.js
|
2054 | var nameFunction = __webpack_require__("./lib/methods/_internal/nameFunction.js");
|
2055 |
|
2056 | // CONCATENATED MODULE: ./lib/methods/other/logAF.js
|
2057 |
|
2058 |
|
2059 |
|
2060 |
|
2061 | /**
|
2062 | * logs items to the console in the order given
|
2063 | *
|
2064 | * if any items are a promise, they will first be resolved in parallel and then logged
|
2065 | *
|
2066 | * ```js
|
2067 | * import { logAF } from 'async-af';
|
2068 | *
|
2069 | * const promise = new Promise(resolve => setTimeout(
|
2070 | * () => resolve(2), 1000)
|
2071 | * );
|
2072 | *
|
2073 | * logAF(1, promise, 3);
|
2074 | *
|
2075 | * // @filename.js:6:12:
|
2076 | * // 1 2 3
|
2077 | * // in 0.998 secs
|
2078 | * ```
|
2079 | *
|
2080 | * **Note:** since logAF returns a promise, the items in the previous example would be logged *after* any synchronous calls to `console.log`
|
2081 | *
|
2082 | * to produce in-order logging with any surrounding calls to `console.log`, `await` logAF:
|
2083 | * ```js
|
2084 | * logAF.options({ label: false, duration: false });
|
2085 | *
|
2086 | * (async () => {
|
2087 | * console.log(1);
|
2088 | * // ...some code
|
2089 | * await logAF(promise);
|
2090 | * // ...some more code
|
2091 | * console.log(3);
|
2092 | * })();
|
2093 | *
|
2094 | * // 1
|
2095 | * // 2
|
2096 | * // 3
|
2097 | * ```
|
2098 | *
|
2099 | * **experimental feature**: the label may not work correctly in all environments; to turn the label off, set `label` to `false` in {@link AsyncAF#logAF_options logAF.options}, where you can also change the label's format
|
2100 | *
|
2101 | * @static
|
2102 | * @param {any} items The items to print (log to the console)
|
2103 | * @returns {Promise<undefined>} returns a `Promise` that logs items to the console
|
2104 | * @see log (alias)
|
2105 | * @see {@link AsyncAF#logAF_options logAF.options} to turn the label off or change its format
|
2106 | * @see logAF.options.reset to reset options to default
|
2107 | * @since 3.0.0
|
2108 | * @memberof AsyncAF
|
2109 | * @alias AsyncAF#logAF
|
2110 | */
|
2111 |
|
2112 | const logAF = function logAF() {
|
2113 | for (var _len = arguments.length, items = new Array(_len), _key = 0; _key < _len; _key++) {
|
2114 | items[_key] = arguments[_key];
|
2115 | }
|
2116 |
|
2117 | if (logAF.label) items.unshift(logAF.setFormat(logAF.labelFormat));
|
2118 | const start = Date.now();
|
2119 | return Promise.all(items).then(toLog => {
|
2120 | if (logAF.duration) {
|
2121 | const end = Date.now();
|
2122 | const numberOf = ((end - start) / 1000).toFixed(3);
|
2123 | toLog.push("\n in ".concat(numberOf, " secs"));
|
2124 | }
|
2125 |
|
2126 | logAF.wrappedLog('', ...toLog);
|
2127 | });
|
2128 | };
|
2129 |
|
2130 | Object.defineProperties(logAF, {
|
2131 | wrappedLog: {
|
2132 | value: wrappedLog,
|
2133 | writable: true
|
2134 | },
|
2135 | wrappedWarn: {
|
2136 | value: wrappedWarn,
|
2137 | writable: true
|
2138 | },
|
2139 | setFormat: {
|
2140 | value: logAfHelpers_setFormat,
|
2141 | writable: true
|
2142 | },
|
2143 | options: {
|
2144 | value: logAfHelpers_logAfOptions,
|
2145 | writable: true
|
2146 | }
|
2147 | });
|
2148 | (logAF.options.reset = function logAfOptionsReset() {
|
2149 | logAF.label = true;
|
2150 | logAF.labelFormat = 'file';
|
2151 | logAF.duration = true;
|
2152 | })();
|
2153 | /* harmony default export */ var other_logAF = __webpack_exports__["default"] = (Object(nameFunction["default"])(logAF, 'logAF'));
|
2154 |
|
2155 | /***/ }),
|
2156 |
|
2157 | /***/ "./lib/methods/strings/splitAF.js":
|
2158 | /***/ (function(module, __webpack_exports__, __webpack_require__) {
|
2159 |
|
2160 | ;
|
2161 | __webpack_require__.r(__webpack_exports__);
|
2162 | /**
|
2163 | * splits a string into an array of substrings, using a specified separator to determine where to make each split
|
2164 | *
|
2165 | * @param {String|RegExp=} separator a string or regular expression that denotes the points at which each split should occur
|
2166 | * - if a plain-text separator contains more than one character, the entire separator must be found to represent a split point
|
2167 | * - if separator is omitted or does not occur in the string, the array returned will contain one element consisting of the entire string
|
2168 | * - if separator is an empty string, the string is converted to an array of individual characters
|
2169 | * - if separator is a regular expression, the array returned will also contain any separators found as a result of matches within capturing parentheses
|
2170 | * @param {Number=} limit integer specifying a limit on the number of elements to be included in the result; when provided, the string is split at each occurrence of the specified separator but stops including elements when the limit is reached (or the end of the string, if reached sooner); any left-over text is not included in the result
|
2171 | * @returns {Promise.<String[]>} `Promise` that resolves to an array of strings, split at each point the separator occurs in the given string
|
2172 | * @example
|
2173 | *
|
2174 | * // basic usage
|
2175 | * const str = Promise.resolve('s; p; l; i; t');
|
2176 | *
|
2177 | * AsyncAF(str).splitAF('; '); // Promise that resolves to ['s', 'p', 'l', 'i', 't']
|
2178 | *
|
2179 | * // no separator specified or separator not found
|
2180 | * const str = Promise.resolve('splat');
|
2181 | *
|
2182 | * AsyncAF(str).splitAF(); // Promise that resolves to ['splat']
|
2183 | * AsyncAF(str).splitAF('n/a'); // Promise that resolves to ['splat']
|
2184 | *
|
2185 | * // split to individual characters
|
2186 | * const str = Promise.resolve('splitAF');
|
2187 | *
|
2188 | * AsyncAF(str).splitAF(''); // Promise that resolves to ['s', 'p', 'l', 'i', 't', 'A', 'F']
|
2189 | *
|
2190 | * // split on a regular expression
|
2191 | * const str = Promise.resolve('splittedAF');
|
2192 | *
|
2193 | * AsyncAF(str).splitAF(/sp|ted/); // Promise that resolves to ['', 'lit', 'AF']
|
2194 | *
|
2195 | * // and w/ capturing parentheses
|
2196 | *
|
2197 | * AsyncAF(str).splitAF(/(lit|AF)/); // Promise that resolves to ['sp', 'lit', '', 'AF', '']
|
2198 | *
|
2199 | * // setting limit
|
2200 | * const str = Promise.resolve('splitted');
|
2201 | *
|
2202 | * AsyncAF(str).splitAF('', 5); // Promise that resolves to ['s', 'p', 'l', 'i', 't']
|
2203 | * AsyncAF(str).splitAF('', 12); // Promise that resolves to ['s', 'p', 'l', 'i', 't', 't', 'e', 'd']
|
2204 | * AsyncAF(str).splitAF('', 0); // Promise that resolves to []
|
2205 | *
|
2206 | * @since 5.1.0
|
2207 | * @see split (alias)
|
2208 | * @memberof AsyncAF#
|
2209 | */
|
2210 | const splitAF = function splitAF() {
|
2211 | let separator = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : undefined;
|
2212 | let limit = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : undefined;
|
2213 | return this.then(str => {
|
2214 | if (typeof str !== 'string' || Array.isArray(str)) throw TypeError("splitAF may be called on a string but was called on ".concat(str));
|
2215 | return String.prototype.split.call(str, separator, limit);
|
2216 | });
|
2217 | };
|
2218 |
|
2219 | /* harmony default export */ __webpack_exports__["default"] = (splitAF);
|
2220 |
|
2221 | /***/ })
|
2222 |
|
2223 | /******/ })["default"];
|
2224 | });
|
2225 | //# sourceMappingURL=index.js.map |
\ | No newline at end of file |