
Research
Security News
Malicious PyPI Package Exploits Deezer API for Coordinated Music Piracy
Socket researchers uncovered a malicious PyPI package exploiting Deezer’s API to enable coordinated music piracy through API abuse and C2 server control.
a typed event emitter that provides removal protection, filtering, and inheritance
ts-ev is a typed event emitter that provides removal protection, filtering, and inheritance.
Unlike other typed event emitters, ts-ev includes a mechanism for arbitrarily deep extensions of its Emitter class such that each derived class has full access to its own events.
ts-ev has zero imports, so it should be usable in any context.
Execution Order Guarantees:
.emit()
operates on the currently registered listeners.
Protection:
.off()
will not remove the listener unless it is explicitly specified.Filtering:
export class Emitter<
BaseEvents extends { [event: string]: (...args: any[]) => any },
DerivedEvents extends { [event: string]: (...args: any[]) => any } = {},
> { ... }
BaseEvents:
DerivedEvents:
public [on|prependOn|once|prependOnce]<
Ev extends keyof BaseEvents | keyof DerivedEvents,
Data extends EvData<BaseEvents, DerivedEvents, Ev> = EvData<BaseEvents, DerivedEvents, Ev>
> { ... }
Ev:
Data:
BaseEvents
or DerivedEvents
value.import { Emitter } from "ts-ev";
class Foo<
DerivedEvents extends Emitter.Events.Except<"baseEv1" | "baseEv2">
> extends Emitter<
{
baseEv1: (requires: number, these: string, args: boolean) => any;
baseEv2: () => any;
},
DerivedEvents
> {
constructor() {
super();
setTimeout(() => this.emit("baseEv1", 1, "foo", true), 100);
setTimeout(() => this.emit("baseEv2"), 1000);
// this.emit("derivedEv") // ts error
// this.emit("anythingElse") // ts error
}
}
const foo = new Foo();
// standard on/once/off functionality
await foo.once("baseEv2");
const l = () => console.log("received");
foo.on("baseEv2", l);
foo.off("baseEv2", l);
// or foo.off("baseEv2");
// or foo.off();
// protection
foo.on("baseEv2", l, { protect: true });
foo.off("baseEv2"); // does not remove the above listener
foo.off(); // does not remove the above listener
foo.off("baseEv2", l); // OK
// filtering
// must specify the expected type (extends original type)
foo.on<"baseEv1", [number, "foo", boolean]>(
"baseEv1",
(a, b, c) => console.log(a, b, c), // b is type "foo" (instead of type "string")
{
protect: true,
filter: (data: [number, string, boolean]): data is [number, "foo", boolean] =>
data[1] === "foo",
}
);
// inheritance
class Bar extends Foo<{
derivedEv: (add: "more", events: "to", the: "emitter") => any;
}> {
constructor() {
super();
// can operate on base class events
setTimeout(() => this.emit("baseEv1", 1, "foo", true), 100);
// can operate on events provided to Foo via OtherEvents
setTimeout(() => this.emit("derivedEv", "more", "to", "emitter"), 200);
}
}
const bar = new Bar();
bar.on("baseEv2", () => console.log("receives base class events!"));
bar.on("derivedEv", () => console.log("receives derived class events!"));
0.2.0 (2021-09-15)
| Changes since 0.1.0 | Release Notes | README | | --- | --- | --- |
| Source Code (zip) | Source Code (tar.gz) | | --- | --- |
<a name="0.1.0"></a>
FAQs
a typed event emitter that provides removal protection, filtering, and inheritance
The npm package ts-ev receives a total of 913 weekly downloads. As such, ts-ev popularity was classified as not popular.
We found that ts-ev demonstrated a not healthy version release cadence and project activity because the last version was released a year ago. It has 1 open source maintainer collaborating on the project.
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Research
Security News
Socket researchers uncovered a malicious PyPI package exploiting Deezer’s API to enable coordinated music piracy through API abuse and C2 server control.
Research
The Socket Research Team discovered a malicious npm package, '@ton-wallet/create', stealing cryptocurrency wallet keys from developers and users in the TON ecosystem.
Security News
Newly introduced telemetry in devenv 1.4 sparked a backlash over privacy concerns, leading to the removal of its AI-powered feature after strong community pushback.