webserial-core
Version:
A strongly-typed, event-driven, abstract TypeScript library for the Web Serial API with custom parsers, command queue, handshake validation, and auto-reconnect.
48 lines (47 loc) • 1.65 kB
TypeScript
import { SerialParser } from '../types/index.js';
export interface DelimiterOptions {
/** Whether to include the delimiter at the end of each emitted value. Defaults to false. */
includeDelimiter?: boolean;
}
/**
* Creates a delimiter-based parser that splits the byte stream on the given
* delimiter and emits string messages.
*
* Commonly used with `'\n'` for Arduino `Serial.println()` output.
*
* @param char - The delimiter string (e.g. `'\n'`, `'\r\n'`, `';'`).
* @param options - Optional configuration.
* @returns A {@link SerialParser} that emits `string` values.
*
* @example
* ```ts
* import { AbstractSerialDevice, delimiter } from 'webserial-core';
*
* class MyDevice extends AbstractSerialDevice<string> {
* constructor() {
* super({ baudRate: 9600, parser: delimiter('\n') });
* }
* }
* ```
*/
export declare function delimiter(char: string, options?: DelimiterOptions): SerialParser<string>;
/**
* Creates a delimiter-based parser that splits the byte stream on the given
* binary delimiter and emits Uint8Array chunks.
*
* @param char - The delimiter as a `Uint8Array` or `number[]`.
* @param options - Optional configuration.
* @returns A {@link SerialParser} that emits `Uint8Array` values.
*
* @example
* ```ts
* import { AbstractSerialDevice, delimiter } from 'webserial-core';
*
* class MyDevice extends AbstractSerialDevice<Uint8Array> {
* constructor() {
* super({ baudRate: 9600, parser: delimiter(new Uint8Array([0x0d, 0x0a])) });
* }
* }
* ```
*/
export declare function delimiter(char: Uint8Array | number[], options?: DelimiterOptions): SerialParser<Uint8Array>;