Skip to content

Commit

Permalink
Update to package.json and rollup.config
Browse files Browse the repository at this point in the history
rollup.config now has named exports "Emitter", dist/emitter.umd.js is now "main" property in package.json
  • Loading branch information
mdaemon-technologies committed May 13, 2024
1 parent ef8d588 commit 3a8324d
Show file tree
Hide file tree
Showing 9 changed files with 13 additions and 24 deletions.
2 changes: 1 addition & 1 deletion dist/emitter.cjs
Original file line number Diff line number Diff line change
@@ -1 +1 @@
"use strict";const e={string:function(e){return"string"==typeof e},object:function(e){return"object"==typeof e&&null!==e&&!Array.isArray(e)},array:function(e){return Array.isArray(e)},bool:function(e){return"boolean"==typeof e},number:function(e){return"number"==typeof e},func:function(e){return"function"==typeof e},nul:function(e){return null===e},undef:function(e){return void 0===e||void 0===e}};function t(t,n,r,i){this.name=t,this.namespace=n,this.func=r,this.priority=e.number(i)?i:1}function n(n){this.config={},Object.defineProperty(this.config,"maxListeners",{value:n&&"number"==typeof n.maxListeners?n.maxListeners:50,writable:!1,enumerable:!0}),Object.defineProperty(this.config,"maxOnceListeners",{value:n&&"number"==typeof n.maxOnceListeners?n.maxOnceListeners:50,writable:!1,enumerable:!0});const r=[],i=[],s=e=>r.filter((t=>t.name===e)).length>=this.config.maxListeners,o=e=>i.filter((t=>t.name===e)).length>=this.config.maxListeners,a=(e,t)=>{let n=r.length;for(;n;)if(n-=1,r[n].name===e&&r[n].namespace===t)return n;return-1};this.register=(n,i,o,f)=>{if(!n)return;if(void 0!==f&&!e.number(f))throw new Error("priority must be a number");if(e.func(i))if(e.string(o)){const e=o;o=i,i=e}else e.number(o)&&(f=o),o=i,i="all";const u=a(n,i),l=new t(n,i,o,f);-1===u?s(n)?console.warn(`Max listeners reached for event ${n}`):r.push(l):r[u]=l,r.sort(((e,t)=>e.priority===t.priority?0:e.priority<t.priority?1:-1))},this.on=this.register,this.subscribe=this.register,this.once=(e,n,r)=>{if(!e)return;const s=new t(e,"",n,r);o(e)?console.warn(`Max once listeners reached for event ${e}`):i.push(s),i.sort(((e,t)=>e.priority===t.priority?0:e.priority>t.priority?1:-1))},this.onMany=(e,t)=>{t&&Object.keys(t).forEach((n=>{this.on(n,e,t[n])}))},this.unregister=(e,t)=>{if(!e)return;let n=0;if("all"!==(t=t||"all"))n=a(e,t),-1!==n&&r.splice(n,1);else{for(n=r.length;n;)n-=1,r[n].name===e&&"all"===r[n].namespace&&r.splice(n,1);for(n=i.length;n;)n-=1,i[n].name===e&&i.splice(n,1)}},this.off=this.unregister,this.unsubscribe=this.unregister,this.offAll=e=>{let t=r.length;for(;t;)t-=1,r[t].namespace===e&&r.splice(t,1)};this.trigger=(e,t)=>{const n=(e=>{const t=[];for(let n=0,i=r.length;n<i;n+=1)((r[n].name.indexOf("*")>-1||r[n].name.indexOf("?")>-1)&&new RegExp(r[n].name.replace(/\*/g,".*")).test(e)||r[n].name===e)&&t.push(r[n]);return t})(e);for(let r=0,i=n.length;r<i;r+=1)n[r].func(t,e);((e,t)=>{let n=i.length;for(;n;)n-=1,((i[n].name.indexOf("*")>-1||i[n].name.indexOf("?")>-1)&&new RegExp(i[n].name.replace(/\*/g,".*").replace(/\?/g,".")).test(e)||i[n].name===e)&&(i[n].func(t,e),i.splice(n,1))})(e,t)},this.emit=this.trigger,this.publish=this.trigger,this.propagate=(e,t)=>{this.trigger(t,e)},this.isRegistered=(e,t)=>{t=t||"all";let n=r.length;for(;n;)if(n-=1,r[n].namespace===t&&r[n].name===e)return!0;for(n=i.length;n;)if(n-=1,i[n].name===e)return!0;return!1}}n.HIGH_PRIORITY=2,n.NORMAL_PRIORITY=1,n.LOW_PRIORITY=0,module.exports=n;
"use strict";const e={string:function(e){return"string"==typeof e},object:function(e){return"object"==typeof e&&null!==e&&!Array.isArray(e)},array:function(e){return Array.isArray(e)},bool:function(e){return"boolean"==typeof e},number:function(e){return"number"==typeof e},func:function(e){return"function"==typeof e},nul:function(e){return null===e},undef:function(e){return void 0===e||void 0===e}};function n(n,t,r,i){this.name=n,this.namespace=t,this.func=r,this.priority=e.number(i)?i:1}function t(t){this.config={},Object.defineProperty(this.config,"maxListeners",{value:t&&"number"==typeof t.maxListeners?t.maxListeners:50,writable:!1,enumerable:!0}),Object.defineProperty(this.config,"maxOnceListeners",{value:t&&"number"==typeof t.maxOnceListeners?t.maxOnceListeners:50,writable:!1,enumerable:!0});const r=[],i=[],s=e=>r.filter((n=>n.name===e)).length>=this.config.maxListeners,o=e=>i.filter((n=>n.name===e)).length>=this.config.maxListeners,a=(e,n)=>{let t=r.length;for(;t;)if(t-=1,r[t].name===e&&r[t].namespace===n)return t;return-1};this.register=(t,i,o,f)=>{if(!t)return;if(void 0!==f&&!e.number(f))throw new Error("priority must be a number");if(e.func(i))if(e.string(o)){const e=o;o=i,i=e}else e.number(o)&&(f=o),o=i,i="all";const u=a(t,i),l=new n(t,i,o,f);-1===u?s(t)?console.warn(`Max listeners reached for event ${t}`):r.push(l):r[u]=l,r.sort(((e,n)=>e.priority===n.priority?0:e.priority<n.priority?1:-1))},this.on=this.register,this.subscribe=this.register,this.once=(e,t)=>{if(!e)return;const r=new n(e,"",t);o(e)?console.warn(`Max once listeners reached for event ${e}`):i.push(r)},this.onMany=(e,n)=>{n&&Object.keys(n).forEach((t=>{this.on(t,e,n[t])}))},this.unregister=(e,n)=>{if(!e)return;let t=0;if("all"!==(n=n||"all"))t=a(e,n),-1!==t&&r.splice(t,1);else{for(t=r.length;t;)t-=1,r[t].name===e&&"all"===r[t].namespace&&r.splice(t,1);for(t=i.length;t;)t-=1,i[t].name===e&&i.splice(t,1)}},this.off=this.unregister,this.unsubscribe=this.unregister,this.offAll=e=>{let n=r.length;for(;n;)n-=1,r[n].namespace===e&&r.splice(n,1)};this.trigger=(e,n)=>{const t=(e=>{const n=[];for(let t=0,i=r.length;t<i;t+=1)((r[t].name.indexOf("*")>-1||r[t].name.indexOf("?")>-1)&&new RegExp(r[t].name.replace(/\*/g,".*")).test(e)||r[t].name===e)&&n.push(r[t]);return n})(e);for(let r=0,i=t.length;r<i;r+=1)t[r].func(n,e);((e,n)=>{let t=i.length;for(;t;)t-=1,((i[t].name.indexOf("*")>-1||i[t].name.indexOf("?")>-1)&&new RegExp(i[t].name.replace(/\*/g,".*").replace(/\?/g,".")).test(e)||i[t].name===e)&&(i[t].func(n,e),i.splice(t,1))})(e,n)},this.emit=this.trigger,this.publish=this.trigger,this.propagate=(e,n)=>{this.trigger(n,e)},this.isRegistered=(e,n)=>{n=n||"all";let t=r.length;for(;t;)if(t-=1,r[t].namespace===n&&r[t].name===e)return!0;for(t=i.length;t;)if(t-=1,i[t].name===e)return!0;return!1}}t.HIGH_PRIORITY=2,t.NORMAL_PRIORITY=1,t.LOW_PRIORITY=0,module.exports=t;
1 change: 0 additions & 1 deletion dist/emitter.cjs.d.ts
Original file line number Diff line number Diff line change
@@ -1 +0,0 @@
declare module '@mdaemon/emitter/dist/emitter.cjs';
2 changes: 1 addition & 1 deletion dist/emitter.mjs
Original file line number Diff line number Diff line change
@@ -1 +1 @@
const e={string:function(e){return"string"==typeof e},object:function(e){return"object"==typeof e&&null!==e&&!Array.isArray(e)},array:function(e){return Array.isArray(e)},bool:function(e){return"boolean"==typeof e},number:function(e){return"number"==typeof e},func:function(e){return"function"==typeof e},nul:function(e){return null===e},undef:function(e){return void 0===e||void 0===e}};function t(t,n,r,i){this.name=t,this.namespace=n,this.func=r,this.priority=e.number(i)?i:1}function n(n){this.config={},Object.defineProperty(this.config,"maxListeners",{value:n&&"number"==typeof n.maxListeners?n.maxListeners:50,writable:!1,enumerable:!0}),Object.defineProperty(this.config,"maxOnceListeners",{value:n&&"number"==typeof n.maxOnceListeners?n.maxOnceListeners:50,writable:!1,enumerable:!0});const r=[],i=[],s=e=>r.filter((t=>t.name===e)).length>=this.config.maxListeners,o=e=>i.filter((t=>t.name===e)).length>=this.config.maxListeners,a=(e,t)=>{let n=r.length;for(;n;)if(n-=1,r[n].name===e&&r[n].namespace===t)return n;return-1};this.register=(n,i,o,f)=>{if(!n)return;if(void 0!==f&&!e.number(f))throw new Error("priority must be a number");if(e.func(i))if(e.string(o)){const e=o;o=i,i=e}else e.number(o)&&(f=o),o=i,i="all";const l=a(n,i),u=new t(n,i,o,f);-1===l?s(n)?console.warn(`Max listeners reached for event ${n}`):r.push(u):r[l]=u,r.sort(((e,t)=>e.priority===t.priority?0:e.priority<t.priority?1:-1))},this.on=this.register,this.subscribe=this.register,this.once=(e,n,r)=>{if(!e)return;const s=new t(e,"",n,r);o(e)?console.warn(`Max once listeners reached for event ${e}`):i.push(s),i.sort(((e,t)=>e.priority===t.priority?0:e.priority>t.priority?1:-1))},this.onMany=(e,t)=>{t&&Object.keys(t).forEach((n=>{this.on(n,e,t[n])}))},this.unregister=(e,t)=>{if(!e)return;let n=0;if("all"!==(t=t||"all"))n=a(e,t),-1!==n&&r.splice(n,1);else{for(n=r.length;n;)n-=1,r[n].name===e&&"all"===r[n].namespace&&r.splice(n,1);for(n=i.length;n;)n-=1,i[n].name===e&&i.splice(n,1)}},this.off=this.unregister,this.unsubscribe=this.unregister,this.offAll=e=>{let t=r.length;for(;t;)t-=1,r[t].namespace===e&&r.splice(t,1)};this.trigger=(e,t)=>{const n=(e=>{const t=[];for(let n=0,i=r.length;n<i;n+=1)((r[n].name.indexOf("*")>-1||r[n].name.indexOf("?")>-1)&&new RegExp(r[n].name.replace(/\*/g,".*")).test(e)||r[n].name===e)&&t.push(r[n]);return t})(e);for(let r=0,i=n.length;r<i;r+=1)n[r].func(t,e);((e,t)=>{let n=i.length;for(;n;)n-=1,((i[n].name.indexOf("*")>-1||i[n].name.indexOf("?")>-1)&&new RegExp(i[n].name.replace(/\*/g,".*").replace(/\?/g,".")).test(e)||i[n].name===e)&&(i[n].func(t,e),i.splice(n,1))})(e,t)},this.emit=this.trigger,this.publish=this.trigger,this.propagate=(e,t)=>{this.trigger(t,e)},this.isRegistered=(e,t)=>{t=t||"all";let n=r.length;for(;n;)if(n-=1,r[n].namespace===t&&r[n].name===e)return!0;for(n=i.length;n;)if(n-=1,i[n].name===e)return!0;return!1}}n.HIGH_PRIORITY=2,n.NORMAL_PRIORITY=1,n.LOW_PRIORITY=0;export{n as default};
const e={string:function(e){return"string"==typeof e},object:function(e){return"object"==typeof e&&null!==e&&!Array.isArray(e)},array:function(e){return Array.isArray(e)},bool:function(e){return"boolean"==typeof e},number:function(e){return"number"==typeof e},func:function(e){return"function"==typeof e},nul:function(e){return null===e},undef:function(e){return void 0===e||void 0===e}};function n(n,t,r,i){this.name=n,this.namespace=t,this.func=r,this.priority=e.number(i)?i:1}function t(t){this.config={},Object.defineProperty(this.config,"maxListeners",{value:t&&"number"==typeof t.maxListeners?t.maxListeners:50,writable:!1,enumerable:!0}),Object.defineProperty(this.config,"maxOnceListeners",{value:t&&"number"==typeof t.maxOnceListeners?t.maxOnceListeners:50,writable:!1,enumerable:!0});const r=[],i=[],s=e=>r.filter((n=>n.name===e)).length>=this.config.maxListeners,o=e=>i.filter((n=>n.name===e)).length>=this.config.maxListeners,a=(e,n)=>{let t=r.length;for(;t;)if(t-=1,r[t].name===e&&r[t].namespace===n)return t;return-1};this.register=(t,i,o,f)=>{if(!t)return;if(void 0!==f&&!e.number(f))throw new Error("priority must be a number");if(e.func(i))if(e.string(o)){const e=o;o=i,i=e}else e.number(o)&&(f=o),o=i,i="all";const l=a(t,i),u=new n(t,i,o,f);-1===l?s(t)?console.warn(`Max listeners reached for event ${t}`):r.push(u):r[l]=u,r.sort(((e,n)=>e.priority===n.priority?0:e.priority<n.priority?1:-1))},this.on=this.register,this.subscribe=this.register,this.once=(e,t)=>{if(!e)return;const r=new n(e,"",t);o(e)?console.warn(`Max once listeners reached for event ${e}`):i.push(r)},this.onMany=(e,n)=>{n&&Object.keys(n).forEach((t=>{this.on(t,e,n[t])}))},this.unregister=(e,n)=>{if(!e)return;let t=0;if("all"!==(n=n||"all"))t=a(e,n),-1!==t&&r.splice(t,1);else{for(t=r.length;t;)t-=1,r[t].name===e&&"all"===r[t].namespace&&r.splice(t,1);for(t=i.length;t;)t-=1,i[t].name===e&&i.splice(t,1)}},this.off=this.unregister,this.unsubscribe=this.unregister,this.offAll=e=>{let n=r.length;for(;n;)n-=1,r[n].namespace===e&&r.splice(n,1)};this.trigger=(e,n)=>{const t=(e=>{const n=[];for(let t=0,i=r.length;t<i;t+=1)((r[t].name.indexOf("*")>-1||r[t].name.indexOf("?")>-1)&&new RegExp(r[t].name.replace(/\*/g,".*")).test(e)||r[t].name===e)&&n.push(r[t]);return n})(e);for(let r=0,i=t.length;r<i;r+=1)t[r].func(n,e);((e,n)=>{let t=i.length;for(;t;)t-=1,((i[t].name.indexOf("*")>-1||i[t].name.indexOf("?")>-1)&&new RegExp(i[t].name.replace(/\*/g,".*").replace(/\?/g,".")).test(e)||i[t].name===e)&&(i[t].func(n,e),i.splice(t,1))})(e,n)},this.emit=this.trigger,this.publish=this.trigger,this.propagate=(e,n)=>{this.trigger(n,e)},this.isRegistered=(e,n)=>{n=n||"all";let t=r.length;for(;t;)if(t-=1,r[t].namespace===n&&r[t].name===e)return!0;for(t=i.length;t;)if(t-=1,i[t].name===e)return!0;return!1}}t.HIGH_PRIORITY=2,t.NORMAL_PRIORITY=1,t.LOW_PRIORITY=0;export{t as default};
2 changes: 1 addition & 1 deletion dist/emitter.mjs.d.ts
Original file line number Diff line number Diff line change
@@ -1 +1 @@
declare module '@mdaemon/emitter/dist/emitter.mjs';
declare module '@mdaemon/emitter/dist/emitter.mjs'
2 changes: 1 addition & 1 deletion dist/emitter.umd.d.ts
Original file line number Diff line number Diff line change
@@ -1 +1 @@
declare module '@mdaemon/emitter/dist/emitter.umd.js';
declare module '@mdaemon/emitter/dist/emitter.umd.js'
2 changes: 1 addition & 1 deletion dist/emitter.umd.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion dist/index.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,4 +15,4 @@ declare class Emitter {
publish(name: string, data?: any): void;
propagate(data: any, name: string): void;
isRegistered(name: string, namespace: string): boolean;
}
}
5 changes: 3 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,11 +1,12 @@
{
"name": "@mdaemon/emitter",
"type": "module",
"version": "1.3.0",
"version": "1.3.1",
"description": "A basic event emitter / publish subscribe library used by MDaemon Webmail",
"main": "dist/emitter.cjs",
"main": "dist/emitter.umd.js",
"module": "dist/emitter.mjs",
"browser": "dist/emitter.umd.js",
"common": "dist/emitter.cjs",
"typings": "dist/index.d.ts",
"publishConfig": {
"access": "public"
Expand Down
19 changes: 4 additions & 15 deletions rollup.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,26 +3,15 @@ import terser from '@rollup/plugin-terser';
import pkg from './package.json';

export default [
// browser-friendly UMD build
{
input: 'src/emitter.js',
output: {
name: 'emitter',
file: pkg.browser,
format: 'umd'
},
plugins: [
commonjs(),
terser()
]
},
{
input: 'src/emitter.js',
output: [
{ file: pkg.main, format: 'cjs', exports: "default" },
{ file: pkg.module, format: 'es', exports: "default" }
{ file: pkg.main, format: 'umd', exports: "default", name: "Emitter" },
{ file: pkg.common, format: 'cjs', exports: "default", name: "Emitter" },
{ file: pkg.module, format: 'es', exports: "default", name: "Emitter" }
],
plugins: [
commonjs(),
terser()
]
},
Expand Down

0 comments on commit 3a8324d

Please sign in to comment.