-
Notifications
You must be signed in to change notification settings - Fork 323
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'main' into feat/kebab-case
- Loading branch information
Showing
100 changed files
with
3,056 additions
and
13 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,50 @@ | ||
![](./docs/public/og.png) | ||
|
||
# es-toolkit · [![MIT License](https://img.shields.io/badge/license-MIT-blue.svg)](https://github.com/toss/slash/blob/main/LICENSE) [![codecov](https://codecov.io/gh/toss/es-toolkit/graph/badge.svg?token=8N5S3AR3C7)](https://codecov.io/gh/toss/es-toolkit) [![NPM badge](https://img.shields.io/npm/v/es-toolkit?logo=npm)](https://www.npmjs.com/package/es-toolkit) [![JSR badge](https://jsr.io/badges/@es-toolkit/es-toolkit)](https://jsr.io/@es-toolkit/es-toolkit) | ||
|
||
[English](https://github.com/toss/es-toolkit/blob/main/README.md) | [한국어](https://github.com/toss/es-toolkit/blob/main/README-ko_kr.md) | 简体中文 | ||
|
||
es-toolkit 是一个先进的、高性能的 JavaScript 实用工具库,具有小的捆绑包大小和强大的类型注解。 | ||
|
||
- es-toolkit 提供多种现代实现的日常实用函数,如 [debounce](https://es-toolkit.slash.page/reference/function/debounce.html)、[delay](https://es-toolkit.slash.page/reference/promise/delay.html)、[chunk](https://es-toolkit.slash.page/reference/array/chunk.html)、[sum](https://es-toolkit.slash.page/reference/math/sum.html) 和 [pick](https://es-toolkit.slash.page/reference/object/pick.html)。 | ||
- 设计时考虑了性能,es-toolkit 在现代 JavaScript 环境中实现了 [2-3 倍的性能提升](https://es-toolkit.slash.page/zh_hans/performance.html)。 | ||
- es-toolkit 支持开箱即用,并且与其他库相比,可以将 JavaScript 代码减少高达 [97%](https://es-toolkit.slash.page/zh_hans/bundle-size.html)。 | ||
- es-toolkit 包含内置的 TypeScript 支持,提供直观且强大的类型。它还提供诸如 [isNotNil](https://es-toolkit.slash.page/zh_hans/reference/predicate/isNotNil.html) 等有用的类型保护。 | ||
- es-toolkit 经过了百分之百的测试覆盖率的实战检验,确保其可靠性和稳健性。 | ||
|
||
## 示例 | ||
|
||
```tsx | ||
// import from '@es-toolkit/es-toolkit' in jsr. | ||
import { debounce, chunk } from 'es-toolkit'; | ||
|
||
const debouncedLog = debounce(message => { | ||
console.log(message); | ||
}, 300); | ||
|
||
// 这个调用将会被防抖处理 | ||
debouncedLog('Hello, world!'); | ||
|
||
const array = [1, 2, 3, 4, 5, 6]; | ||
const chunkedArray = chunk(array, 2); | ||
|
||
console.log(chunkedArray); | ||
// 输出: [[1, 2], [3, 4], [5, 6]] | ||
``` | ||
|
||
## 贡献 | ||
|
||
我们欢迎社区中的每个人贡献。请阅读下面的详细贡献指南。 | ||
|
||
[CONTRIBUTING](https://github.com/toss/es-toolkit/blob/main/.github/CONTRIBUTING.md) | ||
|
||
## 许可证 | ||
|
||
MIT © Viva Republica, Inc. 详细信息请参阅 [LICENSE](./LICENSE)。 | ||
|
||
<a title="Toss" href="https://toss.im"> | ||
<picture> | ||
<source media="(prefers-color-scheme: dark)" srcset="https://static.toss.im/logos/png/4x/logo-toss-reverse.png"> | ||
<img alt="Toss" src="https://static.toss.im/logos/png/4x/logo-toss.png" width="100"> | ||
</picture> | ||
</a> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
import { bench, describe } from 'vitest'; | ||
import { capitalize as capitalizeToolkit } from 'es-toolkit'; | ||
import { capitalize as capitalizeLodash } from 'lodash'; | ||
|
||
describe('capitalize', () => { | ||
bench('es-toolkit/capitalize', () => { | ||
const str = 'camelCase'; | ||
capitalizeToolkit(str); | ||
}); | ||
|
||
bench('lodash/capitalize', () => { | ||
const str = 'camelCase'; | ||
capitalizeLodash(str); | ||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
import { bench, describe } from 'vitest'; | ||
import { flattenDeep as flattenDeepToolkit } from 'es-toolkit'; | ||
import { flattenDeep as flattenDeepLodash } from 'lodash'; | ||
|
||
const createNestedArray = (values: number[]) => { | ||
if (values.length === 0) { | ||
return []; | ||
} | ||
const [first, ...rest] = values; | ||
return [first, createNestedArray(rest)]; | ||
}; | ||
|
||
describe('flattenDeep', () => { | ||
const arr = createNestedArray(Array.from({ length: 30 }, (_, index) => index)); | ||
|
||
bench('es-toolkit/flattenDeep', () => { | ||
flattenDeepToolkit(arr); | ||
}); | ||
|
||
bench('lodash/flattenDeep', () => { | ||
flattenDeepLodash(arr); | ||
}); | ||
|
||
bench('js built-in/flat(Infinity)', () => { | ||
arr.flat(Infinity); | ||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,12 +1,14 @@ | ||
import { defineConfig } from 'vitepress'; | ||
import { en } from './en.mts'; | ||
import { ko } from './ko.mts'; | ||
import { zh_hans } from './zh_hans.mts'; | ||
import { shared } from './shared.mts'; | ||
|
||
export default defineConfig({ | ||
...shared, | ||
locales: { | ||
root: { label: 'English', ...en }, | ||
ko: { label: '한국어', ...ko }, | ||
zh_hans: { label: '简体中文', ...zh_hans }, | ||
}, | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,179 @@ | ||
import { defineConfig, type DefaultTheme } from 'vitepress'; | ||
|
||
export const zh_hans = defineConfig({ | ||
lang: 'zh_hans', | ||
description: | ||
'一款先进的高性能 JavaScript 实用库,具有小巧的包体积和强大的类型注解。', | ||
|
||
themeConfig: { | ||
nav: nav(), | ||
|
||
sidebar: sidebar(), | ||
|
||
editLink: { | ||
pattern: 'https://github.com/toss/es-toolkit/edit/main/docs/:path', | ||
text: '在 GitHub 上编辑此页面', | ||
}, | ||
|
||
footer: { | ||
message: '采用 MIT 许可证发布。', | ||
copyright: `Copyright © ${new Date().getFullYear()} Viva Republica, Inc.`, | ||
}, | ||
}, | ||
}); | ||
|
||
function nav(): DefaultTheme.NavItem[] { | ||
return [ | ||
{ text: '主页', link: '/zh_hans/' }, | ||
{ text: '简介', link: '/zh_hans/intro' }, | ||
{ text: '参考', link: '/zh_hans/reference/array/chunk' }, | ||
]; | ||
} | ||
|
||
function sidebar(): DefaultTheme.Sidebar { | ||
return [ | ||
{ | ||
text: '指南', | ||
items: [ | ||
{ text: '简介', link: '/zh_hans/intro' }, | ||
{ text: '安装', link: '/zh_hans/installation' }, | ||
{ text: '包体积影响', link: '/zh_hans/bundle-size' }, | ||
{ text: '性能', link: '/zh_hans/performance' }, | ||
], | ||
}, | ||
{ | ||
text: '参考', | ||
items: [ | ||
{ | ||
text: '数组工具', | ||
items: [ | ||
{ text: 'chunk', link: '/zh_hans/reference/array/chunk' }, | ||
{ text: 'countBy', link: '/zh_hans/reference/array/countBy' }, | ||
{ text: 'compact', link: '/zh_hans/reference/array/compact' }, | ||
{ text: 'difference', link: '/zh_hans/reference/array/difference' }, | ||
{ text: 'differenceBy', link: '/zh_hans/reference/array/differenceBy' }, | ||
{ text: 'differenceWith', link: '/zh_hans/reference/array/differenceWith' }, | ||
{ text: 'drop', link: '/zh_hans/reference/array/drop' }, | ||
{ text: 'dropWhile', link: '/zh_hans/reference/array/dropWhile' }, | ||
{ text: 'dropRight', link: '/zh_hans/reference/array/dropRight' }, | ||
{ text: 'dropRightWhile', link: '/zh_hans/reference/array/dropRightWhile' }, | ||
{ text: 'fill', link: '/zh_hans/reference/array/fill' }, | ||
{ text: 'toFilled', link: '/zh_hans/reference/array/toFilled' }, | ||
{ text: 'flatten', link: '/zh_hans/reference/array/flatten' }, | ||
{ text: 'forEachRight', link: '/zh_hans/reference/array/forEachRight' }, | ||
{ text: 'groupBy', link: '/zh_hans/reference/array/groupBy' }, | ||
{ text: 'intersection', link: '/zh_hans/reference/array/intersection' }, | ||
{ text: 'intersectionBy', link: '/zh_hans/reference/array/intersectionBy' }, | ||
{ text: 'intersectionWith', link: '/zh_hans/reference/array/intersectionWith' }, | ||
{ text: 'keyBy', link: '/zh_hans/reference/array/keyBy' }, | ||
{ text: 'minBy', link: '/zh_hans/reference/array/minBy' }, | ||
{ text: 'maxBy', link: '/zh_hans/reference/array/maxBy' }, | ||
{ text: 'orderBy', link: '/zh_hans/reference/array/orderBy' }, | ||
{ text: 'partition', link: '/zh_hans/reference/array/partition' }, | ||
{ text: 'sample', link: '/zh_hans/reference/array/sample' }, | ||
{ text: 'sampleSize', link: '/zh_hans/reference/array/sampleSize' }, | ||
{ text: 'shuffle', link: '/zh_hans/reference/array/shuffle' }, | ||
{ text: 'take', link: '/zh_hans/reference/array/take' }, | ||
{ text: 'takeWhile', link: '/zh_hans/reference/array/takeWhile' }, | ||
{ text: 'takeRight', link: '/zh_hans/reference/array/takeRight' }, | ||
{ text: 'takeRightWhile', link: '/zh_hans/reference/array/takeRightWhile' }, | ||
{ text: 'union', link: '/zh_hans/reference/array/union' }, | ||
{ text: 'unionBy', link: '/zh_hans/reference/array/unionBy' }, | ||
{ text: 'unionWith', link: '/zh_hans/reference/array/unionWith' }, | ||
{ text: 'uniq', link: '/zh_hans/reference/array/uniq' }, | ||
{ text: 'uniqBy', link: '/zh_hans/reference/array/uniqBy' }, | ||
{ text: 'uniqWith', link: '/zh_hans/reference/array/uniqWith' }, | ||
{ text: 'unzip', link: '/zh_hans/reference/array/unzip' }, | ||
{ text: 'unzipWith', link: '/zh_hans/reference/array/unzipWith' }, | ||
{ text: 'without', link: '/zh_hans/reference/array/without' }, | ||
{ text: 'xor', link: '/zh_hans/reference/array/xor' }, | ||
{ text: 'xorBy', link: '/zh_hans/reference/array/xorBy' }, | ||
{ text: 'xorWith', link: '/zh_hans/reference/array/xorWith' }, | ||
{ text: 'zip', link: '/zh_hans/reference/array/zip' }, | ||
{ text: 'zipObject', link: '/zh_hans/reference/array/zipObject' }, | ||
{ text: 'zipWith', link: '/zh_hans/reference/array/zipWith' }, | ||
{ text: 'head', link: '/zh_hans/reference/array/head' }, | ||
{ text: 'tail', link: '/zh_hans/reference/array/tail' }, | ||
{ text: 'last', link: '/zh_hans/reference/array/last' }, | ||
], | ||
}, | ||
{ | ||
text: '函数工具', | ||
items: [ | ||
{ text: 'debounce', link: '/zh_hans/reference/function/debounce' }, | ||
{ text: 'throttle', link: '/zh_hans/reference/function/throttle' }, | ||
{ text: 'once', link: '/zh_hans/reference/function/once' }, | ||
{ text: 'noop', link: '/zh_hans/reference/function/noop' }, | ||
], | ||
}, | ||
{ | ||
text: '数学工具', | ||
items: [ | ||
{ text: 'clamp', link: '/zh_hans/reference/math/clamp' }, | ||
{ text: 'inRange', link: '/zh_hans/reference/math/inRange' }, | ||
{ text: 'mean', link: '/zh_hans/reference/math/mean' }, | ||
{ text: 'meanBy', link: '/zh_hans/reference/math/meanBy' }, | ||
{ text: 'random', link: '/zh_hans/reference/math/random' }, | ||
{ text: 'randomInt', link: '/zh_hans/reference/math/randomInt' }, | ||
{ text: 'range', link: '/zh_hans/reference/math/range' }, | ||
{ text: 'round', link: '/zh_hans/reference/math/round' }, | ||
{ text: 'sum', link: '/zh_hans/reference/math/sum' }, | ||
], | ||
}, | ||
{ | ||
text: '对象工具', | ||
items: [ | ||
{ text: 'omit', link: '/zh_hans/reference/object/omit' }, | ||
{ text: 'omitBy', link: '/zh_hans/reference/object/omitBy' }, | ||
{ text: 'pick', link: '/zh_hans/reference/object/pick' }, | ||
{ text: 'pickBy', link: '/zh_hans/reference/object/pickBy' }, | ||
{ text: 'invert', link: '/zh_hans/reference/object/invert' }, | ||
], | ||
}, | ||
{ | ||
text: '谓词', | ||
items: [ | ||
{ text: 'isNil', link: '/zh_hans/reference/predicate/isNil' }, | ||
{ text: 'isNotNil', link: '/zh_hans/reference/predicate/isNotNil' }, | ||
{ text: 'isNull', link: '/zh_hans/reference/predicate/isNull' }, | ||
{ text: 'isUndefined', link: '/zh_hans/reference/predicate/isUndefined' }, | ||
], | ||
}, | ||
{ | ||
text: 'Promise 工具', | ||
items: [{ text: 'delay', link: '/zh_hans/reference/promise/delay' }], | ||
}, | ||
{ | ||
text: '字符串工具', | ||
items: [{ text: 'snakeCase', link: '/zh_hans/reference/string/snakeCase' }], | ||
}, | ||
], | ||
}, | ||
]; | ||
} | ||
|
||
export const search: DefaultTheme.LocalSearchOptions['locales'] = { | ||
zh_hans: { | ||
translations: { | ||
button: { | ||
buttonText: '搜索', | ||
buttonAriaLabel: '搜索', | ||
}, | ||
modal: { | ||
backButtonTitle: '返回', | ||
displayDetails: '显示详情', | ||
footer: { | ||
closeKeyAriaLabel: '关闭', | ||
closeText: '关闭', | ||
navigateDownKeyAriaLabel: '向下导航', | ||
navigateText: '导航', | ||
navigateUpKeyAriaLabel: '向上导航', | ||
selectKeyAriaLabel: '选择', | ||
selectText: '选择', | ||
}, | ||
noResultsText: '未找到搜索结果。', | ||
resetButtonTitle: '重置', | ||
}, | ||
}, | ||
}, | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.