diff options
| author | Mike Vink <mike1994vink@gmail.com> | 2021-06-04 17:08:53 +0200 |
|---|---|---|
| committer | Mike Vink <mike1994vink@gmail.com> | 2021-06-04 17:08:53 +0200 |
| commit | 2f9cd43f44f8cdd4bdb16bb95a507b5f45c8e44d (patch) | |
| tree | 34fd744bf9475fdc977fc697331854db61d0f15c /client/src/utils.js | |
| parent | 0114244663fbb8cd45a7cc4489bda469b31f0698 (diff) | |
server and response api
Diffstat (limited to 'client/src/utils.js')
| -rw-r--r-- | client/src/utils.js | 48 |
1 files changed, 48 insertions, 0 deletions
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); + } + } + + } +} |
