Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

emitter-master

Package Overview
Dependencies
Maintainers
1
Versions
23
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

emitter-master - npm Package Compare versions

Comparing version 1.1.0 to 2.0.0-dev.20240226

2

browser/index.js

@@ -1,1 +0,1 @@

var Emitter=function(e){"use strict";let r=0,t=!1;const n={},o={};function p(e){return o[e]??(o[e]=[])}function s(e){return n[e]??(n[e]=[])}function l(e,t){let n=[],o;if("string"==typeof e)o="string",n.push(e);else{if(!Array.isArray(e))throw new Error("错误的参数:"+e);o="array",n=e}if("function"==typeof t){for(let e=0,r=n.length;e<r;e++){var l=n[e],a=s(l);for(let e=0,r=a.length;e<r;e++)"array"===o?t({event_name:l,data:a[e]}):t(a[e]);a.length=0,p(l).push({type:"normal",event_name_type:o,handle:t})}return()=>c(e,t)}for(let e=0,r=n.length;e<r;e++){const i=n[e],f=s(i);if(0!=f.length)return new Promise(e=>{"array"===o?e({event_name:i,data:f.pop()}):e(f.pop())})}return new Promise(e=>e(void 0===t?null:t))}function a(e,t){let n=[];if("string"==typeof e)n.push(e);else{if(!Array.isArray(e))throw new Error("错误的参数:"+e);n=e}for(let e=0,r=n.length;e<r;e++){var o=n[e],l=p(o);if(0===l.length)s(o).push(t);else for(let e=0;e<l.length;e++){var a=l[e];"string"===a.event_name_type?a.handle(t):a.handle({event_name:o,data:t}),"once"===a.type&&(l.splice(e,1),e--)}}}function c(e,r){let t=[];if("string"==typeof e)t.push(e);else{if(!Array.isArray(e))throw new Error("错误的参数:"+e);t=e}var n={offline:!1};if(void 0!==r&&("function"==typeof r?n.callback=r:(void 0!==r.offline&&(n.offline=r.offline),void 0!==r.callback&&(n.callback=r.callback))),void 0===n.callback)for(let e=0,r=t.length;e<r;e++){var o=t[e];n.offline&&(s(o).length=0),p(o).length=0}else for(let e=0,r=t.length;e<r;e++){var l=p(t[e]);for(let e=0;e<l.length;e++)l[e].handle===n.callback&&(l.splice(e,1),e--)}}var i=l,f=a,u=c,i=(console.log("%cemitter-master:%c 1.1.0 %c=> %curl:%c https://www.npmjs.com/package/emitter-master","color: #fff;background: purple;padding: 2px 5px;border-radius:4px;font-size: 14px;","color: purple;font-size:14px;","color: #333;font-size:14px;","background: purple;font-size:14px; padding: 2px 5px; border-radius: 4px; color: #fff;","font-size:14px;"),{get timeout(){return r},set timeout(e){r=e},get debug(){return t},set debug(e){t=e},sender:a,receiver:l,listener:i,once:function(e,t){let n=[],o;if("string"==typeof e)o="string",n.push(e);else{if(!Array.isArray(e))throw new Error("错误的参数:"+e);o="array",n=e}if("function"==typeof t){for(let e=0,r=n.length;e<r;e++){var l=n[e],a=s(l);0===a.length?p(l).push({type:"once",event_name_type:o,handle:t}):"array"===o?t({event_name:l,data:a.pop()}):t(a.pop())}return()=>c(e,t)}for(let e=0;e<n.length;e++){const r=n[e],i=s(r);if(0!==i.length)return new Promise(e=>"array"===o?e({event_name:r,data:i.pop()}):e(i.pop()))}return new Promise(e=>e(void 0===t?null:t))},trigger:f,clear:c,debug_print:function(){console.log("事件缓存--\x3e",o),console.log("离线缓存--\x3e",n)},remove:u});return e.Emitter=i,Object.defineProperty(e,"__esModule",{value:!0}),e}({});
var Emitter=function(e){"use strict";function v(e,t){t=e.indexOf(t);-1!==t&&e.splice(t,1)}let t=0,r=!1,m=(e,t)=>e===t;const a={},n={},s={},o={};function y(){}function _(e){return s[e]??(s[e]=[])}function w(e){return a[e]??(a[e]=[])}function x(e){return o[e]??(o[e]=[])}function E(e){return n[e]??(n[e]=[])}function p(e,r,a){let n=[];if("string"==typeof e)n.push(e);else{if(!Array.isArray(e))throw new Error("错误的参数:"+e);n=e}if(a?.passphrase)for(let e=0,t=n.length;e<t;e++){var s=n[e],o=w(s),p=E(s),l=p.filter(e=>m(e.passphrase,a.passphrase));if(0===l.length){var i={data_type:"sender",start:(new Date).getTime(),passphrase:a.passphrase,data:r};a?.timeout&&(i.timeout=a.timeout),o.push(i)}else for(let e=0;e<l.length;e++){var f=l[e];"string"===f.event_name_type?f.handle(r,y):f.handle({event_name:s,data:r},y),"once"===f.event_type&&v(p,f)}}else for(let e=0,t=n.length;e<t;e++){var h=n[e],c=_(h),u=x(h);if(0===u.length){var d={data_type:"sender",start:(new Date).getTime(),data:r};a?.timeout&&(d.timeout=a.timeout),c.push(d)}else for(let e=0;e<u.length;e++){var g=u[e];"string"===g.event_name_type?g.handle(r,y):g.handle({event_name:h,data:r},y),"once"===g.event_type&&(u.splice(e,1),e--)}}}function l(e,r,a){let n=[],s;if("string"==typeof e)s="string",n.push(e);else{if(!Array.isArray(e))throw new Error("错误的参数:"+e);s="array",n=e}if(a?.passphrase){if("function"==typeof r){for(let e=0;e<n.length;e++){const l=n[e],i=w(l);var t=i.filter(e=>m(a.passphrase,e.passphrase)),o=E(l);0!==t.length&&a?.once||o.push({event_type:a?.once?"once":"normal",event_name_type:s,start:(new Date).getTime(),passphrase:a.passphrase,handle:r}),t.forEach(e=>{var t="array"===s?{event_name:l,data:e.data}:e.data;r(t),v(i,e)})}return()=>A(e,r)}for(let e=0,t=n.length;e<t;e++){const f=n[e];const h=w(f).filter(e=>m(a.passphrase,e.passphrase));if(0!=h.length)return new Promise(e=>{e("array"===s?{event_name:f,data:h.pop().data}:h.pop().data)})}return new Promise(e=>e(void 0===r?null:r))}if("function"==typeof r){for(let e=0;e<n.length;e++){const c=n[e],u=_(c);var p=E(c);0!==u.length&&a?.once||p.push({event_type:a?.once?"once":"normal",event_name_type:s,start:(new Date).getTime(),handle:r}),u.forEach(e=>{var t="array"===s?{event_name:c,data:e.data}:e.data;"sender"===e.data_type?(r(t),v(u,e)):r(e.data,()=>v(u,e))})}return()=>A(e,r)}for(let e=0,t=n.length;e<t;e++){const d=n[e],g=_(d);if(0!=g.length)return new Promise(e=>{var t=g[g.length-1],r="array"===s?{event_name:d,data:t.data}:t.data;"sender"===t.data_type&&v(g,t),e(r)})}return new Promise(e=>e(void 0===r?null:r))}function A(e,r=null,t={clear_data:!1}){let a=[];if("string"==typeof e)a.push(e);else{if(!Array.isArray(e))throw new Error("错误的参数:"+e);a=e}if(null===r)if(t.passphrase)for(let e=0;e<a.length;e++){var n=a[e];if(t.clear_data){var s=w(n);for(let e=0;e<s.length;e++)m(t.passphrase,s[e].passphrase)&&(s.splice(e,1),e--)}var o=E(n);for(let e=0;e<o.length;e++)m(t.passphrase,o[e].passphrase)&&(o.splice(e,1),e--)}else a.forEach(e=>{t.clear_data&&(w(e).length=0),E(e).length=0});else if(t.passphrase)for(let e=0;e<a.length;e++){var p=a[e];if(t.clear_data){var l=w(p);for(let e=0;e<l.length;e++)m(t.passphrase,l[e].passphrase)&&(l.splice(e,1),e--)}var i=E(p);for(let e=0;e<i.length;e++)m(t.passphrase,i[e].passphrase)&&r===i[e].handle&&(i.splice(e,1),e--)}else a.forEach(e=>{var t=x(e);for(let e=0;e<t.length;e++)t[e].handle===r&&(t.splice(e,1),e--)})}var i=l,f=p,h=A,i=(console.log("%cemitter-master:%c 2.0.0-dev.20240226 %c=> %curl:%c https://www.npmjs.com/package/emitter-master","color: #fff;background: purple;padding: 2px 5px;border-radius:4px;font-size: 14px;","color: purple;font-size:14px;","color: #333;font-size:14px;","background: purple;font-size:14px; padding: 2px 5px; border-radius: 4px; color: #fff;","font-size:14px;"),{get timeout(){return t},set timeout(e){t=e},get debug(){return r},set debug(e){r=e},sender:p,receiver:l,forwarder:function(e,r,a){let n=[];if("string"==typeof e)n.push(e);else{if(!Array.isArray(e))throw new Error("错误的参数:"+e);n=e}for(let e=0,t=n.length;e<t;e++){var s=n[e],o=x(s);const i={data_type:"forwarder",start:(new Date).getTime(),data:r},f=(a?.timeout&&(i.timeout=a.timeout),_(s));function p(){var e=f.indexOf(i);-1!==e&&f.splice(e,1)}if(f.push(i),o.length)for(let e=0;e<o.length;e++){var l=o[e];"string"===l.event_name_type?l.handle(r,p):l.handle({event_name:s,data:r},p),"once"===l.event_type&&(o.splice(e,1),e--)}}},listener:i,trigger:f,clear:A,remove:h,custom_passphrase_check:function(e){m=e}});return e.Emitter=i,Object.defineProperty(e,"__esModule",{value:!0}),e}({});

