From 174161d7b7aad2f3fca48a021bc67e1eb10f136a Mon Sep 17 00:00:00 2001 From: ssi02014 Date: Sun, 15 Dec 2024 18:15:09 +0900 Subject: [PATCH 1/5] feat(asyncNoop): add asyncNoop --- docs/ja/reference/function/asyncNoop.md | 32 ++++++++++++++++++++ docs/ko/reference/function/asyncNoop.md | 32 ++++++++++++++++++++ docs/reference/function/asyncNoop.md | 32 ++++++++++++++++++++ docs/zh_hans/reference/function/asyncNoop.md | 32 ++++++++++++++++++++ src/function/asyncNoop.spec.ts | 16 ++++++++++ src/function/asyncNoop.ts | 10 ++++++ src/function/index.ts | 1 + 7 files changed, 155 insertions(+) create mode 100644 docs/ja/reference/function/asyncNoop.md create mode 100644 docs/ko/reference/function/asyncNoop.md create mode 100644 docs/reference/function/asyncNoop.md create mode 100644 docs/zh_hans/reference/function/asyncNoop.md create mode 100644 src/function/asyncNoop.spec.ts create mode 100644 src/function/asyncNoop.ts diff --git a/docs/ja/reference/function/asyncNoop.md b/docs/ja/reference/function/asyncNoop.md new file mode 100644 index 000000000..262f9dbc9 --- /dev/null +++ b/docs/ja/reference/function/asyncNoop.md @@ -0,0 +1,32 @@ +# asyncNoop + +非同期で何もしない関数です。 関数を要求する場所に空白を埋めるために使用したり、デフォルトで使用することができます。 + +## インターフェース + +```typescript +function asyncNoop(): Promise; +``` + +### 戻り値 + +(`Promise`): この関数は、未定義を解決するPromiseを返します。 + +## 例 + +```typescript +import { asyncNoop } from 'es-toolkit/function'; + +interface Props { + fetchData?: () => Promise; +} + +function MyComponent({ fetchData = asyncNoop }: Props) { + const handleFetchData = async () => { + // ここでfetchDataは関数であることが保証されているため、安全に呼び出すことができます。 + await fetchData(); + }; + + handleFetchData(); +} +``` diff --git a/docs/ko/reference/function/asyncNoop.md b/docs/ko/reference/function/asyncNoop.md new file mode 100644 index 000000000..83ff306ef --- /dev/null +++ b/docs/ko/reference/function/asyncNoop.md @@ -0,0 +1,32 @@ +# asyncNoop + +비동기적으로 아무것도 하지 않는 함수예요. 함수를 요구하는 곳에 빈 자리를 채우기 위해 사용하거나, 기본값으로 사용할 수 있어요. + +## 인터페이스 + +```typescript +function asyncNoop(): Promise; +``` + +### 반환 값 + +(`Promise`): 이 함수는 아무런 값도 resolve하지 않는 Promise를 반환해요. + +## 예시 + +```typescript +import { asyncNoop } from 'es-toolkit/function'; + +interface Props { + fetchData?: () => Promise; +} + +function MyComponent({ fetchData = asyncNoop }: Props) { + const handleFetchData = async () => { + // 여기서 fetchData는 undefined일 수 없어서, 자유롭게 부를 수 있어요. + await fetchData(); + }; + + handleFetchData(); +} +``` diff --git a/docs/reference/function/asyncNoop.md b/docs/reference/function/asyncNoop.md new file mode 100644 index 000000000..c3baa494a --- /dev/null +++ b/docs/reference/function/asyncNoop.md @@ -0,0 +1,32 @@ +# asyncNoop + +An asynchronous no-operation function that does nothing. This can be used as a placeholder or default function. + +## Signature + +```typescript +function asyncNoop(): Promise; +``` + +### Returns + +(`Promise`): This function returns a Promise that resolves to undefined. + +## Examples + +```typescript +import { asyncNoop } from 'es-toolkit/function'; + +interface Props { + fetchData?: () => Promise; +} + +function MyComponent({ fetchData = asyncNoop }: Props) { + const handleFetchData = async () => { + // Here fetchData is guaranteed to be a function, so it's safe to call. + await fetchData(); + }; + + handleFetchData(); +} +``` diff --git a/docs/zh_hans/reference/function/asyncNoop.md b/docs/zh_hans/reference/function/asyncNoop.md new file mode 100644 index 000000000..20a267253 --- /dev/null +++ b/docs/zh_hans/reference/function/asyncNoop.md @@ -0,0 +1,32 @@ +# asyncNoop + +一个非同步的空函数。 可以用来在函数需要的地方填充空白,或者作为默认值使用。 + +## 接口 + +```typescript +function asyncNoop(): Promise; +``` + +### 返回值 + +(`Promise`): 这个函数返回一个Promise,它将解析为undefined。 + +## 示例 + +```typescript +import { asyncNoop } from 'es-toolkit/function'; + +interface Props { + fetchData?: () => Promise; +} + +function MyComponent({ fetchData = asyncNoop }: Props) { + const handleFetchData = async () => { + // 这里fetchData是函数,所以可以安全地调用。 + await fetchData(); + }; + + handleFetchData(); +} +``` diff --git a/src/function/asyncNoop.spec.ts b/src/function/asyncNoop.spec.ts new file mode 100644 index 000000000..67ed89966 --- /dev/null +++ b/src/function/asyncNoop.spec.ts @@ -0,0 +1,16 @@ +import { describe, expect, it } from 'vitest'; +import { asyncNoop } from './asyncNoop'; + +describe('asyncNoop', () => { + it('should be a function', () => { + expect(typeof asyncNoop).toBe('function'); + }); + + it('should return a Promise', () => { + expect(asyncNoop()).toBeInstanceOf(Promise); + }); + + it('should resolve to undefined', async () => { + await expect(asyncNoop()).resolves.toBeUndefined(); + }); +}); diff --git a/src/function/asyncNoop.ts b/src/function/asyncNoop.ts new file mode 100644 index 000000000..10c283d8d --- /dev/null +++ b/src/function/asyncNoop.ts @@ -0,0 +1,10 @@ +/** + * An asynchronous no-operation function that does nothing. + * This can be used as a placeholder or default function. + * + * @example + * asyncNoop(); // Does nothing + * + * @returns {Promise} This function returns a Promise that resolves to undefined. + */ +export async function asyncNoop(): Promise {} diff --git a/src/function/index.ts b/src/function/index.ts index fcb4b11e6..e3ab8311c 100644 --- a/src/function/index.ts +++ b/src/function/index.ts @@ -1,5 +1,6 @@ export { after } from './after.ts'; export { ary } from './ary.ts'; +export { asyncNoop } from './asyncNoop.ts'; export { before } from './before.ts'; export { curry } from './curry.ts'; export { curryRight } from './curryRight.ts'; From 9708d369e34e6284e013035d8c4043777ba32ae7 Mon Sep 17 00:00:00 2001 From: Sojin Park Date: Sun, 15 Dec 2024 21:42:27 +0900 Subject: [PATCH 2/5] Update docs/ko/reference/function/asyncNoop.md --- docs/ko/reference/function/asyncNoop.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/docs/ko/reference/function/asyncNoop.md b/docs/ko/reference/function/asyncNoop.md index 83ff306ef..2c5a89bb9 100644 --- a/docs/ko/reference/function/asyncNoop.md +++ b/docs/ko/reference/function/asyncNoop.md @@ -10,7 +10,7 @@ function asyncNoop(): Promise; ### 반환 값 -(`Promise`): 이 함수는 아무런 값도 resolve하지 않는 Promise를 반환해요. +(`Promise`): `undefined`로 이행하는 `Promise`. ## 예시 From 2e5cb551714a8ca91381a2c6fc831eeb0d98b262 Mon Sep 17 00:00:00 2001 From: Sojin Park Date: Sun, 15 Dec 2024 21:42:33 +0900 Subject: [PATCH 3/5] Update docs/ja/reference/function/asyncNoop.md --- docs/ja/reference/function/asyncNoop.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/docs/ja/reference/function/asyncNoop.md b/docs/ja/reference/function/asyncNoop.md index 262f9dbc9..ae641e5bb 100644 --- a/docs/ja/reference/function/asyncNoop.md +++ b/docs/ja/reference/function/asyncNoop.md @@ -10,7 +10,7 @@ function asyncNoop(): Promise; ### 戻り値 -(`Promise`): この関数は、未定義を解決するPromiseを返します。 +(`Promise`): `undefined` に解決する `Promise`。 ## 例 From 1b3940f43e1ec1519949b16a8a04743093c4bc4d Mon Sep 17 00:00:00 2001 From: Sojin Park Date: Sun, 15 Dec 2024 21:42:48 +0900 Subject: [PATCH 4/5] Update docs/reference/function/asyncNoop.md --- docs/reference/function/asyncNoop.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/docs/reference/function/asyncNoop.md b/docs/reference/function/asyncNoop.md index c3baa494a..7d899fe66 100644 --- a/docs/reference/function/asyncNoop.md +++ b/docs/reference/function/asyncNoop.md @@ -10,7 +10,7 @@ function asyncNoop(): Promise; ### Returns -(`Promise`): This function returns a Promise that resolves to undefined. +(`Promise`): A Promise that resolves to undefined. ## Examples From 021dc3814c24079dd94f582767a0062b2281ef60 Mon Sep 17 00:00:00 2001 From: Sojin Park Date: Sun, 15 Dec 2024 21:43:06 +0900 Subject: [PATCH 5/5] Update docs/zh_hans/reference/function/asyncNoop.md --- docs/zh_hans/reference/function/asyncNoop.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/docs/zh_hans/reference/function/asyncNoop.md b/docs/zh_hans/reference/function/asyncNoop.md index 20a267253..af26fd1dd 100644 --- a/docs/zh_hans/reference/function/asyncNoop.md +++ b/docs/zh_hans/reference/function/asyncNoop.md @@ -10,7 +10,7 @@ function asyncNoop(): Promise; ### 返回值 -(`Promise`): 这个函数返回一个Promise,它将解析为undefined。 +(`Promise`): 一个`Promise`,它将解析为`undefined`。 ## 示例