Created
May 15, 2019 06:05
-
-
Save root-cause/500b6e197348e941aeebfa8f883486bb to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
const invAPI = require("../inventory-api"); | |
const drinkItem = invAPI.addItem("item_drink", "Drink", "Generic drink."); | |
drinkItem.nameFunc = function(data) { | |
if (data && data.hasOwnProperty("drinkType")) { | |
return `Drink (${data.drinkType})`; | |
} else { | |
return "Drink"; | |
} | |
}; | |
drinkItem.descFunc = function(data) { | |
if (data && data.hasOwnProperty("drinkType")) { | |
switch (data.drinkType) { | |
case "wine": | |
return "Wine description."; | |
case "water": | |
return "Water description."; | |
} | |
} else { | |
return "Generic drink."; | |
} | |
}; | |
// Outputs | |
console.log(invAPI.getItemName("item_drink")); // Drink | |
console.log(invAPI.getItemName("item_drink", { drinkType: "wine" })); // Drink (wine) | |
console.log(invAPI.getItemName("item_drink", { drinkType: "water" })); // Drink (water) | |
console.log(invAPI.getItemDescription("item_drink")); // Generic drink. | |
console.log(invAPI.getItemDescription("item_drink", { drinkType: "wine" })); // Wine description. | |
console.log(invAPI.getItemDescription("item_drink", { drinkType: "water" })); // Water description. |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment