@ubnt/store.core 9.15.0-alpha.3 → 9.15.0-prealpha.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 (306) hide show
  1. package/CHANGELOG.md +1 -138
  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/close.svg +1 -3
  7. package/lib/assets/close2.svg +2 -3
  8. package/lib/assets/close3.svg +4 -1
  9. package/lib/assets/minus4.svg +8 -8
  10. package/lib/assets/minus5.svg +8 -8
  11. package/lib/assets/pause.svg +3 -3
  12. package/lib/assets/pause2.svg +3 -3
  13. package/lib/assets/plus5.svg +9 -9
  14. package/lib/assets/plus6.svg +9 -9
  15. package/lib/assets/ucgMax.jpg +0 -0
  16. package/lib/assets/ucgMax2.jpg +0 -0
  17. package/lib/assets/ucgUltra.jpg +0 -0
  18. package/lib/assets/ucgUltra2.jpg +0 -0
  19. package/lib/assets/udmPro.jpg +0 -0
  20. package/lib/assets/udmPro2.jpg +0 -0
  21. package/lib/assets/udmProMax.jpg +0 -0
  22. package/lib/assets/udmProMax2.jpg +0 -0
  23. package/lib/assets/udmProSpecial.jpg +0 -0
  24. package/lib/assets/udmProSpecial2.jpg +0 -0
  25. package/lib/components/CustomImage/CustomImage.js +1 -1
  26. package/lib/components/CustomImage/CustomImage.mjs +1 -1
  27. package/lib/components/FeaturesSection_deprecated/FeaturesSection.js +1 -1
  28. package/lib/components/FeaturesSection_deprecated/FeaturesSection.mjs +1 -1
  29. package/lib/components/FeaturesSection_deprecated/assets/close.svg.js +1 -1
  30. package/lib/components/FeaturesSection_deprecated/assets/close.svg.mjs +2 -2
  31. package/lib/components/GridGallery/GridModal/GridModal.js +1 -1
  32. package/lib/components/GridGallery/GridModal/GridModal.mjs +1 -1
  33. package/lib/components/Header/CartModalV2/CartModal.js +1 -1
  34. package/lib/components/Header/CartModalV2/CartModal.mjs +1 -1
  35. package/lib/components/Header/Header.js +1 -1
  36. package/lib/components/Header/Header.mjs +1 -1
  37. package/lib/components/LandingPagePro/LandingPagePro.d.ts +0 -3
  38. package/lib/components/LandingPagePro/LandingPagePro.js +3 -3
  39. package/lib/components/LandingPagePro/LandingPagePro.js.map +1 -1
  40. package/lib/components/LandingPagePro/LandingPagePro.mjs +2 -2
  41. package/lib/components/LandingPagePro/LandingPagePro.mjs.map +1 -1
  42. package/lib/components/LandingPageSidebar/LandingPageSidebar.js +1 -1
  43. package/lib/components/LandingPageSidebar/LandingPageSidebar.mjs +1 -1
  44. package/lib/components/MicrositeVideoSlideshow/MicrositeVideoSlideshow.js +1 -1
  45. package/lib/components/MicrositeVideoSlideshow/MicrositeVideoSlideshow.mjs +1 -1
  46. package/lib/components/MicrositeVideoSlideshow/assets/pause.svg.js +1 -1
  47. package/lib/components/MicrositeVideoSlideshow/assets/pause.svg.mjs +2 -2
  48. package/lib/components/ModelCompareV3/assets/Consoles/bigCompare/ucgMax.jpg.js +5 -5
  49. package/lib/components/ModelCompareV3/assets/Consoles/bigCompare/ucgMax.jpg.mjs +2 -2
  50. package/lib/components/ModelCompareV3/assets/Consoles/bigCompare/ucgUltra.jpg.js +5 -5
  51. package/lib/components/ModelCompareV3/assets/Consoles/bigCompare/ucgUltra.jpg.mjs +2 -2
  52. package/lib/components/ModelCompareV3/assets/Consoles/bigCompare/udmPro.jpg.js +5 -5
  53. package/lib/components/ModelCompareV3/assets/Consoles/bigCompare/udmPro.jpg.mjs +2 -2
  54. package/lib/components/ModelCompareV3/assets/Consoles/bigCompare/udmProMax.jpg.js +5 -5
  55. package/lib/components/ModelCompareV3/assets/Consoles/bigCompare/udmProMax.jpg.mjs +2 -2
  56. package/lib/components/ModelCompareV3/assets/Consoles/bigCompare/udmProSpecial.jpg.js +5 -5
  57. package/lib/components/ModelCompareV3/assets/Consoles/bigCompare/udmProSpecial.jpg.mjs +2 -2
  58. package/lib/components/ModelCompareV3/assets/Consoles/ucgMax.jpg.js +1 -1
  59. package/lib/components/ModelCompareV3/assets/Consoles/ucgMax.jpg.mjs +2 -2
  60. package/lib/components/ModelCompareV3/assets/Consoles/ucgUltra.jpg.js +1 -1
  61. package/lib/components/ModelCompareV3/assets/Consoles/ucgUltra.jpg.mjs +2 -2
  62. package/lib/components/ModelCompareV3/assets/Consoles/udmPro.jpg.js +1 -1
  63. package/lib/components/ModelCompareV3/assets/Consoles/udmPro.jpg.mjs +2 -2
  64. package/lib/components/ModelCompareV3/assets/Consoles/udmProMax.jpg.js +1 -1
  65. package/lib/components/ModelCompareV3/assets/Consoles/udmProMax.jpg.mjs +2 -2
  66. package/lib/components/ModelCompareV3/assets/Consoles/udmProSpecial.jpg.js +1 -1
  67. package/lib/components/ModelCompareV3/assets/Consoles/udmProSpecial.jpg.mjs +2 -2
  68. package/lib/components/ModelCompareV3/data/CloudGateways.js +15 -15
  69. package/lib/components/ModelCompareV3/data/CloudGateways.mjs +10 -10
  70. package/lib/components/ModelCompareV3/data/products/ucgMax.js +1 -1
  71. package/lib/components/ModelCompareV3/data/products/ucgMax.mjs +1 -1
  72. package/lib/components/ModelCompareV3/data/products/ucgUltra.js +1 -1
  73. package/lib/components/ModelCompareV3/data/products/ucgUltra.mjs +1 -1
  74. package/lib/components/ModelCompareV3/data/products/udmPro.js +1 -1
  75. package/lib/components/ModelCompareV3/data/products/udmPro.mjs +1 -1
  76. package/lib/components/ModelCompareV3/data/products/udmProMax.js +1 -1
  77. package/lib/components/ModelCompareV3/data/products/udmProMax.mjs +1 -1
  78. package/lib/components/ModelCompareV3/data/products/udmProSpecial.js +1 -1
  79. package/lib/components/ModelCompareV3/data/products/udmProSpecial.mjs +1 -1
  80. package/lib/components/ResourceCalculatorV1/ComputeResourceCalculator/ComputeResourceCalculator.constants.js +17 -313
  81. package/lib/components/ResourceCalculatorV1/ComputeResourceCalculator/ComputeResourceCalculator.constants.js.map +1 -1
  82. package/lib/components/ResourceCalculatorV1/ComputeResourceCalculator/ComputeResourceCalculator.constants.mjs +17 -311
  83. package/lib/components/ResourceCalculatorV1/ComputeResourceCalculator/ComputeResourceCalculator.constants.mjs.map +1 -1
  84. package/lib/components/ResourceCalculatorV1/ComputeResourceCalculator/ComputeResourceCalculator.types.d.ts +2 -3
  85. package/lib/components/ResourceCalculatorV1/ComputeResourceCalculator/ComputeResourceCalculator.types.js +0 -2
  86. package/lib/components/ResourceCalculatorV1/ComputeResourceCalculator/ComputeResourceCalculator.types.js.map +1 -1
  87. package/lib/components/ResourceCalculatorV1/ComputeResourceCalculator/ComputeResourceCalculator.types.mjs +0 -2
  88. package/lib/components/ResourceCalculatorV1/ComputeResourceCalculator/ComputeResourceCalculator.types.mjs.map +1 -1
  89. package/lib/components/ResourceCalculatorV1/ComputeResourceCalculator/components/DeviceSelect/DeviceSelect.js +34 -120
  90. package/lib/components/ResourceCalculatorV1/ComputeResourceCalculator/components/DeviceSelect/DeviceSelect.js.map +1 -1
  91. package/lib/components/ResourceCalculatorV1/ComputeResourceCalculator/components/DeviceSelect/DeviceSelect.mjs +34 -120
  92. package/lib/components/ResourceCalculatorV1/ComputeResourceCalculator/components/DeviceSelect/DeviceSelect.mjs.map +1 -1
  93. package/lib/components/ResourceCalculatorV1/ComputeResourceCalculator/components/DeviceSelect/DeviceSelect.styles.d.ts +2 -16
  94. package/lib/components/ResourceCalculatorV1/ComputeResourceCalculator/components/DeviceSelect/DeviceSelect.styles.js +12 -54
  95. package/lib/components/ResourceCalculatorV1/ComputeResourceCalculator/components/DeviceSelect/DeviceSelect.styles.js.map +1 -1
  96. package/lib/components/ResourceCalculatorV1/ComputeResourceCalculator/components/DeviceSelect/DeviceSelect.styles.mjs +11 -50
  97. package/lib/components/ResourceCalculatorV1/ComputeResourceCalculator/components/DeviceSelect/DeviceSelect.styles.mjs.map +1 -1
  98. package/lib/components/ResourceCalculatorV1/ComputeResourceCalculator/components/DeviceSelect/assets/ArrowLeftPrimary.svg.js +5 -5
  99. package/lib/components/ResourceCalculatorV1/ComputeResourceCalculator/components/DeviceSelect/assets/ArrowRightPrimary.svg.js +5 -5
  100. package/lib/components/ResourceCalculatorV1/ComputeResourceCalculator/components/InputCard/InputCard.js +1 -1
  101. package/lib/components/ResourceCalculatorV1/ComputeResourceCalculator/components/InputCard/InputCard.js.map +1 -1
  102. package/lib/components/ResourceCalculatorV1/ComputeResourceCalculator/components/InputCard/InputCard.mjs +1 -1
  103. package/lib/components/ResourceCalculatorV1/ComputeResourceCalculator/components/InputCard/InputCard.mjs.map +1 -1
  104. package/lib/components/ResourceCalculatorV1/ComputeResourceCalculator/components/InputCard/InputCard.styles.js +0 -2
  105. package/lib/components/ResourceCalculatorV1/ComputeResourceCalculator/components/InputCard/InputCard.styles.js.map +1 -1
  106. package/lib/components/ResourceCalculatorV1/ComputeResourceCalculator/components/InputCard/InputCard.styles.mjs +0 -2
  107. package/lib/components/ResourceCalculatorV1/ComputeResourceCalculator/components/InputCard/InputCard.styles.mjs.map +1 -1
  108. package/lib/components/ResourceCalculatorV1/ComputeResourceCalculator/components/InputCard/InputSections/CounterSection.js +2 -2
  109. package/lib/components/ResourceCalculatorV1/ComputeResourceCalculator/components/InputCard/InputSections/CounterSection.mjs +2 -2
  110. package/lib/components/ResourceCalculatorV1/ComputeResourceCalculator/components/InputCard/assets/minus.svg.js +1 -1
  111. package/lib/components/ResourceCalculatorV1/ComputeResourceCalculator/components/InputCard/assets/minus.svg.mjs +2 -2
  112. package/lib/components/ResourceCalculatorV1/ComputeResourceCalculator/components/InputCard/assets/plus.svg.js +1 -1
  113. package/lib/components/ResourceCalculatorV1/ComputeResourceCalculator/components/InputCard/assets/plus.svg.mjs +2 -2
  114. package/lib/components/ResourceCalculatorV1/ComputeResourceCalculator/useComputeResourceCalculator.js +1 -1
  115. package/lib/components/ResourceCalculatorV1/ComputeResourceCalculator/useComputeResourceCalculator.js.map +1 -1
  116. package/lib/components/ResourceCalculatorV1/ComputeResourceCalculator/useComputeResourceCalculator.mjs +1 -1
  117. package/lib/components/ResourceCalculatorV1/ComputeResourceCalculator/useComputeResourceCalculator.mjs.map +1 -1
  118. package/lib/components/ResourceCalculatorV1/PoeCalculator/components/PoeConsumerConfigurator/PoeConsumerSelectModal/PoeConsumerSelectModal.js +4 -4
  119. package/lib/components/ResourceCalculatorV1/PoeCalculator/components/PoeConsumerConfigurator/PoeConsumerSelectModal/PoeConsumerSelectModal.js.map +1 -1
  120. package/lib/components/ResourceCalculatorV1/PoeCalculator/components/PoeConsumerConfigurator/PoeConsumerSelectModal/PoeConsumerSelectModal.mjs +4 -4
  121. package/lib/components/ResourceCalculatorV1/PoeCalculator/components/PoeConsumerConfigurator/PoeConsumerSelectModal/PoeConsumerSelectModal.mjs.map +1 -1
  122. package/lib/components/ResourceCalculatorV1/PoeCalculator/components/PoeConsumerConfigurator/assets/minus.svg.js +1 -1
  123. package/lib/components/ResourceCalculatorV1/PoeCalculator/components/PoeConsumerConfigurator/assets/minus.svg.mjs +2 -2
  124. package/lib/components/ResourceCalculatorV1/PoeCalculator/components/PoeConsumerConfigurator/assets/plus.svg.js +1 -1
  125. package/lib/components/ResourceCalculatorV1/PoeCalculator/components/PoeConsumerConfigurator/assets/plus.svg.mjs +2 -2
  126. package/lib/components/ResourceCalculatorV1/ResourceCalculator.js +2 -1
  127. package/lib/components/ResourceCalculatorV1/ResourceCalculator.js.map +1 -1
  128. package/lib/components/ResourceCalculatorV1/ResourceCalculator.mjs +2 -1
  129. package/lib/components/ResourceCalculatorV1/ResourceCalculator.mjs.map +1 -1
  130. package/lib/components/{HorizontalOptionSelect → ResourceCalculatorV1/components/HorizontalOptionSelect}/HorizontalOptionSelect.d.ts +1 -1
  131. package/lib/components/{HorizontalOptionSelect → ResourceCalculatorV1/components/HorizontalOptionSelect}/HorizontalOptionSelect.js +1 -3
  132. package/lib/components/ResourceCalculatorV1/components/HorizontalOptionSelect/HorizontalOptionSelect.js.map +1 -0
  133. package/lib/components/{HorizontalOptionSelect → ResourceCalculatorV1/components/HorizontalOptionSelect}/HorizontalOptionSelect.mjs +1 -3
  134. package/lib/components/ResourceCalculatorV1/components/HorizontalOptionSelect/HorizontalOptionSelect.mjs.map +1 -0
  135. package/lib/components/{HorizontalOptionSelect → ResourceCalculatorV1/components/HorizontalOptionSelect}/HorizontalOptionSelect.styles.d.ts +0 -1
  136. package/lib/components/{HorizontalOptionSelect → ResourceCalculatorV1/components/HorizontalOptionSelect}/HorizontalOptionSelect.styles.js +7 -10
  137. package/lib/components/ResourceCalculatorV1/components/HorizontalOptionSelect/HorizontalOptionSelect.styles.js.map +1 -0
  138. package/lib/components/{HorizontalOptionSelect → ResourceCalculatorV1/components/HorizontalOptionSelect}/HorizontalOptionSelect.styles.mjs +7 -10
  139. package/lib/components/ResourceCalculatorV1/components/HorizontalOptionSelect/HorizontalOptionSelect.styles.mjs.map +1 -0
  140. package/lib/components/{HorizontalOptionSelect → ResourceCalculatorV1/components/HorizontalOptionSelect}/HorizontalOptionSelect.types.d.ts +0 -1
  141. package/lib/components/ResourceCalculatorV1/components/index.d.ts +1 -0
  142. package/lib/components/ResourceCalculatorV1/components/index.js +5 -0
  143. package/lib/{utils/money/allocators → components/ResourceCalculatorV1/components}/index.js.map +1 -1
  144. package/lib/components/ResourceCalculatorV1/components/index.mjs +3 -0
  145. package/lib/{utils/money/allocators → components/ResourceCalculatorV1/components}/index.mjs.map +1 -1
  146. package/lib/components/ResourceCalculatorV1/translations/en.json.js +4 -6
  147. package/lib/components/ResourceCalculatorV1/translations/en.json.js.map +1 -1
  148. package/lib/components/ResourceCalculatorV1/translations/en.json.mjs +4 -6
  149. package/lib/components/ResourceCalculatorV1/translations/en.json.mjs.map +1 -1
  150. package/lib/components/ResourceCalculatorV1/translations/useResourceCalculatorTranslation.d.ts +2 -2
  151. package/lib/components/Search/Input/Input.js +1 -1
  152. package/lib/components/Search/Input/Input.mjs +1 -1
  153. package/lib/components/VideoPlayerNew/VideoPlayer.js +2 -2
  154. package/lib/components/VideoPlayerNew/VideoPlayer.mjs +2 -2
  155. package/lib/components/VideoPlayerNew/assets/close.svg.js +1 -1
  156. package/lib/components/VideoPlayerNew/assets/close.svg.mjs +2 -2
  157. package/lib/components/VideoPlayerNew/assets/pause.svg.js +1 -1
  158. package/lib/components/VideoPlayerNew/assets/pause.svg.mjs +2 -2
  159. package/lib/components/index.d.ts +0 -1
  160. package/lib/components/index.js +0 -2
  161. package/lib/components/index.js.map +1 -1
  162. package/lib/components/index.mjs +0 -2
  163. package/lib/components/index.mjs.map +1 -1
  164. package/lib/constants/icons/generic/close.svg.js +1 -1
  165. package/lib/constants/icons/generic/close.svg.mjs +2 -2
  166. package/lib/constants/icons/generic/index.js +1 -1
  167. package/lib/constants/icons/generic/index.mjs +1 -1
  168. package/lib/constants/proStoreCategories/mapping/index.d.ts +0 -1
  169. package/lib/constants/proStoreCategories/mapping/index.js +11 -16
  170. package/lib/constants/proStoreCategories/mapping/index.js.map +1 -1
  171. package/lib/constants/proStoreCategories/mapping/index.mjs +11 -16
  172. package/lib/constants/proStoreCategories/mapping/index.mjs.map +1 -1
  173. package/lib/constants/proStoreCategories/mapping/unifi.d.ts +1 -2
  174. package/lib/constants/proStoreCategories/mapping/unifi.js +0 -1
  175. package/lib/constants/proStoreCategories/mapping/unifi.js.map +1 -1
  176. package/lib/constants/proStoreCategories/mapping/unifi.mjs +0 -1
  177. package/lib/constants/proStoreCategories/mapping/unifi.mjs.map +1 -1
  178. package/lib/constants/proStoreCategories/translations/en.json.js +0 -3
  179. package/lib/constants/proStoreCategories/translations/en.json.js.map +1 -1
  180. package/lib/constants/proStoreCategories/translations/en.json.mjs +1 -3
  181. package/lib/constants/proStoreCategories/translations/en.json.mjs.map +1 -1
  182. package/lib/constants/proStoreCategories/translations/fr.json.js +1 -1
  183. package/lib/constants/proStoreCategories/translations/fr.json.mjs +1 -1
  184. package/lib/constants/proStoreCategories/translations/zh-Hans.json.js +1 -1
  185. package/lib/constants/proStoreCategories/translations/zh-Hans.json.mjs +1 -1
  186. package/lib/constants/proStoreCategories/translations/zh-Hant-TW.json.js +1 -1
  187. package/lib/constants/proStoreCategories/translations/zh-Hant-TW.json.mjs +1 -1
  188. package/lib/helpers/index.d.ts +0 -1
  189. package/lib/helpers/index.js +0 -11
  190. package/lib/helpers/index.js.map +1 -1
  191. package/lib/helpers/index.mjs +0 -1
  192. package/lib/helpers/index.mjs.map +1 -1
  193. package/lib/types/index.d.ts +0 -1
  194. package/lib/types/index.js +0 -2
  195. package/lib/types/index.js.map +1 -1
  196. package/lib/types/index.mjs +0 -1
  197. package/lib/types/index.mjs.map +1 -1
  198. package/lib/utils/array.d.ts +0 -4
  199. package/lib/utils/array.js +0 -10
  200. package/lib/utils/array.js.map +1 -1
  201. package/lib/utils/array.mjs +1 -10
  202. package/lib/utils/array.mjs.map +1 -1
  203. package/lib/utils/money/constants.d.ts +25 -56
  204. package/lib/utils/money/constants.js +7 -72
  205. package/lib/utils/money/constants.js.map +1 -1
  206. package/lib/utils/money/constants.mjs +7 -70
  207. package/lib/utils/money/constants.mjs.map +1 -1
  208. package/lib/utils/money/format.d.ts +5 -10
  209. package/lib/utils/money/format.js +14 -22
  210. package/lib/utils/money/format.js.map +1 -1
  211. package/lib/utils/money/format.mjs +16 -23
  212. package/lib/utils/money/format.mjs.map +1 -1
  213. package/lib/utils/money/index.d.ts +1 -4
  214. package/lib/utils/money/index.js +8 -26
  215. package/lib/utils/money/index.js.map +1 -1
  216. package/lib/utils/money/index.mjs +4 -8
  217. package/lib/utils/money/index.mjs.map +1 -1
  218. package/lib/utils/money/misc.d.ts +28 -68
  219. package/lib/utils/money/misc.js +64 -35
  220. package/lib/utils/money/misc.js.map +1 -1
  221. package/lib/utils/money/misc.mjs +43 -32
  222. package/lib/utils/money/misc.mjs.map +1 -1
  223. package/lib/utils/money/tax.d.ts +2 -38
  224. package/lib/utils/money/tax.js +10 -46
  225. package/lib/utils/money/tax.js.map +1 -1
  226. package/lib/utils/money/tax.mjs +11 -42
  227. package/lib/utils/money/tax.mjs.map +1 -1
  228. package/lib/utils/money/types.d.ts +3 -78
  229. package/lib/utils/number.d.ts +1 -1
  230. package/lib/utils/number.js +1 -1
  231. package/lib/utils/number.js.map +1 -1
  232. package/lib/utils/number.mjs +1 -1
  233. package/lib/utils/number.mjs.map +1 -1
  234. package/lib/utils/validations.d.ts +15 -0
  235. package/lib/utils/validations.js +23 -0
  236. package/lib/utils/validations.js.map +1 -0
  237. package/lib/utils/validations.mjs +21 -0
  238. package/lib/utils/validations.mjs.map +1 -0
  239. package/package.json +1 -1
  240. package/lib/assets/efg.png +0 -0
  241. package/lib/assets/ucg-max.png +0 -0
  242. package/lib/components/HorizontalOptionSelect/HorizontalOptionSelect.js.map +0 -1
  243. package/lib/components/HorizontalOptionSelect/HorizontalOptionSelect.mjs.map +0 -1
  244. package/lib/components/HorizontalOptionSelect/HorizontalOptionSelect.styles.js.map +0 -1
  245. package/lib/components/HorizontalOptionSelect/HorizontalOptionSelect.styles.mjs.map +0 -1
  246. package/lib/components/ResourceCalculatorV1/assets/consoles/efg.png.js +0 -27
  247. package/lib/components/ResourceCalculatorV1/assets/consoles/efg.png.js.map +0 -1
  248. package/lib/components/ResourceCalculatorV1/assets/consoles/efg.png.mjs +0 -3
  249. package/lib/components/ResourceCalculatorV1/assets/consoles/efg.png.mjs.map +0 -1
  250. package/lib/components/ResourceCalculatorV1/assets/consoles/ucg-max.png.js +0 -27
  251. package/lib/components/ResourceCalculatorV1/assets/consoles/ucg-max.png.js.map +0 -1
  252. package/lib/components/ResourceCalculatorV1/assets/consoles/ucg-max.png.mjs +0 -3
  253. package/lib/components/ResourceCalculatorV1/assets/consoles/ucg-max.png.mjs.map +0 -1
  254. package/lib/helpers/product.d.ts +0 -87
  255. package/lib/helpers/product.js +0 -346
  256. package/lib/helpers/product.js.map +0 -1
  257. package/lib/helpers/product.mjs +0 -335
  258. package/lib/helpers/product.mjs.map +0 -1
  259. package/lib/types/product.d.ts +0 -87
  260. package/lib/types/product.js +0 -14
  261. package/lib/types/product.js.map +0 -1
  262. package/lib/types/product.mjs +0 -13
  263. package/lib/types/product.mjs.map +0 -1
  264. package/lib/utils/money/allocators/fixedAmount.d.ts +0 -26
  265. package/lib/utils/money/allocators/fixedAmount.js +0 -55
  266. package/lib/utils/money/allocators/fixedAmount.js.map +0 -1
  267. package/lib/utils/money/allocators/fixedAmount.mjs +0 -53
  268. package/lib/utils/money/allocators/fixedAmount.mjs.map +0 -1
  269. package/lib/utils/money/allocators/index.d.ts +0 -2
  270. package/lib/utils/money/allocators/index.js +0 -8
  271. package/lib/utils/money/allocators/index.mjs +0 -4
  272. package/lib/utils/money/allocators/productAmount.d.ts +0 -13
  273. package/lib/utils/money/allocators/productAmount.js +0 -110
  274. package/lib/utils/money/allocators/productAmount.js.map +0 -1
  275. package/lib/utils/money/allocators/productAmount.mjs +0 -108
  276. package/lib/utils/money/allocators/productAmount.mjs.map +0 -1
  277. package/lib/utils/money/exchangeRate.d.ts +0 -31
  278. package/lib/utils/money/exchangeRate.js +0 -27
  279. package/lib/utils/money/exchangeRate.js.map +0 -1
  280. package/lib/utils/money/exchangeRate.mjs +0 -23
  281. package/lib/utils/money/exchangeRate.mjs.map +0 -1
  282. package/lib/utils/money/misc.private.d.ts +0 -23
  283. package/lib/utils/money/misc.private.js +0 -46
  284. package/lib/utils/money/misc.private.js.map +0 -1
  285. package/lib/utils/money/misc.private.mjs +0 -21
  286. package/lib/utils/money/misc.private.mjs.map +0 -1
  287. package/lib/utils/money/shipping.d.ts +0 -5
  288. package/lib/utils/money/shipping.js +0 -8
  289. package/lib/utils/money/shipping.js.map +0 -1
  290. package/lib/utils/money/shipping.mjs +0 -6
  291. package/lib/utils/money/shipping.mjs.map +0 -1
  292. package/lib/utils/money/tax.private.d.ts +0 -17
  293. package/lib/utils/money/tax.private.js +0 -65
  294. package/lib/utils/money/tax.private.js.map +0 -1
  295. package/lib/utils/money/tax.private.mjs +0 -60
  296. package/lib/utils/money/tax.private.mjs.map +0 -1
  297. package/lib/utils/productSort.d.ts +0 -41
  298. package/lib/utils/productSort.js +0 -66
  299. package/lib/utils/productSort.js.map +0 -1
  300. package/lib/utils/productSort.mjs +0 -59
  301. package/lib/utils/productSort.mjs.map +0 -1
  302. /package/lib/components/{HorizontalOptionSelect → ResourceCalculatorV1/components/HorizontalOptionSelect}/index.d.ts +0 -0
  303. /package/lib/components/{HorizontalOptionSelect → ResourceCalculatorV1/components/HorizontalOptionSelect}/index.js +0 -0
  304. /package/lib/components/{HorizontalOptionSelect → ResourceCalculatorV1/components/HorizontalOptionSelect}/index.js.map +0 -0
  305. /package/lib/components/{HorizontalOptionSelect → ResourceCalculatorV1/components/HorizontalOptionSelect}/index.mjs +0 -0
  306. /package/lib/components/{HorizontalOptionSelect → ResourceCalculatorV1/components/HorizontalOptionSelect}/index.mjs.map +0 -0
