What Lodash Does
- Array — chunk, difference, flatten, uniq, zip
- Collection — each, filter, groupBy, map, reduce, sortBy
- Function — debounce, throttle, memoize, once, partial
- Lang — clone, cloneDeep, isEqual, isEmpty, merge
- Object — get, set, pick, omit, invert, mapKeys
- String — camelCase, kebabCase, startCase, template, truncate
- Chain — fluent API for composing operations
- FP —
lodash/fpprovides auto-curried, immutable versions
Architecture
Highly optimized pure-JS functions, many with custom fast paths for common cases. Each function is publishable as its own npm package (lodash.debounce) for minimal bundles. The main lodash package is ~70KB gzipped but heavily tree-shakeable.
Self-Hosting
Client library — ships in bundle.
Key Features
- 200+ utility functions
- Tree-shakeable when imported by name
- Separate tiny packages per function
- Functional programming variant (
lodash/fp) - Chaining API
- TypeScript types (
@types/lodash) - Battle-tested (30M+ projects use it)
- Zero runtime dependencies
Comparison
| Library | Size | Features | Immutable | TS |
|---|---|---|---|---|
| Lodash | ~70KB | 200+ | fp variant | via @types |
| Ramda | ~50KB | 200+ (FP only) | Yes | Yes |
| Radash | ~10KB | 100+ | Yes | Native |
| es-toolkit | ~8KB | 100+ | Yes | Native |
| Underscore | ~15KB | 100+ | No | via @types |
常见问题 FAQ
Q: ES2023 了还需要 Lodash? A: 大部分简单操作可以用原生(Array.flat, Object.fromEntries),但 cloneDeep, debounce, isEqual, groupBy 原生还不够好或不存在。
Q: Bundle 太大?
A: 按函数导入 import debounce from "lodash/debounce",或用 lodash-es + tree-shake。
Q: 有更现代的替代吗? A: 有。es-toolkit(TypeScript 原生、零依赖、更小)和 Radash 是新势力。
来源与致谢 Sources
- Docs: https://lodash.com/docs
- GitHub: https://github.com/lodash/lodash
- License: MIT