UNPKG

@ryusei/code

Version:

<div align="center"> <a href="https://code.ryuseijs.com"> <img alt="RyuseiCode" src="https://code.ryuseijs.com/images/svg/logo.svg" width="70"> </a>

17 lines (14 loc) 605 B
import { AnyFunction } from '@ryusei/code'; import { Throttle, throttle } from '../throttle/throttle'; /** * Returns a debounced function that invokes the provided function only after the internal timer expires. * The timer is reset whenever the debounced function is called. * * @param func - A callback function. * @param duration - Debounce duration in milliseconds. * * @return A debounced function. */ export function debounce<F extends AnyFunction = AnyFunction>( func: AnyFunction, duration: number ): Throttle<F> { return throttle( func, duration, false, true ); }