- Spec files
npm-lodash
Describes: pkg:npm/lodash@4.1.x
- Description
- A comprehensive JavaScript utility library delivering modularity, performance and extra features for arrays, objects, functions and more
- Author
- tessl
- Last updated
index.md docs/
1# Lodash23Lodash 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.45## Package Information67- **Package Name**: lodash8- **Package Type**: npm9- **Language**: JavaScript10- **Installation**: `npm install lodash`1112## Core Imports1314```javascript15const _ = require('lodash');16```1718For ES6 modules:1920```javascript21import _ from 'lodash';22```2324For selective imports:2526```javascript27import { map, filter, chunk, get, debounce } from 'lodash';28```2930For CommonJS selective imports:3132```javascript33const { map, filter, chunk, get, debounce } = require('lodash');34```3536## Basic Usage3738```javascript39const _ = require('lodash');4041// Array operations42const chunks = _.chunk([1, 2, 3, 4, 5, 6], 2);43// => [[1, 2], [3, 4], [5, 6]]4445const unique = _.uniq([1, 2, 2, 3, 3, 4]);46// => [1, 2, 3, 4]4748// Collection operations49const users = [50{ name: 'John', age: 30, active: true },51{ name: 'Jane', age: 25, active: false },52{ name: 'Bob', age: 35, active: true }53];5455const activeUsers = _.filter(users, 'active');56// => [{ name: 'John', age: 30, active: true }, { name: 'Bob', age: 35, active: true }]5758const names = _.map(users, 'name');59// => ['John', 'Jane', 'Bob']6061// Object operations62const data = { user: { name: 'John', profile: { age: 30 } } };63const age = _.get(data, 'user.profile.age', 0);64// => 306566const merged = _.assign({}, { a: 1 }, { b: 2 }, { c: 3 });67// => { a: 1, b: 2, c: 3 }6869// Function operations70const debouncedSave = _.debounce(saveData, 250);71const curried = _.curry((a, b, c) => a + b + c);7273// String operations74const camelCased = _.camelCase('hello world');75// => 'helloWorld'7677const padded = _.pad('abc', 8);78// => ' abc '79```8081## Architecture8283Lodash is organized around several key design principles:8485- **Functional Programming**: Supports both imperative and functional programming styles86- **Immutability**: Most operations return new values rather than modifying existing ones87- **Iteratee Support**: Functions accept various iteratee types (functions, strings, objects)88- **Performance**: Optimized algorithms and lazy evaluation for efficient processing89- **Modularity**: Available as individual modules for selective imports and tree-shaking9091The library is structured into distinct categories based on data types and operation types, with consistent API patterns across similar functions.9293## Capabilities9495### Array Processing9697Comprehensive array manipulation including chunking, flattening, deduplication, set operations, and transformations.9899```javascript { .api }100function chunk(array, size);101function compact(array);102function difference(array, ...values);103function flatten(array);104function uniq(array);105function zip(...arrays);106```107108[Array Processing](./array.md)109110### Collection Operations111112Iteration, filtering, mapping, grouping, and aggregation functions that work with arrays, objects, and array-like objects.113114```javascript { .api }115function forEach(collection, iteratee);116function map(collection, iteratee);117function filter(collection, predicate);118function reduce(collection, iteratee, accumulator);119function groupBy(collection, iteratee);120function find(collection, predicate);121```122123[Collection Operations](./collection.md)124125### Object Manipulation126127Property access, merging, transformation, and inspection functions for working with objects and their properties.128129```javascript { .api }130function assign(object, ...sources);131function get(object, path, defaultValue);132function set(object, path, value);133function pick(object, ...paths);134function omit(object, ...paths);135function merge(object, ...sources);136```137138[Object Manipulation](./object.md)139140### Function Utilities141142Function composition, currying, throttling, memoization, and other higher-order function operations.143144```javascript { .api }145function curry(func, arity);146function debounce(func, wait, options);147function throttle(func, wait, options);148function memoize(func, resolver);149function partial(func, ...partials);150function bind(func, thisArg, ...partials);151```152153[Function Utilities](./function.md)154155### String Processing156157String manipulation including case conversion, padding, trimming, templating, and parsing operations.158159```javascript { .api }160function camelCase(string);161function kebabCase(string);162function capitalize(string);163function pad(string, length, chars);164function trim(string, chars);165function split(string, separator, limit);166```167168[String Processing](./string.md)169170### Type Checking and Language Utilities171172Comprehensive type checking, value comparison, cloning, and type conversion functions.173174```javascript { .api }175function isArray(value);176function isObject(value);177function isEmpty(value);178function isEqual(value, other);179function clone(value);180function cloneDeep(value);181```182183[Language Utilities](./lang.md)184185### Mathematical Operations186187Mathematical functions for arithmetic, aggregation, rounding, and range operations.188189```javascript { .api }190function add(augend, addend);191function sum(array);192function max(array);193function min(array);194function mean(array);195function round(number, precision);196```197198[Mathematical Operations](./math.md)199200### Utility Functions201202General-purpose utilities including identity functions, flow control, property accessors, and iteration helpers.203204```javascript { .api }205function identity(value);206function noop();207function range(start, end, step);208function times(n, iteratee);209function uniqueId(prefix);210function template(string, options);211```212213[Utility Functions](./util.md)214215### Number Utilities216217Number manipulation functions for clamping, range checking, and random number generation.218219```javascript { .api }220function clamp(number, lower, upper);221function inRange(number, start, end);222function random(lower, upper, floating);223```224225[Number Utilities](./number.md)226227### Date Utilities228229Date and time related utilities for current timestamp retrieval.230231```javascript { .api }232function now();233```234235[Date Utilities](./date.md)236237## Types238239### Common Types240241```javascript { .api }242// Basic iteratee types used throughout the library243type Iteratee<T> = Function | Object | string | number;244type Predicate<T> = Function | Object | string | number;245246// Collection types247type Collection<T> = Array<T> | Object;248type Dictionary<T> = { [key: string]: T };249250// Function wrapper options251interface DebounceOptions {252leading?: boolean;253maxWait?: number;254trailing?: boolean;255}256257interface ThrottleOptions {258leading?: boolean;259trailing?: boolean;260}261262// Template options263interface TemplateOptions {264escape?: RegExp;265evaluate?: RegExp;266imports?: Object;267interpolate?: RegExp;268sourceURL?: string;269variable?: string;270}271```