Security News
Research
Data Theft Repackaged: A Case Study in Malicious Wrapper Packages on npm
The Socket Research Team breaks down a malicious wrapper package that uses obfuscation to harvest credentials and exfiltrate sensitive data.
@tomdionysus/event-tree
Advanced tools
event-tree is a JavaScript library designed to facilitate the organization and management of events using a hierarchical tree structure. The library allows developers to easily subscribe and unsubscribe event listeners, as well as trigger events throughout the tree. By organizing events in a tree, the library helps developers visualize and manage event relationships more effectively. event-tree supports adding and removing event listeners, triggering events, and pruning unused nodes, making it an efficient and practical solution for event-driven applications.
Event-Tree organizes events in a hierarchical tree structure, making it simple to visualize and manage event relationships. Here's an example of an event tree:
factory
├── security
│ ├── signIn
│ ├── signOut
│ └── alarm
├── process
│ ├── production
│ │ ├── start
│ │ └── stop
│ └── assembly
│ ├── start
│ └── stop
└── timeclock
├── shift
│ ├── starts
│ └── ends
├── dayStart
└── dayEnd
Each node in the tree has an "address" (e.g., factory.process.production.start
or factory.timeclock
). You can subscribe to a specific event by its address and provide a callback function.
npm i @tomdionysus/event-tree
const { EventTree } = require('@tomdionysus/event-tree')
// Create a new event tree
const myTree = new EventTree()
// Add an event listener
myTree.on('myEvent', {}, (data) => {
console.log(`Received data for 'myEvent': ${data}`)
})
// Trigger the event
myTree.trigger('myEvent', 'Hello, world!')
In this example, we create a new EventTree instance and add an event listener for the myEvent event. When the event is triggered with the string 'Hello, world!', the listener will log a message to the console.
const { EventTree } = require('@tomdionysus/event-tree')
// Create a new event tree
const myTree = new EventTree()
// Add an event listener for event1
myTree.on('event1', {}, (data) => {
console.log(`Received data for 'event1': ${data}`)
})
// Add an event listener for event1.event2
myTree.on('event1.event2', {}, (data) => {
console.log(`Received data for 'event1.event2': ${data}`)
})
// Trigger the event1.event2 event
myTree.trigger('event1.event2', 'Hello, world from event1.event2!')
In this example, we create a new EventTree instance and add event listeners for two events, event1 and event1.event2, which is a hierarchical event. When the event1.event2 event is triggered, both event listeners will fire and log messages to the console, since event1 is a parent event of event1.event2. Therefore, the output will be:
Received data for 'event1': Hello, world from event1.event2!
Received data for 'event1.event2': Hello, world from event1.event2!
To subscribe to an event, use on
or addEventListener
:
on(eventName, [options], handler)
The handler function will be called with these parameters: handler({ eventName: <original eventName>, context: <context from trigger>, options: <options from on> })
To unsubscribe from an event, use unon or removeEventListener:
unon(eventName, [options], handler)
When you trigger an event, all handlers in the event's route are also called. For example:
trigger('factory.security.signIn', context)
The following event's listeners will be called:
factory
factory.security
factory.security.signIn
If any handler returns explictly false
, all downline events will not be triggered. For example:
trigger('factory.security.signIn', context)
Event listeners are registered on the following events:
factory
- returns nullfactory.security
- returns falsefactory.security.signIn
- These handlers will not be called, because a handler on factory.security
returned false.The following event's listeners will be called:
factory
factory.security
factory.security.signIn
You can get all the handlers that will be called for an event using listeners(eventName)
. This will include handlers from ancestor events:
on('event1', {}}, handler1)
on('event1.event2', {}}, handler2)
listeners('event1.event2') === [ handler1, handler2 ]
This project is licensed under the terms of the MIT license. See the LICENSE file for details.
Contributors must observe the Code Of Conduct.
FAQs
A tree-based event system for JavaScript
The npm package @tomdionysus/event-tree receives a total of 0 weekly downloads. As such, @tomdionysus/event-tree popularity was classified as not popular.
We found that @tomdionysus/event-tree 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
Research
The Socket Research Team breaks down a malicious wrapper package that uses obfuscation to harvest credentials and exfiltrate sensitive data.
Research
Security News
Attackers used a malicious npm package typosquatting a popular ESLint plugin to steal sensitive data, execute commands, and exploit developer systems.
Security News
The Ultralytics' PyPI Package was compromised four times in one weekend through GitHub Actions cache poisoning and failure to rotate previously compromised API tokens.