UNPKG

555 BJavaScriptView Raw
1var utils = require('../utils');
2
3/**
4 * Returns true if the given selector exists.
5 *
6 * @param {String} sel
7 * @return {Boolean}
8 * @api public
9 */
10
11function selectorExists(sel) {
12 utils.assertString(sel, 'selector');
13
14 if (!this.__selectorsMap__) {
15 var Normalizer = require('../visitor/normalizer')
16 , visitor = new Normalizer(this.root.clone());
17 visitor.visit(visitor.root);
18
19 this.__selectorsMap__ = visitor.map;
20 }
21
22 return sel.string in this.__selectorsMap__;
23}
24selectorExists.params = ['sel'];
25module.exports = selectorExists;