@ubnt/store.core 9.9.0-alpha.9 → 9.9.0-konutis.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (370) hide show
  1. package/CHANGELOG.md +0 -30
  2. package/lib/_virtual/_virtual_multi-entry.js +16 -4
  3. package/lib/_virtual/_virtual_multi-entry.js.map +1 -1
  4. package/lib/_virtual/_virtual_multi-entry.mjs +2 -2
  5. package/lib/assets/attention.svg +5 -5
  6. package/lib/assets/attention2.svg +5 -5
  7. package/lib/assets/close2.svg +3 -2
  8. package/lib/assets/close3.svg +2 -3
  9. package/lib/assets/minus4.svg +8 -8
  10. package/lib/assets/minus5.svg +8 -8
  11. package/lib/assets/plus5.svg +9 -9
  12. package/lib/assets/plus6.svg +9 -9
  13. package/lib/assets/socialMedia/{x.svg.js → twitter.svg.js} +6 -6
  14. package/lib/assets/socialMedia/twitter.svg.js.map +1 -0
  15. package/lib/assets/socialMedia/twitter.svg.mjs +3 -0
  16. package/lib/assets/socialMedia/twitter.svg.mjs.map +1 -0
  17. package/lib/assets/twitter.svg +3 -0
  18. package/lib/assets/ucgUltra.jpg +0 -0
  19. package/lib/assets/ucgUltra2.jpg +0 -0
  20. package/lib/assets/udmPro.jpg +0 -0
  21. package/lib/assets/udmPro2.jpg +0 -0
  22. package/lib/assets/udmProMax.jpg +0 -0
  23. package/lib/assets/udmProMax2.jpg +0 -0
  24. package/lib/assets/udmProSpecial.jpg +0 -0
  25. package/lib/assets/udmProSpecial2.jpg +0 -0
  26. package/lib/components/FeaturesSection_deprecated/FeaturesSection.js +1 -1
  27. package/lib/components/FeaturesSection_deprecated/FeaturesSection.mjs +1 -1
  28. package/lib/components/FeaturesSection_deprecated/assets/close.svg.js +1 -1
  29. package/lib/components/FeaturesSection_deprecated/assets/close.svg.mjs +2 -2
  30. package/lib/components/Footer/Footer.d.ts +1 -1
  31. package/lib/components/Footer/Footer.js +74 -192
  32. package/lib/components/Footer/Footer.js.map +1 -1
  33. package/lib/components/Footer/Footer.mjs +76 -174
  34. package/lib/components/Footer/Footer.mjs.map +1 -1
  35. package/lib/components/Footer/Footer.styles.d.ts +5 -17
  36. package/lib/components/Footer/Footer.styles.js +44 -91
  37. package/lib/components/Footer/Footer.styles.js.map +1 -1
  38. package/lib/components/Footer/Footer.styles.mjs +44 -87
  39. package/lib/components/Footer/Footer.styles.mjs.map +1 -1
  40. package/lib/components/Footer/Footer.types.d.ts +0 -40
  41. package/lib/components/Footer/Footer.types.js +0 -16
  42. package/lib/components/Footer/Footer.types.js.map +1 -1
  43. package/lib/components/Footer/Footer.types.mjs +0 -15
  44. package/lib/components/Footer/Footer.types.mjs.map +1 -1
  45. package/lib/components/Footer/index.js +1 -3
  46. package/lib/components/Footer/index.js.map +1 -1
  47. package/lib/components/Footer/index.mjs +1 -1
  48. package/lib/components/Header/AccountMenu/AccountMenu.js +3 -6
  49. package/lib/components/Header/AccountMenu/AccountMenu.js.map +1 -1
  50. package/lib/components/Header/AccountMenu/AccountMenu.mjs +3 -6
  51. package/lib/components/Header/AccountMenu/AccountMenu.mjs.map +1 -1
  52. package/lib/components/Header/Navigation/MobileMenu/MobileMenu.js +6 -11
  53. package/lib/components/Header/Navigation/MobileMenu/MobileMenu.js.map +1 -1
  54. package/lib/components/Header/Navigation/MobileMenu/MobileMenu.mjs +6 -11
  55. package/lib/components/Header/Navigation/MobileMenu/MobileMenu.mjs.map +1 -1
  56. package/lib/components/Header/Navigation/ProMobileMenu/ProMobileMenu.js +4 -8
  57. package/lib/components/Header/Navigation/ProMobileMenu/ProMobileMenu.js.map +1 -1
  58. package/lib/components/Header/Navigation/ProMobileMenu/ProMobileMenu.mjs +4 -8
  59. package/lib/components/Header/Navigation/ProMobileMenu/ProMobileMenu.mjs.map +1 -1
  60. package/lib/components/Header/ProHeader/ProHeader.js +2 -19
  61. package/lib/components/Header/ProHeader/ProHeader.js.map +1 -1
  62. package/lib/components/Header/ProHeader/ProHeader.mjs +2 -19
  63. package/lib/components/Header/ProHeader/ProHeader.mjs.map +1 -1
  64. package/lib/components/Header/ProHeader/ProHeader.styles.d.ts +0 -1
  65. package/lib/components/Header/ProHeader/ProHeader.styles.js +0 -6
  66. package/lib/components/Header/ProHeader/ProHeader.styles.js.map +1 -1
  67. package/lib/components/Header/ProHeader/ProHeader.styles.mjs +0 -6
  68. package/lib/components/Header/ProHeader/ProHeader.styles.mjs.map +1 -1
  69. package/lib/components/LandingPagePro/LandingPagePro.d.ts +0 -3
  70. package/lib/components/LandingPagePro/LandingPagePro.js +3 -3
  71. package/lib/components/LandingPagePro/LandingPagePro.js.map +1 -1
  72. package/lib/components/LandingPagePro/LandingPagePro.mjs +2 -2
  73. package/lib/components/LandingPagePro/LandingPagePro.mjs.map +1 -1
  74. package/lib/components/ModelCompareV3/assets/Consoles/bigCompare/ucgUltra.jpg.js +5 -5
  75. package/lib/components/ModelCompareV3/assets/Consoles/bigCompare/ucgUltra.jpg.mjs +2 -2
  76. package/lib/components/ModelCompareV3/assets/Consoles/bigCompare/udmPro.jpg.js +5 -5
  77. package/lib/components/ModelCompareV3/assets/Consoles/bigCompare/udmPro.jpg.mjs +2 -2
  78. package/lib/components/ModelCompareV3/assets/Consoles/bigCompare/udmProMax.jpg.js +5 -5
  79. package/lib/components/ModelCompareV3/assets/Consoles/bigCompare/udmProMax.jpg.mjs +2 -2
  80. package/lib/components/ModelCompareV3/assets/Consoles/bigCompare/udmProSpecial.jpg.js +5 -5
  81. package/lib/components/ModelCompareV3/assets/Consoles/bigCompare/udmProSpecial.jpg.mjs +2 -2
  82. package/lib/components/ModelCompareV3/assets/Consoles/ucgUltra.jpg.js +1 -1
  83. package/lib/components/ModelCompareV3/assets/Consoles/ucgUltra.jpg.mjs +2 -2
  84. package/lib/components/ModelCompareV3/assets/Consoles/udmPro.jpg.js +1 -1
  85. package/lib/components/ModelCompareV3/assets/Consoles/udmPro.jpg.mjs +2 -2
  86. package/lib/components/ModelCompareV3/assets/Consoles/udmProMax.jpg.js +1 -1
  87. package/lib/components/ModelCompareV3/assets/Consoles/udmProMax.jpg.mjs +2 -2
  88. package/lib/components/ModelCompareV3/assets/Consoles/udmProSpecial.jpg.js +1 -1
  89. package/lib/components/ModelCompareV3/assets/Consoles/udmProSpecial.jpg.mjs +2 -2
  90. package/lib/components/ModelCompareV3/data/CloudGateways.js +12 -12
  91. package/lib/components/ModelCompareV3/data/CloudGateways.mjs +8 -8
  92. package/lib/components/ModelCompareV3/data/products/ucgUltra.js +1 -1
  93. package/lib/components/ModelCompareV3/data/products/ucgUltra.mjs +1 -1
  94. package/lib/components/ModelCompareV3/data/products/udmPro.js +1 -1
  95. package/lib/components/ModelCompareV3/data/products/udmPro.mjs +1 -1
  96. package/lib/components/ModelCompareV3/data/products/udmProMax.js +1 -1
  97. package/lib/components/ModelCompareV3/data/products/udmProMax.mjs +1 -1
  98. package/lib/components/ModelCompareV3/data/products/udmProSpecial.js +1 -1
  99. package/lib/components/ModelCompareV3/data/products/udmProSpecial.mjs +1 -1
  100. package/lib/components/ResourceCalculatorV1/ComputeResourceCalculator/ComputeResourceCalculator.constants.js +1 -6
  101. package/lib/components/ResourceCalculatorV1/ComputeResourceCalculator/ComputeResourceCalculator.constants.js.map +1 -1
  102. package/lib/components/ResourceCalculatorV1/ComputeResourceCalculator/ComputeResourceCalculator.constants.mjs +1 -6
  103. package/lib/components/ResourceCalculatorV1/ComputeResourceCalculator/ComputeResourceCalculator.constants.mjs.map +1 -1
  104. package/lib/components/ResourceCalculatorV1/ComputeResourceCalculator/components/InputCard/InputCard.js +2 -2
  105. package/lib/components/ResourceCalculatorV1/ComputeResourceCalculator/components/InputCard/InputCard.js.map +1 -1
  106. package/lib/components/ResourceCalculatorV1/ComputeResourceCalculator/components/InputCard/InputCard.mjs +2 -2
  107. package/lib/components/ResourceCalculatorV1/ComputeResourceCalculator/components/InputCard/InputCard.mjs.map +1 -1
  108. package/lib/components/ResourceCalculatorV1/ComputeResourceCalculator/components/InputCard/InputCard.styles.js +0 -2
  109. package/lib/components/ResourceCalculatorV1/ComputeResourceCalculator/components/InputCard/InputCard.styles.js.map +1 -1
  110. package/lib/components/ResourceCalculatorV1/ComputeResourceCalculator/components/InputCard/InputCard.styles.mjs +0 -2
  111. package/lib/components/ResourceCalculatorV1/ComputeResourceCalculator/components/InputCard/InputCard.styles.mjs.map +1 -1
  112. package/lib/components/ResourceCalculatorV1/ComputeResourceCalculator/components/InputCard/InputSections/CounterSection.js +2 -2
  113. package/lib/components/ResourceCalculatorV1/ComputeResourceCalculator/components/InputCard/InputSections/CounterSection.mjs +2 -2
  114. package/lib/components/ResourceCalculatorV1/ComputeResourceCalculator/components/InputCard/assets/attention.svg.js +1 -1
  115. package/lib/components/ResourceCalculatorV1/ComputeResourceCalculator/components/InputCard/assets/attention.svg.mjs +2 -2
  116. package/lib/components/ResourceCalculatorV1/ComputeResourceCalculator/components/InputCard/assets/minus.svg.js +1 -1
  117. package/lib/components/ResourceCalculatorV1/ComputeResourceCalculator/components/InputCard/assets/minus.svg.mjs +2 -2
  118. package/lib/components/ResourceCalculatorV1/ComputeResourceCalculator/components/InputCard/assets/plus.svg.js +1 -1
  119. package/lib/components/ResourceCalculatorV1/ComputeResourceCalculator/components/InputCard/assets/plus.svg.mjs +2 -2
  120. package/lib/components/ResourceCalculatorV1/ComputeResourceCalculator/components/ProgressBarChart/ProgressBarChart.js +1 -1
  121. package/lib/components/ResourceCalculatorV1/ComputeResourceCalculator/components/ProgressBarChart/ProgressBarChart.mjs +1 -1
  122. package/lib/components/ResourceCalculatorV1/ComputeResourceCalculator/components/ProgressBarChart/assets/attention.svg.js +1 -1
  123. package/lib/components/ResourceCalculatorV1/ComputeResourceCalculator/components/ProgressBarChart/assets/attention.svg.mjs +2 -2
  124. package/lib/components/ResourceCalculatorV1/PoeCalculator/components/PoeConsumerConfigurator/PoeConsumerSelectModal/PoeConsumerSelectModal.js +2 -2
  125. package/lib/components/ResourceCalculatorV1/PoeCalculator/components/PoeConsumerConfigurator/PoeConsumerSelectModal/PoeConsumerSelectModal.mjs +2 -2
  126. package/lib/components/ResourceCalculatorV1/PoeCalculator/components/PoeConsumerConfigurator/assets/minus.svg.js +1 -1
  127. package/lib/components/ResourceCalculatorV1/PoeCalculator/components/PoeConsumerConfigurator/assets/minus.svg.mjs +2 -2
  128. package/lib/components/ResourceCalculatorV1/PoeCalculator/components/PoeConsumerConfigurator/assets/plus.svg.js +1 -1
  129. package/lib/components/ResourceCalculatorV1/PoeCalculator/components/PoeConsumerConfigurator/assets/plus.svg.mjs +2 -2
  130. package/lib/components/VideoPlayerNew/VideoPlayer.js +1 -1
  131. package/lib/components/VideoPlayerNew/VideoPlayer.mjs +1 -1
  132. package/lib/components/VideoPlayerNew/assets/close.svg.js +1 -1
  133. package/lib/components/VideoPlayerNew/assets/close.svg.mjs +2 -2
  134. package/lib/constants/footerContent.d.ts +145 -0
  135. package/lib/constants/footerContent.js +313 -0
  136. package/lib/constants/footerContent.js.map +1 -0
  137. package/lib/constants/footerContent.mjs +293 -0
  138. package/lib/constants/footerContent.mjs.map +1 -0
  139. package/lib/constants/icons/options/colors/black.svg.js +5 -5
  140. package/lib/constants/icons/options/colors/index.js +3 -3
  141. package/lib/constants/icons/options/styles/black.svg.js +5 -5
  142. package/lib/constants/icons/options/styles/index.js +3 -3
  143. package/lib/constants/optionIcons.js +6 -6
  144. package/lib/constants/optionIcons.mjs +4 -4
  145. package/lib/constants/proStoreCategories/mapping/index.d.ts +0 -3
  146. package/lib/constants/proStoreCategories/mapping/index.js +10 -20
  147. package/lib/constants/proStoreCategories/mapping/index.js.map +1 -1
  148. package/lib/constants/proStoreCategories/mapping/index.mjs +10 -20
  149. package/lib/constants/proStoreCategories/mapping/index.mjs.map +1 -1
  150. package/lib/constants/proStoreCategories/mapping/unifi.d.ts +1 -3
  151. package/lib/constants/proStoreCategories/mapping/unifi.js +0 -2
  152. package/lib/constants/proStoreCategories/mapping/unifi.js.map +1 -1
  153. package/lib/constants/proStoreCategories/mapping/unifi.mjs +0 -2
  154. package/lib/constants/proStoreCategories/mapping/unifi.mjs.map +1 -1
  155. package/lib/constants/proStoreCategories/translations/ar.json.js +1 -1
  156. package/lib/constants/proStoreCategories/translations/ar.json.mjs +1 -1
  157. package/lib/constants/proStoreCategories/translations/de.json.js +1 -1
  158. package/lib/constants/proStoreCategories/translations/de.json.mjs +1 -1
  159. package/lib/constants/proStoreCategories/translations/el.json.js +1 -1
  160. package/lib/constants/proStoreCategories/translations/el.json.mjs +1 -1
  161. package/lib/constants/proStoreCategories/translations/en.json.js +0 -5
  162. package/lib/constants/proStoreCategories/translations/en.json.js.map +1 -1
  163. package/lib/constants/proStoreCategories/translations/en.json.mjs +1 -5
  164. package/lib/constants/proStoreCategories/translations/en.json.mjs.map +1 -1
  165. package/lib/constants/proStoreCategories/translations/es.json.js +1 -1
  166. package/lib/constants/proStoreCategories/translations/es.json.mjs +1 -1
  167. package/lib/constants/proStoreCategories/translations/fr.json.js +2 -2
  168. package/lib/constants/proStoreCategories/translations/fr.json.mjs +2 -2
  169. package/lib/constants/proStoreCategories/translations/it.json.js +1 -1
  170. package/lib/constants/proStoreCategories/translations/it.json.mjs +1 -1
  171. package/lib/constants/proStoreCategories/translations/ja.json.js +1 -1
  172. package/lib/constants/proStoreCategories/translations/ja.json.mjs +1 -1
  173. package/lib/constants/proStoreCategories/translations/pt-BR.json.js +1 -1
  174. package/lib/constants/proStoreCategories/translations/pt-BR.json.mjs +1 -1
  175. package/lib/constants/proStoreCategories/translations/zh-Hans.json.js +2 -2
  176. package/lib/constants/proStoreCategories/translations/zh-Hans.json.mjs +2 -2
  177. package/lib/constants/proStoreCategories/translations/zh-Hant-TW.json.js +2 -2
  178. package/lib/constants/proStoreCategories/translations/zh-Hant-TW.json.mjs +2 -2
  179. package/lib/constants/url.d.ts +4 -4
  180. package/lib/constants/url.js +4 -4
  181. package/lib/constants/url.js.map +1 -1
  182. package/lib/constants/url.mjs +4 -4
  183. package/lib/constants/url.mjs.map +1 -1
  184. package/lib/contexts/MenuContext/mapping.js +0 -41
  185. package/lib/contexts/MenuContext/mapping.js.map +1 -1
  186. package/lib/contexts/MenuContext/mapping.mjs +0 -41
  187. package/lib/contexts/MenuContext/mapping.mjs.map +1 -1
  188. package/lib/contexts/MenuContext/presets.js.map +1 -1
  189. package/lib/contexts/MenuContext/presets.mjs.map +1 -1
  190. package/lib/helpers/index.d.ts +1 -0
  191. package/lib/helpers/index.js +12 -0
  192. package/lib/helpers/index.js.map +1 -1
  193. package/lib/helpers/index.mjs +1 -0
  194. package/lib/helpers/index.mjs.map +1 -1
  195. package/lib/helpers/product.d.ts +96 -0
  196. package/lib/helpers/product.js +360 -0
  197. package/lib/helpers/product.js.map +1 -0
  198. package/lib/helpers/product.mjs +348 -0
  199. package/lib/helpers/product.mjs.map +1 -0
  200. package/lib/types/index.d.ts +1 -0
  201. package/lib/types/index.js +2 -0
  202. package/lib/types/index.js.map +1 -1
  203. package/lib/types/index.mjs +1 -0
  204. package/lib/types/index.mjs.map +1 -1
  205. package/lib/types/product.d.ts +87 -0
  206. package/lib/types/product.js +14 -0
  207. package/lib/types/product.js.map +1 -0
  208. package/lib/types/product.mjs +13 -0
  209. package/lib/types/product.mjs.map +1 -0
  210. package/lib/utils/address.d.ts +61 -61
  211. package/lib/utils/array.d.ts +4 -0
  212. package/lib/utils/array.js +10 -0
  213. package/lib/utils/array.js.map +1 -1
  214. package/lib/utils/array.mjs +10 -1
  215. package/lib/utils/array.mjs.map +1 -1
  216. package/lib/utils/index.d.ts +0 -1
  217. package/lib/utils/index.js +0 -2
  218. package/lib/utils/index.js.map +1 -1
  219. package/lib/utils/index.mjs +0 -2
  220. package/lib/utils/index.mjs.map +1 -1
  221. package/lib/utils/money/constants.d.ts +25 -56
  222. package/lib/utils/money/constants.js +7 -72
  223. package/lib/utils/money/constants.js.map +1 -1
  224. package/lib/utils/money/constants.mjs +7 -70
  225. package/lib/utils/money/constants.mjs.map +1 -1
  226. package/lib/utils/money/format.d.ts +5 -10
  227. package/lib/utils/money/format.js +14 -22
  228. package/lib/utils/money/format.js.map +1 -1
  229. package/lib/utils/money/format.mjs +16 -23
  230. package/lib/utils/money/format.mjs.map +1 -1
  231. package/lib/utils/money/index.d.ts +1 -4
  232. package/lib/utils/money/index.js +8 -26
  233. package/lib/utils/money/index.js.map +1 -1
  234. package/lib/utils/money/index.mjs +4 -8
  235. package/lib/utils/money/index.mjs.map +1 -1
  236. package/lib/utils/money/misc.d.ts +28 -68
  237. package/lib/utils/money/misc.js +64 -35
  238. package/lib/utils/money/misc.js.map +1 -1
  239. package/lib/utils/money/misc.mjs +43 -32
  240. package/lib/utils/money/misc.mjs.map +1 -1
  241. package/lib/utils/money/tax.d.ts +2 -38
  242. package/lib/utils/money/tax.js +10 -46
  243. package/lib/utils/money/tax.js.map +1 -1
  244. package/lib/utils/money/tax.mjs +11 -42
  245. package/lib/utils/money/tax.mjs.map +1 -1
  246. package/lib/utils/money/types.d.ts +3 -78
  247. package/lib/utils/number.d.ts +1 -1
  248. package/lib/utils/number.js +1 -1
  249. package/lib/utils/number.js.map +1 -1
  250. package/lib/utils/number.mjs +1 -1
  251. package/lib/utils/number.mjs.map +1 -1
  252. package/lib/utils/productSort.d.ts +41 -0
  253. package/lib/utils/productSort.js +66 -0
  254. package/lib/utils/productSort.js.map +1 -0
  255. package/lib/utils/productSort.mjs +59 -0
  256. package/lib/utils/productSort.mjs.map +1 -0
  257. package/lib/utils/validations.d.ts +15 -0
  258. package/lib/utils/validations.js +23 -0
  259. package/lib/utils/validations.js.map +1 -0
  260. package/lib/utils/validations.mjs +21 -0
  261. package/lib/utils/validations.mjs.map +1 -0
  262. package/package.json +1 -1
  263. package/lib/assets/socialMedia/x.svg.js.map +0 -1
  264. package/lib/assets/socialMedia/x.svg.mjs +0 -3
  265. package/lib/assets/socialMedia/x.svg.mjs.map +0 -1
  266. package/lib/assets/x.svg +0 -3
  267. package/lib/components/Footer/hooks/useFooterContent.d.ts +0 -94
  268. package/lib/components/Footer/hooks/useFooterContent.js +0 -384
  269. package/lib/components/Footer/hooks/useFooterContent.js.map +0 -1
  270. package/lib/components/Footer/hooks/useFooterContent.mjs +0 -348
  271. package/lib/components/Footer/hooks/useFooterContent.mjs.map +0 -1
  272. package/lib/components/Footer/translations/ar.json.js +0 -47
  273. package/lib/components/Footer/translations/ar.json.js.map +0 -1
  274. package/lib/components/Footer/translations/ar.json.mjs +0 -42
  275. package/lib/components/Footer/translations/ar.json.mjs.map +0 -1
  276. package/lib/components/Footer/translations/de.json.js +0 -47
  277. package/lib/components/Footer/translations/de.json.js.map +0 -1
  278. package/lib/components/Footer/translations/de.json.mjs +0 -42
  279. package/lib/components/Footer/translations/de.json.mjs.map +0 -1
  280. package/lib/components/Footer/translations/el.json.js +0 -47
  281. package/lib/components/Footer/translations/el.json.js.map +0 -1
  282. package/lib/components/Footer/translations/el.json.mjs +0 -42
  283. package/lib/components/Footer/translations/el.json.mjs.map +0 -1
  284. package/lib/components/Footer/translations/en.json.js +0 -46
  285. package/lib/components/Footer/translations/en.json.js.map +0 -1
  286. package/lib/components/Footer/translations/en.json.mjs +0 -41
  287. package/lib/components/Footer/translations/en.json.mjs.map +0 -1
  288. package/lib/components/Footer/translations/es.json.js +0 -47
  289. package/lib/components/Footer/translations/es.json.js.map +0 -1
  290. package/lib/components/Footer/translations/es.json.mjs +0 -42
  291. package/lib/components/Footer/translations/es.json.mjs.map +0 -1
  292. package/lib/components/Footer/translations/fr.json.js +0 -47
  293. package/lib/components/Footer/translations/fr.json.js.map +0 -1
  294. package/lib/components/Footer/translations/fr.json.mjs +0 -42
  295. package/lib/components/Footer/translations/fr.json.mjs.map +0 -1
  296. package/lib/components/Footer/translations/it.json.js +0 -47
  297. package/lib/components/Footer/translations/it.json.js.map +0 -1
  298. package/lib/components/Footer/translations/it.json.mjs +0 -42
  299. package/lib/components/Footer/translations/it.json.mjs.map +0 -1
  300. package/lib/components/Footer/translations/ja.json.js +0 -47
  301. package/lib/components/Footer/translations/ja.json.js.map +0 -1
  302. package/lib/components/Footer/translations/ja.json.mjs +0 -42
  303. package/lib/components/Footer/translations/ja.json.mjs.map +0 -1
  304. package/lib/components/Footer/translations/pt-BR.json.js +0 -47
  305. package/lib/components/Footer/translations/pt-BR.json.js.map +0 -1
  306. package/lib/components/Footer/translations/pt-BR.json.mjs +0 -42
  307. package/lib/components/Footer/translations/pt-BR.json.mjs.map +0 -1
  308. package/lib/components/Footer/translations/zh-Hans.json.js +0 -47
  309. package/lib/components/Footer/translations/zh-Hans.json.js.map +0 -1
  310. package/lib/components/Footer/translations/zh-Hans.json.mjs +0 -42
  311. package/lib/components/Footer/translations/zh-Hans.json.mjs.map +0 -1
  312. package/lib/components/Footer/translations/zh-Hant-TW.json.js +0 -47
  313. package/lib/components/Footer/translations/zh-Hant-TW.json.js.map +0 -1
  314. package/lib/components/Footer/translations/zh-Hant-TW.json.mjs +0 -42
  315. package/lib/components/Footer/translations/zh-Hant-TW.json.mjs.map +0 -1
  316. package/lib/components/Tooltip/Tooltip.d.ts +0 -2
  317. package/lib/components/Tooltip/Tooltip.js +0 -45
  318. package/lib/components/Tooltip/Tooltip.js.map +0 -1
  319. package/lib/components/Tooltip/Tooltip.mjs +0 -43
  320. package/lib/components/Tooltip/Tooltip.mjs.map +0 -1
  321. package/lib/components/Tooltip/Tooltip.styles.d.ts +0 -32
  322. package/lib/components/Tooltip/Tooltip.styles.js +0 -44
  323. package/lib/components/Tooltip/Tooltip.styles.js.map +0 -1
  324. package/lib/components/Tooltip/Tooltip.styles.mjs +0 -34
  325. package/lib/components/Tooltip/Tooltip.styles.mjs.map +0 -1
  326. package/lib/components/Tooltip/index.d.ts +0 -1
  327. package/lib/components/Tooltip/index.js +0 -6
  328. package/lib/components/Tooltip/index.js.map +0 -1
  329. package/lib/components/Tooltip/index.mjs +0 -3
  330. package/lib/components/Tooltip/index.mjs.map +0 -1
  331. package/lib/utils/money/allocators/fixedAmount.d.ts +0 -26
  332. package/lib/utils/money/allocators/fixedAmount.js +0 -55
  333. package/lib/utils/money/allocators/fixedAmount.js.map +0 -1
  334. package/lib/utils/money/allocators/fixedAmount.mjs +0 -53
  335. package/lib/utils/money/allocators/fixedAmount.mjs.map +0 -1
  336. package/lib/utils/money/allocators/index.d.ts +0 -2
  337. package/lib/utils/money/allocators/index.js +0 -8
  338. package/lib/utils/money/allocators/index.js.map +0 -1
  339. package/lib/utils/money/allocators/index.mjs +0 -4
  340. package/lib/utils/money/allocators/index.mjs.map +0 -1
  341. package/lib/utils/money/allocators/productAmount.d.ts +0 -13
  342. package/lib/utils/money/allocators/productAmount.js +0 -110
  343. package/lib/utils/money/allocators/productAmount.js.map +0 -1
  344. package/lib/utils/money/allocators/productAmount.mjs +0 -108
  345. package/lib/utils/money/allocators/productAmount.mjs.map +0 -1
  346. package/lib/utils/money/exchangeRate.d.ts +0 -31
  347. package/lib/utils/money/exchangeRate.js +0 -27
  348. package/lib/utils/money/exchangeRate.js.map +0 -1
  349. package/lib/utils/money/exchangeRate.mjs +0 -23
  350. package/lib/utils/money/exchangeRate.mjs.map +0 -1
  351. package/lib/utils/money/misc.private.d.ts +0 -23
  352. package/lib/utils/money/misc.private.js +0 -46
  353. package/lib/utils/money/misc.private.js.map +0 -1
  354. package/lib/utils/money/misc.private.mjs +0 -21
  355. package/lib/utils/money/misc.private.mjs.map +0 -1
  356. package/lib/utils/money/shipping.d.ts +0 -5
  357. package/lib/utils/money/shipping.js +0 -8
  358. package/lib/utils/money/shipping.js.map +0 -1
  359. package/lib/utils/money/shipping.mjs +0 -6
  360. package/lib/utils/money/shipping.mjs.map +0 -1
  361. package/lib/utils/money/tax.private.d.ts +0 -17
  362. package/lib/utils/money/tax.private.js +0 -65
  363. package/lib/utils/money/tax.private.js.map +0 -1
  364. package/lib/utils/money/tax.private.mjs +0 -60
  365. package/lib/utils/money/tax.private.mjs.map +0 -1
  366. package/lib/utils/typeGuards.d.ts +0 -1
  367. package/lib/utils/typeGuards.js +0 -6
  368. package/lib/utils/typeGuards.js.map +0 -1
  369. package/lib/utils/typeGuards.mjs +0 -5
  370. package/lib/utils/typeGuards.mjs.map +0 -1
