UNPKG

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.

27 lines (26 loc) 883 B
import { SerialParser } from '../types/index.js'; export interface RegexParserOptions { /** Regular expression used to split the incoming text stream. */ regex: RegExp | string; /** Text encoding used to decode bytes. Defaults to `'utf-8'`. */ encoding?: string; } /** * Creates a regex parser that decodes incoming bytes and emits string segments * split by the provided regular expression. * * @param options - Configuration options. * @returns A {@link SerialParser} that emits `string` values. * * @example * ```ts * import { AbstractSerialDevice, regexParser } from 'webserial-core'; * * class MyDevice extends AbstractSerialDevice<string> { * constructor() { * super({ baudRate: 9600, parser: regexParser({ regex: /[\r\n]+/ }) }); * } * } * ``` */ export declare function regexParser(options: RegexParserOptions): SerialParser<string>;