go back
Getting Started with the Documentation
bun add one-firework
import firework from 'one-firework';
function veryExpensiveFunction() {
// did some expensive work
return result;
}
const oneFireworkExecution = firework(veryExpensiveFunction);
console.log(oneFireworkExecution()); // will call the function and return the result
console.log(oneFireworkExecution()); // will return the cached result
console.log(firework.fired(oneFireworkExecution)) // will return true if the function was called at least once
API
firework(fn: Function): Function
fn
: The function to be executed. It can be any function that you want to cache the result of.
- Returns a new function that, when called, will execute the original function and cache its result.
firework.fired(fn: Function): number
fn
: The function to check if it has been executed how many times.
- Returns a number of times firework function executed.