/** * 生成一个指定长度的alphaId并返回。id内容由随机字母表字符组成 * @example * // urN-k0mpetBwboeQ * console.log(_.alphaId()) * // Ii6cPyfw-Ql5YC8OIhVwH1lpGY9x * console.log(_.alphaId(28)) * * @param len id长度 * @returns alphaId * @since 1.0.0 */ declare function alphaId(len?: number): string; /** * 如果v是null/undefined/NaN中的一个,返回defaultValue * @example * //"x" * console.log(_.defaultTo(null,'x')) * //0 * console.log(_.defaultTo(0,'y')) * * @param v 任何值 * @param defaultValue 任何值 * @returns v或defaultValue * @since 0.16.0 */ declare function defaultTo(v: T, defaultValue: V): T | V; /** * 返回参数列表中的第一个值,即f(x) = x。该函数可以用来为高阶函数提供数据如过滤列表或map,也用作默认迭代器 * @example * //[1,2,4,'a','1'] * console.log(_.filter([0,1,false,2,4,undefined,'a','1','',null],_.identity)) * const list = [ * {name:'a',value:1}, * {name:'b',value:2}, * {name:'c',value:3} * ] * //list * console.log(_.map(list,_.identity)) * * @param v * @returns 第一个参数 * @since 0.17.0 */ declare function identity(v: any): any; /** * 非函数迭代类型 */ type NonFuncItee = string | Record | Array; /** * 创建一个函数,函数类型根据参数值类型而定。创建的函数常用于迭代回调,在Func.js内部被大量使用 * * @example * const libs = [ * {name:'func.js',platform:['web','nodejs'],tags:{utils:true},js:true}, * {name:'juth2',platform:['web','java'],tags:{utils:false,middleware:true},js:false}, * {name:'soya2d',platform:['web'],tags:{utils:true},js:false} * ]; * * //[{func.js...}] 如果参数是object,返回_.matcher * console.log(_.filter(libs,_.iteratee({tags:{utils:true},js:true}))) * //[func.js,juth2,soya2d] 如果参数是字符串,返回_.prop * console.log(_.map(libs,_.iteratee('name'))) * //[true,false,true] 如果参数是数组,内容会转为path,并返回_.prop * console.log(_.map(libs,_.iteratee(['tags','utils']))) * //[1,3,5] 如果参数是函数,返回这个函数 * console.log(_.filter([1,2,3,4,5],_.iteratee(n=>n%2))) * //[1,2,4,'a','1'] 无参返回_.identity * console.log(_.filter([0,1,false,2,4,undefined,'a','1','',null],_.iteratee())) * * * @param value 迭代模式 *
当value是字符串类型时,返回_.prop *
当value是对象类型时,返回_.matcher *
当value是数组类型时,内容会转为path,并返回_.prop *
当value是函数时,返回这个函数 *
当value未定义时,返回_.identity *
其他类型返回f() = false * @returns 不同类型的返回函数 * @since 0.17.0 */ declare function iteratee(value: Function | NonFuncItee): Function; /** * 创建一个函数,该函数接收一个对象为参数并返回对该对象使用props进行验证的的断言结果。 * * * @example * const libs = [ * {name:'func.js',platform:['web','nodejs'],tags:{utils:true},js:true}, * {name:'juth2',platform:['web','java'],tags:{utils:false,middleware:true},js:false}, * {name:'soya2d',platform:['web'],tags:{utils:true},js:false} * ]; * * //[{func.js...}] * console.log(_.filter(libs,_.matcher({tags:{utils:true},js:true}))) * * @param props 断言条件对象 * @returns matcher(v)函数 * @since 0.17.0 */ declare function matcher(props: T): (obj: T) => boolean; /** * 为 myfx 扩展额外函数,扩展后的函数同样具有函数链访问能力 * * @example * //增加扩展 * _.mixin({ * select:_.get, * from:_.chain, * where:_.filter, * top:_.first * }); * * const libs = [ * {name:'myfx',platform:['web','nodejs'],tags:{utils:true},js:true}, * {name:'juth2',platform:['web','java'],tags:{utils:false,middleware:true},js:false}, * {name:'soya2d',platform:['web'],tags:{utils:true},js:true} * ]; * //查询utils是true的第一行数据的name值 * console.log(_.from(libs).where({tags:{utils:true}}).top().select('name').value()) * * @param obj 扩展的函数声明 */ declare function mixin(target: Record, obj: Record): void; /** * 当通过非esm方式引用函数库时,函数库会默认挂载全局变量_。 * 如果项目中存在其它以该变量为命名空间的函数库(如lodash、underscore等)则会发生命名冲突。 * 该函数可恢复全局变量为挂载前的引用,并返回myfuncs命名空间 * @example * // 返回myfuncs并重置全局命名空间 _ * console.log(_.noConflict()) * * @returns 返回myfuncs命名空间 * @since 1.0.0 */ declare function noConflict(): Record; /** * 永远返回undefined * @example * //undefined * console.log(_.noop('func')) * //undefined * console.log(_.noop()) * * @returns undefined * @since 0.16.0 */ declare function noop(): undefined; /** * 生成一个64bit整数的雪花id并返回,具体格式如下: * * 0 - timestamp - nodeId - sequence
* 0 - [0000000000 0000000000 0000000000 0000000000 0] - [0000000000] - [000000000000] *
* 可用于客户端生成可跟踪统计的id,如定制终端 * @example * // 343155438738309188 * console.log(_.snowflakeId(123)) * // 78249955004317758 * console.log(_.snowflakeId(456,new Date(2022,1,1).getTime())) * * @param nodeId 节点id,10bit整数 * @param epoch 时间起点,用于计算相对时间戳 * @returns snowflakeId 由于js精度问题,直接返回字符串而不是number,如果nodeId为空返回 '0000000000000000000' * @since 1.0.0 */ declare function snowflakeId(nodeId: number, epoch?: number): string; /** * 调用iteratee函数n次,并将历次调用的返回值数组作为结果返回 * @example * //['0',...,'4'] * console.log(_.times(5,String)) * //[[0],[1]] * console.log(_.times(2,_.toArray)) * * @param n 迭代次数 * @param iteratee 每次迭代调用函数 * @returns 返回值数组 * @since 0.17.0 */ declare function times(n: number, iteratee: (n: number) => V): V[]; /** * 解析path并返回数组 * @example * //['a', 'b', '2', 'c'] * console.log(_.toPath('a.b[2].c')) * //['a', 'b', 'c', '1'] * console.log(_.toPath(['a','b','c[1]'])) * //['1'] * console.log(_.toPath(1)) * * @param path 属性路径,可以是数字索引,字符串key,或者多级属性数组 * @returns path数组 * @since 0.16.0 */ declare function toPath(path: Array | string | number): string[]; /** * 返回一个全局的整数id,序号从0开始。可以用于前端列表编号等用途 * * @example * //func_0 * console.log(_.uniqueId('func')) * //1 * console.log(_.uniqueId()) * * @param prefix id前缀 * @returns 唯一id * @since 0.16.0 */ declare function uniqueId(prefix?: string): string; /** * 生成一个32/36个字符组件的随机uuid(v4)并返回 * @example * // ddfd73a5-62ac-4412-ad2b-fd495f766caf * console.log(_.uuid(true)) * // ddfd73a562ac4412ad2bfd495f766caf * console.log(_.uuid()) * * @param delimiter 是否生成分隔符 * @returns uuid * @since 1.0.0 */ declare function uuid(delimiter?: boolean): string; export { alphaId, defaultTo, identity, iteratee, matcher, mixin, noConflict, noop, snowflakeId, times, toPath, uniqueId, uuid };