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.6.0

index.md docs/

1
# Lodash
2
3
Lodash is a modern JavaScript utility library delivering modularity, performance, and extras. It provides over 260 utility methods for common programming tasks such as array and object manipulation, string processing, function utilities, and type checking, making JavaScript development more efficient by eliminating boilerplate code.
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 import specific functions
17
import { union, map, filter, isArray } from "lodash";
18
```
19
20
For CommonJS:
21
22
```javascript
23
const _ = require("lodash");
24
// or require specific functions
25
const { union, map, filter, isArray } = require("lodash");
26
```
27
28
## Basic Usage
29
30
```javascript
31
import _ from "lodash";
32
33
// Array operations
34
const arrays = [[2, 1], [4, 2], [1, 2]];
35
const combined = _.union(...arrays);
36
// Result: [2, 1, 4]
37
38
// Object manipulation
39
const users = [
40
{ name: "Alice", age: 25, active: true },
41
{ name: "Bob", age: 30, active: false },
42
{ name: "Charlie", age: 35, active: true }
43
];
44
45
const activeUsers = _.filter(users, "active");
46
const names = _.map(activeUsers, "name");
47
// Result: ["Alice", "Charlie"]
48
49
// Function utilities
50
const expensive = _.memoize(function(n) {
51
return n * n;
52
});
53
54
// Type checking
55
_.isArray([1, 2, 3]); // true
56
_.isString("hello"); // true
57
```
58
59
## Architecture
60
61
Lodash is organized around several key design patterns:
62
63
- **Modular Design**: Every method can be used standalone or as part of the main library
64
- **Method Chaining**: Fluent interface supporting chained operations via `_.chain()`
65
- **Iteratee Shorthand**: Support for property strings, object matches, and functions as iteratees
66
- **Lazy Evaluation**: Deferred execution for chained operations to optimize performance
67
- **Functional Programming**: FP build provides auto-curried, immutable versions of all methods
68
- **Cross-Platform**: Works in browsers, Node.js, and other JavaScript environments
69
70
## Capabilities
71
72
### Array Operations
73
74
Comprehensive array manipulation including transformation, filtering, set operations, and sorting utilities.
75
76
```javascript { .api }
77
// Core union functions
78
function union(...arrays: Array[]): Array;
79
function unionBy(...arrays: Array[], iteratee: Function|Object|string): Array;
80
function unionWith(...arrays: Array[], comparator: Function): Array;
81
82
// Other key array methods
83
function chunk(array: Array, size: number): Array[];
84
function compact(array: Array): Array;
85
function difference(array: Array, ...values: Array[]): Array;
86
function intersection(...arrays: Array[]): Array;
87
function uniq(array: Array): Array;
88
```
89
90
[Array Operations](./array.md)
91
92
### Collection Processing
93
94
Iteration and processing methods for both arrays and objects, including mapping, filtering, grouping, and reduction operations.
95
96
```javascript { .api }
97
function map(collection: Array|Object, iteratee: Function|Object|string): Array;
98
function filter(collection: Array|Object, predicate: Function|Object|string): Array;
99
function find(collection: Array|Object, predicate: Function|Object|string, fromIndex?: number): any;
100
function groupBy(collection: Array|Object, iteratee: Function|Object|string): Object;
101
function reduce(collection: Array|Object, iteratee: Function, accumulator?: any): any;
102
```
103
104
[Collection Processing](./collection.md)
105
106
### Object Utilities
107
108
Object manipulation including property access, assignment, merging, and transformation utilities.
109
110
```javascript { .api }
111
function assign(object: Object, ...sources: Object[]): Object;
112
function get(object: Object, path: Array|string, defaultValue?: any): any;
113
function set(object: Object, path: Array|string, value: any): Object;
114
function pick(object: Object, ...paths: Array|string[]): Object;
115
function omit(object: Object, ...paths: Array|string[]): Object;
116
```
117
118
[Object Utilities](./object.md)
119
120
### Function Utilities
121
122
Function composition, currying, debouncing, throttling, and other functional programming utilities.
123
124
```javascript { .api }
125
function debounce(func: Function, wait: number, options?: Object): Function;
126
function throttle(func: Function, wait: number, options?: Object): Function;
127
function memoize(func: Function, resolver?: Function): Function;
128
function curry(func: Function, arity?: number): Function;
129
function partial(func: Function, ...partials: any[]): Function;
130
```
131
132
[Function Utilities](./function.md)
133
134
### String Processing
135
136
String manipulation including case conversion, trimming, padding, and template utilities.
137
138
```javascript { .api }
139
function camelCase(string: string): string;
140
function kebabCase(string: string): string;
141
function snakeCase(string: string): string;
142
function startsWith(string: string, target: string, position?: number): boolean;
143
function template(string: string, options?: Object): Function;
144
```
145
146
[String Processing](./string.md)
147
148
### Type Checking
149
150
Comprehensive type checking utilities for JavaScript values and objects.
151
152
```javascript { .api }
153
function isArray(value: any): boolean;
154
function isObject(value: any): boolean;
155
function isString(value: any): boolean;
156
function isNumber(value: any): boolean;
157
function isFunction(value: any): boolean;
158
function isEmpty(value: any): boolean;
159
```
160
161
[Type Checking](./lang.md)
162
163
### Mathematical Operations
164
165
Mathematical utilities including basic arithmetic, rounding, and statistical operations.
166
167
```javascript { .api }
168
function add(augend: number, addend: number): number;
169
function subtract(minuend: number, subtrahend: number): number;
170
function max(array: Array): number;
171
function min(array: Array): number;
172
function sum(array: Array): number;
173
```
174
175
[Mathematical Operations](./math.md)
176
177
### General Utilities
178
179
Miscellaneous utilities including iteration, constants, method chaining, and utility functions.
180
181
```javascript { .api }
182
function times(n: number, iteratee: Function): Array;
183
function range(start?: number, end?: number, step?: number): Array;
184
function identity(value: any): any;
185
function constant(value: any): Function;
186
function noop(): undefined;
187
```
188
189
[General Utilities](./util.md)
190
191
## Common Types
192
193
```javascript { .api }
194
// Iteratee can be a function, object, array, or string
195
type Iteratee = Function | Object | Array | string;
196
197
// Many methods accept iteratee shorthands
198
type PropertyName = string | number | Symbol;
199
type PropertyPath = PropertyName | PropertyName[];
200
201
// Collection can be array or object
202
type Collection = Array | Object;
203
204
// Comparator function for custom equality checks
205
type Comparator = (a: any, b: any) => boolean;
206
207
// Predicate function for filtering
208
type Predicate = (value: any, index: number|string, collection: Collection) => boolean;
209
```
210
211
## Aliases
212
213
Lodash provides several aliases for commonly used methods:
214
215
- **each** → forEach
216
- **eachRight** → forEachRight
217
- **extend** → assignIn
218
- **extendWith** → assignInWith
219
- **first** → head
220
221
## Method Chaining
222
223
Lodash supports explicit chaining with `_.chain()` for complex operations:
224
225
```javascript
226
import _ from "lodash";
227
228
const result = _.chain([1, 2, 3, 4, 5, 6])
229
.filter(n => n % 2 === 0)
230
.map(n => n * n)
231
.sum()
232
.value();
233
// Result: 56 (2² + 4² + 6² = 4 + 16 + 36)
234
```
235
236
## Functional Programming
237
238
Lodash provides a separate FP build with auto-curried, data-last functions:
239
240
```javascript
241
import fp from "lodash/fp";
242
243
const getActiveUserNames = fp.flow(
244
fp.filter("active"),
245
fp.map("name")
246
);
247
248
const activeNames = getActiveUserNames(users);
249
```