From d1aeb50f2943a2e3b65b043d0d34ce0e7443fc4d Mon Sep 17 00:00:00 2001 From: Your Name Date: Wed, 9 Nov 2022 11:10:27 +0200 Subject: [PATCH] Don't put a comma in the last menuitem if there is no others left --- index.mjs | 20 +++++++++++++++----- package.json | 2 +- 2 files changed, 16 insertions(+), 6 deletions(-) diff --git a/index.mjs b/index.mjs index 7c02aa1..2d78832 100755 --- a/index.mjs +++ b/index.mjs @@ -1,18 +1,28 @@ #!/usr/bin/env node import fetch from "node-fetch"; -const APIURI = "https://fi.jamix.cloud/apps/menuservice/rest/haku/menu/92225/1?lang=fi" -var todayDate = new Date().toISOString().slice(0, 10).replaceAll('-', ''); +const APIURI = "https://fi.jamix.cloud/apps/menuservice/rest/haku/menu/92225/1?lang=fi"; +const myArgs = process.argv.slice(2); + +function getDate() { + switch (myArgs[0]) { + case "t": + return new Date(new Date().getTime() + 24 * 60 * 60 * 1000).toISOString().slice(0, 10).replaceAll('-', ''); + default: + return new Date().toISOString().slice(0, 10).replaceAll('-', ''); + } +} function getFood(data) { const days = data[0].menuTypes[0].menus[0].days - const daysFiltered = days.filter((day) => String(day.date) === todayDate); + const daysFiltered = days.filter((day) => String(day.date) === getDate()); const foods = []; daysFiltered[0].mealoptions.map((mealoption) => { let str = "" str += mealoption.name + ": " - mealoption.menuItems.map((menuItem) => { - str += menuItem.name + ", " + mealoption.menuItems.map((menuItem, index) => { + index !== mealoption.menuItems.length - 1 ? str += menuItem.name + ", " : str += menuItem.name; + console.log(index, mealoption.menuItems.length) }) foods.push(str); }) diff --git a/package.json b/package.json index 009bf67..8e73a90 100644 --- a/package.json +++ b/package.json @@ -7,7 +7,7 @@ "start": "node index.mjs" }, "bin": { - "faifood": "index.mjs" + "faifood": "index.mjs" }, "keywords": [], "author": "",