@ubnt/store.core 9.13.0-alpha.4 → 9.13.0

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 (263) hide show
  1. package/CHANGELOG.md +0 -115
  2. package/lib/_virtual/_virtual_multi-entry.js +12 -27
  3. package/lib/_virtual/_virtual_multi-entry.js.map +1 -1
  4. package/lib/_virtual/_virtual_multi-entry.mjs +10 -14
  5. package/lib/_virtual/_virtual_multi-entry.mjs.map +1 -1
  6. package/lib/assets/attention.svg +5 -5
  7. package/lib/assets/attention2.svg +5 -5
  8. package/lib/assets/minus4.svg +8 -8
  9. package/lib/assets/minus5.svg +8 -8
  10. package/lib/assets/plus5.svg +9 -9
  11. package/lib/assets/plus6.svg +9 -9
  12. package/lib/components/Header/Header.js +1 -1
  13. package/lib/components/Header/Header.js.map +1 -1
  14. package/lib/components/Header/Header.mjs +1 -1
  15. package/lib/components/Header/Header.mjs.map +1 -1
  16. package/lib/components/Header/LinksModal/mapping.d.ts +1 -2
  17. package/lib/components/Header/LinksModal/mapping.js +3 -4
  18. package/lib/components/Header/LinksModal/mapping.js.map +1 -1
  19. package/lib/components/Header/LinksModal/mapping.mjs +3 -4
  20. package/lib/components/Header/LinksModal/mapping.mjs.map +1 -1
  21. package/lib/components/Header/Navigation/MobileMenu/MobileMenu.js +3 -4
  22. package/lib/components/Header/Navigation/MobileMenu/MobileMenu.js.map +1 -1
  23. package/lib/components/Header/Navigation/MobileMenu/MobileMenu.mjs +4 -5
  24. package/lib/components/Header/Navigation/MobileMenu/MobileMenu.mjs.map +1 -1
  25. package/lib/components/Header/Navigation/ProMobileMenu/ProMobileMenu.js +2 -7
  26. package/lib/components/Header/Navigation/ProMobileMenu/ProMobileMenu.js.map +1 -1
  27. package/lib/components/Header/Navigation/ProMobileMenu/ProMobileMenu.mjs +3 -8
  28. package/lib/components/Header/Navigation/ProMobileMenu/ProMobileMenu.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/ResourceCalculatorV1/ComputeResourceCalculator/ComputeResourceCalculator.constants.js +15 -311
  35. package/lib/components/ResourceCalculatorV1/ComputeResourceCalculator/ComputeResourceCalculator.constants.js.map +1 -1
  36. package/lib/components/ResourceCalculatorV1/ComputeResourceCalculator/ComputeResourceCalculator.constants.mjs +15 -309
  37. package/lib/components/ResourceCalculatorV1/ComputeResourceCalculator/ComputeResourceCalculator.constants.mjs.map +1 -1
  38. package/lib/components/ResourceCalculatorV1/ComputeResourceCalculator/ComputeResourceCalculator.js +22 -38
  39. package/lib/components/ResourceCalculatorV1/ComputeResourceCalculator/ComputeResourceCalculator.js.map +1 -1
  40. package/lib/components/ResourceCalculatorV1/ComputeResourceCalculator/ComputeResourceCalculator.mjs +22 -38
  41. package/lib/components/ResourceCalculatorV1/ComputeResourceCalculator/ComputeResourceCalculator.mjs.map +1 -1
  42. package/lib/components/ResourceCalculatorV1/ComputeResourceCalculator/ComputeResourceCalculator.types.d.ts +2 -10
  43. package/lib/components/ResourceCalculatorV1/ComputeResourceCalculator/ComputeResourceCalculator.types.js +0 -2
  44. package/lib/components/ResourceCalculatorV1/ComputeResourceCalculator/ComputeResourceCalculator.types.js.map +1 -1
  45. package/lib/components/ResourceCalculatorV1/ComputeResourceCalculator/ComputeResourceCalculator.types.mjs +0 -2
  46. package/lib/components/ResourceCalculatorV1/ComputeResourceCalculator/ComputeResourceCalculator.types.mjs.map +1 -1
  47. package/lib/components/ResourceCalculatorV1/ComputeResourceCalculator/components/HddSlots/HddSlots.d.ts +1 -1
  48. package/lib/components/ResourceCalculatorV1/ComputeResourceCalculator/components/HddSlots/HddSlots.js +4 -5
  49. package/lib/components/ResourceCalculatorV1/ComputeResourceCalculator/components/HddSlots/HddSlots.js.map +1 -1
  50. package/lib/components/ResourceCalculatorV1/ComputeResourceCalculator/components/HddSlots/HddSlots.mjs +4 -5
  51. package/lib/components/ResourceCalculatorV1/ComputeResourceCalculator/components/HddSlots/HddSlots.mjs.map +1 -1
  52. package/lib/components/ResourceCalculatorV1/ComputeResourceCalculator/components/InputCard/InputCard.js +2 -2
  53. package/lib/components/ResourceCalculatorV1/ComputeResourceCalculator/components/InputCard/InputCard.js.map +1 -1
  54. package/lib/components/ResourceCalculatorV1/ComputeResourceCalculator/components/InputCard/InputCard.mjs +2 -2
  55. package/lib/components/ResourceCalculatorV1/ComputeResourceCalculator/components/InputCard/InputCard.mjs.map +1 -1
  56. package/lib/components/ResourceCalculatorV1/ComputeResourceCalculator/components/InputCard/InputCard.styles.js +0 -2
  57. package/lib/components/ResourceCalculatorV1/ComputeResourceCalculator/components/InputCard/InputCard.styles.js.map +1 -1
  58. package/lib/components/ResourceCalculatorV1/ComputeResourceCalculator/components/InputCard/InputCard.styles.mjs +0 -2
  59. package/lib/components/ResourceCalculatorV1/ComputeResourceCalculator/components/InputCard/InputCard.styles.mjs.map +1 -1
  60. package/lib/components/ResourceCalculatorV1/ComputeResourceCalculator/components/InputCard/InputSections/CounterSection.js +2 -2
  61. package/lib/components/ResourceCalculatorV1/ComputeResourceCalculator/components/InputCard/InputSections/CounterSection.mjs +2 -2
  62. package/lib/components/ResourceCalculatorV1/ComputeResourceCalculator/components/InputCard/assets/attention.svg.js +1 -1
  63. package/lib/components/ResourceCalculatorV1/ComputeResourceCalculator/components/InputCard/assets/attention.svg.mjs +2 -2
  64. package/lib/components/ResourceCalculatorV1/ComputeResourceCalculator/components/InputCard/assets/minus.svg.js +1 -1
  65. package/lib/components/ResourceCalculatorV1/ComputeResourceCalculator/components/InputCard/assets/minus.svg.mjs +2 -2
  66. package/lib/components/ResourceCalculatorV1/ComputeResourceCalculator/components/InputCard/assets/plus.svg.js +1 -1
  67. package/lib/components/ResourceCalculatorV1/ComputeResourceCalculator/components/InputCard/assets/plus.svg.mjs +2 -2
  68. package/lib/components/ResourceCalculatorV1/ComputeResourceCalculator/components/ProgressBarChart/ProgressBarChart.js +1 -1
  69. package/lib/components/ResourceCalculatorV1/ComputeResourceCalculator/components/ProgressBarChart/ProgressBarChart.mjs +1 -1
  70. package/lib/components/ResourceCalculatorV1/ComputeResourceCalculator/components/ProgressBarChart/assets/attention.svg.js +1 -1
  71. package/lib/components/ResourceCalculatorV1/ComputeResourceCalculator/components/ProgressBarChart/assets/attention.svg.mjs +2 -2
  72. package/lib/components/ResourceCalculatorV1/ComputeResourceCalculator/useComputeResourceCalculator.js +1 -1
  73. package/lib/components/ResourceCalculatorV1/ComputeResourceCalculator/useComputeResourceCalculator.js.map +1 -1
  74. package/lib/components/ResourceCalculatorV1/ComputeResourceCalculator/useComputeResourceCalculator.mjs +1 -1
  75. package/lib/components/ResourceCalculatorV1/ComputeResourceCalculator/useComputeResourceCalculator.mjs.map +1 -1
  76. package/lib/components/ResourceCalculatorV1/PoeCalculator/components/PoeConsumerConfigurator/PoeConsumerSelectModal/PoeConsumerSelectModal.js +4 -4
  77. package/lib/components/ResourceCalculatorV1/PoeCalculator/components/PoeConsumerConfigurator/PoeConsumerSelectModal/PoeConsumerSelectModal.js.map +1 -1
  78. package/lib/components/ResourceCalculatorV1/PoeCalculator/components/PoeConsumerConfigurator/PoeConsumerSelectModal/PoeConsumerSelectModal.mjs +4 -4
  79. package/lib/components/ResourceCalculatorV1/PoeCalculator/components/PoeConsumerConfigurator/PoeConsumerSelectModal/PoeConsumerSelectModal.mjs.map +1 -1
  80. package/lib/components/ResourceCalculatorV1/PoeCalculator/components/PoeConsumerConfigurator/assets/minus.svg.js +1 -1
  81. package/lib/components/ResourceCalculatorV1/PoeCalculator/components/PoeConsumerConfigurator/assets/minus.svg.mjs +2 -2
  82. package/lib/components/ResourceCalculatorV1/PoeCalculator/components/PoeConsumerConfigurator/assets/plus.svg.js +1 -1
  83. package/lib/components/ResourceCalculatorV1/PoeCalculator/components/PoeConsumerConfigurator/assets/plus.svg.mjs +2 -2
  84. package/lib/components/ResourceCalculatorV1/ResourceCalculator.js +2 -1
  85. package/lib/components/ResourceCalculatorV1/ResourceCalculator.js.map +1 -1
  86. package/lib/components/ResourceCalculatorV1/ResourceCalculator.mjs +2 -1
  87. package/lib/components/ResourceCalculatorV1/ResourceCalculator.mjs.map +1 -1
  88. package/lib/components/{HorizontalOptionSelect → ResourceCalculatorV1/components/HorizontalOptionSelect}/HorizontalOptionSelect.d.ts +1 -1
  89. package/lib/components/{HorizontalOptionSelect → ResourceCalculatorV1/components/HorizontalOptionSelect}/HorizontalOptionSelect.js +1 -3
  90. package/lib/components/ResourceCalculatorV1/components/HorizontalOptionSelect/HorizontalOptionSelect.js.map +1 -0
  91. package/lib/components/{HorizontalOptionSelect → ResourceCalculatorV1/components/HorizontalOptionSelect}/HorizontalOptionSelect.mjs +1 -3
  92. package/lib/components/ResourceCalculatorV1/components/HorizontalOptionSelect/HorizontalOptionSelect.mjs.map +1 -0
  93. package/lib/components/{HorizontalOptionSelect → ResourceCalculatorV1/components/HorizontalOptionSelect}/HorizontalOptionSelect.styles.d.ts +0 -1
  94. package/lib/components/{HorizontalOptionSelect → ResourceCalculatorV1/components/HorizontalOptionSelect}/HorizontalOptionSelect.styles.js +7 -10
  95. package/lib/components/ResourceCalculatorV1/components/HorizontalOptionSelect/HorizontalOptionSelect.styles.js.map +1 -0
  96. package/lib/components/{HorizontalOptionSelect → ResourceCalculatorV1/components/HorizontalOptionSelect}/HorizontalOptionSelect.styles.mjs +7 -10
  97. package/lib/components/ResourceCalculatorV1/components/HorizontalOptionSelect/HorizontalOptionSelect.styles.mjs.map +1 -0
  98. package/lib/components/{HorizontalOptionSelect → ResourceCalculatorV1/components/HorizontalOptionSelect}/HorizontalOptionSelect.types.d.ts +0 -1
  99. package/lib/components/ResourceCalculatorV1/components/index.d.ts +1 -0
  100. package/lib/components/ResourceCalculatorV1/components/index.js +5 -0
  101. package/lib/{utils/money/allocators → components/ResourceCalculatorV1/components}/index.js.map +1 -1
  102. package/lib/components/ResourceCalculatorV1/components/index.mjs +3 -0
  103. package/lib/{utils/money/allocators → components/ResourceCalculatorV1/components}/index.mjs.map +1 -1
  104. package/lib/components/ResourceCalculatorV1/translations/en.json.js +1 -4
  105. package/lib/components/ResourceCalculatorV1/translations/en.json.js.map +1 -1
  106. package/lib/components/ResourceCalculatorV1/translations/en.json.mjs +1 -4
  107. package/lib/components/ResourceCalculatorV1/translations/en.json.mjs.map +1 -1
  108. package/lib/components/ResourceCalculatorV1/translations/useResourceCalculatorTranslation.d.ts +2 -2
  109. package/lib/components/index.d.ts +0 -1
  110. package/lib/components/index.js +0 -2
  111. package/lib/components/index.js.map +1 -1
  112. package/lib/components/index.mjs +0 -2
  113. package/lib/components/index.mjs.map +1 -1
  114. package/lib/constants/icons/options/colors/black.svg.js +5 -5
  115. package/lib/constants/icons/options/colors/index.js +3 -3
  116. package/lib/constants/icons/options/styles/black.svg.js +5 -5
  117. package/lib/constants/icons/options/styles/index.js +3 -3
  118. package/lib/constants/optionIcons.js +6 -6
  119. package/lib/constants/optionIcons.mjs +4 -4
  120. package/lib/constants/proStoreCategories/mapping/index.d.ts +0 -1
  121. package/lib/constants/proStoreCategories/mapping/index.js +10 -15
  122. package/lib/constants/proStoreCategories/mapping/index.js.map +1 -1
  123. package/lib/constants/proStoreCategories/mapping/index.mjs +10 -15
  124. package/lib/constants/proStoreCategories/mapping/index.mjs.map +1 -1
  125. package/lib/constants/proStoreCategories/mapping/unifi.d.ts +1 -2
  126. package/lib/constants/proStoreCategories/mapping/unifi.js +0 -1
  127. package/lib/constants/proStoreCategories/mapping/unifi.js.map +1 -1
  128. package/lib/constants/proStoreCategories/mapping/unifi.mjs +0 -1
  129. package/lib/constants/proStoreCategories/mapping/unifi.mjs.map +1 -1
  130. package/lib/constants/proStoreCategories/translations/en.json.js +0 -3
  131. package/lib/constants/proStoreCategories/translations/en.json.js.map +1 -1
  132. package/lib/constants/proStoreCategories/translations/en.json.mjs +1 -3
  133. package/lib/constants/proStoreCategories/translations/en.json.mjs.map +1 -1
  134. package/lib/constants/proStoreCategories/translations/fr.json.js +1 -1
  135. package/lib/constants/proStoreCategories/translations/fr.json.mjs +1 -1
  136. package/lib/constants/proStoreCategories/translations/zh-Hans.json.js +1 -1
  137. package/lib/constants/proStoreCategories/translations/zh-Hans.json.mjs +1 -1
  138. package/lib/constants/proStoreCategories/translations/zh-Hant-TW.json.js +1 -1
  139. package/lib/constants/proStoreCategories/translations/zh-Hant-TW.json.mjs +1 -1
  140. package/lib/constants/url.d.ts +0 -1
  141. package/lib/constants/url.js +0 -1
  142. package/lib/constants/url.js.map +1 -1
  143. package/lib/constants/url.mjs +0 -1
  144. package/lib/constants/url.mjs.map +1 -1
  145. package/lib/helpers/index.d.ts +0 -1
  146. package/lib/helpers/index.js +0 -11
  147. package/lib/helpers/index.js.map +1 -1
  148. package/lib/helpers/index.mjs +0 -1
  149. package/lib/helpers/index.mjs.map +1 -1
  150. package/lib/types/index.d.ts +0 -1
  151. package/lib/types/index.js +0 -2
  152. package/lib/types/index.js.map +1 -1
  153. package/lib/types/index.mjs +0 -1
  154. package/lib/types/index.mjs.map +1 -1
  155. package/lib/utils/array.d.ts +0 -4
  156. package/lib/utils/array.js +0 -10
  157. package/lib/utils/array.js.map +1 -1
  158. package/lib/utils/array.mjs +1 -10
  159. package/lib/utils/array.mjs.map +1 -1
  160. package/lib/utils/money/constants.d.ts +25 -56
  161. package/lib/utils/money/constants.js +7 -72
  162. package/lib/utils/money/constants.js.map +1 -1
  163. package/lib/utils/money/constants.mjs +7 -70
  164. package/lib/utils/money/constants.mjs.map +1 -1
  165. package/lib/utils/money/format.d.ts +5 -10
  166. package/lib/utils/money/format.js +14 -22
  167. package/lib/utils/money/format.js.map +1 -1
  168. package/lib/utils/money/format.mjs +16 -23
  169. package/lib/utils/money/format.mjs.map +1 -1
  170. package/lib/utils/money/index.d.ts +1 -4
  171. package/lib/utils/money/index.js +8 -26
  172. package/lib/utils/money/index.js.map +1 -1
  173. package/lib/utils/money/index.mjs +4 -8
  174. package/lib/utils/money/index.mjs.map +1 -1
  175. package/lib/utils/money/misc.d.ts +28 -68
  176. package/lib/utils/money/misc.js +64 -35
  177. package/lib/utils/money/misc.js.map +1 -1
  178. package/lib/utils/money/misc.mjs +43 -32
  179. package/lib/utils/money/misc.mjs.map +1 -1
  180. package/lib/utils/money/tax.d.ts +2 -38
  181. package/lib/utils/money/tax.js +10 -46
  182. package/lib/utils/money/tax.js.map +1 -1
  183. package/lib/utils/money/tax.mjs +11 -42
  184. package/lib/utils/money/tax.mjs.map +1 -1
  185. package/lib/utils/money/types.d.ts +3 -78
  186. package/lib/utils/number.d.ts +1 -1
  187. package/lib/utils/number.js +1 -1
  188. package/lib/utils/number.js.map +1 -1
  189. package/lib/utils/number.mjs +1 -1
  190. package/lib/utils/number.mjs.map +1 -1
  191. package/lib/utils/validations.d.ts +15 -0
  192. package/lib/utils/validations.js +23 -0
  193. package/lib/utils/validations.js.map +1 -0
  194. package/lib/utils/validations.mjs +21 -0
  195. package/lib/utils/validations.mjs.map +1 -0
  196. package/package.json +1 -1
  197. package/lib/assets/efg.png +0 -0
  198. package/lib/assets/ucg-max.png +0 -0
  199. package/lib/components/HorizontalOptionSelect/HorizontalOptionSelect.js.map +0 -1
  200. package/lib/components/HorizontalOptionSelect/HorizontalOptionSelect.mjs.map +0 -1
  201. package/lib/components/HorizontalOptionSelect/HorizontalOptionSelect.styles.js.map +0 -1
  202. package/lib/components/HorizontalOptionSelect/HorizontalOptionSelect.styles.mjs.map +0 -1
  203. package/lib/components/ResourceCalculatorV1/assets/consoles/efg.png.js +0 -27
  204. package/lib/components/ResourceCalculatorV1/assets/consoles/efg.png.js.map +0 -1
  205. package/lib/components/ResourceCalculatorV1/assets/consoles/efg.png.mjs +0 -3
  206. package/lib/components/ResourceCalculatorV1/assets/consoles/efg.png.mjs.map +0 -1
  207. package/lib/components/ResourceCalculatorV1/assets/consoles/ucg-max.png.js +0 -27
  208. package/lib/components/ResourceCalculatorV1/assets/consoles/ucg-max.png.js.map +0 -1
  209. package/lib/components/ResourceCalculatorV1/assets/consoles/ucg-max.png.mjs +0 -3
  210. package/lib/components/ResourceCalculatorV1/assets/consoles/ucg-max.png.mjs.map +0 -1
  211. package/lib/helpers/product.d.ts +0 -87
  212. package/lib/helpers/product.js +0 -346
  213. package/lib/helpers/product.js.map +0 -1
  214. package/lib/helpers/product.mjs +0 -335
  215. package/lib/helpers/product.mjs.map +0 -1
  216. package/lib/types/product.d.ts +0 -87
  217. package/lib/types/product.js +0 -14
  218. package/lib/types/product.js.map +0 -1
  219. package/lib/types/product.mjs +0 -13
  220. package/lib/types/product.mjs.map +0 -1
  221. package/lib/utils/money/allocators/fixedAmount.d.ts +0 -26
  222. package/lib/utils/money/allocators/fixedAmount.js +0 -55
  223. package/lib/utils/money/allocators/fixedAmount.js.map +0 -1
  224. package/lib/utils/money/allocators/fixedAmount.mjs +0 -53
  225. package/lib/utils/money/allocators/fixedAmount.mjs.map +0 -1
  226. package/lib/utils/money/allocators/index.d.ts +0 -2
  227. package/lib/utils/money/allocators/index.js +0 -8
  228. package/lib/utils/money/allocators/index.mjs +0 -4
  229. package/lib/utils/money/allocators/productAmount.d.ts +0 -13
  230. package/lib/utils/money/allocators/productAmount.js +0 -110
  231. package/lib/utils/money/allocators/productAmount.js.map +0 -1
  232. package/lib/utils/money/allocators/productAmount.mjs +0 -108
  233. package/lib/utils/money/allocators/productAmount.mjs.map +0 -1
  234. package/lib/utils/money/exchangeRate.d.ts +0 -31
  235. package/lib/utils/money/exchangeRate.js +0 -27
  236. package/lib/utils/money/exchangeRate.js.map +0 -1
  237. package/lib/utils/money/exchangeRate.mjs +0 -23
  238. package/lib/utils/money/exchangeRate.mjs.map +0 -1
  239. package/lib/utils/money/misc.private.d.ts +0 -23
  240. package/lib/utils/money/misc.private.js +0 -46
  241. package/lib/utils/money/misc.private.js.map +0 -1
  242. package/lib/utils/money/misc.private.mjs +0 -21
  243. package/lib/utils/money/misc.private.mjs.map +0 -1
  244. package/lib/utils/money/shipping.d.ts +0 -5
  245. package/lib/utils/money/shipping.js +0 -8
  246. package/lib/utils/money/shipping.js.map +0 -1
  247. package/lib/utils/money/shipping.mjs +0 -6
  248. package/lib/utils/money/shipping.mjs.map +0 -1
  249. package/lib/utils/money/tax.private.d.ts +0 -17
  250. package/lib/utils/money/tax.private.js +0 -65
  251. package/lib/utils/money/tax.private.js.map +0 -1
  252. package/lib/utils/money/tax.private.mjs +0 -60
  253. package/lib/utils/money/tax.private.mjs.map +0 -1
  254. package/lib/utils/productSort.d.ts +0 -41
  255. package/lib/utils/productSort.js +0 -66
  256. package/lib/utils/productSort.js.map +0 -1
  257. package/lib/utils/productSort.mjs +0 -59
  258. package/lib/utils/productSort.mjs.map +0 -1
  259. /package/lib/components/{HorizontalOptionSelect → ResourceCalculatorV1/components/HorizontalOptionSelect}/index.d.ts +0 -0
  260. /package/lib/components/{HorizontalOptionSelect → ResourceCalculatorV1/components/HorizontalOptionSelect}/index.js +0 -0
  261. /package/lib/components/{HorizontalOptionSelect → ResourceCalculatorV1/components/HorizontalOptionSelect}/index.js.map +0 -0
  262. /package/lib/components/{HorizontalOptionSelect → ResourceCalculatorV1/components/HorizontalOptionSelect}/index.mjs +0 -0
  263. /package/lib/components/{HorizontalOptionSelect → ResourceCalculatorV1/components/HorizontalOptionSelect}/index.mjs.map +0 -0
