31 KiB
Compatibility with Lodash
// 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
For maximum compatibility with lodash
, use es-toolkit/compat
, a compatibility layer that bridges the gap between the two libraries.
This module is designed to provide an identical API to lodash
, making it easier to switch between the two libraries.
It's important to note that es-toolkit/compat
may have a slight performance impact and a larger bundle size compared to the original es-toolkit
. This module is designed to facilitate a smooth transition and should be replaced with the original es-toolkit
for optimal performance once the migration is complete.
Design Principles
::: info
The es-toolkit/compat
project is currently in beta and under active development, with design principles subject to change.
:::
Our compatibility layer aims to achieve feature parity with 100% accuracy for:
- Features that are written as a test case in lodash.
- Features that can be inferred from types of
@types/lodash
or@types/lodash-es
.
However, the following are out of scope for es-toolkit/compat
:
- Implicit type conversions, such as converting an empty string to zero or false.
- Functions that have specialized implementations for specific types of arrays, like sortedUniq.
- Method chaining support through "Seq" methods.
Implementation Status
::: info The following emojis indicate the status of each feature:
- ✅: Completed
- 📝: In Review
- ❌: Not Implemented
It's worth noting that even if an implementation is labeled as "in review", it may already be under review to ensure 100% feature parity with lodash, and it's possible that it already offers identical functionality. :::
"Array" method
Function Name | Implementation Status |
---|---|
chunk | ✅ |
compact | 📝 |
concat | ❌ |
difference | 📝 |
differenceBy | 📝 |
differenceWith | 📝 |
drop | 📝 |
dropRight | 📝 |
dropRightWhile | 📝 |
dropWhile | 📝 |
fill | 📝 |
findIndex | ❌ |
findLastIndex | ❌ |
flatten | 📝 |
flattenDeep | 📝 |
flattenDepth | 📝 |
fromPairs | ❌ |
head | 📝 |
indexOf | ❌ |
initial | 📝 |
intersection | 📝 |
intersectionBy | 📝 |
intersectionWith | 📝 |
join | ❌ |
last | 📝 |
lastIndexOf | ❌ |
nth | ❌ |
pull | ❌ |
pullAll | ❌ |
pullAllBy | ❌ |
pullAllWith | ❌ |
pullAt | ❌ |
remove | ❌ |
reverse | ❌ |
slice | ❌ |
sortedIndex | No support |
sortedIndexBy | No support |
sortedIndexOf | No support |
sortedLastIndex | No support |
sortedLastIndexBy | No support |
sortedLastIndexOf | No support |
sortedUniq | No support |
sortedUniqBy | No support |
tail | 📝 |
take | 📝 |
takeRight | 📝 |
takeRightWhile | 📝 |
takeWhile | 📝 |
union | 📝 |
unionBy | 📝 |
unionWith | 📝 |
uniq | 📝 |
uniqBy | 📝 |
uniqWith | 📝 |
unzip | 📝 |
unzipWith | 📝 |
without | 📝 |
xor | 📝 |
xorBy | 📝 |
xorWith | 📝 |
zip | 📝 |
zipObject | 📝 |
zipObjectDeep | ✅ |
zipWith | 📝 |
"Collection" methods
Function Name | Implementation Status |
---|---|
countBy | 📝 |
every | ❌ |
filter | ❌ |
find | ❌ |
findLast | ❌ |
flatMap | ❌ |
flatMapDeep | ❌ |
flatMapDepth | ❌ |
forEach | ❌ |
forEachRight | ❌ |
groupBy | 📝 |
includes | ❌ |
invokeMap | ❌ |
keyBy | 📝 |
map | ❌ |
orderBy | 📝 |
partition | 📝 |
reduce | ❌ |
reduceRight | ❌ |
reject | ❌ |
sample | 📝 |
sampleSize | 📝 |
shuffle | 📝 |
size | ❌ |
some | ❌ |
sortBy | ❌ |
"Date" methods
Function Name | Implementation Status |
---|---|
now | ❌ |
"Function" methods
Function Name | Implementation Status |
---|---|
after | ❌ |
ary | ❌ |
before | ❌ |
bind | ❌ |
bindKey | ❌ |
curry | ❌ |
curryRight | ❌ |
debounce | 📝 |
defer | ❌ |
delay | ❌ |
flip | ❌ |
memoize | ❌ |
negate | 📝 |
once | 📝 |
overArgs | ❌ |
partial | ❌ |
partialRight | ❌ |
rearg | ❌ |
rest | ❌ |
spread | ❌ |
throttle | 📝 |
unary | ❌ |
wrap | ❌ |
"Lang" methods
Function Name | Implementation Status |
---|---|
castArray | ❌ |
clone | 📝 |
cloneDeep | ❌ |
cloneDeepWith | ❌ |
cloneWith | ❌ |
conformsTo | ❌ |
eq | ❌ |
gt | ❌ |
gte | ❌ |
isArguments | ❌ |
isArray | ❌ |
isArrayBuffer | ❌ |
isArrayLike | ❌ |
isArrayLikeObject | ❌ |
isBoolean | ❌ |
isBuffer | ❌ |
isDate | ❌ |
isElement | ❌ |
isEmpty | ❌ |
isEqual | ❌ |
isEqualWith | ❌ |
isError | ❌ |
isFinite | ❌ |
isFunction | ❌ |
isInteger | ❌ |
isLength | ❌ |
isMap | ❌ |
isMatch | ❌ |
isMatchWith | ❌ |
isNaN | ❌ |
isNative | ❌ |
isNil | 📝 |
isNull | 📝 |
isNumber | ❌ |
isObject | ❌ |
isObjectLike | ❌ |
isPlainObject | ❌ |
isRegExp | ❌ |
isSafeInteger | ❌ |
isSet | ❌ |
isString | ❌ |
isSymbol | ❌ |
isTypedArray | ❌ |
isUndefined | 📝 |
isWeakMap | ❌ |
isWeakSet | ❌ |
lt | ❌ |
lte | ❌ |
toArray | ❌ |
toFinite | ❌ |
toInteger | ❌ |
toLength | ❌ |
toNumber | ❌ |
toPlainObject | ❌ |
toSafeInteger | ❌ |
toString | ❌ |
"Math" methods
Function Name | Implementation Status |
---|---|
add | ❌ |
ceil | ❌ |
divide | ❌ |
floor | ❌ |
max | ❌ |
maxBy | 📝 |
mean | 📝 |
meanBy | 📝 |
min | 📝 |
minBy | 📝 |
multiply | ❌ |
round | ❌ |
subtract | ❌ |
sum | 📝 |
sumBy | ❌ |
"Number" methods
Function Name | Implementation Status |
---|---|
clamp | 📝 |
inRange | 📝 |
random | 📝 |
"Object" methods
Function Name | Implementation Status |
---|---|
assign | ❌ |
assignIn | ❌ |
assignInWith | ❌ |
assignWith | ❌ |
at | ❌ |
create | ❌ |
defaults | ❌ |
defaultsDeep | ❌ |
findKey | ❌ |
findLastKey | ❌ |
forIn | ❌ |
forInRight | ❌ |
forOwn | ❌ |
forOwnRight | ❌ |
functions | ❌ |
functionsIn | ❌ |
get | ❌ |
has | ❌ |
hasIn | ❌ |
invert | 📝 |
invertBy | ❌ |
invoke | ❌ |
keys | ❌ |
keysIn | ❌ |
mapKeys | ❌ |
mapValues | ❌ |
mapValues | ❌ |
merge | ❌ |
mergeWith | ❌ |
omit | 📝 |
omitBy | 📝 |
pick | 📝 |
pickBy | 📝 |
result | ❌ |
set | ✅ |
setWith | ❌ |
toPairs | ❌ |
toPairsIn | ❌ |
transform | ❌ |
unset | ❌ |
update | ❌ |
updateWith | ❌ |
values | ❌ |
valuesIn | ❌ |
"String" methods
Function Name | Implementation Status |
---|---|
camelCase | 📝 |
capitalize | 📝 |
deburr | ❌ |
endsWith | ❌ |
escape | ❌ |
escapeRegExp | ❌ |
kebabCase | 📝 |
lowerCase | 📝 |
lowerFirst | ❌ |
pad | ❌ |
padEnd | ❌ |
padStart | ❌ |
parseInt | ❌ |
repeat | ❌ |
replace | ❌ |
snakeCase | 📝 |
split | ❌ |
startCase | ❌ |
startsWith | ❌ |
template | ❌ |
toLower | ❌ |
toUpper | ❌ |
trim | ❌ |
trimEnd | ❌ |
trimStart | ❌ |
truncate | ❌ |
unescape | ❌ |
upperCase | 📝 |
upperFirst | 📝 |
words | ❌ |
"Util" methods
Function Name | Implementation Status |
---|---|
attempt | ❌ |
bindAll | ❌ |
cond | ❌ |
confirms | ❌ |
constant | ❌ |
defaultTo | ❌ |
flow | ❌ |
flowRight | ❌ |
identity | 📝 |
iteratee | ❌ |
matches | ❌ |
matchesProperty | ❌ |
method | ❌ |
methodOf | ❌ |
mixin | No support |
noConflict | No support |
noop | ❌ |
nthArg | ❌ |
over | ❌ |
overEvery | ❌ |
overSome | ❌ |
property | ❌ |
propertyOf | ❌ |
range | 📝 |
rangeRight | 📝 |
runInContext | No support |
stubArray | ❌ |
stubFalse | ❌ |
stubObject | ❌ |
stubString | ❌ |
stubTrue | ❌ |
times | ❌ |
toPath | ❌ |
uniqueId | ❌ |