src/index.js
/**
 * Parse a range to form a "quality weights" list.
 *
 * @param {String} range A range string to languagePriorityList
 * @return {Array<Object>} A Language Priority List
 */
Parse a range to form a "quality weights" list.
@param {String} range A range string to languagePriorityList
@return {Array} A Language Priority List
Parse a range to form a " quality weights " list . @param { String } range A range string to languagePriorityList @return { Array } A Language Priority List
function languagePriorityList(range) {
  function extractTag(rangeTag) {
    const ensureParsedValue = v => (v < 1 ? v : 1);
    const extractQuality = q => (q ? ensureParsedValue(parseFloat(q.split('q=')[1])) : 1);
    const matches = rangeTag.match(/^\s*([^\s\-;]+)(?:-([^\s;]+))?\s*(?:;(.*))?$/);
    if (!matches) return undefined;
    return { tag: matches[2] ? [matches[1], matches[2]].join('-') : matches[1], quality: extractQuality(matches[3]) };
  }
  return isString(range)
    ? range
        .split(',')
        .map(extractTag)
        .filter(isObject)
        .sort(rangeSort)
    : DEFAULT_WILDCARD;
}
function languagePriorityList ( range ) { function extractTag ( rangeTag ) { const ensureParsedValue = v => ( v < 1 ? v : 1 ) ; const extractQuality = q => ( q ? ensureParsedValue ( parseFloat ( q . split ( 'q=' ) [ 1 ] ) ) : 1 ) ; const matches = rangeTag . match ( / ^\s*([^\s\-;]+)(?:-([^\s;]+))?\s*(?:;(.*))?$ / ) ; if ( ! matches ) return undefined ; return { tag : matches [ 2 ] ? [ matches [ 1 ] , matches [ 2 ] ] . join ( '-' ) : matches [ 1 ] , quality : extractQuality ( matches [ 3 ] ) } ; } return isString ( range ) ? range . split ( ',' ) . map ( extractTag ) . filter ( isObject ) . sort ( rangeSort ) : DEFAULT_WILDCARD ; }
Parse a range to form a "quality weights" list.
Parse a range to form a " quality weights " list .