extract-ids-from-rules.js 571 B

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