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