Back to Explore

sindresorhus/onetime

GitHub
1 watchersOpen source

Last release: 4 months ago

Provides a helper to wrap a function so it can only be called once, returning the first call’s return value on subsequent calls. It can optionally throw an error when the wrapped function is called more than once, and includes an API to check how many times the wrapped function has been invoked.

Project status

  • Actively maintained, with recent upstream activity (last push 2026-02-02) and a new tagged update v8.0.0 on 2026-02-02.
  • Apparent update cadence is uneven, with a long gap between v7.0.0 (2023-11-05) and v8.0.0 (2026-02-02), suggesting occasional major updates rather than frequent patch releases.

AI summary generated Today

AI-generated from public sources. May be inaccurate. Report

Recent updates

  • v8.0.0

    4 months ago

    v8.0.0 introduces a Node.js 22+ requirement and tightens TypeScript typing for `callCount` so it only accepts functions wrapped by `onetime`. It also changes runtime call behavior in `onetime` itself, particularly when the wrapped function throws on the first invocation.

    Breaking
  • v7.0.0

    11/5/2023

    This release upgrades the package to target Node.js 18 (and updates the CI workflow accordingly). The functional runtime logic is mostly unchanged, but the TypeScript declarations and package metadata were modified alongside a dependency swap.

    Breaking
  • v6.0.0

    4/8/2021

    v6.0.0 makes the package pure ESM and raises the minimum supported Node.js version to 12. The codebase also switches from CommonJS exports to a default export and updates types, tests, and several dependency versions.

    Breaking
  • v5.1.2

    8/9/2020

    This release makes a small naming consistency change (v5.1.1 to v5.1.2) with a single commit referenced in the notes. The code change primarily renames the exported identifier and TypeScript namespace from `oneTime` to `onetime`.

  • v5.1.1

    8/2/2020

    v5.1.1 is described in the release notes as a documentation-only update. However, the actual diff includes a code refactor of the onetime wrapper implementation, along with test and CI configuration changes and additional repo metadata files.

  • v5.1.0

    4/2/2019

    v5.1.0 is primarily a TypeScript typing change intended to make the package’s exports more compatible with CommonJS consumption. The diff also includes small runtime interop additions and dependency/tooling bumps.

    Breaking
  • v5.0.0

    3/8/2019

    v5.0.0 updates the TypeScript type definitions so `callCount` is exposed on the default export (`onetime.callCount`) instead of as a named export. The diff also includes dependency version bumps (not mentioned in the release notes) and minor README/example adjustments.

    Breaking
  • v4.0.0

    3/1/2019

    v4.0.0 adds TypeScript definitions and introduces stricter behavior around `onetime.callCount()`. The documented breaking change is that `callCount` now throws when given a function that was not wrapped by `onetime`. Code changes also adjust the internal call counter behavior and add `tsd-check` to the test suite.

    BreakingFeatures
  • v3.0.0

    1/20/2019

    v3.0.0 introduces a new utility method for retrieving how many times a function was called. It also changes the supported runtime by requiring a newer Node.js version, which may require upgrading your environment before you can adopt the release.

    BreakingFeatures