es-toolkit Documentation

repository·main·Indexed 27 days ago

https://github.com/toss/es-toolkit

A high-performance, small-bundle-size JavaScript utility library with strong TypeScript support. Designed as a modern, tree-shakeable alternative to lodash, it includes a compatibility layer (es-toolkit/compat) for 1:1 lodash parity and provides specialized AI agent skills for tools like Claude Code.

Tokens
410.5K
Snippets
1K
Records
2.1K
Agent score
90%

What's inside es-toolkit

  1. Introduction to es-toolkit

    main

    es-toolkit is a modern JavaScript utility library designed for high performance and minimal footprint. It provides a collection of powerful functions for common programming tasks, optimized by leveraging the latest JavaScript features.

    Key advantages over alternatives like lodash include:

    • Smaller Bundle Size: Up to 97% reduction in bundle size.
    • Higher Performance: 2-3x faster runtime performance.
    • Reliability: Built-in TypeScript support and 100% test coverage.
  2. Overview of es-toolkit

    main

    es-toolkit is a high-performance JavaScript utility library designed for modern environments. It provides a wide range of utility functions (such as debounce, delay, chunk, sum, and pick) with a focus on:

    • Performance: Optimized to achieve 2-3x performance improvements in modern JavaScript environments.
    • Small Bundle Size: Supports tree-shaking, potentially reducing JavaScript code by up to 97% compared to other libraries.
    • TypeScript Support: Built-in, robust type annotations and useful type guards like isNotNil.
    • Compatibility: Provides es-toolkit/compat as a compatibility layer to easily replace lodash.
    • Reliability: Maintains 100% test coverage and is used by major open-source projects like Storybook, Recharts, ink, and CKEditor.
  3. Understand es-toolkit bundle size efficiency

    main
    es-toolkit is designed for a minimal bundle footprint, offering up to a 97% reduction in size compared to libraries like lodash. Individual utility functions can be as small as less than 100 bytes, making it highly efficient for modern web applications.
  4. Performance characteristics of es-toolkit/fp

    main
    The es-toolkit/fp package is optimized for high performance by utilizing modern JavaScript APIs and a streamlined implementation focused on essential features. In comparisons with other libraries like remeda, es-toolkit/fp has demonstrated an average performance improvement of 1.5x to 3x.
  5. Understand es-toolkit bundle size advantages

    main
    es-toolkit is designed with a modern implementation to minimize bundle size. Compared to libraries like lodash, es-toolkit can reduce bundle size by up to 97%. Some utility functions in es-toolkit are optimized to be smaller than 100 bytes, making it a highly efficient choice for performance-sensitive applications.
  6. Understand es-toolkit performance characteristics

    main
    es-toolkit is designed for high performance, providing an average of 2× performance improvement compared to alternative libraries like lodash. Certain functions can achieve up to an 11× performance gain by leveraging modern JavaScript APIs. For detailed implementation details of how these benchmarks are conducted, refer to the benchmark code in the repository.
  7. Optimize bundle size with es-toolkit/fp

    main
    The es-toolkit/fp package is designed for minimal bundle size impact. It is significantly smaller than alternatives like remeda (ranging from 1.5x to over 10x smaller). Many utility functions are optimized to be under 100 bytes. The library fully supports tree shaking, allowing you to import only the specific functions you need to keep your production bundles lean.
  8. Choose between es-toolkit, es-toolkit/fp, and es-toolkit/compat

    main

    Depending on your preferred coding style, choose the appropriate entry point:

    • es-toolkit: Use for direct, standard function calls (e.g., map(array, fn)).
    • es-toolkit/fp: Use for functional programming pipelines using pipe (e.g., pipe(array, map(fn))).
    • es-toolkit/compat: Use when migrating from Lodash to maintain existing call sites.
  9. Understand the differences between es-toolkit/compat and es-toolkit

    main

    While es-toolkit/compat is designed for Lodash parity, it differs from the core es-toolkit package in several ways:

    • API Shape: es-toolkit/compat matches Lodash 1:1, including implicit type coercions, multiple argument shapes, and deprecated helpers. es-toolkit only exposes type-safe, modern forms.
    • Performance: es-toolkit/compat is slightly larger and slower than es-toolkit because it includes extra logic to ensure exact Lodash behavior parity.
    • Deprecated Helpers: Functions that are deprecated in Lodash are kept in compat for parity but are not available in es-toolkit.
  10. Understand es-toolkit/fp bundle size advantages

    main
    es-toolkit/fp is designed with a modern implementation to ensure a minimal bundle size. It is significantly smaller than alternatives like remeda, offering up to 1.5x to 10x reduction in size. Many utility functions are optimized to be under 100 bytes. The library also fully supports tree shaking to ensure only the functions you use are included in your final bundle.
  11. Use es-toolkit/server for server-side utilities

    main

    es-toolkit/server is a utility module designed for server runtimes that provide Node.js-compatible APIs (such as Node.js, Deno, and Bun). It provides lightweight APIs for common server-side tasks like running processes and styling terminal output. It includes TypeScript types and maintains a small, predictable interface.

    import { colors, exec } from 'es-toolkit/server';
    
    const result = await exec('git', ['status', '--short'], {
      throwOnNonZeroExitCode: false,
    });
    
    if (result.stdout.trim().length === 0) {
      console.log(colors.green('Working tree is clean.'));
    } else {
      console.log(colors.yellow(result.stdout.trim()));
    }