This repository has been archived on 2020-11-02. You can view files and clone it, but cannot push or open issues or pull requests.
TripSit_Suite/node_modules/@sinonjs/commons/lib/every.js

28 lines
650 B
JavaScript
Raw Permalink Normal View History

"use strict";
/**
* Returns true when fn returns true for all members of obj.
* This is an every implementation that works for all iterables
*
* @param {object} obj
* @param {Function} fn
* @returns {boolean}
*/
module.exports = function every(obj, fn) {
var pass = true;
try {
/* eslint-disable-next-line local-rules/no-prototype-methods */
obj.forEach(function() {
if (!fn.apply(this, arguments)) {
// Throwing an error is the only way to break `forEach`
throw new Error();
}
});
} catch (e) {
pass = false;
}
return pass;
};