@ubnt/store.core 9.11.0-alpha.0 → 9.11.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (200) hide show
  1. package/CHANGELOG.md +7 -48
  2. package/lib/assets/attention.svg +5 -5
  3. package/lib/assets/attention2.svg +5 -5
  4. package/lib/assets/close2.svg +2 -3
  5. package/lib/assets/close3.svg +3 -2
  6. package/lib/assets/minus4.svg +8 -8
  7. package/lib/assets/minus5.svg +8 -8
  8. package/lib/assets/pause.svg +3 -3
  9. package/lib/assets/pause2.svg +3 -3
  10. package/lib/assets/udmPro.jpg +0 -0
  11. package/lib/assets/udmPro2.jpg +0 -0
  12. package/lib/assets/udmProMax.jpg +0 -0
  13. package/lib/assets/udmProMax2.jpg +0 -0
  14. package/lib/assets/udmProSpecial.jpg +0 -0
  15. package/lib/assets/udmProSpecial2.jpg +0 -0
  16. package/lib/components/FeaturesSection_deprecated/FeaturesSection.js +1 -1
  17. package/lib/components/FeaturesSection_deprecated/FeaturesSection.mjs +1 -1
  18. package/lib/components/FeaturesSection_deprecated/assets/close.svg.js +1 -1
  19. package/lib/components/FeaturesSection_deprecated/assets/close.svg.mjs +2 -2
  20. package/lib/components/Header/ProHeader/ProHeader.js +2 -19
  21. package/lib/components/Header/ProHeader/ProHeader.js.map +1 -1
  22. package/lib/components/Header/ProHeader/ProHeader.mjs +2 -19
  23. package/lib/components/Header/ProHeader/ProHeader.mjs.map +1 -1
  24. package/lib/components/Header/ProHeader/ProHeader.styles.d.ts +0 -1
  25. package/lib/components/Header/ProHeader/ProHeader.styles.js +0 -6
  26. package/lib/components/Header/ProHeader/ProHeader.styles.js.map +1 -1
  27. package/lib/components/Header/ProHeader/ProHeader.styles.mjs +0 -6
  28. package/lib/components/Header/ProHeader/ProHeader.styles.mjs.map +1 -1
  29. package/lib/components/LandingPagePro/LandingPagePro.d.ts +0 -3
  30. package/lib/components/LandingPagePro/LandingPagePro.js +3 -3
  31. package/lib/components/LandingPagePro/LandingPagePro.js.map +1 -1
  32. package/lib/components/LandingPagePro/LandingPagePro.mjs +2 -2
  33. package/lib/components/LandingPagePro/LandingPagePro.mjs.map +1 -1
  34. package/lib/components/MicrositeVideoSlideshow/MicrositeVideoSlideshow.js +1 -1
  35. package/lib/components/MicrositeVideoSlideshow/MicrositeVideoSlideshow.mjs +1 -1
  36. package/lib/components/MicrositeVideoSlideshow/assets/pause.svg.js +1 -1
  37. package/lib/components/MicrositeVideoSlideshow/assets/pause.svg.mjs +2 -2
  38. package/lib/components/ModelCompareV3/assets/Consoles/bigCompare/udmPro.jpg.js +5 -5
  39. package/lib/components/ModelCompareV3/assets/Consoles/bigCompare/udmPro.jpg.mjs +2 -2
  40. package/lib/components/ModelCompareV3/assets/Consoles/bigCompare/udmProMax.jpg.js +5 -5
  41. package/lib/components/ModelCompareV3/assets/Consoles/bigCompare/udmProMax.jpg.mjs +2 -2
  42. package/lib/components/ModelCompareV3/assets/Consoles/bigCompare/udmProSpecial.jpg.js +5 -5
  43. package/lib/components/ModelCompareV3/assets/Consoles/bigCompare/udmProSpecial.jpg.mjs +2 -2
  44. package/lib/components/ModelCompareV3/assets/Consoles/udmPro.jpg.js +1 -1
  45. package/lib/components/ModelCompareV3/assets/Consoles/udmPro.jpg.mjs +2 -2
  46. package/lib/components/ModelCompareV3/assets/Consoles/udmProMax.jpg.js +1 -1
  47. package/lib/components/ModelCompareV3/assets/Consoles/udmProMax.jpg.mjs +2 -2
  48. package/lib/components/ModelCompareV3/assets/Consoles/udmProSpecial.jpg.js +1 -1
  49. package/lib/components/ModelCompareV3/assets/Consoles/udmProSpecial.jpg.mjs +2 -2
  50. package/lib/components/ModelCompareV3/data/CloudGateways.js +9 -9
  51. package/lib/components/ModelCompareV3/data/CloudGateways.mjs +6 -6
  52. package/lib/components/ModelCompareV3/data/products/udmPro.js +1 -1
  53. package/lib/components/ModelCompareV3/data/products/udmPro.mjs +1 -1
  54. package/lib/components/ModelCompareV3/data/products/udmProMax.js +1 -1
  55. package/lib/components/ModelCompareV3/data/products/udmProMax.mjs +1 -1
  56. package/lib/components/ModelCompareV3/data/products/udmProSpecial.js +1 -1
  57. package/lib/components/ModelCompareV3/data/products/udmProSpecial.mjs +1 -1
  58. package/lib/components/ResourceCalculatorV1/ComputeResourceCalculator/ComputeResourceCalculator.constants.js +1 -6
  59. package/lib/components/ResourceCalculatorV1/ComputeResourceCalculator/ComputeResourceCalculator.constants.js.map +1 -1
  60. package/lib/components/ResourceCalculatorV1/ComputeResourceCalculator/ComputeResourceCalculator.constants.mjs +1 -6
  61. package/lib/components/ResourceCalculatorV1/ComputeResourceCalculator/ComputeResourceCalculator.constants.mjs.map +1 -1
  62. package/lib/components/ResourceCalculatorV1/ComputeResourceCalculator/components/InputCard/InputCard.js +2 -2
  63. package/lib/components/ResourceCalculatorV1/ComputeResourceCalculator/components/InputCard/InputCard.js.map +1 -1
  64. package/lib/components/ResourceCalculatorV1/ComputeResourceCalculator/components/InputCard/InputCard.mjs +2 -2
  65. package/lib/components/ResourceCalculatorV1/ComputeResourceCalculator/components/InputCard/InputCard.mjs.map +1 -1
  66. package/lib/components/ResourceCalculatorV1/ComputeResourceCalculator/components/InputCard/InputCard.styles.js +0 -2
  67. package/lib/components/ResourceCalculatorV1/ComputeResourceCalculator/components/InputCard/InputCard.styles.js.map +1 -1
  68. package/lib/components/ResourceCalculatorV1/ComputeResourceCalculator/components/InputCard/InputCard.styles.mjs +0 -2
  69. package/lib/components/ResourceCalculatorV1/ComputeResourceCalculator/components/InputCard/InputCard.styles.mjs.map +1 -1
  70. package/lib/components/ResourceCalculatorV1/ComputeResourceCalculator/components/InputCard/InputSections/CounterSection.js +1 -1
  71. package/lib/components/ResourceCalculatorV1/ComputeResourceCalculator/components/InputCard/InputSections/CounterSection.mjs +1 -1
  72. package/lib/components/ResourceCalculatorV1/ComputeResourceCalculator/components/InputCard/assets/attention.svg.js +1 -1
  73. package/lib/components/ResourceCalculatorV1/ComputeResourceCalculator/components/InputCard/assets/attention.svg.mjs +2 -2
  74. package/lib/components/ResourceCalculatorV1/ComputeResourceCalculator/components/InputCard/assets/minus.svg.js +1 -1
  75. package/lib/components/ResourceCalculatorV1/ComputeResourceCalculator/components/InputCard/assets/minus.svg.mjs +2 -2
  76. package/lib/components/ResourceCalculatorV1/ComputeResourceCalculator/components/ProgressBarChart/ProgressBarChart.js +1 -1
  77. package/lib/components/ResourceCalculatorV1/ComputeResourceCalculator/components/ProgressBarChart/ProgressBarChart.mjs +1 -1
  78. package/lib/components/ResourceCalculatorV1/ComputeResourceCalculator/components/ProgressBarChart/assets/attention.svg.js +1 -1
  79. package/lib/components/ResourceCalculatorV1/ComputeResourceCalculator/components/ProgressBarChart/assets/attention.svg.mjs +2 -2
  80. package/lib/components/ResourceCalculatorV1/PoeCalculator/components/PoeConsumerConfigurator/PoeConsumerSelectModal/PoeConsumerSelectModal.js +1 -1
  81. package/lib/components/ResourceCalculatorV1/PoeCalculator/components/PoeConsumerConfigurator/PoeConsumerSelectModal/PoeConsumerSelectModal.mjs +1 -1
  82. package/lib/components/ResourceCalculatorV1/PoeCalculator/components/PoeConsumerConfigurator/assets/minus.svg.js +1 -1
  83. package/lib/components/ResourceCalculatorV1/PoeCalculator/components/PoeConsumerConfigurator/assets/minus.svg.mjs +2 -2
  84. package/lib/components/VideoPlayerNew/VideoPlayer.js +2 -2
  85. package/lib/components/VideoPlayerNew/VideoPlayer.mjs +2 -2
  86. package/lib/components/VideoPlayerNew/assets/close.svg.js +1 -1
  87. package/lib/components/VideoPlayerNew/assets/close.svg.mjs +2 -2
  88. package/lib/components/VideoPlayerNew/assets/pause.svg.js +1 -1
  89. package/lib/components/VideoPlayerNew/assets/pause.svg.mjs +2 -2
  90. package/lib/constants/proStoreCategories/mapping/index.d.ts +0 -1
  91. package/lib/constants/proStoreCategories/mapping/index.js +8 -13
  92. package/lib/constants/proStoreCategories/mapping/index.js.map +1 -1
  93. package/lib/constants/proStoreCategories/mapping/index.mjs +8 -13
  94. package/lib/constants/proStoreCategories/mapping/index.mjs.map +1 -1
  95. package/lib/constants/proStoreCategories/mapping/unifi.d.ts +1 -2
  96. package/lib/constants/proStoreCategories/mapping/unifi.js +0 -1
  97. package/lib/constants/proStoreCategories/mapping/unifi.js.map +1 -1
  98. package/lib/constants/proStoreCategories/mapping/unifi.mjs +0 -1
  99. package/lib/constants/proStoreCategories/mapping/unifi.mjs.map +1 -1
  100. package/lib/constants/proStoreCategories/translations/en.json.js +0 -3
  101. package/lib/constants/proStoreCategories/translations/en.json.js.map +1 -1
  102. package/lib/constants/proStoreCategories/translations/en.json.mjs +1 -3
  103. package/lib/constants/proStoreCategories/translations/en.json.mjs.map +1 -1
  104. package/lib/constants/proStoreCategories/translations/fr.json.js +1 -1
  105. package/lib/constants/proStoreCategories/translations/fr.json.mjs +1 -1
  106. package/lib/constants/proStoreCategories/translations/zh-Hans.json.js +1 -1
  107. package/lib/constants/proStoreCategories/translations/zh-Hans.json.mjs +1 -1
  108. package/lib/constants/proStoreCategories/translations/zh-Hant-TW.json.js +1 -1
  109. package/lib/constants/proStoreCategories/translations/zh-Hant-TW.json.mjs +1 -1
  110. package/lib/contexts/MenuContext/mapping.js +7 -1
  111. package/lib/contexts/MenuContext/mapping.js.map +1 -1
  112. package/lib/contexts/MenuContext/mapping.mjs +7 -1
  113. package/lib/contexts/MenuContext/mapping.mjs.map +1 -1
  114. package/lib/utils/money/constants.d.ts +25 -56
  115. package/lib/utils/money/constants.js +7 -72
  116. package/lib/utils/money/constants.js.map +1 -1
  117. package/lib/utils/money/constants.mjs +7 -70
  118. package/lib/utils/money/constants.mjs.map +1 -1
  119. package/lib/utils/money/format.d.ts +5 -10
  120. package/lib/utils/money/format.js +14 -22
  121. package/lib/utils/money/format.js.map +1 -1
  122. package/lib/utils/money/format.mjs +16 -23
  123. package/lib/utils/money/format.mjs.map +1 -1
  124. package/lib/utils/money/index.d.ts +1 -4
  125. package/lib/utils/money/index.js +8 -26
  126. package/lib/utils/money/index.js.map +1 -1
  127. package/lib/utils/money/index.mjs +4 -8
  128. package/lib/utils/money/index.mjs.map +1 -1
  129. package/lib/utils/money/misc.d.ts +28 -68
  130. package/lib/utils/money/misc.js +64 -35
  131. package/lib/utils/money/misc.js.map +1 -1
  132. package/lib/utils/money/misc.mjs +43 -32
  133. package/lib/utils/money/misc.mjs.map +1 -1
  134. package/lib/utils/money/tax.d.ts +2 -38
  135. package/lib/utils/money/tax.js +10 -46
  136. package/lib/utils/money/tax.js.map +1 -1
  137. package/lib/utils/money/tax.mjs +11 -42
  138. package/lib/utils/money/tax.mjs.map +1 -1
  139. package/lib/utils/money/types.d.ts +3 -78
  140. package/lib/utils/number.d.ts +1 -1
  141. package/lib/utils/number.js +1 -1
  142. package/lib/utils/number.js.map +1 -1
  143. package/lib/utils/number.mjs +1 -1
  144. package/lib/utils/number.mjs.map +1 -1
  145. package/lib/utils/validations.d.ts +15 -0
  146. package/lib/utils/validations.js +23 -0
  147. package/lib/utils/validations.js.map +1 -0
  148. package/lib/utils/validations.mjs +21 -0
  149. package/lib/utils/validations.mjs.map +1 -0
  150. package/package.json +2 -2
  151. package/lib/components/Tooltip/Tooltip.d.ts +0 -2
  152. package/lib/components/Tooltip/Tooltip.js +0 -45
  153. package/lib/components/Tooltip/Tooltip.js.map +0 -1
  154. package/lib/components/Tooltip/Tooltip.mjs +0 -43
  155. package/lib/components/Tooltip/Tooltip.mjs.map +0 -1
  156. package/lib/components/Tooltip/Tooltip.styles.d.ts +0 -32
  157. package/lib/components/Tooltip/Tooltip.styles.js +0 -44
  158. package/lib/components/Tooltip/Tooltip.styles.js.map +0 -1
  159. package/lib/components/Tooltip/Tooltip.styles.mjs +0 -34
  160. package/lib/components/Tooltip/Tooltip.styles.mjs.map +0 -1
  161. package/lib/components/Tooltip/index.d.ts +0 -1
  162. package/lib/components/Tooltip/index.js +0 -6
  163. package/lib/components/Tooltip/index.js.map +0 -1
  164. package/lib/components/Tooltip/index.mjs +0 -3
  165. package/lib/components/Tooltip/index.mjs.map +0 -1
  166. package/lib/utils/money/allocators/fixedAmount.d.ts +0 -26
  167. package/lib/utils/money/allocators/fixedAmount.js +0 -55
  168. package/lib/utils/money/allocators/fixedAmount.js.map +0 -1
  169. package/lib/utils/money/allocators/fixedAmount.mjs +0 -53
  170. package/lib/utils/money/allocators/fixedAmount.mjs.map +0 -1
  171. package/lib/utils/money/allocators/index.d.ts +0 -2
  172. package/lib/utils/money/allocators/index.js +0 -8
  173. package/lib/utils/money/allocators/index.js.map +0 -1
  174. package/lib/utils/money/allocators/index.mjs +0 -4
  175. package/lib/utils/money/allocators/index.mjs.map +0 -1
  176. package/lib/utils/money/allocators/productAmount.d.ts +0 -13
  177. package/lib/utils/money/allocators/productAmount.js +0 -110
  178. package/lib/utils/money/allocators/productAmount.js.map +0 -1
  179. package/lib/utils/money/allocators/productAmount.mjs +0 -108
  180. package/lib/utils/money/allocators/productAmount.mjs.map +0 -1
  181. package/lib/utils/money/exchangeRate.d.ts +0 -31
  182. package/lib/utils/money/exchangeRate.js +0 -27
  183. package/lib/utils/money/exchangeRate.js.map +0 -1
  184. package/lib/utils/money/exchangeRate.mjs +0 -23
  185. package/lib/utils/money/exchangeRate.mjs.map +0 -1
  186. package/lib/utils/money/misc.private.d.ts +0 -23
  187. package/lib/utils/money/misc.private.js +0 -46
  188. package/lib/utils/money/misc.private.js.map +0 -1
  189. package/lib/utils/money/misc.private.mjs +0 -21
  190. package/lib/utils/money/misc.private.mjs.map +0 -1
  191. package/lib/utils/money/shipping.d.ts +0 -5
  192. package/lib/utils/money/shipping.js +0 -8
  193. package/lib/utils/money/shipping.js.map +0 -1
  194. package/lib/utils/money/shipping.mjs +0 -6
  195. package/lib/utils/money/shipping.mjs.map +0 -1
  196. package/lib/utils/money/tax.private.d.ts +0 -17
  197. package/lib/utils/money/tax.private.js +0 -65
  198. package/lib/utils/money/tax.private.js.map +0 -1
  199. package/lib/utils/money/tax.private.mjs +0 -60
  200. package/lib/utils/money/tax.private.mjs.map +0 -1