@@ -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;
@@ -1 +1 @@
1
- {"version":3,"file":"misc.js","sources":["../../../src/utils/money/misc.ts"],"sourcesContent":["import {\n add,\n dinero,\n hasSubUnits,\n multiply,\n subtract,\n toSnapshot,\n toUnit,\n transformScale,\n} from \"dinero.js\";\n\nimport { Currency } from \"../../types\";\nimport { assert } from \"../errors\";\nimport { isFloat, isInt } from \"../number\";\nimport { capitalize } from \"../string\";\nimport { smallestSubunitLookup } from \"./constants\";\nimport {\n currencyLookup,\n dineroCurrenciesLookup,\n floatToInt,\n} from \"./misc.private\";\nimport type { Cents, Dino, DinoCurrency, Money, RoundingFn } from \"./types\";\n\n/**\n * 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.\n * This util rounds down any unused subunits to closest subunit resolution.\n *\n * ! Not to be confused with prettifyTotal\n */\nexport const toSmallestSubunit = (total: Dino): Dino => {\n // Nothing to round\n if (!hasSubUnits(total)) {\n return total;\n }\n\n const totalJson = total.toJSON();\n\n const [roundToDigits, roundingMode] =\n smallestSubunitLookup.get(totalJson.currency.code) ?? [];\n\n if (roundToDigits == null || roundingMode == null) {\n return total;\n }\n\n return roundDinero(total, roundingMode);\n};\n\n/**\n * Find Dinero.js currency instance from our Currency enum.\n * @throws Throws an error if currency is not found!\n *\n * @example\n * getDineroCurrency(Currency.Usd); // => Dinero.js currency instance\n * getDineroCurrency(\"invalid\"); // => throws AssertionError\n */\nexport const getDineroCurrency = (currency: Currency): DinoCurrency => {\n const dineroCurrency = dineroCurrenciesLookup.get(currency);\n assert(!!dineroCurrency, `Unsupported currency: \"${currency}\"`);\n return dineroCurrency;\n};\n\n/**\n * Convert Dinero currency (case-insensitive) to local currency type\n * @throws Throws an error if currency is not found!\n *\n * @example\n * parseCurrencyCode('usd') // Currency.Usd\n * parseCurrencyCode('JPY') // Currency.Jpy\n * parseCurrencyCode('invalid') // throws AssertionError\n */\nexport const parseCurrencyCode = (code: string): Currency => {\n const normalizedCode = capitalize(code.toLowerCase());\n assert(\n currencyLookup.has(normalizedCode),\n `Invalid currency code: ${normalizedCode}`,\n );\n return Currency[normalizedCode as keyof typeof Currency];\n};\n\n/**\n * Utility to quickly convert cents to a to currency float amount number\n *\n * @example\n * centsToCurrencyUnit(100, \"USD\") // 1\n * centsToCurrencyUnit(1, \"USD\") // 0.01\n * centsToCurrencyUnit(420, \"USD\") // 4.2\n * centsToCurrencyUnit(420, \"JPY\") // 420\n * FIXME: worth moving to a combined method of centsToCurrencyUnit & dineroToCurrencyUnit that accepts Money|Dino as input\n */\nexport const centsToCurrencyUnit = (\n centsAmount: Cents,\n currency: Currency,\n): number => {\n const dineroCurrency = getDineroCurrency(currency);\n const dineroObj = dinero({ amount: centsAmount, currency: dineroCurrency });\n return dineroToCurrencyUnit(dineroObj);\n};\n\n/**\n * Utility to quickly convert dinero instance to a to currency amount number\n *\n * @example\n * dineroToCurrencyUnit(getDinero(100, Currency.Usd)) // 1\n * dineroToCurrencyUnit(getDinero(1, Currency.Usd)) // 0.01\n * dineroToCurrencyUnit(getDinero(420, Currency.Usd)) // 4.2\n */\nexport const dineroToCurrencyUnit = (dineroObj: Dino): number => {\n return toUnit(dineroObj);\n};\n\n/**\n * Parse arbitrary float amount in a given currency to a dinero object.\n * Wrapper around `parseFloatToDineroRaw` for easier usage.\n *\n * Doesn't work on string float amounts!\n * @example\n * parseFloatToDinero(420, Currency.Usd); // => Dinero.js instance\n */\nexport const parseFloatToDinero = (floatAmount: number, currency: Currency) => {\n const dineroCurrency = getDineroCurrency(currency);\n return parseFloatToDineroRaw(floatAmount, dineroCurrency);\n};\n\n/**\n * Parse arbitrary float amount in a given dinero like currency object to a dinero object.\n * ! Typically use `parseFloatToDinero` instead of this method ! But this one is useful for custom currencies (e.g. custom exchange rates)\n */\nexport const parseFloatToDineroRaw = (\n floatAmount: number,\n dineroCurrency: DinoCurrency,\n) => {\n isFloat(floatAmount, \"Amount\");\n\n /**\n * Try to determine given input scale after comma, if not found, use currency default as that would indicate that\n * given input was an integer instead of a float\n *\n * FIXME: Won't work correctly if some currencies use dot/comma separation for decimal digits:\n * At least MacOS shows 4 different kind of formats to numbers.\n * 1. \"1234567,89\"\n * 2. \"1,234,567,89\"\n * 3. \"1.234.567,89\"\n * 4. \"1 234 567,89\"\n * Have to research if there are any more standards we should try to parse support\n */\n const scaleOfGivenAmount =\n String(floatAmount).split(\".\")[1]?.length ?? dineroCurrency.exponent;\n\n if (\n scaleOfGivenAmount == null ||\n scaleOfGivenAmount > dineroCurrency.exponent\n ) {\n throw new Error(`scaleOfGivenAmount is unsupported ${scaleOfGivenAmount}`);\n }\n const rateInt = floatToInt(\n floatAmount,\n dineroCurrency.base,\n dineroCurrency.exponent,\n );\n return dinero({\n amount: rateInt,\n currency: dineroCurrency,\n });\n};\n\n/**\n * Shorthand for dinero constructor\n *\n * @example\n * getDinero(100, Currency.Usd); // => Dinero.js instance (representing $1)\n */\nexport const getDinero = (amount: Cents, currency: Currency): Dino => {\n // TODO: verify if this is even needed, as dinero might already handle this\n isInt(amount, \"Amount\");\n return dinero({ amount, currency: getDineroCurrency(currency) });\n};\n\n/**\n * Shorthand to get amount from dinero instance\n *\n * FIXME: There is potential issue because we are not trimming scale:\n * multiply(getDinero(100, Currency.Usd), { amount: 100 + percentIncrease, scale: 2 })\n * will result in amount:10600, scale:4 (2*2), because dinero is rounding to safest scale.\n * @see https://v2.dinerojs.com/docs/core-concepts/scale#trimming-scale\n *\n * We should call something like: transformScale(d, currency.exponent)\n * @see https://v2.dinerojs.com/docs/api/conversions/transform-scale\n *\n * @example\n * amount(getDinero(100, Currency.Usd)); // 100\n */\nexport const amount = (dinero: Dino): Cents => {\n return toSnapshot(dinero).amount;\n};\n\n/**\n * Method to multiply dinero amount by full percent.\n * It also transforms scale back to currency exponent.\n * Where in case 20.34*1.06=21,5604, it will round to 21.56\n *\n * Will convert 0.01 - 12% to 0, but thats edge case we can tolerate, because\n * of dinero version we do not control rounding\n */\nexport const multiplyByFullPercent = (\n dinero: Dino,\n percentIncrease: number,\n): Dino => {\n assert(\n percentIncrease >= -100 && percentIncrease <= 100,\n \"Range should be in [-100, 100]\",\n );\n // (106 / 10^2 = 1.06)\n const multiplyResult = multiply(dinero, {\n amount: 100 + percentIncrease,\n scale: 2,\n });\n return transformScale(\n multiplyResult,\n multiplyResult.toJSON().currency.exponent,\n );\n};\n\n/**\n * Shorthand to get currency from dinero instance\n *\n * @example\n * currency(getDinero(100, Currency.Usd)); // Currency.Usd\n */\nexport const currency = (dinero: Dino): Currency => {\n return parseCurrencyCode(toSnapshot(dinero).currency.code);\n};\n\n/**\n * Shorthand to get our GraphQL Money type from dinero instance\n *\n * @example\n * money(getDinero(100, Currency.Usd)); // { amount: 100, currency: Currency.Usd }\n */\nexport const money = (dinero: Dino): Money => {\n const { amount, currency } = toSnapshot(dinero);\n\n return {\n amount,\n currency: parseCurrencyCode(currency.code),\n };\n};\n\n/**\n * Helper to quickly add multiple dinero instances with same currency\n *\n * @example\n * addMany([getDinero(100, Currency.Usd), getDinero(200, Currency.Usd)], Currency.Usd); // => Dinero.js instance (representing $3)\n */\nexport const addMany = (addends: Array<Dino>, defaultCurrency: Currency) =>\n [...addends, getDinero(0, defaultCurrency)].reduce(add);\n\n/**\n * Helper to quickly subtract multiple dinero instances with same currency\n */\nexport const subtractMany = (\n subtractions: Array<Dino>,\n defaultCurrency: Currency,\n) => [...subtractions, getDinero(0, defaultCurrency)].reduce(subtract);\n\n/**\n * Helper to quickly get dinero object from string\n */\nexport const stringAmountToDinero = (price: string, currency: Currency) =>\n // FIXME: parseFloat seems dangerous O_O\n parseFloatToDinero(parseFloat(price), currency);\n\n/**\n * Helper to quickly round dinero object to closest integer by a given rounding function\n * FIXME: add tests\n *\n * @example\n * roundDinero(getDinero(120, Currency.Usd), Math.floor); // => Dinero.js instance (representing $1)\n * roundDinero(getDinero(120, Currency.Usd), Math.ceil); // => Dinero.js instance (representing $2)\n */\nexport const roundDinero = (dinero: Dino, roundingFn: RoundingFn): Dino => {\n const roundedUnitPrice = toUnit(dinero, { digits: 0, round: roundingFn });\n\n const snapshot = toSnapshot(dinero);\n\n return dinero.create({\n amount:\n roundedUnitPrice * snapshot.currency.base ** snapshot.currency.exponent,\n currency: snapshot.currency,\n });\n};\n"],"names":["toSmallestSubunit","total","hasSubUnits","totalJson","toJSON","roundToDigits","roundingMode","smallestSubunitLookup","get","currency","code","roundDinero","getDineroCurrency","dineroCurrency","dineroCurrenciesLookup","assert","parseCurrencyCode","normalizedCode","capitalize","toLowerCase","currencyLookup","has","Currency","centsToCurrencyUnit","centsAmount","dineroObj","dinero","amount","dineroToCurrencyUnit","toUnit","parseFloatToDinero","floatAmount","parseFloatToDineroRaw","isFloat","scaleOfGivenAmount","String","split","length","exponent","Error","rateInt","floatToInt","base","getDinero","isInt","toSnapshot","multiplyByFullPercent","percentIncrease","multiplyResult","multiply","scale","transformScale","money","addMany","addends","defaultCurrency","reduce","add","subtractMany","subtractions","subtract","stringAmountToDinero","price","parseFloat","roundingFn","roundedUnitPrice","digits","round","snapshot","create"],"mappings":";;;;;;;;;;;AA6Ba,MAAAA,iBAAA,GAAqBC,KAAsB,IAAA;EAElD,IAAA,CAACC,SAAAA,CAAAA,WAAY,CAAAD,KAAK,CAAG,EAAA;IAChB,OAAAA,KAAA;EACT;EAEM,MAAAE,SAAA,GAAYF,MAAMG,MAAO,EAAA;EAEzB,MAAA,CAACC,aAAe,EAAAC,YAAY,CAChC,GAAAC,SAAA,CAAAA,qBAAA,CAAsBC,IAAIL,SAAU,CAAAM,QAAA,CAASC,IAAI,CAAA,IAAK,EAAC;EAErD,IAAAL,aAAA,IA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AAM,CAAA;EAElC,OAAOA,QAAO2C,MAAO,CAAA;IACnB1C,QACEsC,gBAAmB,GAAAG,QAAA,CAAS3D,QAAS,CAAAiC,IAAA,IAAQ0B,SAAS3D,QAAS,CAAA6B,QAAA;IACjE7B,UAAU2D,QAAS,CAAA3D;EAAA,CACpB,CAAA;AACH,CAAA;;;;;;;;;;;;;;;;"}
1
+ {"version":3,"file":"misc.js","sources":["../../../src/utils/money/misc.ts"],"sourcesContent":["import * as currencies from \"@dinero.js/currencies\";\nimport type { Dinero, Currency as DineroCurrency } from \"dinero.js\";\nimport {\n add,\n dinero,\n down,\n hasSubUnits,\n multiply,\n subtract,\n toSnapshot,\n toUnit,\n transformScale,\n} from \"dinero.js\";\n\nimport { Currency } from \"../../types\";\nimport { assert } from \"../errors\";\nimport { isFloat } from \"../number\";\nimport { capitalize } from \"../string\";\nimport { isInt } from \"../validations\";\nimport {\n financialRound,\n prettifyPriceLookup,\n smallestSubunitLookup,\n} from \"./constants\";\n\nexport interface Money {\n amount: number;\n currency: Currency;\n}\n\n// #############################################################################\n// Private helpers\n// #############################################################################\nconst currencyLookup = new Set(\n Object.keys(Currency).map((el) => el.toString()),\n);\n\n/**\n * Creating a map of currencies for way faster lookup then doing a array.find()\n * @see https://stackoverflow.com/a/65604244/1378261\n */\nconst currenciesMap = new Map(\n Object.values(currencies).map((currency) => [currency.code, currency]),\n);\n\n/**\n * Private util to convert a float value into a int. Also applies financial rounding to the value if needed.\n * Inspired by https://v2.dinerojs.com/docs/faq/how-can-i-create-dinero-objects-from-floats\n * @private Just for using within this file, please consider using other methods to solve your issue\n * @example\n * floatToInt(69.10, 10, 2); // 6910\n * floatToInt(42, 10, 2); // 4200\n * floatToInt(0.22, 10, 6); // 220000\n */\nconst floatToInt = (\n floatAmount: number,\n base: number,\n exponent: number,\n): number => financialRound(floatAmount * Math.pow(base, exponent));\n\n// #############################################################################\n// Public functions\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: Dinero<number>): Dinero<number> => {\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 const roundedUnitPrice = toUnit(total, { digits: 0, round: down });\n // Multiplying by 100 to get the cents\n return dinero({\n amount:\n roundedUnitPrice *\n Math.pow(totalJson.currency.base, totalJson.currency.exponent),\n currency: totalJson.currency,\n });\n};\n\n/**\n * 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.\n * This util rounds down any unused subunits to closest subunit resolution.\n *\n * ! Not to be confused with prettifyTotal\n */\nexport const toSmallestSubunit = (total: Dinero<number>): Dinero<number> => {\n // Nothing to round\n if (!hasSubUnits(total)) {\n return total;\n }\n\n const totalJson = total.toJSON();\n\n const [roundToDigits, roundingMode] =\n smallestSubunitLookup.get(totalJson.currency.code) ?? [];\n\n if (roundToDigits == null || roundingMode == null) {\n return total;\n }\n\n const roundedUnitPrice = toUnit(total, {\n digits: roundToDigits,\n round: roundingMode,\n });\n return dinero({\n amount:\n roundedUnitPrice *\n Math.pow(totalJson.currency.base, totalJson.currency.exponent),\n currency: totalJson.currency,\n });\n};\n\n/**\n * Find Dinero.js currency instance from our Currency enum.\n * @throws Throws an error if currency is not found!\n * @example\n * getDineroCurrency(Currency.Usd); // => Dinero.js currency instance\n * getDineroCurrency(\"invalid\"); // => throws AssertionError\n */\nexport const getDineroCurrency = (\n currency: Currency,\n): DineroCurrency<number> => {\n const dineroCurrency = currenciesMap.get(currency);\n assert(!!dineroCurrency, `Unsupported currency: \"${currency}\"`);\n return dineroCurrency;\n};\n\n/**\n * Convert Dinero currency to local currency type\n */\nexport const parseCurrencyCode = (code: string): Currency => {\n const normalizedCode = capitalize(code.toLowerCase());\n assert(\n currencyLookup.has(normalizedCode),\n `Invalid currency code: ${normalizedCode}`,\n );\n return Currency[normalizedCode as keyof typeof Currency];\n};\n\n/**\n * Get major units amount for cents amount and currency\n *\n * Can look into the approach of dinero core toUnits if we need a more robust approach\n * https://github.com/dinerojs/dinero.js/blob/main/packages/core/src/api/toUnits.ts\n * Though, based on experimentation, it's a basic division in the end regardless\n */\nexport const centsToMajorUnits = (\n amount: number,\n currency: Currency,\n): number => {\n const dineroCurrency = getDineroCurrency(currency);\n const price = dinero({ amount, currency: dineroCurrency });\n const divider = Math.pow(10, dineroCurrency.exponent);\n\n return toSnapshot(price).amount / divider;\n};\n\n/**\n * Parse arbitrary float amount in a given currency to a dinero object\n *\n * Doesn't work on string float amounts!\n * @example\n * parseFloatToDinero(420, Currency.Usd); // => Dinero.js instance\n */\nexport const parseFloatToDinero = (floatAmount: number, currency: Currency) => {\n isFloat(floatAmount, \"Amount\");\n\n const dineroCurrency = getDineroCurrency(currency);\n\n /**\n * Try to determine given input scale after comma, if not found, use currency default as that would indicate that\n * given input was an integer instead of a float\n *\n * FIXME: Won't work correctly if some currencies use dot/comma separation for decimal digits:\n * At least MacOS shows 4 different kind of formats to numbers.\n * 1. \"1234567,89\"\n * 2. \"1,234,567,89\"\n * 3. \"1.234.567,89\"\n * 4. \"1 234 567,89\"\n * Have to research if there are any more standards we should try to parse support\n */\n const scaleOfGivenAmount =\n String(floatAmount).split(\".\")[1]?.length ?? dineroCurrency.exponent;\n\n if (\n scaleOfGivenAmount == null ||\n scaleOfGivenAmount > dineroCurrency.exponent\n ) {\n throw new Error(`scaleOfGivenAmount is unsupported ${scaleOfGivenAmount}`);\n }\n const rateInt = floatToInt(\n floatAmount,\n dineroCurrency.base,\n dineroCurrency.exponent,\n );\n return dinero({\n amount: rateInt,\n currency: dineroCurrency,\n });\n};\n\n/**\n * Shorthand for dinero constructor\n */\nexport const getDinero = (\n amount: number,\n currency: Currency,\n): Dinero<number> => {\n isInt(amount, \"Amount\");\n return dinero({ amount, currency: getDineroCurrency(currency) });\n};\n\n/**\n * Shorthand to get amount from dinero instance\n *\n * FIXME: There is potential issue because we are not trimming scale:\n * multiply(getDinero(100, Currency.Usd), { amount: 100 + percentIncrease, scale: 2 })\n * will result in amount:10600, scale:4 (2*2), because dinero is rounding to safest scale.\n * @see https://v2.dinerojs.com/docs/core-concepts/scale#trimming-scale\n *\n * We should call something like: transformScale(d, currency.exponent)\n * @see https://v2.dinerojs.com/docs/api/conversions/transform-scale\n */\nexport const amount = (dinero: Dinero<number>): number => {\n return toSnapshot(dinero).amount;\n};\n\n/**\n * Method to multiply dinero amount by full percent.\n * It also transforms scale back to currency exponent.\n * Where in case 20.34*1.06=21,5604, it will round to 21.56\n *\n * Will convert 0.01 - 12% to 0, but thats edge case we can tolerate, because\n * of dinero version we do not control rounding\n */\nexport const multiplyByFullPercent = (\n dinero: Dinero<number>,\n percentIncrease: number,\n): Dinero<number> => {\n assert(\n percentIncrease >= -100 && percentIncrease <= 100,\n \"Range should be in [-100, 100]\",\n );\n // (106 / 10^2 = 1.06)\n const multiplyResult = multiply(dinero, {\n amount: 100 + percentIncrease,\n scale: 2,\n });\n return transformScale(\n multiplyResult,\n multiplyResult.toJSON().currency.exponent,\n );\n};\n\n/**\n * Shorthand to get currency from dinero instance\n */\nexport const currency = (dinero: Dinero<number>): Currency => {\n return parseCurrencyCode(toSnapshot(dinero).currency.code);\n};\n\n/**\n * Shorthand to get our GraphQL Money type from dinero instance\n */\nexport const money = (dinero: Dinero<number>): Money => {\n const { amount, currency } = toSnapshot(dinero);\n\n return {\n amount,\n currency: parseCurrencyCode(currency.code),\n };\n};\n\n/**\n * Helper to quickly add multiple dinero instances with same currency\n */\nexport const addMany = (\n addends: Array<Dinero<number>>,\n defaultCurrency: Currency,\n) => [...addends, getDinero(0, defaultCurrency)].reduce(add);\n\n/**\n * Helper to quickly subtract multiple dinero instances with same currency\n */\nexport const subtractMany = (\n subtractions: Array<Dinero<number>>,\n defaultCurrency: Currency,\n) => [...subtractions, getDinero(0, defaultCurrency)].reduce(subtract);\n\n/**\n * Helper to quickly get dinero object from string\n */\nexport const stringAmountToDinero = (price: string, currency: Currency) =>\n parseFloatToDinero(parseFloat(price), currency);\n"],"names":["currencyLookup","Set","Object","keys","Currency","map","el","toString","currenciesMap","Map","values","currencies","currency","code","floatToInt","floatAmount","base","exponent","financialRound","Math","pow","prettifyTotal","total","hasSubUnits","totalJson","toJSON","minValueInclusiveToRoundDownFrom","prettifyPriceLookup","get","toUnit","roundedUnitPrice","digits","round","down","dinero","amount","toSmallestSubunit","roundToDigits","roundingMode","smallestSubunitLookup","getDineroCurrency","dineroCurrency","assert","parseCurrencyCode","normalizedCode","capitalize","toLowerCase","has","centsToMajorUnits","price","divider","toSnapshot","parseFloatToDinero","isFloat","scaleOfGivenAmount","String","split","length","Error","rateInt","getDinero","isInt","multiplyByFullPercent","percentIncrease","multiplyResult","multiply","scale","transformScale","money","addMany","addends","defaultCurrency","reduce","add","subtractMany","subtractions","subtract","stringAmountToDinero","parseFloat"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAiCA,MAAMA,iBAAiB,IAAIC,GAAA,CACzBC,MAAA,CAAOC,KAAKC,SAAAA,CAAAA,QAAQ,CAAA,CAAEC,IAAKC,EAAA,IAAOA,EAAG,CAAAC,QAAA,EAAU,CACjD,CAAA;AAMA,MAAMC,gBAAgB,IAAIC,GAAA,CACxBP,MAAA,CAAOQ,MAAO,CAAAC,qBAAU,CAAE,CAAAN,GAAA,CAAKO,SAAAA,IAAa,CAACA,SAAAA,CAASC,IAAMD,EAAAA,SAAQ,CAAC,CACvE,CAAA;AAWA,MAAME,UAAA,GAAaA,CACjBC,WAAA,EACAC,IACA,EAAAC,QAAA,KACWC,SAAe,CAAAA,cAAA,CAAAH,WAAA,GAAcI,IAAK,CAAAC,GAAA,CAAIJ,IAAM,EAAAC,QAAQ,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