CoolFace
Datasetpublic

basant307/AI_Governance_Project

sourceHugging Faceapache-2.0updated 2mo agoView on Hugging Face
0likes48downloads
any.js122 linesDownload Raw Back to async
1'use strict';2 3Object.defineProperty(exports, "__esModule", {4    value: true5});6 7var _createTester = require('./internal/createTester.js');8 9var _createTester2 = _interopRequireDefault(_createTester);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 `true` if at least one element in the `coll` satisfies an async test.23 * If any iteratee call returns `true`, the main `callback` is immediately24 * called.25 *26 * @name some27 * @static28 * @memberOf module:Collections29 * @method30 * @alias any31 * @category Collection32 * @param {Array|Iterable|AsyncIterable|Object} coll - A collection to iterate over.33 * @param {AsyncFunction} iteratee - An async truth test to apply to each item34 * in the collections in parallel.35 * The iteratee should complete with a boolean `result` value.36 * Invoked with (item, callback).37 * @param {Function} [callback] - A callback which is called as soon as any38 * iteratee returns `true`, or after all the iteratee functions have finished.39 * Result will be either `true` or `false` depending on the values of the async40 * tests. Invoked with (err, result).41 * @returns {Promise} a promise, if no callback provided42 * @example43 *44 * // dir1 is a directory that contains file1.txt, file2.txt45 * // dir2 is a directory that contains file3.txt, file4.txt46 * // dir3 is a directory that contains file5.txt47 * // dir4 does not exist48 *49 * // asynchronous function that checks if a file exists50 * function fileExists(file, callback) {51 *    fs.access(file, fs.constants.F_OK, (err) => {52 *        callback(null, !err);53 *    });54 * }55 *56 * // Using callbacks57 * async.some(['dir1/missing.txt','dir2/missing.txt','dir3/file5.txt'], fileExists,58 *    function(err, result) {59 *        console.log(result);60 *        // true61 *        // result is true since some file in the list exists62 *    }63 *);64 *65 * async.some(['dir1/missing.txt','dir2/missing.txt','dir4/missing.txt'], fileExists,66 *    function(err, result) {67 *        console.log(result);68 *        // false69 *        // result is false since none of the files exists70 *    }71 *);72 *73 * // Using Promises74 * async.some(['dir1/missing.txt','dir2/missing.txt','dir3/file5.txt'], fileExists)75 * .then( result => {76 *     console.log(result);77 *     // true78 *     // result is true since some file in the list exists79 * }).catch( err => {80 *     console.log(err);81 * });82 *83 * async.some(['dir1/missing.txt','dir2/missing.txt','dir4/missing.txt'], fileExists)84 * .then( result => {85 *     console.log(result);86 *     // false87 *     // result is false since none of the files exists88 * }).catch( err => {89 *     console.log(err);90 * });91 *92 * // Using async/await93 * async () => {94 *     try {95 *         let result = await async.some(['dir1/missing.txt','dir2/missing.txt','dir3/file5.txt'], fileExists);96 *         console.log(result);97 *         // true98 *         // result is true since some file in the list exists99 *     }100 *     catch (err) {101 *         console.log(err);102 *     }103 * }104 *105 * async () => {106 *     try {107 *         let result = await async.some(['dir1/missing.txt','dir2/missing.txt','dir4/missing.txt'], fileExists);108 *         console.log(result);109 *         // false110 *         // result is false since none of the files exists111 *     }112 *     catch (err) {113 *         console.log(err);114 *     }115 * }116 *117 */118function some(coll, iteratee, callback) {119    return (0, _createTester2.default)(Boolean, res => res)(_eachOf2.default, coll, iteratee, callback);120}121exports.default = (0, _awaitify2.default)(some, 3);122module.exports = exports.default;
basant307/AI_Governance_Project · CoolFace