@@ -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,YAAe,GAAAC,SAAAA,CAAAA,uBAAA,CAAwBC,GAAI,CAAAF,YAAY,CAAI,GAAA,KAAA,CAAA;AACpE,CAAA;AAKA,MAAMG,sBAAA,GAAA,mBAA6BC,GAA+B,EAAA;AAOlE,MAAMC,oBAAA,GAAuBA,CAC3BC,MAAA,EACAN,YACsB,KAAA;EACtB,MAAMO,QAAW,GAAA,GAAGD,MAAM,IAAIN,YAAY,EAAA;EAEtC,IAAAQ,SAAA,GAAYL,sBAAuB,CAAAD,GAAA,CAAIK,QAAQ,CAAA;EACnD,IAAIC,SAAW,EAAA;IACN,OAAAA,SAAA;EACT;EAEYA,SAAA,GAAA,IAAIC,IAAK,CAAAC,YAAA,CAAaJ,MAAQ,EAAA;IACxCK,KAAO,EAAA,UAAA;IACPC,QAAU,EAAAZ,YAAA;IAAA;AAAA;AAAA;AAAA;AAAA;IAMVa,YAAc,EAAA,UAAA;IACdC,eAAiB,EAAA;EAAA,CAClB,CAAA;EACsBX,sBAAA,CAAAY,GAAA,CAAIR,UAAUC,SAAS,CAAA;EAEvC,OAAAA,SAAA;AACT,CAAA;AAoCgB,SAAAQ,cAAAA,CACdC,MACA,EAAAX,MAAA,EACAY,OACQ,EAAA;EACR,OAAOC,mBAASF,MAAQ,EAAA,CAAC;IAAEG,MAAA;IAAQR;GAAe,KAAA;IAChD,MAAMJ,SAAY,GAAAH,oBAAA,CAAqBC,MAAQ,EAAAM,QAAA,CAASS,IAAI,CAAA;IACtD,MAAAC,SAAA,GAAYd,SAAU,CAAAe,MAAA,CAAOH,MAAM,CAAA;IAElC,OAAAF,OAAA,EAASM,mBAAmBN,OAAS,EAAAO,mBAAA;IAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;IAQxCH,SAAU,CAAAI,OAAA;IAAA;IAER,IAAIC,MAAA,CACF,UAAA;IAEET,SAASM,eAAkB,GAAA,KAAA,GAAQ,CACrC,MAAMZ,SAASgB,QAAQ,aACzB,CAAA;IAAA;IAEA,IACF,CAAA,IACAN,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,MAAAA,cAAA,GACXC,YAC4B,IAAA;EAC5B,OAAOA,YAAe,GAAAC,SAAAA,CAAAA,iBAAA,CAAkBC,GAAI,CAAAF,YAAY,CAAI,GAAA,KAAA,CAAA;AAC9D,CAAA;AAKA,MAAMG,sBAAA,GAAA,mBAA6BC,GAA+B,EAAA;AAOlE,MAAMC,oBAAA,GAAuBA,CAC3BC,MAAA,EACAN,YACsB,KAAA;EACtB,MAAMO,QAAW,GAAA,GAAGD,MAAM,IAAIN,YAAY,EAAA;EACtC,IAAAQ,SAAA,GAAYL,sBAAuB,CAAAD,GAAA,CAAIK,QAAQ,CAAA;EACnD,IAAIC,SAAW,EAAA;IACN,OAAAA,SAAA;EACT;EAEYA,SAAA,GAAA,IAAIC,IAAK,CAAAC,YAAA,CAAaJ,MAAQ,EAAA;IACxCK,KAAO,EAAA,UAAA;IACPC,QAAU,EAAAZ,YAAA;IAAA;AAAA;AAAA;AAAA;AAAA;IAMVa,YAAc,EAAA,UAAA;IACdC,eAAiB,EAAA;EAAA,CAClB,CAAA;EACsBX,sBAAA,CAAAY,GAAA,CAAIR,UAAUC,SAAS,CAAA;EAEvC,OAAAA,SAAA;AACT,CAAA;AAkCgB,SAAAQ,cAAAA,CACdC,YACA,EAAAX,MAAA,EACAY,OACA,EAAA;EACA,OAAOC,mBAASF,YAAc,EAAA,CAAC;IAAEG,MAAA;IAAQR;GAAe,KAAA;IACtD,MAAMJ,SAAY,GAAAH,oBAAA,CAAqBC,MAAQ,EAAAM,QAAA,CAASS,IAAI,CAAA;IACtD,MAAAC,SAAA,GAAYd,SAAU,CAAAe,MAAA,CAAOH,MAAM,CAAA;IAElC,OAAAF,OAAA,EAASM,mBAAmBN,OAAS,EAAAO,mBAAA;IAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;IAQxCH,SAAU,CAAAI,OAAA;IAAA;IAER,IAAIC,MAAA,CACF,UAAA;IAEET,SAASM,eAAkB,GAAA,KAAA,GAAQ,CACrC,MAAMZ,SAASgB,QAAQ,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
@@ -1 +1 @@
1
- {"version":3,"file":"format.mjs","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,YAAe,GAAAC,uBAAA,CAAwBC,GAAI,CAAAF,YAAY,CAAI,GAAA,KAAA,CAAA;AACpE,CAAA;AAKA,MAAMG,sBAAA,GAAA,mBAA6BC,GAA+B,EAAA;AAOlE,MAAMC,oBAAA,GAAuBA,CAC3BC,MAAA,EACAN,YACsB,KAAA;EACtB,MAAMO,QAAW,GAAA,GAAGD,MAAM,IAAIN,YAAY,EAAA;EAEtC,IAAAQ,SAAA,GAAYL,sBAAuB,CAAAD,GAAA,CAAIK,QAAQ,CAAA;EACnD,IAAIC,SAAW,EAAA;IACN,OAAAA,SAAA;EACT;EAEYA,SAAA,GAAA,IAAIC,IAAK,CAAAC,YAAA,CAAaJ,MAAQ,EAAA;IACxCK,KAAO,EAAA,UAAA;IACPC,QAAU,EAAAZ,YAAA;IAAA;AAAA;AAAA;AAAA;AAAA;IAMVa,YAAc,EAAA,UAAA;IACdC,eAAiB,EAAA;EAAA,CAClB,CAAA;EACsBX,sBAAA,CAAAY,GAAA,CAAIR,UAAUC,SAAS,CAAA;EAEvC,OAAAA,SAAA;AACT,CAAA;AAoCgB,SAAAQ,cAAAA,CACdC,MACA,EAAAX,MAAA,EACAY,OACQ,EAAA;EACR,OAAOC,SAASF,MAAQ,EAAA,CAAC;IAAEG,MAAA;IAAQR;GAAe,KAAA;IAChD,MAAMJ,SAAY,GAAAH,oBAAA,CAAqBC,MAAQ,EAAAM,QAAA,CAASS,IAAI,CAAA;IACtD,MAAAC,SAAA,GAAYd,SAAU,CAAAe,MAAA,CAAOH,MAAM,CAAA;IAElC,OAAAF,OAAA,EAASM,mBAAmBN,OAAS,EAAAO,mBAAA;IAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;IAQxCH,SAAU,CAAAI,OAAA;IAAA;IAER,IAAIC,MAAA,CACF,UAAA;IAEET,SAASM,eAAkB,GAAA,KAAA,GAAQ,CACrC,MAAMZ,SAASgB,QAAQ,aACzB,CAAA;IAAA;IAEA,IACF,CAAA,IACAN,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,MAAA,CAAO,CAAC,CAACD,iBAAA,EAA+B,YAAAD,KAAA,CAAMlB,QAAwB,gBAAA,CAAA;EAE/D,OAAAI,cAAA,CACLiB,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,WAAY,CAAAD,KAAK,CAAG,EAAA;IAChB,OAAAA,KAAA;EACT;EAEM,MAAAE,SAAA,GAAYF,MAAMG,MAAO,EAAA;EAE/B,MAAMC,mCAAmCC,mBAAoB,CAAAtC,GAAA,CAC3DmC,UAAUzB,QAAS,CAAAS,IAAA,CACrB;EAGA,IACEkB,gCAAoC,IAAA,IAAA,IACpCE,MAAO,CAAAN,KAAK,IAAII,gCAChB,EAAA;IACO,OAAAJ,KAAA;EACT;EAEO,OAAAO,WAAA,CAAYP,KAAO,EAAAQ,KAAA,CAAMC,QAAQ,CAAA;AAC1C,CAAA;"}
1
+ {"version":3,"file":"format.mjs","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,MAAAA,cAAA,GACXC,YAC4B,IAAA;EAC5B,OAAOA,YAAe,GAAAC,iBAAA,CAAkBC,GAAI,CAAAF,YAAY,CAAI,GAAA,KAAA,CAAA;AAC9D,CAAA;AAKA,MAAMG,sBAAA,GAAA,mBAA6BC,GAA+B,EAAA;AAOlE,MAAMC,oBAAA,GAAuBA,CAC3BC,MAAA,EACAN,YACsB,KAAA;EACtB,MAAMO,QAAW,GAAA,GAAGD,MAAM,IAAIN,YAAY,EAAA;EACtC,IAAAQ,SAAA,GAAYL,sBAAuB,CAAAD,GAAA,CAAIK,QAAQ,CAAA;EACnD,IAAIC,SAAW,EAAA;IACN,OAAAA,SAAA;EACT;EAEYA,SAAA,GAAA,IAAIC,IAAK,CAAAC,YAAA,CAAaJ,MAAQ,EAAA;IACxCK,KAAO,EAAA,UAAA;IACPC,QAAU,EAAAZ,YAAA;IAAA;AAAA;AAAA;AAAA;AAAA;IAMVa,YAAc,EAAA,UAAA;IACdC,eAAiB,EAAA;EAAA,CAClB,CAAA;EACsBX,sBAAA,CAAAY,GAAA,CAAIR,UAAUC,SAAS,CAAA;EAEvC,OAAAA,SAAA;AACT,CAAA;AAkCgB,SAAAQ,cAAAA,CACdC,YACA,EAAAX,MAAA,EACAY,OACA,EAAA;EACA,OAAOC,SAASF,YAAc,EAAA,CAAC;IAAEG,MAAA;IAAQR;GAAe,KAAA;IACtD,MAAMJ,SAAY,GAAAH,oBAAA,CAAqBC,MAAQ,EAAAM,QAAA,CAASS,IAAI,CAAA;IACtD,MAAAC,SAAA,GAAYd,SAAU,CAAAe,MAAA,CAAOH,MAAM,CAAA;IAElC,OAAAF,OAAA,EAASM,mBAAmBN,OAAS,EAAAO,mBAAA;IAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;IAQxCH,SAAU,CAAAI,OAAA;IAAA;IAER,IAAIC,MAAA,CACF,UAAA;IAEET,SAASM,eAAkB,GAAA,KAAA,GAAQ,CACrC,MAAMZ,SAASgB,QAAQ,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,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,8 +1,5 @@
1
- export * as Allocators from "./allocators";
2
1
  export * from "./constants";
3
- export * from "./exchangeRate";
4
2
  export * from "./format";
5
3
  export * from "./misc";
6
- export * from "./shipping";
7
- export * from "./tax";
8
4
  export * from "./types";
5
+ export * from "./tax";
@@ -1,51 +1,33 @@
1
1
  'use strict';
2
2
 
3
- var index = require('./allocators/index.js');
4
3
  var constants = require('./constants.js');
5
- var exchangeRate = require('./exchangeRate.js');
6
4
  var format = require('./format.js');
7
5
  var misc = require('./misc.js');
8
- var shipping = require('./shipping.js');
9
- var tax = require('./tax.js');
10
6
  require('./types.js');
7
+ var tax = require('./tax.js');
11
8
  "use strict";
12
- exports.Allocators = index;
13
- exports.EXCHANGE_RATE_DINERO_CURRENCY = constants.EXCHANGE_RATE_DINERO_CURRENCY;
14
- exports.Round = constants.Round;
15
- exports.TAX_RATE_DINERO_CURRENCY = constants.TAX_RATE_DINERO_CURRENCY;
16
- exports.localizedCurrencyLookup = constants.localizedCurrencyLookup;
9
+ exports.currencyObjLookup = constants.currencyObjLookup;
10
+ exports.financialRound = constants.financialRound;
11
+ exports.maximumPriceFilterLookup = constants.maximumPriceFilterLookup;
17
12
  exports.prettifyPriceLookup = constants.prettifyPriceLookup;
18
13
  exports.smallestSubunitLookup = constants.smallestSubunitLookup;
19
- exports.storesWithPerItemTaxRate = constants.storesWithPerItemTaxRate;
20
- exports.invertExchangeRate = exchangeRate.invertExchangeRate;
21
- exports.toFixedExchangeRate = exchangeRate.toFixedExchangeRate;
22
- exports.toSnapshotExchangeRate = exchangeRate.toSnapshotExchangeRate;
23
14
  exports.formatPrice = format.formatPrice;
24
15
  exports.formatPriceRaw = format.formatPriceRaw;
25
- exports.getLocalizedCurrency = format.getLocalizedCurrency;
26
- exports.prettifyTotal = format.prettifyTotal;
16
+ exports.getCurrencyObj = format.getCurrencyObj;
27
17
  exports.addMany = misc.addMany;
28
18
  exports.amount = misc.amount;
29
- exports.centsToCurrencyUnit = misc.centsToCurrencyUnit;
19
+ exports.centsToMajorUnits = misc.centsToMajorUnits;
30
20
  exports.currency = misc.currency;
31
- exports.dineroToCurrencyUnit = misc.dineroToCurrencyUnit;
32
21
  exports.getDinero = misc.getDinero;
33
22
  exports.getDineroCurrency = misc.getDineroCurrency;
34
23
  exports.money = misc.money;
35
24
  exports.multiplyByFullPercent = misc.multiplyByFullPercent;
36
25
  exports.parseCurrencyCode = misc.parseCurrencyCode;
37
26
  exports.parseFloatToDinero = misc.parseFloatToDinero;
38
- exports.parseFloatToDineroRaw = misc.parseFloatToDineroRaw;
39
- exports.roundDinero = misc.roundDinero;
27
+ exports.prettifyTotal = misc.prettifyTotal;
40
28
  exports.stringAmountToDinero = misc.stringAmountToDinero;
41
29
  exports.subtractMany = misc.subtractMany;
42
30
  exports.toSmallestSubunit = misc.toSmallestSubunit;
43
- exports.roundShippingPrice = shipping.roundShippingPrice;
44
- exports.calculateLineItemTax = tax.calculateLineItemTax;
45
- exports.calculateTotalTaxRate = tax.calculateTotalTaxRate;
46
- exports.convertDecimalTaxRateToPercentage = tax.convertDecimalTaxRateToPercentage;
47
- exports.decimalTaxRateToDinero = tax.decimalTaxRateToDinero;
48
- exports.formatDecimalTaxRate = tax.formatDecimalTaxRate;
31
+ exports.allocateTaxAmount = tax.allocateTaxAmount;
49
32
  exports.removeTaxAmount = tax.removeTaxAmount;
50
- exports.stringTaxRateToFloat = tax.stringTaxRateToFloat;
51
33
  //# sourceMappingURL=index.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"index.js","sources":[],"sourcesContent":[],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;"}
1
+ {"version":3,"file":"index.js","sources":[],"sourcesContent":[],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;"}
@@ -1,11 +1,7 @@
1
- import * as index from './allocators/index.mjs';
2
- export { index as Allocators };
3
- export { EXCHANGE_RATE_DINERO_CURRENCY, Round, TAX_RATE_DINERO_CURRENCY, localizedCurrencyLookup, prettifyPriceLookup, smallestSubunitLookup, storesWithPerItemTaxRate } from './constants.mjs';
4
- export { invertExchangeRate, toFixedExchangeRate, toSnapshotExchangeRate } from './exchangeRate.mjs';
5
- export { formatPrice, formatPriceRaw, getLocalizedCurrency, prettifyTotal } from './format.mjs';
6
- export { addMany, amount, centsToCurrencyUnit, currency, dineroToCurrencyUnit, getDinero, getDineroCurrency, money, multiplyByFullPercent, parseCurrencyCode, parseFloatToDinero, parseFloatToDineroRaw, roundDinero, stringAmountToDinero, subtractMany, toSmallestSubunit } from './misc.mjs';
7
- export { roundShippingPrice } from './shipping.mjs';
8
- export { calculateLineItemTax, calculateTotalTaxRate, convertDecimalTaxRateToPercentage, decimalTaxRateToDinero, formatDecimalTaxRate, removeTaxAmount, stringTaxRateToFloat } from './tax.mjs';
1
+ export { currencyObjLookup, financialRound, maximumPriceFilterLookup, prettifyPriceLookup, smallestSubunitLookup } from './constants.mjs';
2
+ export { formatPrice, formatPriceRaw, getCurrencyObj } from './format.mjs';
3
+ export { addMany, amount, centsToMajorUnits, currency, getDinero, getDineroCurrency, money, multiplyByFullPercent, parseCurrencyCode, parseFloatToDinero, prettifyTotal, stringAmountToDinero, subtractMany, toSmallestSubunit } from './misc.mjs';
9
4
  import './types.mjs';
5
+ export { allocateTaxAmount, removeTaxAmount } from './tax.mjs';
10
6
  "use strict";
11
7
  //# sourceMappingURL=index.mjs.map
@@ -1 +1 @@
1
- {"version":3,"file":"index.mjs","sources":[],"sourcesContent":[],"names":[],"mappings":";;;;;;;;;"}
1
+ {"version":3,"file":"index.mjs","sources":[],"sourcesContent":[],"names":[],"mappings":";;;;;"}
@@ -1,72 +1,53 @@
1
+ import type { Dinero, Currency as DineroCurrency } from "dinero.js";
1
2
  import { Currency } from "../../types";
2
- import type { Cents, Dino, DinoCurrency, Money, RoundingFn } from "./types";
3
+ export interface Money {
4
+ amount: number;
5
+ currency: Currency;
6
+ }
7
+ /**
8
+ * Prettify numbers depending on the currency using rounding down.
9
+ * ! Should only be used to prettify storefront product prices after currency conversion but nothing else !
10
+ */
11
+ export declare const prettifyTotal: (total: Dinero<number>) => Dinero<number>;
3
12
  /**
4
13
  * Some currencies have subunits in their currency spec that are not used in reality. This causes Dinero to return incorrect subunit values for those currencies.
5
14
  * This util rounds down any unused subunits to closest subunit resolution.
6
15
  *
7
16
  * ! Not to be confused with prettifyTotal
8
17
  */
9
- export declare const toSmallestSubunit: (total: Dino) => Dino;
18
+ export declare const toSmallestSubunit: (total: Dinero<number>) => Dinero<number>;
10
19
  /**
11
20
  * Find Dinero.js currency instance from our Currency enum.
12
21
  * @throws Throws an error if currency is not found!
13
- *
14
22
  * @example
15
23
  * getDineroCurrency(Currency.Usd); // => Dinero.js currency instance
16
24
  * getDineroCurrency("invalid"); // => throws AssertionError
17
25
  */
18
- export declare const getDineroCurrency: (currency: Currency) => DinoCurrency;
26
+ export declare const getDineroCurrency: (currency: Currency) => DineroCurrency<number>;
19
27
  /**
20
- * Convert Dinero currency (case-insensitive) to local currency type
21
- * @throws Throws an error if currency is not found!
22
- *
23
- * @example
24
- * parseCurrencyCode('usd') // Currency.Usd
25
- * parseCurrencyCode('JPY') // Currency.Jpy
26
- * parseCurrencyCode('invalid') // throws AssertionError
28
+ * Convert Dinero currency to local currency type
27
29
  */
28
30
  export declare const parseCurrencyCode: (code: string) => Currency;
29
31
  /**
30
- * Utility to quickly convert cents to a to currency float amount number
31
- *
32
- * @example
33
- * centsToCurrencyUnit(100, "USD") // 1
34
- * centsToCurrencyUnit(1, "USD") // 0.01
35
- * centsToCurrencyUnit(420, "USD") // 4.2
36
- * centsToCurrencyUnit(420, "JPY") // 420
37
- * FIXME: worth moving to a combined method of centsToCurrencyUnit & dineroToCurrencyUnit that accepts Money|Dino as input
38
- */
39
- export declare const centsToCurrencyUnit: (centsAmount: Cents, currency: Currency) => number;
40
- /**
41
- * Utility to quickly convert dinero instance to a to currency amount number
32
+ * Get major units amount for cents amount and currency
42
33
  *
43
- * @example
44
- * dineroToCurrencyUnit(getDinero(100, Currency.Usd)) // 1
45
- * dineroToCurrencyUnit(getDinero(1, Currency.Usd)) // 0.01
46
- * dineroToCurrencyUnit(getDinero(420, Currency.Usd)) // 4.2
34
+ * Can look into the approach of dinero core toUnits if we need a more robust approach
35
+ * https://github.com/dinerojs/dinero.js/blob/main/packages/core/src/api/toUnits.ts
36
+ * Though, based on experimentation, it's a basic division in the end regardless
47
37
  */
48
- export declare const dineroToCurrencyUnit: (dineroObj: Dino) => number;
38
+ export declare const centsToMajorUnits: (amount: number, currency: Currency) => number;
49
39
  /**
50
- * Parse arbitrary float amount in a given currency to a dinero object.
51
- * Wrapper around `parseFloatToDineroRaw` for easier usage.
40
+ * Parse arbitrary float amount in a given currency to a dinero object
52
41
  *
53
42
  * Doesn't work on string float amounts!
54
43
  * @example
55
44
  * parseFloatToDinero(420, Currency.Usd); // => Dinero.js instance
56
45
  */
57
- export declare const parseFloatToDinero: (floatAmount: number, currency: Currency) => import("dinero.js").Dinero<number>;
58
- /**
59
- * Parse arbitrary float amount in a given dinero like currency object to a dinero object.
60
- * ! Typically use `parseFloatToDinero` instead of this method ! But this one is useful for custom currencies (e.g. custom exchange rates)
61
- */
62
- export declare const parseFloatToDineroRaw: (floatAmount: number, dineroCurrency: DinoCurrency) => import("dinero.js").Dinero<number>;
46
+ export declare const parseFloatToDinero: (floatAmount: number, currency: Currency) => Dinero<number>;
63
47
  /**
64
48
  * Shorthand for dinero constructor
65
- *
66
- * @example
67
- * getDinero(100, Currency.Usd); // => Dinero.js instance (representing $1)
68
49
  */
69
- export declare const getDinero: (amount: Cents, currency: Currency) => Dino;
50
+ export declare const getDinero: (amount: number, currency: Currency) => Dinero<number>;
70
51
  /**
71
52
  * Shorthand to get amount from dinero instance
72
53
  *
@@ -77,11 +58,8 @@ export declare const getDinero: (amount: Cents, currency: Currency) => Dino;
77
58
  *
78
59
  * We should call something like: transformScale(d, currency.exponent)
79
60
  * @see https://v2.dinerojs.com/docs/api/conversions/transform-scale
80
- *
81
- * @example
82
- * amount(getDinero(100, Currency.Usd)); // 100
83
61
  */
84
- export declare const amount: (dinero: Dino) => Cents;
62
+ export declare const amount: (dinero: Dinero<number>) => number;
85
63
  /**
86
64
  * Method to multiply dinero amount by full percent.
87
65
  * It also transforms scale back to currency exponent.
@@ -90,42 +68,24 @@ export declare const amount: (dinero: Dino) => Cents;
90
68
  * Will convert 0.01 - 12% to 0, but thats edge case we can tolerate, because
91
69
  * of dinero version we do not control rounding
92
70
  */
93
- export declare const multiplyByFullPercent: (dinero: Dino, percentIncrease: number) => Dino;
71
+ export declare const multiplyByFullPercent: (dinero: Dinero<number>, percentIncrease: number) => Dinero<number>;
94
72
  /**
95
73
  * Shorthand to get currency from dinero instance
96
- *
97
- * @example
98
- * currency(getDinero(100, Currency.Usd)); // Currency.Usd
99
74
  */
100
- export declare const currency: (dinero: Dino) => Currency;
75
+ export declare const currency: (dinero: Dinero<number>) => Currency;
101
76
  /**
102
77
  * Shorthand to get our GraphQL Money type from dinero instance
103
- *
104
- * @example
105
- * money(getDinero(100, Currency.Usd)); // { amount: 100, currency: Currency.Usd }
106
78
  */
107
- export declare const money: (dinero: Dino) => Money;
79
+ export declare const money: (dinero: Dinero<number>) => Money;
108
80
  /**
109
81
  * Helper to quickly add multiple dinero instances with same currency
110
- *
111
- * @example
112
- * addMany([getDinero(100, Currency.Usd), getDinero(200, Currency.Usd)], Currency.Usd); // => Dinero.js instance (representing $3)
113
82
  */
114
- export declare const addMany: (addends: Array<Dino>, defaultCurrency: Currency) => Dino;
83
+ export declare const addMany: (addends: Array<Dinero<number>>, defaultCurrency: Currency) => Dinero<number>;
115
84
  /**
116
85
  * Helper to quickly subtract multiple dinero instances with same currency
117
86
  */
118
- export declare const subtractMany: (subtractions: Array<Dino>, defaultCurrency: Currency) => Dino;
87
+ export declare const subtractMany: (subtractions: Array<Dinero<number>>, defaultCurrency: Currency) => Dinero<number>;
119
88
  /**
120
89
  * Helper to quickly get dinero object from string
121
90
  */
122
- export declare const stringAmountToDinero: (price: string, currency: Currency) => import("dinero.js").Dinero<number>;
123
- /**
124
- * Helper to quickly round dinero object to closest integer by a given rounding function
125
- * FIXME: add tests
126
- *
127
- * @example
128
- * roundDinero(getDinero(120, Currency.Usd), Math.floor); // => Dinero.js instance (representing $1)
129
- * roundDinero(getDinero(120, Currency.Usd), Math.ceil); // => Dinero.js instance (representing $2)
130
- */
131
- export declare const roundDinero: (dinero: Dino, roundingFn: RoundingFn) => Dino;
91
+ export declare const stringAmountToDinero: (price: string, currency: Currency) => Dinero<number>;