Skip to main content

Built and signed on GitHub Actions

A modern JavaScript utility library that's 2-3 times faster and up to 97% smaller—a major upgrade to lodash.

This package works with Cloudflare Workers, Node.js, Deno, Bun, Browsers
This package works with Cloudflare Workers
This package works with Node.js
This package works with Deno
This package works with Bun
This package works with Browsers
JSR Score
100%
Published
2 weeks ago (1.17.0)
function after
after<F extends (...args: any[]) => any>(
n: number,
func: F,
): F

Creates a function that only executes starting from the n-th call. The provided function will be invoked starting from the n-th call.

This is particularly useful for scenarios involving events or asynchronous operations where an action should occur only after a certain number of invocations.

Examples

const afterFn = after(3, () => { console.log("called") });

// Will not log anything. afterFn() // Will not log anything. afterFn() // Will log 'called'. afterFn()

Type Parameters

F extends (...args: any[]) => any
  • The type of the function to be invoked.

Parameters

  • The number of calls required for func to execute.
func: F
  • The function to be invoked.

Return Type

  • A new function that:
  • Tracks the number of calls.
  • Invokes func starting from the n-th call.
  • Returns undefined if fewer than n calls have been made.

Add Package

deno add @es-toolkit/es-toolkit

Import symbol

import { after } from "@es-toolkit/es-toolkit/compat";

---- OR ----

Import directly with a jsr specifier

import { after } from "jsr:@es-toolkit/es-toolkit/compat";

Add Package

npx jsr add @es-toolkit/es-toolkit

Import symbol

import { after } from "@es-toolkit/es-toolkit/compat";

Add Package

yarn dlx jsr add @es-toolkit/es-toolkit

Import symbol

import { after } from "@es-toolkit/es-toolkit/compat";

Add Package

pnpm dlx jsr add @es-toolkit/es-toolkit

Import symbol

import { after } from "@es-toolkit/es-toolkit/compat";

Add Package

bunx jsr add @es-toolkit/es-toolkit

Import symbol

import { after } from "@es-toolkit/es-toolkit/compat";