- Spec files
npm-lodash
Describes: pkg:npm/lodash@4.9.x
- Description
- A comprehensive JavaScript utility library with 296+ functions for arrays, objects, strings, and functional programming
- Author
- tessl
- Last updated
index.md docs/
1# Lodash23Lodash is a modern JavaScript utility library delivering modularity, performance & extras. It provides 296+ utility methods for common programming tasks using a functional programming approach, making JavaScript easier by taking the hassle out of working with arrays, numbers, objects, strings, etc.45## Overview67Lodash is the most popular JavaScript utility library, providing a comprehensive set of 296+ functions for common programming tasks. Built with a focus on modularity, performance, and functional programming principles, Lodash simplifies complex operations on arrays, objects, strings, functions, and other data types.89**Key Features:**10- **Comprehensive API**: 296+ utility methods covering arrays, collections, functions, objects, strings, math, and more11- **Modular Architecture**: Import individual methods or entire categories to optimize bundle size12- **Method Chaining**: Fluent interface for composing complex data transformations13- **Functional Programming**: `/fp` variant with auto-curried, iteratee-first methods14- **Performance Optimized**: Heavily optimized implementations with lazy evaluation15- **Cross-platform**: Works in Node.js, browsers, and other JavaScript environments16- **Type Safety**: Full TypeScript definitions for complete type safety1718## Package Information1920- **Package Name**: lodash21- **Package Type**: npm22- **Language**: JavaScript23- **Installation**: `npm install lodash`2425## Core Imports2627```javascript28// Full library import (UMD)29const _ = require('lodash');30```3132```javascript33// ES6 imports34import _ from 'lodash';35import { map, filter, reduce } from 'lodash';36```3738```javascript39// Individual method imports (recommended for bundle size)40const map = require('lodash/map');41const filter = require('lodash/filter');42```4344```javascript45// Category imports46const array = require('lodash/array');47const object = require('lodash/object');48```4950```javascript51// Functional programming variant52const fp = require('lodash/fp');53```5455Browser (UMD):5657```html58<script src="lodash.js"></script>59<script>60_.map([1, 2, 3], n => n * 2);61</script>62```6364## Basic Usage6566```javascript67const _ = require('lodash');6869// Array operations70const numbers = [1, 2, 3, 4, 5, 6];71const evens = _.filter(numbers, n => n % 2 === 0);72const doubled = _.map(numbers, n => n * 2);73const chunks = _.chunk(numbers, 2); // [[1, 2], [3, 4], [5, 6]]7475// Object manipulation76const users = [77{ name: 'Alice', age: 25, active: true },78{ name: 'Bob', age: 30, active: false },79{ name: 'Charlie', age: 35, active: true }80];8182const activeUsers = _.filter(users, 'active');83const usersByAge = _.groupBy(users, 'age');84const names = _.map(users, 'name');8586// String operations87const text = 'hello world';88const camelCase = _.camelCase(text); // 'helloWorld'89const kebabCase = _.kebabCase(text); // 'hello-world'9091// Method chaining92const result = _(users)93.filter('active')94.map('name')95.sort()96.value(); // ['Alice', 'Charlie']97```9899## Architecture100101Lodash is built around several key architectural patterns:102103- **Modular Design**: Every method is available as an individual module for optimal bundle sizing104- **Method Chaining**: Supports both explicit chaining with `_.chain()` and implicit chaining with `_(value)`105- **Functional Programming**: `/fp` variants provide auto-curried, iteratee-first, and composition-friendly methods106- **Performance Optimization**: Heavily optimized implementations with lazy evaluation in chains107- **Type Safety**: Includes TypeScript definitions for full type safety108- **Cross-platform**: Works in Node.js, browsers, and other JavaScript environments109110## Capabilities111112### Array Methods113114Comprehensive array manipulation utilities for chunking, flattening, filtering, and transforming arrays.115116```javascript { .api }117function chunk<T>(array: T[], size?: number): T[][];118function flatten<T>(array: T[] | T[][]): T[];119function uniq<T>(array: T[]): T[];120function intersection<T>(...arrays: T[][]): T[];121```122123[Array Methods](./array-methods.md)124125### Collection Methods126127Iteration and manipulation methods that work on arrays, objects, and other iterable collections.128129```javascript { .api }130function map<T, R>(collection: T[], iteratee: (value: T, index: number, array: T[]) => R): R[];131function filter<T>(collection: T[], predicate: (value: T, index: number, array: T[]) => boolean): T[];132function groupBy<T>(collection: T[], iteratee: string | ((value: T) => any)): { [key: string]: T[] };133function reduce<T, R>(collection: T[], iteratee: (accumulator: R, value: T, index: number, array: T[]) => R, initialValue?: R): R;134```135136[Collection Methods](./collection-methods.md)137138### Function Utilities139140Function composition, currying, debouncing, throttling, and other function manipulation utilities.141142```javascript { .api }143function debounce<T extends (...args: any[]) => any>(func: T, wait?: number, options?: DebounceOptions): T & { cancel(): void; flush(): ReturnType<T> };144function throttle<T extends (...args: any[]) => any>(func: T, wait?: number, options?: ThrottleOptions): T & { cancel(): void; flush(): ReturnType<T> };145function curry<T extends (...args: any[]) => any>(func: T, arity?: number): CurriedFunction<T>;146function memoize<T extends (...args: any[]) => any>(func: T, resolver?: (...args: any[]) => any): T & { cache: Map<any, any> };147148interface DebounceOptions {149leading?: boolean;150maxWait?: number;151trailing?: boolean;152}153154interface ThrottleOptions {155leading?: boolean;156trailing?: boolean;157}158159type CurriedFunction<T> = T & {160(...args: any[]): any;161};162```163164[Function Methods](./function-methods.md)165166### Type Checking & Language Utilities167168Comprehensive type checking predicates and value conversion utilities for JavaScript types.169170```javascript { .api }171function isArray(value: any): value is any[];172function isObject(value: any): value is object;173function isString(value: any): value is string;174function isFunction(value: any): value is Function;175function clone<T>(value: T): T;176function cloneDeep<T>(value: T): T;177```178179[Language Methods](./lang-methods.md)180181### Mathematical Operations182183Mathematical computations including basic arithmetic, aggregation, and range utilities.184185```javascript { .api }186function add(augend: number, addend: number): number;187function sum(array: number[]): number;188function max(array: number[]): number | undefined;189function min(array: number[]): number | undefined;190function mean(array: number[]): number;191function range(start?: number, end?: number, step?: number): number[];192```193194[Math Methods](./math-methods.md)195196### Object Manipulation197198Deep object operations including property access, merging, transformation, and key/value manipulation.199200```javascript { .api }201function get(object: any, path: string | string[], defaultValue?: any): any;202function set(object: any, path: string | string[], value: any): any;203function merge<T, S>(object: T, source: S): T & S;204function omit<T, K extends keyof T>(object: T, ...paths: K[]): Omit<T, K>;205function pick<T, K extends keyof T>(object: T, ...paths: K[]): Pick<T, K>;206```207208[Object Methods](./object-methods.md)209210### String Processing211212String transformation utilities for case conversion, templating, and text manipulation.213214```javascript { .api }215function camelCase(string?: string): string;216function kebabCase(string?: string): string;217function capitalize(string?: string): string;218function template(string: string, options?: TemplateOptions): TemplateExecutor;219function truncate(string?: string, options?: TruncateOptions): string;220221interface TemplateOptions {222escape?: RegExp;223evaluate?: RegExp;224interpolate?: RegExp;225variable?: string;226}227228interface TruncateOptions {229length?: number;230omission?: string;231separator?: string | RegExp;232}233234type TemplateExecutor = (data?: any) => string;235```236237[String Methods](./string-methods.md)238239### Utility Functions240241General-purpose utilities including function creation, control flow, and miscellaneous helpers.242243```javascript { .api }244function identity<T>(value: T): T;245function noop(): void;246function constant<T>(value: T): () => T;247function times<T>(n: number, iteratee: (index: number) => T): T[];248function uniqueId(prefix?: string): string;249```250251[Utility Methods](./util-methods.md)252253## Method Chaining254255Lodash provides powerful chaining capabilities for composing operations:256257```javascript { .api }258// Explicit chaining259function chain<T>(value: T): LodashWrapper<T>;260261// Chain methods262interface LodashWrapper<T> {263value(): T;264tap(interceptor: (value: T) => void): LodashWrapper<T>;265thru<R>(interceptor: (value: T) => R): LodashWrapper<R>;266}267268// Implicit chaining with _(value)269function _<T>(value: T): LodashWrapper<T>;270```271272## Constants273274```javascript { .api }275const VERSION: string; // "4.9.0"276277interface TemplateSettings {278escape?: RegExp;279evaluate?: RegExp;280interpolate?: RegExp;281variable?: string;282}283284const templateSettings: TemplateSettings;285```286287## Types288289```javascript { .api }290type Iteratee<T, R = any> =291| ((value: T, index: number, collection: T[]) => R)292| string293| number294| object;295296type Predicate<T> =297| ((value: T, index: number, collection: T[]) => boolean)298| string299| [string, any]300| object;301302type PropertyPath = string | number | symbol | Array<string | number | symbol>;303304interface LoDashStatic {305VERSION: string;306templateSettings: TemplateSettings;307308// All lodash methods are available on the main export309[key: string]: any;310}311312interface TemplateSettings {313escape?: RegExp;314evaluate?: RegExp;315interpolate?: RegExp;316variable?: string;317}318```