Skip to content

Instantly share code, notes, and snippets.

@pulkitsinghal
Last active September 5, 2017 00:20
Show Gist options
  • Save pulkitsinghal/d5a49fdd26e76db48743e248dbec426d to your computer and use it in GitHub Desktop.
Save pulkitsinghal/d5a49fdd26e76db48743e248dbec426d to your computer and use it in GitHub Desktop.
{
"id": "0adfd74a-15a7-11e7-fa42-91cf3a1e0138",
"handle": "in",
"has_variants": false,
"variant_parent_id": "0adfd74a-15a7-11e7-fa42-7a8da948e8d9",
"active": true,
"name": "Sleek Rubber Ball",
"base_name": "Sleek Rubber Ball",
"description": "Et iure nulla pariatur odit vel veritatis.",
"images": null,
"sku": "47544",
"supply_price": "8.00",
"track_inventory": true,
"inventory": [
],
"price_book_entries": [
{
"id": "4fbd5791-4183-5180-7165-cd9cbbf654b2",
"product_id": "0adfd74a-15a7-11e7-fa42-91cf3a1e0138",
"price_book_id": "8d4918f4-4df1-11e2-b1f5-4040782fde00",
"price_book_name": "General Price Book (All Products)",
"type": "BASE",
"customer_group_id": "8d464ce3-4df1-11e2-b1f5-4040782fde00",
"price": 18,
"loyalty_value": null,
"tax": 1.08,
"tax_id": "0adfd74a-15a7-11e7-fa42-91b2fb4d898b",
"tax_rate": 0.06,
"tax_name": "Normal Sales Tax",
"display_retail_price_tax_inclusive": 0
}
],
"price": 18,
"tax": 1.08,
"tax_id": "0adfd74a-15a7-11e7-fa42-91b2fb4d898b",
"tax_rate": 0.06,
"tax_name": "Normal Sales Tax",
"taxes": null,
"display_retail_price_tax_inclusive": 0,
"updated_at": "2017-09-04 17:14:47"
}
{
"id": "0adfd74a-15a7-11e7-fa42-91cf3a1e0138",
"source_id": "",
"variant_source_id": "",
"handle": "in",
"type": "",
"has_variants": false,
"variant_parent_id": "0adfd74a-15a7-11e7-fa42-7a8da948e8d9",
"variant_option_one_name": "",
"variant_option_one_value": "",
"variant_option_two_name": "",
"variant_option_two_value": "",
"variant_option_three_name": "",
"variant_option_three_value": "",
"active": true,
"name": "Sleek Rubber Ball",
"base_name": "Sleek Rubber Ball",
"description": "Et iure nulla pariatur odit vel veritatis.",
"image": "",
"image_large": "",
"images": null,
"sku": "47544",
"tags": "",
"brand_id": "",
"brand_name": "",
"supplier_name": "",
"supplier_code": "",
"supply_price": "8.00",
"account_code_purchase": "",
"account_code_sales": "",
"track_inventory": true,
"button_order": "",
"inventory": [
],
"price_book_entries": [
{
"id": "4fbd5791-4183-5180-7165-cd9cbbf654b2",
"product_id": "0adfd74a-15a7-11e7-fa42-91cf3a1e0138",
"price_book_id": "8d4918f4-4df1-11e2-b1f5-4040782fde00",
"price_book_name": "General Price Book (All Products)",
"type": "BASE",
"outlet_name": "",
"outlet_id": "",
"customer_group_name": "",
"customer_group_id": "8d464ce3-4df1-11e2-b1f5-4040782fde00",
"price": 18,
"loyalty_value": null,
"tax": 1.08,
"tax_id": "0adfd74a-15a7-11e7-fa42-91b2fb4d898b",
"tax_rate": 0.06,
"tax_name": "Normal Sales Tax",
"display_retail_price_tax_inclusive": 0,
"min_units": "",
"max_units": "",
"valid_from": "",
"valid_to": ""
}
],
"price": 18,
"tax": 1.08,
"tax_id": "0adfd74a-15a7-11e7-fa42-91b2fb4d898b",
"tax_rate": 0.06,
"tax_name": "Normal Sales Tax",
"taxes": null,
"display_retail_price_tax_inclusive": 0,
"updated_at": "2017-09-04 17:14:47",
"deleted_at": ""
}
var _ = require('underscore');
var omitEmptyValues = function omitEmptyValues(data) {
if(!_.isObject(data)) {
return data;
}
else {
if (_.isArray(data)) {
var clone = [];
_.each(data, function(value) {
if (_.isObject(value)) {
clone.push(omitEmptyValues(value));
}
else if (_.isString(value) && value.trim() !== '') {
clone.push(value);
}
else if (!_.isString(value)) {
clone.push(value);
}
});
return clone;
}
else if (_.isObject(data)) {
var clone = {};
_.each(data, function(value, key) {
if (_.isObject(value)) {
clone[key] = omitEmptyValues(value);
}
else if (_.isString(value) && value.trim() !== '') {
clone[key] = value;
}
else if (!_.isString(value)) {
clone[key] = value;
}
});
return clone;
}
else {
return data;
}
}
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment