'use strict';constmimicFn=require('mimic-fn');module.exports=(fn,opts)=>{// TODO: Remove this in v3if(opts===true){thrownewTypeError('The second argument is now an options object');}if(typeoffn!=='function'){thrownewTypeError('Expected a function');}opts=opts||{};letret;letcalled=false;constfnName=fn.displayName||fn.name||'<anonymous>';constonetime=function(){if(called){if(opts.throw===true){thrownewError(`Function \`${fnName}\` can only be called once`);}returnret;}called=true;ret=fn.apply(this,arguments);fn=null;returnret;};mimicFn(onetime,fn);returnonetime;};