src/match.js
function findAttributesPattern (priority, element, ignore) {
  const attributes = element.attributes
  const sortedKeys = Object.keys(attributes).sort((curr, next) => {
    const currPos = priority.indexOf(attributes[curr].name)
    const nextPos = priority.indexOf(attributes[next].name)
    if (nextPos === -1) {
      if (currPos === -1) {
        return 0
      }
      return -1
    }
    return currPos - nextPos
  })

  for (var i = 0, l = sortedKeys.length; i < l; i++) {
    const key = sortedKeys[i]
    const attribute = attributes[key]
    const attributeName = attribute.name
    const attributeValue = escapeValue(attribute.value)

    const currentIgnore = ignore[attributeName] || ignore.attribute
    const currentDefaultIgnore = defaultIgnore[attributeName] || defaultIgnore.attribute
    if (checkIgnore(currentIgnore, attributeName, attributeValue, currentDefaultIgnore)) {
      continue
    }

    var pattern = `[${attributeName}="${attributeValue}"]`

    if ((/\b\d/).test(attributeValue) === false) {
      if (attributeName === 'id') {
        pattern = `#${attributeValue}`
      }

      if (attributeName === 'class') {
        const className = attributeValue.trim().replace(/\s+/g, '.')
        pattern = `.${className}`
      }
    }

    return pattern
  }
  return null
}
function findAttributesPattern (priority, element, ignore) {
  const attributes = element.attributes
  const sortedKeys = Object.keys(attributes).sort((curr, next) => {
    const currPos = priority.indexOf(attributes[curr].name)
    const nextPos = priority.indexOf(attributes[next].name)
    if (nextPos === -1) {
      if (currPos === -1) {
        return 0
      }
      return -1
    }
    return currPos - nextPos
  })

  for (var i = 0, l = sortedKeys.length; i < l; i++) {
    const key = sortedKeys[i]
    const attribute = attributes[key]
    const attributeName = attribute.name
    const attributeValue = escapeValue(attribute.value)

    const currentIgnore = ignore[attributeName] || ignore.attribute
    const currentDefaultIgnore = defaultIgnore[attributeName] || defaultIgnore.attribute
    if (checkIgnore(currentIgnore, attributeName, attributeValue, currentDefaultIgnore)) {
      continue
    }

    var pattern = `[${attributeName}="${attributeValue}"]`

    if ((/\b\d/).test(attributeValue) === false) {
      if (attributeName === 'id') {
        pattern = `#${attributeValue}`
      }

      if (attributeName === 'class') {
        const className = attributeValue.trim().replace(/\s+/g, '.')
        pattern = `.${className}`
      }
    }

    return pattern
  }
  return null
}
function findAttributesPattern ( priority , element , ignore ) { const attributes = element . attributes const sortedKeys = Object . keys ( attributes ) . sort ( ( curr , next ) => { const currPos = priority . indexOf ( attributes [ curr ] . name ) const nextPos = priority . indexOf ( attributes [ next ] . name ) if ( nextPos === - 1 ) { if ( currPos === - 1 ) { return 0 } return - 1 } return currPos - nextPos } ) for ( var i = 0 , l = sortedKeys . length ; i < l ; i ++ ) { const key = sortedKeys [ i ] const attribute = attributes [ key ] const attributeName = attribute . name const attributeValue = escapeValue ( attribute . value ) const currentIgnore = ignore [ attributeName ] || ignore . attribute const currentDefaultIgnore = defaultIgnore [ attributeName ] || defaultIgnore . attribute if ( checkIgnore ( currentIgnore , attributeName , attributeValue , currentDefaultIgnore ) ) { continue } var pattern = ` ${ attributeName } ${ attributeValue } ` if ( ( / \b\d / ) . test ( attributeValue ) === false ) { if ( attributeName === 'id' ) { pattern = ` ${ attributeValue } ` } if ( attributeName === 'class' ) { const className = attributeValue . trim ( ) . replace ( / \s+ / g , '.' ) pattern = ` ${ className } ` } } return pattern } return null }
Lookup attribute identifier

@param  {Array.<string>} priority - [description]
@param  {HTMLElement}    element  - [description]
@param  {Object}         ignore   - [description]
@return {string?}                 - [description]
Lookup attribute identifier