index.js
function factory(check, filter) {
  return match

  function match(tags, ranges) {
    var values = normalize(tags, ranges)
    var result = []
    var next
    var tagIndex
    var tagLength
    var tag
    var rangeIndex
    var rangeLength
    var range
    var matches

    tags = values.tags
    ranges = values.ranges
    rangeLength = ranges.length
    rangeIndex = -1

    while (++rangeIndex < rangeLength) {
      range = ranges[rangeIndex]

      // Ignore wildcards in lookup mode.
      if (!filter && range === asterisk) {
        continue
      }

      tagLength = tags.length
      tagIndex = -1
      next = []

      while (++tagIndex < tagLength) {
        tag = tags[tagIndex]
        matches = check(tag, range)
        ;(matches ? result : next).push(tag)

        // Exit if this is a lookup and we have a match.
        if (!filter && matches) {
          return tag
        }
      }

      tags = next
    }

    // If this is a filter, return the list.  If it’s a lookup, we didn’t find
    // a match, so return `undefined`.
    return filter ? result : undefined
  }
}
function factory(check, filter) {
  return match

  function match(tags, ranges) {
    var values = normalize(tags, ranges)
    var result = []
    var next
    var tagIndex
    var tagLength
    var tag
    var rangeIndex
    var rangeLength
    var range
    var matches

    tags = values.tags
    ranges = values.ranges
    rangeLength = ranges.length
    rangeIndex = -1

    while (++rangeIndex < rangeLength) {
      range = ranges[rangeIndex]

      // Ignore wildcards in lookup mode.
      if (!filter && range === asterisk) {
        continue
      }

      tagLength = tags.length
      tagIndex = -1
      next = []

      while (++tagIndex < tagLength) {
        tag = tags[tagIndex]
        matches = check(tag, range)
        ;(matches ? result : next).push(tag)

        // Exit if this is a lookup and we have a match.
        if (!filter && matches) {
          return tag
        }
      }

      tags = next
    }

    // If this is a filter, return the list.  If it’s a lookup, we didn’t find
    // a match, so return `undefined`.
    return filter ? result : undefined
  }
}
function factory ( check , filter ) { return match function match ( tags , ranges ) { var values = normalize ( tags , ranges ) var result = [ ] var next var tagIndex var tagLength var tag var rangeIndex var rangeLength var range var matches tags = values . tags ranges = values . ranges rangeLength = ranges . length rangeIndex = - 1 while ( ++ rangeIndex < rangeLength ) { range = ranges [ rangeIndex ] // Ignore wildcards in lookup mode. if ( ! filter && range === asterisk ) { continue } tagLength = tags . length tagIndex = - 1 next = [ ] while ( ++ tagIndex < tagLength ) { tag = tags [ tagIndex ] matches = check ( tag , range ) ; ( matches ? result : next ) . push ( tag ) // Exit if this is a lookup and we have a match. if ( ! filter && matches ) { return tag } } tags = next } // If this is a filter, return the list.  If it’s a lookup, we didn’t find // a match, so return `undefined`. return filter ? result : undefined } }
Factory to perform a filter or a lookup. This factory creates a function that accepts a list of tags and a list of ranges, and contains logic to exit early for lookups. `check` just has to deal with one tag and one range. This match function iterates over ranges, and for each range, iterates over tags.  That way, earlier ranges matching any tag have precedence over later ranges.
Factory to perform a filter or a lookup . This factory creates a function that accepts a list of tags and a list of ranges and contains logic to exit early for lookups . check just has to deal with one tag and one range . This match function iterates over ranges and for each range iterates over tags . That way earlier ranges matching any tag have precedence over later ranges .