feat(noop): Add noop function

This commit is contained in:
Sojin Park 2024-06-08 15:47:30 +09:00
parent 958de0f94b
commit 678028dd3d
8 changed files with 82 additions and 1 deletions

View File

@ -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' },
],
},
{

View File

@ -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' },
],
},
{

View 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();
}
```

View 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();
}
```

View File

@ -130,4 +130,4 @@
"lint": "eslint ./src --ext .ts",
"format": "prettier --write ."
}
}
}

View File

@ -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
View 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
View 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 {}