Skip to content

Commit

Permalink
corrected some typings
Browse files Browse the repository at this point in the history
  • Loading branch information
muratgozel committed Mar 8, 2024
1 parent 76b81a5 commit 6b616af
Show file tree
Hide file tree
Showing 63 changed files with 201 additions and 211 deletions.
6 changes: 4 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,17 +1,19 @@
# MIMEText
[RFC-2822](https://www.rfc-editor.org/rfc/rfc2822), [RFC-2045](https://www.rfc-editor.org/rfc/rfc2045) and [RFC-2049](https://www.rfc-editor.org/rfc/rfc2049) compliant raw email message generator. Refer to [https://muratgozel.github.io/MIMEText/](https://muratgozel.github.io/MIMEText/) for full api docs.

It has full typings. Optimized to run on node, browser and google apps script environments. Compatible with commonjs and esm.

## Install
```sh
npm i mimetext
```

## Use
Import the appropriate version for your environment. Use `mimetext/browser` for browser, `mimetext/gas` for google apps script and `mimetext` for node environments.
```js
// cjs
const {createMimeMessage} = require('mimetext')
// es
import {createMimeMessage} from 'mimetext'
// or const {createMimeMessage} = require('mimetext') for commonjs

// create a simple plain text email
const msg = createMimeMessage()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,11 @@ declare class Mailbox {
name: string;
addr: string;
type: MailboxType;
constructor(input: MailboxAddrObject | MailboxAddrText | Email, config?: MailboxConfig);
constructor(input: MailboxAddrObject | string, config?: MailboxConfig);
getAddrDomain(): string;
dump(): string;
parse(input: MailboxAddrObject | MailboxAddrText | Email): this;
isMailboxAddrText(v: unknown): v is MailboxAddrText;
parse(input: MailboxAddrObject | string): this;
isMailboxAddrText(v: unknown): boolean;
isMailboxAddrObject(v: unknown): v is MailboxAddrObject;
isObject(v: unknown): v is object;
}
Expand All @@ -20,17 +20,15 @@ interface MailboxAddrObject {
type?: MailboxType;
}
type MailboxType = 'To' | 'From' | 'Cc' | 'Bcc';
type Email = string;
type MailboxAddrText = string;

declare class MIMEMessageHeader {
envctx: EnvironmentContext;
fields: HeaderField[];
constructor(envctx: EnvironmentContext);
dump(): string;
toObject(): HeadersObject;
get(name: string): string | Mailbox | undefined;
set(name: string, value: any): HeaderField;
get(name: string): string | Mailbox | Mailbox[] | undefined;
set(name: string, value: string | Mailbox | Mailbox[]): HeaderField;
setCustom(obj: HeaderField): HeaderField;
validateMailboxSingle(v: unknown): v is Mailbox;
validateMailboxMulti(v: unknown): boolean;
Expand All @@ -39,19 +37,19 @@ declare class MIMEMessageHeader {
isHeaderField(v: unknown): v is HeaderField;
isObject(v: unknown): v is object;
isArrayOfMailboxes(v: unknown): v is Mailbox[];
isArray(v: unknown): v is any[];
isArray(v: unknown): v is never[];
}
declare class MIMEMessageContentHeader extends MIMEMessageHeader {
fields: {
name: string;
}[];
constructor(envctx: EnvironmentContext);
}
type HeadersObject = Record<string, string | Mailbox | undefined>;
type HeadersObject = Record<string, string | Mailbox | Mailbox[] | undefined>;
interface HeaderField {
name: string;
dump?: (v: string | Mailbox | Mailbox[] | undefined) => string;
value?: string | Mailbox | undefined;
value?: string | Mailbox | Mailbox[] | undefined;
validate?: (v: unknown) => boolean;
required?: boolean;
disabled?: boolean;
Expand All @@ -67,9 +65,9 @@ declare class MIMEMessageContent {
dump(): string;
isAttachment(): boolean;
isInlineAttachment(): boolean;
setHeader(name: string, value: any): string;
getHeader(name: string): string | Mailbox | undefined;
setHeaders(obj: Record<string, any>): string[];
setHeader(name: string, value: string | Mailbox | Mailbox[]): string;
getHeader(name: string): string | Mailbox | Mailbox[] | undefined;
setHeaders(obj: Record<string, string | Mailbox | Mailbox[]>): string[];
getHeaders(): HeadersObject;
}

Expand All @@ -92,24 +90,24 @@ declare class MIMEMessage {
addAttachment(opts: AttachmentOptions): MIMEMessageContent;
addMessage(opts: ContentOptions): MIMEMessageContent;
private _addMessage;
setSender(input: MailboxAddrObject | MailboxAddrText | Email, config?: MailboxConfig): Mailbox;
getSender(): string | Mailbox | undefined;
setRecipients(input: MailboxAddrObject | MailboxAddrText | Email | MailboxAddrObject[] | MailboxAddrText[] | Email[], config?: MailboxConfig): Mailbox[];
getRecipients(config?: MailboxConfig): string | Mailbox | undefined;
setRecipient(input: MailboxAddrObject | MailboxAddrText | Email | MailboxAddrObject[] | MailboxAddrText[] | Email[], config?: MailboxConfig): Mailbox[];
setTo(input: MailboxAddrObject | MailboxAddrText | Email | MailboxAddrObject[] | MailboxAddrText[] | Email[], config?: MailboxConfig): Mailbox[];
setCc(input: MailboxAddrObject | MailboxAddrText | Email | MailboxAddrObject[] | MailboxAddrText[] | Email[], config?: MailboxConfig): Mailbox[];
setBcc(input: MailboxAddrObject | MailboxAddrText | Email | MailboxAddrObject[] | MailboxAddrText[] | Email[], config?: MailboxConfig): Mailbox[];
setSender(input: MailboxAddrObject | string, config?: MailboxConfig): Mailbox;
getSender(): Mailbox | undefined;
setRecipients(input: MailboxAddrObject | string | MailboxAddrObject[] | string[], config?: MailboxConfig): Mailbox[];
getRecipients(config?: MailboxConfig): Mailbox | Mailbox[] | undefined;
setRecipient(input: MailboxAddrObject | string | MailboxAddrObject[] | string[], config?: MailboxConfig): Mailbox[];
setTo(input: MailboxAddrObject | string | MailboxAddrObject[] | string[], config?: MailboxConfig): Mailbox[];
setCc(input: MailboxAddrObject | string | MailboxAddrObject[] | string[], config?: MailboxConfig): Mailbox[];
setBcc(input: MailboxAddrObject | string | MailboxAddrObject[] | string[], config?: MailboxConfig): Mailbox[];
setSubject(value: string): string;
getSubject(): string | Mailbox | undefined;
setHeader(name: string, value: any): string;
getHeader(name: string): string | Mailbox | undefined;
setHeaders(obj: Record<string, any>): string[];
getSubject(): string | undefined;
setHeader(name: string, value: string | Mailbox | Mailbox[]): string;
getHeader(name: string): string | Mailbox | Mailbox[] | undefined;
setHeaders(obj: Record<string, string | Mailbox | Mailbox[]>): string[];
getHeaders(): HeadersObject;
toBase64(v: string): string;
toBase64WebSafe(v: string): string;
generateBoundaries(): void;
isArray(v: unknown): v is any[];
isArray(v: unknown): v is unknown[];
isObject(v: unknown): v is object;
}
interface EnvironmentContext {
Expand Down Expand Up @@ -149,4 +147,4 @@ declare class MIMETextError extends Error {
constructor(message: string, description?: string);
}

export { type AttachmentOptions as A, type Boundaries as B, type ContentTransferEncoding as C, type EnvironmentContext as E, type HeadersObject as H, MIMEMessage as M, Mailbox as a, MIMETextError as b, MIMEMessageHeader as c, MIMEMessageContent as d, type ContentHeaders as e, type ContentOptions as f, type MailboxConfig as g, type MailboxAddrObject as h, type MailboxType as i, type Email as j, type MailboxAddrText as k, MIMEMessageContentHeader as l, type HeaderField as m };
export { type AttachmentOptions as A, type Boundaries as B, type ContentTransferEncoding as C, type EnvironmentContext as E, type HeadersObject as H, MIMEMessage as M, Mailbox as a, MIMETextError as b, MIMEMessageHeader as c, MIMEMessageContent as d, type ContentHeaders as e, type ContentOptions as f, type MailboxConfig as g, type MailboxAddrObject as h, type MailboxType as i, MIMEMessageContentHeader as j, type HeaderField as k };
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,11 @@ declare class Mailbox {
name: string;
addr: string;
type: MailboxType;
constructor(input: MailboxAddrObject | MailboxAddrText | Email, config?: MailboxConfig);
constructor(input: MailboxAddrObject | string, config?: MailboxConfig);
getAddrDomain(): string;
dump(): string;
parse(input: MailboxAddrObject | MailboxAddrText | Email): this;
isMailboxAddrText(v: unknown): v is MailboxAddrText;
parse(input: MailboxAddrObject | string): this;
isMailboxAddrText(v: unknown): boolean;
isMailboxAddrObject(v: unknown): v is MailboxAddrObject;
isObject(v: unknown): v is object;
}
Expand All @@ -20,17 +20,15 @@ interface MailboxAddrObject {
type?: MailboxType;
}
type MailboxType = 'To' | 'From' | 'Cc' | 'Bcc';
type Email = string;
type MailboxAddrText = string;

declare class MIMEMessageHeader {
envctx: EnvironmentContext;
fields: HeaderField[];
constructor(envctx: EnvironmentContext);
dump(): string;
toObject(): HeadersObject;
get(name: string): string | Mailbox | undefined;
set(name: string, value: any): HeaderField;
get(name: string): string | Mailbox | Mailbox[] | undefined;
set(name: string, value: string | Mailbox | Mailbox[]): HeaderField;
setCustom(obj: HeaderField): HeaderField;
validateMailboxSingle(v: unknown): v is Mailbox;
validateMailboxMulti(v: unknown): boolean;
Expand All @@ -39,19 +37,19 @@ declare class MIMEMessageHeader {
isHeaderField(v: unknown): v is HeaderField;
isObject(v: unknown): v is object;
isArrayOfMailboxes(v: unknown): v is Mailbox[];
isArray(v: unknown): v is any[];
isArray(v: unknown): v is never[];
}
declare class MIMEMessageContentHeader extends MIMEMessageHeader {
fields: {
name: string;
}[];
constructor(envctx: EnvironmentContext);
}
type HeadersObject = Record<string, string | Mailbox | undefined>;
type HeadersObject = Record<string, string | Mailbox | Mailbox[] | undefined>;
interface HeaderField {
name: string;
dump?: (v: string | Mailbox | Mailbox[] | undefined) => string;
value?: string | Mailbox | undefined;
value?: string | Mailbox | Mailbox[] | undefined;
validate?: (v: unknown) => boolean;
required?: boolean;
disabled?: boolean;
Expand All @@ -67,9 +65,9 @@ declare class MIMEMessageContent {
dump(): string;
isAttachment(): boolean;
isInlineAttachment(): boolean;
setHeader(name: string, value: any): string;
getHeader(name: string): string | Mailbox | undefined;
setHeaders(obj: Record<string, any>): string[];
setHeader(name: string, value: string | Mailbox | Mailbox[]): string;
getHeader(name: string): string | Mailbox | Mailbox[] | undefined;
setHeaders(obj: Record<string, string | Mailbox | Mailbox[]>): string[];
getHeaders(): HeadersObject;
}

Expand All @@ -92,24 +90,24 @@ declare class MIMEMessage {
addAttachment(opts: AttachmentOptions): MIMEMessageContent;
addMessage(opts: ContentOptions): MIMEMessageContent;
private _addMessage;
setSender(input: MailboxAddrObject | MailboxAddrText | Email, config?: MailboxConfig): Mailbox;
getSender(): string | Mailbox | undefined;
setRecipients(input: MailboxAddrObject | MailboxAddrText | Email | MailboxAddrObject[] | MailboxAddrText[] | Email[], config?: MailboxConfig): Mailbox[];
getRecipients(config?: MailboxConfig): string | Mailbox | undefined;
setRecipient(input: MailboxAddrObject | MailboxAddrText | Email | MailboxAddrObject[] | MailboxAddrText[] | Email[], config?: MailboxConfig): Mailbox[];
setTo(input: MailboxAddrObject | MailboxAddrText | Email | MailboxAddrObject[] | MailboxAddrText[] | Email[], config?: MailboxConfig): Mailbox[];
setCc(input: MailboxAddrObject | MailboxAddrText | Email | MailboxAddrObject[] | MailboxAddrText[] | Email[], config?: MailboxConfig): Mailbox[];
setBcc(input: MailboxAddrObject | MailboxAddrText | Email | MailboxAddrObject[] | MailboxAddrText[] | Email[], config?: MailboxConfig): Mailbox[];
setSender(input: MailboxAddrObject | string, config?: MailboxConfig): Mailbox;
getSender(): Mailbox | undefined;
setRecipients(input: MailboxAddrObject | string | MailboxAddrObject[] | string[], config?: MailboxConfig): Mailbox[];
getRecipients(config?: MailboxConfig): Mailbox | Mailbox[] | undefined;
setRecipient(input: MailboxAddrObject | string | MailboxAddrObject[] | string[], config?: MailboxConfig): Mailbox[];
setTo(input: MailboxAddrObject | string | MailboxAddrObject[] | string[], config?: MailboxConfig): Mailbox[];
setCc(input: MailboxAddrObject | string | MailboxAddrObject[] | string[], config?: MailboxConfig): Mailbox[];
setBcc(input: MailboxAddrObject | string | MailboxAddrObject[] | string[], config?: MailboxConfig): Mailbox[];
setSubject(value: string): string;
getSubject(): string | Mailbox | undefined;
setHeader(name: string, value: any): string;
getHeader(name: string): string | Mailbox | undefined;
setHeaders(obj: Record<string, any>): string[];
getSubject(): string | undefined;
setHeader(name: string, value: string | Mailbox | Mailbox[]): string;
getHeader(name: string): string | Mailbox | Mailbox[] | undefined;
setHeaders(obj: Record<string, string | Mailbox | Mailbox[]>): string[];
getHeaders(): HeadersObject;
toBase64(v: string): string;
toBase64WebSafe(v: string): string;
generateBoundaries(): void;
isArray(v: unknown): v is any[];
isArray(v: unknown): v is unknown[];
isObject(v: unknown): v is object;
}
interface EnvironmentContext {
Expand Down Expand Up @@ -149,4 +147,4 @@ declare class MIMETextError extends Error {
constructor(message: string, description?: string);
}

export { type AttachmentOptions as A, type Boundaries as B, type ContentTransferEncoding as C, type EnvironmentContext as E, type HeadersObject as H, MIMEMessage as M, Mailbox as a, MIMETextError as b, MIMEMessageHeader as c, MIMEMessageContent as d, type ContentHeaders as e, type ContentOptions as f, type MailboxConfig as g, type MailboxAddrObject as h, type MailboxType as i, type Email as j, type MailboxAddrText as k, MIMEMessageContentHeader as l, type HeaderField as m };
export { type AttachmentOptions as A, type Boundaries as B, type ContentTransferEncoding as C, type EnvironmentContext as E, type HeadersObject as H, MIMEMessage as M, Mailbox as a, MIMETextError as b, MIMEMessageHeader as c, MIMEMessageContent as d, type ContentHeaders as e, type ContentOptions as f, type MailboxConfig as g, type MailboxAddrObject as h, type MailboxType as i, MIMEMessageContentHeader as j, type HeaderField as k };
Loading

0 comments on commit 6b616af

Please sign in to comment.