UNPKG

tiny-once

Version:

Very simple wrapper to run a function only once

19 lines (14 loc) 379 B
"use strict"; function once(fn) { var options = arguments.length <= 1 || arguments[1] === undefined ? {} : arguments[1]; var called = false; var result = void 0; return function () { if (called) { return options.cached ? result : null; } called = true; return result = fn.apply(options.context || this, arguments); }; } module.exports = once;