Skip to main content

Built and signed on GitHub Actions

A modern JavaScript utility library that's 2-3 times faster and up to 97% smaller—a major upgrade to lodash.

This package works with Cloudflare Workers, Node.js, Deno, Bun, Browsers
This package works with Cloudflare Workers
This package works with Node.js
This package works with Deno
This package works with Bun
This package works with Browsers
JSR Score
100%
Published
3 days ago (1.23.0)

es-toolkit compatibility layer with lodash (WIP)

// es-toolkit/compat aims to provide 100% feature parity with lodash
import { chunk } from 'es-toolkit/compat';

chunk([1, 2, 3, 4], 0);
// Returns [], which is identical to lodash

es-toolkit/compat will offer complete compatibility with lodash, ensuring a seamless transition.

To guarantee identical behavior, es-toolkit/compat will be thoroughly tested using actual lodash test cases.

The primary goal of es-toolkit/compat is to serve as a drop-in replacement for lodash.

It's important to note that while es-toolkit/compat will mirror the behavior of lodash functions with 100% accuracy, it will deliberately omit unsafe features, such as:

  • Implicit type casting from an empty string '' to 0 or false, and similar cases.

Classes

c
AbortError

An error class representing an aborted operation.

c
TimeoutError

An error class representing an timeout operation.

Functions

f
after

Creates a function that only executes starting from the n-th call.The provided function will be invoked starting from the n-th call.

f
ary

Creates a function that invokes func, with up to n arguments, ignoring any additional arguments.

f
at

Retrieves elements from an array at the specified indices.

f
attempt

Attempts to execute a function with the provided arguments.If the function throws an error, it catches the error and returns it.If the caught error is not an instance of Error, it wraps it in a new Error.

f
before

Creates a function that limits the number of times the given function (func) can be called.

f
N
bind

Creates a function that invokes func with the this binding of thisArg and partials prepended to the arguments it receives.

f
N
bindKey

Creates a function that invokes the method at object[key] with partialArgs prepended to the arguments it receives.

f
camelCase

Converts a string to camel case.

f
capitalize

Converts the first character of string to upper case and the remaining to lower case.

f
castArray

Casts value as an array if it's not one.

f
ceil

Computes number rounded up to precision.

f
chunk

Splits an array into smaller arrays of a specified length.

f
clamp

Clamps a number within the inclusive upper bound.

f
clone

Creates a shallow clone of the given object.

f
cloneDeep

Creates a deep clone of the given object.

f
compact

Removes falsey values (false, null, 0, 0n, '', undefined, NaN) from an array.

f
concat

Concatenates multiple arrays and values into a single array.

f
conforms

Creates a function that invokes the predicate properties of source with the corresponding property values of a given object, returning true if all predicates return truthy, else false.

f
conformsTo

Checks if object conforms to source by invoking the predicate properties of source with the corresponding property values of object.

f
constantCase

Converts a string to constant case.

f
countBy

Count the occurrences of each item in an arraybased on a transformation function.

f
N
curry

Creates a function that accepts arguments of func and either invokes func returning its result, if at least arity number of arguments have been provided, or returns a function that accepts the remaining func arguments, and so on.The arity of func may be specified if func.length is not sufficient.

f
curryRight

Curries a function, allowing it to be called with a single argument at a time and returning a new function that takes the next argument.This process continues until all arguments have been provided, at which point the original function is called with all accumulated arguments.

f
debounce

Creates a debounced function that delays invoking the provided function until after debounceMs millisecondshave elapsed since the last time the debounced function was invoked. The debounced function also has a cancelmethod to cancel any pending execution.

f
deburr

Converts a string by replacing special characters and diacritical marks with their ASCII equivalents.For example, "Crème brûlée" becomes "Creme brulee".

f
defer

Defers invoking the func until the current call stack has cleared. Any additional arguments are provided to func when it's invoked.

f
delay

Delays the execution of code for a specified number of milliseconds.

f
difference

Computes the difference between an array and multiple arrays.

f
differenceBy

Computes the difference between two arrays after mapping their elements through a provided function.

f
differenceWith

Computes the difference between two arrays based on a custom equality function.

f
drop

Removes a specified number of elements from the beginning of an array and returns the rest.

f
dropRight

Removes a specified number of elements from the end of an array and returns the rest.

f
dropRightWhile

Removes elements from the end of an array until the predicate returns false.

f
dropWhile

Drops elements from the beginning of an array while the predicate function returns truthy.

f
endsWith

Checks if a string contains another string at the end of the string.

f
escape

Converts the characters "&", "<", ">", '"', and "'" in str to their corresponding HTML entities.For example, "<" becomes "<".

f
escapeRegExp

