Tweakr
    Preparing search index...

    Function before

    • Creates a function that invokes fn until it has been called n - 1 times.

      The returned function will call fn for the first n - 1 invocations. After that, it always returns undefined.

      Type Parameters

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

        The type of the function to be invoked.

      Parameters

      • n: number

        The maximum number of times fn can be invoked plus one.

      • fn: T

        The function to invoke until the limit is reached.

      Returns (...args: Parameters<T>) => undefined | ReturnType<T>

      A new function that stops invoking fn after n - 1 calls.

      1.2.0

      const limited = before(3, () => console.log("Run"));
      limited(); limited(); limited(); // logs "Run" twice