Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
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
You can’t perform that action at this time.