UNPKG

caniemail

Version:

HTML and CSS Feature Support for Email Clients from caniemail.com

42 lines 1.63 kB
import { checkStylesheet } from './checks/check-css.js'; import { checkHtml } from './checks/check-html.js'; import { parseClients } from './clients.js'; import { FeatureMap } from './features.js'; import { parseCss, parseHtml } from './helpers.js'; export * from './helpers.js'; export { getAllFeatures, rawData } from './features.js'; export const caniemail = ({ clients: globs, css, html }) => { if (!css && !html) throw new RangeError('Please provide either `code` or `html` options'); let document = null; let stylesheets = []; const clients = parseClients(globs); const issues = { errors: new FeatureMap(), warnings: new FeatureMap() }; if (!clients.length) throw new RangeError(`The specified email client(s) (${globs.join(', ')}) were not found`); if (css) stylesheets.push(parseCss(css)); if (html) ({ document, stylesheets } = parseHtml(html)); for (const stylesheet of stylesheets) checkStylesheet({ clients, issues, stylesheet }); if (document) checkHtml({ clients, document, issues, source: html }); return { issues, success: issues.errors.size === 0 }; }; export const formatIssue = ({ client, issue, issueType }) => { const { notes, title } = issue; return { message: issueType === 'error' ? `\`${title}\` is not supported by \`${client}\`` : `\`${title}\` is only partially supported by \`${client}\``, notes: notes.map((note) => `Note about \`${title}\` support for \`${client}\`: ${note}`) }; }; //# sourceMappingURL=index.js.map