basant307/AI_Governance_Project
048
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 every element in `coll` satisfies an async test. If any23 * iteratee call returns `false`, the main `callback` is immediately called.24 *25 * @name every26 * @static27 * @memberOf module:Collections28 * @method29 * @alias all30 * @category Collection31 * @param {Array|Iterable|AsyncIterable|Object} coll - A collection to iterate over.32 * @param {AsyncFunction} iteratee - An async truth test to apply to each item33 * in the collection in parallel.34 * The iteratee must complete with a boolean result value.35 * Invoked with (item, callback).36 * @param {Function} [callback] - A callback which is called after all the37 * `iteratee` functions have finished. Result will be either `true` or `false`38 * depending on the values of the async tests. Invoked with (err, result).39 * @returns {Promise} a promise, if no callback provided40 * @example41 *42 * // dir1 is a directory that contains file1.txt, file2.txt43 * // dir2 is a directory that contains file3.txt, file4.txt44 * // dir3 is a directory that contains file5.txt45 * // dir4 does not exist46 *47 * const fileList = ['dir1/file1.txt','dir2/file3.txt','dir3/file5.txt'];48 * const withMissingFileList = ['file1.txt','file2.txt','file4.txt'];49 *50 * // asynchronous function that checks if a file exists51 * function fileExists(file, callback) {52 * fs.access(file, fs.constants.F_OK, (err) => {53 * callback(null, !err);54 * });55 * }56 *57 * // Using callbacks58 * async.every(fileList, fileExists, function(err, result) {59 * console.log(result);60 * // true61 * // result is true since every file exists62 * });63 *64 * async.every(withMissingFileList, fileExists, function(err, result) {65 * console.log(result);66 * // false67 * // result is false since NOT every file exists68 * });69 *70 * // Using Promises71 * async.every(fileList, fileExists)72 * .then( result => {73 * console.log(result);74 * // true75 * // result is true since every file exists76 * }).catch( err => {77 * console.log(err);78 * });79 *80 * async.every(withMissingFileList, fileExists)81 * .then( result => {82 * console.log(result);83 * // false84 * // result is false since NOT every file exists85 * }).catch( err => {86 * console.log(err);87 * });88 *89 * // Using async/await90 * async () => {91 * try {92 * let result = await async.every(fileList, fileExists);93 * console.log(result);94 * // true95 * // result is true since every file exists96 * }97 * catch (err) {98 * console.log(err);99 * }100 * }101 *102 * async () => {103 * try {104 * let result = await async.every(withMissingFileList, fileExists);105 * console.log(result);106 * // false107 * // result is false since NOT every file exists108 * }109 * catch (err) {110 * console.log(err);111 * }112 * }113 *114 */115function every(coll, iteratee, callback) {116 return (0, _createTester2.default)(bool => !bool, res => !res)(_eachOf2.default, coll, iteratee, callback);117}118exports.default = (0, _awaitify2.default)(every, 3);119module.exports = exports.default;