Skip to content

Commit

Permalink
Merge branch 'main' into feat/kebab-case
Browse files Browse the repository at this point in the history
  • Loading branch information
raon0211 authored Jul 12, 2024
2 parents ac3abb1 + e9ede74 commit 7ebaae7
Show file tree
Hide file tree
Showing 100 changed files with 3,056 additions and 13 deletions.
2 changes: 1 addition & 1 deletion README-ko_kr.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

# 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)

[English](https://github.com/toss/es-toolkit/blob/main/README.md) | 한국어
[English](https://github.com/toss/es-toolkit/blob/main/README.md) | 한국어 | [简体中文](https://github.com/toss/es-toolkit/blob/main/README-zh_hans.md)

es-toolkit은 높은 성능과 작은 번들 사이즈, 강력한 타입을 자랑하는 현대적인 JavaScript 유틸리티 라이브러리예요.

Expand Down
50 changes: 50 additions & 0 deletions README-zh_hans.md
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>
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

# es-toolkit &middot; [![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-ko_kr.md)
English | [한국어](https://github.com/toss/es-toolkit/blob/main/README-ko_kr.md) | [简体中文](https://github.com/toss/es-toolkit/blob/main/README-zh_hans.md)

es-toolkit is a state-of-the-art, high-performance JavaScript utility library with a small bundle size and strong type annotations.

Expand Down
15 changes: 15 additions & 0 deletions benchmarks/capitalize.bench.ts
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);
});
});
27 changes: 27 additions & 0 deletions benchmarks/flattenDeep.bench.ts
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);
});
});
2 changes: 2 additions & 0 deletions docs/.vitepress/config.mts
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 },
},
});
4 changes: 3 additions & 1 deletion docs/.vitepress/en.mts
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,7 @@ function sidebar(): DefaultTheme.Sidebar {
{ text: 'fill', link: '/reference/array/fill' },
{ text: 'toFilled', link: '/reference/array/toFilled' },
{ text: 'flatten', link: '/reference/array/flatten' },
{ text: 'flattenDeep', link: '/reference/array/flattenDeep' },
{ text: 'forEachRight', link: '/reference/array/forEachRight' },
{ text: 'groupBy', link: '/reference/array/groupBy' },
{ text: 'intersection', link: '/reference/array/intersection' },
Expand Down Expand Up @@ -147,7 +148,8 @@ function sidebar(): DefaultTheme.Sidebar {
text: 'String Utilities',
items: [
{ text: 'snakeCase', link: '/reference/string/snakeCase' },
{ text: 'kebabCase', link: '/reference/string/kebabCase' }
{ text: 'kebabCase', link: '/reference/string/kebabCase' },
{ text: 'capitalize', link: '/reference/string/capitalize' },
],
},
],
Expand Down
2 changes: 2 additions & 0 deletions docs/.vitepress/ko.mts
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,7 @@ function sidebar(): DefaultTheme.Sidebar {
{ text: 'fill', link: '/ko/reference/array/fill' },
{ text: 'toFilled', link: '/ko/reference/array/toFilled' },
{ text: 'flatten', link: '/ko/reference/array/flatten' },
{ text: 'flattenDeep', link: '/ko/reference/array/flattenDeep' },
{ text: 'forEachRight', link: '/reference/array/forEachRight' },
{ text: 'groupBy', link: '/ko/reference/array/groupBy' },
{ text: 'intersection', link: '/ko/reference/array/intersection' },
Expand Down Expand Up @@ -147,6 +148,7 @@ function sidebar(): DefaultTheme.Sidebar {
items: [
{ text: 'snakeCase', link: '/ko/reference/string/snakeCase' },
{ text: 'kebabCase', link: '/ko/reference/string/kebabCase' }
{ text: 'capitalize', link: '/ko/reference/string/capitalize' },
],
},
],
Expand Down
2 changes: 2 additions & 0 deletions docs/.vitepress/shared.mts
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ import { createRequire } from 'module';
import path from 'path';
import { defineConfig } from 'vitepress';
import { search as koSearch } from './ko.mts';
import { search as zh_hansSearch } from './zh_hans.mts';

const require = createRequire(import.meta.url);

Expand Down Expand Up @@ -58,6 +59,7 @@ export const shared = defineConfig({
options: {
locales: {
...koSearch,
...zh_hansSearch,
},
},
},
Expand Down
179 changes: 179 additions & 0 deletions docs/.vitepress/zh_hans.mts
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: '重置',
},
},
},
};
8 changes: 4 additions & 4 deletions docs/ko/reference/array/flatten.md
Original file line number Diff line number Diff line change
Expand Up @@ -22,14 +22,14 @@ function flatten<T, D extends number = 1>(arr: T[], depth?: D): Array<FlatArray<
## 예시

```typescript
const originArr = [1, [2, 3], [4, [5, 6]]];
const array = [1, [2, 3], [4, [5, 6]]];

const array1 = flatten(originArr);
const result1 = flatten(array);
// [1, 2, 3, 4, [5, 6]]를 반환해요.

const array2 = flatten(originArr, 1);
const result2 = flatten(array, 1);
// [1, 2, 3, 4, [5, 6]]를 반환해요.

const array3 = flatten(originArr, 2);
const result3 = flatten(array, 2);
// [1, 2, 3, 4, 5, 6]를 반환해요.
```
Loading

0 comments on commit 7ebaae7

Please sign in to comment.