保誠-保戶業務員媒合平台
HelenHuang
2022-06-09 9bdb95c9e34cef640534e5e5a1e2225a80442000
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
 
var processSelectors = require('./process-selectors');
 
/**
 * Returns the matches of the first capture group in the given regular
 * expression in the specified rules (AST), without repetition
 *
 * @example
 * var rules = getRulesFromCode('[href] { background: red }');
 * var regexp = /\[(\w+)\]/g; // Notice the parenthesis!
 * selectorUniqueMatches(rules, regexp);
 * //> ['href']
 *
 * @param  {Object[]} rules
 * @param  {RegExp} regexp
 * @return {string[]}
 */
function selectorUniqueMatches(rules, regexp) {
  var resultSet = {};
  processSelectors(rules, function(selector) {
    var match;
    while (!!(match = regexp.exec(selector))) {
      resultSet[match[1]] = true;
    }
  });
  return Object.keys(resultSet);
}
 
module.exports = selectorUniqueMatches;