@ryanuo/utils
Version:
提供多种实用工具函数,涵盖算法、浏览器操作、网络请求等多个领域
144 lines (143 loc) • 3.72 kB
TypeScript
/**
* Checks if the value is a boolean
* @param value - The value to check
* @category is
* @example
* ```ts twoslash
* import { isBoolean } from '@ryanuo/utils'
* isBoolean(true) // true
* isBoolean(false) // true
* isBoolean(1) // false
* ```
* @returns Whether the value is a boolean
*/
export declare function isBoolean(value: unknown): value is boolean;
/**
* Checks if the value is a number
* @param value - The value to check
* @category is
* @example
* ```ts twoslash
* import { isNumber } from '@ryanuo/utils'
* isNumber(123) // true
* isNumber('123') // false
* ```
* @returns Whether the value is a number
*/
export declare function isNumber(value: unknown): value is number;
/**
* Checks if the value is a function
* @category is
* @example
* ```ts twoslash
* import { isFunction } from '@ryanuo/utils'
* isFunction(() => {}) // true
* isFunction(123) // false
* isFunction('123') // false
* ```
* @param val - The value to check
* @returns Whether the value is a function
*/
export declare const isFunction: <T extends Function>(val: any) => val is T;
/**
* Checks if the value is an string
* @category is
* @example
* ```ts twoslash
* import { isString } from '@ryanuo/utils'
* isString('123') // true
* isString(123) // false
* ```
* @param val - The value to check
* @returns Whether the value is an string
*/
export declare const isString: (val: unknown) => val is string;
/**
* Checks if the value is an object
* @category is
* @example
* ```ts twoslash
* import { isObject } from '@ryanuo/utils'
* isObject({}) // true
* isObject([]) // false
* ```
* @param val - The value to check
* @returns Whether the value is an object
*/
export declare const isObject: (val: any) => val is object;
/**
* Check if an object is empty.
* @category is
* @example
* ```ts twoslash
* import { isEmptyObject } from '@ryanuo/utils'
* isEmptyObject({}) // true
* isEmptyObject([]) // true
* isEmptyObject({ a: 1 }) // false
* ```
*/
export declare const isEmptyObject: (val: any) => val is object;
/**
* Checks if the value is an undefined
* @category is
* @example
* ```ts twoslash
* import { isUndefined } from '@ryanuo/utils'
* isUndefined(undefined) // true
* isUndefined(null) // false
* ```
* @param val - The value to check
* @returns Whether the value is an undefined
*/
export declare const isUndefined: (val: any) => val is undefined;
/**
* Checks if the value is an null
* @category is
* @example
* ```ts twoslash
* import { isNull } from '@ryanuo/utils'
* isNull(null) // true
* isNull(undefined) // false
* ```
* @param val - The value to check
* @returns Whether the value is an null
*/
export declare const isNull: (val: any) => val is null;
/**
* Checks if the value is an regexp
* @category is
* @example
* ```ts twoslash
* import { isRegExp } from '@ryanuo/utils'
* isRegExp(/test/) // true
* isRegExp('test') // false
* ```
* @param val - The value to check
* @returns Whether the value is an regexp
*/
export declare const isRegExp: (val: any) => val is RegExp;
/**
* Checks if the value is an date
* @category is
* @example
* ```ts twoslash
* import { isDate } from '@ryanuo/utils'
* isDate(new Date()) // true
* isDate('2023-01-01') // false
* isDate(123) // false
* ```
* @param val - The value to check
* @returns Whether the value is an date
*/
export declare const isDate: (val: any) => val is Date;
/**
* Checks if the current environment is a browser
* @category is
* @example
* ```ts twoslash
* import { isBrowser } from '@ryanuo/utils'
* isBrowser() // true
* ```
* @returns Whether the current environment is a browser
*/
export declare function isBrowser(): boolean;