function parse(str) {
  let index = str.indexOf(";");
  const type = index !== -1 ? str.substr(0, index).trim() : str.trim();
  if (!TYPE_REGEXP.test(type)) {
    throw new TypeError("invalid media type");
  }
  const obj = new ContentTypeImpl(type.toLowerCase());
  // parse parameters
  if (index !== -1) {
    let key;
    let match;
    let value;
    PARAM_REGEXP.lastIndex = index;
    while (match = PARAM_REGEXP.exec(str)) {
      if (match.index !== index) {
        throw new TypeError("invalid parameter format");
      }
      index += match[0].length;
      key = match[1].toLowerCase();
      value = match[2];
      if (value[0] === '"') {
        // remove quotes and escapes
        value = value.substr(1, value.length - 2).replace(QESC_REGEXP, "$1");
      }
      obj.parameters[key] = value;
    }
    if (index !== str.length) {
      throw new TypeError("invalid parameter format");
    }
  }
  return obj;
}
/**
 * Parse media type to object.
 */
Parse media type to object.
Parse media type to object .
function parse(str) {
  let index = str.indexOf(";");
  const type = index !== -1 ? str.substr(0, index).trim() : str.trim();
  if (!TYPE_REGEXP.test(type)) {
    throw new TypeError("invalid media type");
  }
  const obj = new ContentTypeImpl(type.toLowerCase());
  if (index !== -1) {
    let key;
    let match;
    let value;
    PARAM_REGEXP.lastIndex = index;
    while (match = PARAM_REGEXP.exec(str)) {
      if (match.index !== index) {
        throw new TypeError("invalid parameter format");
      }
      index += match[0].length;
      key = match[1].toLowerCase();
      value = match[2];
      if (value[0] === '"') {
        value = value.substr(1, value.length - 2).replace(QESC_REGEXP, "$1");
      }
      obj.parameters[key] = value;
    }
    if (index !== str.length) {
      throw new TypeError("invalid parameter format");
    }
  }
  return obj;
}
function parse ( str ) { let index = str . indexOf ( ";" ) ; const type = index !== - 1 ? str . substr ( 0 , index ) . trim ( ) : str . trim ( ) ; if ( ! TYPE_REGEXP . test ( type ) ) { throw new TypeError ( "invalid media type" ) ; } const obj = new ContentTypeImpl ( type . toLowerCase ( ) ) ; if ( index !== - 1 ) { let key ; let match ; let value ; PARAM_REGEXP . lastIndex = index ; while ( match = PARAM_REGEXP . exec ( str ) ) { if ( match . index !== index ) { throw new TypeError ( "invalid parameter format" ) ; } index += match [ 0 ] . length ; key = match [ 1 ] . toLowerCase ( ) ; value = match [ 2 ] ; if ( value [ 0 ] === '"' ) { value = value . substr ( 1 , value . length - 2 ) . replace ( QESC_REGEXP , "$1" ) ; } obj . parameters [ key ] = value ; } if ( index !== str . length ) { throw new TypeError ( "invalid parameter format" ) ; } } return obj ; }
Parse media type to object.
Parse media type to object .
// parse parameters // remove quotes and escapes