1 | ;
|
2 |
|
3 | Object.defineProperty(exports, "__esModule", {
|
4 | value: true
|
5 | });
|
6 |
|
7 | var _createTester = require('./internal/createTester.js');
|
8 |
|
9 | var _createTester2 = _interopRequireDefault(_createTester);
|
10 |
|
11 | var _eachOf = require('./eachOf.js');
|
12 |
|
13 | var _eachOf2 = _interopRequireDefault(_eachOf);
|
14 |
|
15 | var _awaitify = require('./internal/awaitify.js');
|
16 |
|
17 | var _awaitify2 = _interopRequireDefault(_awaitify);
|
18 |
|
19 | function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
|
20 |
|
21 | /**
|
22 | * Returns `true` if every element in `coll` satisfies an async test. If any
|
23 | * iteratee call returns `false`, the main `callback` is immediately called.
|
24 | *
|
25 | * @name every
|
26 | * @static
|
27 | * @memberOf module:Collections
|
28 | * @method
|
29 | * @alias all
|
30 | * @category Collection
|
31 | * @param {Array|Iterable|AsyncIterable|Object} coll - A collection to iterate over.
|
32 | * @param {AsyncFunction} iteratee - An async truth test to apply to each item
|
33 | * 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 the
|
37 | * `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 provided
|
40 | * @example
|
41 | *
|
42 | * // dir1 is a directory that contains file1.txt, file2.txt
|
43 | * // dir2 is a directory that contains file3.txt, file4.txt
|
44 | * // dir3 is a directory that contains file5.txt
|
45 | * // dir4 does not exist
|
46 | *
|
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 exists
|
51 | * function fileExists(file, callback) {
|
52 | * fs.access(file, fs.constants.F_OK, (err) => {
|
53 | * callback(null, !err);
|
54 | * });
|
55 | * }
|
56 | *
|
57 | * // Using callbacks
|
58 | * async.every(fileList, fileExists, function(err, result) {
|
59 | * console.log(result);
|
60 | * // true
|
61 | * // result is true since every file exists
|
62 | * });
|
63 | *
|
64 | * async.every(withMissingFileList, fileExists, function(err, result) {
|
65 | * console.log(result);
|
66 | * // false
|
67 | * // result is false since NOT every file exists
|
68 | * });
|
69 | *
|
70 | * // Using Promises
|
71 | * async.every(fileList, fileExists)
|
72 | * .then( result => {
|
73 | * console.log(result);
|
74 | * // true
|
75 | * // result is true since every file exists
|
76 | * }).catch( err => {
|
77 | * console.log(err);
|
78 | * });
|
79 | *
|
80 | * async.every(withMissingFileList, fileExists)
|
81 | * .then( result => {
|
82 | * console.log(result);
|
83 | * // false
|
84 | * // result is false since NOT every file exists
|
85 | * }).catch( err => {
|
86 | * console.log(err);
|
87 | * });
|
88 | *
|
89 | * // Using async/await
|
90 | * async () => {
|
91 | * try {
|
92 | * let result = await async.every(fileList, fileExists);
|
93 | * console.log(result);
|
94 | * // true
|
95 | * // result is true since every file exists
|
96 | * }
|
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 | * // false
|
107 | * // result is false since NOT every file exists
|
108 | * }
|
109 | * catch (err) {
|
110 | * console.log(err);
|
111 | * }
|
112 | * }
|
113 | *
|
114 | */
|
115 | function every(coll, iteratee, callback) {
|
116 | return (0, _createTester2.default)(bool => !bool, res => !res)(_eachOf2.default, coll, iteratee, callback);
|
117 | }
|
118 | exports.default = (0, _awaitify2.default)(every, 3);
|
119 | module.exports = exports.default; |
\ | No newline at end of file |