appointments.js
5 days ago
attendees.js
5 days ago
colorManipulation.js
5 days ago
customer.js
5 days ago
date.js
5 days ago
defaultCustomize.js
5 days ago
employee.js
5 days ago
events.js
5 days ago
formFieldsTemplates.js
5 days ago
formatting.js
5 days ago
helper.js
5 days ago
image.js
5 days ago
integrationApple.js
5 days ago
integrationGoogle.js
5 days ago
integrationOutlook.js
5 days ago
integrationStripe.js
5 days ago
integrationZoom.js
5 days ago
licence.js
5 days ago
phone.js
5 days ago
pricing.js
5 days ago
recurring.js
5 days ago
responsive.js
5 days ago
scrollElements.js
5 days ago
settings.js
5 days ago
translationsElementPlus.js
5 days ago
utilHeaderHeight.js
5 days ago
formatting.js
110 lines
| 1 | import { settings } from '../../../plugins/settings.js' |
| 2 | |
| 3 | const thousandSeparatorMap = { |
| 4 | 1: ',', |
| 5 | 2: '.', |
| 6 | 3: ' ', |
| 7 | 4: ' ', |
| 8 | } |
| 9 | |
| 10 | const decimalSeparatorMap = { |
| 11 | 1: '.', |
| 12 | 2: ',', |
| 13 | 3: '.', |
| 14 | 4: ',', |
| 15 | } |
| 16 | |
| 17 | function getCurrencySymbol() { |
| 18 | return settings.payments.currency |
| 19 | } |
| 20 | |
| 21 | function getPriceThousandSeparator() { |
| 22 | return thousandSeparatorMap[settings.payments.priceSeparator] |
| 23 | } |
| 24 | |
| 25 | function getPriceDecimalSeparator() { |
| 26 | return decimalSeparatorMap[settings.payments.priceSeparator] |
| 27 | } |
| 28 | |
| 29 | function getPriceNumberOfDecimalPlaces() { |
| 30 | return settings.payments.priceNumberOfDecimals |
| 31 | } |
| 32 | |
| 33 | function getPricePrefix() { |
| 34 | if ( |
| 35 | settings.payments.priceSymbolPosition === 'after' || |
| 36 | settings.payments.priceSymbolPosition === 'afterWithSpace' |
| 37 | ) { |
| 38 | return '' |
| 39 | } else if (settings.payments.priceSymbolPosition === 'before') { |
| 40 | return getCurrencySymbol() |
| 41 | } else { |
| 42 | return getCurrencySymbol() + ' ' |
| 43 | } |
| 44 | } |
| 45 | |
| 46 | function getPriceSuffix() { |
| 47 | if ( |
| 48 | settings.payments.priceSymbolPosition === 'before' || |
| 49 | settings.payments.priceSymbolPosition === 'beforeWithSpace' |
| 50 | ) { |
| 51 | return '' |
| 52 | } else if (settings.payments.priceSymbolPosition === 'after') { |
| 53 | return getCurrencySymbol() |
| 54 | } else { |
| 55 | return ' ' + getCurrencySymbol() |
| 56 | } |
| 57 | } |
| 58 | |
| 59 | function useFormattedPrice(price) { |
| 60 | let showCurrency = !settings.payments.hideCurrencySymbolFrontend |
| 61 | let decimalPlaces = getPriceNumberOfDecimalPlaces() |
| 62 | let thousandSeparator = getPriceThousandSeparator() |
| 63 | let decimalSeparator = getPriceDecimalSeparator() |
| 64 | let pricePrefix = getPricePrefix() |
| 65 | let priceSuffix = getPriceSuffix() |
| 66 | |
| 67 | let i = parseInt((price = Math.abs(+price || 0).toFixed(decimalPlaces))) + '' |
| 68 | let j = i.length > 3 ? i.length % 3 : 0 |
| 69 | |
| 70 | return ( |
| 71 | (showCurrency ? pricePrefix : '') + |
| 72 | (j ? i.substr(0, j) + thousandSeparator : '') + |
| 73 | i.substr(j).replace(/(\d{3})(?=\d)/g, '$1' + thousandSeparator) + |
| 74 | (decimalPlaces |
| 75 | ? decimalSeparator + |
| 76 | Math.abs(price - i) |
| 77 | .toFixed(decimalPlaces) |
| 78 | .slice(2) |
| 79 | : '') + |
| 80 | (showCurrency ? priceSuffix : '') |
| 81 | ) |
| 82 | } |
| 83 | |
| 84 | function capitalizeFirstLetter(string) { |
| 85 | return string.charAt(0).toUpperCase() + string.slice(1) |
| 86 | } |
| 87 | |
| 88 | function useRandomIntFromInterval(min, max) { |
| 89 | // min and max included |
| 90 | return Math.floor(Math.random() * (max - min + 1) + min) |
| 91 | } |
| 92 | |
| 93 | function useCurrencyOptions() { |
| 94 | return { |
| 95 | thousands: getPriceThousandSeparator(), |
| 96 | decimal: getPriceDecimalSeparator(), |
| 97 | precision: getPriceNumberOfDecimalPlaces(), |
| 98 | suffix: getPriceSuffix(), |
| 99 | prefix: getPricePrefix(), |
| 100 | } |
| 101 | } |
| 102 | |
| 103 | export { |
| 104 | useCurrencyOptions, |
| 105 | useFormattedPrice, |
| 106 | useRandomIntFromInterval, |
| 107 | capitalizeFirstLetter, |
| 108 | getCurrencySymbol, |
| 109 | } |
| 110 |