isValidFontSize.cjs 822 B

12345678910111213141516171819202122232425262728293031323334353637383940414243
  1. // NOTICE: This file is generated by Rollup. To modify it,
  2. // please instead edit the ESM counterpart and rebuild with Rollup (npm run build).
  3. 'use strict';
  4. const valueParser = require('postcss-value-parser');
  5. const keywords = require('../reference/keywords.cjs');
  6. const units = require('../reference/units.cjs');
  7. /**
  8. * Check if a word is a font-size value.
  9. *
  10. * @param {string} word
  11. * @returns {boolean}
  12. */
  13. function isValidFontSize(word) {
  14. if (!word) {
  15. return false;
  16. }
  17. if (keywords.fontSizeKeywords.has(word)) {
  18. return true;
  19. }
  20. const numberUnit = valueParser.unit(word);
  21. if (!numberUnit) {
  22. return false;
  23. }
  24. const unit = numberUnit.unit;
  25. if (unit === '%') {
  26. return true;
  27. }
  28. if (units.lengthUnits.has(unit.toLowerCase())) {
  29. return true;
  30. }
  31. return false;
  32. }
  33. module.exports = isValidFontSize;