isUnicodeRangeDescriptor.mjs 553 B

123456789101112131415161718192021222324
  1. import { isAtRule } from './typeGuards.mjs';
  2. const IS_UNICODE_RANGE = /^unicode-range$/i;
  3. const IS_AT_FONT_FACE = /^font-face$/i;
  4. /**
  5. * Check whether a declaration is the `unicode-range` descriptor of an `@font-face` rule.
  6. *
  7. * @param {import('postcss').Declaration} decl
  8. * @returns {boolean}
  9. */
  10. export default function isUnicodeRangeDescriptor(decl) {
  11. if (!IS_UNICODE_RANGE.test(decl.prop)) {
  12. return false;
  13. }
  14. const parent = decl.parent;
  15. if (!parent || !isAtRule(parent)) {
  16. return false;
  17. }
  18. return IS_AT_FONT_FACE.test(parent.name);
  19. }