Lodash.pairs Module
This package provides the `_.pairs` function from the Lodash utility library, specifically from the Lodash v3 era, as a standalone Node.js module. The `_.pairs` function converts an object into an array of `[key, value]` pairs. While originally part of a strategy for modularizing Lodash functions, this `lodash.pairs` package is at version 3.0.1 and was last published over a decade ago. It is considered deprecated in favor of direct imports from the main `lodash` package (which is currently at v4.18.1 and actively maintained) or, preferably, `lodash-es` for modern, tree-shakable ES Module environments. Relying on this older, single-function module can lead to outdated behavior, missed bug fixes, and potential security vulnerabilities present in the main Lodash library that have since been addressed in v4.x. Modern applications should use `lodash-es` or specific imports from `lodash` itself for optimized bundle sizes and access to the latest features and patches.
Common errors
-
TypeError: pairs is not a function
cause Attempting to use `_.pairs` from a partial or incorrect `lodash` import, or trying to use the CommonJS `lodash.pairs` module with an ES module import syntax.fixEnsure you are importing `pairs` correctly for your module system. For ES Modules: `import { pairs } from 'lodash-es';`. For CommonJS using the main `lodash` package: `const { pairs } = require('lodash');` (if using Lodash v4+ with a bundler that can cherry-pick) or `const pairs = require('lodash/pairs');`. For this specific `lodash.pairs` module (deprecated): `const pairs = require('lodash.pairs');`. -
ReferenceError: require is not defined
cause Attempting to use `require('lodash.pairs')` within an ES Module (ESM) file context in Node.js, where `require` is not globally available.fixIf your project uses ESM, you must use `import` statements. Replace `require('lodash.pairs')` with `import { pairs } from 'lodash-es';` or `import pairs from 'lodash/pairs';` (after installing `lodash` or `lodash-es`). Alternatively, if you must use the old `lodash.pairs` package, convert your file to CommonJS or use an interop solution.
Warnings
- breaking This `lodash.pairs` package is stuck at version 3.0.1 (published 11 years ago) and does not receive updates, bug fixes, or security patches from the main Lodash library, which is currently at v4.x. Its behavior might differ from `_.pairs` in Lodash v4.x due to breaking changes between Lodash v3 and v4.
- deprecated The pattern of using individual `lodash.<function>` modular packages like `lodash.pairs` is generally deprecated. Modern Lodash (v4+) favors `lodash-es` for tree-shakable ES module imports or direct cherry-picking from `lodash/functionName` paths for optimized bundle sizes.
- gotcha Using this outdated `lodash.pairs` package means your application will not benefit from critical security advisories and patches released for the main `lodash` library, such as prototype pollution fixes in v4.18.0 (GHSA-f23m-r3pf-42rh). Although `_.pairs` itself might not be directly vulnerable, relying on an unmaintained module introduces unnecessary risk.
Install
-
npm install lodash.pairs -
yarn add lodash.pairs -
pnpm add lodash.pairs
Imports
- pairs
var pairs = require('lodash.pairs');import { pairs } from 'lodash-es'; - pairs
import { pairs } from 'lodash';import pairs from 'lodash/pairs';
- pairs
import { pairs } from 'lodash.pairs';var pairs = require('lodash.pairs');
Quickstart
import { pairs } from 'lodash-es';
const myObject = {
firstName: 'Alice',
lastName: 'Smith',
age: 30,
city: 'New York'
};
const keyValuePairs = pairs(myObject);
console.log(keyValuePairs);
// Expected output: [['firstName', 'Alice'], ['lastName', 'Smith'], ['age', 30], ['city', 'New York']]
// For older Node.js environments or if explicitly using the deprecated lodash.pairs package:
// var oldPairs = require('lodash.pairs');
// const oldKeyValuePairs = oldPairs(myObject);
// console.log(oldKeyValuePairs);