Skip to documentation

package

@stackline/once 1.0.5 — installation and API

Compatibility-first one-shot function wrappers with safe callback decorations and the restored prototype API

Install @stackline/once

npm install @stackline/[email protected]

Package version: 1.0.5. Metadata verified: 2026-11-12. This is separate from the framework version and demonstration runtime.

Node.js requirement
{"node": ">=0.10.0"}
Accepted peer dependencies (declared ranges)
{}

Tested environments are described in the versioned README and linked source checks. A declared peer range is not evidence that every version in it was tested.

Versioned reference

This reference comes from the published @stackline/[email protected] README. Its upstream attribution and license remain with the source. Benchmark and security statements describe the cited tests and advisories, not a guarantee for every application.

@stackline/once

Compatibility-first one-shot function wrappers with safe callback decorations and the restored prototype API.

Documentation | npm | Issues | Repository

Current package version: 1.0.5


Why this package?

Compatibility-first one-shot function wrappers with the documented prototype initializer restored and callback decorations prevented from corrupting wrapper state.

This is an independent Stackline continuation of once; it is not affiliated with or endorsed by Isaac Z. Schlueter, npm, or the upstream project.

Compatibility

Item Value
Package @stackline/[email protected]
Node.js runtime >=0.10.0
CommonJS / primary entry ./once.js
Type declarations ./once.d.ts

Installation

Install

For new code:

npm install @stackline/[email protected]

To preserve an existing require('once') without source changes:

npm install once@npm:@stackline/[email protected]

Usage

CommonJS

var once = require('@stackline/once')

var initialize = once(function (value) {
  return { value: value }
})

var first = initialize('ready')
var second = initialize('ignored')

console.log(first === second) // true
console.log(initialize.called) // true
console.log(initialize.value === first) // true

The historical deep entry is preserved:

var once = require('@stackline/once/once.js')

Features and Integrations

ESM and TypeScript

The runtime remains one ES5 CommonJS implementation. Ordinary ESM default interop works without a second implementation:

import once from '@stackline/once'

First-party declarations preserve parameters, this, return type, state, strict state, and the opt-in prototype helpers. They are tested with TypeScript 3.9 and current TypeScript.

Support boundary

The maintained runtime matrix begins at exact Node.js 0.10.48 and covers the active LTS/current line. The production source is ES5, uses no Node-only API, and is also bundled for a browser test. Development, type, package, and release tools require a current Node release; they do not ship. There are no runtime dependencies. See COMPATIBILITY_CONTRACT.md, MIGRATION.md, SECURITY.md, and THIRD_PARTY_LICENSES.md for precise boundaries.

Security

Review inputs and the package-specific compatibility limits before processing untrusted data. Report suspected vulnerabilities as described in the security policy.

API Surface

Strict mode

once.strict(fn) executes the function once and throws on every later call. Its public onceError string can be customized after wrapping.

var connect = once.strict(function connect () {})
connect.onceError = 'connect may only run once'
connect()
connect() // throws Error: connect may only run once

Public state and decorations

Wrappers expose mutable called state. value is created when the first call completes, including when the value is undefined; a synchronous throw leaves called === true and no cached value. Re-entry before the first call returns sees the same historical state: ordinary mode returns the current value, and strict mode throws.

Own enumerable string decorations on the input function are copied by value. Inherited, non-enumerable, and symbol properties are not copied, matching [email protected]. The reserved keys called, value, and onceError are not copied because they control wrapper state. An enumerable __proto__ decoration is copied as ordinary own data without changing the wrapper's prototype.

Optional Function prototype helpers

The upstream README documented once.proto(), but published [email protected] failed to export it. This package includes the signed upstream v1.4.1 fix:

once.proto()

var load = function load () { return 42 }
load.once()()
load.onceStrict()()

Calling once.proto() mutates Function.prototype. The installed once and onceStrict properties are non-enumerable, non-writable, and configurable, matching upstream. Prefer direct wrappers in libraries; call proto() only in an application that owns this global policy.

Local Development

git clone https://github.com/alexandroit/stackline-once.git
cd stackline-once
npm ci
npm run verify

Release tooling uses Node.js 24.20.0 and npm 11.19.0. The consumer runtime contract remains the one documented above.

Consumer Smoke Test

Run the repository's existing consumer/package check after installing development dependencies:

npm run test:smoke

Release Checklist

Run npm run verify and inspect the package contents before release. Publish a new version through the GitHub Actions publishing workflow, using the SHA-512 digest of the reviewed tarball. Verify the exact published version, tarball integrity, and npm provenance after the run.

License

ISC. See the license for the complete terms.

Original authorship and third-party attribution are preserved in NOTICE.

Credits and original authors

  • Stackline Maintainers.
  • Isaac Z. Schlueter and Contributors.
  • Copyright (c) 2012-2022 Isaac Z. Schlueter and Contributors.
  • Copyright (c) 2026 Stackline Maintainers.
  • Stackline maintenance: Alexandro Paixao Marques and Stackline contributors.

Original copyright, license notices and contributor acknowledgements remain part of this distribution. Stackline maintenance does not replace authorship of the original work.

Use this repository's issue tracker for reproducible bugs and feature requests. Join r/Stackline for examples, usage questions and release discussions.

Examples and compatibility

The original example runtime is preserved. Its build is identified by source commit c7a8cf137fcf17c2ee990a53f02d89a8a9f06fd5. Package version and runtime version must be checked independently.

Open the original example

Examples load only when requested. They have their own runtime and are separate from this reference.