Escapes the RegExp special characters "^", "$", "\", ".", "*", "+", "?", "(", ")", "[", "]", "{", "}", and "|" in str.

f
every

Checks if all elements in an array are truthy.

f
fill

Fills the whole array with a specified value.

f
filter

Filters items from a array and returns an array of elements.

f
find

Finds the first item in an array that matches the given predicate function.

f
findIndex

Finds the index of the first item in an array that matches the given predicate function.

f
findLastIndex

Iterates through an array in reverse order and returns the index of the first item that matches the given predicate function.

f
first

Returns the first element of an array.

f
flatMap

Maps each element in the array using the iteratee function and flattens the result up to the specified depth.

f
flatMapDeep

Recursively maps each element in an array using a provided iteratee function and then deeply flattens the resulting array.

f
flatten

Flattens an array up to the specified depth.

f
flattenDeep

Flattens all depths of a nested array.

f
flattenDepth

Flattens an array up to the specified depth.

f
flattenObject

Flattens a nested object into a single level object with dot-separated keys.

f
flip

Reverses the order of arguments for a given function.

f
floor

Computes number rounded down to precision.

f
flow

Creates a new function that executes the given functions in sequence. The return value of the previous function is passed as an argument to the next function.

f
flowRight

Creates a new function that executes the given functions in sequence from right to left. The return value of the previous function is passed as an argument to the next function.

f
forEachRight

Iterates over elements of 'arr' from right to left and invokes 'callback' for each element.

f
fromPairs

Converts an array of key-value pairs into an object.

f
get

Retrieves the value at a given path from an object. If the resolved value is undefined, the defaultValue is returned instead.

f
groupBy

Groups the elements of an array based on a provided key-generating function.

f
has

Checks if a given path exists within an object.

f
head

Returns the first element of an array.

f
includes

Checks if an item is included in an array.

f
indexOf

Finds the index of the first occurrence of a value in an array.

f
initial

Returns an empty array when the input is a tuple containing exactly one element.

f
inRange

Checks if the value is less than the maximum.

f
intersection

Returns the intersection of two arrays.

f
intersectionBy

Returns the intersection of two arrays based on a mapping function.

f
intersectionWith

Returns the intersection of two arrays based on a custom equality function.

f
invert

Inverts the keys and values of an object. The keys of the input object become the values of the output object and vice versa.

f
isArguments

Checks if the given value is an arguments object.

f
isArray

Checks if the given value is an array.

f
isArrayBuffer

Checks if a given value is ArrayBuffer.

f
isArrayLike

Checks if value is array-like.

f
isArrayLikeObject

Checks if the given value is a non-primitive, array-like object.

f
isBoolean

Checks if the given value is boolean.

f
isDate

Checks if value is a Date object.

f
isEqual

Checks if two values are equal, including support for Date, RegExp, and deep object comparison.

f
isEqualWith

Compares two values for equality using a custom comparison function.

f
isError

Checks if value is an Error object.

f
isFinite

Checks if value is a finite number.

f
isFunction

Checks if value is a function.

f
isInteger

Checks if value is an integer.

f
isJSONArray

Checks if a given value is a valid JSON array.

f
isJSONObject

Checks if a value is a JSON object.

f
isJSONValue

Checks if a given value is a valid JSON value.

f
isLength

Checks if a given value is a valid length.

f
isMap

Checks if a given value is Map.

f
isMatch

Checks if the target matches the source by comparing their structures and values.This function supports deep comparison for objects, arrays, maps, and sets.

f
isNaN

Checks if the value is NaN.

f
isNil

Checks if a given value is null or undefined.

f
isNotNil

Checks if the given value is not null nor undefined.

f
isNull

Checks if the given value is null.

f
isNumber

Checks if a given value is a number.

f
isObject

Checks if the given value is an object. An object is a value that isnot a primitive type (string, number, boolean, symbol, null, or undefined).

f
isObjectLike

Checks if the given value is object-like.

f
isPlainObject

Checks if a given value is a plain object.

f
isPrimitive

Checks whether a value is a JavaScript primitive.JavaScript primitives include null, undefined, strings, numbers, booleans, symbols, and bigints.

f
isRegExp

Checks if value is a RegExp.

f
isSafeInteger

Checks if value is a safe integer (between -(253 – 1) and (253 – 1), inclusive).

f
isSet

Checks if a given value is Set.

f
isString

Checks if a given value is string.

f
isSubset

Checks if the subset array is entirely contained within the superset array.

f
isSymbol

Check whether a value is a symbol.

f
isTypedArray

Checks if a value is a TypedArray.

f
isUndefined

Checks if the given value is undefined.

f
isWeakMap

Checks if the given value is a WeakMap.

f
isWeakSet

