SIGN IN SIGN UP

A modern JavaScript utility library delivering modularity, performance, & extras.

0 0 9 JavaScript
2016-01-28 01:16:24 -08:00
define(['./_arrayFilter', './_baseFilter', './_baseIteratee', './isArray'], function(arrayFilter, baseFilter, baseIteratee, isArray) {
2015-12-16 17:53:20 -08:00
/**
* Iterates over elements of `collection`, returning an array of all elements
2016-03-26 00:00:01 -07:00
* `predicate` returns truthy for. The predicate is invoked with three
* arguments: (value, index|key, collection).
2015-12-16 17:53:20 -08:00
*
2016-07-24 09:52:04 -07:00
* **Note:** Unlike `_.remove`, this method returns a new array.
*
2015-12-16 17:53:20 -08:00
* @static
* @memberOf _
2016-03-26 00:00:01 -07:00
* @since 0.1.0
2015-12-16 17:53:20 -08:00
* @category Collection
* @param {Array|Object} collection The collection to iterate over.
2016-10-30 20:06:57 -07:00
* @param {Function} [predicate=_.identity] The function invoked per iteration.
2015-12-16 17:53:20 -08:00
* @returns {Array} Returns the new filtered array.
2016-04-19 22:17:16 -07:00
* @see _.reject
2015-12-16 17:53:20 -08:00
* @example
*
* var users = [
* { 'user': 'barney', 'age': 36, 'active': true },
* { 'user': 'fred', 'age': 40, 'active': false }
* ];
*
* _.filter(users, function(o) { return !o.active; });
* // => objects for ['fred']
*
2016-02-01 23:13:04 -08:00
* // The `_.matches` iteratee shorthand.
2015-12-16 17:53:20 -08:00
* _.filter(users, { 'age': 36, 'active': true });
* // => objects for ['barney']
*
2016-02-01 23:13:04 -08:00
* // The `_.matchesProperty` iteratee shorthand.
2015-12-16 17:53:20 -08:00
* _.filter(users, ['active', false]);
* // => objects for ['fred']
*
2016-02-01 23:13:04 -08:00
* // The `_.property` iteratee shorthand.
2015-12-16 17:53:20 -08:00
* _.filter(users, 'active');
* // => objects for ['barney']
Update lodash-amd to v4.17.21 + edadd45 (#6064) * Fix prototype pollution in _.set and related functions Prevents setting dangerous properties (__proto__, constructor, prototype) that could lead to prototype pollution vulnerabilities. * Fix command injection vulnerability in _.template - Add validation for the variable option to prevent injection attacks - Improve sourceURL whitespace normalization to prevent code injection * Fix cyclic value comparison in _.isEqual Properly checks both directions when comparing cyclic values to ensure correct equality comparisons for circular references. * Improve _.sortBy and _.orderBy performance and array handling - Add early return for empty arrays in sorted index operations - Improve array iteratee handling to support nested property paths - Add missing keysIn import in baseClone * Refactor _.trim, _.trimEnd, and _.trimStart implementations Extract shared trim logic into reusable utilities (_baseTrim, _trimmedEndIndex) for better code organization and consistency. Update related functions (toNumber, parseInt) to use new utilities. Improve comment accuracy. * Add documentation for predicate composition with _.overEvery and _.overSome Enhance documentation to show how _.matches and _.matchesProperty can be combined using _.overEvery and _.overSome for more powerful filtering. Add examples demonstrating shorthand predicate syntax. * Bump to v4.17.21 * Fix prototype pollution in _.unset and _.omit Prevent prototype pollution on baseUnset function by: - Blocking "__proto__" if not an own property - Blocking "constructor.prototype" chains (except when starting at primitive root) - Skipping non-string keys See: https://github.com/lodash/lodash/security/advisories/GHSA-xxjr-mmjv-4gpg * Update JSDoc documentation to align with main branch - Fix sortBy example ages (40 -> 30) for correct sort order demonstration - Fix _setCacheHas return type (number -> boolean)
2025-12-10 17:03:07 -05:00
*
* // Combining several predicates using `_.overEvery` or `_.overSome`.
* _.filter(users, _.overSome([{ 'age': 36 }, ['age', 40]]));
* // => objects for ['fred', 'barney']
2015-12-16 17:53:20 -08:00
*/
function filter(collection, predicate) {
var func = isArray(collection) ? arrayFilter : baseFilter;
return func(collection, baseIteratee(predicate, 3));
}
return filter;
});