- Spec files
npm-lodash
Describes: pkg:npm/lodash@4.6.x
- Description
- A modern JavaScript utility library delivering modularity, performance & extras
- Author
- tessl
- Last updated
index.md docs/
1# Lodash23Lodash is a modern JavaScript utility library delivering modularity, performance, and extras. It provides over 260 utility methods for common programming tasks such as array and object manipulation, string processing, function utilities, and type checking, making JavaScript development more efficient by eliminating boilerplate code.45## Package Information67- **Package Name**: lodash8- **Package Type**: npm9- **Language**: JavaScript10- **Installation**: `npm install lodash`1112## Core Imports1314```javascript15import _ from "lodash";16// or import specific functions17import { union, map, filter, isArray } from "lodash";18```1920For CommonJS:2122```javascript23const _ = require("lodash");24// or require specific functions25const { union, map, filter, isArray } = require("lodash");26```2728## Basic Usage2930```javascript31import _ from "lodash";3233// Array operations34const arrays = [[2, 1], [4, 2], [1, 2]];35const combined = _.union(...arrays);36// Result: [2, 1, 4]3738// Object manipulation39const users = [40{ name: "Alice", age: 25, active: true },41{ name: "Bob", age: 30, active: false },42{ name: "Charlie", age: 35, active: true }43];4445const activeUsers = _.filter(users, "active");46const names = _.map(activeUsers, "name");47// Result: ["Alice", "Charlie"]4849// Function utilities50const expensive = _.memoize(function(n) {51return n * n;52});5354// Type checking55_.isArray([1, 2, 3]); // true56_.isString("hello"); // true57```5859## Architecture6061Lodash is organized around several key design patterns:6263- **Modular Design**: Every method can be used standalone or as part of the main library64- **Method Chaining**: Fluent interface supporting chained operations via `_.chain()`65- **Iteratee Shorthand**: Support for property strings, object matches, and functions as iteratees66- **Lazy Evaluation**: Deferred execution for chained operations to optimize performance67- **Functional Programming**: FP build provides auto-curried, immutable versions of all methods68- **Cross-Platform**: Works in browsers, Node.js, and other JavaScript environments6970## Capabilities7172### Array Operations7374Comprehensive array manipulation including transformation, filtering, set operations, and sorting utilities.7576```javascript { .api }77// Core union functions78function union(...arrays: Array[]): Array;79function unionBy(...arrays: Array[], iteratee: Function|Object|string): Array;80function unionWith(...arrays: Array[], comparator: Function): Array;8182// Other key array methods83function chunk(array: Array, size: number): Array[];84function compact(array: Array): Array;85function difference(array: Array, ...values: Array[]): Array;86function intersection(...arrays: Array[]): Array;87function uniq(array: Array): Array;88```8990[Array Operations](./array.md)9192### Collection Processing9394Iteration and processing methods for both arrays and objects, including mapping, filtering, grouping, and reduction operations.9596```javascript { .api }97function map(collection: Array|Object, iteratee: Function|Object|string): Array;98function filter(collection: Array|Object, predicate: Function|Object|string): Array;99function find(collection: Array|Object, predicate: Function|Object|string, fromIndex?: number): any;100function groupBy(collection: Array|Object, iteratee: Function|Object|string): Object;101function reduce(collection: Array|Object, iteratee: Function, accumulator?: any): any;102```103104[Collection Processing](./collection.md)105106### Object Utilities107108Object manipulation including property access, assignment, merging, and transformation utilities.109110```javascript { .api }111function assign(object: Object, ...sources: Object[]): Object;112function get(object: Object, path: Array|string, defaultValue?: any): any;113function set(object: Object, path: Array|string, value: any): Object;114function pick(object: Object, ...paths: Array|string[]): Object;115function omit(object: Object, ...paths: Array|string[]): Object;116```117118[Object Utilities](./object.md)119120### Function Utilities121122Function composition, currying, debouncing, throttling, and other functional programming utilities.123124```javascript { .api }125function debounce(func: Function, wait: number, options?: Object): Function;126function throttle(func: Function, wait: number, options?: Object): Function;127function memoize(func: Function, resolver?: Function): Function;128function curry(func: Function, arity?: number): Function;129function partial(func: Function, ...partials: any[]): Function;130```131132[Function Utilities](./function.md)133134### String Processing135136String manipulation including case conversion, trimming, padding, and template utilities.137138```javascript { .api }139function camelCase(string: string): string;140function kebabCase(string: string): string;141function snakeCase(string: string): string;142function startsWith(string: string, target: string, position?: number): boolean;143function template(string: string, options?: Object): Function;144```145146[String Processing](./string.md)147148### Type Checking149150Comprehensive type checking utilities for JavaScript values and objects.151152```javascript { .api }153function isArray(value: any): boolean;154function isObject(value: any): boolean;155function isString(value: any): boolean;156function isNumber(value: any): boolean;157function isFunction(value: any): boolean;158function isEmpty(value: any): boolean;159```160161[Type Checking](./lang.md)162163### Mathematical Operations164165Mathematical utilities including basic arithmetic, rounding, and statistical operations.166167```javascript { .api }168function add(augend: number, addend: number): number;169function subtract(minuend: number, subtrahend: number): number;170function max(array: Array): number;171function min(array: Array): number;172function sum(array: Array): number;173```174175[Mathematical Operations](./math.md)176177### General Utilities178179Miscellaneous utilities including iteration, constants, method chaining, and utility functions.180181```javascript { .api }182function times(n: number, iteratee: Function): Array;183function range(start?: number, end?: number, step?: number): Array;184function identity(value: any): any;185function constant(value: any): Function;186function noop(): undefined;187```188189[General Utilities](./util.md)190191## Common Types192193```javascript { .api }194// Iteratee can be a function, object, array, or string195type Iteratee = Function | Object | Array | string;196197// Many methods accept iteratee shorthands198type PropertyName = string | number | Symbol;199type PropertyPath = PropertyName | PropertyName[];200201// Collection can be array or object202type Collection = Array | Object;203204// Comparator function for custom equality checks205type Comparator = (a: any, b: any) => boolean;206207// Predicate function for filtering208type Predicate = (value: any, index: number|string, collection: Collection) => boolean;209```210211## Aliases212213Lodash provides several aliases for commonly used methods:214215- **each** → forEach216- **eachRight** → forEachRight217- **extend** → assignIn218- **extendWith** → assignInWith219- **first** → head220221## Method Chaining222223Lodash supports explicit chaining with `_.chain()` for complex operations:224225```javascript226import _ from "lodash";227228const result = _.chain([1, 2, 3, 4, 5, 6])229.filter(n => n % 2 === 0)230.map(n => n * n)231.sum()232.value();233// Result: 56 (2² + 4² + 6² = 4 + 16 + 36)234```235236## Functional Programming237238Lodash provides a separate FP build with auto-curried, data-last functions:239240```javascript241import fp from "lodash/fp";242243const getActiveUserNames = fp.flow(244fp.filter("active"),245fp.map("name")246);247248const activeNames = getActiveUserNames(users);249```