Skip to content

Commit

Permalink
Improve documentation and dist types
Browse files Browse the repository at this point in the history
  • Loading branch information
Aspedm committed Mar 9, 2024
1 parent 71549a4 commit f9c84cc
Show file tree
Hide file tree
Showing 7 changed files with 62 additions and 18 deletions.
1 change: 1 addition & 0 deletions .eslintignore
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
node_modules
build
dist
playground
13 changes: 1 addition & 12 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,18 +8,7 @@ This project containts libs to get information about system.
### Supported modules

#### USB
| Name | Type | Linux | Mac OS | Windows (10+) | Description |
|---------------|-----------------|-------|--------|---------------|---------------------------------------------------|
|`bus` | string \| null |||| Identifies the USB bus the device is connected to |
|`deviceId` | string \| null |||| Unique identifier assigned to the USB device |
|`id` | string \| null |||| Unique identifier for the USB device |
|`name` | string \| null |||| Human-readable name of the USB device |
|`type` | string \| null |||| Categorizes the USB device based on functionality |
|`removable` | boolean \| null |||| Indicates if the device is removable |
|`vendor` | string \| null |||| Identifies the vendor |
|`manufacturer` | string \| null |||| Specifies the device's manufacturer. |
|`maxPower` | string \| null |||| Maximum power the device can draw (in mA) |
|`serialNumber` | string \| null |||| Unique serial number assigned by the manufacturer |
- The documentation for USB devices can be found [here](https://github.com/Aspedm/spci-libs/blob/main/src/system/usb/README.md)

### Install
```sh
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "spci-libs",
"version": "0.0.3",
"version": "0.0.4",
"description": "System information library",
"author": "Tagir Khadzhiev <aspedm@gmail.com>",
"license": "MIT",
Expand Down
2 changes: 2 additions & 0 deletions src/index.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
import Usb from './system/usb';
import { USB_DEVICE_TYPE } from './system/usb/config';

export { Usb };
export { USB_DEVICE_TYPE };
42 changes: 39 additions & 3 deletions src/system/usb/README.md
Original file line number Diff line number Diff line change
@@ -1,9 +1,7 @@
# USB
This class returned array of detected USB devices

### Fields
Returned fields depends of OS.

### Supported fields
| Name | Type | Linux | Mac OS | Windows (10+) | Description |
|---------------|-----------------|-------|--------|---------------|---------------------------------------------------|
|`bus` | string \| null |||| Identifies the USB bus the device is connected to |
Expand All @@ -17,6 +15,44 @@ Returned fields depends of OS.
|`maxPower` | string \| null |||| Maximum power the device can draw (in mA) |
|`serialNumber` | string \| null |||| Unique serial number assigned by the manufacturer |

### Supported usb types
#### Mac OS
- camera
- touch bar
- controller
- headset
- iphone
- ipad
- nintendo
- magsafe
- earpods
- keyboard
- trackpad
- sensor
- bthusb
- bth
- rfcomm
- usbhub
- hub
- mouse
- mic
- removable

#### Windows
- iphone
- ipad
- magsafe
- earpods
- usbstor
- usbaudio
- disk
- usbhub
- bthusb
- usbccgp
- wudfwpdmtp
- controller

All device types are defined in the USB_DEVICE_TYPE enum.

### How to use

Expand Down
13 changes: 11 additions & 2 deletions src/system/usb/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,9 @@ import { ISpciUsb, ISpciUsbDevice } from './interface';
import Macos from './macos';
import Windows from './windows';

/**
* Class representing a USB device.
*/
class Usb {
private PLATFORM: ISpciUsb | null = null;

Expand All @@ -16,8 +19,14 @@ class Usb {
}

/**
* Get USB devices
* @returns {Promise<ISpciUsbDevice[]>}
* Get information about USB devices.
* This method returns an array of USB devices.
* The fields in each USB device object depend on the underlying operating system.
* @example
* const usb = new Usb();
* const devices = await usb.getDevices();
* console.log(devices);
* @returns {Promise<ISpciUsbDevice[]>} A promise that resolves to an array of USB devices.
*/
public async getDevices(): Promise<ISpciUsbDevice[]> {
if (this.PLATFORM === null) return [];
Expand Down
7 changes: 7 additions & 0 deletions src/system/usb/interface.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,13 @@ export interface ISpciUsbDevice {
serialNumber: string | null;
}

/**
* Interface representing a USB device.
*/
export interface ISpciUsb {
/**
* Get information about USB devices.
* @returns {Promise<ISpciUsbDevice[]>} A promise that resolves to an array of USB devices.
*/
getInfo: () => Promise<ISpciUsbDevice[]>;
}

0 comments on commit f9c84cc

Please sign in to comment.