@@ -1,68 +1,37 @@
1
- import { Currency, StoreId } from "../../types";
2
- import type { LocalizedCurrency, RoundingFn } from "./types";
3
- export declare const Round: {
4
- /**
5
- * ⚠️ Instead of using Math.round, we HAVE to use this method to round the financial numbers everywhere where we CAN'T
6
- * deal with dinero.js (Dinero.js should be the priority). But often for converting from API requests we have to
7
- * normalise the values so we use this method.
8
- *
9
- * It just a re-export of the dinero.js halfEven (a.k.a bankers rounding) method which is the default rounding method.
10
- * @see https://github.com/dinerojs/dinero.js/blob/main/packages/core/src/round/halfEven.ts
11
- * @see
12
- *
13
- * Compared to Math.round (arithmetic rounding) it differentiates that it changes the `.5` round up or down behaviour based on if the rounded
14
- * number would be an even number. So 1.5 would round to 2 while 2.5 would round to 2.
15
- * See the youtube link below for a brief exclamation on why it's important to use this method over regular rounding (half-up):
16
- * https://youtu.be/yuRdYlZvs1E
17
- *
18
- * If you really want to get knee-deep in the rounding subject, you can read the following:
19
- * https://en.wikipedia.org/wiki/Rounding#Round_half_toward_zero
20
- */
21
- Financial: import("@dinero.js/core").RoundingMode;
22
- Shipping: import("@dinero.js/core").RoundingMode;
23
- Prettify: import("@dinero.js/core").RoundingMode;
24
- Subunit: import("@dinero.js/core").RoundingMode;
25
- };
1
+ import { Currency } from "../../types";
2
+ import type { CurrencyObj } from "./types";
26
3
  /**
27
4
  * Mapping of how prices should be rounded down to "whole numbers" after certain threshold
28
5
  */
29
6
  export declare const prettifyPriceLookup: Map<string, number>;
30
7
  /**
31
- * Map of dinero code to subunit digit count.
8
+ * Map of currencycode to subunit digit count.
32
9
  */
33
- export declare const smallestSubunitLookup: Map<string, [number, RoundingFn]>;
10
+ export declare const smallestSubunitLookup: Map<string, [number, (value: number) => number]>;
34
11
  /**
35
- * Precompiled list for faster currency and locale lookups
12
+ * Mapping of maximum price filter
13
+ * TODO: Add all possible currencies
36
14
  */
37
- export declare const localizedCurrencyLookup: Map<Currency, LocalizedCurrency>;
15
+ export declare const maximumPriceFilterLookup: Map<string, number>;
38
16
  /**
39
- * List of stores that require calculating per single item qty and then combining them to get the total tax amount for a
40
- * single line. Rest of the stores inherit default behavior that tax calculated on whole line item
17
+ * ⚠️ Instead of using Math.round, we HAVE to use this method to round the financial numbers everywhere where we CAN'T
18
+ * deal with dinero.js (Dinero.js should be the priority). But often for converting from API requests we have to
19
+ * normalise the values so we use this method.
20
+ *
21
+ * It just a re-export of the dinero.js halfEven (a.k.a bankers rounding) method which is the default rounding method.
22
+ * @see https://github.com/dinerojs/dinero.js/blob/main/packages/core/src/round/halfEven.ts
23
+ * @see
24
+ *
25
+ * Compared to Math.round (arithmetic rounding) it differentiates that it changes the `.5` round up or down behaviour based on if the rounded
26
+ * number would be an even number. So 1.5 would round to 2 while 2.5 would round to 2.
27
+ * See the youtube link below for a brief exclamation on why it's important to use this method over regular rounding (half-up):
28
+ * https://youtu.be/yuRdYlZvs1E
29
+ *
30
+ * If you really want to get knee-deep in the rounding subject, you can read the following:
31
+ * https://en.wikipedia.org/wiki/Rounding#Round_half_toward_zero
41
32
  */
42
- export declare const storesWithPerItemTaxRate: Set<StoreId>;
33
+ export declare const financialRound: import("@dinero.js/core").RoundingMode;
43
34
  /**
44
- * Dinero currency option block for working with tax rates within dinero
35
+ * Precompiled list for faster currency and locale lookups
45
36
  */
46
- export declare const TAX_RATE_DINERO_CURRENCY: {
47
- base: number;
48
- /**
49
- * We expect the tax rate to be in the range of 0..1
50
- * 0 --> 0%
51
- * 1 --> 100%
52
- * 0.21 --> 21%
53
- * 0.2169 --> 21.69%
54
- * 0.12345678 --> 12.345678%
55
- * !!! Don't change as this value is tied to store.backend DB schema !!!
56
- */
57
- exponent: number;
58
- code: string;
59
- };
60
- export declare const EXCHANGE_RATE_DINERO_CURRENCY: {
61
- base: number;
62
- /**
63
- * We support having certain decimal places for exchange rates
64
- * !!! Don't change as this value is tied to store.backend DB schema !!!
65
- */
66
- exponent: number;
67
- code: string;
68
- };
37
+ export declare const currencyObjLookup: Map<Currency, CurrencyObj>;
@@ -5,33 +5,6 @@ var dinero_js = require('dinero.js');
5
5
  require('../../types/index.js');
6
6
  var generated = require('../../types/generated.js');
7
7
  "use strict";
