Lodash Internal baseMatches Module

3.2.0 · abandoned · verified Sun Apr 19

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

Warnings

Install

Imports

Quickstart

Demonstrates how to import and use the `baseMatches` function to create a predicate for object property matching.

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

view raw JSON →