vendor-index.9d9196cc.mjs 1.5 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061
  1. var onetime$1 = {exports: {}};
  2. var mimicFn$2 = {exports: {}};
  3. const mimicFn$1 = (to, from) => {
  4. for (const prop of Reflect.ownKeys(from)) {
  5. Object.defineProperty(to, prop, Object.getOwnPropertyDescriptor(from, prop));
  6. }
  7. return to;
  8. };
  9. mimicFn$2.exports = mimicFn$1;
  10. // TODO: Remove this for the next major release
  11. mimicFn$2.exports.default = mimicFn$1;
  12. const mimicFn = mimicFn$2.exports;
  13. const calledFunctions = new WeakMap();
  14. const onetime = (function_, options = {}) => {
  15. if (typeof function_ !== 'function') {
  16. throw new TypeError('Expected a function');
  17. }
  18. let returnValue;
  19. let callCount = 0;
  20. const functionName = function_.displayName || function_.name || '<anonymous>';
  21. const onetime = function (...arguments_) {
  22. calledFunctions.set(onetime, ++callCount);
  23. if (callCount === 1) {
  24. returnValue = function_.apply(this, arguments_);
  25. function_ = null;
  26. } else if (options.throw === true) {
  27. throw new Error(`Function \`${functionName}\` can only be called once`);
  28. }
  29. return returnValue;
  30. };
  31. mimicFn(onetime, function_);
  32. calledFunctions.set(onetime, callCount);
  33. return onetime;
  34. };
  35. onetime$1.exports = onetime;
  36. // TODO: Remove this for the next major release
  37. onetime$1.exports.default = onetime;
  38. onetime$1.exports.callCount = function_ => {
  39. if (!calledFunctions.has(function_)) {
  40. throw new Error(`The given function \`${function_.name}\` is not wrapped by the \`onetime\` package`);
  41. }
  42. return calledFunctions.get(function_);
  43. };
  44. export { onetime$1 as o };