UNPKG

native-lodash

Version:
248 lines (219 loc) 7.87 kB
/** * @description 剪贴板 */ declare const clipboard: (text: string) => Promise<void>; type Numeric = number | string; type TObject = Record<PropertyKey, any>; /** * @description 深度克隆 * @param data 需要深度克隆的对象 * @return 克隆后的对象或者原始值 */ declare const cloneDeep: <T extends TObject | null | undefined>(data: T) => T; /** * 创建一个 debounced(防抖动)函数,该函数会从上一次被调用后,延迟 wait 毫秒后调用 fn 方法 * @param fn 需要防抖的函数 * @param ms 毫秒数 * @param immediate 是否立即执行 */ declare const debounce: (fn: (...args: any[]) => any, ms?: number, immediate?: boolean) => (this: unknown, ...args: any[]) => void; /** * @description 延迟 wait 毫秒后调用 fn。 调用时,任何附加的参数会传给 fn。 */ declare function delay(fn: (...args: any[]) => any, wait?: number, ...args: any[]): number; declare function later(delay?: number): Promise<unknown>; /** * @description 字符串脱敏(手机号,身份证,银行卡号、姓名等) * @param value 要脱敏的数据 * @param start 前几位不参与脱敏,默认 3 * @param end 后几位不参与脱敏,默认 4 */ declare function desensitize(value: Numeric, start?: number, end?: number, str?: string): Numeric; /** * @description: 根据地址下载文件(浏览器不支持打开的格式文件) * 如需下载图片请使用 downloadImage * @param href 下载链接 * @param title 文件名称 */ declare function download(href: string, title?: string): void; /** * @Description: 根据图片地址下载图片 * @param src 下载图片链接 * @param title 图片名称 */ declare function downloadImage(src: string, title?: string): void; /** * @description 使用 SameValueZero 比较两者的值,来确定它们是否相等。 * @param value 要比较的值 * @param other 另一个要比较的值 */ declare function eq(value: unknown, other: unknown): boolean; /** * Recursively flattens array. * * @example * * flattenDeep([1, [[2], [3, [4]], 5]]) * output: [1, 2, 3, 4, 5] */ declare const flattenDeep: <T>(array: T[]) => T[]; /** * @description 获取当前网页所在的运行环境 */ declare function getUa(): 'ios' | 'android' | 'wechat' | 'wxwork' | 'wxmini' | 'dingding' | 'feishu' | 'mobile' | undefined; /** * @description 获取 url 中所有参数,并转换为 json 对象 * @param url 指定url,默认 location.href */ declare function getUrlAllParams(url?: string): TObject; /** * @description 获取 url 中指定参数 * @param name 要获取的参数名 * @param url 指定url,默认 location.href */ declare function getUrlParams(name: string, url?: string): string | null; /** * @description 对象数组根据某个字段分类,常用于 index 索引列表 * @param array 必须是对象数组 * @param property 分类依据的字段 */ declare function groupBy(array: any[], property: string): any; /** * @description 全局唯一标识 * @param len uuid的长度 * @param firstLetter 将首位设置为某个字母,默认为 u * @param radix 生成 uuid 的基数(意味着返回的字符串都是这个基数),2-二进制,8-八进制,10-十进制,16-十六进制,默认62 */ declare function guid(len?: number, firstLetter?: string, radix?: number): string; /** * @description Checks if key is a direct property of object. Key may be a path of a value separated by . */ declare const has: (obj: TObject, key: string) => boolean; /** * @description 判断对象或数组是否相等。 * @param value 要比较的值 * @param other 另一个要比较的值 */ declare function isEqual(value: TObject, other: TObject): boolean; /** * @description 金额格式化 * @param number 要格式化的数字 * @param decimals 保留几位小数 */ declare function moneyFormat(number: Numeric, decimals?: number): string; /** * @description 返回一个对象,这个对象由忽略属性之外的自身和继承的可枚举属性组成。(注:可以理解为删除对象的属性)。 * @param obj 目标对象. * @param props 要被忽略的属性 * @example * * const object = { 'a': 1, 'b': '2', 'c': 3 }; * * omit(object, ['a', 'c']); * // => { 'b': '2' } * * omit(object, 'a'); * // => { 'b': '2', 'c': 3 } */ declare function omit(obj: TObject, props: string | string[]): TObject; type ArrayFormat = 'indices' | 'brackets' | 'repeat' | 'comma'; /** * @description 对象转 url 参数 * @param data 对象 * @param isPrefix 是否自动加上'?' * @param arrayFormat 规则 indices|brackets|repeat|comma */ declare function queryParams(data?: TObject, isPrefix?: boolean, arrayFormat?: ArrayFormat): string; /** * 各类校验方法 */ declare const isDef: <T>(val: T) => val is NonNullable<T>; /** * 验证电子邮箱格式 */ declare function isEmail(value: string): boolean; /** * 验证手机格式 */ declare function isMobile(value: Numeric): boolean; /** * 验证字符串 */ declare function isString(str: unknown): boolean; /** * 验证身份证号码 */ declare function isIdCard(value: string): boolean; /** * 是否车牌号 */ declare function isCarNo(value: string): boolean; /** * 判断是否为空 */ declare function isEmpty(val: any): boolean; /** * 是否数组 */ declare function isArray(value: unknown): boolean; /** * 是否对象 */ declare function isObject(value: unknown): boolean; /** * 是否短信验证码 */ declare function isCode(value: string, len?: number): boolean; /** * 是否函数方法 */ declare const isFunction: (fn: unknown) => fn is Function; /** * 是否是布尔 true 或者是字符 'true' */ declare const isTrue: (val: unknown) => val is true | "true"; /** * 是否是 URL */ declare const isURL: (url: string) => boolean; /** * 是否在浏览器中 */ declare const inBrowser: boolean; /** * @description 创建一个节流函数,在 wait 秒内最多执行 fn 一次的函数。 */ declare const throttle: (fn: (...args: any[]) => any, time?: number) => (this: unknown, ...args: any[]) => void; type TimeFormatItem = 'y' | 'm' | 'd' | 'h' | 'M' | 's'; /** * @description 格式化时间 * @param dateTime 需要格式化的时间 * @param format 格式化规则 yyyy:mm:dd|yyyy:mm|yyyy年mm月dd日|yyyy年mm月dd日 hh时MM分等,可自定义组合 默认yyyy-mm-dd */ declare function timeFormat(dateTime: Numeric, format?: string): string; /** * @description 时间戳转为多久之前 * @param timestamp 时间戳 * @param format 格式化规则,超出一定时间范围,返回固定的时间格式 */ declare function timeFrom(timestamp: Numeric, format?: string): string; /** * @description: 重写 toFixed。原因:比如 0.345.toFixed(2) = 0.34 而非 0.35; * @param num 数字 * @param digit 保留位数,默认 2 位 */ declare function toFixed(num: Numeric, digit?: number): string; type Pos = 'both' | 'left' | 'right' | 'all'; /** * @description 去除空格 * @param str 需要去除空格的字符串 * @param pos both (左右) | left | right | all; 默认 both */ declare function trim(str: string, pos?: Pos): string; /** * @description 调用数组的每个元素以产生唯一性 * @param arr 目标数组 * @param iteratee 迭代函数,调用每个元素 */ declare function uniqBy<T>(arr: T[], iteratee?: any): T[]; export { type Numeric, type Pos, type TObject, type TimeFormatItem, clipboard, cloneDeep, debounce, delay, desensitize, download, downloadImage, eq, flattenDeep, getUa, getUrlAllParams, getUrlParams, groupBy, guid, has, inBrowser, isArray, isCarNo, isCode, isDef, isEmail, isEmpty, isEqual, isFunction, isIdCard, isMobile, isObject, isString, isTrue, isURL, later, moneyFormat, omit, queryParams, throttle, timeFormat, timeFrom, toFixed, trim, uniqBy };