Checks if the given value is a WeakSet.

f
join

Joins elements of an array into a string.

f
kebabCase

Converts a string to kebab case.

f
keyBy

Maps each element of an array based on a provided key-generating function.

f
last

Returns the last element of an array.

f
lowerCase

Converts a string to lower case.

f
lowerFirst

Converts the first character of string to lower case.

f
mapKeys

Creates a new object with the same values as the given object, but with keys generatedby running each own enumerable property of the object through the iteratee function.

f
mapValues

Creates a new object with the same keys as the given object, but with values generatedby running each own enumerable property of the object through the iteratee function.

f
matches

Creates a function that performs a deep comparison between a given target and the source object.

f
matchesProperty

Creates a function that checks if a given target object matches a specific property value.

f
max

Finds the element in an array that has the maximum value.

f
maxBy

Finds the element in an array that has the maximum value when applyingthe getValue function to each element.

f
mean

Calculates the average of an array of numbers.

f
meanBy

Calculates the average of an array of numbers when applyingthe getValue function to each element.

f
memoize

Creates a memoized version of the provided function. The memoized function cachesresults based on the argument it receives, so if the same argument is passed again,it returns the cached result instead of recomputing it.

f
merge

Merges the properties of one or more source objects into the target object.

f
mergeWith

Merges the properties of one or more source objects into the target object.

f
min

Finds the element in an array that has the minimum value.

f
minBy

Finds the element in an array that has the minimum value when applyingthe getValue function to each element.

f
negate

Creates a function that negates the result of the predicate function.

f
noop

A no-operation function that does nothing.This can be used as a placeholder or default function.

f
omit

Creates a new object with specified keys omitted.

f
omitBy

Creates a new object composed of the properties that do not satisfy the predicate function.

f
once

Creates a function that is restricted to invoking the provided function func once.Repeated calls to the function will return the value from the first invocation.

f
orderBy

Sorts an array of objects based on multiple properties and their corresponding order directions.

f
pad

Pads string on the left and right sides if it's shorter than length. Padding characters are truncated if they can't be evenly divided by length.If the length is less than or equal to the original string's length, or if the padding character is an empty string, the original string is returned unchanged.

f
padEnd

Pads the end of a string with a given character until it reaches the specified length.

f
padStart

Pads the start of a string with a given character until it reaches the specified length.

f
parseInt

Converts string to an integer of the specified radix. If radix is undefined or 0, a radix of 10 is used unless string is a hexadecimal, in which case a radix of 16 is used.

f
N
partial

Creates a function that invokes func with partialArgs prepended to the arguments it receives. This method is like bind except it does not alter the this binding.

f
N
partialRight

This method is like partial except that partially applied arguments are appended to the arguments it receives.

f
partition

Splits an array into two groups based on a predicate function.

f
pascalCase

Converts a string to Pascal case.

f
pick

Creates a new object composed of the picked object properties.

f
pickBy

Creates a new object composed of the properties that satisfy the predicate function.

f
property

Creates a function that returns the value at a given path of an object.

f
pullAt

Removes elements from an array at specified indices and returns the removed elements.

f
random

Generate a random number within 0 and 1.

f
randomInt

Generates a random integer between 0 (inclusive) and the given maximum (exclusive).

f
range

Returns an array of numbers from 0 (inclusive) to end (exclusive), incrementing by 1.

f
rearg

Creates a function that invokes func with arguments arranged according to the specified indiceswhere the argument value at the first index is provided as the first argument,the argument value at the second index is provided as the second argument, and so on.

f
repeat

Repeats the given string n times.

f
rest

Creates a function that transforms the arguments of the provided function func.The transformed arguments are passed to func such that the arguments starting from a specified indexare grouped into an array, while the previous arguments are passed as individual elements.

f
round

Computes number rounded to precision.

f
sample

Returns a random element from an array.

f
sampleSize

Returns a sample element array of a specified size.

f
set

Sets the value at the specified path of the given object. If any part of the path does not exist, it will be created.

f
shuffle

Randomizes the order of elements in an array using the Fisher-Yates algorithm.

f
size

Returns the length of an array, string, or object.

f
snakeCase

Converts a string to snake case.

f
some

Checks if there is an element in an array that is truthy.

f
sortBy

Sorts an array of objects based on multiple properties and their corresponding order directions.

f
spread

Creates a new function that spreads elements of an array argument into individual argumentsfor the original function. The array argument is positioned based on the argsIndex parameter.

f
startCase

Converts the first character of each word in a string to uppercase and the remaining characters to lowercase.

f
startsWith

Checks if a string contains another string at the beginning of the string.

f
sum

Calculates the sum of an array of numbers.

f
sumBy

