Back to search
Author
tessl
Last updated
Spec files

npm-lodash

Description
A comprehensive JavaScript utility library delivering modularity, performance and extra features for arrays, objects, functions and more
Author
tessl
Last updated

How to use

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

index.md docs/

1
# Lodash
2
3
Lodash is a comprehensive JavaScript utility library delivering modularity, performance and extra features for working with arrays, objects, functions, strings and more. It provides over 280 utility functions that complement JavaScript's built-in methods with additional functionality for common programming tasks.
4
5
## Package Information
6
7
- **Package Name**: lodash
8
- **Package Type**: npm
9
- **Language**: JavaScript
10
- **Installation**: `npm install lodash`
11
12
## Core Imports
13
14
```javascript
15
const _ = require('lodash');
16
```
17
18
For ES6 modules:
19
20
```javascript
21
import _ from 'lodash';
22
```
23
24
For selective imports:
25
26
```javascript
27
import { map, filter, chunk, get, debounce } from 'lodash';
28
```
29
30
For CommonJS selective imports:
31
32
```javascript
33
const { map, filter, chunk, get, debounce } = require('lodash');
34
```
35
36
## Basic Usage
37
38
```javascript
39
const _ = require('lodash');
40
41
// Array operations
42
const chunks = _.chunk([1, 2, 3, 4, 5, 6], 2);
43
// => [[1, 2], [3, 4], [5, 6]]
44
45
const unique = _.uniq([1, 2, 2, 3, 3, 4]);
46
// => [1, 2, 3, 4]
47
48
// Collection operations
49
const users = [
50
{ name: 'John', age: 30, active: true },
51
{ name: 'Jane', age: 25, active: false },
52
{ name: 'Bob', age: 35, active: true }
53
];
54
55
const activeUsers = _.filter(users, 'active');
56
// => [{ name: 'John', age: 30, active: true }, { name: 'Bob', age: 35, active: true }]
57
58
const names = _.map(users, 'name');
59
// => ['John', 'Jane', 'Bob']
60
61
// Object operations
62
const data = { user: { name: 'John', profile: { age: 30 } } };
63
const age = _.get(data, 'user.profile.age', 0);
64
// => 30
65
66
const merged = _.assign({}, { a: 1 }, { b: 2 }, { c: 3 });
67
// => { a: 1, b: 2, c: 3 }
68
69
// Function operations
70
const debouncedSave = _.debounce(saveData, 250);
71
const curried = _.curry((a, b, c) => a + b + c);
72
73
// String operations
74
const camelCased = _.camelCase('hello world');
75
// => 'helloWorld'
76
77
const padded = _.pad('abc', 8);
78
// => ' abc '
79
```
80
81
## Architecture
82
83
Lodash is organized around several key design principles:
84
85
- **Functional Programming**: Supports both imperative and functional programming styles
86
- **Immutability**: Most operations return new values rather than modifying existing ones
87
- **Iteratee Support**: Functions accept various iteratee types (functions, strings, objects)
88
- **Performance**: Optimized algorithms and lazy evaluation for efficient processing
89
- **Modularity**: Available as individual modules for selective imports and tree-shaking
90
91
The library is structured into distinct categories based on data types and operation types, with consistent API patterns across similar functions.
92
93
## Capabilities
94
95
### Array Processing
96
97
Comprehensive array manipulation including chunking, flattening, deduplication, set operations, and transformations.
98
99
```javascript { .api }
100
function chunk(array, size);
101
function compact(array);
102
function difference(array, ...values);
103
function flatten(array);
104
function uniq(array);
105
function zip(...arrays);
106
```
107
108
[Array Processing](./array.md)
109
110
### Collection Operations
111
112
Iteration, filtering, mapping, grouping, and aggregation functions that work with arrays, objects, and array-like objects.
113
114
```javascript { .api }
115
function forEach(collection, iteratee);
116
function map(collection, iteratee);
117
function filter(collection, predicate);
118
function reduce(collection, iteratee, accumulator);
119
function groupBy(collection, iteratee);
120
function find(collection, predicate);
121
```
122
123
[Collection Operations](./collection.md)
124
125
### Object Manipulation
126
127
Property access, merging, transformation, and inspection functions for working with objects and their properties.
128
129
```javascript { .api }
130
function assign(object, ...sources);
131
function get(object, path, defaultValue);
132
function set(object, path, value);
133
function pick(object, ...paths);
134
function omit(object, ...paths);
135
function merge(object, ...sources);
136
```
137
138
[Object Manipulation](./object.md)
139
140
### Function Utilities
141
142
Function composition, currying, throttling, memoization, and other higher-order function operations.
143
144
```javascript { .api }
145
function curry(func, arity);
146
function debounce(func, wait, options);
147
function throttle(func, wait, options);
148
function memoize(func, resolver);
149
function partial(func, ...partials);
150
function bind(func, thisArg, ...partials);
151
```
152
153
[Function Utilities](./function.md)
154
155
### String Processing
156
157
String manipulation including case conversion, padding, trimming, templating, and parsing operations.
158
159
```javascript { .api }
160
function camelCase(string);
161
function kebabCase(string);
162
function capitalize(string);
163
function pad(string, length, chars);
164
function trim(string, chars);
165
function split(string, separator, limit);
166
```
167
168
[String Processing](./string.md)
169
170
### Type Checking and Language Utilities
171
172
Comprehensive type checking, value comparison, cloning, and type conversion functions.
173
174
```javascript { .api }
175
function isArray(value);
176
function isObject(value);
177
function isEmpty(value);
178
function isEqual(value, other);
179
function clone(value);
180
function cloneDeep(value);
181
```
182
183
[Language Utilities](./lang.md)
184
185
### Mathematical Operations
186
187
Mathematical functions for arithmetic, aggregation, rounding, and range operations.
188
189
```javascript { .api }
190
function add(augend, addend);
191
function sum(array);
192
function max(array);
193
function min(array);
194
function mean(array);
195
function round(number, precision);
196
```
197
198
[Mathematical Operations](./math.md)
199
200
### Utility Functions
201
202
General-purpose utilities including identity functions, flow control, property accessors, and iteration helpers.
203
204
```javascript { .api }
205
function identity(value);
206
function noop();
207
function range(start, end, step);
208
function times(n, iteratee);
209
function uniqueId(prefix);
210
function template(string, options);
211
```
212
213
[Utility Functions](./util.md)
214
215
### Number Utilities
216
217
Number manipulation functions for clamping, range checking, and random number generation.
218
219
```javascript { .api }
220
function clamp(number, lower, upper);
221
function inRange(number, start, end);
222
function random(lower, upper, floating);
223
```
224
225
[Number Utilities](./number.md)
226
227
### Date Utilities
228
229
Date and time related utilities for current timestamp retrieval.
230
231
```javascript { .api }
232
function now();
233
```
234
235
[Date Utilities](./date.md)
236
237
## Types
238
239
### Common Types
240
241
```javascript { .api }
242
// Basic iteratee types used throughout the library
243
type Iteratee<T> = Function | Object | string | number;
244
type Predicate<T> = Function | Object | string | number;
245
246
// Collection types
247
type Collection<T> = Array<T> | Object;
248
type Dictionary<T> = { [key: string]: T };
249
250
// Function wrapper options
251
interface DebounceOptions {
252
leading?: boolean;
253
maxWait?: number;
254
trailing?: boolean;
255
}
256
257
interface ThrottleOptions {
258
leading?: boolean;
259
trailing?: boolean;
260
}
261
262
// Template options
263
interface TemplateOptions {
264
escape?: RegExp;
265
evaluate?: RegExp;
266
imports?: Object;
267
interpolate?: RegExp;
268
sourceURL?: string;
269
variable?: string;
270
}
271
```