Advertisement
orksnork

Untitled

May 28th, 2015
210
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. var data = {
  2.         "estimate_number_text": "MMIQ1282",
  3.         "date_text": "05-13-15",
  4.         "company_text": "Meteor Managed Inc",
  5.         "contact_persons_text": "Mike Kozak",
  6.         "item_content_text": "$item $qty 2 $description 54 Bit Driver Kit https://www.ifixit.com/Store/Tools/54-Bit-Driver-Kit/IF145-022-1 $rate 30.00 $ $item $qty 1 $description Enfain 10 Pack 16 GB USB Flash Drive Blue $rate 51.99 $ $item $qty 1 $description Cable Matters® 2 Pack DVI-I to VGA Male to Female Adapter $rate 7.99 $ $item $qty 1 $description Cable Matters® 8-Pack, Cat5E Snagless Ethernet Patch Cable in Blue 7 Feet $rate 16.99 $ $item $qty 2 $description Optimal Shop 4 in 1 Remote RJ-45 RJ-11 USB and BNC LAN Network Phone Cable Tester Meter $rate 15.99 $"
  7. };
  8. var parseData = function(data) {
  9.         var parsedItems = [];
  10.         var items = data.item_content_text.split("$item");
  11.         var parseItem = function(item) {
  12.                 var itemObj = {};
  13.                 for (x = 0; x < item.length; x++) {
  14.                         var re = /[a-z]+(\s)/;
  15.                         var re2 = /(\s\b)(.+)/;
  16.                         var subst = '';
  17.                         var key = item[x].replace(re2, subst);
  18.                         var value = item[x].replace(re, subst);
  19.                         itemObj[key] = value;
  20.                 }
  21.                 return itemObj;
  22.         };
  23.         for (i = 1; i < items.length; i++) {
  24.                 var item = _.without(items[i].split("$"), " ");
  25.                 /*              console.log(item) */
  26.                 parsedItems[i] = parseItem(item);;
  27.         }
  28.         console.log(parsedItems);
  29. };
  30. parseData(data);
  31.  
  32. **RESULTS**
  33.  
  34. VM743: 33[1: Object, 2: Object, 3: Object, 4: Object, 5: Object] 1: Objectdescription: "54 Bit Driver Kit https://www.ifixit.com/Store/Tools/54-Bit-Driver-Kit/IF145-022-1 "
  35. qty: "2 "
  36. rate: "30.00 "
  37. __proto__: Object2: Objectdescription: "Enfain 10 Pack 16 GB USB Flash Drive Blue "
  38. qty: "1 "
  39. rate: "51.99 "
  40. __proto__: Object3: Objectdescription: "Cable Matters® 2 Pack DVI-I to VGA Male to Female Adapter "
  41. qty: "1 "
  42. rate: "7.99 "
  43. __proto__: Object4: Objectdescription: "Cable Matters® 8-Pack, Cat5E Snagless Ethernet Patch Cable in Blue 7 Feet "
  44. qty: "1 "
  45. rate: "16.99 "
  46. __proto__: Object5: Object "": ""
  47. description: "Optimal Shop 4 in 1 Remote RJ-45 RJ-11 USB and BNC LAN Network Phone Cable Tester Meter "
  48. qty: "2 "
  49. rate: "15.99 "
  50. __proto__: Objectlength: 6__proto__: Array[0]
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement