1 var arrayEvery = require('../internal/arrayEvery'),
2 baseCallback = require('../internal/baseCallback'),
3 baseEvery = require('../internal/baseEvery'),
4 isArray = require('../lang/isArray'),
5 isIterateeCall = require('../internal/isIterateeCall');
8 * Checks if `predicate` returns truthy for **all** elements of `collection`.
9 * The predicate is bound to `thisArg` and invoked with three arguments:
10 * (value, index|key, collection).
12 * If a property name is provided for `predicate` the created `_.property`
13 * style callback returns the property value of the given element.
15 * If a value is also provided for `thisArg` the created `_.matchesProperty`
16 * style callback returns `true` for elements that have a matching property
17 * value, else `false`.
19 * If an object is provided for `predicate` the created `_.matches` style
20 * callback returns `true` for elements that have the properties of the given
21 * object, else `false`.
26 * @category Collection
27 * @param {Array|Object|string} collection The collection to iterate over.
28 * @param {Function|Object|string} [predicate=_.identity] The function invoked
30 * @param {*} [thisArg] The `this` binding of `predicate`.
31 * @returns {boolean} Returns `true` if all elements pass the predicate check,
35 * _.every([true, 1, null, 'yes'], Boolean);
39 * { 'user': 'barney', 'active': false },
40 * { 'user': 'fred', 'active': false }
43 * // using the `_.matches` callback shorthand
44 * _.every(users, { 'user': 'barney', 'active': false });
47 * // using the `_.matchesProperty` callback shorthand
48 * _.every(users, 'active', false);
51 * // using the `_.property` callback shorthand
52 * _.every(users, 'active');
55 function every(collection, predicate, thisArg) {
56 var func = isArray(collection) ? arrayEvery : baseEvery;
57 if (thisArg && isIterateeCall(collection, predicate, thisArg)) {
58 predicate = undefined;
60 if (typeof predicate != 'function' || thisArg !== undefined) {
61 predicate = baseCallback(predicate, thisArg, 3);
63 return func(collection, predicate);
66 module.exports = every;