From 2f9cd43f44f8cdd4bdb16bb95a507b5f45c8e44d Mon Sep 17 00:00:00 2001 From: Mike Vink Date: Fri, 4 Jun 2021 17:08:53 +0200 Subject: server and response api --- client/src/utils.js | 48 ++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 48 insertions(+) create mode 100644 client/src/utils.js (limited to 'client/src/utils.js') diff --git a/client/src/utils.js b/client/src/utils.js new file mode 100644 index 0000000..03416f0 --- /dev/null +++ b/client/src/utils.js @@ -0,0 +1,48 @@ +export function displayNumberOfItemsInShoppingBasketWithBadge() { + var shoppingBasketArray = JSON.parse(localStorage.getItem("shoppingBasketArray")); + if (shoppingBasketArray === null) { + document.querySelector(".badge").innerText = 0; + } else { + document.querySelector(".badge").innerText = shoppingBasketArray.length; + } +} + +export function dutchCurrencyFormat(number) { + var decimal = (number * 10) % 10 + if (decimal === 0) return number + ",-"; + else { + return (number * 10 - decimal) / 10 + "," + decimal; + } +} + +export function dutchCurrencyFormatWithSign(number) { + return "\u20AC" + dutchCurrencyFormat(number); +} + + +export function findParentWithTag(tagName) { + if (this.tagName === tagName.toUpperCase()) { + return this; + } else { + return findParentWithTag.bind(this.parentNode)(tagName); + } +} + +export function childKillerUsingTags(parent) { + + return function oneOfMyChildren(child) { + + return function killChildrenWithTag(tag) { + if (child === null) { + return + } else if (child.tagName === tag.toUpperCase()) { + var next = child.nextSibling; + parent.removeChild(child); + return oneOfMyChildren(next)(tag); + } else { + return oneOfMyChildren(child.nextSibling)(tag); + } + } + + } +} -- cgit v1.2.3