A state-of-the-art, high-performance JavaScript utility library with a small bundle size and strong type annotations.
npx @tessl/cli install tessl/npm-es-toolkit@1.39.0ES-Toolkit is a state-of-the-art, high-performance JavaScript utility library designed as a modern alternative to lodash. It achieves 2-3x better performance with up to 97% smaller bundle sizes while providing comprehensive type safety through TypeScript.
npm install es-toolkitimport { chunk, debounce, sum, pick, isNotNil } from 'es-toolkit';Module-specific imports:
import { chunk } from 'es-toolkit/array';
import { pick } from 'es-toolkit/object';
import { camelCase } from 'es-toolkit/string';
import { debounce } from 'es-toolkit/function';
import { sum } from 'es-toolkit/math';
import { isNotNil } from 'es-toolkit/predicate';
import { delay } from 'es-toolkit/promise';
import { AbortError } from 'es-toolkit/error';
import { attempt, invariant } from 'es-toolkit/util';Lodash compatibility layer:
import { chunk } from 'es-toolkit/compat';import { debounce, chunk, pick, sum, camelCase, isNotNil } from 'es-toolkit';
// Function utilities - debounced logging
const debouncedLog = debounce(message => {
console.log(message);
}, 300);
debouncedLog('Hello, world!');
// Array utilities - chunk array into groups
const numbers = [1, 2, 3, 4, 5, 6];
const chunked = chunk(numbers, 2);
console.log(chunked); // [[1, 2], [3, 4], [5, 6]]
// Object utilities - select properties
const user = { id: 1, name: 'Alice', email: 'alice@example.com', age: 25 };
const publicUser = pick(user, ['id', 'name']);
console.log(publicUser); // { id: 1, name: 'Alice' }
// Math utilities - calculate sum
const scores = [85, 92, 78, 96, 88];
const total = sum(scores);
console.log(total); // 439
// String utilities - convert case
const title = camelCase('hello world example');
console.log(title); // 'helloWorldExample'
// Type guards - filter out nullish values
const mixedArray = [1, null, 'hello', undefined, true, 0];
const validValues = mixedArray.filter(isNotNil);
console.log(validValues); // [1, 'hello', true, 0]ES-Toolkit is organized into modular categories that can be imported individually for optimal tree-shaking:
Comprehensive array manipulation functions including chunking, flattening, set operations, sorting, and transformation utilities. Optimized for performance with strong type safety.
function chunk<T>(arr: readonly T[], size: number): T[][];
function uniq<T>(arr: readonly T[]): T[];
function difference<T>(firstArr: readonly T[], secondArr: readonly T[]): T[];
function flatten<T, D>(arr: readonly T[], depth?: D): Array<FlatArray<T[], D>>;
function groupBy<T, K>(arr: readonly T[], getKeyFromItem: (item: T) => K): Record<K, T[]>;Object property manipulation, merging, cloning, and transformation functions. Includes deep operations and case conversion utilities.
function pick<T, K extends keyof T>(obj: T, keys: readonly K[]): Pick<T, K>;
function omit<T, K extends keyof T>(obj: T, keys: readonly K[]): Omit<T, K>;
function merge<T, S>(target: T, source: S): T & S;
function cloneDeep<T>(obj: T): T;
function mapValues<T, V>(object: T, getNewValue: (value: T[keyof T], key: keyof T, object: T) => V): Record<keyof T, V>;String case conversion, trimming, padding, escaping, and word processing functions. Supports all common case formats and HTML escaping.
function camelCase(str: string): string;
function snakeCase(str: string): string;
function kebabCase(str: string): string;
function capitalize(str: string): string;
function trim(str: string, chars?: string): string;Advanced function utilities including debouncing, throttling, memoization, currying, and composition. Essential for controlling function execution and optimizing performance.
function debounce<F extends (...args: any[]) => any>(
func: F,
debounceMs: number,
options?: DebounceOptions
): DebouncedFunction<F>;
function throttle<F extends (...args: any[]) => any>(
func: F,
throttleMs: number,
options?: ThrottleOptions
): ThrottledFunction<F>;
function memoize<F extends (...args: any[]) => any>(
fn: F,
options?: MemoizeOptions<F>
): F & { cache: MemoizeCache<any, ReturnType<F>> };
function flow<T extends ReadonlyArray<(...args: any[]) => any>>(
...funcs: T
): (...args: Parameters<T[0]>) => ReturnType<T[T['length']][number]>;
function curry<P extends ReadonlyArray<any>, R>(
func: (...args: P) => R
): CurriedFunction<P, R>;
interface DebounceOptions {
signal?: AbortSignal;
edges?: Array<'leading' | 'trailing'>;
}
interface ThrottleOptions {
signal?: AbortSignal;
edges?: Array<'leading' | 'trailing'>;
}
interface MemoizeOptions<F extends (...args: any) => any> {
cache?: MemoizeCache<any, ReturnType<F>>;
getCacheKey?: (args: Parameters<F>[0]) => unknown;
}
interface MemoizeCache<K, V> {
set(key: K, value: V): void;
get(key: K): V | undefined;
has(key: K): boolean;
delete(key: K): boolean | void;
clear(): void;
}
interface DebouncedFunction<F extends (...args: any[]) => void> {
(...args: Parameters<F>): void;
cancel: () => void;
flush: () => void;
schedule: () => void;
}
interface ThrottledFunction<F extends (...args: any[]) => void> {
(...args: Parameters<F>): void;
cancel: () => void;
flush: () => void;
}
type CurriedFunction<P extends ReadonlyArray<any>, R> = P extends readonly [
infer First,
...infer Rest
]
? (arg: First) => Rest extends ReadonlyArray<any>
? CurriedFunction<Rest, R>
: R
: () => R;Numerical computation functions including statistics, random number generation, and range utilities. Optimized for accuracy and performance.
function sum(nums: readonly number[]): number;
function mean(nums: readonly number[]): number;
function median(nums: readonly number[]): number;
function clamp(value: number, bound1: number, bound2?: number): number;
function random(minimum?: number, maximum?: number): number;
function range(start: number, end?: number, step?: number): number[];Comprehensive type checking functions that provide TypeScript type guards for runtime type validation. Essential for type-safe JavaScript development.
function isNotNil<T>(x: T | null | undefined): x is T;
function isPlainObject(value: unknown): value is Record<PropertyKey, any>;
function isEqual(a: any, b: any): boolean;
function isString(value: unknown): value is string;
function isFunction(value: unknown): value is (...args: any[]) => any;
function isPromise(value: unknown): value is Promise<any>;Asynchronous programming utilities including delays, timeouts, and synchronization primitives. Designed for modern async/await patterns.
function delay(ms: number, options?: { signal?: AbortSignal }): Promise<void>;
function withTimeout<T>(promise: Promise<T>, ms: number): Promise<T>;
class Mutex {
acquire(): Promise<void>;
release(): void;
get isLocked(): boolean;
}
class Semaphore {
constructor(permits: number);
acquire(): Promise<void>;
release(): void;
get available(): number;
}Custom error classes for robust application development and enhanced error context.
class AbortError extends Error {
constructor(message?: string);
name: 'AbortError';
}
class TimeoutError extends Error {
constructor(message?: string);
name: 'TimeoutError';
}Essential utility functions for error handling, assertions, and safe function execution. Provides robust patterns for handling failures and ensuring application reliability.
function attempt<T, E>(func: () => T): [null, T] | [E, null];
function attemptAsync<T, E>(func: () => Promise<T>): Promise<[null, T] | [E, null]>;
function invariant(condition: unknown, message: string | Error): asserts condition;
function assert(condition: unknown, message: string | Error): asserts condition;Drop-in replacement layer providing 100% compatibility with lodash functions for seamless migration.
// All standard functions plus lodash-specific behaviors
import { castArray, forEach, every, some } from 'es-toolkit/compat';