src/index.js
function getMatchRanking(testString, stringToRank, options) {
  /* eslint complexity:[2, 12] */
  testString = prepareValueForComparison(testString, options)
  stringToRank = prepareValueForComparison(stringToRank, options)

  // too long
  if (stringToRank.length > testString.length) {
    return rankings.NO_MATCH
  }

  // case sensitive equals
  if (testString === stringToRank) {
    return rankings.CASE_SENSITIVE_EQUAL
  }

  const caseRank = getCaseRanking(testString)
  const isPartial = isPartialOfCase(testString, stringToRank, caseRank)
  const isCasedAcronym = isCaseAcronym(testString, stringToRank, caseRank)

  // Lower casing before further comparison
  testString = testString.toLowerCase()
  stringToRank = stringToRank.toLowerCase()

  // case insensitive equals
  if (testString === stringToRank) {
    return rankings.EQUAL + caseRank
  }

  // starts with
  if (testString.indexOf(stringToRank) === 0) {
    return rankings.STARTS_WITH + caseRank
  }

  // word starts with
  if (testString.indexOf(` ${stringToRank}`) !== -1) {
    return rankings.WORD_STARTS_WITH + caseRank
  }

  // is a part inside a cased string
  if (isPartial) {
    return rankings.STRING_CASE + caseRank
  }

  // is acronym for a cased string
  if (caseRank > 0 && isCasedAcronym) {
    return rankings.STRING_CASE_ACRONYM + caseRank
  }

  // contains
  if (testString.indexOf(stringToRank) !== -1) {
    return rankings.CONTAINS + caseRank
  } else if (stringToRank.length === 1) {
    // If the only character in the given stringToRank
    //   isn't even contained in the testString, then
    //   it's definitely not a match.
    return rankings.NO_MATCH
  }

  // acronym
  if (getAcronym(testString).indexOf(stringToRank) !== -1) {
    return rankings.ACRONYM + caseRank
  }

  // will return a number between rankings.MATCHES and
  // rankings.MATCHES + 1 depending  on how close of a match it is.
  return getClosenessRanking(testString, stringToRank)
}
function getMatchRanking(testString, stringToRank, options) {
  /* eslint complexity:[2, 12] */
  testString = prepareValueForComparison(testString, options)
  stringToRank = prepareValueForComparison(stringToRank, options)

  // too long
  if (stringToRank.length > testString.length) {
    return rankings.NO_MATCH
  }

  // case sensitive equals
  if (testString === stringToRank) {
    return rankings.CASE_SENSITIVE_EQUAL
  }

  const caseRank = getCaseRanking(testString)
  const isPartial = isPartialOfCase(testString, stringToRank, caseRank)
  const isCasedAcronym = isCaseAcronym(testString, stringToRank, caseRank)

  // Lower casing before further comparison
  testString = testString.toLowerCase()
  stringToRank = stringToRank.toLowerCase()

  // case insensitive equals
  if (testString === stringToRank) {
    return rankings.EQUAL + caseRank
  }

  // starts with
  if (testString.indexOf(stringToRank) === 0) {
    return rankings.STARTS_WITH + caseRank
  }

  // word starts with
  if (testString.indexOf(` ${stringToRank}`) !== -1) {
    return rankings.WORD_STARTS_WITH + caseRank
  }

  // is a part inside a cased string
  if (isPartial) {
    return rankings.STRING_CASE + caseRank
  }

  // is acronym for a cased string
  if (caseRank > 0 && isCasedAcronym) {
    return rankings.STRING_CASE_ACRONYM + caseRank
  }

  // contains
  if (testString.indexOf(stringToRank) !== -1) {
    return rankings.CONTAINS + caseRank
  } else if (stringToRank.length === 1) {
    // If the only character in the given stringToRank
    //   isn't even contained in the testString, then
    //   it's definitely not a match.
    return rankings.NO_MATCH
  }

  // acronym
  if (getAcronym(testString).indexOf(stringToRank) !== -1) {
    return rankings.ACRONYM + caseRank
  }

  // will return a number between rankings.MATCHES and
  // rankings.MATCHES + 1 depending  on how close of a match it is.
  return getClosenessRanking(testString, stringToRank)
}
function getMatchRanking ( testString , stringToRank , options ) { /* eslint complexity:[2, 12] */ testString = prepareValueForComparison ( testString , options ) stringToRank = prepareValueForComparison ( stringToRank , options ) // too long if ( stringToRank . length > testString . length ) { return rankings . NO_MATCH } // case sensitive equals if ( testString === stringToRank ) { return rankings . CASE_SENSITIVE_EQUAL } const caseRank = getCaseRanking ( testString ) const isPartial = isPartialOfCase ( testString , stringToRank , caseRank ) const isCasedAcronym = isCaseAcronym ( testString , stringToRank , caseRank ) // Lower casing before further comparison testString = testString . toLowerCase ( ) stringToRank = stringToRank . toLowerCase ( ) // case insensitive equals if ( testString === stringToRank ) { return rankings . EQUAL + caseRank } // starts with if ( testString . indexOf ( stringToRank ) === 0 ) { return rankings . STARTS_WITH + caseRank } // word starts with if ( testString . indexOf ( ` ${ stringToRank } ` ) !== - 1 ) { return rankings . WORD_STARTS_WITH + caseRank } // is a part inside a cased string if ( isPartial ) { return rankings . STRING_CASE + caseRank } // is acronym for a cased string if ( caseRank > 0 && isCasedAcronym ) { return rankings . STRING_CASE_ACRONYM + caseRank } // contains if ( testString . indexOf ( stringToRank ) !== - 1 ) { return rankings . CONTAINS + caseRank } else if ( stringToRank . length === 1 ) { // If the only character in the given stringToRank //   isn't even contained in the testString, then //   it's definitely not a match. return rankings . NO_MATCH } // acronym if ( getAcronym ( testString ) . indexOf ( stringToRank ) !== - 1 ) { return rankings . ACRONYM + caseRank } // will return a number between rankings.MATCHES and // rankings.MATCHES + 1 depending  on how close of a match it is. return getClosenessRanking ( testString , stringToRank ) }
Gives a rankings score based on how well the two strings match.
@param {String} testString - the string to test against
@param {String} stringToRank - the string to rank
@param {Object} options - options for the match (like keepDiacritics for comparison)
@returns {Number} the ranking for how well stringToRank matches testString
Gives a rankings score based on how well the two strings match .