Security News
UK Officials Consider Banning Ransomware Payments from Public Entities
The UK is proposing a bold ban on ransomware payments by public entities to disrupt cybercrime, protect critical services, and lead global cybersecurity efforts.
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 8 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.
Security News
The UK is proposing a bold ban on ransomware payments by public entities to disrupt cybercrime, protect critical services, and lead global cybersecurity efforts.
Security News
Snyk's use of malicious npm packages for research raises ethical concerns, highlighting risks in public deployment, data exfiltration, and unauthorized testing.
Research
Security News
Socket researchers found several malicious npm packages typosquatting Chalk and Chokidar, targeting Node.js developers with kill switches and data theft.