You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

2 lines
640 B

"use strict";function monkeyPatch(e,t,o){var n=Symbol();const i=o.before,c=o.instead,f=o.after,r=new Proxy(t[e],{apply:(e,t,[n,r])=>{void 0!==i&&i.apply(n,r);const a=void 0!==o.instead?c.apply(n,[e.bind(n),...r]):e.apply(n,r);return void 0===f?a:f.apply(n,[a].concat(r))}}),a=t[e];t[e]=function(){return r(this,arguments)};var u=()=>{t[e]=a};return t[n]={name:e,orig:a,unpatch:u},u}function before(e,t,n){return monkeyPatch(e,t,{before:n})}function instead(e,t,n){return monkeyPatch(e,t,{instead:n})}function after(e,t,n){return monkeyPatch(e,t,{after:n})}module.exports={monkeyPatch:monkeyPatch,before:before,instead:instead,after:after};