reject.js 2.6 KB

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