@@ -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>;
@@ -1,14 +1,56 @@
1
1
  'use strict';
2
2
 
3
+ var currencies = require('@dinero.js/currencies');
3
4
  var dinero_js = require('dinero.js');
4
5
  require('../../types/index.js');
5
6
  var errors = require('../errors.js');
6
7
  var number = require('../number.js');
7
8
  var string = require('../string.js');
9
+ var validations = require('../validations.js');
8
10
  var constants = require('./constants.js');
9
- var misc_private = require('./misc.private.js');
10
11
  var generated = require('../../types/generated.js');
12
+ function _interopNamespace(e) {
13
+ if (e && e.__esModule) return e;
14
+ var n = Object.create(null);
15
+ if (e) {
16
+ Object.keys(e).forEach(function (k) {
17
+ if (k !== 'default') {
18
+ var d = Object.getOwnPropertyDescriptor(e, k);
19
+ Object.defineProperty(n, k, d.get ? d : {
20
+ enumerable: true,
21
+ get: function () {
22
+ return e[k];
23
+ }
24
+ });
25
+ }
26
+ });
27
+ }
28
+ n["default"] = e;
29
+ return Object.freeze(n);
30
+ }
31
+ var currencies__namespace = /*#__PURE__*/_interopNamespace(currencies);
11
32
  "use strict";
