every.js 665 B

123456789101112131415161718192021222324252627
  1. "use strict";
  2. /**
  3. * Returns true when fn returns true for all members of obj.
  4. * This is an every implementation that works for all iterables
  5. *
  6. * @param {object} obj
  7. * @param {Function} fn
  8. * @returns {boolean}
  9. */
  10. module.exports = function every(obj, fn) {
  11. var pass = true;
  12. try {
  13. // eslint-disable-next-line @sinonjs/no-prototype-methods/no-prototype-methods
  14. obj.forEach(function() {
  15. if (!fn.apply(this, arguments)) {
  16. // Throwing an error is the only way to break `forEach`
  17. throw new Error();
  18. }
  19. });
  20. } catch (e) {
  21. pass = false;
  22. }
  23. return pass;
  24. };