diff --git a/docs/ja/reference/function/asyncNoop.md b/docs/ja/reference/function/asyncNoop.md new file mode 100644 index 000000000..ae641e5bb --- /dev/null +++ b/docs/ja/reference/function/asyncNoop.md @@ -0,0 +1,32 @@ +# asyncNoop + +非同期で何もしない関数です。 関数を要求する場所に空白を埋めるために使用したり、デフォルトで使用することができます。 + +## インターフェース + +```typescript +function asyncNoop(): Promise; +``` + +### 戻り値 + +(`Promise`): `undefined` に解決する `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..2c5a89bb9 --- /dev/null +++ b/docs/ko/reference/function/asyncNoop.md @@ -0,0 +1,32 @@ +# asyncNoop + +비동기적으로 아무것도 하지 않는 함수예요. 함수를 요구하는 곳에 빈 자리를 채우기 위해 사용하거나, 기본값으로 사용할 수 있어요. + +## 인터페이스 + +```typescript +function asyncNoop(): Promise; +``` + +### 반환 값 + +(`Promise`): `undefined`로 이행하는 `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..7d899fe66 --- /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`): 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..af26fd1dd --- /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';