npm-lodash

Description
Comprehensive JavaScript utility library with 300+ methods for arrays, objects, strings, functions, and more.
Author
tessl
Last updated

How to use

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

index.md docs/

1
# Lodash
2
3
Lodash is a comprehensive JavaScript utility library that makes JavaScript easier by taking the hassle out of working with arrays, numbers, objects, strings, and more. With over 300 utility methods, Lodash provides modular, high-performance solutions for common programming tasks and supports both imperative and functional programming paradigms.
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
import _ from "lodash";
16
// or
17
import { map, filter, get } from "lodash";
18
```
19
20
For CommonJS:
21
22
```javascript
23
const _ = require("lodash");
24
// or
25
const { map, filter, get } = require("lodash");
26
```
27
28
For functional programming style:
29
30
```javascript
31
import fp from "lodash/fp";
32
// or
33
import { map, filter, get } from "lodash/fp";
34
```
35
36
## Basic Usage
37
38
```javascript
39
import { map, filter, get, groupBy } from "lodash";
40
41
// Working with arrays
42
const numbers = [1, 2, 3, 4, 5];
43
const doubled = map(numbers, n => n * 2);
44
const evens = filter(numbers, n => n % 2 === 0);
45
46
// Working with objects
47
const user = { name: 'John', profile: { age: 30 } };
48
const age = get(user, 'profile.age', 0);
49
50
// Working with collections
51
const users = [
52
{ name: 'John', role: 'admin' },
53
{ name: 'Jane', role: 'user' },
54
{ name: 'Bob', role: 'admin' }
55
];
56
const byRole = groupBy(users, 'role');
57
```
58
59
## Architecture
60
61
Lodash is organized around several key design principles:
62
63
- **Modular Design**: Each method can be imported individually for optimal bundle size
64
- **Multiple Build Formats**: Full build (~21kB), core build (~4kB), and per-method packages
65
- **Functional Programming Support**: FP variants with curried, data-last argument order
66
- **Performance Optimized**: Highly optimized implementations for common operations
67
- **Cross-Platform**: Works in browsers, Node.js, and other JavaScript environments
68
69
## Capabilities
70
71
### Array Manipulation
72
73
Comprehensive utilities for working with arrays including transformation, filtering, grouping, and set operations.
74
75
```javascript { .api }
76
function chunk(array, size = 1);
77
function compact(array);
78
function concat(array, ...values);
79
function difference(array, ...values);
80
function flatten(array);
81
function uniq(array);
82
function zip(...arrays);
83
```
84
85
[Array Methods](./array-methods.md)
86
87
### Collection Processing
88
89
Powerful iteration and transformation methods that work with arrays, objects, and other collections.
90
91
```javascript { .api }
92
function map(collection, iteratee);
93
function filter(collection, predicate);
94
function find(collection, predicate, fromIndex = 0);
95
function forEach(collection, iteratee);
96
function groupBy(collection, iteratee);
97
function reduce(collection, iteratee, accumulator);
98
function sortBy(collection, ...iteratees);
99
```
100
101
[Collection Methods](./collection-methods.md)
102
103
### Object Utilities
104
105
Deep object manipulation including property access, merging, transformation, and introspection.
106
107
```javascript { .api }
108
function get(object, path, defaultValue);
109
function set(object, path, value);
110
function merge(object, ...sources);
111
function omit(object, ...paths);
112
function pick(object, ...paths);
113
function keys(object);
114
```
115
116
[Object Methods](./object-methods.md)
117
118
### String Processing
119
120
String manipulation utilities for case conversion, formatting, templating, and parsing.
121
122
```javascript { .api }
123
function camelCase(string);
124
function kebabCase(string);
125
function capitalize(string);
126
function template(string, options);
127
function trim(string, chars = whitespace);
128
function truncate(string, options);
129
```
130
131
[String Methods](./string-methods.md)
132
133
### Function Enhancement
134
135
Function composition, currying, throttling, debouncing, and other functional programming utilities.
136
137
```javascript { .api }
138
function debounce(func, wait = 0, options);
139
function throttle(func, wait = 0, options);
140
function curry(func, arity = func.length);
141
function memoize(func, resolver);
142
function once(func);
143
function partial(func, ...partials);
144
```
145
146
[Function Methods](./function-methods.md)
147
148
### Type Checking & Validation
149
150
Comprehensive type checking utilities for determining data types and validating values.
151
152
```javascript { .api }
153
function isArray(value);
154
function isObject(value);
155
function isString(value);
156
function isFunction(value);
157
function isEmpty(value);
158
function isEqual(value, other);
159
```
160
161
[Type Checking](./type-checking.md)
162
163
### Mathematical Operations
164
165
Mathematical utilities for arithmetic, aggregation, and numerical processing.
166
167
```javascript { .api }
168
function add(augend, addend);
169
function sum(array);
170
function mean(array);
171
function max(array);
172
function min(array);
173
function clamp(number, lower, upper);
174
```
175
176
[Math & Number Methods](./math-number-methods.md)
177
178
### Utility Functions
179
180
General-purpose utilities including flow control, constant generation, and identity functions.
181
182
```javascript { .api }
183
function identity(value);
184
function noop();
185
function constant(value);
186
function times(n, iteratee);
187
function uniqueId(prefix = '');
188
function flow(...funcs);
189
function chain(value);
190
```
191
192
[Utility Methods](./utility-methods.md)
193
194
## Core Types
195
196
```javascript { .api }
197
// Lodash main interface (when using default import)
198
interface LoDashStatic {
199
// All methods are available as properties
200
// Examples:
201
map: typeof map;
202
filter: typeof filter;
203
get: typeof get;
204
// ... 300+ more methods
205
}
206
207
// Iteratee types - functions used for transformation/filtering
208
type Iteratee<T> = string | number | symbol | object | ((value: T) => any);
209
210
// Property paths for object access
211
type PropertyPath = string | number | symbol | Array<string | number | symbol>;
212
213
// Common callback function signatures
214
type ListIterator<T, TResult> = (value: T, index: number, collection: T[]) => TResult;
215
type ObjectIterator<TObject, TResult> = (value: TObject[keyof TObject], key: string, collection: TObject) => TResult;
216
```