-
Notifications
You must be signed in to change notification settings - Fork 343
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
8 changed files
with
82 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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(); | ||
} | ||
``` |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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(); | ||
} | ||
``` |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -130,4 +130,4 @@ | |
"lint": "eslint ./src --ext .ts", | ||
"format": "prettier --write ." | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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'; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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(); | ||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 {} |