dist/optimal-select.js
/**
 * # Match
 *
 * Retrieve selector for a node.
 */
# Match
Retrieve selector for a node.
# Match Retrieve selector for a node .
function match(node, options) {
  var _options$root = options.root,
      root = _options$root === undefined ? document : _options$root,
      _options$skip = options.skip,
      skip = _options$skip === undefined ? null : _options$skip,
      _options$priority = options.priority,
      priority = _options$priority === undefined ? ['id', 'class', 'href', 'src'] : _options$priority,
      _options$ignore = options.ignore,
      ignore = _options$ignore === undefined ? {} : _options$ignore;
  var path = [];
  var element = node;
  var length = path.length;
  var ignoreClass = false;
  var skipCompare = skip && (Array.isArray(skip) ? skip : [skip]).map(function (entry) {
    if (typeof entry !== 'function') {
      return function (element) {
        return element === entry;
      };
    }
    return entry;
  });
  var skipChecks = function skipChecks(element) {
    return skip && skipCompare.some(function (compare) {
      return compare(element);
    });
  };
  Object.keys(ignore).forEach(function (type) {
    if (type === 'class') {
      ignoreClass = true;
    }
    var predicate = ignore[type];
    if (typeof predicate === 'function') return;
    if (typeof predicate === 'number') {
      predicate = predicate.toString();
    }
    if (typeof predicate === 'string') {
      predicate = new RegExp((0, _utilities.escapeValue)(predicate).replace(/\\/g, '\\\\'));
    }
    if (typeof predicate === 'boolean') {
      predicate = predicate ? /(?:)/ : /.^/;
    }
    ignore[type] = function (name, value) {
      return predicate.test(value);
    };
  });
  if (ignoreClass) {
    (function () {
      var ignoreAttribute = ignore.attribute;
      ignore.attribute = function (name, value, defaultPredicate) {
        return ignore.class(value) || ignoreAttribute && ignoreAttribute(name, value, defaultPredicate);
      };
    })();
  }
  while (element !== root) {
    if (skipChecks(element) !== true) {
      if (checkAttributes(priority, element, ignore, path, root)) break;
      if (checkTag(element, ignore, path, root)) break;
      checkAttributes(priority, element, ignore, path);
      if (path.length === length) {
        checkTag(element, ignore, path);
      }
      if (path.length === length) {
        checkChilds(priority, element, ignore, path);
      }
    }
    element = element.parentNode;
    length = path.length;
  }
  if (element === root) {
    var pattern = findPattern(priority, element, ignore);
    path.unshift(pattern);
  }
  return path.join(' ');
}
function match ( node , options ) { var _options$root = options . root , root = _options$root === undefined ? document : _options$root , _options$skip = options . skip , skip = _options$skip === undefined ? null : _options$skip , _options$priority = options . priority , priority = _options$priority === undefined ? [ 'id' , 'class' , 'href' , 'src' ] : _options$priority , _options$ignore = options . ignore , ignore = _options$ignore === undefined ? { } : _options$ignore ; var path = [ ] ; var element = node ; var length = path . length ; var ignoreClass = false ; var skipCompare = skip && ( Array . isArray ( skip ) ? skip : [ skip ] ) . map ( function ( entry ) { if ( typeof entry !== 'function' ) { return function ( element ) { return element === entry ; } ; } return entry ; } ) ; var skipChecks = function skipChecks ( element ) { return skip && skipCompare . some ( function ( compare ) { return compare ( element ) ; } ) ; } ; Object . keys ( ignore ) . forEach ( function ( type ) { if ( type === 'class' ) { ignoreClass = true ; } var predicate = ignore [ type ] ; if ( typeof predicate === 'function' ) return ; if ( typeof predicate === 'number' ) { predicate = predicate . toString ( ) ; } if ( typeof predicate === 'string' ) { predicate = new RegExp ( ( 0 , _utilities . escapeValue ) ( predicate ) . replace ( / \\ / g , '\\\\' ) ) ; } if ( typeof predicate === 'boolean' ) { predicate = predicate ? / (?:) / : / .^ / ; } ignore [ type ] = function ( name , value ) { return predicate . test ( value ) ; } ; } ) ; if ( ignoreClass ) { ( function ( ) { var ignoreAttribute = ignore . attribute ; ignore . attribute = function ( name , value , defaultPredicate ) { return ignore . class ( value ) || ignoreAttribute && ignoreAttribute ( name , value , defaultPredicate ) ; } ; } ) ( ) ; } while ( element !== root ) { if ( skipChecks ( element ) !== true ) { if ( checkAttributes ( priority , element , ignore , path , root ) ) break ; if ( checkTag ( element , ignore , path , root ) ) break ; checkAttributes ( priority , element , ignore , path ) ; if ( path . length === length ) { checkTag ( element , ignore , path ) ; } if ( path . length === length ) { checkChilds ( priority , element , ignore , path ) ; } } element = element . parentNode ; length = path . length ; } if ( element === root ) { var pattern = findPattern ( priority , element , ignore ) ; path . unshift ( pattern ) ; } return path . join ( ' ' ) ; }
# Match
 Retrieve selector for a node.
# Match Retrieve selector for a node .
// check class-/attributename for regex // ~ global // ~ local // define only one part each iteration