Calculates the sum of an array of numbers when applyingthe getValue function to each element.

f
tail

Returns an empty array when the input is a single-element array.

f
take

Returns a new array containing the first count elements from the input array arr.If count is greater than the length of arr, the entire array is returned.

f
takeRight

Returns a new array containing the last count elements from the input array arr.If count is greater than the length of arr, the entire array is returned.

f
takeRightWhile

Takes elements from the end of the array while the predicate function returns true.

f
takeWhile

Returns a new array containing the leading elements of the provided arraythat satisfy the provided predicate function. It stops taking elements as soonas an element does not satisfy the predicate.

f
throttle

Creates a throttled function that only invokes the provided function at most onceper every throttleMs milliseconds. Subsequent calls to the throttled functionwithin the wait time will not trigger the execution of the original function.

f
timeout

Returns a promise that rejects with a TimeoutError after a specified delay.

f
toFilled

Creates a new array filled with the specified value from the start position up to, but not including, the end position.This function does not mutate the original array.

f
toFinite

Converts value to a finite number.

f
toInteger

Converts value to an integer.

f
toMerged

Merges the properties of the source object into a deep clone of the target object.Unlike merge, This function does not modify the original target object.

f
toNumber

Converts value to a number.

f
toPath

Converts a deep key string into an array of path segments.

f
toString

Converts value to a string.

f
trim

Removes leading and trailing whitespace or specified characters from a string.

f
trimEnd

Removes trailing whitespace or specified characters from a string.

f
trimStart

Removes leading whitespace or specified characters from a string.

f
unary

Creates a function that accepts up to one argument, ignoring any additional arguments.

f
unescape

Converts the HTML entities &amp;, &lt;, &gt;, &quot;, and &#39; in str to their corresponding characters.It is the inverse of escape.

f
union

Creates an array of unique values from all given arrays.

f
unionBy

Creates an array of unique values, in order, from all given arrays using a provided mapping function to determine equality.

f
unionWith

Creates an array of unique values from two given arrays based on a custom equality function.

f
uniq

Creates a duplicate-free version of an array.

f
uniqBy

Returns a new array containing only the unique elements from the original array,based on the values returned by the mapper function.

f
uniqWith

Returns a new array containing only the unique elements from the original array,based on the values returned by the comparator function.

f
unset

Removes the property at the given path of the object.

f
unzip

Gathers elements in the same position in an internal arrayfrom a grouped array of elements and returns them as a new array.

f
unzipWith

Unzips an array of arrays, applying an iteratee function to regrouped elements.

f
upperCase

Converts a string to upper case.

f
upperFirst

Converts the first character of string to upper case.

f
without

Creates an array that excludes all specified values.

f
withTimeout

Executes an async function and enforces a timeout.

f
xor

Computes the symmetric difference between two arrays. The symmetric difference is the set of elementswhich are in either of the arrays, but not in their intersection.

f
xorBy

Computes the symmetric difference between two arrays using a custom mapping function.The symmetric difference is the set of elements which are in either of the arrays,but not in their intersection, determined by the result of the mapping function.

f
xorWith

Computes the symmetric difference between two arrays using a custom equality function.The symmetric difference is the set of elements which are in either of the arrays,but not in their intersection.

f
zip

Combines multiple arrays into a single array of tuples.

f
zipObject

Combines two arrays, one of property names and one of corresponding values, into a single object.

f
zipObjectDeep

Creates a deeply nested object given arrays of paths and values.

f
zipWith

Combines multiple arrays into a single array using a custom combiner function.

Interfaces

I
MemoizeCache

Represents a cache for memoization, allowing storage and retrieval of computed values.

Variables

v
bind.placeholder
No documentation available
v
bindKey.placeholder
No documentation available
v
curry.placeholder
No documentation available
v
partial.placeholder
No documentation available
v
partialRight.placeholder
No documentation available

Add Package

deno add jsr:@es-toolkit/es-toolkit

Import symbol

import * as mod from "@es-toolkit/es-toolkit/compat";

---- OR ----

Import directly with a jsr specifier

import * as mod from "jsr:@es-toolkit/es-toolkit/compat";

Add Package

npx jsr add @es-toolkit/es-toolkit

Import symbol

import * as mod from "@es-toolkit/es-toolkit/compat";

Add Package

yarn dlx jsr add @es-toolkit/es-toolkit

Import symbol

import * as mod from "@es-toolkit/es-toolkit/compat";

Add Package

pnpm dlx jsr add @es-toolkit/es-toolkit

Import symbol

import * as mod from "@es-toolkit/es-toolkit/compat";

Add Package

bunx jsr add @es-toolkit/es-toolkit

Import symbol

import * as mod from "@es-toolkit/es-toolkit/compat";