@@ -14,2 +14,19 @@ interface EmitterMasterEventMap {

type ClearFn = () => any;
type SenderOptions = {
passphrase?: any;
timeout?: number;
};
type ForwarderOptions = {
timeout?: number;
};
interface ClearOptions {
clear_data: boolean;
passphrase?: any;
}
declare function custom_passphrase_check(fn: (a: any, b: any) => boolean): void;
declare function sender<const T extends keyof EmitterMasterEventMap | (keyof EmitterMasterEventMap)[]>(event_names: T, // 事件名称或事件名称的数组
data: T extends keyof EmitterMasterEventMap ? EmitterMasterEventMap[T] : EmitterMasterEventMap[T[number]], // 携带的数据
options?: SenderOptions): void;
declare function forwarder<const T extends keyof EmitterMasterEventMap | (keyof EmitterMasterEventMap)[]>(event_names: T, data: T extends keyof EmitterMasterEventMap ? EmitterMasterEventMap[T] : EmitterMasterEventMap[T[number]], options?: ForwarderOptions): void;
declare function receiver<const E extends string>(event_name: E): Promise<null | ReceiverData<E>>;

@@ -21,15 +38,3 @@ declare function receiver<const E extends string>(event_name: E, handle: (arg: ReceiverData<E>) => any): ClearFn;

declare function receiver<const T extends readonly string[], const DefaultType>(event_names: T, default_value: DefaultType): Promise<DefaultType | ReceiverArrData<T>>;
declare function once<const E extends string>(event_name: E): Promise<null | ReceiverData<E>>;
declare function once<const E extends string>(event_name: E, handle: (arg: ReceiverData<E>) => any): ClearFn;
declare function once<const DefaultType, const E extends string>(event_name: E, default_value: DefaultType): Promise<ReceiverData<E> | DefaultType>;
declare function once<const T extends readonly string[]>(event_names: T): Promise<null | ReceiverArrData<T>>;
declare function once<const T extends readonly string[]>(event_names: T, handle: (arg: ReceiverArrData<T>) => any): ClearFn;
declare function once<const T extends readonly string[], const DefaultType>(event_names: T, default_value: DefaultType): Promise<DefaultType | ReceiverArrData<T>>;
declare function sender<T extends keyof EmitterMasterEventMap | (keyof EmitterMasterEventMap)[]>(event_names: T, data: T extends keyof EmitterMasterEventMap ? EmitterMasterEventMap[T] : EmitterMasterEventMap[T[number]]): void;
interface EventConfig {
offline: boolean;
callback?: Function;
}
declare function clear(event_names: string | string[], callback_or_config?: ((arg: any) => any) | EventConfig): void;
declare function debug_print(): void;
declare function clear(event_names: string | string[], handle?: Function | null, options?: ClearOptions): void;
declare const Emitter: {

@@ -40,10 +45,10 @@ timeout: number;

receiver: typeof receiver;
forwarder: typeof forwarder;
listener: typeof receiver;
once: typeof once;
trigger: typeof sender;
clear: typeof clear;
debug_print: typeof debug_print;
remove: typeof clear;
custom_passphrase_check: typeof custom_passphrase_check;
};
export { Emitter, EmitterMasterEventMap };
{
"name": "emitter-master",
"version": "1.1.0",
"version": "2.0.0-dev.20240226",
"description": "Support for offline event emitters, event, listener",

@@ -74,4 +74,7 @@ "main": "./cjs/index.cjs",

"typescript": "^5.1.6",
"vitest": "^1.0.4"
"vitest": "^1.3.1"
},
"dependencies": {
"typescript-treasure": "^0.0.10"
}
}

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc