or run

npx @tessl/cli init
Log in

Version

Tile

Overview

Evals

Files

docs

array.mdcompat.mderror.mdfunction.mdindex.mdmath.mdobject.mdpredicate.mdpromise.mdstring.mdutil.md
tile.json

tessl/npm-es-toolkit

A state-of-the-art, high-performance JavaScript utility library with a small bundle size and strong type annotations.

Workspace
tessl
Visibility
Public
Created
Last updated
Describes
npmpkg:npm/es-toolkit@1.39.x

To install, run

npx @tessl/cli install tessl/npm-es-toolkit@1.39.0

index.mddocs/

ES-Toolkit

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

Package Information

  • Package Name: es-toolkit
  • Package Type: npm
  • Language: TypeScript
  • Installation: npm install es-toolkit

Core Imports

import { 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';

Basic Usage

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]

Architecture

ES-Toolkit is organized into modular categories that can be imported individually for optimal tree-shaking:

  • Core Functions: Main library exports (all modules combined)
  • Typed Utilities: Full TypeScript integration with generic type preservation
  • Performance Focus: Optimized implementations for modern JavaScript environments
  • Tree-Shaking: Module-based exports allow bundlers to include only used functions
  • Compatibility Layer: Optional lodash-compatible API for migration scenarios

Capabilities

Array Utilities

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[]>;

Array Utilities

Object Utilities

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>;

Object Utilities

String Processing

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;

String Processing

Function Control

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;

Function Control

Mathematical Operations

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[];

Mathematical Operations

Type Guards and Predicates

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>;

Type Guards

Promise Utilities

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;
}

Promise Utilities

Error Handling

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';
}

Error Handling

Utility Functions

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;

Utility Functions

Lodash Compatibility

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';

Lodash Compatibility

Performance Benefits

  • 2-3x faster than lodash in modern JavaScript environments
  • Up to 97% smaller bundle size with tree-shaking
  • Zero dependencies - no transitive dependency issues
  • 100% test coverage - production-ready reliability
  • Modern JavaScript - optimized for ES2019+ environments
  • Full TypeScript support - comprehensive type definitions included