MailTo

npm Build Status Coverage Status

Replaces obscured element with a mailto link

Install

npm install @threespot/mailto

Mailto uses the data-email attribute of an element and converts them to mailto links. It uses the value of that attribute as the email address. Inner HTML is preserved and any occurrences of [at] are converted to @.

Exmaple:

<span data-email="hello[at]threespot.com">Contact Us</span>

Becomes:

<a href="mailto:hello@threespot.com">Contact Us</a>

Works with inner HTML

Exmaple:

<span data-email="hello[at]threespot.com">
  <b>hello[at]threespot.com</b>
</span>

Becomes:

<a href="mailto:hello@threespot.com">
  <b>hello@threespot.com</b>
</a>

Usage

html

<span id="mailtoLink" data-email="hello[at]threespot.com">Contact Us</span>

js

import MailToLink from "@threespot/mailto";

const linkElem = document.getElementById("mailtoLink");

new MailToLink(linkElem);

License

Mailto is free software, and may be redistributed under the terms of the MIT license.

About Threespot

Threespot is a design and development agency from Washington, DC. We work for organizations that we believe are making a positive change in the world. Find out more about us, our projects or hire us!

Threespot