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 at least one element in the `coll` satisfies an async test.
|
23 | * If any iteratee call returns `true`, the main `callback` is immediately
|
24 | * called.
|
25 | *
|
26 | * @name some
|
27 | * @static
|
28 | * @memberOf module:Collections
|
29 | * @method
|
30 | * @alias any
|
31 | * @category Collection
|
32 | * @param {Array|Iterable|AsyncIterable|Object} coll - A collection to iterate over.
|
33 | * @param {AsyncFunction} iteratee - An async truth test to apply to each item
|
34 | * 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 any
|
38 | * 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 async
|
40 | * tests. Invoked with (err, result).
|
41 | * @returns {Promise} a promise, if no callback provided
|
42 | * @example
|
43 | *
|
44 | * // dir1 is a directory that contains file1.txt, file2.txt
|
45 | * // dir2 is a directory that contains file3.txt, file4.txt
|
46 | * // dir3 is a directory that contains file5.txt
|
47 | * // dir4 does not exist
|
48 | *
|
49 | * // asynchronous function that checks if a file exists
|
50 | * function fileExists(file, callback) {
|
51 | * fs.access(file, fs.constants.F_OK, (err) => {
|
52 | * callback(null, !err);
|
53 | * });
|
54 | * }
|
55 | *
|
56 | * // Using callbacks
|
57 | * async.some(['dir1/missing.txt','dir2/missing.txt','dir3/file5.txt'], fileExists,
|
58 | * function(err, result) {
|
59 | * console.log(result);
|
60 | * // true
|
61 | * // result is true since some file in the list exists
|
62 | * }
|
63 | *);
|
64 | *
|
65 | * async.some(['dir1/missing.txt','dir2/missing.txt','dir4/missing.txt'], fileExists,
|
66 | * function(err, result) {
|
67 | * console.log(result);
|
68 | * // false
|
69 | * // result is false since none of the files exists
|
70 | * }
|
71 | *);
|
72 | *
|
73 | * // Using Promises
|
74 | * async.some(['dir1/missing.txt','dir2/missing.txt','dir3/file5.txt'], fileExists)
|
75 | * .then( result => {
|
76 | * console.log(result);
|
77 | * // true
|
78 | * // result is true since some file in the list exists
|
79 | * }).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 | * // false
|
87 | * // result is false since none of the files exists
|
88 | * }).catch( err => {
|
89 | * console.log(err);
|
90 | * });
|
91 | *
|
92 | * // Using async/await
|
93 | * async () => {
|
94 | * try {
|
95 | * let result = await async.some(['dir1/missing.txt','dir2/missing.txt','dir3/file5.txt'], fileExists);
|
96 | * console.log(result);
|
97 | * // true
|
98 | * // result is true since some file in the list exists
|
99 | * }
|
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 | * // false
|
110 | * // result is false since none of the files exists
|
111 | * }
|
112 | * catch (err) {
|
113 | * console.log(err);
|
114 | * }
|
115 | * }
|
116 | *
|
117 | */
|
118 | function some(coll, iteratee, callback) {
|
119 | return (0, _createTester2.default)(Boolean, res => res)(_eachOf2.default, coll, iteratee, callback);
|
120 | }
|
121 | exports.default = (0, _awaitify2.default)(some, 3);
|
122 | module.exports = exports.default; |
\ | No newline at end of file |