8
- const Round = {
9
- /**
10
- * ⚠️ Instead of using Math.round, we HAVE to use this method to round the financial numbers everywhere where we CAN'T
11
- * deal with dinero.js (Dinero.js should be the priority). But often for converting from API requests we have to
12
- * normalise the values so we use this method.
13
- *
14
- * It just a re-export of the dinero.js halfEven (a.k.a bankers rounding) method which is the default rounding method.
15
- * @see https://github.com/dinerojs/dinero.js/blob/main/packages/core/src/round/halfEven.ts
16
- * @see
17
- *
18
- * Compared to Math.round (arithmetic rounding) it differentiates that it changes the `.5` round up or down behaviour based on if the rounded
19
- * number would be an even number. So 1.5 would round to 2 while 2.5 would round to 2.
20
- * See the youtube link below for a brief exclamation on why it's important to use this method over regular rounding (half-up):
21
- * https://youtu.be/yuRdYlZvs1E
22
- *
23
- * If you really want to get knee-deep in the rounding subject, you can read the following:
24
- * https://en.wikipedia.org/wiki/Rounding#Round_half_toward_zero
25
- */
26
- Financial: dinero_js.halfEven,
27
- // TODO: maybe we should have separate rounding functions depending on the input value?
28
- // Reading from wiki "Round half toward zero" is better if the value is already "normalized to cents"
29
- // But the "Round half to even" seems better for when working with float like values
30
- // financialRound = Math.round;
31
- Shipping: dinero_js.down,
32
- Prettify: dinero_js.down,
33
- Subunit: dinero_js.halfUp
34
- };
35
8
  const prettifyPriceLookup = /* @__PURE__ */new Map([[currencies.USD.code, 20], [currencies.CAD.code, 20], [currencies.EUR.code, 20], [currencies.GBP.code, 20], [currencies.AED.code, 50],
36
9
  // Approximately every price above ~1.1 usd will be rounded in ZAR
37
10
  [currencies.ZAR.code, 20]]);
