1.0.6 • Published 6 months ago

@types/dom-serial v1.0.6

Weekly downloads
15
License
MIT
Repository
github
Last release
6 months ago

Installation

npm install --save @types/dom-serial

Summary

This package contains type definitions for Web Serial API based on spec and Chromium implementation (https://wicg.github.io/serial/).

Details

Files were exported from https://github.com/DefinitelyTyped/DefinitelyTyped/tree/master/types/dom-serial.

index.d.ts

// Type definitions for non-npm package Web Serial API based on spec and Chromium implementation 1.0
// Project: https://wicg.github.io/serial/
// Definitions by: Maciej Mroziński <https://github.com/maciejmrozinski>
// Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped

type EventHandler = (event: Event) => void;

interface SerialPortInfoBase {
    serialNumber: string;
    manufacturer: string;
    locationId: string;
    vendorId: string;
    vendor: string;
    productId: string;
    product: string;
}

interface SerialPortFilter {
    usbVendorId: number;
    usbProductId?: number | undefined;
}

interface SerialPortInfo extends SerialPortInfoBase, SerialPortFilter {} // mix spec and Chromium implementation

type ParityType = 'none' | 'even' | 'odd' | 'mark' | 'space';

type FlowControlType = 'none' | 'hardware';

interface SerialOptions {
    baudRate: number;
    dataBits?: number | undefined;
    stopBits?: number | undefined;
    parity?: ParityType | undefined;
    bufferSize?: number | undefined;
    flowControl?: FlowControlType | undefined;
}

interface SerialPort extends EventTarget {
    onconnect: EventHandler;
    ondisconnect: EventHandler;
    readonly readable: ReadableStream; // Chromium implementation (spec: in)
    readonly writable: WritableStream; // Chromium implementation (spec: out)
    open(options: SerialOptions): Promise<void>;
    close(): Promise<void>;
    getInfo(): Partial<SerialPortInfo>;
}

interface SerialPortRequestOptions {
    filters: SerialPortFilter[];
}

interface Serial extends EventTarget {
    onconnect: EventHandler;
    ondisconnect: EventHandler;
    getPorts(): Promise<SerialPort[]>;
    requestPort(options?: SerialPortRequestOptions): Promise<SerialPort>; // Chromium implementation (spec: SerialOptions)
}

interface Navigator {
    readonly serial: Serial;
}

Additional Details

  • Last updated: Mon, 20 Sep 2021 21:31:21 GMT
  • Dependencies: none
  • Global values: none

Credits

These definitions were written by Maciej Mroziński.