UNPKG

ucc-utils

Version:
1,501 lines (1,493 loc) 52.3 kB
interface ConvertRoutesToLevelOptions { fld?: string; glFld?: string; childFld?: string; isJudgeType?: boolean; isChangeOwner?: boolean; } /** * window对象 - 兼容 * @author Yuluo * @link https://github.com/YuluoY * @date 2024-08-24 * @constant {Window | null} root * @description 获取window对象,兼容浏览器、node、webworker等环境 */ declare const root: Window | null; /** * 去掉字符串中的空格 * @author Yuluo * @link https://github.com/YuluoY * @date 2024-09-28 * @param {string} str 字符串 * @returns {string} 去掉空格后的字符串 * @example * ```ts * const str = ' 123 456 789 '; * trimSpace(str); // '123456789' * ``` */ declare const trimSpace: (str: string) => string; /** * 去掉字符串中的换行符 * @author Yuluo * @link https://github.com/YuluoY * @date 2024-09-28 * @param {string} str 字符串 * @returns {string} 去掉换行符后的字符串 * @example * ```ts * const str = '123\n456\n789'; * trimNL(str); // '123456789' * ``` */ declare const trimNL: (str: string) => string; /** * 去掉字符串中的回车符 * @author Yuluo * @link https://github.com/YuluoY * @date 2024-09-28 * @param {string} str 字符串 * @returns {string} 去掉回车符后的字符串 * @example * ```ts * const str = '123\r456\r789'; * trimCR(str); // '123456789' * ``` */ declare const trimCR: (str: string) => string; /** * 去掉字符串中的制表符 * @author Yuluo * @link https://github.com/YuluoY * @date 2024-09-28 * @param {string} str 字符串 * @returns {string} 去掉制表符后的字符串 * @example * ```ts * const str = '123\t456\t789'; * trimTabForString(str); // '123456789' * ``` */ declare const trimTab: (str: string) => string; /** * 去掉字符串中的空格、换行符、回车符、制表符 * @author Yuluo * @link https://github.com/YuluoY * @date 2024-09-28 * @param {string} str 字符串 * @returns {string} 去掉空格、换行符、回车符、制表符后的字符串 * @example * ```ts * const str = ' 123 \n 456 \r 789 \t '; * trimWhitespace(str); // '123456789' * ``` */ declare const trimWhitespace: (str: string) => string; /** * 给字符串中对象属性名加双引号 * @author Yuluo * @link https://github.com/YuluoY * @date 2024-09-28 * @param {string} str 字符串 * @returns {string} 给字符串中对象属性名加双引号后的字符串 * @example * ```ts * const str = 'a:1,b:2,c:3'; * const result = str.replace(addQuotesToProps, '"$1":$2'); * console.log(result); // '"a":1,"b":2,"c":3' * * const str2 = '{a:1,b:2,c:3}'; * const result2 = str2.replace(addQuotesToProps, '"$1":$2'); * console.log(result2); // '{"a":1,"b":2,"c":3}' * ``` */ declare const addQuotesToProps: (str: string) => string; /** * 扁平路由表转换有层级的路由表 * @author Yuluo * @link https://github.com/YuluoY * @date 2024-08-29 * @param {T} routes 需要转换的路由表 * @param {ConvertRoutesToLevelOptions} opts 配置项 * @param {string} [opts.fld= 'id'] 路由表中的id字段名,默认为id * @param {string} [opts.glFld= 'parentId'] 路由表中的父级id字段名,默认为parentId * @param {string} [opts.childFld= 'children'] 路由表中的子级字段名,默认为children * @param {boolean} [opts.isJudgeType= true] 是否判断类型,默认为true * @param {boolean} [opts.isChangeOwner= true] 是否改变原数组,默认为true * @returns {T} 返回转换后的路由表 * @example * ```ts * const routes = [ * { id: 1, pid: 0, name: 'home' }, * { id: 2, pid: 1, name: 'home1' }, * { id: 3, pid: 1, name: 'home2' }, * { id: 4, pid: 2, name: 'home3' }, * ] * const result = convertRoutesToLevel(routes, { fld: 'id', glFld: 'pid', childFld: 'children' }) * // [ * { * id: 1, * pid: 0, * name: 'home', * children: [ * { * id: 2, * pid: 1, * name: 'home1', * children: [ * { id: 4, pid: 2, name: 'home3' } * ] * }, * { id: 3, pid: 1, name: 'home2' } * ] * } * ] * ``` */ declare const convertRoutesToLevel: <T = any>(routes: T[], opts?: ConvertRoutesToLevelOptions) => T[]; /** * 根据属性对数组分组 * @author Yuluo * @link https://github.com/YuluoY * @date 2024-08-24 * @template {T} * @param {T[]} array 需要分组的数组 * @param {string} prop 对某个属性的值进行分组 * @returns {{[key:string]: T[]}} 根据prop值分组后的对象数组 * @example * ```js * const array = [ * { name: 'hello world', age: 18 }, * { name: 'hello world', age: 20} * ] * groupByProp(array, 'name') * // { 'hello world': [ { name: 'hello world', age: 18 }, { name: 'hello world', age: 20 } ] } * ``` */ declare const groupByProp: <T = any>(array: T[], prop: string) => Record<string, T[]> | T[]; /** * 解析 JSON 字符串 * @author Yuluo * @link https://github.com/YuluoY * @date 2024-08-24 * @param {string} str JSON 字符串 * @param {any} [defVal={}] 默认返回值 * @returns {any} * @example * ```js * parseJSON('{"name": "hello world"}') // {name: 'hello world'} * ``` */ declare const parseJSON: <T = any>(str: string, defVal?: T) => T; /** * 英文单词首字母大写 * @author Yuluo * @link https://github.com/YuluoY * @date 2024-08-24 * @param {string} str 英文字符串 * @returns {string} * @example * ```js * capitalizeForWord('hello world') // Hello World * ``` */ declare const capitalizeForWord: (str: string) => string; /** * 获取类型 * @author Yuluo * @link https://github.com/YuluoY * @date 2024-08-24 * @param {any} val 需要获取类型的值 * @return {string} * @example * ```js * getType(1) // number * getType('1') // string * getType([]) // array * getType({}) // object * ``` */ declare const getType: (val: any) => string; /** * 将 CSS 渐变(线性或径向)转换为 ECharts 的渐变配置 * @author Yuluo * @link https://github.com/YuluoY * @date 2024-09-14 * @param {string} cssGradient - CSS 渐变字符串 (linear-gradient 或 radial-gradient) * @returns {Object} - ECharts 兼容的渐变配置 (linearGradient 或 radialGradient) * @example * ```js * cssGradientToECharts('linear-gradient(45deg, rgba(255, 0, 0, 1) 0%, rgba(0, 255, 0, 1) 100%)'); * * // 输出: * { * type: 'linear', * x: 0.7071067811865476, * y: 0.7071067811865475, * x2: 1, * y2: 0, * colorStops: * [ * { offset: 0, color: 'rgba(255, 0, 0, 1)' }, * { offset: 1, color: 'rgba(0, 255, 0, 1)' } * ], * global: false, * value: 'linear-gradient(45deg, rgba(255, 0, 0, 1) 0%, rgba(0, 255, 0, 1) 100%)' * } * ``` */ declare function cssGradientToECharts(cssGradient: string): { type: 'linear' | 'radial'; x: number; y: number; x2?: number; y2?: number; r?: number; colorStops: { offset: number; color: string; }[]; global: boolean; value: string; } | string; /** * 设置对象属性值(支持深度路径) * @deprecated 已废弃,建议使用 _.set * @author Yuluo * @link https://github.com/YuluoY * @date 2024-09-14 * @param {Record<string, any>} obj - 目标对象 * @param {string | string[]} path - 属性路径,支持点分隔的字符串或数组 * @param {any} val - 要设置的值 * @param {string} [splitter='.'] - 分隔符,默认为 '.' * @returns {[Record<string, any>, string]} - 修改后的对象和最后一个属性的 key * @memberof core.setValue * @example * ```ts * const obj = { a: { b: { c: 1 } } } * setValue(obj, 'a.b.c', 2) // obj = { a: { b: { c: 2 } } } * ``` */ declare function setValue<T = any>(obj: Record<string, any>, path: string | string[], val: any, splitter?: string): [Record<string, T>, string]; /** * 获取对象属性值(支持深度路径) * @deprecated 已废弃,建议使用 _.get * @author Yuluo * @link https://github.com/YuluoY * @date 2024-09-14 * @param {Record<string, any>} obj - 目标对象 * @param {string | string[]} path - 属性路径,支持点分隔的字符串或数组 * @param {string} [splitter='.'] - 分隔符,默认为 '.' * @returns {any} * @memberof core.getValue * @example * ```ts * const obj = { a: { b: { c: 1 } } } * getValue<number>(obj, 'a.b.c') // 1 * * const obj2 = { a: { b: { c: 1 } } } * getValue(obj, 'a.b.c.d') // undefined * ``` */ declare function getValue<T = any>(obj: Record<string, any>, path: string | string[], splitter?: string): T; /** * watch 监听一个函数返回为 true 的时机,并执行回调 - 有执行间隔和次数限制 * @author Yuluo * @link https://github.com/YuluoY * @date 2024-09-14 * @param {(() => Promise<boolean>) | (() => boolean)} fn - 监听的函数 * @param {(() => Promise<void>) | (() => void)} callback - 回调函数 * @param {object} [options] - 配置项 * @param {number} [options.delay] - 执行间隔,单位毫秒,默认 100 * @param {number} [options.limit] - 执行次数限制,默认 1 * @param {number} [options.timeout] - 超时时间,单位毫秒,默认 0,表示不限制 * @param {() => void} [options.timeoutFn] - 超时回调函数 * @returns {() => void} - 取消监听的函数 * @example * ```ts * const cancel = watchFn(() => isReady(), () => { * console.log('isReady') * }, { delay: 100, limit: 1, timeout: 5000, timeoutFn: () => {} }) * // 取消监听 * cancel() * ``` */ declare function watchFn(fn: (() => boolean) | (() => Promise<boolean>), callback: (() => void) | (() => Promise<void>), options?: Partial<{ delay: number; limit: number; timeout: number; timeoutFn: () => void; }>): () => void; /** * 立即执行函数 * @author Yuluo * @link https://github.com/YuluoY * @date 2024-09-24 * @param {() => void} fn - 需要执行的函数 * @returns {any} - 返回值 * @example * ```ts * const result = runFn(() => 'hello', null) // hello * ``` */ declare const runFn: <T = any>(fn: () => T, ctx: any) => T; /** * 将字符串对象解析为带类型的对象 * @author Yuluo * @link https://github.com/YuluoY * @date 2024-09-28 * @param {string} str - 字符串值 * @returns {any} - 带类型的值 * @example * ```ts * const str = "{a: 10, b: function() {}, c: 'jhahah', d: null, e: undefined, f: [1,2,3,4]}" * const obj = parseStrWithType(str3); * * console.log(obj); * // {a: 10, b: function() {}, c: 'jhahah', d: null, e: undefined, f: [1, 2, 3, 4]} * ``` */ declare const parseStrWithType: <T = any>(str: string) => T | string; /** * 字符串值还原类型值 * @author Yuluo * @link https://github.com/YuluoY * @date 2024-09-24 * @param {string} str - 字符串 * @returns {any} - 还原后的值 * @example * ```ts * restoreValue('undefined') // undefined * restoreValue('null') // null * restoreValue('true') // true * restoreValue('false') // false * restoreValue('NaN') // NaN * restoreValue('Infinity') // Infinity * restoreValue('-Infinity') // -Infinity * restoreValue<string>('123') // 123 * restoreValue<{a: number}>('{"a":1}') // {a: 1} * restoreValue<{a: number[]}>('{a:[1,2,3]}') // {a: [1,2,3]} * restoreValue<number[]>('[1,2,3]') // [1,2,3] * ``` */ declare function restoreValue<T = any>(str: string): T; /** * 将字符串 ==> 对象,并解析其中的函数和符号 * @author Yuluo * @link https://github.com/YuluoY * @date 2024-10-15 * @param {string} str - 字符串 * @returns {object} * @example * ```ts * const str = '{"a":10,"b":"function() {}","c":"symbol()","d":"undefined"}' * const obj = parseStringify(str); * console.log(obj); * // {a: 10, b: function() {}, c: Symbol(), d: undefined} * ``` */ declare function parseStringify<T = any>(str: string): T; /** * 将对象 ==> 字符串,并解析其中的函数和符号 * @author Yuluo * @link https://github.com/YuluoY * @date 2024-10-15 * @param {object} obj - 对象 * @returns {string} * @example * ```ts * const obj = {a: 10, b: function() {}, c: Symbol(), d: undefined} * const str = toStringify(obj); * console.log(str); * // '{"a":10,"b":"function() {}","c":"symbol()","d":"undefined"}' * ``` */ declare function toStringify<T = any>(obj: T): string; /** * 将小驼峰命名的字符串展开 * @author Yuluo * @link https://github.com/YuluoY * @date 2024-10-15 * @param {string} str - 字符串 * @param {string} [sep=' '] - 分隔符 * @returns {string} * @example * ```ts * const str = 'helloWorld'; * const result = expandCamelCase(str); // 'hello world' * * const str2 = 'helloWorld expandCamelCase' * const result2 = expandCamelCase(str2); // 'hello world expand camel case' * * const str3 = 'helloWorldExpandCamelCase'; * const result3 = expandCamelCase(str3, '-'); // 'hello-world-expand-camel-case' * ``` */ declare function expandCamelCase(str: string, sep?: string): string; /** * 将下划线命名的字符串转换成小驼峰命名 * @deprecated 已废弃,建议使用 _.camelCase * @author Yuluo * @link https://github.com/YuluoY * @date 2024-10-15 * @param {string} str - 字符串 * @returns {string} * @memberof core.underlineToCamelCase * @example * ```ts * const str = 'hello_world'; * const result = underlineToCamelCase(str); // 'helloWorld' * * const str2 = 'hello_World_underline_to_camel_case'; * const result2 = underlineToCamelCase(str2); // 'helloWorldUnderlineToCamelCase' * ``` */ declare const underlineToCamelCase: (str: string) => string; /** * 保留指定小数位数 * @author Yuluo * @link https://github.com/YuluoY * @date 2024-10-17 * @param {number} num - 数字 * @param {number} [digits=2] - 保留的小数位数 * @returns {number} * @example * ```ts * const num = 10.123456; * const result = toFixed(num); // 10.12 * * const num2 = 10.123456; * const result2 = toFixed(num2, 4); // 10.1234 * ``` */ declare const toFixed: (num: number, digits?: number) => number; /** * 占位写入模板字符串 * @author Yuluo * @link https://github.com/YuluoY * @date 2024-10-18 * @param {string} template - 模板字符串 * @param {Record<string, any> | any[]} data - 数据 * @returns {string} * @example * ```ts * const template = 'Hello, {name}!'; * const data = { name: 'Yuluo' }; * const result = fillTemplate(template, data); // 'Hello, Yuluo!' * * const template2 = 'Hello, {name}! You have {count} new messages.'; * const data2 = { name: 'Yuluo', count: 5 }; * const result2 = fillTemplate(template2, data2); // 'Hello, Yuluo! You have 5 new messages.' * * const template3 = 'Hello, {0}! You have {1} new messages.'; * const data3 = ['Yuluo', 5]; * const result3 = fillTemplate(template3, data3); // 'Hello, Yuluo! You have 5 new messages.' * * const template4 = 'Hello, {name}! You have {1} new messages.'; * const data4 = { name: 'Yuluo', count: 5 }; * const result4 = fillTemplate(template4, data4); // 'Hello, Yuluo! You have 5 new messages.' * ``` */ declare const fillTemplate: (template: string, data: Record<string, any> | any[]) => string; /** * px与rem转换 * @author Yuluo * @link https://github.com/YuluoY * @date 2024-03-03 * @param {number} px - px值 * @param {object} opts - 配置项 * @param {boolean} [opts.isReverse=false] - 是否反转 * @param {string} [opts.unit] - 单位,如果存在,则返回字符串 * @param {number} [opts.rootFontSize] - 根字体大小 * @returns {number | string} * @example * ```ts * const px = 100 * const rem = pxToRem(px) // 100 * * const rem = 10 * const px = pxToRem(rem, { isReverse: true }) // 100 * * const px2 = pxToRem(rem, { isReverse: true, rootFontSize: 16 }) // 100 * const rem2 = pxToRem(px2) // 10 * ``` */ declare function pxToRem<T = string | number>(val: number, opts?: Partial<{ isReverse: boolean; isNumber: boolean; rootFontSize: number; }>): T; /** * 添加自定义分隔符 * @author Yuluo * @link https://github.com/YuluoY * @date 2024-03-04 * @param {string} str - 字符串 * @param {number} count - 分隔符数量 * @param {string} [separator='\n'] - 分隔符 * @returns {string} * @example * ```ts * const str = '1234567890' * const result = addCustomSeparator(str, 3) // '123\n456\n789\n0' * * const str2 = '1234567890' * const result2 = addCustomSeparator(str2, 3, '-') // '123-456-789-0' * ``` */ declare const addCustomSeparator: (str: string, count: number, separator?: string) => string; type StepResult<T> = T | Error; type StepHandler<Prev, Out> = (input: Prev, done: (result: Out | Error) => void) => void | Promise<void>; type StepOutputs<T extends readonly StepHandler<any, any>[]> = { [K in keyof T]: T[K] extends StepHandler<infer _, infer Out> ? StepResult<Out> : never; }; interface ChainOptions { timeout?: number; isComplete?: boolean; } /** * * 链式执行多个步骤函数,每个步骤函数接收上一步结果和 done 回调,通过调用 done 传递结果或错误 * @author Yuluo * @link https://github.com/YuluoY * @date 2025-06-08 * @template T 步骤函数数组类型 * @param {T} steps 步骤函数数组 * @param {ChainOptions} [opts] 执行选项 * @returns {StepOutputs<T>} 包含每个步骤结果的数组 * * @example * // 1. 基本使用 * const res = chain([ * (_, done) => done('123'), * (val: string, done) => { * console.log(val) // '123' * done(val.length) * } * ]) * console.log(res) // ['123', 3] * * // 2. 提前结束 * const res = chain([ * (_, done) => done(new Error('error')), * (val, done) => done(val * 2) // 不会执行 * ], { isComplete: false }) * console.log(res) // [Error: error] * * // 3. 超时设置 * const res = chain([ * (_, done) => setTimeout(() => done('data'), 2000), * (val: string, done) => done(val.toUpperCase()) * ], { timeout: 1000 }) * console.log(res) // [Error: chain: step 0 timeout, undefined] */ declare const chain: <T extends readonly StepHandler<any, any>[]>(steps: T, opts?: ChainOptions) => StepOutputs<T>; /** * 均为类型判断函数 */ /** * 判断是否是 CommonJS 模块环境 * @author Yuluo * @link https://github.com/YuluoY * @date 2024-10-15 * @return {boolean} 如果是 CommonJS 模块环境则返回 true,否则返回 false */ declare const isCJS: () => boolean; /** * 判断是否是 ECMAScript 模块环境 * @author Yuluo * @link https://github.com/YuluoY * @date 2024-10-15 * @return {boolean} 如果是 ECMAScript 模块环境则返回 true,否则返回 false */ declare const isESM: () => boolean; /** * 是否是基本类型 * @author Yuluo * @link https://github.com/YuluoY * @date 2024-08-24 * @param {any} val 需要判断的值 * @return {boolean} * @example * ```ts * isPrimitive(1) // true * isPrimitive('1') // true * isPrimitive(true) // true * isPrimitive(null) // true * isPrimitive(undefined) // true * isPrimitive({}) // false * isPrimitive([]) // false * isPrimitive(() => {}) // false * ``` */ declare const isPrimitive: (val: any) => val is boolean; /** * 是否有分量的值 * @author Yuluo * @link https://github.com/YuluoY * @date 2024-09-14 * @param {any} val 需要判断的值 * @return {boolean} * @example * ```ts * hasWeightValue(1) // true * hasWeightValue(0) // false * hasWeightValue('1') // true * hasWeightValue('') // false * hasWeightValue(true) // true * hasWeightValue(false) // false * hasWeightValue(null) // false * hasWeightValue(undefined) // false * hasWeightValue({}) // false * hasWeightValue([]) // false * ``` */ declare const hasWeightValue: (val: any) => val is boolean; /** * 是否为null * @author Yuluo * @link https://github.com/YuluoY * @date 2024-09-14 * @param {any} val 需要判断的值 * @return {boolean} * @example * ```ts * isNull(null) // true * isNull(undefined) // false * ``` */ declare const isNull: (val: any) => val is boolean; /** * 是否为undefined or null * @author Yuluo * @link https://github.com/YuluoY * @date 2024-09-28 * @param {any} val 需要判断的值 * @return {boolean} * @example * ```ts * isNullish(undefined) // true * isNullish(null) // true * isNullish(1) // false * ``` */ declare const isNullish: (val: any) => val is boolean; /** * 是否为undefined * @author Yuluo * @link https://github.com/YuluoY * @date 2024-09-14 * @param {any} val 需要判断的值 * @return {boolean} * @example * ```ts * isUndefined(undefined) // true * isUndefined(null) // false * ``` */ declare const isUndefined: (val: any) => val is boolean; /** * 是否是symbol * @author Yuluo * @link https://github.com/YuluoY * @date 2024-09-14 * @param {any} val 需要判断的值 * @return {boolean} * @example * ```ts * isSymbol(Symbol()) // true * isSymbol('1') // false * ``` */ declare const isSymbol: (val: any) => val is boolean; /** * 是否是函数 * @author Yuluo * @link https://github.com/YuluoY * @date 2024-08-24 * @param {any} val 需要判断的值 * @return {boolean} * @example * ```ts * isFunction(() => {}) // true * isFunction(1) // false * isFunction('1') // false * ``` */ declare const isFunction: (val: any) => val is boolean; /** * 是否是对象 * @author Yuluo * @link https://github.com/YuluoY * @date 2024-08-24 * @param {any} val 需要判断的值 * @return {boolean} * @example * ```ts * isObject({}) // true * isObject([]) // true * isObject(1) // false * ``` */ declare const isObject: (val: any) => val is boolean; /** * 是否是普通对象 * @author Yuluo * @link https://github.com/YuluoY * @date 2024-09-14 * @param {any} val 需要判断的值 * @return {boolean} * @example * ```ts * isPlainObject({}) // true * isPlainObject([]) // false * isPlainObject(1) // false * ``` */ declare const isPlainObject: (val: any) => val is boolean; /** * 是否是空对象 * @author Yuluo * @link https://github.com/YuluoY * @date 2024-08-24 * @param {any} val 需要判断的值 * @return {boolean} * @example * ```ts * isEmptyObject({}) // true * isEmptyObject({a: 1}) // false * isEmptyObject([]) // true * ``` */ declare const isEmptyObject: (val: any) => val is boolean; /** * 是否是普通空对象 * @author Yuluo * @link https://github.com/YuluoY * @date 2024-09-14 * @param {any} val 需要判断的值 * @return {boolean} * @example * ```ts * isEmptyPlainObject({}) // true * isEmptyPlainObject({a: 1}) // false * isEmptyPlainObject([]) // false * ``` */ declare const isEmptyPlainObject: (val: any) => val is boolean; /** * 是否是字符串 * @author Yuluo * @link https://github.com/YuluoY * @date 2024-08-24 * @param {any} val 需要判断的值 * @return {boolean} * @example * ```ts * isString('1') // true * isString(1) // false * isString(true) // false * ``` */ declare const isString: (val: any) => val is boolean; /** * 是否是数组 * @author Yuluo * @link https://github.com/YuluoY * @date 2024-08-24 * @param {any} val 需要判断的值 * @return {boolean} * @example * ```ts * isArray([1, 2, 3]) // true * isArray('1,2,3') // false * ``` */ declare const isArray: (val: any) => val is boolean; /** * 是否是空数组 * @author Yuluo * @link https://github.com/YuluoY * @date 2024-08-24 * @param {any} val 需要判断的值 * @return {boolean} * @example * ```ts * isEmptyArray([1, 2, 3]) // false * isEmptyArray([]) // true * ``` */ declare const isEmptyArray: (val: any) => val is boolean; /** * 是否是浮点小数 * @author Yuluo * @link https://github.com/YuluoY * @date 2024-08-24 * @param {any} val 需要判断的值 * @return {boolean} * @example * ```ts * isFloat(1) // false * isFloat(1.1) // true * isFloat('1.1') // false * ``` */ declare const isFloat: (val: any) => val is boolean; /** * 是否是数字 * @author Yuluo * @link https://github.com/YuluoY * @date 2024-08-24 * @param {any} val 需要判断的值 * @return {boolean} * @example * ```ts * isNumber(1) // true * isNumber(1.1) // true * isNumber('1') // false * isNumber('1.1') // false * ``` */ declare const isNumber: (val: any) => val is boolean; /** * 是否是整形数字 * @author Yuluo * @link https://github.com/YuluoY * @date 2024-08-24 * @param {any} val 需要判断的值 * @return {boolean} * @example * ```ts * isInteger(1) // true * isInteger(1.1) // false * ``` */ declare const isInteger: (val: any) => val is boolean; /** * 判断是否是JSON string * @author Yuluo * @link https://github.com/YuluoY * @date 2024-09-14 * @param {any} str - 要检查的值 * @returns {boolean} - 如果是JSON string返回 true,否则返回 false * @example * ```ts * isJSONString('{"name": "John", "age": 30}') // true * isJSONString('{"name": "John", "age": 30,}') // false * ``` */ declare const isJSONString: (str: any) => str is boolean; /** * 判断是否是字符串数字 * @author Yuluo * @link https://github.com/YuluoY * @date 2024-09-24 * @param {any} str - 要检查的值 * @returns {boolean} - 如果是字符串数字返回 true,否则返回 false * @example * ```ts * isStringNumber('123') // true * isStringNumber('123.45') // true * isStringNumber('abc') // false * ``` */ declare const isStringNumber: (str: any) => str is boolean; /** * 判断是否是字符串布尔值 * @author Yuluo * @link https://github.com/YuluoY * @date 2024-09-28 * @param {any} str - 要检查的值 * @returns {boolean} - 如果是字符串布尔值返回 true,否则返回 false * @example * ```ts * isStringBoolean('true') // true * isStringBoolean('false') // true * isStringBoolean('abc') // false * ``` */ declare const isStringBoolean: (str: any) => str is boolean; /** * 判断是否是字符串数组 * @author Yuluo * @link https://github.com/YuluoY * @date 2024-09-28 * @param {any} str - 要检查的值 * @returns {boolean} - 如果是字符串数组返回 true,否则返回 false * @example * ```ts * isStringArray('[1, 2, 3]') // true * isStringArray('[]') // true * isStringArray('123') // false * ``` */ declare const isStringArray: (str: any) => str is boolean; /** * 判断是否是字符串对象 * @author Yuluo * @link https://github.com/YuluoY * @date 2024-09-28 * @param {any} str - 要检查的值 * @returns {boolean} - 如果是字符串对象返回 true,否则返回 false * @example * ```ts * isStringObject('{"name": "John", "age": 30}') // true * isStringObject('{"name": "John", "age": 30,}') // true * isStringObject('{name: "John", age: 30}') // true * ``` */ declare const isStringObject: (str: any) => str is boolean; /** * 判断是否是字符串函数 * @author Yuluo * @link https://github.com/YuluoY * @date 2024-09-28 * @param {any} str - 要检查的值 * @returns {boolean} - 如果是字符串函数返回 true,否则返回 false * @example * ```ts * isStringFunction('function(){}') // true * isStringFunction('()=>{}') // true * isStringFunction('_=>{}') // true * ``` */ declare const isStringFunction: (str: any) => str is boolean; /** * 判断当前系统是否是 Windows 系统 * @author Yuluo * @link https://github.com/YuluoY * @date 2024-09-14 * @param {Navigator} - 可选参数,用于指定要检查的 navigator 对象 * @return {boolean} * @example * ```ts * isWindows() // true or false * ``` */ declare const isWindows: (navigator?: Navigator) => boolean; /** * 判断当前系统是否是 macOS 系统 * @author Yuluo * @link https://github.com/YuluoY * @date 2024-09-14 * @param {Navigator} - 可选参数,用于指定要检查的 navigator 对象 * @return {boolean} * @example * ```ts * isMacOS() // true or false * ``` */ declare const isMacOS: (navigator?: Navigator) => boolean; /** * 判断是否是移动端 * @author Yuluo * @link https://github.com/YuluoY * @date 2024-09-14 * @param {Navigator} - 可选参数,用于指定要检查的 navigator 对象 * @return {boolean} * @example * ```ts * isMobile() // true or false * ``` */ declare const isMobile: (navigator?: Navigator) => boolean; /** * 判断是否是PC端 * @author Yuluo * @link https://github.com/YuluoY * @date 2024-09-14 * @param {Navigator} - 可选参数,用于指定要检查的 navigator 对象 * @return {boolean} * @example * ```ts * isPC() // true or false * ``` */ declare const isPC: (navigator?: Navigator) => boolean; /** * 判断是否是URL * @author Yuluo * @link https://github.com/YuluoY * @date 2024-09-14 * @param {string} url - 要检查的URL * @return {boolean} * @example * ```ts * isURL('https://www.baidu.com') // true * isURL('www.baidu.com') // true * isURL('baidu.com') // true * ``` */ declare const isURL: (url: string) => boolean; /** * 判断是否是Email * @author Yuluo * @link https://github.com/YuluoY * @date 2024-09-14 * @param {string} email - 要检查的Email * @return {boolean} * @example * ```ts * isEmail('123456789@qq.com') // true * ``` */ declare const isEmail: (email: string) => boolean; /** * 判断是否是移动手机号 - 有严格与宽松两种模式 * @author Yuluo * @link https://github.com/YuluoY * @date 2024-09-14 * @param {string} phone - 要检查的手机号 * @param {boolean} strict - 是否严格模式,默认为 false * @return {boolean} * @example * ```ts * isPhone('12345678901') // true * isPhone('12345678901', true) // false * ``` */ declare const isPhone: (phone: string, strict?: boolean) => boolean; /** * 判断是否是QQ号 * @author Yuluo * @link https://github.com/YuluoY * @date 2024-09-14 * @param {string} qq - 要检查的QQ号 * @return {boolean} * @example * ```ts * isQQ('123456789') // true * ``` */ declare const isQQ: (qq: string) => boolean; /** * 是否是Promise * @param {any} obj - 要检查的对象 * @return {boolean} * @example * ```ts * isPromise(Promise.resolve()) // true * ``` */ declare const isPromise: (obj: any) => boolean; /** * 是否是AsyncComponent的异步组件 * @author Yuluo * @link https://github.com/YuluoY * @date 2024-09-28 * @param {any} obj - 要检查的对象 * @return {boolean} * @example * ```ts * isAsyncComponent(defineAsyncComponent(() => import('../index')) ) // true * isAsyncComponent(import('../index')) // false * isAsyncComponent(() => import('../index')) // false * ``` */ declare const isAsyncComponent: (obj: any) => boolean; /** * 是否是Vue组件 * @author Yuluo * @link https://github.com/YuluoY * @date 2024-10-15 * @param {any} obj - 要检查的对象 * @return {boolean} * @example * ```ts * isVueComponent({ render: () => {} }) // true * isVueComponent({ setup: () => {} }) // true * isVueComponent({}) // false * ``` */ declare const isVueComponent: (obj: any) => boolean; /** * 判断是否是值 * @author Yuluo * @link https://github.com/YuluoY * @date 2024-10-15 * @param {any} val - 要检查的对象 * @return {boolean} * @example * ```ts * isValue(123) // true * isValue('123') // true * isValue(true) // true * isValue(null) // false * isValue(undefined) // false * isValue(NaN) // false * ``` */ declare const isValue: (val: any) => boolean; /** * 是否是有效数组 * @author Yuluo * @link https://github.com/YuluoY * @param {any} arr - 要检查的对象 * @return {boolean} * @example * ```ts * isValidArray([1, 2, 3]) // true * isValidArray([]) // false * isValidArray(null) // false * isValidArray(undefined) // false * isValidArray(NaN) // false * isValidArray('123') // false * ``` */ declare const isValidArray: (arr: any) => boolean; /** * 是否是有效对象 * @author Yuluo * @link https://github.com/YuluoY * @date 2024-10-15 * @param {any} obj - 要检查的对象 * @return {boolean} * @example * ```ts * isValidPlainObject({ a: 1, b: 2 }) // true * isValidPlainObject({}) // false * isValidPlainObject(null) // false * isValidPlainObject(undefined) // false * isValidPlainObject(NaN) // false * isValidPlainObject('123') // false * ``` */ declare const isValidPlainObject: (obj: any) => boolean; /** * 性能优化函数 */ /** * 浏览器空闲时间执行 * @author Yuluo * @link https://github.com/YuluoY * @date 2024-08-24 * @param {Function} fn 回调函数 * @returns {number} * @example * ```js * idleCallback(() => console.log('hello world')) * ``` */ declare const idleCallback: (fn: Function) => number; /** * 在浏览器空闲时执行任务队列 - 可以传递一个WeakMap,将会收取所有id和任务 * @author Yuluo * @link https://github.com/YuluoY * @date 2024-08-24 * @param {Function[] | Function} task 任务队列 * @param {WeakMap<Function, number>} idleMap 已请求的空闲回调ID * @returns {void} * @example * ```js * const idleMap = new WeakMap() * idleTaskQueue([() => console.log('hello'), () => console.log('world')], idleMap) * ``` */ declare const idleTaskQueue: (task: Function[] | Function, idleMap?: WeakMap<Function, number>) => void; /** * 并发队列控制 - 保证并发数量始终是limit个 * @author Yuluo * @link https://github.com/YuluoY * @date 2024-10-18 * @param {Function[] | Promise[]} tasks 任务队列 * @param {object} opts 配置项 * @param {number} [opts.limit=3] 最大并发数量,默认为3 * @returns {Promise<void>} * @example * ```ts * const tasks = [() => console.log('hello'), () => console.log('world')] * await toConcurrency(tasks) // hello world * * const tasks = [Promise.resolve('hello'), Promise.resolve('world')] * await toConcurrency(tasks) // hello world * ``` */ declare const concurRequest: <T = any>(tasks: Function[] | Promise<any>[], opts?: { limit?: number; }) => Promise<{ success: boolean; value: T | any; }[]>; /** * 异常处理函数 * @author Yuluo * @link https://github.com/YuluoY * @date 2024-08-29 * @template {T} * @param {Function} fn 函数 * @param {Object} opts * @param {Array} [opts.fnArgs=[]] 函数参数,默认为[ ] * @param {Boolean} [opts.isToThrow=false] 是否抛出异常,默认为false * @param {Function} [opts.onErrorFn=null] 异常处理函数,默认为null * @returns {Promise<[any, T]>} * @example * ```js * const getDataBind = getData.bind(this, '123') * const [err, data] = await tryit(getDataBind, { onErrorFn: console.log }) * ``` */ declare const tryit: <T = any>(fn: Function, opts: { isToThrow?: boolean; fnArgs?: any[]; onErrorFn?: (e: any) => void | null; }) => Promise<[any, T]>; /** * 正则:去掉字符串中的空格 * @author Yuluo * @link https://github.com/YuluoY * @date 2024-09-28 * @constant * @example * ```ts * const str = ' 123 456 789 '; * const result = str.replace(TrimSpaceRegExp, ''); * console.log(result); // '123456789' * ``` */ declare const TrimSpaceRegExp: Readonly<RegExp>; /** * 正则:去掉字符串中的换行符 * @author Yuluo * @link https://github.com/YuluoY * @date 2024-09-28 * @constant * @example * ```ts * const str = '123\n456\n789'; * const result = str.replace(TrimNLRegExp, ''); * console.log(result); // '123456789' * ``` */ declare const TrimNLRegExp: Readonly<RegExp>; /** * 正则:去掉字符串中的回车符 * @author Yuluo * @link https://github.com/YuluoY * @date 2024-09-28 * @constant * @example * ```ts * const str = '123\r456\r789'; * const result = str.replace(TrimCRRegExp, ''); * console.log(result); // '123456789' * ``` */ declare const TrimCRRegExp: Readonly<RegExp>; /** * 正则:去掉字符串中的制表符 * @author Yuluo * @link https://github.com/YuluoY * @date 2024-09-28 * @constant * @example * ```ts * const str = '123\t456\t789'; * const result = str.replace(TrimTabRegExp, ''); * console.log(result); // '123456789' * ``` */ declare const TrimTabRegExp: Readonly<RegExp>; /** * 正则:去掉字符串中的空格、换行符、回车符、制表符 * @author Yuluo * @link https://github.com/YuluoY * @date 2024-09-28 * @constant * @example * ```ts * const str = ' 123 \n 456 \r 789 \t '; * const result = str.replace(TrimWhitespaceRegExp, ''); * console.log(result); // '123456789' * ``` */ declare const TrimWhitespaceRegExp: Readonly<RegExp>; /** * 正则:给字符串中对象属性名加双引号 * @author Yuluo * @link https://github.com/YuluoY * @date 2024-09-28 * @constant * @example * ```ts * const str = 'a:1,b:2,c:3'; * const result = str.replace(AddQuotesToPropsRegExp, '"$1":$2'); * console.log(result); // '"a":1,"b":2,"c":3' * * const str2 = '{a:1,b:2,c:3}'; * const result2 = str2.replace(AddQuotesToPropsRegExp, '"$1":$2'); * console.log(result2); // '{"a":1,"b":2,"c":3}' * ``` */ declare const AddQuotesToPropsRegExp: Readonly<RegExp>; /** * 正则:英文首字母大写 * @author Yuluo * @link https://github.com/YuluoY * @date 2024-09-28 * @constant * @example * ```ts * const str = 'hello world'; * const result = str.replace(UpperCaseRegExp, (match) => match.toUpperCase()); * console.log(result); // Hello world * ``` */ declare const UpperCaseRegExp: Readonly<RegExp>; /** * 正则:提取Symbol中的字符串 * @author Yuluo * @link https://github.com/YuluoY * @date 2024-10-15 * @constant * @example * ```ts * const str = 'Symbol("hello world")'; * const result = str.replace(SymbolRegExp, '$1'); * console.log(result); // hello world * * const str2 = 'Symbol("hello world") Symbol("hello world")'; * const result2 = str2.replace(SymbolRegExp, '$1'); * console.log(result2); // hello world hello world * ``` */ declare const SymbolRegExp: Readonly<RegExp>; /** * 正则:展开小驼峰命名的字符串 * @author Yuluo * @link https://github.com/YuluoY * @date 2024-10-15 * @constant * @example * ```ts * const str = 'helloWorld'; * const result = str.replace(CamelCaseRegExp, ' $1'); * console.log(result); // hello world * * const str2 = 'helloWorld helloWorld'; * const result2 = str2.replace(CamelCaseRegExp, ' $1'); * console.log(result2); // hello world hello world * ``` */ declare const CamelCaseRegExp: Readonly<RegExp>; /** * 正则:将下划线命名的字符串转换为小驼峰命名 * @author Yuluo * @link https://github.com/YuluoY * @date 2024-10-15 * @constant * @example * ```ts * const str = 'hello_world'; * const result = str.replace(UnderlineToCamelCaseRegExp, (_, letter) => letter.toUpperCase()); * console.log(result); // helloWorld * * const str2 = 'Underline_to_camel_case'; * const result2 = str2.replace(UnderlineToCamelCaseRegExp, (_, letter) => letter.toUpperCase()); * console.log(result2); // underlineToCamelCase * ``` */ declare const UnderlineToCamelCaseRegExp: Readonly<RegExp>; /** * 正则:模板字符串占位替换 - {} * @author Yuluo * @link https://github.com/YuluoY * @date 2024-10-18 * @constant * @example * ```ts * const template = 'Hello, {name}! You are {age} years old.'; * const result = template.replace(PlaceholderRegExp, (_, key: string) => {/\{(\d+)\}/g * const index = parseInt(key, 10) * return Array.isArray(data) ? data[index] : data[key] * }) * console.log(result); // Hello, world! You are 18 years old. * ``` */ declare const PlaceholderRegExp: Readonly<RegExp>; declare const core_AddQuotesToPropsRegExp: typeof AddQuotesToPropsRegExp; declare const core_CamelCaseRegExp: typeof CamelCaseRegExp; declare const core_PlaceholderRegExp: typeof PlaceholderRegExp; declare const core_SymbolRegExp: typeof SymbolRegExp; declare const core_TrimCRRegExp: typeof TrimCRRegExp; declare const core_TrimNLRegExp: typeof TrimNLRegExp; declare const core_TrimSpaceRegExp: typeof TrimSpaceRegExp; declare const core_TrimTabRegExp: typeof TrimTabRegExp; declare const core_TrimWhitespaceRegExp: typeof TrimWhitespaceRegExp; declare const core_UnderlineToCamelCaseRegExp: typeof UnderlineToCamelCaseRegExp; declare const core_UpperCaseRegExp: typeof UpperCaseRegExp; declare const core_addCustomSeparator: typeof addCustomSeparator; declare const core_addQuotesToProps: typeof addQuotesToProps; declare const core_capitalizeForWord: typeof capitalizeForWord; declare const core_chain: typeof chain; declare const core_concurRequest: typeof concurRequest; declare const core_convertRoutesToLevel: typeof convertRoutesToLevel; declare const core_cssGradientToECharts: typeof cssGradientToECharts; declare const core_expandCamelCase: typeof expandCamelCase; declare const core_fillTemplate: typeof fillTemplate; declare const core_getType: typeof getType; declare const core_getValue: typeof getValue; declare const core_groupByProp: typeof groupByProp; declare const core_hasWeightValue: typeof hasWeightValue; declare const core_idleCallback: typeof idleCallback; declare const core_idleTaskQueue: typeof idleTaskQueue; declare const core_isArray: typeof isArray; declare const core_isAsyncComponent: typeof isAsyncComponent; declare const core_isCJS: typeof isCJS; declare const core_isESM: typeof isESM; declare const core_isEmail: typeof isEmail; declare const core_isEmptyArray: typeof isEmptyArray; declare const core_isEmptyObject: typeof isEmptyObject; declare const core_isEmptyPlainObject: typeof isEmptyPlainObject; declare const core_isFloat: typeof isFloat; declare const core_isFunction: typeof isFunction; declare const core_isInteger: typeof isInteger; declare const core_isJSONString: typeof isJSONString; declare const core_isMacOS: typeof isMacOS; declare const core_isMobile: typeof isMobile; declare const core_isNull: typeof isNull; declare const core_isNullish: typeof isNullish; declare const core_isNumber: typeof isNumber; declare const core_isObject: typeof isObject; declare const core_isPC: typeof isPC; declare const core_isPhone: typeof isPhone; declare const core_isPlainObject: typeof isPlainObject; declare const core_isPrimitive: typeof isPrimitive; declare const core_isPromise: typeof isPromise; declare const core_isQQ: typeof isQQ; declare const core_isString: typeof isString; declare const core_isStringArray: typeof isStringArray; declare const core_isStringBoolean: typeof isStringBoolean; declare const core_isStringFunction: typeof isStringFunction; declare const core_isStringNumber: typeof isStringNumber; declare const core_isStringObject: typeof isStringObject; declare const core_isSymbol: typeof isSymbol; declare const core_isURL: typeof isURL; declare const core_isUndefined: typeof isUndefined; declare const core_isValidArray: typeof isValidArray; declare const core_isValidPlainObject: typeof isValidPlainObject; declare const core_isValue: typeof isValue; declare const core_isVueComponent: typeof isVueComponent; declare const core_isWindows: typeof isWindows; declare const core_parseJSON: typeof parseJSON; declare const core_parseStrWithType: typeof parseStrWithType; declare const core_parseStringify: typeof parseStringify; declare const core_pxToRem: typeof pxToRem; declare const core_restoreValue: typeof restoreValue; declare const core_root: typeof root; declare const core_runFn: typeof runFn; declare const core_setValue: typeof setValue; declare const core_toFixed: typeof toFixed; declare const core_toStringify: typeof toStringify; declare const core_trimCR: typeof trimCR; declare const core_trimNL: typeof trimNL; declare const core_trimSpace: typeof trimSpace; declare const core_trimTab: typeof trimTab; declare const core_trimWhitespace: typeof trimWhitespace; declare const core_tryit: typeof tryit; declare const core_underlineToCamelCase: typeof underlineToCamelCase; declare const core_watchFn: typeof watchFn; declare namespace core { export { core_AddQuotesToPropsRegExp as AddQuotesToPropsRegExp, core_CamelCaseRegExp as CamelCaseRegExp, core_PlaceholderRegExp as PlaceholderRegExp, core_SymbolRegExp as SymbolRegExp, core_TrimCRRegExp as TrimCRRegExp, core_TrimNLRegExp as TrimNLRegExp, core_TrimSpaceRegExp as TrimSpaceRegExp, core_TrimTabRegExp as TrimTabRegExp, core_TrimWhitespaceRegExp as TrimWhitespaceRegExp, core_UnderlineToCamelCaseRegExp as UnderlineToCamelCaseRegExp, core_UpperCaseRegExp as UpperCaseRegExp, core_addCustomSeparator as addCustomSeparator, core_addQuotesToProps as addQuotesToProps, core_capitalizeForWord as capitalizeForWord, core_chain as chain, core_concurRequest as concurRequest, core_convertRoutesToLevel as convertRoutesToLevel, core_cssGradientToECharts as cssGradientToECharts, core_expandCamelCase as expandCamelCase, core_fillTemplate as fillTemplate, core_getType as getType, core_getValue as getValue, core_groupByProp as groupByProp, core_hasWeightValue as hasWeightValue, core_idleCallback as idleCallback, core_idleTaskQueue as idleTaskQueue, core_isArray as isArray, core_isAsyncComponent as isAsyncComponent, core_isCJS as isCJS, core_isESM as isESM, core_isEmail as isEmail, core_isEmptyArray as isEmptyArray, core_isEmptyObject as isEmptyObject, core_isEmptyPlainObject as isEmptyPlainObject, core_isFloat as isFloat, core_isFunction as isFunction, core_isInteger as isInteger, core_isJSONString as isJSONString, core_isMacOS as isMacOS, core_isMobile as isMobile, core_isNull as isNull, core_isNullish as isNullish, core_isNumber as isNumber, core_isObject as isObject, core_isPC as isPC, core_isPhone as isPhone, core_isPlainObject as isPlainObject, core_isPrimitive as isPrimitive, core_isPromise as isPromise, core_isQQ as isQQ, core_isString as isString, core_isStringArray as isStringArray, core_isStringBoolean as isStringBoolean, core_isStringFunction as isStringFunction, core_isStringNumber as isStringNumber, core_isStringObject as isStringObject, core_isSymbol as isSymbol, core_isURL as isURL, core_isUndefined as isUndefined, core_isValidArray as isValidArray, core_isValidPlainObject as isValidPlainObject, core_isValue as isValue, core_isVueComponent as isVueComponent, core_isWindows as isWindows, core_parseJSON as parseJSON, core_parseStrWithType as parseStrWithType, core_parseStringify as parseStringify, core_pxToRem as pxToRem, core_restoreValue as restoreValue, core_root as root, core_runFn as runFn, core_setValue as setValue, core_toFixed as toFixed, core_toStringify as toStringify, core_trimCR as trimCR, core_trimNL as trimNL, core_trimSpace as trimSpace, core_trimTab as trimTab, core_trimWhitespace as trimWhitespace, core_tryit as tryit, core_underlineToCamelCase as underlineToCamelCase, core_watchFn as watchFn }; } export { isStringFunction as $, pxToRem as A, addCustomSeparator as B, chain as C, isCJS as D, isESM as E, isPrimitive as F, hasWeightValue as G, isNull as H, isNullish as I, isUndefined as J, isSymbol as K, isFunction as L, isObject as M, isPlainObject as N, isEmptyObject as O, isEmptyPlainObject as P, isString as Q, isArray as R, isEmptyArray as S, isFloat as T, isNumber as U, isInteger as V, isJSONString as W, isStringNumber as X, isStringBoolean as Y, isStringArray as Z, isStringObject as _, trimNL as a, isWindows as a0, isMacOS as a1, isMobile as a2, isPC as a3, isURL as a4, isEmail as a5, isPhone as a6, isQQ as a7, isPromise as a8, isAsyncComponent as a9, isVueComponent as aa, isValue as ab, isValidArray as ac, isValidPlainObject as ad, idleCallback as ae, idleTaskQueue as af, concurRequest as ag, tryit as ah, TrimSpaceRegExp as ai, TrimNLRegExp as aj, TrimCRRegExp as ak, TrimTabRegExp as al, TrimWhitespaceRegExp as am, AddQuotesToPropsRegExp as an, UpperCaseRegExp as ao, SymbolRegExp as ap, CamelCaseRegExp as aq, UnderlineToCamelCaseRegExp as ar, PlaceholderRegExp as as, trimCR as b, core as c, trimTab as d, trimWhitespace as e, addQuotesToProps as f, convertRoutesToLevel as g, groupByProp as h, capitalizeForWord as i, getType as j, cssGradientToECharts as k, getValue as l, runFn as m, parseStrWithType as n, restoreValue as o, parseJSON as p, parseStringify as q, root as r, setValue as s, trimSpace as t, toStringify as u, expandCamelCase as v, watchFn as w, underlineToCamelCase as x, toFixed as y, fillTemplate as z };