PageSourceSearch

https://establishmentbardubbo.com.au/wp-content/plugins/bookingpre…/js/booking-form-vue3/utils/currency.js

js establishmentbardubbo.com.au collected 2026-10-06 20:15:59 UTC 3,131 bytes, 78 lines download raw bytes

1/**
2 * currency.js — price formatting parity with legacy
3 * `bookingpress_price_formatter_with_currency_symbol`
4 * (class.bookingpress.php:5997+) and its client-side mirror in
5 * class.bookingpress_appointment_bookings.php:6157-6168.
6 *
7 * Inputs come from `state.config`, seeded by StateBuilder.php:
8 *   - currencySymbol            actual symbol from countries JSON
9 *   - symbolPosition            'before' | 'before_with_space' | 'after' | 'after_with_space'
10 *   - priceSeparator            'comma-dot' | 'dot-comma' | 'space-dot' | 'space-comma' | 'Custom'
11 *   - priceDecimals             integer (admin "Number of decimals")
12 *   - customCommaSeparator      used when priceSeparator === 'Custom' (thousands)
13 *   - customThousandSeparator   used when priceSeparator === 'Custom' (decimals)
14 */
15
16/**
17 * Format an amount honoring the active payment-settings configuration.
18 *
19 * @param {object} config  state.config — currency formatting fields.
20 * @param {number|string} amount
21 * @returns {string}
22 */
23export function formatPrice(config, amount) {
24  const cfg = config || {};
25  const decimals = Math.max(0, parseInt(cfg.priceDecimals != null ? cfg.priceDecimals : 2, 10) || 0);
26  const separator = String(cfg.priceSeparator || 'comma-dot');
27  const symbol = String(cfg.currencySymbol || '$');
28  const position = String(cfg.symbolPosition || 'before');
29
30  let decimalSep = '.';
31  let thousandsSep = ',';
32  if (separator === 'dot-comma') {
33    decimalSep = ',';
34    thousandsSep = '.';
35  } else if (separator === 'space-dot') {
36    decimalSep = '.';
37    thousandsSep = ' ';
38  } else if (separator === 'space-comma') {
39    decimalSep = ',';
40    thousandsSep = ' ';
41  } else if (separator === 'Custom') {
42    decimalSep = String(cfg.customThousandSeparator != null ? cfg.customThousandSeparator : '.');
43    thousandsSep = String(cfg.customCommaSeparator != null ? cfg.customCommaSeparator : ',');
44  }
45
46  const price = numberFormat(amount, decimals, decimalSep, thousandsSep);
47
48  if (position === 'before_with_space') return symbol + ' ' + price;
49  if (position === 'after')              return price + symbol;
50  if (position === 'after_with_space')   return price + ' ' + symbol;
51  return symbol + price;
52}
53
54/**
55 * PHP-style number_format port — same shape as the legacy
56 * `vm.bookingpress_number_format` in class.bookingpress_appointment_bookings.php:6173.
57 *
58 * @param {number|string} number
59 * @param {number} decimals
60 * @param {string} decPoint
61 * @param {string} thousandsSep
62 * @returns {string}
63 */
64function numberFormat(number, decimals, decPoint, thousandsSep) {
65  const cleaned = (number + '').replace(/[^0-9+\-Ee.]/g, '');
66  const n = !isFinite(+cleaned) ? 0 : +cleaned;
67  const prec = !isFinite(+decimals) ? 0 : Math.abs(decimals);
68  const fixed = prec ? n.toFixed(prec) : '' + Math.round(n);
69  const parts = fixed.split('.');
70  if (parts[0].length > 3) {
71    parts[0] = parts[0].replace(/\B(?=(?:\d{3})+(?!\d))/g, thousandsSep);
72  }
73  if ((parts[1] || '').length < prec) {
74    parts[1] = parts[1] || '';
75    parts[1] += new Array(prec - parts[1].length + 1).join('0');
76  }
77  return parts.join(decPoint);
78}

Line numbers count LF bytes from the start of the resource, as the search results do. Vendor segments are library code the classifier recognised; they are stored but not indexed. Bytes are shown as Latin1 characters, one per byte.