Back to search
Author
tessl
Last updated
Spec files

npm-lodash

Description
A modern JavaScript utility library delivering modularity, performance & extras.
Author
tessl
Last updated

How to use

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

index.md docs/

1
# Lodash
2
3
Lodash is a modern JavaScript utility library delivering modularity, performance & extras. It provides utility functions for common programming tasks using a functional programming paradigm with over 290 utility functions.
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
// Full library import
16
const _ = require('lodash');
17
18
// Individual function imports
19
const { map, filter, reduce } = require('lodash');
20
```
21
22
ES6 modules:
23
24
```javascript
25
// Full library import
26
import _ from 'lodash';
27
28
// Individual function imports
29
import { map, filter, reduce } from 'lodash';
30
31
// Method categories
32
import * as array from 'lodash/array';
33
import * as object from 'lodash/object';
34
```
35
36
## Basic Usage
37
38
```javascript
39
const _ = require('lodash');
40
41
// Array operations
42
const numbers = [1, 2, 3, 4, 5];
43
const doubled = _.map(numbers, n => n * 2);
44
// => [2, 4, 6, 8, 10]
45
46
// Object manipulation
47
const users = [
48
{ user: 'barney', age: 36, active: true },
49
{ user: 'fred', age: 40, active: false }
50
];
51
const activeUsers = _.filter(users, { active: true });
52
// => [{ user: 'barney', age: 36, active: true }]
53
54
// Function utilities
55
const greet = _.template('Hello <%= name %>!');
56
const greeting = greet({ name: 'World' });
57
// => 'Hello World!'
58
59
// Chaining
60
const result = _(users)
61
.filter({ active: true })
62
.map('user')
63
.value();
64
// => ['barney']
65
```
66
67
## Architecture
68
69
Lodash is organized around several key design principles:
70
71
- **Functional Programming**: Pure functions without side effects where possible
72
- **Immutability**: Functions generally don't mutate input data (with exceptions like `_.assign`)
73
- **Chainable Interface**: Fluent API allowing method chaining with `_()` wrapper
74
- **Modular Design**: Functions can be imported individually to reduce bundle size
75
- **Performance Optimized**: Highly optimized implementations with internal caching
76
- **Cross-Platform**: Works in browsers, Node.js, and other JavaScript environments
77
78
## Capabilities
79
80
### Array Functions
81
82
Utilities for manipulating arrays including iteration, filtering, transformation, and set operations.
83
84
```javascript { .api }
85
// Key array functions
86
function chunk(array, size);
87
function compact(array);
88
function concat(array, ...values);
89
function difference(array, ...values);
90
function drop(array, n);
91
function fill(array, value, start, end);
92
function filter(collection, predicate);
93
function find(collection, predicate, fromIndex);
94
function findIndex(array, predicate, fromIndex);
95
function first(array); // alias: head
96
function flatten(array);
97
function flattenDeep(array);
98
function indexOf(array, value, fromIndex);
99
function initial(array);
100
function intersection(...arrays);
101
function join(array, separator);
102
function last(array);
103
function map(collection, iteratee);
104
function pull(array, ...values);
105
function pullAll(array, values);
106
function remove(array, predicate);
107
function reverse(array);
108
function slice(array, start, end);
109
function sortBy(collection, iteratees);
110
function tail(array);
111
function take(array, n);
112
function union(...arrays);
113
function uniq(array);
114
function without(array, ...values);
115
function zip(...arrays);
116
```
117
118
[Array Functions](./array.md)
119
120
### Object Functions
121
122
Utilities for working with objects including property access, manipulation, and transformation.
123
124
```javascript { .api }
125
// Key object functions
126
function assign(object, ...sources);
127
function assignIn(object, ...sources); // alias: extend
128
function at(object, paths);
129
function create(object, properties);
130
function defaults(object, ...sources);
131
function findKey(object, predicate);
132
function forIn(object, iteratee);
133
function forOwn(object, iteratee);
134
function functions(object);
135
function get(object, path, defaultValue);
136
function has(object, path);
137
function hasIn(object, path);
138
function invert(object);
139
function invoke(object, path, ...args);
140
function keys(object);
141
function mapKeys(object, iteratee);
142
function mapValues(object, iteratee);
143
function merge(object, ...sources);
144
function omit(object, paths);
145
function pick(object, paths);
146
function result(object, path, defaultValue);
147
function set(object, path, value);
148
function transform(object, iteratee, accumulator);
149
function unset(object, path);
150
function values(object);
151
```
152
153
[Object Functions](./object.md)
154
155
### Collection Functions
156
157
Utilities for working with arrays and objects as collections, including iteration, searching, and grouping.
158
159
```javascript { .api }
160
// Key collection functions
161
function countBy(collection, iteratee);
162
function each(collection, iteratee); // alias: forEach
163
function every(collection, predicate);
164
function groupBy(collection, iteratee);
165
function includes(collection, value, fromIndex);
166
function invokeMap(collection, path, ...args);
167
function keyBy(collection, iteratee);
168
function orderBy(collection, iteratees, orders);
169
function partition(collection, predicate);
170
function reduce(collection, iteratee, accumulator);
171
function reduceRight(collection, iteratee, accumulator);
172
function reject(collection, predicate);
173
function sample(collection);
174
function sampleSize(collection, n);
175
function shuffle(collection);
176
function size(collection);
177
function some(collection, predicate);
178
function sortBy(collection, iteratees);
179
```
180
181
[Collection Functions](./collection.md)
182
183
### Function Functions
184
185
Utilities for function composition, currying, throttling, and other functional programming patterns.
186
187
```javascript { .api }
188
// Key function utilities
189
function after(n, func);
190
function ary(func, n);
191
function before(n, func);
192
function bind(func, thisArg, ...partials);
193
function bindKey(object, key, ...partials);
194
function curry(func, arity);
195
function curryRight(func, arity);
196
function debounce(func, wait, options);
197
function defer(func, ...args);
198
function delay(func, wait, ...args);
199
function flip(func);
200
function memoize(func, resolver);
201
function negate(predicate);
202
function once(func);
203
function partial(func, ...partials);
204
function partialRight(func, ...partials);
205
function rearg(func, indexes);
206
function rest(func, start);
207
function spread(func, start);
208
function throttle(func, wait, options);
209
function unary(func);
210
function wrap(value, wrapper);
211
```
212
213
[Function Functions](./function.md)
214
215
### String Functions
216
217
Utilities for string manipulation including case conversion, padding, templating, and parsing.
218
219
```javascript { .api }
220
// Key string functions
221
function camelCase(string);
222
function capitalize(string);
223
function deburr(string);
224
function endsWith(string, target, position);
225
function escape(string);
226
function escapeRegExp(string);
227
function kebabCase(string);
228
function lowerCase(string);
229
function lowerFirst(string);
230
function pad(string, length, chars);
231
function padEnd(string, length, chars);
232
function padStart(string, length, chars);
233
function parseInt(string, radix);
234
function repeat(string, n);
235
function replace(string, pattern, replacement);
236
function snakeCase(string);
237
function split(string, separator, limit);
238
function startCase(string);
239
function startsWith(string, target, position);
240
function template(string, options);
241
function toLower(string);
242
function toUpper(string);
243
function trim(string, chars);
244
function trimEnd(string, chars);
245
function trimStart(string, chars);
246
function truncate(string, options);
247
function unescape(string);
248
function upperCase(string);
249
function upperFirst(string);
250
function words(string, pattern);
251
```
252
253
[String Functions](./string.md)
254
255
### Number Functions
256
257
Utilities for mathematical operations, number validation, and formatting.
258
259
```javascript { .api }
260
// Key number functions
261
function add(augend, addend);
262
function ceil(number, precision);
263
function clamp(number, lower, upper);
264
function divide(dividend, divisor);
265
function floor(number, precision);
266
function inRange(number, start, end);
267
function max(array);
268
function maxBy(array, iteratee);
269
function mean(array);
270
function min(array);
271
function minBy(array, iteratee);
272
function multiply(multiplier, multiplicand);
273
function random(lower, upper, floating);
274
function round(number, precision);
275
function subtract(minuend, subtrahend);
276
function sum(array);
277
function sumBy(array, iteratee);
278
```
279
280
[Number Functions](./number.md)
281
282
### Type Checking Functions
283
284
Utilities for runtime type checking and validation.
285
286
```javascript { .api }
287
// Key type checking functions
288
function isArguments(value);
289
function isArray(value);
290
function isArrayLike(value);
291
function isArrayLikeObject(value);
292
function isBoolean(value);
293
function isDate(value);
294
function isElement(value);
295
function isEmpty(value);
296
function isEqual(value, other);
297
function isEqualWith(value, other, customizer);
298
function isError(value);
299
function isFinite(value);
300
function isFunction(value);
301
function isInteger(value);
302
function isLength(value);
303
function isMatch(object, source);
304
function isMatchWith(object, source, customizer);
305
function isNaN(value);
306
function isNative(value);
307
function isNil(value);
308
function isNull(value);
309
function isNumber(value);
310
function isObject(value);
311
function isObjectLike(value);
312
function isPlainObject(value);
313
function isRegExp(value);
314
function isSafeInteger(value);
315
function isString(value);
316
function isSymbol(value);
317
function isTypedArray(value);
318
function isUndefined(value);
319
```
320
321
[Type Functions](./type.md)
322
323
### Utility Functions
324
325
General utility functions including templating, identity, uniqueId generation, and more.
326
327
```javascript { .api }
328
// Key utility functions
329
function attempt(func, ...args);
330
function cond(pairs);
331
function conforms(source);
332
function constant(value);
333
function flow(...funcs);
334
function flowRight(...funcs);
335
function identity(value);
336
function iteratee(func);
337
function matches(source);
338
function matchesProperty(path, srcValue);
339
function method(path, ...args);
340
function methodOf(object, ...args);
341
function mixin(object, source, options);
342
function noConflict();
343
function noop();
344
function nthArg(n);
345
function over(...iteratees);
346
function overArgs(func, ...transforms);
347
function overEvery(...predicates);
348
function overSome(...predicates);
349
function property(path);
350
function propertyOf(object);
351
function range(start, end, step);
352
function rangeRight(start, end, step);
353
function runInContext(context);
354
function stubArray();
355
function stubFalse();
356
function stubObject();
357
function stubString();
358
function stubTrue();
359
function times(n, iteratee);
360
function toPath(value);
361
function uniqueId(prefix);
362
```
363
364
[Utility Functions](./utility.md)
365
366
## Types
367
368
```javascript { .api }
369
// Lodash wrapper for chaining
370
interface LodashWrapper<T> {
371
value(): T;
372
valueOf(): T;
373
commit(): LodashWrapper<T>;
374
next(): { done: boolean, value: T };
375
plant(value: any): LodashWrapper<any>;
376
reverse(): LodashWrapper<T>;
377
toJSON(): T;
378
toString(): string;
379
}
380
381
// Template options
382
interface TemplateOptions {
383
escape?: RegExp;
384
evaluate?: RegExp;
385
imports?: object;
386
interpolate?: RegExp;
387
sourceURL?: string;
388
variable?: string;
389
}
390
391
// Debounce/Throttle options
392
interface DebounceSettings {
393
leading?: boolean;
394
maxWait?: number;
395
trailing?: boolean;
396
}
397
398
// Truncate options
399
interface TruncateOptions {
400
length?: number;
401
omission?: string;
402
separator?: string | RegExp;
403
}
404
```