Skip to content

Commit

Permalink
feat(gte): Add gte to compatibility layer (#850)
Browse files Browse the repository at this point in the history
Co-authored-by: Sojin Park <[email protected]>
  • Loading branch information
mass2527 and raon0211 authored Nov 29, 2024
1 parent 49ffce2 commit 05261a9
Show file tree
Hide file tree
Showing 8 changed files with 187 additions and 0 deletions.
20 changes: 20 additions & 0 deletions benchmarks/performance/gte.bench.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
import { bench, describe } from 'vitest';
import { gte as gteToolkitCompat_ } from 'es-toolkit/compat';
import { gte as gteLodash_ } from 'lodash';

const gteToolkitCompat = gteToolkitCompat_;
const gteLodash = gteLodash_;

describe('gte', () => {
bench('es-toolkit/compat/gte', () => {
gteToolkitCompat(3, 1);
gteToolkitCompat(3, 3);
gteToolkitCompat(1, 3);
});

bench('lodash/gte', () => {
gteLodash(3, 1);
gteLodash(3, 3);
gteLodash(1, 3);
});
});
32 changes: 32 additions & 0 deletions docs/ja/reference/compat/util/gte.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
# gte

::: info
この関数は互換性のために `es-toolkit/compat` からのみインポートできます。代替可能なネイティブ JavaScript API があるか、まだ十分に最適化されていないためです。

`es-toolkit/compat` からこの関数をインポートすると、[lodash と完全に同じように動作](../../../compatibility.md)します。
:::

値が他の値以上であるかどうかを確認します。

## インターフェース

```typescript
function gte(value: unknown, other: unknown): boolean;
```

### パラメータ

- `value` (`unknown`): 比較する値です。
- `other` (`unknown`): 比較する他の値です。

### 戻り値

(`boolean`): 値が他の値以上である場合は`true`を、それ以外の場合は`false`を返します。

##

```typescript
gte(3, 1); // => true
gte(3, 3); // => true
gte(1, 3); // => false
```
33 changes: 33 additions & 0 deletions docs/ko/reference/compat/util/gte.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
# gte

::: info
이 함수는 호환성을 위한 `es-toolkit/compat` 에서만 가져올 수 있어요. 대체할 수 있는 네이티브 JavaScript API가 있거나, 아직 충분히 최적화되지 않았기 때문이에요.

`es-toolkit/compat`에서 이 함수를 가져오면, [lodash와 완전히 똑같이 동작](../../../compatibility.md)해요.
:::

값이 다른 값보다 크거나 같은지 확인해요.

## 인터페이스

```typescript
function gte(value: unknown, other: unknown): boolean;
```

### 파라미터

- `value` (`unknown`): 비교할 값이에요. 문자열.
- `other` (`unknown`): 비교할 다른 값이에요. 문자열.

### 반환 값

(`boolean`): 값이 다른 값보다 크거나 같으면 `true`를 반환하고, 그렇지 않으면 `false`를 반환해요.
문자열.

## 예시

```typescript
gte(3, 1); // => true
gte(3, 3); // => true
gte(1, 3); // => false
```
32 changes: 32 additions & 0 deletions docs/reference/compat/util/gte.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
# gte

::: info
This function is only available in `es-toolkit/compat` for compatibility reasons. It either has alternative native JavaScript APIs or isn’t fully optimized yet.

When imported from `es-toolkit/compat`, it behaves exactly like lodash and provides the same functionalities, as detailed [here](../../../compatibility.md).
:::

Checks if value is greater than or equal to other.

## Signature

```typescript
function gte(value: unknown, other: unknown): boolean;
```

### Parameters

- `value` (`unknown`): The value to compare.
- `other` (`unknown`): The other value to compare.

### Returns

(`boolean`): Returns `true` if value is greater than or equal to other, else `false`.

## Examples

```typescript
gte(3, 1); // => true
gte(3, 3); // => true
gte(1, 3); // => false
```
32 changes: 32 additions & 0 deletions docs/zh_hans/reference/compat/util/gte.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
# gte

::: info
出于兼容性原因,此函数仅在 `es-toolkit/compat` 中提供。它可能具有替代的原生 JavaScript API,或者尚未完全优化。

`es-toolkit/compat` 导入时,它的行为与 lodash 完全一致,并提供相同的功能,详情请见 [这里](../../../compatibility.md)
:::

检查值是否大于或等于另一个值。

## 签名

```typescript
function gte(value: unknown, other: unknown): boolean;
```

### 参数

- `value` (`unknown`): 要比较的值。
- `other` (`unknown`): 要比较的另一个值。

### 返回值

(`boolean`): 如果值大于或等于另一个值,则返回`true`,否则返回`false`

## 示例

```typescript
gte(3, 1); // => true
gte(3, 3); // => true
gte(1, 3); // => false
```
1 change: 1 addition & 0 deletions src/compat/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -178,6 +178,7 @@ export { words } from './string/words.ts';
export { constant } from './util/constant.ts';
export { defaultTo } from './util/defaultTo.ts';
export { eq } from './util/eq.ts';
export { gte } from './util/gte.ts';
export { gt } from './util/gt.ts';
export { iteratee } from './util/iteratee.ts';
export { times } from './util/times.ts';
Expand Down
16 changes: 16 additions & 0 deletions src/compat/util/gte.spec.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
import { describe, expect, it } from 'vitest';
import { gte } from './gte';

describe('gte', () => {
it('should return `true` if `value` >= `other`', () => {
expect(gte(3, 1)).toBe(true);
expect(gte(3, 3)).toBe(true);
expect(gte('def', 'abc')).toBe(true);
expect(gte('def', 'def')).toBe(true);
});

it('should return `false` if `value` is less than `other`', () => {
expect(gte(1, 3)).toBe(false);
expect(gte('abc', 'def')).toBe(false);
});
});
21 changes: 21 additions & 0 deletions src/compat/util/gte.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
import { toNumber } from './toNumber.ts';

/**
* Checks if value is greater than or equal to other.
*
* @param {unknown} value The value to compare.
* @param {unknown} other The other value to compare.
* @returns {boolean} Returns `true` if value is greater than or equal to other, else `false`.
*
* @example
* gte(3, 1); // => true
* gte(3, 3); // => true
* gte(1, 3); // => false
*/
export function gte(value: unknown, other: unknown): boolean {
if (typeof value === 'string' && typeof other === 'string') {
return value >= other;
}

return toNumber(value) >= toNumber(other);
}

0 comments on commit 05261a9

Please sign in to comment.