From a7a6770bd3674ae8aea31d25d9f88361d2f71106 Mon Sep 17 00:00:00 2001 From: Luke Cunningham Date: Thu, 23 Nov 2023 23:51:21 +0800 Subject: [PATCH] Add typescript definitions --- index.d.ts | 41 +++++++++++++++++++++++++++++++++++++++++ package.json | 1 + 2 files changed, 42 insertions(+) create mode 100644 index.d.ts diff --git a/index.d.ts b/index.d.ts new file mode 100644 index 0000000..9c9f5aa --- /dev/null +++ b/index.d.ts @@ -0,0 +1,41 @@ +declare module 'node-mbox' { + import { Transform, Writable, Readable } from 'stream'; + + interface MboxOptions { + includeMboxHeader?: boolean; + } + + /** + * Class implements Transform stream. Transforming lines to messages as Buffers. + */ + export class Mbox extends Transform { + constructor(opts?: MboxOptions); + } + + /** + * MboxStream simply pipes `split('\n')` with Mbox(). + * + * @param readStream An instance of Readable stream. + * @param opts Params passed to Mbox. + * @returns An instance of Mbox stream. + */ + export function MboxStream(readStream: Readable, opts?: MboxOptions): Mbox; + + /** + * MboxStreamConsumer is simple abstract class extending Writable. + * You must implement consume method which consumes particular messages. + */ + export class MboxStreamConsumer extends Writable { + constructor(opts?: any); + + /** + * Consume method to be implemented by subclasses. + * + * @param message Message in buffer format. + * @param encoding Encoding of the message. + * @param cb Callback function. + */ + consume(message: Buffer, encoding: BufferEncoding, cb: (err?: Error) => void): void; + } + } + \ No newline at end of file diff --git a/package.json b/package.json index 97b9417..ce3603b 100644 --- a/package.json +++ b/package.json @@ -2,6 +2,7 @@ "name": "node-mbox", "version": "2.0.0", "description": "mbox parser for Node", + "types": "index.d.ts", "scripts": { "test": "mocha -R spec test/" },