-
-
Notifications
You must be signed in to change notification settings - Fork 0
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
1 parent
4e7edee
commit b82fada
Showing
26 changed files
with
862 additions
and
0 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,9 @@ | ||
export const STRING = 'string' | ||
export const NUMBER = 'number' | ||
export const UNDEFINED = 'undefined' | ||
export const SYMBOL = 'symbol' | ||
export const BOOLEAN = 'boolean' | ||
export const OBJECT = 'object' | ||
export const FUNCTION = 'function' | ||
export const NULL = null | ||
export const BIGINT = 'bigint' |
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,4 +1,17 @@ | ||
export { add } from '@/add' | ||
export { divide } from '@/divide' | ||
export type { IsBigint } from '@/isBigint' | ||
export { isBigint } from '@/isBigint' | ||
export type { IsNill } from '@/isNill' | ||
export { isNill } from '@/isNill' | ||
export type { IsNull } from '@/isNull' | ||
export { isNull } from '@/isNull' | ||
export type { IsNumber } from '@/isNumber' | ||
export { isNumber } from '@/isNumber' | ||
export type { IsString } from '@/isString' | ||
export { isString } from '@/isString' | ||
export type { IsSymbol } from '@/isSymbol' | ||
export { isSymbol } from '@/isSymbol' | ||
export { multiply } from '@/multiply' | ||
export { subtract } from '@/subtract' | ||
export type { AnyFn } from '@/types' |
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,24 @@ | ||
import { BIGINT } from '@/constants' | ||
|
||
/** | ||
* Bigint or not | ||
* | ||
* @typeParam T - any value | ||
*/ | ||
type IsBigint<T extends unknown> = T extends bigint ? true : false | ||
|
||
/** | ||
* Whatever argument is type of bigint or not. | ||
* | ||
* @param val - input any value | ||
* @returns The result of `typeof val === 'bigint'` | ||
* | ||
* @example | ||
* isBigint(1n) // true | ||
* isBigint(1000) // false | ||
*/ | ||
const isBigint = <T extends unknown>(val: T): IsBigint<T> => | ||
(typeof val === BIGINT) as IsBigint<T> | ||
|
||
export { isBigint } | ||
export type { IsBigint } |
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,24 @@ | ||
import { BOOLEAN } from '@/constants' | ||
|
||
/** | ||
* Boolean or not | ||
* | ||
* @typeParam T - any value | ||
*/ | ||
type IsBoolean<T extends unknown> = T extends boolean ? true : false | ||
|
||
/** | ||
* Whatever argument is type of boolean or not. | ||
* | ||
* @param val - input any value | ||
* @returns The result of `typeof val === 'boolean'` | ||
* | ||
* @example | ||
* isBoolean(true) // true | ||
* isBoolean('hello') // false | ||
*/ | ||
const isBoolean = <T extends unknown>(val: T): IsBoolean<T> => | ||
(typeof val === BOOLEAN) as IsBoolean<T> | ||
|
||
export { isBoolean } | ||
export type { IsBoolean } |
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 @@ | ||
import { FUNCTION } from '@/constants' | ||
import type { AnyFn } from '@/types' | ||
|
||
/** | ||
* Function or not | ||
* | ||
* @typeParam T - any value | ||
*/ | ||
type IsFunction<T extends unknown> = T extends AnyFn ? true : false | ||
|
||
/** | ||
* Whatever argument is type of function or not. | ||
* | ||
* @param val - input any value | ||
* @returns The result of `typeof val === 'function'` | ||
* | ||
* @example | ||
* isFunction(function) // true | ||
* isFunction('hello') // false | ||
*/ | ||
const isFunction = <T extends unknown>(val: T): IsFunction<T> => | ||
(typeof val === FUNCTION) as IsFunction<T> | ||
|
||
export { isFunction } | ||
export type { IsFunction } |
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,29 @@ | ||
import type { IsNull } from '@/isNull' | ||
import { isNull } from '@/isNull' | ||
import { IsUndefined, isUndefined } from '@/isUndefined' | ||
/** | ||
* Undefiled or null, or not | ||
* | ||
* @typeParam T - any value | ||
*/ | ||
type IsNill<T extends unknown> = IsUndefined<T> extends true | ||
? true | ||
: IsNull<T> extends true | ||
? true | ||
: false | ||
|
||
/** | ||
* Whatever argument is type of undefined or null. | ||
* | ||
* @param val - input any value | ||
* @returns The result of type of `val` is undefined or null | ||
* | ||
* @example | ||
* isNumber(0) // true | ||
* isNumber('hello') // false | ||
*/ | ||
const isNill = <T extends unknown>(val: T): IsNill<T> => | ||
((isUndefined(val) || isNull(val)) as unknown) as IsNill<T> | ||
|
||
export { isNill } | ||
export type { IsNill } |
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,24 @@ | ||
import { NULL } from '@/constants' | ||
|
||
/** | ||
* Null or not | ||
* | ||
* @typeParam T - any value | ||
*/ | ||
type IsNull<T extends unknown> = T extends null ? true : false | ||
|
||
/** | ||
* Whatever argument is type of null or not. | ||
* | ||
* @param val - input any value | ||
* @returns The result of `val === null` | ||
* | ||
* @example | ||
* isNull(null) // true | ||
* isNull(undefined) // false | ||
*/ | ||
const isNull = <T extends unknown>(val: T): IsNull<T> => | ||
(val === NULL) as IsNull<T> | ||
|
||
export { isNull } | ||
export type { IsNull } |
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,24 @@ | ||
import { NUMBER } from '@/constants' | ||
|
||
/** | ||
* Number or not | ||
* | ||
* @typeParam T - any value | ||
*/ | ||
type IsNumber<T extends unknown> = T extends number ? true : false | ||
|
||
/** | ||
* Whatever argument is type of number or not. | ||
* | ||
* @param val - input any value | ||
* @returns The result of `typeof val === 'number'` | ||
* | ||
* @example | ||
* isNumber(0) // true | ||
* isNumber('hello') // false | ||
*/ | ||
const isNumber = <T extends unknown>(val: T): IsNumber<T> => | ||
(typeof val === NUMBER) as IsNumber<T> | ||
|
||
export { isNumber } | ||
export type { IsNumber } |
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,40 @@ | ||
import { IsPrimitive, isPrimitive } from '@/isPrimitive' | ||
|
||
/** | ||
* Object or not | ||
* | ||
* @typeParam T - any value | ||
*/ | ||
type IsObject<T extends unknown> = IsPrimitive<T> extends true ? false : true | ||
|
||
/** | ||
* Whatever argument is type of object or not. | ||
* | ||
* @param val - input any value | ||
* @returns The result of object or not | ||
* | ||
* @remarks | ||
* Definition of Object | ||
* | ||
* Not Primitive | ||
* | ||
* @remarks | ||
* Definition of Primitive | ||
* - string | ||
* - number | ||
* - bigint | ||
* - boolean | ||
* - symbol | ||
* - undefined | ||
* - null | ||
* | ||
* | ||
* @example | ||
* isObject([]) // true | ||
* isObject('hello') // false | ||
*/ | ||
const isObject = <T extends unknown>(val: unknown): IsObject<T> => | ||
!isPrimitive(val) as IsObject<T> | ||
|
||
export { isObject } | ||
export type { IsObject } |
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,53 @@ | ||
import { IsBigint, isBigint } from '@/isBigint' | ||
import { IsBoolean, isBoolean } from '@/isBoolean' | ||
import { IsNill, isNill } from '@/isNill' | ||
import { IsNumber, isNumber } from '@/isNumber' | ||
import { IsString, isString } from '@/isString' | ||
import { IsSymbol, isSymbol } from '@/isSymbol' | ||
|
||
/** | ||
* Primitive or not | ||
* | ||
* @typeParam T - any value | ||
*/ | ||
type IsPrimitive<T extends unknown> = IsBigint<T> extends true | ||
? true | ||
: IsBoolean<T> extends true | ||
? true | ||
: IsNill<T> extends true | ||
? true | ||
: IsNumber<T> extends true | ||
? true | ||
: IsString<T> extends true | ||
? true | ||
: IsSymbol<T> extends true | ||
? true | ||
: false | ||
|
||
/** | ||
* Whatever argument is primitive or not. | ||
* | ||
* @param val - input any value | ||
* @returns The result of primitive or not | ||
* | ||
* @remarks | ||
* Definition of Primitive | ||
* - string | ||
* - number | ||
* - bigint | ||
* - boolean | ||
* - symbol | ||
* - undefined | ||
* - null | ||
* | ||
* @example | ||
* isPrimitive(true) // true | ||
* isPrimitive([]) // false | ||
*/ | ||
const isPrimitive = <T extends unknown>(val: T): IsPrimitive<T> => | ||
[isNill, isBoolean, isNumber, isString, isBigint, isSymbol].some((is) => | ||
is(val) | ||
) as IsPrimitive<T> | ||
|
||
export { isPrimitive } | ||
export type { IsPrimitive } |
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,24 @@ | ||
import { STRING } from '@/constants' | ||
|
||
/** | ||
* String or not | ||
* | ||
* @typeParam T - any value | ||
*/ | ||
type IsString<T extends unknown> = T extends string ? true : false | ||
|
||
/** | ||
* Whatever argument is type of string or not. | ||
* | ||
* @param val - input any value | ||
* @returns The result of `typeof val === 'string'` | ||
* | ||
* @example | ||
* isString('hello world') // true | ||
* isString(1000) // false | ||
*/ | ||
const isString = <T extends unknown>(val: T): IsString<T> => | ||
(typeof val === STRING) as IsString<T> | ||
|
||
export { isString } | ||
export type { IsString } |
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,24 @@ | ||
import { SYMBOL } from '@/constants' | ||
|
||
/** | ||
* Symbol or not | ||
* | ||
* @typeParam T - any value | ||
*/ | ||
type IsSymbol<T extends unknown> = T extends symbol ? true : false | ||
|
||
/** | ||
* Whatever argument is type of symbol or not. | ||
* | ||
* @param val - input any value | ||
* @returns The result of `typeof val === 'symbol'` | ||
* | ||
* @example | ||
* isSymbol(Symbol('hello')) // true | ||
* isSymbol('hello') // false | ||
*/ | ||
const isSymbol = <T extends unknown>(val: T): IsSymbol<T> => | ||
(typeof val === SYMBOL) as IsSymbol<T> | ||
|
||
export { isSymbol } | ||
export type { IsSymbol } |
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,24 @@ | ||
import { UNDEFINED } from '@/constants' | ||
|
||
/** | ||
* Undefined or not | ||
* | ||
* @typeParam T - any value | ||
*/ | ||
type IsUndefined<T extends unknown> = T extends undefined ? true : false | ||
|
||
/** | ||
* Whatever argument is type of undefined or not. | ||
* | ||
* @param val - input any value | ||
* @returns The result of `typeof val === 'undefined'` | ||
* | ||
* @example | ||
* isUndefined(undefined) // true | ||
* isUndefined('hello') // false | ||
*/ | ||
const isUndefined = <T extends unknown>(val: T): IsUndefined<T> => | ||
(typeof val === UNDEFINED) as IsUndefined<T> | ||
|
||
export { isUndefined } | ||
export type { IsUndefined } |
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,7 @@ | ||
/* eslint-disable @typescript-eslint/no-explicit-any */ | ||
/** | ||
* Type of any function | ||
* | ||
* @typeParam T - argument types | ||
*/ | ||
export type AnyFn<T = any> = (...args: T[]) => unknown |
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 @@ | ||
export * from '@test/constants' |
Oops, something went wrong.