Server IP : 85.214.239.14 / Your IP : 18.118.19.210 Web Server : Apache/2.4.62 (Debian) System : Linux h2886529.stratoserver.net 4.9.0 #1 SMP Tue Jan 9 19:45:01 MSK 2024 x86_64 User : www-data ( 33) PHP Version : 7.4.18 Disable Function : pcntl_alarm,pcntl_fork,pcntl_waitpid,pcntl_wait,pcntl_wifexited,pcntl_wifstopped,pcntl_wifsignaled,pcntl_wifcontinued,pcntl_wexitstatus,pcntl_wtermsig,pcntl_wstopsig,pcntl_signal,pcntl_signal_get_handler,pcntl_signal_dispatch,pcntl_get_last_error,pcntl_strerror,pcntl_sigprocmask,pcntl_sigwaitinfo,pcntl_sigtimedwait,pcntl_exec,pcntl_getpriority,pcntl_setpriority,pcntl_async_signals,pcntl_unshare, MySQL : OFF | cURL : OFF | WGET : ON | Perl : ON | Python : ON | Sudo : ON | Pkexec : OFF Directory : /proc/3/task/3/root/proc/3/root/lib/node_modules/pm2/node_modules/async/ |
Upload File : |
'use strict'; Object.defineProperty(exports, "__esModule", { value: true }); exports.default = groupBy; var _groupByLimit = require('./groupByLimit.js'); var _groupByLimit2 = _interopRequireDefault(_groupByLimit); function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; } /** * Returns a new object, where each value corresponds to an array of items, from * `coll`, that returned the corresponding key. That is, the keys of the object * correspond to the values passed to the `iteratee` callback. * * Note: Since this function applies the `iteratee` to each item in parallel, * there is no guarantee that the `iteratee` functions will complete in order. * However, the values for each key in the `result` will be in the same order as * the original `coll`. For Objects, the values will roughly be in the order of * the original Objects' keys (but this can vary across JavaScript engines). * * @name groupBy * @static * @memberOf module:Collections * @method * @category Collection * @param {Array|Iterable|AsyncIterable|Object} coll - A collection to iterate over. * @param {AsyncFunction} iteratee - An async function to apply to each item in * `coll`. * The iteratee should complete with a `key` to group the value under. * Invoked with (value, callback). * @param {Function} [callback] - A callback which is called when all `iteratee` * functions have finished, or an error occurs. Result is an `Object` whoses * properties are arrays of values which returned the corresponding key. * @returns {Promise} a promise, if no callback is passed * @example * * // dir1 is a directory that contains file1.txt, file2.txt * // dir2 is a directory that contains file3.txt, file4.txt * // dir3 is a directory that contains file5.txt * // dir4 does not exist * * const files = ['dir1/file1.txt','dir2','dir4'] * * // asynchronous function that detects file type as none, file, or directory * function detectFile(file, callback) { * fs.stat(file, function(err, stat) { * if (err) { * return callback(null, 'none'); * } * callback(null, stat.isDirectory() ? 'directory' : 'file'); * }); * } * * //Using callbacks * async.groupBy(files, detectFile, function(err, result) { * if(err) { * console.log(err); * } else { * console.log(result); * // { * // file: [ 'dir1/file1.txt' ], * // none: [ 'dir4' ], * // directory: [ 'dir2'] * // } * // result is object containing the files grouped by type * } * }); * * // Using Promises * async.groupBy(files, detectFile) * .then( result => { * console.log(result); * // { * // file: [ 'dir1/file1.txt' ], * // none: [ 'dir4' ], * // directory: [ 'dir2'] * // } * // result is object containing the files grouped by type * }).catch( err => { * console.log(err); * }); * * // Using async/await * async () => { * try { * let result = await async.groupBy(files, detectFile); * console.log(result); * // { * // file: [ 'dir1/file1.txt' ], * // none: [ 'dir4' ], * // directory: [ 'dir2'] * // } * // result is object containing the files grouped by type * } * catch (err) { * console.log(err); * } * } * */ function groupBy(coll, iteratee, callback) { return (0, _groupByLimit2.default)(coll, Infinity, iteratee, callback); } module.exports = exports.default;