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