@@ -39,8 +12,10 @@ const smallestSubunitLookup = /* @__PURE__ */new Map([
39
12
  /**
40
13
  * TWD does not use subunits at all in day to day transactions.
41
14
  */
42
- [currencies.TWD.code, [0, Round.Subunit]]]);
43
- const localizedCurrencyLookup = /* @__PURE__ */new Map([[generated.Currency.Aed, {
15
+ [currencies.TWD.code, [0, dinero_js.halfUp]]]);
16
+ const maximumPriceFilterLookup = /* @__PURE__ */new Map([[currencies.CAD.code, 7e4], [currencies.EUR.code, 7e4], [currencies.AED.code, 7e4]]);
17
+ const financialRound = dinero_js.halfEven;
18
+ const currencyObjLookup = /* @__PURE__ */new Map([[generated.Currency.Aed, {
44
19
  currency: currencies.AED,
45
20
  locale: "ar-AE"
46
21
  }], [generated.Currency.Bgn, {
@@ -111,49 +86,9 @@ const localizedCurrencyLookup = /* @__PURE__ */new Map([[generated.Currency.Aed,
111
86
  currency: currencies.MXN,
112
87
  locale: "es-MX"
113
88
  }]]);
114
- const storesWithPerItemTaxRate = /* @__PURE__ */new Set([
115
- // #############################################################################
116
- // Stores with custom tax rates
117
- // #############################################################################
118
- generated.StoreId.Br, generated.StoreId.Tw
119
- // #############################################################################
120
- // Stores with Avalara, but will have custom company codes to treat
121
- // FIXME: as PR is rushed we where able to test stores avalara custom codes that enable logic that calculates tax
122
- // "per quantity", so for now disabling this logic and only applying to store with custom tax rates
123
- // #############################################################################
124
- // StoreId.Jp,
125
- // StoreId.Sg,
126
- ]);
127
- const TAX_RATE_DINERO_CURRENCY = {
128
- base: 10,
129
- /**
130
- * We expect the tax rate to be in the range of 0..1
131
- * 0 --> 0%
132
- * 1 --> 100%
133
- * 0.21 --> 21%
134
- * 0.2169 --> 21.69%
135
- * 0.12345678 --> 12.345678%
136
- * !!! Don't change as this value is tied to store.backend DB schema !!!
137
- */
138
- exponent: 8,
139
- code: ""
140
- // Not important
141
- };
142
- const EXCHANGE_RATE_DINERO_CURRENCY = {
143
- base: 10,
144
- /**
145
- * We support having certain decimal places for exchange rates
146
- * !!! Don't change as this value is tied to store.backend DB schema !!!
147
- */
148
- exponent: 6,
149
- code: ""
150
- // Not important
151
- };
152
- exports.EXCHANGE_RATE_DINERO_CURRENCY = EXCHANGE_RATE_DINERO_CURRENCY;
153
- exports.Round = Round;
154
- exports.TAX_RATE_DINERO_CURRENCY = TAX_RATE_DINERO_CURRENCY;
155
- exports.localizedCurrencyLookup = localizedCurrencyLookup;
89
+ exports.currencyObjLookup = currencyObjLookup;
90
+ exports.financialRound = financialRound;
91
+ exports.maximumPriceFilterLookup = maximumPriceFilterLookup;
156
92
  exports.prettifyPriceLookup = prettifyPriceLookup;
157
93
  exports.smallestSubunitLookup = smallestSubunitLookup;
158
- exports.storesWithPerItemTaxRate = storesWithPerItemTaxRate;
159
94
  //# sourceMappingURL=constants.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"constants.js","sources":["../../../src/utils/money/constants.ts"],"sourcesContent":["import {\n AED,\n BGN,\n BRL,\n CAD,\n CHF,\n CZK,\n DKK,\n EUR,\n GBP,\n HRK,\n HUF,\n INR,\n JPY,\n MXN,\n NOK,\n PLN,\n RON,\n SEK,\n SGD,\n TWD,\n USD,\n ZAR,\n} from \"@dinero.js/currencies\";\nimport { down, halfEven, halfUp } from \"dinero.js\";\n\nimport { Currency, StoreId } from \"../../types\";\nimport type {\n Cents,\n DinoCurrency,\n LocalizedCurrency,\n RoundingFn,\n} from \"./types\";\n\n// #############################################################################\n// Constants\n// #############################################################################\n\nexport const Round = {\n /**\n * ⚠️ Instead of using Math.round, we HAVE to use this method to round the financial numbers everywhere where we CAN'T\n * deal with dinero.js (Dinero.js should be the priority). But often for converting from API requests we have to\n * normalise the values so we use this method.\n *\n * It just a re-export of the dinero.js halfEven (a.k.a bankers rounding) method which is the default rounding method.\n * @see https://github.com/dinerojs/dinero.js/blob/main/packages/core/src/round/halfEven.ts\n * @see\n *\n * Compared to Math.round (arithmetic rounding) it differentiates that it changes the `.5` round up or down behaviour based on if the rounded\n * number would be an even number. So 1.5 would round to 2 while 2.5 would round to 2.\n * See the youtube link below for a brief exclamation on why it's important to use this method over regular rounding (half-up):\n * https://youtu.be/yuRdYlZvs1E\n *\n * If you really want to get knee-deep in the rounding subject, you can read the following:\n * https://en.wikipedia.org/wiki/Rounding#Round_half_toward_zero\n */\n Financial: halfEven,\n // TODO: maybe we should have separate rounding functions depending on the input value?\n // Reading from wiki \"Round half toward zero\" is better if the value is already \"normalized to cents\"\n // But the \"Round half to even\" seems better for when working with float like values\n // financialRound = Math.round;\n Shipping: down,\n Prettify: down,\n Subunit: halfUp,\n} satisfies Record<string, RoundingFn>;\n\n/**\n * Mapping of how prices should be rounded down to \"whole numbers\" after certain threshold\n */\nexport const prettifyPriceLookup = new Map([\n [USD.code, 20],\n [CAD.code, 20],\n [EUR.code, 20],\n [GBP.code, 20],\n [AED.code, 50],\n // Approximately every price above ~1.1 usd will be rounded in ZAR\n [ZAR.code, 20],\n]);\n\n/**\n * Map of dinero code to subunit digit count.\n */\nexport const smallestSubunitLookup = new Map<string, [Cents, RoundingFn]>([\n /**\n * TWD does not use subunits at all in day to day transactions.\n */\n [TWD.code, [0, Round.Subunit]],\n]);\n\n/**\n * Precompiled list for faster currency and locale lookups\n */\nexport const localizedCurrencyLookup = new Map<Currency, LocalizedCurrency>([\n [Currency.Aed, { currency: AED, locale: \"ar-AE\" }],\n [Currency.Bgn, { currency: BGN, locale: \"bg-BG\" }],\n [Currency.Cad, { currency: CAD, locale: \"en-CA\" }],\n [Currency.Chf, { currency: CHF, locale: \"it-CH\" }],\n [Currency.Czk, { currency: CZK, locale: \"cs-CZ\" }],\n [Currency.Dkk, { currency: DKK, locale: \"da-DK\" }],\n [Currency.Eur, { currency: EUR, locale: \"de-DE\" }],\n [Currency.Gbp, { currency: GBP, locale: \"en-GB\" }],\n [Currency.Hrk, { currency: HRK, locale: \"hr-HR\" }],\n [Currency.Huf, { currency: HUF, locale: \"hu-HU\" }],\n [Currency.Nok, { currency: NOK, locale: \"no-NO\" }],\n [Currency.Pln, { currency: PLN, locale: \"pl-PL\" }],\n [Currency.Ron, { currency: RON, locale: \"ro-RO\" }],\n [Currency.Sek, { currency: SEK, locale: \"sv-SE\" }],\n [Currency.Usd, { currency: USD, locale: \"en-US\" }],\n [Currency.Zar, { currency: ZAR, locale: \"en-ZA\" }],\n [Currency.Inr, { currency: INR, locale: \"en-IN\" }],\n [Currency.Sgd, { currency: SGD, locale: \"en-SG\" }],\n [Currency.Brl, { currency: BRL, locale: \"pt-BR\" }],\n // NOTE: en-JP Doesn't exist\n [Currency.Jpy, { currency: JPY, locale: \"en-JP\" }],\n // NOTE: en-TW Doesn't exist\n [Currency.Twd, { currency: TWD, locale: \"en-TW\" }],\n [Currency.Mxn, { currency: MXN, locale: \"es-MX\" }],\n]);\n\n// #############################################################################\n// Tax Rate\n// #############################################################################\n/**\n * List of stores that require calculating per single item qty and then combining them to get the total tax amount for a\n * single line. Rest of the stores inherit default behavior that tax calculated on whole line item\n */\nexport const storesWithPerItemTaxRate = new Set([\n // #############################################################################\n // Stores with custom tax rates\n // #############################################################################\n StoreId.Br,\n StoreId.Tw,\n // #############################################################################\n // Stores with Avalara, but will have custom company codes to treat\n // FIXME: as PR is rushed we where able to test stores avalara custom codes that enable logic that calculates tax\n // \"per quantity\", so for now disabling this logic and only applying to store with custom tax rates\n // #############################################################################\n // StoreId.Jp,\n // StoreId.Sg,\n]);\n\n/**\n * Dinero currency option block for working with tax rates within dinero\n */\nexport const TAX_RATE_DINERO_CURRENCY = {\n base: 10,\n /**\n * We expect the tax rate to be in the range of 0..1\n * 0 --> 0%\n * 1 --> 100%\n * 0.21 --> 21%\n * 0.2169 --> 21.69%\n * 0.12345678 --> 12.345678%\n * !!! Don't change as this value is tied to store.backend DB schema !!!\n */\n exponent: 8,\n code: \"\", // Not important\n} satisfies DinoCurrency;\n\n// #############################################################################\n// Exchange Rate\n// #############################################################################\n\nexport const EXCHANGE_RATE_DINERO_CURRENCY = {\n base: 10,\n /**\n * We support having certain decimal places for exchange rates\n * !!! Don't change as this value is tied to store.backend DB schema !!!\n */\n exponent: 6,\n code: \"\", // Not important\n} satisfies DinoCurrency;\n"],"names":["Round","Financial","halfEven","Shipping","down","Prettify","Subunit","halfUp","prettifyPriceLookup","Map","USD","code","CAD","EUR","GBP","AED","ZAR","smallestSubunitLookup","TWD","localizedCurrencyLookup","Currency","Aed","currency","locale","Bgn","BGN","Cad","Chf","CHF","Czk","CZK","Dkk","DKK","Eur","Gbp","Hrk","HRK","Huf","HUF","Nok","NOK","Pln","PLN","Ron","RON","Sek","SEK","Usd","Zar","Inr","INR","Sgd","SGD","Brl","BRL","Jpy","JPY","Twd","Mxn","MXN","storesWithPerItemTaxRate","Set","StoreId","Br","Tw","TAX_RATE_DINERO_CURRENCY","base","exponent","EXCHANGE_RATE_DINERO_CURRENCY"],"mappings":";;;;;;;AAsCO,MAAMA,KAAQ,GAAA;EAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;EAkBnBC,SAAW,EAAAC,SAAA,CAAAA,QAAA;EAAA;EAAA;EAAA;EAAA;EAKXC,QAAU,EAAAC,SAAA,CAAAA,IAAA;EACVC,QAAU,EAAAD,SAAA,CAAAA,IAAA;EACVE,OAAS,EAAAC,SAAA,CAAAA;AACX,CAAA;AAKa,MAAAC,mBAAA,GAAA,mBAA0BC,GAAI,CAAA,CACzC,CAACC,UAAI,CAAAA,GAAA,CAAAC,IAAA,EAAM,EAAE,CAAA,EACb,CAACC,UAAI,CAAAA,GAAA,CAAAD,IAAA,EAAM,EAAE,CAAA,EACb,CAACE,UAAI,CAAAA,GAAA,CAAAF,IAAA,EAAM,EAAE,CAAA,EACb,CAACG,UAAI,CAAAA,GAAA,CAAAH,IAAA,EAAM,EAAE,CAAA,EACb,CAACI,UAAI,CAAAA,GAAA,CAAAJ,IAAA,EAAM,EAAE,CAAA;AAAA;AAEb,CAACK,UAAI,CAAAA,GAAA,CAAAL,IAAA,EAAM,EAAE,CAAA,CACd,CAAA;AAKY,MAAAM,qBAAA,GAAA,mBAA4BR,GAAiC,CAAA;AAAA;AAAA;AAAA;AAIxE,CAACS,UAAAA,CAAAA,GAAI,CAAAP,IAAA,EAAM,CAAC,CAAG,EAAAX,KAAA,CAAMM,OAAO,CAA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AK,MAAA,EAAQ;CAAS,CAAA,EACjD,CAACH,SAAAA,CAAAA,SAASsC,GAAK,EAAA;EAAEpC,UAAUqC,UAAAA,CAAAA,GAAK;EAAApC,MAAA,EAAQ;CAAS,CAAA,CAClD,CAAA;AASY,MAAAqC,wBAAA,GAAA,mBAA+BC,GAAI,CAAA;AAAA;AAAA;AAAA;AAI9CC,SAAAA,CAAAA,OAAQ,CAAAC,EAAA,EACRD,SAAAA,CAAAA,OAAQ,CAAAE;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,CAQT,CAAA;AAKM,MAAMC,wBAA2B,GAAA;EACtCC,IAAM,EAAA,EAAA;EAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;EAUNC,QAAU,EAAA,CAAA;EACVxD,IAAM,EAAA;EAAA;AACR,CAAA;AAMO,MAAMyD,6BAAgC,GAAA;EAC3CF,IAAM,EAAA,EAAA;EAAA;AAAA;AAAA;AAAA;EAKNC,QAAU,EAAA,CAAA;EACVxD,IAAM,EAAA;EAAA;AACR,CAAA;;;;;;;"}
1
+ {"version":3,"file":"constants.js","sources":["../../../src/utils/money/constants.ts"],"sourcesContent":["import {\n AED,\n BGN,\n BRL,\n CAD,\n CHF,\n CZK,\n DKK,\n EUR,\n GBP,\n HRK,\n HUF,\n INR,\n JPY,\n MXN,\n NOK,\n PLN,\n RON,\n SEK,\n SGD,\n TWD,\n USD,\n ZAR,\n} from \"@dinero.js/currencies\";\nimport { halfEven, halfUp } from \"dinero.js\";\n\nimport { Currency } from \"../../types\";\nimport type { CurrencyObj } from \"./types\";\n\n// #############################################################################\n// Constants\n// #############################################################################\n\n/**\n * Mapping of how prices should be rounded down to \"whole numbers\" after certain threshold\n */\nexport const prettifyPriceLookup = new Map([\n [USD.code, 20],\n [CAD.code, 20],\n [EUR.code, 20],\n [GBP.code, 20],\n [AED.code, 50],\n // Approximately every price above ~1.1 usd will be rounded in ZAR\n [ZAR.code, 20],\n]);\n\n/**\n * Map of currencycode to subunit digit count.\n */\nexport const smallestSubunitLookup = new Map<\n string,\n [number, (value: number) => number]\n>([\n /**\n * TWD does not use subunits at all in day to day transactions.\n */\n [TWD.code, [0, halfUp]],\n]);\n\n/**\n * Mapping of maximum price filter\n * TODO: Add all possible currencies\n */\nexport const maximumPriceFilterLookup = new Map([\n [CAD.code, 70000],\n [EUR.code, 70000],\n [AED.code, 70000],\n]);\n\n/**\n * ⚠️ Instead of using Math.round, we HAVE to use this method to round the financial numbers everywhere where we CAN'T\n * deal with dinero.js (Dinero.js should be the priority). But often for converting from API requests we have to\n * normalise the values so we use this method.\n *\n * It just a re-export of the dinero.js halfEven (a.k.a bankers rounding) method which is the default rounding method.\n * @see https://github.com/dinerojs/dinero.js/blob/main/packages/core/src/round/halfEven.ts\n * @see\n *\n * Compared to Math.round (arithmetic rounding) it differentiates that it changes the `.5` round up or down behaviour based on if the rounded\n * number would be an even number. So 1.5 would round to 2 while 2.5 would round to 2.\n * See the youtube link below for a brief exclamation on why it's important to use this method over regular rounding (half-up):\n * https://youtu.be/yuRdYlZvs1E\n *\n * If you really want to get knee-deep in the rounding subject, you can read the following:\n * https://en.wikipedia.org/wiki/Rounding#Round_half_toward_zero\n */\nexport const financialRound = halfEven;\n// TODO: maybe we should have separate rounding functions depending on the input value?\n// Reading from wiki \"Round half toward zero\" is better if the value is already \"normalized to cents\"\n// But the \"Round half to even\" seems better for when working with float like values\n// export const financialRound = Math.round;\n\n/**\n * Precompiled list for faster currency and locale lookups\n */\nexport const currencyObjLookup = new Map<Currency, CurrencyObj>([\n [Currency.Aed, { currency: AED, locale: \"ar-AE\" }],\n [Currency.Bgn, { currency: BGN, locale: \"bg-BG\" }],\n [Currency.Cad, { currency: CAD, locale: \"en-CA\" }],\n [Currency.Chf, { currency: CHF, locale: \"it-CH\" }],\n [Currency.Czk, { currency: CZK, locale: \"cs-CZ\" }],\n [Currency.Dkk, { currency: DKK, locale: \"da-DK\" }],\n [Currency.Eur, { currency: EUR, locale: \"de-DE\" }],\n [Currency.Gbp, { currency: GBP, locale: \"en-GB\" }],\n [Currency.Hrk, { currency: HRK, locale: \"hr-HR\" }],\n [Currency.Huf, { currency: HUF, locale: \"hu-HU\" }],\n [Currency.Nok, { currency: NOK, locale: \"no-NO\" }],\n [Currency.Pln, { currency: PLN, locale: \"pl-PL\" }],\n [Currency.Ron, { currency: RON, locale: \"ro-RO\" }],\n [Currency.Sek, { currency: SEK, locale: \"sv-SE\" }],\n [Currency.Usd, { currency: USD, locale: \"en-US\" }],\n [Currency.Zar, { currency: ZAR, locale: \"en-ZA\" }],\n [Currency.Inr, { currency: INR, locale: \"en-IN\" }],\n [Currency.Sgd, { currency: SGD, locale: \"en-SG\" }],\n [Currency.Brl, { currency: BRL, locale: \"pt-BR\" }],\n // NOTE: en-JP Doesn't exist\n [Currency.Jpy, { currency: JPY, locale: \"en-JP\" }],\n // NOTE: en-TW Doesn't exist\n [Currency.Twd, { currency: TWD, locale: \"en-TW\" }],\n [Currency.Mxn, { currency: MXN, locale: \"es-MX\" }],\n]);\n"],"names":["prettifyPriceLookup","Map","USD","code","CAD","EUR","GBP","AED","ZAR","smallestSubunitLookup","TWD","halfUp","maximumPriceFilterLookup","financialRound","halfEven","currencyObjLookup","Currency","Aed","currency","locale","Bgn","BGN","Cad","Chf","CHF","Czk","CZK","Dkk","DKK","Eur","Gbp","Hrk","HRK","Huf","HUF","Nok","NOK","Pln","PLN","Ron","RON","Sek","SEK","Usd","Zar","Inr","INR","Sgd","SGD","Brl","BRL","Jpy","JPY","Twd","Mxn","MXN"],"mappings":";;;;;;;AAoCa,MAAAA,mBAAA,GAAA,mBAA0BC,GAAI,CAAA,CACzC,CAACC,UAAI,CAAAA,GAAA,CAAAC,IAAA,EAAM,EAAE,CAAA,EACb,CAACC,UAAI,CAAAA,GAAA,CAAAD,IAAA,EAAM,EAAE,CAAA,EACb,CAACE,UAAI,CAAAA,GAAA,CAAAF,IAAA,EAAM,EAAE,CAAA,EACb,CAACG,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,GAAK,EAAA;EAAE1B,UAAUV,UAAAA,CAAAA,GAAK;EAAAW,MAAA,EAAQ;CAAS,CAAA,EACjD,CAACH,SAAAA,CAAAA,SAAS6B,GAAK,EAAA;EAAE3B,UAAU4B,UAAAA,CAAAA,GAAK;EAAA3B,MAAA,EAAQ;CAAS,CAAA,EACjD,CAACH,SAAAA,CAAAA,SAAS+B,GAAK,EAAA;EAAE7B,UAAU8B,UAAAA,CAAAA,GAAK;EAAA7B,MAAA,EAAQ;CAAS,CAAA,EACjD,CAACH,SAAAA,CAAAA,SAASiC,GAAK,EAAA;EAAE/B,UAAUgC,UAAAA,CAAAA,GAAK;EAAA/B,MAAA,EAAQ;CAAS,CAAA;AAAA;AAEjD,CAACH,SAAAA,CAAAA,SAASmC,GAAK,EAAA;EAAEjC,UAAUkC,UAAAA,CAAAA,GAAK;EAAAjC,MAAA,EAAQ;CAAS,CAAA;AAAA;AAEjD,CAACH,SAAAA,CAAAA,SAASqC,GAAK,EAAA;EAAEnC,UAAUR,UAAAA,CAAAA,GAAK;EAAAS,MAAA,EAAQ;CAAS,CAAA,EACjD,CAACH,SAAAA,CAAAA,SAASsC,GAAK,EAAA;EAAEpC,UAAUqC,UAAAA,CAAAA,GAAK;EAAApC,MAAA,EAAQ;CAAS,CAAA,CAClD,CAAA;;;;;"}
@@ -1,35 +1,8 @@
1
1
  import { USD, CAD, EUR, GBP, AED, ZAR, TWD, BGN, CHF, CZK, DKK, HRK, HUF, NOK, PLN, RON, SEK, INR, SGD, BRL, JPY, MXN } from '@dinero.js/currencies';
2
- import { halfEven, down, halfUp } from 'dinero.js';
2
+ import { halfUp, halfEven } from 'dinero.js';
3
3
  import '../../types/index.mjs';
4
- import { Currency, StoreId } from '../../types/generated.mjs';
4
+ import { Currency } from '../../types/generated.mjs';
5
5
  "use strict";
6
- const Round = {
7
- /**
8
- * ⚠️ Instead of using Math.round, we HAVE to use this method to round the financial numbers everywhere where we CAN'T
9
- * deal with dinero.js (Dinero.js should be the priority). But often for converting from API requests we have to
10
- * normalise the values so we use this method.
11
- *
12
- * It just a re-export of the dinero.js halfEven (a.k.a bankers rounding) method which is the default rounding method.
13
- * @see https://github.com/dinerojs/dinero.js/blob/main/packages/core/src/round/halfEven.ts
14
- * @see
15
- *
16
- * Compared to Math.round (arithmetic rounding) it differentiates that it changes the `.5` round up or down behaviour based on if the rounded
17
- * number would be an even number. So 1.5 would round to 2 while 2.5 would round to 2.
18
- * See the youtube link below for a brief exclamation on why it's important to use this method over regular rounding (half-up):
19
- * https://youtu.be/yuRdYlZvs1E
20
- *
21
- * If you really want to get knee-deep in the rounding subject, you can read the following:
22
- * https://en.wikipedia.org/wiki/Rounding#Round_half_toward_zero
23
- */
24
- Financial: halfEven,
25
- // TODO: maybe we should have separate rounding functions depending on the input value?
26
- // Reading from wiki "Round half toward zero" is better if the value is already "normalized to cents"
27
- // But the "Round half to even" seems better for when working with float like values
28
- // financialRound = Math.round;
29
- Shipping: down,
30
- Prettify: down,
31
- Subunit: halfUp
32
- };
33
6
  const prettifyPriceLookup = /* @__PURE__ */new Map([[USD.code, 20], [CAD.code, 20], [EUR.code, 20], [GBP.code, 20], [AED.code, 50],
34
7
  // Approximately every price above ~1.1 usd will be rounded in ZAR
35
8
  [ZAR.code, 20]]);
@@ -37,8 +10,10 @@ const smallestSubunitLookup = /* @__PURE__ */new Map([
37
10
  /**
38
11
  * TWD does not use subunits at all in day to day transactions.
39
12
  */
40
- [TWD.code, [0, Round.Subunit]]]);
41
- const localizedCurrencyLookup = /* @__PURE__ */new Map([[Currency.Aed, {
13
+ [TWD.code, [0, halfUp]]]);
14
+ const maximumPriceFilterLookup = /* @__PURE__ */new Map([[CAD.code, 7e4], [EUR.code, 7e4], [AED.code, 7e4]]);
15
+ const financialRound = halfEven;
16
+ const currencyObjLookup = /* @__PURE__ */new Map([[Currency.Aed, {
42
17
  currency: AED,
43
18
  locale: "ar-AE"
44
19
  }], [Currency.Bgn, {
@@ -109,43 +84,5 @@ const localizedCurrencyLookup = /* @__PURE__ */new Map([[Currency.Aed, {
109
84
  currency: MXN,
110
85
  locale: "es-MX"
111
86
  }]]);
112
- const storesWithPerItemTaxRate = /* @__PURE__ */new Set([
113
- // #############################################################################
114
- // Stores with custom tax rates
115
- // #############################################################################
116
- StoreId.Br, StoreId.Tw
117
- // #############################################################################
118
- // Stores with Avalara, but will have custom company codes to treat
119
- // FIXME: as PR is rushed we where able to test stores avalara custom codes that enable logic that calculates tax
120
- // "per quantity", so for now disabling this logic and only applying to store with custom tax rates
121
- // #############################################################################
122
- // StoreId.Jp,
123
- // StoreId.Sg,
124
- ]);
125
- const TAX_RATE_DINERO_CURRENCY = {
126
- base: 10,
127
- /**
128
- * We expect the tax rate to be in the range of 0..1
129
- * 0 --> 0%
130
- * 1 --> 100%
131
- * 0.21 --> 21%
132
- * 0.2169 --> 21.69%
133
- * 0.12345678 --> 12.345678%
134
- * !!! Don't change as this value is tied to store.backend DB schema !!!
135
- */
136
- exponent: 8,
137
- code: ""
138
- // Not important
139
- };
140
- const EXCHANGE_RATE_DINERO_CURRENCY = {
141
- base: 10,
142
- /**
143
- * We support having certain decimal places for exchange rates
144
- * !!! Don't change as this value is tied to store.backend DB schema !!!
145
- */
146
- exponent: 6,
147
- code: ""
148
- // Not important
149
- };
150
- export { EXCHANGE_RATE_DINERO_CURRENCY, Round, TAX_RATE_DINERO_CURRENCY, localizedCurrencyLookup, prettifyPriceLookup, smallestSubunitLookup, storesWithPerItemTaxRate };
87
+ export { currencyObjLookup, financialRound, maximumPriceFilterLookup, prettifyPriceLookup, smallestSubunitLookup };
151
88
  //# sourceMappingURL=constants.mjs.map
@@ -1 +1 @@
1
- {"version":3,"file":"constants.mjs","sources":["../../../src/utils/money/constants.ts"],"sourcesContent":["import {\n AED,\n BGN,\n BRL,\n CAD,\n CHF,\n CZK,\n DKK,\n EUR,\n GBP,\n HRK,\n HUF,\n INR,\n JPY,\n MXN,\n NOK,\n PLN,\n RON,\n SEK,\n SGD,\n TWD,\n USD,\n ZAR,\n} from \"@dinero.js/currencies\";\nimport { down, halfEven, halfUp } from \"dinero.js\";\n\nimport { Currency, StoreId } from \"../../types\";\nimport type {\n Cents,\n DinoCurrency,\n LocalizedCurrency,\n RoundingFn,\n} from \"./types\";\n\n// #############################################################################\n// Constants\n// #############################################################################\n\nexport const Round = {\n /**\n * ⚠️ Instead of using Math.round, we HAVE to use this method to round the financial numbers everywhere where we CAN'T\n * deal with dinero.js (Dinero.js should be the priority). But often for converting from API requests we have to\n * normalise the values so we use this method.\n *\n * It just a re-export of the dinero.js halfEven (a.k.a bankers rounding) method which is the default rounding method.\n * @see https://github.com/dinerojs/dinero.js/blob/main/packages/core/src/round/halfEven.ts\n * @see\n *\n * Compared to Math.round (arithmetic rounding) it differentiates that it changes the `.5` round up or down behaviour based on if the rounded\n * number would be an even number. So 1.5 would round to 2 while 2.5 would round to 2.\n * See the youtube link below for a brief exclamation on why it's important to use this method over regular rounding (half-up):\n * https://youtu.be/yuRdYlZvs1E\n *\n * If you really want to get knee-deep in the rounding subject, you can read the following:\n * https://en.wikipedia.org/wiki/Rounding#Round_half_toward_zero\n */\n Financial: halfEven,\n // TODO: maybe we should have separate rounding functions depending on the input value?\n // Reading from wiki \"Round half toward zero\" is better if the value is already \"normalized to cents\"\n // But the \"Round half to even\" seems better for when working with float like values\n // financialRound = Math.round;\n Shipping: down,\n Prettify: down,\n Subunit: halfUp,\n} satisfies Record<string, RoundingFn>;\n\n/**\n * Mapping of how prices should be rounded down to \"whole numbers\" after certain threshold\n */\nexport const prettifyPriceLookup = new Map([\n [USD.code, 20],\n [CAD.code, 20],\n [EUR.code, 20],\n [GBP.code, 20],\n [AED.code, 50],\n // Approximately every price above ~1.1 usd will be rounded in ZAR\n [ZAR.code, 20],\n]);\n\n/**\n * Map of dinero code to subunit digit count.\n */\nexport const smallestSubunitLookup = new Map<string, [Cents, RoundingFn]>([\n /**\n * TWD does not use subunits at all in day to day transactions.\n */\n [TWD.code, [0, Round.Subunit]],\n]);\n\n/**\n * Precompiled list for faster currency and locale lookups\n */\nexport const localizedCurrencyLookup = new Map<Currency, LocalizedCurrency>([\n [Currency.Aed, { currency: AED, locale: \"ar-AE\" }],\n [Currency.Bgn, { currency: BGN, locale: \"bg-BG\" }],\n [Currency.Cad, { currency: CAD, locale: \"en-CA\" }],\n [Currency.Chf, { currency: CHF, locale: \"it-CH\" }],\n [Currency.Czk, { currency: CZK, locale: \"cs-CZ\" }],\n [Currency.Dkk, { currency: DKK, locale: \"da-DK\" }],\n [Currency.Eur, { currency: EUR, locale: \"de-DE\" }],\n [Currency.Gbp, { currency: GBP, locale: \"en-GB\" }],\n [Currency.Hrk, { currency: HRK, locale: \"hr-HR\" }],\n [Currency.Huf, { currency: HUF, locale: \"hu-HU\" }],\n [Currency.Nok, { currency: NOK, locale: \"no-NO\" }],\n [Currency.Pln, { currency: PLN, locale: \"pl-PL\" }],\n [Currency.Ron, { currency: RON, locale: \"ro-RO\" }],\n [Currency.Sek, { currency: SEK, locale: \"sv-SE\" }],\n [Currency.Usd, { currency: USD, locale: \"en-US\" }],\n [Currency.Zar, { currency: ZAR, locale: \"en-ZA\" }],\n [Currency.Inr, { currency: INR, locale: \"en-IN\" }],\n [Currency.Sgd, { currency: SGD, locale: \"en-SG\" }],\n [Currency.Brl, { currency: BRL, locale: \"pt-BR\" }],\n // NOTE: en-JP Doesn't exist\n [Currency.Jpy, { currency: JPY, locale: \"en-JP\" }],\n // NOTE: en-TW Doesn't exist\n [Currency.Twd, { currency: TWD, locale: \"en-TW\" }],\n [Currency.Mxn, { currency: MXN, locale: \"es-MX\" }],\n]);\n\n// #############################################################################\n// Tax Rate\n// #############################################################################\n/**\n * List of stores that require calculating per single item qty and then combining them to get the total tax amount for a\n * single line. Rest of the stores inherit default behavior that tax calculated on whole line item\n */\nexport const storesWithPerItemTaxRate = new Set([\n // #############################################################################\n // Stores with custom tax rates\n // #############################################################################\n StoreId.Br,\n StoreId.Tw,\n // #############################################################################\n // Stores with Avalara, but will have custom company codes to treat\n // FIXME: as PR is rushed we where able to test stores avalara custom codes that enable logic that calculates tax\n // \"per quantity\", so for now disabling this logic and only applying to store with custom tax rates\n // #############################################################################\n // StoreId.Jp,\n // StoreId.Sg,\n]);\n\n/**\n * Dinero currency option block for working with tax rates within dinero\n */\nexport const TAX_RATE_DINERO_CURRENCY = {\n base: 10,\n /**\n * We expect the tax rate to be in the range of 0..1\n * 0 --> 0%\n * 1 --> 100%\n * 0.21 --> 21%\n * 0.2169 --> 21.69%\n * 0.12345678 --> 12.345678%\n * !!! Don't change as this value is tied to store.backend DB schema !!!\n */\n exponent: 8,\n code: \"\", // Not important\n} satisfies DinoCurrency;\n\n// #############################################################################\n// Exchange Rate\n// #############################################################################\n\nexport const EXCHANGE_RATE_DINERO_CURRENCY = {\n base: 10,\n /**\n * We support having certain decimal places for exchange rates\n * !!! Don't change as this value is tied to store.backend DB schema !!!\n */\n exponent: 6,\n code: \"\", // Not important\n} satisfies DinoCurrency;\n"],"names":["Round","Financial","halfEven","Shipping","down","Prettify","Subunit","halfUp","prettifyPriceLookup","Map","USD","code","CAD","EUR","GBP","AED","ZAR","smallestSubunitLookup","TWD","localizedCurrencyLookup","Currency","Aed","currency","locale","Bgn","BGN","Cad","Chf","CHF","Czk","CZK","Dkk","DKK","Eur","Gbp","Hrk","HRK","Huf","HUF","Nok","NOK","Pln","PLN","Ron","RON","Sek","SEK","Usd","Zar","Inr","INR","Sgd","SGD","Brl","BRL","Jpy","JPY","Twd","Mxn","MXN","storesWithPerItemTaxRate","Set","StoreId","Br","Tw","TAX_RATE_DINERO_CURRENCY","base","exponent","EXCHANGE_RATE_DINERO_CURRENCY"],"mappings":";;;;;AAsCO,MAAMA,KAAQ,GAAA;EAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;EAkBnBC,SAAW,EAAAC,QAAA;EAAA;EAAA;EAAA;EAAA;EAKXC,QAAU,EAAA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ACH,SAASsC,GAAK,EAAA;EAAEpC,UAAUqC,GAAK;EAAApC,MAAA,EAAQ;CAAS,CAAA,CAClD,CAAA;AASY,MAAAqC,wBAAA,GAAA,mBAA+BC,GAAI,CAAA;AAAA;AAAA;AAAA;AAI9CC,OAAQ,CAAAC,EAAA,EACRD,OAAQ,CAAAE;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,CAQT,CAAA;AAKM,MAAMC,wBAA2B,GAAA;EACtCC,IAAM,EAAA,EAAA;EAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;EAUNC,QAAU,EAAA,CAAA;EACVxD,IAAM,EAAA;EAAA;AACR,CAAA;AAMO,MAAMyD,6BAAgC,GAAA;EAC3CF,IAAM,EAAA,EAAA;EAAA;AAAA;AAAA;AAAA;EAKNC,QAAU,EAAA,CAAA;EACVxD,IAAM,EAAA;EAAA;AACR,CAAA;"}
1
+ {"version":3,"file":"constants.mjs","sources":["../../../src/utils/money/constants.ts"],"sourcesContent":["import {\n AED,\n BGN,\n BRL,\n CAD,\n CHF,\n CZK,\n DKK,\n EUR,\n GBP,\n HRK,\n HUF,\n INR,\n JPY,\n MXN,\n NOK,\n PLN,\n RON,\n SEK,\n SGD,\n TWD,\n USD,\n ZAR,\n} from \"@dinero.js/currencies\";\nimport { halfEven, halfUp } from \"dinero.js\";\n\nimport { Currency } from \"../../types\";\nimport type { CurrencyObj } from \"./types\";\n\n// #############################################################################\n// Constants\n// #############################################################################\n\n/**\n * Mapping of how prices should be rounded down to \"whole numbers\" after certain threshold\n */\nexport const prettifyPriceLookup = new Map([\n [USD.code, 20],\n [CAD.code, 20],\n [EUR.code, 20],\n [GBP.code, 20],\n [AED.code, 50],\n // Approximately every price above ~1.1 usd will be rounded in ZAR\n [ZAR.code, 20],\n]);\n\n/**\n * Map of currencycode to subunit digit count.\n */\nexport const smallestSubunitLookup = new Map<\n string,\n [number, (value: number) => number]\n>([\n /**\n * TWD does not use subunits at all in day to day transactions.\n */\n [TWD.code, [0, halfUp]],\n]);\n\n/**\n * Mapping of maximum price filter\n * TODO: Add all possible currencies\n */\nexport const maximumPriceFilterLookup = new Map([\n [CAD.code, 70000],\n [EUR.code, 70000],\n [AED.code, 70000],\n]);\n\n/**\n * ⚠️ Instead of using Math.round, we HAVE to use this method to round the financial numbers everywhere where we CAN'T\n * deal with dinero.js (Dinero.js should be the priority). But often for converting from API requests we have to\n * normalise the values so we use this method.\n *\n * It just a re-export of the dinero.js halfEven (a.k.a bankers rounding) method which is the default rounding method.\n * @see https://github.com/dinerojs/dinero.js/blob/main/packages/core/src/round/halfEven.ts\n * @see\n *\n * Compared to Math.round (arithmetic rounding) it differentiates that it changes the `.5` round up or down behaviour based on if the rounded\n * number would be an even number. So 1.5 would round to 2 while 2.5 would round to 2.\n * See the youtube link below for a brief exclamation on why it's important to use this method over regular rounding (half-up):\n * https://youtu.be/yuRdYlZvs1E\n *\n * If you really want to get knee-deep in the rounding subject, you can read the following:\n * https://en.wikipedia.org/wiki/Rounding#Round_half_toward_zero\n */\nexport const financialRound = halfEven;\n// TODO: maybe we should have separate rounding functions depending on the input value?\n// Reading from wiki \"Round half toward zero\" is better if the value is already \"normalized to cents\"\n// But the \"Round half to even\" seems better for when working with float like values\n// export const financialRound = Math.round;\n\n/**\n * Precompiled list for faster currency and locale lookups\n */\nexport const currencyObjLookup = new Map<Currency, CurrencyObj>([\n [Currency.Aed, { currency: AED, locale: \"ar-AE\" }],\n [Currency.Bgn, { currency: BGN, locale: \"bg-BG\" }],\n [Currency.Cad, { currency: CAD, locale: \"en-CA\" }],\n [Currency.Chf, { currency: CHF, locale: \"it-CH\" }],\n [Currency.Czk, { currency: CZK, locale: \"cs-CZ\" }],\n [Currency.Dkk, { currency: DKK, locale: \"da-DK\" }],\n [Currency.Eur, { currency: EUR, locale: \"de-DE\" }],\n [Currency.Gbp, { currency: GBP, locale: \"en-GB\" }],\n [Currency.Hrk, { currency: HRK, locale: \"hr-HR\" }],\n [Currency.Huf, { currency: HUF, locale: \"hu-HU\" }],\n [Currency.Nok, { currency: NOK, locale: \"no-NO\" }],\n [Currency.Pln, { currency: PLN, locale: \"pl-PL\" }],\n [Currency.Ron, { currency: RON, locale: \"ro-RO\" }],\n [Currency.Sek, { currency: SEK, locale: \"sv-SE\" }],\n [Currency.Usd, { currency: USD, locale: \"en-US\" }],\n [Currency.Zar, { currency: ZAR, locale: \"en-ZA\" }],\n [Currency.Inr, { currency: INR, locale: \"en-IN\" }],\n [Currency.Sgd, { currency: SGD, locale: \"en-SG\" }],\n [Currency.Brl, { currency: BRL, locale: \"pt-BR\" }],\n // NOTE: en-JP Doesn't exist\n [Currency.Jpy, { currency: JPY, locale: \"en-JP\" }],\n // NOTE: en-TW Doesn't exist\n [Currency.Twd, { currency: TWD, locale: \"en-TW\" }],\n [Currency.Mxn, { currency: MXN, locale: \"es-MX\" }],\n]);\n"],"names":["prettifyPriceLookup","Map","USD","code","CAD","EUR","GBP","AED","ZAR","smallestSubunitLookup","TWD","halfUp","maximumPriceFilterLookup","financialRound","halfEven","currencyObjLookup","Currency","Aed","currency","locale","Bgn","BGN","Cad","Chf","CHF","Czk","CZK","Dkk","DKK","Eur","Gbp","Hrk","HRK","Huf","HUF","Nok","NOK","Pln","PLN","Ron","RON","Sek","SEK","Usd","Zar","Inr","INR","Sgd","SGD","Brl","BRL","Jpy","JPY","Twd","Mxn","MXN"],"mappings":";;;;;AAoCa,MAAAA,mBAAA,GAAA,mBAA0BC,GAAI,CAAA,CACzC,CAACC,GAAI,CAAAC,IAAA,EAAM,EAAE,CAAA,EACb,CAACC,GAAI,CAAAD,IAAA,EAAM,EAAE,CAAA,EACb,CAACE,GAAI,CAAAF,IAAA,EAAM,EAAE,CAAA,EACb,CAACG,GAAI,CAAAH,IAAA,EAAM,EAAE,CAAA,EACb,CAACI,GAAI,CAAAJ,IAAA,EAAM,EAAE,CAAA;AAAA;AAEb,CAACK,GAAI,CAAAL,IAAA,EAAM,EAAE,CAAA,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LocalizedCurrency, Money } from "./types";
3
- export declare const getLocalizedCurrency: (currencyCode: Nullish<Currency>) => LocalizedCurrency | undefined;
3
+ import type { Money } from "./misc";
4
+ import type { CurrencyObj } from "./types";
5
+ export declare const getCurrencyObj: (currencyCode: Nullish<Currency>) => CurrencyObj | undefined;
4
6
  export type FormatPriceOptions = {
5
7
  /**
6
8
  * Optionally remove trailing zeroes (only if all of them are 0)
7
- * @default false
8
9
  * @example
9
10
  * "420,66 €" => "420,66 €"
10
11
  * "420,60 €" => "420,60 €"
@@ -17,7 +18,6 @@ export type FormatPriceOptions = {
17
18
  *
18
19
  * ! Only use for display purposes where monetary precision is not required!
19
20
  *
20
- * @default false
21
21
  * @example
22
22
  * "420,66 €" => "420 €"
23
23
  * "420,60 €" => "420 €"
@@ -34,15 +34,10 @@ export type FormatPriceOptions = {
34
34
  * @deprecated Use `formatPrice` instead as this functions is for INTERNAL USE ONLY! (function not actual deprecated,
35
35
  * just marked so it discourages usage of it)
36
36
  */
37
- export declare function formatPriceRaw(dinero: Dino, locale: string, options?: FormatPriceOptions): string;
37
+ export declare function formatPriceRaw(dineroObject: Dinero<number>, locale: string, options?: FormatPriceOptions): string;
38
38
  /**
39
39
  * Currency formatter based on dinero currency types and browser internationalizing functions
40
40
  *
41
41
  * In reality just a wrapper around `formatPriceRaw` that does the real formatting
42
42
  */
43
43
  export declare const formatPrice: (money: Money, options?: FormatPriceOptions) => string;
44
- /**
45
- * Prettify numbers depending on the currency using rounding down.
46
- * ! Should only be used to prettify storefront product prices after currency conversion but nothing else !
47
- */
48
- export declare const prettifyTotal: (total: Dino) => Dino;
@@ -1,12 +1,10 @@
1
1
  'use strict';
2
2
 
3
3
  var dinero_js = require('dinero.js');
4
- var errors = require('../errors.js');
5
4
  var constants = require('./constants.js');
6
- var misc = require('./misc.js');
7
5
  "use strict";
8
- const getLocalizedCurrency = currencyCode => {
9
- return currencyCode ? constants.localizedCurrencyLookup.get(currencyCode) : void 0;
6
+ const getCurrencyObj = currencyCode => {
7
+ return currencyCode ? constants.currencyObjLookup.get(currencyCode) : void 0;
10
8
  };
11
9
  const currencyFormatterCache = /* @__PURE__ */new Map();
12
10
  const getCurrencyFormatter = (locale, currencyCode) => {
@@ -19,7 +17,7 @@ const getCurrencyFormatter = (locale, currencyCode) => {
19
17
  style: "currency",
20
18
  currency: currencyCode,
21
19
  /**
22
- * Explicitly define default behavior - just in case some runtime overrides it
20
+ * Explicitly define default behaviour - just in case some runtime overrides it
23
21
  * @see https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Intl/NumberFormat/NumberFormat#currencysign
24
22
  * @see https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Intl/NumberFormat/NumberFormat#currencydisplay
25
23
  */
@@ -29,8 +27,8 @@ const getCurrencyFormatter = (locale, currencyCode) => {
29
27
  currencyFormatterCache.set(cacheKey, formatter);
30
28
  return formatter;
31
29
  };
32
- function formatPriceRaw(dinero, locale, options) {
33
- return dinero_js.toFormat(dinero, ({
30
+ function formatPriceRaw(dineroObject, locale, options) {
31
+ return dinero_js.toFormat(dineroObject, ({
34
32
  amount,
35
33
  currency
36
34
  }) => {
@@ -53,23 +51,17 @@ function formatPriceRaw(dinero, locale, options) {
53
51
  });
54
52
  }
55
53
  const formatPrice = (money, options) => {
56
- const localizedCurrency = getLocalizedCurrency(money.currency);
57
- errors.assert(!!localizedCurrency, `Currency ${money.currency} not supported`);
58
- return formatPriceRaw(misc.getDinero(money.amount, money.currency), localizedCurrency.locale, options);
59
- };
60
- const prettifyTotal = total => {
61
- if (!dinero_js.hasSubUnits(total)) {
62
- return total;
63
- }
64
- const totalJson = total.toJSON();
65
- const minValueInclusiveToRoundDownFrom = constants.prettifyPriceLookup.get(totalJson.currency.code);
66
- if (minValueInclusiveToRoundDownFrom == null || dinero_js.toUnit(total) < minValueInclusiveToRoundDownFrom) {
67
- return total;
54
+ const currencyObj = getCurrencyObj(money.currency);
55
+ if (!currencyObj) {
56
+ throw new Error(`Currency ${money.currency} not supported`);
68
57
  }
69
- return misc.roundDinero(total, constants.Round.Prettify);
58
+ const d = dinero_js.dinero({
59
+ amount: money.amount,
60
+ currency: currencyObj.currency
61
+ });
62
+ return formatPriceRaw(d, currencyObj.locale, options);
70
63
  };
71
64
  exports.formatPrice = formatPrice;
72
65
  exports.formatPriceRaw = formatPriceRaw;
73
- exports.getLocalizedCurrency = getLocalizedCurrency;
74
- exports.prettifyTotal = prettifyTotal;
66
+ exports.getCurrencyObj = getCurrencyObj;
75
67
  //# sourceMappingURL=format.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"format.js","sources":["../../../src/utils/money/format.ts"],"sourcesContent":["import { hasSubUnits, toFormat, toUnit } from \"dinero.js\";\n\nimport type { Currency, Nullish } from \"../../types\";\nimport { assert } from \"../errors\";\nimport {\n localizedCurrencyLookup,\n prettifyPriceLookup,\n Round,\n} from \"./constants\";\nimport { getDinero, roundDinero } from \"./misc\";\nimport type { Dino, LocalizedCurrency, Money } from \"./types\";\n\nexport const getLocalizedCurrency = (\n currencyCode: Nullish<Currency>,\n): LocalizedCurrency | undefined => {\n return currencyCode ? localizedCurrencyLookup.get(currencyCode) : undefined;\n};\n\n// #############################################################################\n// Formatter\n// #############################################################################\nconst currencyFormatterCache = new Map<string, Intl.NumberFormat>();\n/**\n * Function to get a Int.NumberFormat instance that can be reused to format currency over using\n * `Number.toLocaleString(...)` function, which makes more sense to use as we usually just display 1 or 2 currencies\n * MAX, so reusing the formatted makes a lot of sense\n * @see https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Number/toLocaleString#performance\n */\nconst getCurrencyFormatter = (\n locale: string,\n currencyCode: string,\n): Intl.NumberFormat => {\n const cacheKey = `${locale}_${currencyCode}`;\n\n let formatter = currencyFormatterCache.get(cacheKey);\n if (formatter) {\n return formatter;\n }\n\n formatter = new Intl.NumberFormat(locale, {\n style: \"currency\",\n currency: currencyCode,\n /**\n * Explicitly define default behavior - just in case some runtime overrides it\n * @see https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Intl/NumberFormat/NumberFormat#currencysign\n * @see https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Intl/NumberFormat/NumberFormat#currencydisplay\n */\n currencySign: \"standard\",\n currencyDisplay: \"symbol\",\n });\n currencyFormatterCache.set(cacheKey, formatter);\n\n return formatter;\n};\n\nexport type FormatPriceOptions = {\n /**\n * Optionally remove trailing zeroes (only if all of them are 0)\n * @default false\n * @example\n * \"420,66 €\" => \"420,66 €\"\n * \"420,60 €\" => \"420,60 €\"\n * \"420,00 €\" => \"420 €\"\n */\n removeTrailingZeros?: boolean;\n /**\n * Optionally return currency rounded down to the nearest dollar-equivalent of a the given currency. Doesn't apply any\n * rounding just \"trims\" end decimal values\n *\n * ! Only use for display purposes where monetary precision is not required!\n *\n * @default false\n * @example\n * \"420,66 €\" => \"420 €\"\n * \"420,60 €\" => \"420 €\"\n * \"420,00 €\" => \"420 €\"\n */\n removeFractions?: boolean;\n};\n\n/**\n * Currency formatter based on dinero currency types and browser internationalizing functions\n *\n * Based on:\n * @see https://v2.dinerojs.com/docs/guides/formatting-in-a-multilingual-site#building-a-custom-internationalization-formatter\n * @protected\n * @deprecated Use `formatPrice` instead as this functions is for INTERNAL USE ONLY! (function not actual deprecated,\n * just marked so it discourages usage of it)\n */\nexport function formatPriceRaw(\n dinero: Dino,\n locale: string,\n options?: FormatPriceOptions,\n): string {\n return toFormat(dinero, ({ amount, currency }) => {\n const formatter = getCurrencyFormatter(locale, currency.code);\n const formatted = formatter.format(amount);\n\n return options?.removeFractions || options?.removeTrailingZeros\n ? /**\n * Regex to handle complex removing trailing zeros from currency\n * - Dynamically create regex based on currency as their exponent changes\n * - Also handles some currencies (e.g. EUR) having trailing currency symbol\n *\n * TODO: improve how we detect \"decimal separator\" for formatted currency, at least right now we have tests for it and doesn't seem like an issue\n */\n formatted.replace(\n // For some reason `\\.` need to be double-escaped `\\\\` when creating the regex from template string\n new RegExp(\n `(\\\\.|,)${\n // Depending options remove all trailing digits or just zeros, this way we don't need to do any rounding\n options?.removeFractions ? \"\\\\d\" : 0\n }{0,${currency.exponent}}(\\\\s\\\\D)?$`,\n ),\n // In the replaced using \"last capture group\" (if-exists) so we restore the trailing currency sign\n \"$2\",\n )\n : formatted;\n });\n}\n\n/**\n * Currency formatter based on dinero currency types and browser internationalizing functions\n *\n * In reality just a wrapper around `formatPriceRaw` that does the real formatting\n */\nexport const formatPrice = (\n money: Money,\n options?: FormatPriceOptions,\n): string => {\n const localizedCurrency = getLocalizedCurrency(money.currency);\n assert(!!localizedCurrency, `Currency ${money.currency} not supported`);\n\n return formatPriceRaw(\n getDinero(money.amount, money.currency),\n localizedCurrency.locale,\n options,\n );\n};\n\n/**\n * Prettify numbers depending on the currency using rounding down.\n * ! Should only be used to prettify storefront product prices after currency conversion but nothing else !\n */\nexport const prettifyTotal = (total: Dino): Dino => {\n // Nothing to round\n if (!hasSubUnits(total)) {\n return total;\n }\n\n const totalJson = total.toJSON();\n\n const minValueInclusiveToRoundDownFrom = prettifyPriceLookup.get(\n totalJson.currency.code,\n );\n\n // Don't round if currency unsupported or value is below min threshold\n if (\n minValueInclusiveToRoundDownFrom == null ||\n toUnit(total) < minValueInclusiveToRoundDownFrom\n ) {\n return total;\n }\n\n return roundDinero(total, Round.Prettify);\n};\n"],"names":["getLocalizedCurrency","currencyCode","localizedCurrencyLookup","get","currencyFormatterCache","Map","getCurrencyFormatter","locale","cacheKey","formatter","Intl","NumberFormat","style","currency","currencySign","currencyDisplay","set","formatPriceRaw","dinero","options","toFormat","amount","code","formatted","format","removeFractions","removeTrailingZeros","replace","RegExp","exponent","formatPrice","money","localizedCurrency","assert","getDinero","prettifyTotal","total","hasSubUnits","totalJson","toJSON","minValueInclusiveToRoundDownFrom","prettifyPriceLookup","toUnit","roundDinero","Round","Prettify"],"mappings":";;;;;;;AAYa,MAAAA,oBAAA,GACXC,YACkC,IAAA;EAClC,OAAOA,YA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N,SAAA;EAAA,CACL,CAAA;AACH;AAOa,MAAAO,WAAA,GAAcA,CACzBC,KAAA,EACAZ,OACW,KAAA;EACL,MAAAa,iBAAA,GAAoBhC,oBAAqB,CAAA+B,KAAA,CAAMlB,QAAQ,CAAA;EAC7DoB,aAAA,CAAO,CAAC,CAACD,iBAAA,EAA+B,YAAAD,KAAA,CAAMlB,QAAwB,gBAAA,CAAA;EAE/D,OAAAI,cAAA,CACLiB,IAAAA,CAAAA,SAAU,CAAAH,KAAA,CAAMV,MAAQ,EAAAU,KAAA,CAAMlB,QAAQ,CAAA,EACtCmB,iBAAkB,CAAAzB,MAAA,EAClBY,OAAA,CACF;AACF,CAAA;AAMa,MAAAgB,aAAA,GAAiBC,KAAsB,IAAA;EAE9C,IAAA,CAACC,SAAAA,CAAAA,WAAY,CAAAD,KAAK,CAAG,EAAA;IAChB,OAAAA,KAAA;EACT;EAEM,MAAAE,SAAA,GAAYF,MAAMG,MAAO,EAAA;EAE/B,MAAMC,mCAAmCC,SAAAA,CAAAA,mBAAoB,CAAAtC,GAAA,CAC3DmC,UAAUzB,QAAS,CAAAS,IAAA,CACrB;EAGA,IACEkB,gCAAoC,IAAA,IAAA,IACpCE,SAAO,CAAAA,MAAA,CAAAN,KAAK,IAAII,gCAChB,EAAA;IACO,OAAAJ,KAAA;EACT;EAEO,OAAAO,gBAAA,CAAYP,KAAO,EAAAQ,SAAA,CAAAA,KAAA,CAAMC,QAAQ,CAAA;AAC1C,CAAA;;;;"}
1
+ {"version":3,"file":"format.js","sources":["../../../src/utils/money/format.ts"],"sourcesContent":["import { dinero, toFormat } from \"dinero.js\";\nimport type { Dinero } from \"dinero.js\";\n\nimport type { Currency, Nullish } from \"../../types\";\nimport { currencyObjLookup } from \"./constants\";\nimport type { Money } from \"./misc\";\nimport type { CurrencyObj } from \"./types\";\n\nexport const getCurrencyObj = (\n currencyCode: Nullish<Currency>,\n): CurrencyObj | undefined => {\n return currencyCode ? currencyObjLookup.get(currencyCode) : undefined;\n};\n\n// #############################################################################\n// Formatter\n// #############################################################################\nconst currencyFormatterCache = new Map<string, Intl.NumberFormat>();\n/**\n * Function to get a Int.NumberFormat instance that can be reused to format currency over using\n * `Number.toLocaleString(...)` function, which makes more sense to use as we usually just display 1 or 2 currencies\n * MAX, so reusing the formatted makes a lot of sense\n * @see https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Number/toLocaleString#performance\n */\nconst getCurrencyFormatter = (\n locale: string,\n currencyCode: string,\n): Intl.NumberFormat => {\n const cacheKey = `${locale}_${currencyCode}`;\n let formatter = currencyFormatterCache.get(cacheKey);\n if (formatter) {\n return formatter;\n }\n\n formatter = new Intl.NumberFormat(locale, {\n style: \"currency\",\n currency: currencyCode,\n /**\n * Explicitly define default behaviour - just in case some runtime overrides it\n * @see https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Intl/NumberFormat/NumberFormat#currencysign\n * @see https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Intl/NumberFormat/NumberFormat#currencydisplay\n */\n currencySign: \"standard\",\n currencyDisplay: \"symbol\",\n });\n currencyFormatterCache.set(cacheKey, formatter);\n\n return formatter;\n};\n\nexport type FormatPriceOptions = {\n /**\n * Optionally remove trailing zeroes (only if all of them are 0)\n * @example\n * \"420,66 €\" => \"420,66 €\"\n * \"420,60 €\" => \"420,60 €\"\n * \"420,00 €\" => \"420 €\"\n */\n removeTrailingZeros?: boolean;\n /**\n * Optionally return currency rounded down to the nearest dollar-equivalent of a the given currency. Doesn't apply any\n * rounding just \"trims\" end decimal values\n *\n * ! Only use for display purposes where monetary precision is not required!\n *\n * @example\n * \"420,66 €\" => \"420 €\"\n * \"420,60 €\" => \"420 €\"\n * \"420,00 €\" => \"420 €\"\n */\n removeFractions?: boolean;\n};\n\n/**\n * Currency formatter based on dinero currency types and browser internationalizing functions\n *\n * Based on:\n * @see https://v2.dinerojs.com/docs/guides/formatting-in-a-multilingual-site#building-a-custom-internationalization-formatter\n * @protected\n * @deprecated Use `formatPrice` instead as this functions is for INTERNAL USE ONLY! (function not actual deprecated,\n * just marked so it discourages usage of it)\n */\nexport function formatPriceRaw(\n dineroObject: Dinero<number>,\n locale: string,\n options?: FormatPriceOptions,\n) {\n return toFormat(dineroObject, ({ amount, currency }) => {\n const formatter = getCurrencyFormatter(locale, currency.code);\n const formatted = formatter.format(amount);\n\n return options?.removeFractions || options?.removeTrailingZeros\n ? /**\n * Regex to handle complex removing trailing zeros from currency\n * - Dynamically create regex based on currency as their exponent changes\n * - Also handles some currencies (e.g. EUR) having trailing currency symbol\n *\n * TODO: improve how we detect \"decimal separator\" for formatted currency, at least right now we have tests for it and doesn't seem like an issue\n */\n formatted.replace(\n // For some reason `\\.` need to be double-escaped `\\\\` when creating the regex from template string\n new RegExp(\n `(\\\\.|,)${\n // Depending options remove all trailing digits or just zeros, this way we don't need to do any rounding\n options?.removeFractions ? \"\\\\d\" : 0\n }{0,${currency.exponent}}(\\\\s\\\\D)?$`,\n ),\n // In the replaced using \"last capture group\" (if-exists) so we restore the trailing currency sign\n \"$2\",\n )\n : formatted;\n });\n}\n\n/**\n * Currency formatter based on dinero currency types and browser internationalizing functions\n *\n * In reality just a wrapper around `formatPriceRaw` that does the real formatting\n */\nexport const formatPrice = (\n money: Money,\n options?: FormatPriceOptions,\n): string => {\n const currencyObj = getCurrencyObj(money.currency);\n\n if (!currencyObj) {\n throw new Error(`Currency ${money.currency} not supported`);\n }\n\n const d = dinero({\n amount: money.amount,\n currency: currencyObj.currency,\n });\n return formatPriceRaw(d, currencyObj.locale, options);\n};\n"],"names":["getCurrencyObj","currencyCode","currencyObjLookup","get","currencyFormatterCache","Map","getCurrencyFormatter","locale","cacheKey","formatter","Intl","NumberFormat","style","currency","currencySign","currencyDisplay","set","formatPriceRaw","dineroObject","options","toFormat","amount","code","formatted","format","removeFractions","removeTrailingZeros","replace","RegExp","exponent","formatPrice","money","currencyObj","Error","d","dinero"],"mappings":";;;;;AAQa,MA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AAQ,aACzB,CAAA;IAAA;IAEA,IACF,CAAA,IACAN,SAAA;EAAA,CACL,CAAA;AACH;AAOa,MAAAO,WAAA,GAAcA,CACzBC,KAAA,EACAZ,OACW,KAAA;EACL,MAAAa,WAAA,GAAchC,cAAe,CAAA+B,KAAA,CAAMlB,QAAQ,CAAA;EAEjD,IAAI,CAACmB,WAAa,EAAA;IAChB,MAAM,IAAIC,KAAA,CAAkB,YAAAF,KAAA,CAAMlB,QAAwB,gBAAA,CAAA;EAC5D;EAEA,MAAMqB,IAAIC,SAAAA,CAAAA,MAAO,CAAA;IACfd,QAAQU,KAAM,CAAAV,MAAA;IACdR,UAAUmB,WAAY,CAAAnB;EAAA,CACvB,CAAA;EACD,OAAOI,cAAe,CAAAiB,CAAA,EAAGF,WAAY,CAAAzB,MAAA,EAAQY,OAAO,CAAA;AACtD,CAAA;;;"}
@@ -1,10 +1,8 @@
1
- import { toFormat, hasSubUnits, toUnit } from 'dinero.js';
2
- import { assert } from '../errors.mjs';
3
- import { localizedCurrencyLookup, prettifyPriceLookup, Round } from './constants.mjs';
4
- import { getDinero, roundDinero } from './misc.mjs';
1
+ import { toFormat, dinero } from 'dinero.js';
2
+ import { currencyObjLookup } from './constants.mjs';
5
3
  "use strict";
6
- const getLocalizedCurrency = currencyCode => {
7
- return currencyCode ? localizedCurrencyLookup.get(currencyCode) : void 0;
4
+ const getCurrencyObj = currencyCode => {
5
+ return currencyCode ? currencyObjLookup.get(currencyCode) : void 0;
8
6
  };
9
7
  const currencyFormatterCache = /* @__PURE__ */new Map();
10
8
  const getCurrencyFormatter = (locale, currencyCode) => {
@@ -17,7 +15,7 @@ const getCurrencyFormatter = (locale, currencyCode) => {
17
15
  style: "currency",
18
16
  currency: currencyCode,
19
17
  /**
20
- * Explicitly define default behavior - just in case some runtime overrides it
18
+ * Explicitly define default behaviour - just in case some runtime overrides it
21
19
  * @see https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Intl/NumberFormat/NumberFormat#currencysign
22
20
  * @see https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Intl/NumberFormat/NumberFormat#currencydisplay
23
21
  */
@@ -27,8 +25,8 @@ const getCurrencyFormatter = (locale, currencyCode) => {
27
25
  currencyFormatterCache.set(cacheKey, formatter);
28
26
  return formatter;
29
27
  };
30
- function formatPriceRaw(dinero, locale, options) {
31
- return toFormat(dinero, ({
28
+ function formatPriceRaw(dineroObject, locale, options) {
29
+ return toFormat(dineroObject, ({
32
30
  amount,
33
31
  currency
34
32
  }) => {
@@ -51,20 +49,15 @@ function formatPriceRaw(dinero, locale, options) {
51
49
  });
52
50
  }
53
51
  const formatPrice = (money, options) => {
54
- const localizedCurrency = getLocalizedCurrency(money.currency);
55
- assert(!!localizedCurrency, `Currency ${money.currency} not supported`);
56
- return formatPriceRaw(getDinero(money.amount, money.currency), localizedCurrency.locale, options);
57
- };
58
- const prettifyTotal = total => {
59
- if (!hasSubUnits(total)) {
60
- return total;
61
- }
62
- const totalJson = total.toJSON();
63
- const minValueInclusiveToRoundDownFrom = prettifyPriceLookup.get(totalJson.currency.code);
64
- if (minValueInclusiveToRoundDownFrom == null || toUnit(total) < minValueInclusiveToRoundDownFrom) {
65
- return total;
52
+ const currencyObj = getCurrencyObj(money.currency);
53
+ if (!currencyObj) {
54
+ throw new Error(`Currency ${money.currency} not supported`);
66
55
  }
67
- return roundDinero(total, Round.Prettify);
56
+ const d = dinero({
57
+ amount: money.amount,
58
+ currency: currencyObj.currency
59
+ });
60
+ return formatPriceRaw(d, currencyObj.locale, options);
68
61
  };
69
- export { formatPrice, formatPriceRaw, getLocalizedCurrency, prettifyTotal };
62
+ export { formatPrice, formatPriceRaw, getCurrencyObj };
70
63
  //# sourceMappingURL=format.mjs.map