Registry / serialization / lodash.identity

lodash.identity

JSON →
library3.0.0jsnpmunverified

lodash.identity provides the `_.identity` function from the Lodash utility library as a standalone, modular package. This function is a no-operation (no-op) utility, meaning it returns the first argument it receives without modification. It's primarily used in functional programming contexts where an explicit callback or iterator is required but no data transformation is desired, serving as a placeholder or default for higher-order functions like `_.map`, `_.filter`, or `_.sortBy`. The `lodash` ecosystem, from which this module derives, is actively maintained with the latest stable version being `v4.18.1`. While individual modular packages like `lodash.identity` are stable and less frequently updated, the main Lodash library receives regular maintenance, including security patches and bug fixes. The modular approach helps minimize bundle sizes in client-side applications by allowing developers to import only specific functions rather than the entire library.

npm install lodash.identity
INSTALL
IMPORT
SIG · LODASH.IDENTITY
L
lodash.identity
serializationjavascriptv3.0.0
Install
Import
Disk
Pass rate
0/ 6
Env Coverage0 / 6
glibc
1822
musl
1822
Install & Compatibility
Where this runs
tested against v? · npm install
Install × environment matrix
Each cell = how many times install + import succeeded across repeated harness runs. Partial = flaky.
glibc = Debian/Ubuntu slim · musl = Alpine Linux
musl
node 18226 runs
build_error
glibc
node 18226 runs
build_error
Code
Verified usage

Verified import paths — ran on the pinned version, not inferred.

identity
import identity from 'lodash.identity';
import { identity } from 'lodash.identity';
Most modular Lodash packages, including `lodash.identity`, are exported as default exports for ESM. Attempting to destructure them as named imports will result in runtime errors.
identity
const identity = require('lodash.identity');
Standard CommonJS import pattern for Node.js environments. No common wrong usage, but ensure it's `const` or `var`.
Identity
import type { Identity } from 'lodash';
TypeScript types for `identity` are typically provided by the `@types/lodash` package, not directly by `lodash.identity`.

Demonstrates the basic functionality of `identity` returning its input and its common use cases as a default iterator or no-operation callback.

import identity from 'lodash.identity'; // Basic usage: identity returns its input directly console.log('Direct usage:', identity(42)); // Expected: 42 console.log('With string:', identity('hello')); // Expected: 'hello' // Useful as a default iterator, e.g., with Array.prototype.map const numbers = [1, 2, 3]; const mappedNumbers = numbers.map(identity); console.log('Mapped numbers (identity):', mappedNumbers); // Expected: [1, 2, 3] // Or with a custom function that expects an iterator function processItems(items, iterator = identity) { return items.map(item => iterator(item)); } const processed = processItems(['a', 'b', 'c']); console.log('Processed with default identity:', processed); // Expected: ['a', 'b', 'c'] const processedWithTransform = processItems(['x', 'y', 'z'], item => item.toUpperCase()); console.log('Processed with transform:', processedWithTransform); // Expected: ['X', 'Y', 'Z'] // In some scenarios, it simplifies code where an explicit no-op is clearer const config = { onComplete: identity // No-op on completion }; console.log('Config onComplete:', config.onComplete('task completed')); // Expected: 'task completed'
Debug
Known issues
breakingLodash v4.0.0 introduced significant breaking changes across the entire Lodash API surface. While `lodash.identity` is a simple function, its internal implementation or dependencies might have changed, requiring users upgrading from v3.x to v4.x to review the main Lodash changelog.
fix
Consult the main Lodash v4.0.0 changelog for broader ecosystem changes. Test thoroughly after upgrading.
affects: >=4.0.0
breakingLodash v3.0.0 also contained substantial breaking changes from v2.x. When upgrading between major versions, always assume potential API shifts even for seemingly simple modules like `identity`.
fix
Refer to the Lodash v3.0.0 changelog on the official GitHub wiki for detailed breaking changes and migration guides.
affects: >=3.0.0 <4.0.0
gotchaModular Lodash packages (e.g., `lodash.identity`) are typically distributed as default exports in ESM. Attempting `import { identity } from 'lodash.identity'` will lead to `undefined` or runtime errors because there is no named export 'identity'.
fix
Always use `import identity from 'lodash.identity';` for ESM imports.
affects: *
gotchaA security vulnerability (prototype pollution) was patched in the main Lodash library (v4.18.0) affecting `_.unset` and `_.omit`. While `lodash.identity` is not directly vulnerable, this highlights the importance of keeping all Lodash-related packages up-to-date and being aware of security advisories in the broader ecosystem.
fix
Ensure all Lodash-related packages, including the main `lodash` package if used, are updated to `v4.18.0` or newer. Review `GHSA-f23m-r3pf-42rh` for full details.
affects: <4.18.0
gotchaA `ReferenceError` was fixed in modular builds (v4.18.1) for specific functions like `template` and `fromPairs` when built from the main branch. Although `lodash.identity` was not explicitly listed, this indicates potential build-related issues that could affect other modular packages. Ensure you are on the latest patch version.
fix
Upgrade to `lodash.identity@latest` and any other modular Lodash packages to `v4.18.1` or newer to benefit from recent bug fixes related to modular distributions.
affects: <4.18.1
Errors
Common errors & fixes
TypeError: (0 , _lodash_identity__WEBPACK_IMPORTED_MODULE_0__.identity) is not a function
Attempting to destructure a named export `identity` from `lodash.identity` in an ESM context, but `lodash.identity` provides a default export.
fix
Change `import { identity } from 'lodash.identity';` to `import identity from 'lodash.identity';`.
ReferenceError: identity is not defined
The `identity` variable was used without being properly imported or required first, or the module was imported incorrectly.
fix
Ensure `const identity = require('lodash.identity');` (CommonJS) or `import identity from 'lodash.identity';` (ESM) is correctly placed at the top of your file.
Upgrade
Version history
3.0.0latest on npm
Audit
Dependencies

No dependency data recorded yet.

Agent activity
2 hits · last 30 days
node
2
Resources
lodash.identity — npm install lodash.identity · libregistry