The modern build of lodash's identity utility function exported as a standalone module.
—
Pending
Does it follow best practices?
Impact
Pending
No eval scenarios have been run
Pending
The risk profile of this skill
Lodash Identity provides the identity utility function from the lodash library as a standalone Node.js module. The identity function is a fundamental utility that returns its first argument unchanged, making it essential for functional programming patterns, default callbacks, and placeholder operations.
npm install lodash.identityconst identity = require('lodash.identity');ESM:
import identity from 'lodash.identity';const identity = require('lodash.identity');
// Basic usage - returns the input unchanged
const value = identity(42);
console.log(value); // => 42
const object = { a: 1, b: 2 };
console.log(identity(object) === object); // => true
// Common usage as a default callback
const users = [
{ name: 'Alice', active: true },
{ name: 'Bob', active: false },
{ name: 'Charlie', active: true }
];
// Use as default transformation function - filter truthy values
const activeUsers = users.filter(user => user.active);
// Use in array operations where no transformation is needed
const numbers = [1, 2, 3];
const sameNumbers = numbers.map(identity);
console.log(numbers === sameNumbers); // => false (different array, same values)Returns the first argument it receives unchanged. This function is commonly used as a default transformation function in functional programming patterns and as a placeholder when no transformation is needed.
/**
* This method returns the first argument it receives.
*
* @param {*} value - Any value of any type
* @returns {*} Returns the input value unchanged
* @since 0.1.0
*/
function identity(value);Parameters:
value (*): Any value - can be any JavaScript type including primitives, objects, arrays, functions, etc.Returns:
Usage Examples:
const identity = require('lodash.identity');
// With primitives
identity(1); // => 1
identity('hello'); // => 'hello'
identity(true); // => true
// With objects (returns same reference)
const obj = { name: 'test' };
identity(obj) === obj; // => true
// With arrays (returns same reference)
const arr = [1, 2, 3];
identity(arr) === arr; // => true
// With functions
const fn = () => 'hello';
identity(fn) === fn; // => true
// Common functional programming patterns
const data = [1, 2, 3];
// As a default callback
const transformed = data.map(identity); // [1, 2, 3]
// In filter operations (truthy values)
const values = [1, 0, 'hello', '', true, false];
const truthyValues = values.filter(identity); // [1, 'hello', true]
// As a default transformation in higher-order functions
function processData(data, transform = identity) {
return data.map(transform);
}
processData([1, 2, 3]); // [1, 2, 3] (no transformation)
processData([1, 2, 3], x => x * 2); // [2, 4, 6] (with transformation)Typical Use Cases: