UNPKG

2.68 kBJavaScriptView Raw
1'use strict';
2
3Object.defineProperty(exports, "__esModule", {
4 value: true
5});
6
7var _reject2 = require('./internal/reject.js');
8
9var _reject3 = _interopRequireDefault(_reject2);
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 * The opposite of [`filter`]{@link module:Collections.filter}. Removes values that pass an `async` truth test.
23 *
24 * @name reject
25 * @static
26 * @memberOf module:Collections
27 * @method
28 * @see [async.filter]{@link module:Collections.filter}
29 * @category Collection
30 * @param {Array|Iterable|AsyncIterable|Object} coll - A collection to iterate over.
31 * @param {Function} iteratee - An async truth test to apply to each item in
32 * `coll`.
33 * The should complete with a boolean value as its `result`.
34 * Invoked with (item, callback).
35 * @param {Function} [callback] - A callback which is called after all the
36 * `iteratee` functions have finished. Invoked with (err, results).
37 * @returns {Promise} a promise, if no callback is passed
38 * @example
39 *
40 * // dir1 is a directory that contains file1.txt, file2.txt
41 * // dir2 is a directory that contains file3.txt, file4.txt
42 * // dir3 is a directory that contains file5.txt
43 *
44 * const fileList = ['dir1/file1.txt','dir2/file3.txt','dir3/file6.txt'];
45 *
46 * // asynchronous function that checks if a file exists
47 * function fileExists(file, callback) {
48 * fs.access(file, fs.constants.F_OK, (err) => {
49 * callback(null, !err);
50 * });
51 * }
52 *
53 * // Using callbacks
54 * async.reject(fileList, fileExists, function(err, results) {
55 * // [ 'dir3/file6.txt' ]
56 * // results now equals an array of the non-existing files
57 * });
58 *
59 * // Using Promises
60 * async.reject(fileList, fileExists)
61 * .then( results => {
62 * console.log(results);
63 * // [ 'dir3/file6.txt' ]
64 * // results now equals an array of the non-existing files
65 * }).catch( err => {
66 * console.log(err);
67 * });
68 *
69 * // Using async/await
70 * async () => {
71 * try {
72 * let results = await async.reject(fileList, fileExists);
73 * console.log(results);
74 * // [ 'dir3/file6.txt' ]
75 * // results now equals an array of the non-existing files
76 * }
77 * catch (err) {
78 * console.log(err);
79 * }
80 * }
81 *
82 */
83function reject(coll, iteratee, callback) {
84 return (0, _reject3.default)(_eachOf2.default, coll, iteratee, callback);
85}
86exports.default = (0, _awaitify2.default)(reject, 3);
87module.exports = exports.default;
\No newline at end of file