npm-lodash

Description
A comprehensive JavaScript utility library with 296+ functions for arrays, objects, strings, and functional programming
Author
tessl
Last updated

How to use

npx @tessl/cli registry install tessl/npm-lodash@4.9.0

index.md docs/

1
# Lodash
2
3
Lodash 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.
4
5
## Overview
6
7
Lodash 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.
8
9
**Key Features:**
10
- **Comprehensive API**: 296+ utility methods covering arrays, collections, functions, objects, strings, math, and more
11
- **Modular Architecture**: Import individual methods or entire categories to optimize bundle size
12
- **Method Chaining**: Fluent interface for composing complex data transformations
13
- **Functional Programming**: `/fp` variant with auto-curried, iteratee-first methods
14
- **Performance Optimized**: Heavily optimized implementations with lazy evaluation
15
- **Cross-platform**: Works in Node.js, browsers, and other JavaScript environments
16
- **Type Safety**: Full TypeScript definitions for complete type safety
17
18
## Package Information
19
20
- **Package Name**: lodash
21
- **Package Type**: npm
22
- **Language**: JavaScript
23
- **Installation**: `npm install lodash`
24
25
## Core Imports
26
27
```javascript
28
// Full library import (UMD)
29
const _ = require('lodash');
30
```
31
32
```javascript
33
// ES6 imports
34
import _ from 'lodash';
35
import { map, filter, reduce } from 'lodash';
36
```
37
38
```javascript
39
// Individual method imports (recommended for bundle size)
40
const map = require('lodash/map');
41
const filter = require('lodash/filter');
42
```
43
44
```javascript
45
// Category imports
46
const array = require('lodash/array');
47
const object = require('lodash/object');
48
```
49
50
```javascript
51
// Functional programming variant
52
const fp = require('lodash/fp');
53
```
54
55
Browser (UMD):
56
57
```html
58
<script src="lodash.js"></script>
59
<script>
60
_.map([1, 2, 3], n => n * 2);
61
</script>
62
```
63
64
## Basic Usage
65
66
```javascript
67
const _ = require('lodash');
68
69
// Array operations
70
const numbers = [1, 2, 3, 4, 5, 6];
71
const evens = _.filter(numbers, n => n % 2 === 0);
72
const doubled = _.map(numbers, n => n * 2);
73
const chunks = _.chunk(numbers, 2); // [[1, 2], [3, 4], [5, 6]]
74
75
// Object manipulation
76
const users = [
77
{ name: 'Alice', age: 25, active: true },
78
{ name: 'Bob', age: 30, active: false },
79
{ name: 'Charlie', age: 35, active: true }
80
];
81
82
const activeUsers = _.filter(users, 'active');
83
const usersByAge = _.groupBy(users, 'age');
84
const names = _.map(users, 'name');
85
86
// String operations
87
const text = 'hello world';
88
const camelCase = _.camelCase(text); // 'helloWorld'
89
const kebabCase = _.kebabCase(text); // 'hello-world'
90
91
// Method chaining
92
const result = _(users)
93
.filter('active')
94
.map('name')
95
.sort()
96
.value(); // ['Alice', 'Charlie']
97
```
98
99
## Architecture
100
101
Lodash is built around several key architectural patterns:
102
103
- **Modular Design**: Every method is available as an individual module for optimal bundle sizing
104
- **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 methods
106
- **Performance Optimization**: Heavily optimized implementations with lazy evaluation in chains
107
- **Type Safety**: Includes TypeScript definitions for full type safety
108
- **Cross-platform**: Works in Node.js, browsers, and other JavaScript environments
109
110
## Capabilities
111
112
### Array Methods
113
114
Comprehensive array manipulation utilities for chunking, flattening, filtering, and transforming arrays.
115
116
```javascript { .api }
117
function chunk<T>(array: T[], size?: number): T[][];
118
function flatten<T>(array: T[] | T[][]): T[];
119
function uniq<T>(array: T[]): T[];
120
function intersection<T>(...arrays: T[][]): T[];
121
```
122
123
[Array Methods](./array-methods.md)
124
125
### Collection Methods
126
127
Iteration and manipulation methods that work on arrays, objects, and other iterable collections.
128
129
```javascript { .api }
130
function map<T, R>(collection: T[], iteratee: (value: T, index: number, array: T[]) => R): R[];
131
function filter<T>(collection: T[], predicate: (value: T, index: number, array: T[]) => boolean): T[];
132
function groupBy<T>(collection: T[], iteratee: string | ((value: T) => any)): { [key: string]: T[] };
133
function reduce<T, R>(collection: T[], iteratee: (accumulator: R, value: T, index: number, array: T[]) => R, initialValue?: R): R;
134
```
135
136
[Collection Methods](./collection-methods.md)
137
138
### Function Utilities
139
140
Function composition, currying, debouncing, throttling, and other function manipulation utilities.
141
142
```javascript { .api }
143
function debounce<T extends (...args: any[]) => any>(func: T, wait?: number, options?: DebounceOptions): T & { cancel(): void; flush(): ReturnType<T> };
144
function throttle<T extends (...args: any[]) => any>(func: T, wait?: number, options?: ThrottleOptions): T & { cancel(): void; flush(): ReturnType<T> };
145
function curry<T extends (...args: any[]) => any>(func: T, arity?: number): CurriedFunction<T>;
146
function memoize<T extends (...args: any[]) => any>(func: T, resolver?: (...args: any[]) => any): T & { cache: Map<any, any> };
147
148
interface DebounceOptions {
149
leading?: boolean;
150
maxWait?: number;
151
trailing?: boolean;
152
}
153
154
interface ThrottleOptions {
155
leading?: boolean;
156
trailing?: boolean;
157
}
158
159
type CurriedFunction<T> = T & {
160
(...args: any[]): any;
161
};
162
```
163
164
[Function Methods](./function-methods.md)
165
166
### Type Checking & Language Utilities
167
168
Comprehensive type checking predicates and value conversion utilities for JavaScript types.
169
170
```javascript { .api }
171
function isArray(value: any): value is any[];
172
function isObject(value: any): value is object;
173
function isString(value: any): value is string;
174
function isFunction(value: any): value is Function;
175
function clone<T>(value: T): T;
176
function cloneDeep<T>(value: T): T;
177
```
178
179
[Language Methods](./lang-methods.md)
180
181
### Mathematical Operations
182
183
Mathematical computations including basic arithmetic, aggregation, and range utilities.
184
185
```javascript { .api }
186
function add(augend: number, addend: number): number;
187
function sum(array: number[]): number;
188
function max(array: number[]): number | undefined;
189
function min(array: number[]): number | undefined;
190
function mean(array: number[]): number;
191
function range(start?: number, end?: number, step?: number): number[];
192
```
193
194
[Math Methods](./math-methods.md)
195
196
### Object Manipulation
197
198
Deep object operations including property access, merging, transformation, and key/value manipulation.
199
200
```javascript { .api }
201
function get(object: any, path: string | string[], defaultValue?: any): any;
202
function set(object: any, path: string | string[], value: any): any;
203
function merge<T, S>(object: T, source: S): T & S;
204
function omit<T, K extends keyof T>(object: T, ...paths: K[]): Omit<T, K>;
205
function pick<T, K extends keyof T>(object: T, ...paths: K[]): Pick<T, K>;
206
```
207
208
[Object Methods](./object-methods.md)
209
210
### String Processing
211
212
String transformation utilities for case conversion, templating, and text manipulation.
213
214
```javascript { .api }
215
function camelCase(string?: string): string;
216
function kebabCase(string?: string): string;
217
function capitalize(string?: string): string;
218
function template(string: string, options?: TemplateOptions): TemplateExecutor;
219
function truncate(string?: string, options?: TruncateOptions): string;
220
221
interface TemplateOptions {
222
escape?: RegExp;
223
evaluate?: RegExp;
224
interpolate?: RegExp;
225
variable?: string;
226
}
227
228
interface TruncateOptions {
229
length?: number;
230
omission?: string;
231
separator?: string | RegExp;
232
}
233
234
type TemplateExecutor = (data?: any) => string;
235
```
236
237
[String Methods](./string-methods.md)
238
239
### Utility Functions
240
241
General-purpose utilities including function creation, control flow, and miscellaneous helpers.
242
243
```javascript { .api }
244
function identity<T>(value: T): T;
245
function noop(): void;
246
function constant<T>(value: T): () => T;
247
function times<T>(n: number, iteratee: (index: number) => T): T[];
248
function uniqueId(prefix?: string): string;
249
```
250
251
[Utility Methods](./util-methods.md)
252
253
## Method Chaining
254
255
Lodash provides powerful chaining capabilities for composing operations:
256
257
```javascript { .api }
258
// Explicit chaining
259
function chain<T>(value: T): LodashWrapper<T>;
260
261
// Chain methods
262
interface LodashWrapper<T> {
263
value(): T;
264
tap(interceptor: (value: T) => void): LodashWrapper<T>;
265
thru<R>(interceptor: (value: T) => R): LodashWrapper<R>;
266
}
267
268
// Implicit chaining with _(value)
269
function _<T>(value: T): LodashWrapper<T>;
270
```
271
272
## Constants
273
274
```javascript { .api }
275
const VERSION: string; // "4.9.0"
276
277
interface TemplateSettings {
278
escape?: RegExp;
279
evaluate?: RegExp;
280
interpolate?: RegExp;
281
variable?: string;
282
}
283
284
const templateSettings: TemplateSettings;
285
```
286
287
## Types
288
289
```javascript { .api }
290
type Iteratee<T, R = any> =
291
| ((value: T, index: number, collection: T[]) => R)
292
| string
293
| number
294
| object;
295
296
type Predicate<T> =
297
| ((value: T, index: number, collection: T[]) => boolean)
298
| string
299
| [string, any]
300
| object;
301
302
type PropertyPath = string | number | symbol | Array<string | number | symbol>;
303
304
interface LoDashStatic {
305
VERSION: string;
306
templateSettings: TemplateSettings;
307
308
// All lodash methods are available on the main export
309
[key: string]: any;
310
}
311
312
interface TemplateSettings {
313
escape?: RegExp;
314
evaluate?: RegExp;
315
interpolate?: RegExp;
316
variable?: string;
317
}
318
```