function decodeContentType(body, type, encoding) {
  switch (type) {
    case 'application/x-www-form-urlencoded':
      bodySplit = body.split('&');
      body = {};
      bodySplit.forEach(entry => {
        entry = entry.split('=');
        body[decodeVal(entry[0])] = decodeVal(entry[1]);
      });
      break;
    case 'text/plain':
      if (encoding) {
        // Converts from base64 to string, recommended over atob() in Node.js
        body = Buffer.from(body, 'base64').toString('utf-8');
      }
      bodySplit = body.split(',');
      body = {};
      bodySplit.forEach(entry => {
        entry = entry.split('=');
        body[decodeVal(entry[0])] = decodeVal(entry[1]);
      });
      break;
    case 'text/xml':
      body = parseXML.parse(body).vote;
      body.comment = decodeURIComponent(body.comment);
      break;
    case 'application/json':
      body = JSON.parse(body);
      body.comment = decodeURIComponent(body.comment);
      break;
    case 'text/x-yaml':
      body = YAML.parse(body);
      body.comment = decodeURIComponent(body.comment);
      break;
  }
  // Make sure the rating is of type number
  body.rating = Number(body.rating);
  return body;
}
/**
 * Decodes the given body with the given parameters and returns a parsed object
 * @param {string} body the body of the request that was received
 * @param {string} type the content-type of the body
 * @param {string} encoding (optional) if the string isn't UTF-8, this is what
 *                          the string is encoded as (e.g. 'base64')
 * @returns {object} The parsed version of the given body
 */
Decodes the given body with the given parameters and returns a parsed object
@param {string} body the body of the request that was received
@param {string} type the content-type of the body
@param {string} encoding (optional) if the string isn't UTF-8, this is what
the string is encoded as
@returns {object} The parsed version of the given body
Decodes the given body with the given parameters and returns a parsed object @param { string } body the body of the request that was received @param { string } type the content - type of the body @param { string } encoding ( optional ) if the string isn ' t UTF - 8 this is what the string is encoded as @returns { object } The parsed version of the given body
function decodeContentType(body, type, encoding) {
  switch (type) {
    case 'application/x-www-form-urlencoded':
      bodySplit = body.split('&');
      body = {};
      bodySplit.forEach(entry => {
        entry = entry.split('=');
        body[decodeVal(entry[0])] = decodeVal(entry[1]);
      });
      break;
    case 'text/plain':
      if (encoding) {
        body = Buffer.from(body, 'base64').toString('utf-8');
      }
      bodySplit = body.split(',');
      body = {};
      bodySplit.forEach(entry => {
        entry = entry.split('=');
        body[decodeVal(entry[0])] = decodeVal(entry[1]);
      });
      break;
    case 'text/xml':
      body = parseXML.parse(body).vote;
      body.comment = decodeURIComponent(body.comment);
      break;
    case 'application/json':
      body = JSON.parse(body);
      body.comment = decodeURIComponent(body.comment);
      break;
    case 'text/x-yaml':
      body = YAML.parse(body);
      body.comment = decodeURIComponent(body.comment);
      break;
  }
  body.rating = Number(body.rating);
  return body;
}
function decodeContentType ( body , type , encoding ) { switch ( type ) { case 'application/x-www-form-urlencoded' : bodySplit = body . split ( '&' ) ; body = { } ; bodySplit . forEach ( entry => { entry = entry . split ( '=' ) ; body [ decodeVal ( entry [ 0 ] ) ] = decodeVal ( entry [ 1 ] ) ; } ) ; break ; case 'text/plain' : if ( encoding ) { body = Buffer . from ( body , 'base64' ) . toString ( 'utf-8' ) ; } bodySplit = body . split ( ',' ) ; body = { } ; bodySplit . forEach ( entry => { entry = entry . split ( '=' ) ; body [ decodeVal ( entry [ 0 ] ) ] = decodeVal ( entry [ 1 ] ) ; } ) ; break ; case 'text/xml' : body = parseXML . parse ( body ) . vote ; body . comment = decodeURIComponent ( body . comment ) ; break ; case 'application/json' : body = JSON . parse ( body ) ; body . comment = decodeURIComponent ( body . comment ) ; break ; case 'text/x-yaml' : body = YAML . parse ( body ) ; body . comment = decodeURIComponent ( body . comment ) ; break ; } body . rating = Number ( body . rating ) ; return body ; }
Decodes the given body with the given parameters and returns a parsed object
 @param {string} body the body of the request that was received
 @param {string} type the content-type of the body
 @param {string} encoding (optional) if the string isn't UTF-8, this is what
                          the string is encoded as (e.g.
Decodes the given body with the given parameters and returns a parsed object @param { string } body the body of the request that was received @param { string } type the content - type of the body @param { string } encoding ( optional ) if the string isn ' t UTF - 8 this is what the string is encoded as ( e . g .
// Converts from base64 to string, recommended over atob() in Node.js // Make sure the rating is of type number