Skip to content

Commit

Permalink
feat(noop): Add noop function
Browse files Browse the repository at this point in the history
  • Loading branch information
raon0211 committed Jun 8, 2024
1 parent 958de0f commit 678028d
Show file tree
Hide file tree
Showing 8 changed files with 82 additions and 1 deletion.
1 change: 1 addition & 0 deletions docs/.vitepress/en.mts
Original file line number Diff line number Diff line change
Expand Up @@ -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' },
],
},
{
Expand Down
1 change: 1 addition & 0 deletions docs/.vitepress/ko.mts
Original file line number Diff line number Diff line change
Expand Up @@ -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' },
],
},
{
Expand Down
28 changes: 28 additions & 0 deletions docs/ko/reference/function/noop.md
Original file line number Diff line number Diff line change
@@ -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 changes: 28 additions & 0 deletions docs/reference/function/noop.md
Original file line number Diff line number Diff line change
@@ -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();
}
```
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -130,4 +130,4 @@
"lint": "eslint ./src --ext .ts",
"format": "prettier --write ."
}
}
}
1 change: 1 addition & 0 deletions src/function/index.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
export { debounce } from './debounce';
export { noop } from './noop';
export { once } from './once';
export { throttle } from './throttle';
12 changes: 12 additions & 0 deletions src/function/noop.spec.ts
Original file line number Diff line number Diff line change
@@ -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 changes: 10 additions & 0 deletions src/function/noop.ts
Original file line number Diff line number Diff line change
@@ -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 {}

0 comments on commit 678028d

Please sign in to comment.