-
Notifications
You must be signed in to change notification settings - Fork 13
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix: deleteEmptyProperties 개선 (#118)
* fix(utils): deleteFalsyProperties 개선 및 isArray 함수 추가 * docs: isArray 문서 추가
- Loading branch information
Showing
8 changed files
with
100 additions
and
10 deletions.
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
--- | ||
'@modern-kit/utils': patch | ||
--- | ||
|
||
fix: deleteFalsyProperties 개선 |
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,25 @@ | ||
# isArray | ||
|
||
주어진 인자가 `배열`인지 검사하고, 맞다면 인자의 타입을 `Array`로 좁혀주는 함수입니다. | ||
|
||
<br /> | ||
|
||
## Code | ||
[🔗 실제 구현 코드 확인](https://github.com/modern-agile-team/modern-kit/blob/main/packages/utils/src/validator/isArray/index.ts) | ||
|
||
## Interface | ||
```ts title="typescript" | ||
const isArray: <T>(value: unknown) => value is T[] | ||
``` | ||
## Usage | ||
```ts title="typescript" | ||
import { isArray } from '@modern-kit/utils'; | ||
|
||
isArray([]); // true | ||
|
||
isArray(() => {}); // false | ||
isArray('123'); // false | ||
isArray(123); // false | ||
isArray({}); // false | ||
``` |
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
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,3 @@ | ||
export const isArray = <T>(value: unknown): value is Array<T> => { | ||
return Array.isArray(value); | ||
}; |
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,20 @@ | ||
import { isArray } from '.'; | ||
|
||
describe('isArray', () => { | ||
it('should return true if the argument is an array, and false if it is not', () => { | ||
expect(isArray([])).toBeTruthy(); | ||
expect(isArray(1)).toBeFalsy(); | ||
expect(isArray('')).toBeFalsy(); | ||
expect(isArray({})).toBeFalsy(); | ||
}); | ||
|
||
it('should narrow the type through if statements', () => { | ||
const testValue = ['foo'] as string | string[]; | ||
|
||
if (isArray<string>(testValue)) { | ||
expectTypeOf(testValue).toEqualTypeOf<string[]>(); | ||
} else { | ||
expectTypeOf(testValue).toEqualTypeOf<string>(); | ||
} | ||
}); | ||
}); |