papnkukn/eml-format

TypeScript Definitions

DanielMcAssey opened this issue · 1 comments

Hi love this library.

Are there any plans for TypeScript definitions?

Just used ChatGPT to generate one, seems perfect for me:

declare module 'emlformat' {
  interface Headers {
    [key: string]: string | string[];
  }

  interface Part {
    headers: Headers;
    body: string | Part[] | Body[];
  }

  interface Body {
    boundary: string;
    part: Part;
  }

  interface ParsedEml {
    headers: Headers;
    body: string | Body[];
  }

  interface Attachment {
    id?: string;
    name?: string;
    contentType?: string;
    inline?: boolean;
    data: string | Buffer;
  }

  interface EmailAddress {
    name?: string;
    email: string;
  }

  interface ReadEml {
    date?: Date;
    subject?: string;
    from?: EmailAddress | EmailAddress[];
    to?: EmailAddress | EmailAddress[];
    cc?: EmailAddress | EmailAddress[];
    headers: Headers;
    text?: string;
    html?: string;
    attachments?: Attachment[];
  }

  interface BuildOptions {
    headersOnly?: boolean;
  }

  interface UnpackOptions {
    parsedJsonFile?: string;
    readJsonFile?: string;
    simulate?: boolean;
  }

  function parse(eml: string, options: BuildOptions, callback: (error: Error | null, data: ParsedEml) => void): void;
  function read(eml: string | ParsedEml, options: BuildOptions, callback: (error: Error | null, data: ReadEml) => void): void;
  function build(data: ReadEml, options: BuildOptions, callback: (error: Error | null, eml: string) => void): void;
  function unpack(eml: string | ParsedEml, directory: string, options: UnpackOptions, callback: (error: Error | null, result: { files: string[] }) => void): void;
}