Lodash Internal baseMatches Module
This package, `lodash._basematches`, exposes an internal utility function from Lodash v3, specifically `baseMatches`. It's part of Lodash's legacy modularization strategy (pre-v4) where core internal functions were published as individual npm packages. The `baseMatches` function itself is used internally by Lodash to create a predicate function for deep object comparison, similar to how `_.matches` works in the public API. This module is stable at version 3.2.0, which corresponds to the Lodash v3 release line. It is not actively maintained as a standalone module and is considered superseded by the main `lodash` package (v4.x and later) or `lodash-es` for modern usage. Its primary differentiation was being a single-purpose, highly optimized internal primitive available separately, though this approach is now largely deprecated in favor of comprehensive bundles and tree-shakable ES modules.
Common errors
-
ReferenceError: require is not defined
cause Attempting to use `require()` in an ES module context without proper transpilation or configuration, or directly using `import` with a CommonJS-only package.fixEnsure your environment supports CommonJS `require()` (e.g., Node.js without `"type": "module"` in package.json) or transpile your code if targeting a browser. For new projects, use `lodash` or `lodash-es` with native ESM imports. -
TypeError: (0 , _lodash_basematches.default) is not a function
cause Incorrectly trying to import a CommonJS module with `import baseMatches from 'lodash._basematches';` syntax, assuming a default export that doesn't exist.fixThis package only provides a named export accessible via CommonJS `require`. Change your import to `const baseMatches = require('lodash._basematches');`.
Warnings
- breaking This package is effectively abandoned. Its latest version is 3.2.0, corresponding to Lodash v3. Major changes in Lodash v4 mean this module is not compatible with or recommended for use alongside modern Lodash versions (v4.x and above).
- gotcha This module is strictly CommonJS. Attempting to import it using ES module syntax (`import ... from '...'`) in a modern JavaScript environment will result in errors.
- deprecated As an internal, legacy module, `lodash._basematches` does not receive security updates. While the function itself might be simple, its use in older, unmaintained applications could expose them to broader security issues if other Lodash v3 internals are present.
Install
-
npm install lodash._basematches -
yarn add lodash._basematches -
pnpm add lodash._basematches
Imports
- baseMatches
import { baseMatches } from 'lodash._basematches';const baseMatches = require('lodash._basematches'); - baseMatches (using default import syntax mistakenly)
import baseMatches from 'lodash._basematches';
const baseMatches = require('lodash._basematches');
Quickstart
const baseMatches = require('lodash._basematches');
// baseMatches takes a source object and returns a predicate function.
// The predicate function checks if an object has properties matching the source.
const source = { a: 1, b: 'test' };
const predicate = baseMatches(source);
console.log('Predicate function created:', typeof predicate === 'function');
const object1 = { a: 1, b: 'test', c: 3 };
const object2 = { a: 1, b: 'wrong' };
const object3 = { a: 1 };
console.log('Matching object1:', predicate(object1)); // Expected: true
console.log('Matching object2:', predicate(object2)); // Expected: false
console.log('Matching object3:', predicate(object3)); // Expected: false
const nestedSource = { user: { id: 123, name: 'Alice' } };
const nestedPredicate = baseMatches(nestedSource);
const data1 = { id: 1, user: { id: 123, name: 'Alice', email: 'a@example.com' } };
const data2 = { id: 2, user: { id: 456, name: 'Bob' } };
console.log('Matching data1 (nested):', nestedPredicate(data1)); // Expected: true
console.log('Matching data2 (nested):', nestedPredicate(data2)); // Expected: false