schnee effeckt und fehler Korektur

This commit is contained in:
2023-08-14 17:52:24 +02:00
parent 4a843d4936
commit 79af4e9907
6813 changed files with 343821 additions and 356128 deletions

49
node_modules/onetime/index.js generated vendored
View File

@@ -1,31 +1,44 @@
'use strict';
module.exports = function (fn, errMsg) {
if (typeof fn !== 'function') {
const mimicFn = require('mimic-fn');
const calledFunctions = new WeakMap();
const onetime = (function_, options = {}) => {
if (typeof function_ !== 'function') {
throw new TypeError('Expected a function');
}
var ret;
var called = false;
var fnName = fn.displayName || fn.name || (/function ([^\(]+)/.exec(fn.toString()) || [])[1];
let returnValue;
let callCount = 0;
const functionName = function_.displayName || function_.name || '<anonymous>';
var onetime = function () {
if (called) {
if (errMsg === true) {
fnName = fnName ? fnName + '()' : 'Function';
throw new Error(fnName + ' can only be called once.');
}
const onetime = function (...arguments_) {
calledFunctions.set(onetime, ++callCount);
return ret;
if (callCount === 1) {
returnValue = function_.apply(this, arguments_);
function_ = null;
} else if (options.throw === true) {
throw new Error(`Function \`${functionName}\` can only be called once`);
}
called = true;
ret = fn.apply(this, arguments);
fn = null;
return ret;
return returnValue;
};
onetime.displayName = fnName;
mimicFn(onetime, function_);
calledFunctions.set(onetime, callCount);
return onetime;
};
module.exports = onetime;
// TODO: Remove this for the next major release
module.exports.default = onetime;
module.exports.callCount = function_ => {
if (!calledFunctions.has(function_)) {
throw new Error(`The given function \`${function_.name}\` is not wrapped by the \`onetime\` package`);
}
return calledFunctions.get(function_);
};