33
+ const currencyLookup = new Set(Object.keys(generated.Currency).map(el => el.toString()));
34
+ const currenciesMap = new Map(Object.values(currencies__namespace).map(currency2 => [currency2.code, currency2]));
35
+ const floatToInt = (floatAmount, base, exponent) => constants.financialRound(floatAmount * Math.pow(base, exponent));
36
+ const prettifyTotal = total => {
37
+ if (!dinero_js.hasSubUnits(total)) {
38
+ return total;
39
+ }
40
+ const totalJson = total.toJSON();
41
+ const minValueInclusiveToRoundDownFrom = constants.prettifyPriceLookup.get(totalJson.currency.code);
42
+ if (minValueInclusiveToRoundDownFrom == null || dinero_js.toUnit(total) < minValueInclusiveToRoundDownFrom) {
43
+ return total;
44
+ }
45
+ const roundedUnitPrice = dinero_js.toUnit(total, {
46
+ digits: 0,
47
+ round: dinero_js.down
48
+ });
49
+ return dinero_js.dinero({
50
+ amount: roundedUnitPrice * Math.pow(totalJson.currency.base, totalJson.currency.exponent),
51
+ currency: totalJson.currency
52
+ });
53
+ };
12
54
  const toSmallestSubunit = total => {
13
55
  if (!dinero_js.hasSubUnits(total)) {
14
56
  return total;
@@ -18,47 +60,49 @@ const toSmallestSubunit = total => {
18
60
  if (roundToDigits == null || roundingMode == null) {
19
61
  return total;
20
62
  }
21
- return roundDinero(total, roundingMode);
63
+ const roundedUnitPrice = dinero_js.toUnit(total, {
64
+ digits: roundToDigits,
65
+ round: roundingMode
66
+ });
67
+ return dinero_js.dinero({
68
+ amount: roundedUnitPrice * Math.pow(totalJson.currency.base, totalJson.currency.exponent),
69
+ currency: totalJson.currency
70
+ });
22
71
  };
23
72
  const getDineroCurrency = currency2 => {
24
- const dineroCurrency = misc_private.dineroCurrenciesLookup.get(currency2);
73
+ const dineroCurrency = currenciesMap.get(currency2);
25
74
  errors.assert(!!dineroCurrency, `Unsupported currency: "${currency2}"`);
26
75
  return dineroCurrency;
27
76
  };
28
77
  const parseCurrencyCode = code => {
29
78
  const normalizedCode = string.capitalize(code.toLowerCase());
30
- errors.assert(misc_private.currencyLookup.has(normalizedCode), `Invalid currency code: ${normalizedCode}`);
79
+ errors.assert(currencyLookup.has(normalizedCode), `Invalid currency code: ${normalizedCode}`);
31
80
  return generated.Currency[normalizedCode];
32
81
  };
33
- const centsToCurrencyUnit = (centsAmount, currency2) => {
82
+ const centsToMajorUnits = (amount2, currency2) => {
34
83
  const dineroCurrency = getDineroCurrency(currency2);
35
- const dineroObj = dinero_js.dinero({
36
- amount: centsAmount,
84
+ const price = dinero_js.dinero({
85
+ amount: amount2,
37
86
  currency: dineroCurrency
38
87
  });
39
- return dineroToCurrencyUnit(dineroObj);
40
- };
41
- const dineroToCurrencyUnit = dineroObj => {
42
- return dinero_js.toUnit(dineroObj);
88
+ const divider = Math.pow(10, dineroCurrency.exponent);
89
+ return dinero_js.toSnapshot(price).amount / divider;
43
90
  };
44
91
  const parseFloatToDinero = (floatAmount, currency2) => {
45
- const dineroCurrency = getDineroCurrency(currency2);
46
- return parseFloatToDineroRaw(floatAmount, dineroCurrency);
47
- };
48
- const parseFloatToDineroRaw = (floatAmount, dineroCurrency) => {
49
92
  number.isFloat(floatAmount, "Amount");
93
+ const dineroCurrency = getDineroCurrency(currency2);
50
94
  const scaleOfGivenAmount = String(floatAmount).split(".")[1]?.length ?? dineroCurrency.exponent;
51
95
  if (scaleOfGivenAmount == null || scaleOfGivenAmount > dineroCurrency.exponent) {
52
96
  throw new Error(`scaleOfGivenAmount is unsupported ${scaleOfGivenAmount}`);
53
97
  }
54
- const rateInt = misc_private.floatToInt(floatAmount, dineroCurrency.base, dineroCurrency.exponent);
98
+ const rateInt = floatToInt(floatAmount, dineroCurrency.base, dineroCurrency.exponent);
55
99
  return dinero_js.dinero({
56
100
  amount: rateInt,
57
101
  currency: dineroCurrency
58
102
  });
59
103
  };
60
104
  const getDinero = (amount2, currency2) => {
61
- number.isInt(amount2, "Amount");
105
+ validations.isInt(amount2, "Amount");
62
106
  return dinero_js.dinero({
63
107
  amount: amount2,
64
108
  currency: getDineroCurrency(currency2)
@@ -90,33 +134,18 @@ const money = dinero2 => {
90
134
  };
91
135
  const addMany = (addends, defaultCurrency) => [...addends, getDinero(0, defaultCurrency)].reduce(dinero_js.add);
92
136
  const subtractMany = (subtractions, defaultCurrency) => [...subtractions, getDinero(0, defaultCurrency)].reduce(dinero_js.subtract);
93
- const stringAmountToDinero = (price, currency2) =>
94
- // FIXME: parseFloat seems dangerous O_O
95
- parseFloatToDinero(parseFloat(price), currency2);
96
- const roundDinero = (dinero2, roundingFn) => {
97
- const roundedUnitPrice = dinero_js.toUnit(dinero2, {
98
- digits: 0,
99
- round: roundingFn
100
- });
101
- const snapshot = dinero_js.toSnapshot(dinero2);
102
- return dinero2.create({
103
- amount: roundedUnitPrice * snapshot.currency.base ** snapshot.currency.exponent,
104
- currency: snapshot.currency
105
- });
106
- };
137
+ const stringAmountToDinero = (price, currency2) => parseFloatToDinero(parseFloat(price), currency2);
107
138
  exports.addMany = addMany;
108
139
  exports.amount = amount;
109
- exports.centsToCurrencyUnit = centsToCurrencyUnit;
140
+ exports.centsToMajorUnits = centsToMajorUnits;
110
141
  exports.currency = currency;
111
- exports.dineroToCurrencyUnit = dineroToCurrencyUnit;
112
142
  exports.getDinero = getDinero;
113
143
  exports.getDineroCurrency = getDineroCurrency;
114
144
  exports.money = money;
115
145
  exports.multiplyByFullPercent = multiplyByFullPercent;
116
146
  exports.parseCurrencyCode = parseCurrencyCode;
117
147
  exports.parseFloatToDinero = parseFloatToDinero;
118
- exports.parseFloatToDineroRaw = parseFloatToDineroRaw;
119
- exports.roundDinero = roundDinero;
148
+ exports.prettifyTotal = prettifyTotal;
120
149
  exports.stringAmountToDinero = stringAmountToDinero;
121
150
  exports.subtractMany = subtractMany;
122
151
  exports.toSmallestSubunit = toSmallestSubunit;