Security News
pnpm 10.0.0 Blocks Lifecycle Scripts by Default
pnpm 10 blocks lifecycle scripts by default to improve security, addressing supply chain attack risks but sparking debate over compatibility and workflow changes.
Build beautiful and extensible eventing APIs.
npm install --save dot-event
Part of the beauty of the dot-event
API is that it can shrink down to incredibly simple functionality.
Here we have the simplest possible subscriber and emitter:
import Events from "dot-event"
const events = new Events()
events.on(() => {})
events.emit()
Subscription listeners can be asynchronous:
events.on(async () => {})
await events.emit()
The emitter returns a promise that waits for listeners to resolve.
Identify subscriptions by dot-prop string:
events.on("hello.world", () => {})
events.emit("hello.world") // emits
events.emit() // doesn't emit
Dot-props come in handy with the onAny
subscriber, which subscribes to a dot-prop and its child props:
events.onAny("hello", () => {})
events.emit("hello") // emits
events.emit("hello.world") // emits
events.emit() // doesn't emit
Subscription listeners receive a single object argument. To add to that object, use the withOptions
function on emit:
events.on(({ hello }) => {})
events.withOptions({ hello: "world" }).emit()
Or use withOptions
on the subscriber:
events.withOptions({ hello: "world" }).on(({ hello }) => {})
events.emit()
The listener argument also contains an event
property with extra information, such as the emitter arguments:
events.on(({ event }) => {
event.args // [123, true]
})
events.emit(123, true)
An "operation" is a way to namespace your events and make a custom emitter function:
events.withOp("create").on(() => {})
events.create() // emits
Operation functions take the same arguments and behave similar to emit
.
Subscribe to before or after the main subscription listener:
events.before().on(() => {})
events.on(() => {})
events.after().on(() => {})
events.emit()
Subscribe to any emit:
events.onAny(() => {})
events.emit() // emits
events.emit("hello") // emits
events.emit("hello.world") // emits
events.create() // emits
When used with a dot-prop, it subscribes to any child prop emit:
events.onAny("hello", () => {})
events.emit("hello") // emits
events.emit("hello.world") // emits
events.emit() // doesn't emit
Like on
, but emit immediately if a previous emit occurred:
events.emit()
events.onEmitted(() => {}) // emits immediately
events.emit() // emits
Like onAny
, but emit immediately if a previous emit occurred:
events.emit("hello.world")
events.onAnyEmitted("hello", () => {}) // emits immediately
events.emit("hello.world") // emits
events.emit() // doesn't emit
events.once(() => {})
events.emit() // emits
events.emit() // doesn't emit
Like once
, but emit immediately if a previous emit occurred:
events.emit()
events.onceEmitted(() => {}) // emits immediately
events.emit() // doesn't emit
A combination of once
and onAny
:
events.onceAny("hello", () => {})
events.emit("hello.world") // emits
events.emit("hello.world") // doesn't emit
A combination of once
, onAny
, and onEmitted
:
events.emit("hello.world")
events.onceAnyEmitted("hello", () => {}) // emits immediately
events.emit("hello.world") // doesn't emit
Build lots of dot-prop subscriptions at once:
events.on({
hello: () => {},
"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
pnpm 10 blocks lifecycle scripts by default to improve security, addressing supply chain attack risks but sparking debate over compatibility and workflow changes.
Product
Socket now supports uv.lock files to ensure consistent, secure dependency resolution for Python projects and enhance supply chain security.
Research
Security News
Socket researchers have discovered multiple malicious npm packages targeting Solana private keys, abusing Gmail to exfiltrate the data and drain Solana wallets.