extract-classes-from-rules.js 591 B

1234567891011121314151617181920212223
  1. var cssHelpers = require('./css-helpers');
  2. var selectorUniqueMatches = require('./selector-unique-matches');
  3. /**
  4. * dot followed by an identifier
  5. * @type {RegExp}
  6. */
  7. var rClassInSelector = new RegExp('\\.(' + cssHelpers.rIdentifier.source + ')',
  8. 'gm');
  9. /**
  10. * Extracts classes from CSS rules (as AST)
  11. * @param {Object} rules
  12. * @return {string[]} list of ids in those rules
  13. */
  14. function extractClassesFromRules(rules) {
  15. var classes = selectorUniqueMatches(rules, rClassInSelector);
  16. return classes.map(cssHelpers.unescapeIdentifier);
  17. }
  18. module.exports = extractClassesFromRules;