stylelint
Version:
A mighty CSS linter that helps you avoid errors and enforce conventions.
39 lines (29 loc) • 637 B
JavaScript
import valueParser from 'postcss-value-parser';
import { fontSizeKeywords } from '../reference/keywords.mjs';
import { lengthUnits } from '../reference/units.mjs';
/**
* Check if a word is a font-size value.
*
* @param {string} word
* @returns {boolean}
*/
export default function isValidFontSize(word) {
if (!word) {
return false;
}
if (fontSizeKeywords.has(word)) {
return true;
}
const numberUnit = valueParser.unit(word);
if (!numberUnit) {
return false;
}
const unit = numberUnit.unit;
if (unit === '%') {
return true;
}
if (lengthUnits.has(unit.toLowerCase())) {
return true;
}
return false;
}