lodash vs lodash-es
JavaScript Utility Libraries Comparison
3 Years
lodashlodash-esSimilar Packages:
What's JavaScript Utility Libraries?

lodash and lodash-es are popular utility libraries in JavaScript that provide a wide range of functions for common programming tasks, such as manipulating arrays, objects, and strings. They help developers write cleaner, more efficient code by providing ready-to-use functions that handle complex operations, reduce the need for boilerplate code, and improve code readability. The primary difference between the two packages is that lodash is designed for use in all JavaScript environments, while lodash-es is optimized for ES6 (ECMAScript 2015) and later environments, providing a modular structure that allows for tree-shaking and smaller bundle sizes in modern applications.

Package Weekly Downloads Trend
Github Stars Ranking
Stat Detail
Package
Downloads
Stars
Size
Issues
Publish
License
lodash71,490,332
60,821-1184 years agoMIT
lodash-es15,244,792
60,821-1184 years agoMIT
Feature Comparison: lodash vs lodash-es

Module System

  • lodash:

    lodash uses a traditional CommonJS module system, making it compatible with a wide range of JavaScript environments, including Node.js and older browsers.

  • lodash-es:

    lodash-es is built using ES6 module syntax, which allows for more efficient tree-shaking during the build process. This means that only the code you actually use gets included in your final bundle, potentially leading to smaller file sizes.

Tree Shaking

  • lodash:

    lodash does not support tree-shaking, meaning that when you import the library, all of its code is included in your bundle, regardless of which functions you use. This can lead to larger bundle sizes.

  • lodash-es:

    lodash-es is designed for tree-shaking, allowing modern build tools like Webpack and Rollup to eliminate unused code. This feature is particularly beneficial for projects that only need a few functions from the library, as it helps keep the final bundle size smaller.

Compatibility

  • lodash:

    lodash is compatible with all JavaScript environments, including older browsers and Node.js. This makes it a reliable choice for projects that need to support a wide range of platforms and environments.

  • lodash-es:

    lodash-es is designed for modern JavaScript environments that support ES6. While it may not be suitable for projects that need to support older browsers without transpilation, it is ideal for applications that leverage modern JavaScript features.

Functionality

  • lodash:

    lodash provides a comprehensive set of utility functions for manipulating arrays, objects, strings, and more. It is a one-stop solution for many common programming tasks, making it a valuable tool for developers.

  • lodash-es:

    lodash-es offers the same functionality as lodash, but with the added benefit of being modular. This allows developers to import only the functions they need, reducing the overall size of their code and improving performance.

Example Code

  • lodash:

    Example of using lodash in a project:

    const _ = require('lodash');
    
    // Using lodash to debounce a function
    const debouncedFunction = _.debounce(() => {
      console.log('Function executed!');
    }, 1000);
    
    // Calling the debounced function multiple times
    for (let i = 0; i < 10; i++) {
      debouncedFunction();
    }
    
  • lodash-es:

    Example of using lodash-es in a project:

    import { debounce } from 'lodash-es';
    
    // Using lodash-es to debounce a function
    const debouncedFunction = debounce(() => {
      console.log('Function executed!');
    }, 1000);
    
    // Calling the debounced function multiple times
    for (let i = 0; i < 10; i++) {
      debouncedFunction();
    }
    
How to Choose: lodash vs lodash-es
  • lodash:

    Choose lodash if you need a comprehensive utility library that works in all JavaScript environments, including older browsers. It is suitable for projects that require a wide range of utility functions without concern for bundle size.

  • lodash-es:

    Choose lodash-es if you are working in a modern JavaScript environment that supports ES6 modules. It is ideal for projects that use tree-shaking to reduce bundle size, as it allows you to import only the functions you need.

README for lodash

lodash v4.17.21

The Lodash library exported as Node.js modules.

Installation

Using npm:

$ npm i -g npm
$ npm i --save lodash

In Node.js:

// Load the full build.
var _ = require('lodash');
// Load the core build.
var _ = require('lodash/core');
// Load the FP build for immutable auto-curried iteratee-first data-last methods.
var fp = require('lodash/fp');

// Load method categories.
var array = require('lodash/array');
var object = require('lodash/fp/object');

// Cherry-pick methods for smaller browserify/rollup/webpack bundles.
var at = require('lodash/at');
var curryN = require('lodash/fp/curryN');

See the package source for more details.

Note:
Install n_ for Lodash use in the Node.js < 6 REPL.

Support

Tested in Chrome 74-75, Firefox 66-67, IE 11, Edge 18, Safari 11-12, & Node.js 8-12.
Automated browser & CI test runs are available.