Skip to content

Commit

Permalink
perf: 优化工具函数
Browse files Browse the repository at this point in the history
  • Loading branch information
Tyh2001 committed Dec 14, 2023
1 parent fda5da9 commit 396c411
Showing 1 changed file with 5 additions and 16 deletions.
21 changes: 5 additions & 16 deletions packages/fighting-design/_utils/is/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,25 +3,20 @@ const { toString } = Object.prototype
/**
* 检测一个值是否为指定的类型
*
* @param { * } value 要检测的值
* @param { string } type 预期类型
* @returns { boolean } 这个值是否为传入的类型
*/
export const is = (value: unknown, type: string): boolean => {
return toString.call(value) === `[object ${type}]`
const is = (type: string): ((value: unknown) => void) => {
return (value: unknown): boolean => toString.call(value) === `[object ${type}]`
}

/**
* 检测一个数据是否为 date 类型
*
* @param { * } value 要检测的值
* @returns { boolean }
*/
export const isDate = (value: unknown): value is Date => is(value, 'Date')
export const isDate = is('Date')

/**
* 检测一个数据是否为 string 类型
*
* @param { * } value 要检测的值
* @returns { boolean }
*/
Expand All @@ -43,15 +38,12 @@ export const isNumber = (value: unknown): value is number =>
* @param { * } value 要检测的数据
* @returns { boolean }
*/
export const isBoolean = (value: unknown): value is boolean => is(value, 'Boolean')
export const isBoolean = (value: unknown): value is boolean => typeof value === 'boolean'

/**
* 判断一个值是否为 object 类型
*
* @param { * } value 要检测的值
* @returns { boolean }
*/
export const isObject = (value: unknown): value is object => is(value, 'Object')
export const isObject = is('Object')

/**
* 判断一个值是否为 function 类型
Expand All @@ -64,9 +56,6 @@ export const isFunction = (value: unknown): value is Function =>

/**
* 判断一个值是否为 array 类型
*
* @param { * } value 要检测的值
* @returns { boolean }
*/
export const isArray = Array.isArray

Expand Down

0 comments on commit 396c411

Please sign in to comment.