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

oberknecht-emitters

Package Overview
Dependencies
Maintainers
1
Versions
28
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

oberknecht-emitters - npm Package Compare versions

Comparing version 1.0.2 to 1.0.3

lib-js/types/oberknecht.emitter.options.d.ts

6

lib-js/emitters/oberknecht.emitter.d.ts

@@ -0,5 +1,7 @@

import { oberknechtEmitterOptions } from "../types/oberknecht.emitter.options";
export declare class oberknechtEmitter {
#private;
get symbol(): string;
constructor();
get _options(): oberknechtEmitterOptions;
constructor(options: oberknechtEmitterOptions);
on: (eventName: string | string[], callback: Function) => void;

@@ -12,4 +14,4 @@ addListener: (eventName: string | string[], callback: Function) => void;

emit: (eventName: string | string[], args: any) => void;
emitError: (eventName: string | string[], error: any) => void;
emitError: (eventName: string | string[], error: Error | Record<string, any> | any) => void;
destroy: () => void;
}

@@ -9,10 +9,15 @@ "use strict";

#symbol = `oberknechtEmitter-${clientSymNum++}`;
get symbol() { return this.#symbol; }
;
constructor() {
get symbol() {
return this.#symbol;
}
get _options() {
return __1.i.emitterData[this.symbol]._options;
}
constructor(options) {
let _options = options ?? {};
__1.i.emitterData[this.symbol] = {
"events": {}
events: {},
_options: _options,
};
}
;
on = (eventName, callback) => {

@@ -30,3 +35,3 @@ let eventName_ = (0, oberknecht_utils_1.convertToArray)(eventName);

const onceCallback = (args) => {
eventName_.forEach(a => {
eventName_.forEach((a) => {
this.removeListener(a, onceCallback);

@@ -53,9 +58,9 @@ });

let eventName_ = (0, oberknecht_utils_1.convertToArray)(eventName);
eventName_.forEach(a => {
[...eventName_, "_all"].forEach((a) => {
this.getListeners(a).forEach((callback) => {
callback(args ?? undefined);
if (this._options.withNames)
callback(a, args ?? undefined);
else
callback(args ?? undefined);
});
this.getListeners("_all").forEach((callback) => {
callback(args ?? undefined);
});
});

@@ -67,12 +72,13 @@ };

return;
if (this.getListeners("error").length === 0 && this.getListeners("unhandledRejection").length === 0) {
if (this.getListeners("error").length === 0 &&
this.getListeners("unhandledRejection").length === 0) {
// process.emitWarning((error?.error?.message ?? error.error ?? error?.message ?? error));
}
;
this.emit(["error"].concat(eventName), (error instanceof Error ? Error("Oida", { "cause": error }) : Error((error?.error?.message ?? error?.error ?? error?.message ?? error))));
this.emit(["error"].concat(eventName), error instanceof Error
? Error("Oida", { cause: error })
: Error((0, oberknecht_utils_1.returnErr)(error)));
}
catch (e) {
console.error(Error(`Oida 2`, { "cause": error }));
console.error(Error(`Oida 2`, { cause: error }));
}
;
};

@@ -84,2 +90,1 @@ destroy = () => {

exports.oberknechtEmitter = oberknechtEmitter;
;

@@ -7,3 +7,3 @@ import { expectedEventName as expectedEventName_ } from "oberknecht-utils";

export class oberknechtActionEmitter {
#symbol: string = `oberknechtActionEmitter-${clientSymNum++}`;
readonly #symbol: string = `oberknechtActionEmitter-${clientSymNum++}`;
get symbol() { return this.#symbol };

@@ -10,0 +10,0 @@

@@ -1,20 +0,30 @@

import { convertToArray } from "oberknecht-utils";
import { convertToArray, returnErr } from "oberknecht-utils";
import { i } from "..";
import { oberknechtEmitterOptions } from "../types/oberknecht.emitter.options";
let clientSymNum = 0;
export class oberknechtEmitter {
#symbol: string = `oberknechtEmitter-${clientSymNum++}`;
get symbol() { return this.#symbol };
readonly #symbol: string = `oberknechtEmitter-${clientSymNum++}`;
get symbol() {
return this.#symbol;
}
constructor() {
get _options(): oberknechtEmitterOptions {
return i.emitterData[this.symbol]._options;
}
constructor(options: oberknechtEmitterOptions) {
let _options = options ?? {};
i.emitterData[this.symbol] = {
"events": {}
events: {},
_options: _options,
};
};
}
on = (eventName: string | string[], callback: Function) => {
let eventName_ = convertToArray(eventName)
let eventName_ = convertToArray(eventName);
eventName_.forEach((eventName2) => {
if (!i.emitterData[this.symbol].events[eventName2]) i.emitterData[this.symbol].events[eventName2] = [];
if (!i.emitterData[this.symbol].events[eventName2])
i.emitterData[this.symbol].events[eventName2] = [];

@@ -31,3 +41,3 @@ i.emitterData[this.symbol].events[eventName2].push(callback);

const onceCallback = (args) => {
eventName_.forEach(a => {
eventName_.forEach((a) => {
this.removeListener(a, onceCallback);

@@ -45,5 +55,5 @@ });

i.emitterData[this.symbol].events[eventName] = i.emitterData[this.symbol].events[eventName].filter(
(cb) => cb !== callback
);
i.emitterData[this.symbol].events[eventName] = i.emitterData[
this.symbol
].events[eventName].filter((cb: Function) => cb !== callback);
};

@@ -64,22 +74,31 @@

eventName_.forEach(a => {
this.getListeners(a).forEach((callback) => {
callback(args ?? undefined);
[...eventName_, "_all"].forEach((a) => {
this.getListeners(a).forEach((callback: Function) => {
if (this._options.withNames) callback(a, args ?? undefined);
else callback(args ?? undefined);
});
this.getListeners("_all").forEach((callback) => {
callback(args ?? undefined);
})
});
};
emitError = (eventName: string | string[], error) => {
emitError = (
eventName: string | string[],
error: Error | Record<string, any> | any
) => {
try {
if (!error) return;
if (this.getListeners("error").length === 0 && this.getListeners("unhandledRejection").length === 0) {
if (
this.getListeners("error").length === 0 &&
this.getListeners("unhandledRejection").length === 0
) {
// process.emitWarning((error?.error?.message ?? error.error ?? error?.message ?? error));
};
this.emit(["error"].concat(eventName), (error instanceof Error ? Error("Oida", { "cause": error }) : Error((error?.error?.message ?? error?.error ?? error?.message ?? error))));
}
this.emit(
["error"].concat(eventName),
error instanceof Error
? Error("Oida", { cause: error })
: Error(returnErr(error))
);
} catch (e) {
console.error(Error(`Oida 2`, { "cause": error }));
};
console.error(Error(`Oida 2`, { cause: error }));
}
};

@@ -90,2 +109,2 @@

};
};
}
{
"name": "oberknecht-emitters",
"version": "1.0.2",
"version": "1.0.3",
"description": "",

@@ -5,0 +5,0 @@ "main": "export",

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