@ryanuo/utils
Version:
提供多种实用工具函数,涵盖算法、浏览器操作、网络请求等多个领域
56 lines (55 loc) • 1.62 kB
TypeScript
/**
* to string type of value [Object.prototype.toString]
* @category type
* @example
* ```ts twoslash
* import { toString } from '@ryanuo/utils'
* toString({}) // '[object Object]'
* ```
* @param v - The value to check
* @returns The string representation of the value
*/
export declare const toString: (v: any) => string;
/**
* Get the type name of the value
* @category type
* @example
* ```ts twoslash
* import { getTypeName } from '@ryanuo/utils'
* getTypeName({}) // 'object'
* getTypeName([]) // 'array'
* getTypeName('') // 'string'
* getTypeName(1) // 'number'
* ```
* @param v - get type name
* @returns The type name of the value
*/
export declare function getTypeName(v: any): string;
/**
* Convert a number to a fixed value with specified decimal places.
* @category type
* @example
* ```ts twoslash
* import { numberToFixed } from '@ryanuo/utils'
* numberToFixed(1.23456) // 1.2346
* numberToFixed(1.23456, 2) // 1.23
* numberToFixed(1.23456, 3) // 1.235
* ```
* @param num The number to be converted.
* @param fixed The number of decimal places, defaults to 4.
* @returns The converted number with the specified number of decimal places.
*/
export declare function numberToFixed(num: number, fixed?: number): number;
/**
* 安全的深拷贝(处理循环引用)
* @category type
* @example
* ```ts twoslash
* import { deepClone } from '@ryanuo/utils'
* const obj = { a: 1, b: { c: 2 } }
* const cloneObj = deepClone(obj)
* console.log(cloneObj) // { a: 1, b: { c: 2 } }
* ```
* @param obj 源对象
*/
export declare function deepClone<T>(obj: T): T;