Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- var data = {
- "estimate_number_text": "MMIQ1282",
- "date_text": "05-13-15",
- "company_text": "Meteor Managed Inc",
- "contact_persons_text": "Mike Kozak",
- "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 $"
- };
- var parseData = function(data) {
- var parsedItems = [];
- var items = data.item_content_text.split("$item");
- var parseItem = function(item) {
- var itemObj = {};
- for (x = 0; x < item.length; x++) {
- var re = /[a-z]+(\s)/;
- var re2 = /(\s\b)(.+)/;
- var subst = '';
- var key = item[x].replace(re2, subst);
- var value = item[x].replace(re, subst);
- itemObj[key] = value;
- }
- return itemObj;
- };
- for (i = 1; i < items.length; i++) {
- var item = _.without(items[i].split("$"), " ");
- /* console.log(item) */
- parsedItems[i] = parseItem(item);;
- }
- console.log(parsedItems);
- };
- parseData(data);
- **RESULTS**
- 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 "
- qty: "2 "
- rate: "30.00 "
- __proto__: Object2: Objectdescription: "Enfain 10 Pack 16 GB USB Flash Drive Blue "
- qty: "1 "
- rate: "51.99 "
- __proto__: Object3: Objectdescription: "Cable Matters® 2 Pack DVI-I to VGA Male to Female Adapter "
- qty: "1 "
- rate: "7.99 "
- __proto__: Object4: Objectdescription: "Cable Matters® 8-Pack, Cat5E Snagless Ethernet Patch Cable in Blue 7 Feet "
- qty: "1 "
- rate: "16.99 "
- __proto__: Object5: Object "": ""
- description: "Optimal Shop 4 in 1 Remote RJ-45 RJ-11 USB and BNC LAN Network Phone Cable Tester Meter "
- qty: "2 "
- rate: "15.99 "
- __proto__: Objectlength: 6__proto__: Array[0]
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement