mirror of
https://github.com/toss/es-toolkit.git
synced 2024-11-24 03:32:58 +03:00
feat(noop): Add noop
function
This commit is contained in:
parent
958de0f94b
commit
678028dd3d
@ -83,6 +83,7 @@ function sidebar(): DefaultTheme.Sidebar {
|
||||
{ text: 'debounce', link: '/reference/function/debounce' },
|
||||
{ text: 'throttle', link: '/reference/function/throttle' },
|
||||
{ text: 'once', link: '/reference/function/once' },
|
||||
{ text: 'noop', link: '/reference/function/noop' },
|
||||
],
|
||||
},
|
||||
{
|
||||
|
@ -82,6 +82,7 @@ function sidebar(): DefaultTheme.Sidebar {
|
||||
{ text: 'debounce', link: '/ko/reference/function/debounce' },
|
||||
{ text: 'throttle', link: '/ko/reference/function/throttle' },
|
||||
{ text: 'once', link: '/ko/reference/function/once' },
|
||||
{ text: 'noop', link: '/ko/reference/function/noop' },
|
||||
],
|
||||
},
|
||||
{
|
||||
|
28
docs/ko/reference/function/noop.md
Normal file
28
docs/ko/reference/function/noop.md
Normal file
@ -0,0 +1,28 @@
|
||||
# noop
|
||||
|
||||
아무것도 하지 않는 함수예요. 함수를 요구하는 곳에 빈 자리를 채우기 위해 사용하거나, 기본값으로 사용할 수 있어요.
|
||||
|
||||
## 인터페이스
|
||||
|
||||
```typescript
|
||||
function noop(): void;
|
||||
```
|
||||
|
||||
### 반환 값
|
||||
|
||||
(`void`): 이 함수는 아무것도 반환하지 않아요.
|
||||
|
||||
## 예시
|
||||
|
||||
```typescript
|
||||
import { noop } from 'es-toolkit/function';
|
||||
|
||||
interface Props {
|
||||
onChange?: () => void;
|
||||
}
|
||||
|
||||
function MyComponent({ onChange = noop }: Props) {
|
||||
// 여기서 onChange는 undefined일 수 없어서, 자유롭게 부를 수 있어요.
|
||||
onChange();
|
||||
}
|
||||
```
|
28
docs/reference/function/noop.md
Normal file
28
docs/reference/function/noop.md
Normal file
@ -0,0 +1,28 @@
|
||||
# noop
|
||||
|
||||
A no-operation function that does nothing. This can be used as a placeholder or default function.
|
||||
|
||||
## Signature
|
||||
|
||||
```typescript
|
||||
function noop(): void;
|
||||
```
|
||||
|
||||
### Returns
|
||||
|
||||
(`void`): This function does not return anything.
|
||||
|
||||
## Examples
|
||||
|
||||
```typescript
|
||||
import { noop } from 'es-toolkit/function';
|
||||
|
||||
interface Props {
|
||||
onChange?: () => void;
|
||||
}
|
||||
|
||||
function MyComponent({ onChange = noop }: Props) {
|
||||
// Here onChange is guaranteed to be a function, so it's safe to call.
|
||||
onChange();
|
||||
}
|
||||
```
|
@ -130,4 +130,4 @@
|
||||
"lint": "eslint ./src --ext .ts",
|
||||
"format": "prettier --write ."
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -1,3 +1,4 @@
|
||||
export { debounce } from './debounce';
|
||||
export { noop } from './noop';
|
||||
export { once } from './once';
|
||||
export { throttle } from './throttle';
|
||||
|
12
src/function/noop.spec.ts
Normal file
12
src/function/noop.spec.ts
Normal file
@ -0,0 +1,12 @@
|
||||
import { describe, it, expect } from 'vitest';
|
||||
import { noop } from './path/to/your/noop';
|
||||
|
||||
describe('noop', () => {
|
||||
it('should be a function', () => {
|
||||
expect(typeof noop).toBe('function');
|
||||
});
|
||||
|
||||
it('should return undefined', () => {
|
||||
expect(noop()).toBeUndefined();
|
||||
});
|
||||
});
|
10
src/function/noop.ts
Normal file
10
src/function/noop.ts
Normal file
@ -0,0 +1,10 @@
|
||||
/**
|
||||
* A no-operation function that does nothing.
|
||||
* This can be used as a placeholder or default function.
|
||||
*
|
||||
* @example
|
||||
* noop(); // Does nothing
|
||||
*
|
||||
* @returns {void} This function does not return anything.
|
||||
*/
|
||||
export function noop(): void {}
|
Loading…
Reference in New Issue
Block a user