mirror of
https://github.com/datahub-project/datahub.git
synced 2025-07-26 19:10:15 +00:00
23 lines
810 B
TypeScript
23 lines
810 B
TypeScript
![]() |
import { arrayReduce } from 'wherehows-web/utils/array';
|
||
|
import buildUrl from 'wherehows-web/utils/build-url';
|
||
|
import { IMailHeaderRecord, MailerHeaderValue } from 'wherehows-web/typings/app/helpers/email';
|
||
|
|
||
|
/**
|
||
|
* Constructs a `mailto:` address with supplied email headers as query parameters
|
||
|
* @param {IMailHeaderRecord} [headers={}]
|
||
|
* @returns {string}
|
||
|
*/
|
||
|
const buildMailToUrl = (headers: IMailHeaderRecord = {}): string => {
|
||
|
const { to = '', ...otherHeaders } = headers;
|
||
|
const [...otherHeaderPairs] = Object.entries(otherHeaders);
|
||
|
const mailTo = `mailto:${to}`;
|
||
|
|
||
|
return arrayReduce(
|
||
|
(mailTo: string, [headerName, headerValue = '']: [string, MailerHeaderValue]) =>
|
||
|
buildUrl(mailTo, headerName, String(headerValue)),
|
||
|
mailTo
|
||
|
)([...otherHeaderPairs]);
|
||
|
};
|
||
|
|
||
|
export { buildMailToUrl };
|