From f9c84cca5d8dc6d3e54caab4c4c66e6ba7d83882 Mon Sep 17 00:00:00 2001 From: Tagir Khadzhiev Date: Sat, 9 Mar 2024 16:44:44 +0100 Subject: [PATCH] Improve documentation and dist types --- .eslintignore | 1 + README.md | 13 +----------- package.json | 2 +- src/index.ts | 2 ++ src/system/usb/README.md | 42 ++++++++++++++++++++++++++++++++++--- src/system/usb/index.ts | 13 ++++++++++-- src/system/usb/interface.ts | 7 +++++++ 7 files changed, 62 insertions(+), 18 deletions(-) diff --git a/.eslintignore b/.eslintignore index 904c815..621df9b 100644 --- a/.eslintignore +++ b/.eslintignore @@ -1,3 +1,4 @@ node_modules build +dist playground \ No newline at end of file diff --git a/README.md b/README.md index 63dfe6c..7ff7d5e 100644 --- a/README.md +++ b/README.md @@ -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 diff --git a/package.json b/package.json index 716045d..762eb36 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "spci-libs", - "version": "0.0.3", + "version": "0.0.4", "description": "System information library", "author": "Tagir Khadzhiev ", "license": "MIT", diff --git a/src/index.ts b/src/index.ts index b61bb8a..088d08c 100644 --- a/src/index.ts +++ b/src/index.ts @@ -1,3 +1,5 @@ import Usb from './system/usb'; +import { USB_DEVICE_TYPE } from './system/usb/config'; export { Usb }; +export { USB_DEVICE_TYPE }; diff --git a/src/system/usb/README.md b/src/system/usb/README.md index f457f7b..cdbcb69 100644 --- a/src/system/usb/README.md +++ b/src/system/usb/README.md @@ -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 | @@ -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 diff --git a/src/system/usb/index.ts b/src/system/usb/index.ts index fe3841c..a0b9c43 100644 --- a/src/system/usb/index.ts +++ b/src/system/usb/index.ts @@ -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; @@ -16,8 +19,14 @@ class Usb { } /** - * Get USB devices - * @returns {Promise} + * 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} A promise that resolves to an array of USB devices. */ public async getDevices(): Promise { if (this.PLATFORM === null) return []; diff --git a/src/system/usb/interface.ts b/src/system/usb/interface.ts index ceed8f9..58a7500 100644 --- a/src/system/usb/interface.ts +++ b/src/system/usb/interface.ts @@ -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} A promise that resolves to an array of USB devices. + */ getInfo: () => Promise; }