-
Notifications
You must be signed in to change notification settings - Fork 339
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(gte): Add
gte
to compatibility layer (#850)
Co-authored-by: Sojin Park <[email protected]>
- Loading branch information
Showing
8 changed files
with
187 additions
and
0 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
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); | ||
}); | ||
}); |
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,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 | ||
``` |
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,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 | ||
``` |
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,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 | ||
``` |
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,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 | ||
``` |
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,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); | ||
}); | ||
}); |
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,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); | ||
} |