Skip to content

Lodashとの互換性 ​

tsx
// es-toolkit/compatはlodashと100%同じ動作を提供することを目指しています
import { chunk } from 'es-toolkit/compat';

// es-toolkitは元々chunkのサイズとして0をサポートしていませんでした
chunk([1, 2, 3, 4], 0);
// es-toolkit/compatはlodashと同じ[]を返します

lodashとの最大の互換性を確保するために、2つのライブラリ間のギャップを埋める互換レイヤーであるes-toolkit/compatを使用してください。

es-toolkitはスムーズなマイグレーションを保証するために、2つのライブラリ間の動作の違いがないes-toolkit/compatライブラリを開発しています。lodashと同じAPIと機能を提供し、スムーズにマイグレーションできるようサポートする予定です。

es-toolkit/compatは実際のlodashテストコードを使用してテストされます。

es-toolkit/compatは、元のes-toolkitと比較して若干のパフォーマンス低下とバンドルサイズの増加があることに注意してください。このモジュールはスムーズな移行を支援するために設計されており、移行が完了したら最適なパフォーマンスを得るために元のes-toolkitに置き換えるべきです。

デザイン原則 ​

INFO

デザイン原則は変更される可能性があります。

es-toolkit/compatは以下のような機能についてlodashと100%同じ機能を提供することを目指しています。

  • lodashのテストケースで作成された機能
  • @types/lodashまたは@types/lodash-esの型から推論できる機能

以下のような機能はes-toolkit/compatではサポートしていません。

  • 空文字列を0またはfalseに変換するような暗黙的な型変換
  • sortedUniqのような特定のタイプの配列に特化した実装を持つ関数
  • Array.prototypeのようなJavaScriptの組み込みオブジェクトのプロトタイプが変更された場合に対応するコード
  • JavaScript Realmに対応するコード
  • _(arr).map(...).filter(...)のような"Seq"メソッドを通じたメソッドチェーンのサポート

実装ステータス ​

INFO

以下の絵文字は各機能の実装ステータスを示しています:

  • ✅: 完了(関数は完全に実装され、lodashのテストコードで全てのテストに合格しています。)
  • 📝: レビュー中(関数は実装されていますが、まだlodashのテストコードでテストされていません。)
  • ❌: 未実装(関数はまだ実装されていません。)

"レビュー中"と表示されていても、完全に同じか確認しているだけですでに同じ機能を提供しているかもしれません。

"Array" メソッド

関数名実装状況
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サポートなし
sortedIndexByサポートなし
sortedIndexOfサポートなし
sortedLastIndexサポートなし
sortedLastIndexByサポートなし
sortedLastIndexOfサポートなし
sortedUniqサポートなし
sortedUniqByサポートなし
tail✅
take✅
takeRight✅
takeRightWhile✅
takeWhile📝
union✅
unionBy📝
unionWith📝
uniq✅
uniqBy✅
uniqWith📝
unzip✅
unzipWith📝
without✅
xor📝
xorBy📝
xorWith📝
zip✅
zipObject📝
zipObjectDeep✅
zipWith📝

"Collection" メソッド

関数名実装状況
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" メソッド

関数名実装状況
now✅

"Function" メソッド

関数名実装状況
after✅
ary✅
before✅
bind✅
bindKey✅
curry✅
curryRight✅
debounce✅
defer✅
delay✅
flip✅
memoize📝
negate✅
once✅
overArgs❌
partial📝
partialRight📝
rearg✅
rest✅
spread✅
throttle✅
unary✅
wrap❌

"Lang" メソッド

関数名実装状況
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" メソッド

関数名実装状況
add✅
ceil✅
divide❌
floor✅
max✅
maxBy📝
mean📝
meanBy📝
min✅
minBy📝
multiply✅
round✅
subtract✅
sum✅
sumBy✅

"Number" メソッド

関数名実装状況
clamp✅
inRange✅
random✅

"Object" メソッド

関数名実装状況
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✅
merge✅
mergeWith✅
omit✅
omitBy📝
pick✅
pickBy📝
result❌
set✅
setWith❌
toPairs❌
toPairsIn❌
transform❌
unset✅
update❌
updateWith❌
values❌
valuesIn❌

"String" メソッド

関数名実装状況
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" メソッド

関数名実装状況
attempt✅
bindAll❌
cond❌
conforms✅
constant✅
defaultTo✅
flow✅
flowRight✅
identity✅
iteratee✅
matches✅
matchesProperty✅
method✅
methodOf✅
mixinサポートなし
noConflictサポートなし
noop✅
nthArg✅
over❌
overEvery❌
overSome❌
property✅
propertyOf✅
range✅
rangeRight✅
runInContextサポートなし
stubArray✅
stubFalse✅
stubObject✅
stubString✅
stubTrue✅
times✅
toPath✅
uniqueId✅

MIT ライセンスの下で配布されています。