/
githubmirror
/
hexo
Обзор
Документация
Войти
/
githubmirror
/
hexo
Код
Запросы
0
Пакеты
0
Релизы
0
Аналитика
Безопасность
master
lib/plugins/helper/mail_to.ts
60 строк
1 KB
D-Sketon
refactor: migrate typescript (#5417)
03 мар 2024, 11:04
Не верифицирован
03 мар 2024, 11:04
3c7729d
Код
Авторство
О чём код?
import { htmlTag } from 'hexo-util'; import moize from 'moize'; interface Options { href?: string; title?: string; class?: string | string[]; subject?: string; cc?: string | string[]; bcc?: string | string[]; id?: string; body?: string; } interface Attrs { href: string; title: string; class?: string; subject?: string; cc?: string; bcc?: string; id?: string; body?: string; [key: string]: any; } function mailToHelper(path: string | string[], text?: string, options: Options = {}) { if (Array.isArray(path)) path = path.join(','); if (!text) text = path; const attrs = Object.assign({ href: `mailto:${path}`, title: text }, options); if (attrs.class && Array.isArray(attrs.class)) { attrs.class = attrs.class.join(' '); } const data = {}; ['subject', 'cc', 'bcc', 'body'].forEach(i => { const item = attrs[i]; if (item) { data[i] = Array.isArray(item) ? item.join(',') : item; attrs[i] = null; } }); const querystring = new URLSearchParams(data).toString(); if (querystring) attrs.href += `?${querystring}`; return htmlTag('a', attrs as Attrs, text); } export = moize(mailToHelper, { maxSize: 10, isDeepEqual: true });