mirror of
https://github.com/toss/es-toolkit.git
synced 2024-11-28 20:26:33 +03:00
27 KiB
27 KiB
与 Lodash 兼容性
// es-toolkit/compat 的目标是提供与 lodash 百分之百的功能兼容性
import { chunk } from 'es-toolkit/compat';
chunk([1, 2, 3, 4], 0);
// 返回 [], 与 lodash 完全相同
::: warning
es-toolkit/compat
项目目前处于测试版并处于积极开发中,设计原则可能会有所更改。
:::
为了确保从 es-toolkit
到 lodash
的平滑过渡,我们正在开发 es-toolkit/compat
,这是一个兼容层,弥合了这两个库之间的差异。
该模块旨在提供与 lodash
相同的 API,使得在这两个库之间进行切换更加容易。
需要注意的是,与原始 es-toolkit
相比,es-toolkit/compat
可能会对性能产生轻微影响,并且包大小可能会更大。该模块旨在促进平滑过渡,一旦迁移完成,应替换回原始的 es-toolkit
以获得最佳性能。
设计原则
我们的兼容层旨在实现以下功能百分之百的特性一致性:
- 作为 lodash 测试用例编写的功能。
- 可以从
@types/lodash
或@types/lodash-es
的类型推断出的功能。
然而,以下内容不在 es-toolkit/compat
的范围之内:
- 隐式类型转换,例如将空字符串转换为零或假。
- 对特定类型数组有专门实现的函数,比如 sortedUniq。
- 通过 "Seq" 方法支持方法链。
实现状态
::: info 以下表情符号表示每个功能的状态:
- ✅: 已完成
- 📝: 审查中
- ❌: 未实现
值得注意的是,即使某个实现被标记为 "审查中",它可能已经在审查中,以确保与 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 | 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" 工具
函数名称 | 实现状态 |
---|---|
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 | ❌ |
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 | ❌ |
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 | ❌ |