From b99c1b27d02f427a435fa76cb53046352069d696 Mon Sep 17 00:00:00 2001 From: bot-implementer Date: Tue, 25 Aug 2026 10:45:17 +0000 Subject: [PATCH] feat: add pure mailto URL builder --- js/mailto.js | 15 +++++++++++++++ 1 file changed, 15 insertions(+) create mode 100644 js/mailto.js diff --git a/js/mailto.js b/js/mailto.js new file mode 100644 index 0000000..d353119 --- /dev/null +++ b/js/mailto.js @@ -0,0 +1,15 @@ +/** + * Build a `mailto:` URL from an address, subject, and body. + * Subject and body are URL-encoded so the visitor's mail client + * opens pre-filled with the submitted values. + * + * @param {{to?: string, subject?: string, body?: string}} options + * @returns {string} + */ +export function buildMailtoUrl({ to = "", subject = "", body = "" } = {}) { + const params = new URLSearchParams(); + if (subject) params.set("subject", subject); + if (body) params.set("body", body); + const query = params.toString(); + return query ? `mailto:${to}?${query}` : `mailto:${to}`; +}