import 'whatwg-fetch';

var helpers = {
  checkStatus,
  displayPrice,
  parseJSON,
  headers: {
    'Accept': 'application/json',
    'Content-Type': 'application/json'
  }
};

function checkStatus(res) {
  if (res.status >= 200 && res.status < 300) {
    return res;
  } else {
    var error = new Error(res.statusText);
    error.res = res;
    throw error;
  }
}

function displayPrice(price) {
  if (typeof price === 'string') {
    price = Number(price);
  }

  if (price % 1 === 0) {
    return '$' + price;
  } else {
    return '$' + price.toFixed(2);
  }
}

function parseJSON(res) {
  return res.json();
}

export default helpers;

@@ -15,16 +15,44 @@
 -fetch';
+%0Aimport _ from 'underscore';
 %0A%0Avar he
@@ -61,16 +61,30 @@
 ers = %7B%0A
+  capitalize,%0A
   checkS
@@ -106,16 +106,46 @@
 yPrice,%0A
+  findTypeId,%0A  findTypeName,%0A
   parseJ
@@ -243,16 +243,130 @@
   %7D%0A%7D;%0A%0A
+function capitalize(string) %7B%0A  if (string) %7B%0A    return string.charAt(0).toUpperCase() + string.slice(1);%0A  %7D%0A%7D%0A%0A
 function
@@ -740,23 +740,247 @@
 xed(2);%0A
-
   %7D%0A%7D%0A%0A
+function findTypeId(types, name) %7B%0A  let type = _.findWhere(types, %7B name: name %7D);%0A  return type && type.id;%0A%7D%0A%0Afunction findTypeName(types, id) %7B%0A  let type = _.findWhere(types, %7B id: id %7D);%0A  return type && type.name;%0A%7D%0A%0A
 function

Add findTypeName, findTypeId, and capitalize functions