1.0.2 • Published 11 months ago

email-value v1.0.2

Weekly downloads
-
License
MIT
Repository
github
Last release
11 months ago

Email

The Email interface is used to parse, construct, normalize, and encode emails. It works by providing properties which allow you to easily read and modify the components of an Email.

You normally create a new Email object by specifying the Email as a string when calling its constructor, or by providing a base Email. You can then easily read the parsed components of the Email or make changes to the Email.

Constructor

Properties

Methods

Usage notes

The constructor takes an email parameter.

let email = new Email("username@domain.tld");
console.log(email.hostname); // "domain.tld"
console.log(email.username); // "username"

Email properties can be set to construct the Email:

email.hostname = "example.app";
console.log(email.toString()); // "username@example.app"

The toString() method of Email just returns the email address as a string, so the constructor can be used to normalize and encode an email directly.

The toJSON() method of Email just returns the same value of toString(), so the constructor can be used inside JSON.stringify safely and you'll get a string with the email address.

JSON.stringify({ email }); // "{\"email\":\"username@example.app\"}"