mirror of
https://github.com/swc-project/swc.git
synced 2024-12-30 00:52:29 +03:00
46 lines
1.2 KiB
TypeScript
46 lines
1.2 KiB
TypeScript
|
// Loaded from https://cdn.skypack.dev/-/once@v1.4.0-dZva3nt1fLBY6vpXF5Hj/dist=es2020,mode=imports/optimized/once.js
|
||
|
|
||
|
|
||
|
import wrappy2 from "/-/wrappy@v1.0.2-e8nLh7Qms0NRhbAbUpJP/dist=es2020,mode=imports/optimized/wrappy.js";
|
||
|
var once_1 = wrappy2(once);
|
||
|
var strict = wrappy2(onceStrict);
|
||
|
once.proto = once(function() {
|
||
|
Object.defineProperty(Function.prototype, "once", {
|
||
|
value: function() {
|
||
|
return once(this);
|
||
|
},
|
||
|
configurable: true
|
||
|
});
|
||
|
Object.defineProperty(Function.prototype, "onceStrict", {
|
||
|
value: function() {
|
||
|
return onceStrict(this);
|
||
|
},
|
||
|
configurable: true
|
||
|
});
|
||
|
});
|
||
|
function once(fn) {
|
||
|
var f = function() {
|
||
|
if (f.called)
|
||
|
return f.value;
|
||
|
f.called = true;
|
||
|
return f.value = fn.apply(this, arguments);
|
||
|
};
|
||
|
f.called = false;
|
||
|
return f;
|
||
|
}
|
||
|
function onceStrict(fn) {
|
||
|
var f = function() {
|
||
|
if (f.called)
|
||
|
throw new Error(f.onceError);
|
||
|
f.called = true;
|
||
|
return f.value = fn.apply(this, arguments);
|
||
|
};
|
||
|
var name = fn.name || "Function wrapped with `once`";
|
||
|
f.onceError = name + " shouldn't be called more than once";
|
||
|
f.called = false;
|
||
|
return f;
|
||
|
}
|
||
|
once_1.strict = strict;
|
||
|
export default once_1;
|
||
|
export {once_1 as __moduleExports, strict};
|