Research
Security News
Quasar RAT Disguised as an npm Package for Detecting Vulnerabilities in Ethereum Smart Contracts
Socket researchers uncover a malicious npm package posing as a tool for detecting vulnerabilities in Etherium smart contracts.
Prop-based asynchronous event emitter.
npm install --save dot-event
import Emitter from "dot-event"
const emitter = new Emitter()
emitter.on(() => {})
emitter.emit()
Terms | Functions |
---|---|
Emitter | emit , emitAny , emitOn , emitAnyOn |
Subscriber | on , onAny , once , onceEmitted , onceAny , onceAnyEmitted |
Setter | op |
Subscribers and emitters take one, some, or none of these arguments:
Argument type | Description | Emitter | Subscriber |
---|---|---|---|
String | Preposition (before , after ) | ✔ | |
String | Operation | ✔ | ✔ |
String | Props (period-separated ids) | ✔ | ✔ |
Object | Subscription options | ✔ | ✔ |
Function | Subscription listener | ✔ |
All the features together:
// Define operations
emitter.op("create")
// Subscriber
emitter.on(
"before", // Preposition
"create", // Operation
"my.prop.id", // Props
{ x: true } // Subscription options
({ x, y }) => {}, // Subscription listener
)
// Emitter
emitter.emit(
"create", // Operation
"my.prop.id", // Props
{ y: true } // Susbcription options
)
// Emitter shortcut
emitter.create("my.prop.id", { y: true })
Subscription listeners can be asynchronous. Emitters return a promise that resolves once listeners resolve concurrently.
Subscription listeners receive a single object argument. The object contains subscription options and an event
property with extra info.
There are some features we haven't covered, so keep reading...
emitter.on(({ hello }) => {})
emitter.emit({ hello: "world" })
You may define default options from the subscriber as well:
emitter.on(({ hello }) => {}, { hello: "world" })
emitter.emit()
emitter.once(() => {})
emitter.emit() // emits
emitter.emit() // doesn't emit
Fire immediately if previously emitted:
emitter.emit()
emitter.onceEmitted(() => {}) // emits immediately
Subscribe to before or after the main emit:
emitter.on("before", () => {})
emitter.on(() => {})
emitter.on("after", () => {})
emitter.emit()
Any subscriber can use a prop identifier:
emitter.on("hello", () => {})
emitter.emit("hello") // emits
emitter.emit() // doesn't emit
Subscribe to any prop change:
emitter.onAny(() => {})
emitter.emit("hello") // emits
emitter.emit("hello.world") // emits
Subscribe to any prop change within a prop:
emitter.onAny("hello", () => {})
emitter.emit("hello.world") // emits
emitter.emit() // doesn't emit
emitter.onceAny("hello", () => {})
emitter.emit("hello.world") // emits
emitter.emit("hello.world") // doesn't emit
Subscribe to any prop change within a prop, and fire immediately if previously emitted:
emitter.emit("hello.world")
emitter.onceAnyEmitted("hello", () => {}) // emits immediately
An "operation" is another way to segment your events.
Define your operation (only do this once):
emitter.op("create")
Operations add a nifty shortcut function:
emitter.on("create", () => {})
emitter.emit("create") // emits
emitter.create() // emit with shortcut
Build lots of subscribers at once:
emitter.on([
[() => {}],
["hello.world", () => {}],
["create", "hello.world", () => {}],
["after", "create", "hello.world", () => {}],
])
FAQs
Powerful event emitter
The npm package dot-event receives a total of 90 weekly downloads. As such, dot-event popularity was classified as not popular.
We found that dot-event 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 uncover a malicious npm package posing as a tool for detecting vulnerabilities in Etherium smart contracts.
Security News
Research
A supply chain attack on Rspack's npm packages injected cryptomining malware, potentially impacting thousands of developers.
Research
Security News
Socket researchers discovered a malware campaign on npm delivering the Skuld infostealer via typosquatted packages, exposing sensitive data.