@bnidev/js-utils
    Preparing search index...

    Function throttleFn

    • Creates a throttled version of a function that ensures the original function is invoked at most once every specified number of milliseconds.

      Type Parameters

      • T extends (...args: unknown[]) => void

        The type of the function to throttle.

      Parameters

      • func: T

        The function to be throttled.

      • delay: number

        The minimum time interval (in milliseconds) between invocations of func.

      Returns (...args: Parameters<T>) => void

      A new function that wraps func and enforces the throttling behavior.

      This utility is useful for rate-limiting a function that might be called frequently, such as an event handler or API call, to improve performance or avoid overloading a system.

      // ES Module
      import { throttleFn } from '@bnidev/js-utils'

      // CommonJS
      const { throttleFn } = require('@bnidev/js-utils')
      const log = () => console.log('Hello')
      const throttledLog = throttleFn(log, 1000)

      window.addEventListener('scroll', throttledLog)