npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

periphera

v1.2.13

Published

Periphera: A sleek and efficient Node.js library for real-time monitoring of serial and HID devices. Seamlessly track the addition and removal of peripherals with ease, ensuring your applications stay in sync with connected hardware. Perfect for developer

Downloads

42

Readme

Periphera

Periphera is a library for monitoring serial and HID devices for changes. It provides an elegant API to work with devices, allowing you to find devices by various properties and monitor device changes efficiently.

Installation

Install the library using npm:

npm install periphera

Usage

Importing the Library

First, import the necessary components from the library:

import { DeviceChangeEvent } from "periphera";
import { DeviceManager } from "periphera";
import { DeviceMonitor } from "periphera";

Creating a DeviceMonitor Instance

Create an instance of DeviceMonitor to start monitoring devices. You can specify the monitoring interval and whether to filter out ghost devices (devices with undefined manufacturers).

const monitor = new DeviceMonitor(2000, true);

Creating a DeviceManager Instance

Create an instance of DeviceManager using the DeviceMonitor instance.

const manager = new DeviceManager(monitor);

Initializing the DeviceMonitor

Call the initialize method on DeviceMonitor to set up devices and start monitoring.

await monitor.initialize();

Listening to Device Changes

You can listen to device change events (added or removed) using the deviceMonitor.on method:

monitor.on('deviceChange', (event: DeviceChangeEvent) => {
    console.log(`Device ${event.type}:`, event.deviceType, event.device);
});

Finding Devices by Properties

The DeviceManager class provides methods to find devices by various properties. You can find devices by a specific property in a case-insensitive and partial match manner.

Find Devices by Property

To find devices by a specific property:

const devicesByManufacturer = manager.findDeviceBy('manufacturer', 'ftdi');
console.log('Devices by Manufacturer:', devicesByManufacturer);

Full Example

Here is a complete example of how to use the DeviceMonitor and DeviceManager classes to monitor devices and find devices by specific properties:

import { DeviceChangeEvent } from "periphera";
import { DeviceManager } from "periphera";
import { DeviceMonitor } from "periphera";

const monitor = new DeviceMonitor(2000, true);
const manager = new DeviceManager(monitor);

monitor.on('deviceChange', (event: DeviceChangeEvent) => {
    console.log(`Device ${event.type}:`, event.deviceType, event.device);
});

monitor.initialize().then(() => {
    const devicesByManufacturer = manager.findDeviceBy('manufacturer', 'ftdi');
    console.log('Devices by Manufacturer:', devicesByManufacturer);
}).catch(err => {
    console.error('Error initializing devices:', err);
});

API Reference

DeviceMonitor

Constructor

new DeviceMonitor(monitoringInterval?: number, filterGhostDevices?: boolean);
  • monitoringInterval (optional): The interval (in milliseconds) at which to scan for device changes. Default is 2000ms.
  • filterGhostDevices (optional): Boolean to enable or disable filtering of ghost devices (devices with undefined manufacturers). Default is false.

Methods

  • initialize(): Promise<void>: Initializes the device lists and starts monitoring for changes.
  • on(event: DeviceEventNames, listener: (event: DeviceChangeEvent) => void): this: Adds an event listener for the specified event.
  • getSerialDevices(): SerialInfo: Gets the current list of monitored serial devices.
  • getHIDDevices(): HIDInfo: Gets the current list of monitored HID devices.
  • stopMonitoring(): void: Stops the device monitoring.

DeviceManager

Constructor

new DeviceManager(deviceMonitor: DeviceMonitor);
  • deviceMonitor: An instance of DeviceMonitor.

Methods

  • findDeviceBy(property: keyof DeviceInfo, value: string): DeviceInfo[]: Finds devices by a given property and value (case-insensitive and partial match).

License

This project is licensed under the MIT License - see the LICENSE file for details.