Lodash Internal Array Filter
This package, `lodash._arrayfilter`, provides a modularized, internal implementation of `arrayFilter` originally part of the Lodash v3 ecosystem. Released around 2014-2015, this version (`3.0.0`) predates the significant breaking changes and API refinements introduced with Lodash v4 (currently at `4.18.1`). While the main `lodash` library continues active development with a steady release cadence, `lodash._arrayfilter` as a standalone module is no longer actively maintained. Its original purpose was to allow granular imports of internal Lodash utilities for specific environments, a need largely superseded by modern JavaScript bundlers offering robust tree-shaking capabilities for the complete `lodash` package. It is a CommonJS-only module and is primarily compatible with other Lodash v3 components, making it largely unsuitable for contemporary projects using `lodash` v4+ or ES modules. Key differentiators at its time included extreme modularity for internal functions, but this approach is now considered legacy.
Common errors
-
TypeError: lodash._arrayfilter is not a function
cause Attempting to call the imported module directly when it might be an object or undefined, or using wrong import syntax that doesn't resolve to the function.fixEnsure you are using `const arrayFilter = require('lodash._arrayfilter');` and then correctly invoking `arrayFilter(collection, predicate)`. -
SyntaxError: Cannot use import statement outside a module
cause Using ES module `import` syntax (`import arrayFilter from 'lodash._arrayfilter';`) in a CommonJS environment or for a CommonJS-only package.fixChange your import statement to `const arrayFilter = require('lodash._arrayfilter');`.
Warnings
- breaking This package is a Lodash v3 internal utility. It is not compatible with Lodash v4+ APIs, which introduced significant breaking changes. Using it with a modern Lodash environment or expecting v4 behavior will likely lead to errors.
- deprecated This package represents a specific, older modular build strategy for Lodash internals. It is effectively abandoned as a standalone module in favor of using the main `lodash` package, which offers robust tree-shaking capabilities in modern bundlers, making granular imports unnecessary.
- gotcha This module is a CommonJS-only package. Attempting to use ES module `import` syntax will result in a runtime error or build failure.
- gotcha As an internal utility, `lodash._arrayfilter` may have specific assumptions about its execution context or arguments that differ from the public `_.filter` API, especially across major Lodash versions. Direct usage might not yield expected results without deep knowledge of Lodash v3 internals.
Install
-
npm install lodash._arrayfilter -
yarn add lodash._arrayfilter -
pnpm add lodash._arrayfilter
Imports
- arrayFilter
import arrayFilter from 'lodash._arrayfilter';
const arrayFilter = require('lodash._arrayfilter'); - arrayFilter (named)
import { arrayFilter } from 'lodash._arrayfilter';const arrayFilter = require('lodash._arrayfilter');
Quickstart
const arrayFilter = require('lodash._arrayfilter');
const users = [
{ 'user': 'barney', 'age': 36, 'active': true },
{ 'user': 'fred', 'age': 40, 'active': false },
{ 'user': 'pebbles', 'age': 1, 'active': true }
];
// This is an internal utility and might have specific expectations.
// For general use, prefer Array.prototype.filter or the main lodash `_.filter` (v4+).
const activeUsers = arrayFilter(users, (user) => user.active);
console.log(activeUsers);
// Expected output:
// [ { user: 'barney', age: 36, active: true }, { user: 'pebbles', age: 1, active: true } ]