Skip to content

Commit

Permalink
Merge branch 'main' into feat/zipObject
Browse files Browse the repository at this point in the history
  • Loading branch information
hautest authored Jun 29, 2024
2 parents be711f7 + a8d7e03 commit c741a44
Show file tree
Hide file tree
Showing 35 changed files with 566 additions and 117 deletions.
16 changes: 16 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,21 @@
# es-toolkit Changelog

## Version v1.5.0

Released on June 28th, 2024.

### Features

- Add support for [range](https://es-toolkit.slash.page/reference/math/range.html). (https://github.com/toss/es-toolkit/pull/77, [2db11d8](https://github.com/toss/es-toolkit/commit/2db11d8882f6d7b0b53271c76f4c5007b6a9181e)).
- Add support for [minBy](https://es-toolkit.slash.page/reference/math/minBy.html) (https://github.com/toss/es-toolkit/pull/71).
- Add support for [maxBy](https://es-toolkit.slash.page/reference/math/maxBy.html) (https://github.com/toss/es-toolkit/pull/64).

### Bug fixes

- Enforce stricter argument types in `pickBy` and `omitBy`. (https://github.com/toss/es-toolkit/pull/60)
- Fix a bug in `difference` where one array parameter was not readonly. (https://github.com/toss/es-toolkit/pull/83)
- Fix a bug in `round` where it incorrectly accepts floating-point numbers as `precision`. (https://github.com/toss/es-toolkit/pull/79)

## Version v1.4.0

Released on June 15th, 2024.
Expand Down
13 changes: 13 additions & 0 deletions benchmarks/compact.bench.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
import { bench, describe } from 'vitest';
import { compact as compactToolkit } from 'es-toolkit';
import { compact as compactLodash } from 'lodash';

describe('compact', () => {
bench('es-toolkit', () => {
compactToolkit([0, 1, false, 2, '', 3, null, undefined, 4, NaN, 5]);
});

bench('lodash', () => {
compactLodash([0, 1, false, 2, '', 3, null, undefined, 4, NaN, 5]);
});
});
13 changes: 13 additions & 0 deletions benchmarks/mean.bench.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
import { bench, describe } from 'vitest';
import { mean as meanToolkit } from 'es-toolkit';
import { mean as meanLodash } from 'lodash';

describe('mean', () => {
bench('es-toolkit/mean', () => {
meanToolkit([1, 2, 3]);
});

bench('lodash/mean', () => {
meanLodash([1, 2, 3]);
});
});
13 changes: 13 additions & 0 deletions benchmarks/range.bench.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
import { bench, describe } from 'vitest';
import { range as rangeToolkit } from 'es-toolkit';
import { range as rangeLodash } from 'lodash';

describe('range', () => {
bench('es-toolkit/range', () => {
rangeToolkit(0, 100, 1);
});

bench('lodash/range', () => {
rangeLodash(0, 100, 1);
});
});
5 changes: 5 additions & 0 deletions docs/.vitepress/en.mts
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@ function sidebar(): DefaultTheme.Sidebar {
text: 'Array Utilities',
items: [
{ text: 'chunk', link: '/reference/array/chunk' },
{ text: 'compact', link: '/reference/array/compact' },
{ text: 'difference', link: '/reference/array/difference' },
{ text: 'differenceBy', link: '/reference/array/differenceBy' },
{ text: 'differenceWith', link: '/reference/array/differenceWith' },
Expand All @@ -59,6 +60,8 @@ function sidebar(): DefaultTheme.Sidebar {
{ text: 'intersection', link: '/reference/array/intersection' },
{ text: 'intersectionBy', link: '/reference/array/intersectionBy' },
{ text: 'intersectionWith', link: '/reference/array/intersectionWith' },
{ text: 'minBy', link: '/reference/array/minBy' },
{ text: 'maxBy', link: '/reference/array/maxBy' },
{ text: 'partition', link: '/reference/array/partition' },
{ text: 'sample', link: '/reference/array/sample' },
{ text: 'shuffle', link: '/reference/array/shuffle' },
Expand Down Expand Up @@ -92,8 +95,10 @@ function sidebar(): DefaultTheme.Sidebar {
text: 'Math Utilities',
items: [
{ text: 'clamp', link: '/reference/math/clamp' },
{ text: 'mean', link: '/reference/math/mean' },
{ text: 'random', link: '/reference/math/random' },
{ text: 'randomInt', link: '/reference/math/randomInt' },
{ text: 'range', link: '/reference/math/range' },
{ text: 'round', link: '/reference/math/round' },
{ text: 'sum', link: '/reference/math/sum' },
],
Expand Down
7 changes: 6 additions & 1 deletion docs/.vitepress/ko.mts
Original file line number Diff line number Diff line change
Expand Up @@ -47,17 +47,20 @@ function sidebar(): DefaultTheme.Sidebar {
text: '배열',
items: [
{ text: 'chunk', link: '/ko/reference/array/chunk' },
{ text: 'compact', link: '/ko/reference/array/compact' },
{ text: 'difference', link: '/ko/reference/array/difference' },
{ text: 'differenceBy', link: '/ko/reference/array/differenceBy' },
{ text: 'differenceWith', link: '/ko/reference/array/differenceWith' },
{ text: 'drop', link: '/ko/reference/array/drop' },
{ text: 'dropRight', link: '/ko/reference/array/dropRight' },
{ text: 'dropWhile', link: '/ko/reference/array/dropWhile' },
{ text: 'dropRight', link: '/ko/reference/array/dropRight' },
{ text: 'dropRightWhile', link: '/ko/reference/array/dropRightWhile' },
{ text: 'groupBy', link: '/ko/reference/array/groupBy' },
{ text: 'intersection', link: '/ko/reference/array/intersection' },
{ text: 'intersectionBy', link: '/ko/reference/array/intersectionBy' },
{ text: 'intersectionWith', link: '/ko/reference/array/intersectionWith' },
{ text: 'minBy', link: '/ko/reference/array/minBy' },
{ text: 'maxBy', link: '/ko/reference/array/maxBy' },
{ text: 'partition', link: '/ko/reference/array/partition' },
{ text: 'sample', link: '/ko/reference/array/sample' },
{ text: 'shuffle', link: '/ko/reference/array/shuffle' },
Expand Down Expand Up @@ -91,9 +94,11 @@ function sidebar(): DefaultTheme.Sidebar {
text: '숫자',
items: [
{ text: 'clamp', link: '/ko/reference/math/clamp' },
{ text: 'mean', link: '/ko/reference/math/mean' },
{ text: 'random', link: '/ko/reference/math/random' },
{ text: 'randomInt', link: '/ko/reference/math/randomInt' },
{ text: 'round', link: '/ko/reference/math/round' },
{ text: 'range', link: '/ko/reference/math/range' },
{ text: 'sum', link: '/ko/reference/math/sum' },
],
},
Expand Down
24 changes: 24 additions & 0 deletions docs/ko/reference/array/compact.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
# compact

거짓으로 평가될 수 있는 값인 `false`, `null`, `0`, `''`, `undefined`, `NaN`을 제거한 새로운 배열을 반환해요.

## 인터페이스

```typescript
function compact<T>(arr: T[]): Array<Exclude<T, false | null | 0 | '' | undefined>>;
```

### 파라미터

- `arr` (`T[]`): 거짓으로 평가될 수 있는 값을 제거할 배열

### 반환 값

(`Array<Exclude<T, false | null | 0 | '' | undefined>>`): 거짓으로 평가될 수 있는 값을 모두 제거한 새로운 배열

## 예시

```typescript
compact([0, 1, false, 2, '', 3, null, undefined, 4, NaN, 5]);
// 반환 값: [1, 2, 3, 4, 5]
```
27 changes: 27 additions & 0 deletions docs/ko/reference/array/maxBy.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
# maxBy

함수가 반환하는 값을 기준으로, 배열에서 최댓값을 가지는 요소를 반환해요.

배열이 비어 있다면, `undefined`를 반환해요.

## 인터페이스

```typescript
function maxBy<T>(items: T[], getValue: (element: T) => number): T;
```

### 파라미터

- `items` (`T[]`): 최댓값을 가지는 요소를 찾을 배열.
- `getValue` (`(element: T) => number`): 요소에 해당되는 숫자를 계산하는 함수.

### 반환 값

(`T`): `getValue` 함수를 기준으로, 배열에서 최댓값을 가지는 요소. 배열이 비어 있다면 `undefined`를 반환해요.

### Example

```typescript
maxBy([{ a: 1 }, { a: 2 }, { a: 3 }], x => x.a); // Returns: { a: 3 }
maxBy([], x => x.a); // Returns: undefined
```
27 changes: 27 additions & 0 deletions docs/ko/reference/array/minBy.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
# minBy

함수가 반환하는 값을 기준으로, 배열에서 최솟값을 가지는 요소를 반환해요.

배열이 비어 있다면, `undefined`를 반환해요.

## 인터페이스

```typescript
function minBy<T>(items: T[], getValue: (element: T) => number): T;
```

### 파라미터

- `items` (`T[]`): 최솟값을 가지는 요소를 찾을 배열.
- `getValue` (`(element: T) => number`): 요소에 해당되는 숫자를 계산하는 함수.

### 반환 값

(`T`): `getValue` 함수를 기준으로, 배열에서 최솟값을 가지는 요소. 배열이 비어 있다면 `undefined`를 반환해요.

### Example

```typescript
minBy([{ a: 1 }, { a: 2 }, { a: 3 }], x => x.a); // Returns: { a: 3 }
minBy([], x => x.a); // Returns: undefined
```
25 changes: 25 additions & 0 deletions docs/ko/reference/math/mean.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
# mean

숫자 배열의 평균을 계산하는 함수에요. 빈 배열에 대해서는 `NaN`을 반환해요.

## 인터페이스

```typescript
function mean(nums: number[]): number;
```

### 파라미터

- `nums` (`number[]`): 평균을 계산할 숫자 배열이에요.

### 반환 값

(`number`): 배열에 있는 모든 숫자의 평균을 반환해요.

## 예시

```typescript
const numbers = [1, 2, 3, 4, 5];
const result = mean(numbers);
// result는 3이 되어요.
```
39 changes: 39 additions & 0 deletions docs/ko/reference/math/range.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
# range

`start`에서 시작해서 `end` 전에 끝나는 숫자의 배열을 반환해요. 연속한 숫자는 `step` 만큼 차이가 나요.

`step`이 기본값은 1이고, 0일 수 없어요.

## 인터페이스

```typescript
function range(end: number): number[];
function range(start: number, end: number): number[];
function range(start: number, end: number, step: number): number[];
```

### 파라미터

- `start` (`number`): 시작할 숫자. 배열은 이 숫자를 포함해요.
- `end` (`number`): 끝날 숫자. 배열은 이 숫자를 포함하지 않아요.
- `step` (`number`): 배열에서 연속한 숫자의 차이. 기본값은 `1`이에요.

### 반환 값

- (`number[]`): `start`에서 시작해서 `end` 전에 끝나는, 연속한 숫자가 `step` 만큼 차이나는 배열.

## 예시

```typescript
// Returns [0, 1, 2, 3]
range(4);

// Returns [0, 5, 10, 15]
range(0, 20, 5);

// Returns []
range(0, -4, -1);

// Throws an error: The step value must be a non-zero integer.
range(1, 4, 0);
```
24 changes: 24 additions & 0 deletions docs/reference/array/compact.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
# compact

Removes falsey values (`false`, `null`, `0`, `''`, `undefined`, `NaN`) from an array.

## Signature

```typescript
function compact<T>(arr: T[]): Array<Exclude<T, false | null | 0 | '' | undefined>>;
```

### Parameters

- `arr` (`T[]`): The input array to remove falsey values.

### Returns

(`Array<Exclude<T, false | null | 0 | '' | undefined>>`) A new array with all falsey values removed.

## Examples

```typescript
compact([0, 1, false, 2, '', 3, null, undefined, 4, NaN, 5]);
// Returns: [1, 2, 3, 4, 5]
```
27 changes: 27 additions & 0 deletions docs/reference/array/maxBy.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
# maxBy

Finds the element in an array that has the maximum value when applying the `getValue` function to each element.

If the list is empty, returns `undefined`.

## Signature

```typescript
function maxBy<T>(items: T[], getValue: (item: T) => number): T;
```

### Parameters

- `items` (`T[]`): The array of elements to search.
- `getValue` (`(item: T) => number`): A function that selects a numeric value from each element.

### Returns

The element with the maximum value as determined by the `getValue` function.

### Example

```typescript
maxBy([{ a: 1 }, { a: 2 }, { a: 3 }], x => x.a); // Returns: { a: 3 }
maxBy([], x => x.a); // Returns: undefined
```
27 changes: 27 additions & 0 deletions docs/reference/array/minBy.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
# minBy

Finds the element in an array that has the minimum value when applying the `getValue` function to each element.

If the list is empty, returns `undefined`.

## Signature

```typescript
function minBy<T>(items: T[], getValue: (item: T) => number): T;
```

### Parameters

- `items` (`T[]`): The array of elements to search.
- `getValue` (`(item: T) => number`): A function that selects a numeric value from each element.

### Returns

The element with the minimum value as determined by the `getValue` function.

### Example

```typescript
minBy([{ a: 1 }, { a: 2 }, { a: 3 }], x => x.a); // Returns: { a: 3 }
minBy([], x => x.a); // Returns: undefined
```
27 changes: 0 additions & 27 deletions docs/reference/math/maxBy.md

This file was deleted.

Loading

0 comments on commit c741a44

Please sign in to comment.