papnkukn / eml-format

RFC 822 EML file format parser and builder
MIT License
84 stars 51 forks source link

TypeScript Definitions #30

Open DanielMcAssey opened 2 years ago

DanielMcAssey commented 2 years ago

Hi love this library.

Are there any plans for TypeScript definitions?

ZhuBoao commented 1 year ago

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;
}