
Security News
Attackers Are Hunting High-Impact Node.js Maintainers in a Coordinated Social Engineering Campaign
Multiple high-impact npm maintainers confirm they have been targeted in the same social engineering campaign that compromised Axios.
Create a once-only function and it will be never repeated
npm install once-only
or
yarn add once-only
import { onceOnly } from 'once-only'
Create:
const createUserOnce = onceOnly(createUser);
Original function will be called only once. It returns cache on a repeated call:
const currentUser = createUserOnce({ userId: 234 });
You can pass configuration object to onceOnly as a second argument:
You can pass config as a second argument.
Default values are: { attach: false, strict: false }
attach optionAttach once function to the original function:
onceOnly(fetchCompany, { attach: true });
Then call it:
const promise = fetchCompany.once({ companyId: 11 });
strict optionYou can throw an error when a function is called more than once:
const getIdOnceOnly = onceOnly(getId, { strict: true });
const users = getIdOnceOnly({ userId: 234 }); // Throws an error
Returned function has two static properties (as well as an attached once function):
.calledconsole.log(fetchUsersOnce.called); // true or false
.cacheconsole.log(fetchUserOnce.cache); // function: () => cache
const result = fetchUserOnce.cache(); // call cache getter
console.log(result); // logs the result of the first function call
If you found this packeage useful, please star it on GitHub ★
once-only adjective
That occurs, operates, etc., on one occasion only.
Origin:
1960s; earliest use found in The Sunday Express.
once-only in British adjective
(ˌwʌnsˈəʊnlɪ)
never to be repeated
Examples:
^Collins English Dictionary. Copyright © HarperCollins Publishers
@doasync
MIT
FAQs
Call function once. Create a never to be repeated function
We found that once-only demonstrated a not healthy version release cadence and project activity because the last version was released a year ago. It has 1 open source maintainer collaborating on the project.
Did you know?

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Security News
Multiple high-impact npm maintainers confirm they have been targeted in the same social engineering campaign that compromised Axios.

Security News
Axios compromise traced to social engineering, showing how attacks on maintainers can bypass controls and expose the broader software supply chain.

Security News
Node.js has paused its bug bounty program after funding ended, removing payouts for vulnerability reports but keeping its security process unchanged.