event-mitter-js
Version:
A tiny (less than 1k) event emitter library.
11 lines (10 loc) • 10 kB
JavaScript
/*!
* event-mitter-js v0.0.3
* (c) 2020-2021 qiutian00
* Released under the MIT License.
*/
;Object.defineProperty(exports,"__esModule",{value:!0});var t=function(t){try{return!!t()}catch(t){return!0}},n=!t((function(){var t=function(){}.bind();return"function"!=typeof t||t.hasOwnProperty("prototype")})),r=n,e=Function.prototype,o=e.call,i=r&&e.bind.bind(o,o),u=r?i:function(t){return function(){return o.apply(t,arguments)}},c=u,f=c({}.isPrototypeOf),a="undefined"!=typeof globalThis?globalThis:"undefined"!=typeof window?window:"undefined"!=typeof global?global:"undefined"!=typeof self?self:{};var l,p,s=function(t){return t&&t.Math==Math&&t},y=s("object"==typeof globalThis&&globalThis)||s("object"==typeof window&&window)||s("object"==typeof self&&self)||s("object"==typeof a&&a)||function(){return this}()||Function("return this")(),h=Function.prototype,b=h.apply,v=h.call,d="object"==typeof Reflect&&Reflect.apply||(r?v.bind(b):function(){return v.apply(b,arguments)}),g=c({}.toString),m=c("".slice),w=function(t){return m(g(t),8,-1)},j="object"==typeof document&&document.all,S={all:j,IS_HTMLDDA:void 0===j&&void 0!==j},O=S.all,P=S.IS_HTMLDDA?function(t){return"function"==typeof t||t===O}:function(t){return"function"==typeof t},T=!t((function(){return 7!=Object.defineProperty({},1,{get:function(){return 7}})[1]})),A=Function.prototype.call,E=r?A.bind(A):function(){return A.apply(A,arguments)},M={}.propertyIsEnumerable,x=Object.getOwnPropertyDescriptor,_={f:x&&!M.call({1:2},1)?function(t){var n=x(this,t);return!!n&&n.enumerable}:M},D=Object,F=c("".split),I=t((function(){return!D("z").propertyIsEnumerable(0)}))?function(t){return"String"==w(t)?F(t,""):D(t)}:D,L=function(t){return null==t},z=TypeError,C=I,k=function(t){if(L(t))throw z("Can't call method on "+t);return t},N=P,G=S.all,H=S.IS_HTMLDDA?function(t){return"object"==typeof t?null!==t:N(t)||t===G}:function(t){return"object"==typeof t?null!==t:N(t)},R={},q=y,B=function(t){return N(t)?t:void 0},U="undefined"!=typeof navigator&&String(navigator.userAgent)||"",V=q.process,Y=q.Deno,J=V&&V.versions||Y&&Y.version,K=J&&J.v8;K&&(p=(l=K.split("."))[0]>0&&l[0]<4?1:+(l[0]+l[1])),!p&&U&&(!(l=U.match(/Edge\/(\d+)/))||l[1]>=74)&&(l=U.match(/Chrome\/(\d+)/))&&(p=+l[1]);var Q,W,X,Z=p,$=!!Object.getOwnPropertySymbols&&!t((function(){var t=Symbol();return!String(t)||!(Object(t)instanceof Symbol)||!Symbol.sham&&Z&&Z<41})),tt=$&&!Symbol.sham&&"symbol"==typeof Symbol.iterator,nt=function(t,n){return arguments.length<2?B(R[t])||B(q[t]):R[t]&&R[t][n]||q[t]&&q[t][n]},rt=f,et=tt,ot=Object,it=et?function(t){return"symbol"==typeof t}:function(t){var n=nt("Symbol");return N(n)&&rt(n.prototype,ot(t))},ut=String,ct=function(t){try{return ut(t)}catch(t){return"Object"}},ft=TypeError,at=function(t){if(N(t))return t;throw ft(ct(t)+" is not a function")},lt=E,pt=H,st=TypeError,yt=Object.defineProperty,ht=function(t,n){try{yt(q,t,{value:n,configurable:!0,writable:!0})}catch(r){q[t]=n}return n},bt="__core-js_shared__",vt=q[bt]||ht(bt,{}),dt=vt,gt=(Q=function(t){(t.exports=function(t,n){return dt[t]||(dt[t]=void 0!==n?n:{})})("versions",[]).push({version:"3.27.2",mode:"pure",copyright:"© 2014-2023 Denis Pushkarev (zloirock.ru)",license:"https://github.com/zloirock/core-js/blob/v3.27.2/LICENSE",source:"https://github.com/zloirock/core-js"})},Q(X={path:W,exports:{},require:function(t,n){return function(){throw new Error("Dynamic requires are not currently supported by @rollup/plugin-commonjs")}(null==n&&X.path)}},X.exports),X.exports),mt=Object,wt=function(t){return mt(k(t))},jt=c({}.hasOwnProperty),St=Object.hasOwn||function(t,n){return jt(wt(t),n)},Ot=0,Pt=Math.random(),Tt=c(1..toString),At=gt,Et=St,Mt=function(t){return"Symbol("+(void 0===t?"":t)+")_"+Tt(++Ot+Pt,36)},xt=q.Symbol,_t=At("wks"),Dt=et?xt.for||xt:xt&&xt.withoutSetter||Mt,Ft=it,It=function(t,n){var r=t[n];return L(r)?void 0:at(r)},Lt=function(t,n){var r,e;if("string"===n&&N(r=t.toString)&&!pt(e=lt(r,t)))return e;if(N(r=t.valueOf)&&!pt(e=lt(r,t)))return e;if("string"!==n&&N(r=t.toString)&&!pt(e=lt(r,t)))return e;throw st("Can't convert object to primitive value")},zt=function(t){return Et(_t,t)||(_t[t]=$&&Et(xt,t)?xt[t]:Dt("Symbol."+t)),_t[t]},Ct=TypeError,kt=zt("toPrimitive"),Nt=function(t,n){if(!pt(t)||Ft(t))return t;var r,e=It(t,kt);if(e){if(void 0===n&&(n="default"),r=lt(e,t,n),!pt(r)||Ft(r))return r;throw Ct("Can't convert object to primitive value")}return void 0===n&&(n="number"),Lt(t,n)},Gt=q.document,Ht=pt(Gt)&&pt(Gt.createElement),Rt=T,qt=function(t){return Ht?Gt.createElement(t):{}},Bt=!Rt&&!t((function(){return 7!=Object.defineProperty(qt("div"),"a",{get:function(){return 7}}).a})),Ut=_,Vt=function(t,n){return{enumerable:!(1&t),configurable:!(2&t),writable:!(4&t),value:n}},Yt=function(t){return C(k(t))},Jt=function(t){var n=Nt(t,"string");return Ft(n)?n:n+""},Kt=Bt,Qt=Object.getOwnPropertyDescriptor,Wt={f:Rt?Qt:function(t,n){if(t=Yt(t),n=Jt(n),Kt)try{return Qt(t,n)}catch(t){}if(Et(t,n))return Vt(!lt(Ut.f,t,n),t[n])}},Xt=/#|\.prototype\./,Zt=function(n,r){var e=tn[$t(n)];return e==rn||e!=nn&&(N(r)?t(r):!!r)},$t=Zt.normalize=function(t){return String(t).replace(Xt,".").toLowerCase()},tn=Zt.data={},nn=Zt.NATIVE="N",rn=Zt.POLYFILL="P",en=Zt,on=function(t){if("Function"===w(t))return c(t)},un=on(on.bind),cn=Rt&&t((function(){return 42!=Object.defineProperty((function(){}),"prototype",{value:42,writable:!1}).prototype})),fn=String,an=TypeError,ln=cn,pn=function(t){if(pt(t))return t;throw an(fn(t)+" is not an object")},sn=TypeError,yn=Object.defineProperty,hn=Object.getOwnPropertyDescriptor,bn="enumerable",vn="configurable",dn="writable",gn={f:Rt?ln?function(t,n,r){if(pn(t),n=Jt(n),pn(r),"function"==typeof t&&"prototype"===n&&"value"in r&&dn in r&&!r[dn]){var e=hn(t,n);e&&e[dn]&&(t[n]=r.value,r={configurable:vn in r?r[vn]:e[vn],enumerable:bn in r?r[bn]:e[bn],writable:!1})}return yn(t,n,r)}:yn:function(t,n,r){if(pn(t),n=Jt(n),pn(r),Kt)try{return yn(t,n,r)}catch(t){}if("get"in r||"set"in r)throw sn("Accessors not supported");return"value"in r&&(t[n]=r.value),t}},mn=d,wn=en,jn=function(t,n){return at(t),void 0===n?t:r?un(t,n):function(){return t.apply(n,arguments)}},Sn=Rt?function(t,n,r){return gn.f(t,n,Vt(1,r))}:function(t,n,r){return t[n]=r,t},On=Wt.f,Pn=function(t){var n=function(r,e,o){if(this instanceof n){switch(arguments.length){case 0:return new t;case 1:return new t(r);case 2:return new t(r,e)}return new t(r,e,o)}return mn(t,this,arguments)};return n.prototype=t.prototype,n},Tn=Array.isArray||function(t){return"Array"==w(t)},An={};An[zt("toStringTag")]="z";var En="[object z]"===String(An),Mn=zt("toStringTag"),xn=Object,_n="Arguments"==w(function(){return arguments}()),Dn=En?w:function(t){var n,r,e;return void 0===t?"Undefined":null===t?"Null":"string"==typeof(r=function(t,n){try{return t[n]}catch(t){}}(n=xn(t),Mn))?r:_n?w(n):"Object"==(e=w(n))&&N(n.callee)?"Arguments":e},Fn=c(Function.toString);N(dt.inspectSource)||(dt.inspectSource=function(t){return Fn(t)});var In=dt.inspectSource,Ln=Dn,zn=In,Cn=function(){},kn=[],Nn=nt("Reflect","construct"),Gn=/^\s*(?:class|function)\b/,Hn=c(Gn.exec),Rn=!Gn.exec(Cn),qn=function(t){if(!N(t))return!1;try{return Nn(Cn,kn,t),!0}catch(t){return!1}},Bn=function(t){if(!N(t))return!1;switch(Ln(t)){case"AsyncFunction":case"GeneratorFunction":case"AsyncGeneratorFunction":return!1}try{return Rn||!!Hn(Gn,zn(t))}catch(t){return!0}};Bn.sham=!0;var Un=!Nn||t((function(){var t;return qn(qn.call)||!qn(Object)||!qn((function(){t=!0}))||t}))?Bn:qn,Vn=Math.ceil,Yn=Math.floor,Jn=Math.trunc||function(t){var n=+t;return(n>0?Yn:Vn)(n)},Kn=function(t){var n=+t;return n!=n||0===n?0:Jn(n)},Qn=Math.max,Wn=Math.min,Xn=Math.min,Zn=function(t){return t>0?Xn(Kn(t),9007199254740991):0},$n=zt("species"),tr=c([].slice),nr=function(t,n){var r,e,o,i,u,c,f,a,l,p=t.target,s=t.global,y=t.stat,h=t.proto,b=s?q:y?q[p]:(q[p]||{}).prototype,v=s?R:R[p]||Sn(R,p,{})[p],d=v.prototype;for(i in n)e=!(r=wn(s?i:p+(y?".":"#")+i,t.forced))&&b&&Et(b,i),c=v[i],e&&(f=t.dontCallGetSet?(l=On(b,i))&&l.value:b[i]),u=e&&f?f:n[i],e&&typeof c==typeof u||(a=t.bind&&e?jn(u,q):t.wrap&&e?Pn(u):h&&N(u)?on(u):u,(t.sham||u&&u.sham||c&&c.sham)&&Sn(a,"sham",!0),Sn(v,i,a),h&&(Et(R,o=p+"Prototype")||Sn(R,o,{}),Sn(R[o],i,u),t.real&&d&&(r||!d[i])&&Sn(d,i,u)))},rr=Tn,er=Un,or=function(t,n){var r=Kn(t);return r<0?Qn(r+n,0):Wn(r,n)},ir=function(t){return Zn(t.length)},ur=function(t,n,r){var e=Jt(n);e in t?gn.f(t,e,Vt(0,r)):t[e]=r},cr=tr,fr=function(n){return Z>=51||!t((function(){var t=[];return(t.constructor={})[$n]=function(){return{foo:1}},1!==t[n](Boolean).foo}))}("slice"),ar=zt("species"),lr=Array,pr=Math.max;nr({target:"Array",proto:!0,forced:!fr},{slice:function(t,n){var r,e,o,i=Yt(this),u=ir(i),c=or(t,u),f=or(void 0===n?u:n,u);if(rr(i)&&(r=i.constructor,(er(r)&&(r===lr||rr(r.prototype))||pt(r)&&null===(r=r[ar]))&&(r=void 0),r===lr||void 0===r))return cr(i,c,f);for(e=new(void 0===r?lr:r)(pr(f-c,0)),o=0;c<f;c++,o++)c in i&&ur(e,o,i[c]);return e.length=o,e}});var sr=function(t){return R[t+"Prototype"]}("Array").slice,yr=Array.prototype,hr=function(t){var n=t.slice;return t===yr||rt(yr,t)&&n===yr.slice?sr:n};function br(){
// (via https://github.com/lipsmack from https://github.com/qiutian00/event-mitter-js/issues/3)
}br.prototype={on:function(t,n,r){var e=this.e||(this.e={});return(e[t]||(e[t]=[])).push({fn:n,ctx:r}),this},once:function(t,n,r){var e=this;function o(){e.off(t,o),n.apply(r,arguments)}return o._=n,this.on(t,o,r)},emit:function(t){for(var n,r=hr([]).call(arguments,1),e=hr(n=(this.e||(this.e={}))[t]||[]).call(n),o=0,i=e.length;o<i;o++)e[o].fn.apply(e[o].ctx,r);return this},off:function(t,n){var r=this.e||(this.e={}),e=r[t],o=[];if(e&&n)for(var i=0,u=e.length;i<u;i++)e[i].fn!==n&&e[i].fn._!==n&&o.push(e[i]);
// Ref: https://github.com/qiutian00/event-mitter-js/commit/c6ebfaa9bc973b33d110a84a307742b7cf94c953#commitcomment-5024910
return o.length?r[t]=o:delete r[t],this}};var vr=br,dr=br;vr.TinyEmitter=dr,exports.TinyEmitter=dr,exports.default=vr;