UNPKG

postcss-color-emoji

Version:
39 lines (31 loc) 918 B
'use strict'; /** * Takes an array of font names and returns a font family string * @param {Array} array - Array of font names * @returns {string} */ function createFontFamilyString(array) { return array.map(font => { const hasWhiteSpace = /\s/g.test(font); if (hasWhiteSpace) { return `"${font}"`; } return font; }).join(', '); } const COLOR_EMOJI_FONTS = createFontFamilyString(['Apple Color Emoji', // macOS 'Segoe UI Emoji', // Windows 'Segoe UI Symbol', // Windows 'Noto Color Emoji' // Linux ]); var index = (() => ({ postcssPlugin: 'postcss-color-emoji', Once(root) { root.walkDecls( // Match custom properties (`--custom-property`), `font`, and `font-family` /(?:^(?:-|\\002d){2})|(?:^font(?:-family)?$)/i, decl => { decl.value = decl.value.replace(/color-emoji/, COLOR_EMOJI_FONTS); }); } })); module.exports = index; module.exports.postcss = true