CoolFace
Datasetpublic

basant307/AI_Governance_Project

sourceHugging Faceapache-2.0updated 2mo agoView on Hugging Face
0likes45downloads
select.js93 linesDownload Raw Back to async
1'use strict';2 3Object.defineProperty(exports, "__esModule", {4    value: true5});6 7var _filter2 = require('./internal/filter.js');8 9var _filter3 = _interopRequireDefault(_filter2);10 11var _eachOf = require('./eachOf.js');12 13var _eachOf2 = _interopRequireDefault(_eachOf);14 15var _awaitify = require('./internal/awaitify.js');16 17var _awaitify2 = _interopRequireDefault(_awaitify);18 19function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }20 21/**22 * Returns a new array of all the values in `coll` which pass an async truth23 * test. This operation is performed in parallel, but the results array will be24 * in the same order as the original.25 *26 * @name filter27 * @static28 * @memberOf module:Collections29 * @method30 * @alias select31 * @category Collection32 * @param {Array|Iterable|AsyncIterable|Object} coll - A collection to iterate over.33 * @param {Function} iteratee - A truth test to apply to each item in `coll`.34 * The `iteratee` is passed a `callback(err, truthValue)`, which must be called35 * with a boolean argument once it has completed. Invoked with (item, callback).36 * @param {Function} [callback] - A callback which is called after all the37 * `iteratee` functions have finished. Invoked with (err, results).38 * @returns {Promise} a promise, if no callback provided39 * @example40 *41 * // dir1 is a directory that contains file1.txt, file2.txt42 * // dir2 is a directory that contains file3.txt, file4.txt43 * // dir3 is a directory that contains file5.txt44 *45 * const files = ['dir1/file1.txt','dir2/file3.txt','dir3/file6.txt'];46 *47 * // asynchronous function that checks if a file exists48 * function fileExists(file, callback) {49 *    fs.access(file, fs.constants.F_OK, (err) => {50 *        callback(null, !err);51 *    });52 * }53 *54 * // Using callbacks55 * async.filter(files, fileExists, function(err, results) {56 *    if(err) {57 *        console.log(err);58 *    } else {59 *        console.log(results);60 *        // [ 'dir1/file1.txt', 'dir2/file3.txt' ]61 *        // results is now an array of the existing files62 *    }63 * });64 *65 * // Using Promises66 * async.filter(files, fileExists)67 * .then(results => {68 *     console.log(results);69 *     // [ 'dir1/file1.txt', 'dir2/file3.txt' ]70 *     // results is now an array of the existing files71 * }).catch(err => {72 *     console.log(err);73 * });74 *75 * // Using async/await76 * async () => {77 *     try {78 *         let results = await async.filter(files, fileExists);79 *         console.log(results);80 *         // [ 'dir1/file1.txt', 'dir2/file3.txt' ]81 *         // results is now an array of the existing files82 *     }83 *     catch (err) {84 *         console.log(err);85 *     }86 * }87 *88 */89function filter(coll, iteratee, callback) {90    return (0, _filter3.default)(_eachOf2.default, coll, iteratee, callback);91}92exports.default = (0, _awaitify2.default)(filter, 3);93module.exports = exports.default;
basant307/AI_Governance_Project · CoolFace