UNPKG

caniemail

Version:

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

68 lines 2.2 kB
import { getProperty } from 'dot-prop'; import onetime from 'onetime'; import { getSupportType } from './clients.js'; import { caniEmailJson } from './json.js'; export { caniEmailJson as rawData }; export class FeatureMap extends Map { // @ts-ignore set(key, value) { const values = super.get(key) || []; values.push(value); super.set(key, values); return this; } } export const getFeatures = onetime(() => { const all = new Map(); const css = new Map(); const html = new Map(); const image = new Map(); const others = new Map(); for (const bit of caniEmailJson.data) { all.set(bit.title, bit); if (bit.category === 'css') css.set(bit.title, bit); if (bit.category === 'html') html.set(bit.title, bit); if (bit.category === 'image') image.set(bit.title, bit); if (bit.category === 'others') others.set(bit.title, bit); } return { all, css, html, image, others }; }); export const getAllFeatures = (clients) => { const results = { supported: new FeatureMap(), unsupported: new FeatureMap() }; const { all: features } = getFeatures(); for (const [, feature] of features) { const { stats, title, url } = feature; for (const client of clients) { const supportMap = getProperty(stats, client); // eslint-disable-next-line no-continue if (supportMap === void 0) continue; const supportStatus = getSupportType(supportMap); const notes = (supportStatus.noteNumbers ?? []) .map((noteNumber) => feature.notes_by_num?.[String(noteNumber)]) .filter((note) => note !== undefined); const support = supportStatus.type; if (support === 'none') { results.unsupported.set(client, { notes, support, title, url }); } else { results.supported.set(client, { notes, support, title, url }); } } } return results; }; //# sourceMappingURL=features.js.map