/** * 空函数 * @category 函数 */ export declare const noop: (...args: any) => any; /** * 是否为函数 * @category 函数 */ export declare function isFn(fn: unknown): fn is (...args: any) => any; /** * 防抖函数 * * ```ts * import { debounce } from 'sunny-js' * // 常规用法 * document.addEventListener( * 'mousemove', * debounce(function (e) { * console.log(this, e) * }, 350) * ) * // 带有返回值 * const _wrappedFn = debounce( * (e: MouseEvent) => `clientX ${e.clientX}, clientY ${e.clientY}`, * 350 * ) * document.addEventListener('mousemove', e => { * void _wrappedFn(e).then(console.log) * }) * ``` * * @category 函数 */ export declare function debounce(fn: (this: TContext, ...args: TParams) => TReturn | Promise, wait: number): (this: TContext, ...args: TParams) => TReturn extends void ? void : Promise; /** * 节流函数 * * ```ts * import { throttle } from 'sunny-js' * // 常规用法 * document.addEventListener( * 'mousemove', * throttle(function (e) { * console.log(this, e) * }, 350) * ) * ``` * * @category 函数 */ export declare function throttle(fn: (this: TContext, ...args: TParams) => void, wait: number): (this: TContext, ...args: TParams) => void; /** * 记忆函数 * * ```ts * import { throttle } from 'sunny-js' * const _fn = memoize(function (...args) { * console.log(['compute', this, ...args]) * return ['value', ...args] * }) * console.log(_fn()) * console.log(_fn()) * console.log(_fn(console)) * console.log(_fn(console)) * console.log(_fn(1, 2)) * console.log(_fn(1, 2)) * console.log(_fn.cache) * ``` * * @param fn 被包装的函数 * @param resolver 返回值将作为cache key。默认resolver逻辑是:如果无参数,使用fn.toString()作为key;如果有一个参数,args[0]为key;如果参数个数大于1,JSON.stringify(args)作为key。 * @see {@link https://www.sitepoint.com/implementing-memoization-in-javascript/ Implementing Memoization in JavaScript} * @see {@link https://lodash.com/docs/4.17.15#memoize lodash memoize} * @category 函数 */ export declare function memoize(fn: (this: TContext, ...args: TParams) => TReturn, resolver?: (this: TContext, ...args: TParams) => any): { (this: TContext, ...args: TParams): TReturn; cache: Map; }; /** * 函数合并调用 * * ```ts * import { combineFunctions } from 'sunny-js' * // 合并多个事件监听函数 * document.addEventListener( * 'click', * combineFunctions( * function (e) { * console.log(this, e) * }, * function (e) { * console.info(this, e) * } * ) * ) * // 使用函数的返回值 * const combinedFn = combineFunctions<[], number | string>( * () => 1, * () => 'hello', * () => 'world' * ) * console.log(combinedFn()) * ``` * * @since 2.1.33 * @category 函数 */ export declare function combineFunctions(...functions: Array<(this: TContext, ...args: TArgs) => TReturn>): (this: TContext, ...args: TArgs) => TReturn extends void ? void : TReturn[];