@ubnt/store.core 9.12.1 → 9.13.0-alpha.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 (695) hide show
  1. package/CHANGELOG.md +103 -0
  2. package/lib/_virtual/_virtual_multi-entry.js +15 -2
  3. package/lib/_virtual/_virtual_multi-entry.js.map +1 -1
  4. package/lib/_virtual/_virtual_multi-entry.mjs +2 -0
  5. package/lib/_virtual/_virtual_multi-entry.mjs.map +1 -1
  6. package/lib/assets/ai360.jpg +0 -0
  7. package/lib/assets/attention.svg +5 -5
  8. package/lib/assets/attention2.svg +5 -5
  9. package/lib/assets/close.svg +1 -3
  10. package/lib/assets/close2.svg +3 -1
  11. package/lib/assets/efg.png +0 -0
  12. package/lib/assets/g5-ptz.jpg +0 -0
  13. package/lib/assets/g5Ptz.jpg +0 -0
  14. package/lib/assets/group.svg +6 -0
  15. package/lib/assets/keyFeatures/group.svg +6 -0
  16. package/lib/{components/Explore/assets/ProAV.jpg.js → assets/keyFeatures/group.svg.js} +6 -6
  17. package/lib/assets/keyFeatures/group.svg.js.map +1 -0
  18. package/lib/assets/keyFeatures/group.svg.mjs +3 -0
  19. package/lib/assets/keyFeatures/group.svg.mjs.map +1 -0
  20. package/lib/assets/keyFeatures/music.svg +3 -0
  21. package/lib/{components/Explore/LensCompare/assets/ai360.jpg.js → assets/keyFeatures/music.svg.js} +6 -6
  22. package/lib/assets/keyFeatures/music.svg.js.map +1 -0
  23. package/lib/assets/keyFeatures/music.svg.mjs +3 -0
  24. package/lib/assets/keyFeatures/music.svg.mjs.map +1 -0
  25. package/lib/assets/music.svg +3 -0
  26. package/lib/assets/powerAmp.jpg +0 -0
  27. package/lib/assets/powerAmp.svg +3 -0
  28. package/lib/assets/ucg-max.png +0 -0
  29. package/lib/assets/ucgMax.jpg +0 -0
  30. package/lib/assets/ucgMax2.jpg +0 -0
  31. package/lib/assets/ucgUltra.jpg +0 -0
  32. package/lib/assets/ucgUltra2.jpg +0 -0
  33. package/lib/assets/udmPro.jpg +0 -0
  34. package/lib/assets/udmPro2.jpg +0 -0
  35. package/lib/assets/udr.jpg +0 -0
  36. package/lib/assets/udr2.jpg +0 -0
  37. package/lib/assets/udw.jpg +0 -0
  38. package/lib/assets/udw2.jpg +0 -0
  39. package/lib/assets/umr.jpg +0 -0
  40. package/lib/assets/umr2.jpg +0 -0
  41. package/lib/assets/volume-on2.svg +3 -0
  42. package/lib/assets/wideAngle.jpg +0 -0
  43. package/lib/components/CustomImage/CustomImage.js +1 -1
  44. package/lib/components/CustomImage/CustomImage.mjs +1 -1
  45. package/lib/components/Explore/Explore.js +2 -9
  46. package/lib/components/Explore/Explore.js.map +1 -1
  47. package/lib/components/Explore/Explore.mjs +2 -9
  48. package/lib/components/Explore/Explore.mjs.map +1 -1
  49. package/lib/components/Explore/ExploreData.d.ts +4 -7
  50. package/lib/components/Explore/ExploreData.js +88 -138
  51. package/lib/components/Explore/ExploreData.js.map +1 -1
  52. package/lib/components/Explore/ExploreData.mjs +80 -128
  53. package/lib/components/Explore/ExploreData.mjs.map +1 -1
  54. package/lib/components/Explore/assets/UISPConsole.jpg.js +5 -5
  55. package/lib/components/Explore/assets/{baseStation-mobile.jpg.js → baseStation--mobile.jpg.js} +6 -6
  56. package/lib/components/Explore/assets/baseStation--mobile.jpg.js.map +1 -0
  57. package/lib/components/Explore/assets/baseStation--mobile.jpg.mjs +3 -0
  58. package/lib/components/Explore/assets/baseStation--mobile.jpg.mjs.map +1 -0
  59. package/lib/components/Explore/assets/baseStation.jpg.js +5 -5
  60. package/lib/components/Explore/assets/{g4-ptz.jpg.js → g4Ptz.jpg.js} +2 -2
  61. package/lib/components/Explore/assets/g4Ptz.jpg.js.map +1 -0
  62. package/lib/components/Explore/assets/g4Ptz.jpg.mjs +3 -0
  63. package/lib/components/Explore/assets/g4Ptz.jpg.mjs.map +1 -0
  64. package/lib/components/Explore/assets/{g5-ptz.jpg.js → g5Ptz.jpg.js} +2 -2
  65. package/lib/components/Explore/assets/g5Ptz.jpg.js.map +1 -0
  66. package/lib/components/Explore/assets/g5Ptz.jpg.mjs +3 -0
  67. package/lib/components/Explore/assets/g5Ptz.jpg.mjs.map +1 -0
  68. package/lib/components/Explore/assets/{AITheta.jpg.js → powerAmp.jpg.js} +6 -6
  69. package/lib/components/Explore/assets/powerAmp.jpg.js.map +1 -0
  70. package/lib/components/Explore/assets/powerAmp.jpg.mjs +3 -0
  71. package/lib/components/Explore/assets/powerAmp.jpg.mjs.map +1 -0
  72. package/lib/components/Explore/assets/udr.jpg.js +27 -0
  73. package/lib/components/Explore/assets/udr.jpg.js.map +1 -0
  74. package/lib/components/Explore/assets/udr.jpg.mjs +3 -0
  75. package/lib/components/Explore/assets/udr.jpg.mjs.map +1 -0
  76. package/lib/components/Explore/assets/udw.jpg.js +27 -0
  77. package/lib/components/Explore/assets/udw.jpg.js.map +1 -0
  78. package/lib/components/Explore/assets/udw.jpg.mjs +3 -0
  79. package/lib/components/Explore/assets/udw.jpg.mjs.map +1 -0
  80. package/lib/components/Explore/assets/umr.jpg.js +27 -0
  81. package/lib/components/Explore/assets/umr.jpg.js.map +1 -0
  82. package/lib/components/Explore/assets/umr.jpg.mjs +3 -0
  83. package/lib/components/Explore/assets/umr.jpg.mjs.map +1 -0
  84. package/lib/components/Explore/assets/ux.jpg.js +27 -0
  85. package/lib/components/Explore/assets/ux.jpg.js.map +1 -0
  86. package/lib/components/Explore/assets/ux.jpg.mjs +3 -0
  87. package/lib/components/Explore/assets/ux.jpg.mjs.map +1 -0
  88. package/lib/components/Explore/translations/ar.json.js +19 -0
  89. package/lib/components/Explore/translations/ar.json.js.map +1 -1
  90. package/lib/components/Explore/translations/ar.json.mjs +19 -0
  91. package/lib/components/Explore/translations/ar.json.mjs.map +1 -1
  92. package/lib/components/Explore/translations/de.json.js +19 -0
  93. package/lib/components/Explore/translations/de.json.js.map +1 -1
  94. package/lib/components/Explore/translations/de.json.mjs +19 -0
  95. package/lib/components/Explore/translations/de.json.mjs.map +1 -1
  96. package/lib/components/Explore/translations/el.json.js +19 -0
  97. package/lib/components/Explore/translations/el.json.js.map +1 -1
  98. package/lib/components/Explore/translations/el.json.mjs +19 -0
  99. package/lib/components/Explore/translations/el.json.mjs.map +1 -1
  100. package/lib/components/Explore/translations/en.json.js +11 -30
  101. package/lib/components/Explore/translations/en.json.js.map +1 -1
  102. package/lib/components/Explore/translations/en.json.mjs +12 -30
  103. package/lib/components/Explore/translations/en.json.mjs.map +1 -1
  104. package/lib/components/Explore/translations/es.json.js +101 -82
  105. package/lib/components/Explore/translations/es.json.js.map +1 -1
  106. package/lib/components/Explore/translations/es.json.mjs +101 -82
  107. package/lib/components/Explore/translations/es.json.mjs.map +1 -1
  108. package/lib/components/Explore/translations/fr.json.js +19 -0
  109. package/lib/components/Explore/translations/fr.json.js.map +1 -1
  110. package/lib/components/Explore/translations/fr.json.mjs +19 -0
  111. package/lib/components/Explore/translations/fr.json.mjs.map +1 -1
  112. package/lib/components/Explore/translations/it.json.js +19 -0
  113. package/lib/components/Explore/translations/it.json.js.map +1 -1
  114. package/lib/components/Explore/translations/it.json.mjs +19 -0
  115. package/lib/components/Explore/translations/it.json.mjs.map +1 -1
  116. package/lib/components/Explore/translations/ja.json.js +19 -0
  117. package/lib/components/Explore/translations/ja.json.js.map +1 -1
  118. package/lib/components/Explore/translations/ja.json.mjs +19 -0
  119. package/lib/components/Explore/translations/ja.json.mjs.map +1 -1
  120. package/lib/components/Explore/translations/pt-BR.json.js +19 -0
  121. package/lib/components/Explore/translations/pt-BR.json.js.map +1 -1
  122. package/lib/components/Explore/translations/pt-BR.json.mjs +19 -0
  123. package/lib/components/Explore/translations/pt-BR.json.mjs.map +1 -1
  124. package/lib/components/Explore/translations/zh-Hans.json.js +19 -0
  125. package/lib/components/Explore/translations/zh-Hans.json.js.map +1 -1
  126. package/lib/components/Explore/translations/zh-Hans.json.mjs +19 -0
  127. package/lib/components/Explore/translations/zh-Hans.json.mjs.map +1 -1
  128. package/lib/components/Explore/translations/zh-Hant-TW.json.js +19 -0
  129. package/lib/components/Explore/translations/zh-Hant-TW.json.js.map +1 -1
  130. package/lib/components/Explore/translations/zh-Hant-TW.json.mjs +19 -0
  131. package/lib/components/Explore/translations/zh-Hant-TW.json.mjs.map +1 -1
  132. package/lib/components/GridGallery/GridModal/GridModal.js +1 -1
  133. package/lib/components/GridGallery/GridModal/GridModal.mjs +1 -1
  134. package/lib/components/Header/CartModalV2/CartModal.js +1 -1
  135. package/lib/components/Header/CartModalV2/CartModal.mjs +1 -1
  136. package/lib/components/Header/Header.js +2 -1
  137. package/lib/components/Header/Header.js.map +1 -1
  138. package/lib/components/Header/Header.mjs +2 -1
  139. package/lib/components/Header/Header.mjs.map +1 -1
  140. package/lib/components/LandingPagePro/LandingPagePro.d.ts +3 -0
  141. package/lib/components/LandingPagePro/LandingPagePro.js +3 -3
  142. package/lib/components/LandingPagePro/LandingPagePro.js.map +1 -1
  143. package/lib/components/LandingPagePro/LandingPagePro.mjs +2 -2
  144. package/lib/components/LandingPagePro/LandingPagePro.mjs.map +1 -1
  145. package/lib/components/LandingPageSidebar/LandingPageSidebar.js +1 -1
  146. package/lib/components/LandingPageSidebar/LandingPageSidebar.mjs +1 -1
  147. package/lib/components/ModelCompareV3/ModelCompareV3.types.d.ts +1 -0
  148. package/lib/components/ModelCompareV3/assets/Consoles/bigCompare/ucgMax.jpg.js +5 -5
  149. package/lib/components/ModelCompareV3/assets/Consoles/bigCompare/ucgMax.jpg.mjs +2 -2
  150. package/lib/components/ModelCompareV3/assets/Consoles/bigCompare/ucgUltra.jpg.js +5 -5
  151. package/lib/components/ModelCompareV3/assets/Consoles/bigCompare/ucgUltra.jpg.mjs +2 -2
  152. package/lib/components/ModelCompareV3/assets/Consoles/bigCompare/udmPro.jpg.js +5 -5
  153. package/lib/components/ModelCompareV3/assets/Consoles/bigCompare/udmPro.jpg.mjs +2 -2
  154. package/lib/components/ModelCompareV3/assets/Consoles/bigCompare/udr.jpg.js +1 -1
  155. package/lib/components/ModelCompareV3/assets/Consoles/bigCompare/udr.jpg.mjs +2 -2
  156. package/lib/components/ModelCompareV3/assets/Consoles/bigCompare/udw.jpg.js +1 -1
  157. package/lib/components/ModelCompareV3/assets/Consoles/bigCompare/udw.jpg.mjs +2 -2
  158. package/lib/components/ModelCompareV3/assets/Consoles/ucgMax.jpg.js +1 -1
  159. package/lib/components/ModelCompareV3/assets/Consoles/ucgMax.jpg.mjs +2 -2
  160. package/lib/components/ModelCompareV3/assets/Consoles/ucgUltra.jpg.js +1 -1
  161. package/lib/components/ModelCompareV3/assets/Consoles/ucgUltra.jpg.mjs +2 -2
  162. package/lib/components/ModelCompareV3/assets/Consoles/udmPro.jpg.js +1 -1
  163. package/lib/components/ModelCompareV3/assets/Consoles/udmPro.jpg.mjs +2 -2
  164. package/lib/components/ModelCompareV3/assets/Interior/ai360.jpg.js +1 -1
  165. package/lib/components/ModelCompareV3/assets/Interior/ai360.jpg.mjs +2 -2
  166. package/lib/components/ModelCompareV3/assets/Interior/wideAngle.jpg.js +1 -1
  167. package/lib/components/ModelCompareV3/assets/Interior/wideAngle.jpg.mjs +2 -2
  168. package/lib/components/ModelCompareV3/assets/MobileRouters/umr.jpg.js +1 -1
  169. package/lib/components/ModelCompareV3/assets/MobileRouters/umr.jpg.mjs +2 -2
  170. package/lib/components/ModelCompareV3/assets/PTZ/g5-ptz.jpg.js +1 -1
  171. package/lib/components/ModelCompareV3/assets/PTZ/g5-ptz.jpg.mjs +2 -2
  172. package/lib/components/ModelCompareV3/assets/volume-on.svg.js +27 -0
  173. package/lib/components/ModelCompareV3/assets/volume-on.svg.js.map +1 -0
  174. package/lib/components/ModelCompareV3/assets/volume-on.svg.mjs +3 -0
  175. package/lib/components/ModelCompareV3/assets/volume-on.svg.mjs.map +1 -0
  176. package/lib/components/ModelCompareV3/data/CloudGateways.js +11 -11
  177. package/lib/components/ModelCompareV3/data/CloudGateways.mjs +8 -8
  178. package/lib/components/ModelCompareV3/data/Switching.js +3 -1
  179. package/lib/components/ModelCompareV3/data/Switching.js.map +1 -1
  180. package/lib/components/ModelCompareV3/data/Switching.mjs +3 -1
  181. package/lib/components/ModelCompareV3/data/Switching.mjs.map +1 -1
  182. package/lib/components/ModelCompareV3/data/products/aggregation.js +16 -8
  183. package/lib/components/ModelCompareV3/data/products/aggregation.js.map +1 -1
  184. package/lib/components/ModelCompareV3/data/products/aggregation.mjs +16 -8
  185. package/lib/components/ModelCompareV3/data/products/aggregation.mjs.map +1 -1
  186. package/lib/components/ModelCompareV3/data/products/connectDisplay.js +1 -1
  187. package/lib/components/ModelCompareV3/data/products/connectDisplay.js.map +1 -1
  188. package/lib/components/ModelCompareV3/data/products/connectDisplay.mjs +1 -1
  189. package/lib/components/ModelCompareV3/data/products/connectDisplay.mjs.map +1 -1
  190. package/lib/components/ModelCompareV3/data/products/enterprise24PoE.js +16 -8
  191. package/lib/components/ModelCompareV3/data/products/enterprise24PoE.js.map +1 -1
  192. package/lib/components/ModelCompareV3/data/products/enterprise24PoE.mjs +16 -8
  193. package/lib/components/ModelCompareV3/data/products/enterprise24PoE.mjs.map +1 -1
  194. package/lib/components/ModelCompareV3/data/products/enterprise48PoE.js +16 -8
  195. package/lib/components/ModelCompareV3/data/products/enterprise48PoE.js.map +1 -1
  196. package/lib/components/ModelCompareV3/data/products/enterprise48PoE.mjs +16 -8
  197. package/lib/components/ModelCompareV3/data/products/enterprise48PoE.mjs.map +1 -1
  198. package/lib/components/ModelCompareV3/data/products/enterpriseXG24.js +16 -8
  199. package/lib/components/ModelCompareV3/data/products/enterpriseXG24.js.map +1 -1
  200. package/lib/components/ModelCompareV3/data/products/enterpriseXG24.mjs +16 -8
  201. package/lib/components/ModelCompareV3/data/products/enterpriseXG24.mjs.map +1 -1
  202. package/lib/components/ModelCompareV3/data/products/g5Ptz.js +1 -1
  203. package/lib/components/ModelCompareV3/data/products/g5Ptz.mjs +1 -1
  204. package/lib/components/ModelCompareV3/data/products/highCapacityAggregation.js +16 -8
  205. package/lib/components/ModelCompareV3/data/products/highCapacityAggregation.js.map +1 -1
  206. package/lib/components/ModelCompareV3/data/products/highCapacityAggregation.mjs +16 -8
  207. package/lib/components/ModelCompareV3/data/products/highCapacityAggregation.mjs.map +1 -1
  208. package/lib/components/ModelCompareV3/data/products/missionCritical.js +8 -0
  209. package/lib/components/ModelCompareV3/data/products/missionCritical.js.map +1 -1
  210. package/lib/components/ModelCompareV3/data/products/missionCritical.mjs +8 -0
  211. package/lib/components/ModelCompareV3/data/products/missionCritical.mjs.map +1 -1
  212. package/lib/components/ModelCompareV3/data/products/phoneTouch.js +5 -3
  213. package/lib/components/ModelCompareV3/data/products/phoneTouch.js.map +1 -1
  214. package/lib/components/ModelCompareV3/data/products/phoneTouch.mjs +5 -3
  215. package/lib/components/ModelCompareV3/data/products/phoneTouch.mjs.map +1 -1
  216. package/lib/components/ModelCompareV3/data/products/phoneTouchMax.js +4 -2
  217. package/lib/components/ModelCompareV3/data/products/phoneTouchMax.js.map +1 -1
  218. package/lib/components/ModelCompareV3/data/products/phoneTouchMax.mjs +4 -2
  219. package/lib/components/ModelCompareV3/data/products/phoneTouchMax.mjs.map +1 -1
  220. package/lib/components/ModelCompareV3/data/products/professional24.js +8 -0
  221. package/lib/components/ModelCompareV3/data/products/professional24.js.map +1 -1
  222. package/lib/components/ModelCompareV3/data/products/professional24.mjs +8 -0
  223. package/lib/components/ModelCompareV3/data/products/professional24.mjs.map +1 -1
  224. package/lib/components/ModelCompareV3/data/products/professional24PoE.js +8 -0
  225. package/lib/components/ModelCompareV3/data/products/professional24PoE.js.map +1 -1
  226. package/lib/components/ModelCompareV3/data/products/professional24PoE.mjs +8 -0
  227. package/lib/components/ModelCompareV3/data/products/professional24PoE.mjs.map +1 -1
  228. package/lib/components/ModelCompareV3/data/products/professional48.js +8 -0
  229. package/lib/components/ModelCompareV3/data/products/professional48.js.map +1 -1
  230. package/lib/components/ModelCompareV3/data/products/professional48.mjs +8 -0
  231. package/lib/components/ModelCompareV3/data/products/professional48.mjs.map +1 -1
  232. package/lib/components/ModelCompareV3/data/products/professional48PoE.js +8 -0
  233. package/lib/components/ModelCompareV3/data/products/professional48PoE.js.map +1 -1
  234. package/lib/components/ModelCompareV3/data/products/professional48PoE.mjs +8 -0
  235. package/lib/components/ModelCompareV3/data/products/professional48PoE.mjs.map +1 -1
  236. package/lib/components/ModelCompareV3/data/products/professionalMax16.js +7 -0
  237. package/lib/components/ModelCompareV3/data/products/professionalMax16.js.map +1 -1
  238. package/lib/components/ModelCompareV3/data/products/professionalMax16.mjs +7 -0
  239. package/lib/components/ModelCompareV3/data/products/professionalMax16.mjs.map +1 -1
  240. package/lib/components/ModelCompareV3/data/products/professionalMax16PoE.js +7 -0
  241. package/lib/components/ModelCompareV3/data/products/professionalMax16PoE.js.map +1 -1
  242. package/lib/components/ModelCompareV3/data/products/professionalMax16PoE.mjs +7 -0
  243. package/lib/components/ModelCompareV3/data/products/professionalMax16PoE.mjs.map +1 -1
  244. package/lib/components/ModelCompareV3/data/products/professionalMax24.js +7 -0
  245. package/lib/components/ModelCompareV3/data/products/professionalMax24.js.map +1 -1
  246. package/lib/components/ModelCompareV3/data/products/professionalMax24.mjs +7 -0
  247. package/lib/components/ModelCompareV3/data/products/professionalMax24.mjs.map +1 -1
  248. package/lib/components/ModelCompareV3/data/products/professionalMax24PoE.js +7 -0
  249. package/lib/components/ModelCompareV3/data/products/professionalMax24PoE.js.map +1 -1
  250. package/lib/components/ModelCompareV3/data/products/professionalMax24PoE.mjs +7 -0
  251. package/lib/components/ModelCompareV3/data/products/professionalMax24PoE.mjs.map +1 -1
  252. package/lib/components/ModelCompareV3/data/products/professionalMax48.js +7 -0
  253. package/lib/components/ModelCompareV3/data/products/professionalMax48.js.map +1 -1
  254. package/lib/components/ModelCompareV3/data/products/professionalMax48.mjs +7 -0
  255. package/lib/components/ModelCompareV3/data/products/professionalMax48.mjs.map +1 -1
  256. package/lib/components/ModelCompareV3/data/products/professionalMax48PoE.js +7 -0
  257. package/lib/components/ModelCompareV3/data/products/professionalMax48PoE.js.map +1 -1
  258. package/lib/components/ModelCompareV3/data/products/professionalMax48PoE.mjs +7 -0
  259. package/lib/components/ModelCompareV3/data/products/professionalMax48PoE.mjs.map +1 -1
  260. package/lib/components/ModelCompareV3/data/products/switchesEnterprise.js +11 -1
  261. package/lib/components/ModelCompareV3/data/products/switchesEnterprise.js.map +1 -1
  262. package/lib/components/ModelCompareV3/data/products/switchesEnterprise.mjs +11 -1
  263. package/lib/components/ModelCompareV3/data/products/switchesEnterprise.mjs.map +1 -1
  264. package/lib/components/ModelCompareV3/data/products/switchesProfessional.js +8 -0
  265. package/lib/components/ModelCompareV3/data/products/switchesProfessional.js.map +1 -1
  266. package/lib/components/ModelCompareV3/data/products/switchesProfessional.mjs +8 -0
  267. package/lib/components/ModelCompareV3/data/products/switchesProfessional.mjs.map +1 -1
  268. package/lib/components/ModelCompareV3/data/products/switchesProfessionalMax.js +8 -0
  269. package/lib/components/ModelCompareV3/data/products/switchesProfessionalMax.js.map +1 -1
  270. package/lib/components/ModelCompareV3/data/products/switchesProfessionalMax.mjs +8 -0
  271. package/lib/components/ModelCompareV3/data/products/switchesProfessionalMax.mjs.map +1 -1
  272. package/lib/components/ModelCompareV3/data/products/switchesStandard.js +8 -0
  273. package/lib/components/ModelCompareV3/data/products/switchesStandard.js.map +1 -1
  274. package/lib/components/ModelCompareV3/data/products/switchesStandard.mjs +8 -0
  275. package/lib/components/ModelCompareV3/data/products/switchesStandard.mjs.map +1 -1
  276. package/lib/components/ModelCompareV3/data/products/theta360.js +1 -1
  277. package/lib/components/ModelCompareV3/data/products/theta360.mjs +1 -1
  278. package/lib/components/ModelCompareV3/data/products/thetaWideAngle.js +1 -1
  279. package/lib/components/ModelCompareV3/data/products/thetaWideAngle.mjs +1 -1
  280. package/lib/components/ModelCompareV3/data/products/ucCast.js +1 -1
  281. package/lib/components/ModelCompareV3/data/products/ucCast.js.map +1 -1
  282. package/lib/components/ModelCompareV3/data/products/ucCast.mjs +1 -1
  283. package/lib/components/ModelCompareV3/data/products/ucCast.mjs.map +1 -1
  284. package/lib/components/ModelCompareV3/data/products/ucCastPro.js +1 -1
  285. package/lib/components/ModelCompareV3/data/products/ucCastPro.js.map +1 -1
  286. package/lib/components/ModelCompareV3/data/products/ucCastPro.mjs +1 -1
  287. package/lib/components/ModelCompareV3/data/products/ucCastPro.mjs.map +1 -1
  288. package/lib/components/ModelCompareV3/data/products/ucgMax.js +1 -1
  289. package/lib/components/ModelCompareV3/data/products/ucgMax.mjs +1 -1
  290. package/lib/components/ModelCompareV3/data/products/ucgUltra.js +1 -1
  291. package/lib/components/ModelCompareV3/data/products/ucgUltra.mjs +1 -1
  292. package/lib/components/ModelCompareV3/data/products/udmPro.js +1 -1
  293. package/lib/components/ModelCompareV3/data/products/udmPro.mjs +1 -1
  294. package/lib/components/ModelCompareV3/data/products/udr.js +1 -1
  295. package/lib/components/ModelCompareV3/data/products/udr.mjs +1 -1
  296. package/lib/components/ModelCompareV3/data/products/udw.js +1 -1
  297. package/lib/components/ModelCompareV3/data/products/udw.mjs +1 -1
  298. package/lib/components/ModelCompareV3/data/products/umr.js +1 -1
  299. package/lib/components/ModelCompareV3/data/products/umr.mjs +1 -1
  300. package/lib/components/ModelCompareV3/data/properties/index.d.ts +1 -0
  301. package/lib/components/ModelCompareV3/data/properties/index.js +2 -0
  302. package/lib/components/ModelCompareV3/data/properties/index.js.map +1 -1
  303. package/lib/components/ModelCompareV3/data/properties/index.mjs +1 -0
  304. package/lib/components/ModelCompareV3/data/properties/index.mjs.map +1 -1
  305. package/lib/components/ModelCompareV3/data/properties/proAvSupport.d.ts +2 -0
  306. package/lib/components/ModelCompareV3/data/properties/proAvSupport.js +19 -0
  307. package/lib/components/ModelCompareV3/data/properties/proAvSupport.js.map +1 -0
  308. package/lib/components/ModelCompareV3/data/properties/proAvSupport.mjs +11 -0
  309. package/lib/components/ModelCompareV3/data/properties/proAvSupport.mjs.map +1 -0
  310. package/lib/components/ModelCompareV3/data/property-sets/switching.js +6 -4
  311. package/lib/components/ModelCompareV3/data/property-sets/switching.js.map +1 -1
  312. package/lib/components/ModelCompareV3/data/property-sets/switching.mjs +6 -4
  313. package/lib/components/ModelCompareV3/data/property-sets/switching.mjs.map +1 -1
  314. package/lib/components/ModelCompareV3/translations/ar.json.js +3 -0
  315. package/lib/components/ModelCompareV3/translations/ar.json.js.map +1 -1
  316. package/lib/components/ModelCompareV3/translations/ar.json.mjs +3 -0
  317. package/lib/components/ModelCompareV3/translations/ar.json.mjs.map +1 -1
  318. package/lib/components/ModelCompareV3/translations/de.json.js +3 -0
  319. package/lib/components/ModelCompareV3/translations/de.json.js.map +1 -1
  320. package/lib/components/ModelCompareV3/translations/de.json.mjs +3 -0
  321. package/lib/components/ModelCompareV3/translations/de.json.mjs.map +1 -1
  322. package/lib/components/ModelCompareV3/translations/el.json.js +3 -0
  323. package/lib/components/ModelCompareV3/translations/el.json.js.map +1 -1
  324. package/lib/components/ModelCompareV3/translations/el.json.mjs +3 -0
  325. package/lib/components/ModelCompareV3/translations/el.json.mjs.map +1 -1
  326. package/lib/components/ModelCompareV3/translations/en.json.js +3 -0
  327. package/lib/components/ModelCompareV3/translations/en.json.js.map +1 -1
  328. package/lib/components/ModelCompareV3/translations/en.json.mjs +3 -0
  329. package/lib/components/ModelCompareV3/translations/en.json.mjs.map +1 -1
  330. package/lib/components/ModelCompareV3/translations/es.json.js +3 -0
  331. package/lib/components/ModelCompareV3/translations/es.json.js.map +1 -1
  332. package/lib/components/ModelCompareV3/translations/es.json.mjs +3 -0
  333. package/lib/components/ModelCompareV3/translations/es.json.mjs.map +1 -1
  334. package/lib/components/ModelCompareV3/translations/fr.json.js +3 -0
  335. package/lib/components/ModelCompareV3/translations/fr.json.js.map +1 -1
  336. package/lib/components/ModelCompareV3/translations/fr.json.mjs +3 -0
  337. package/lib/components/ModelCompareV3/translations/fr.json.mjs.map +1 -1
  338. package/lib/components/ModelCompareV3/translations/it.json.js +3 -0
  339. package/lib/components/ModelCompareV3/translations/it.json.js.map +1 -1
  340. package/lib/components/ModelCompareV3/translations/it.json.mjs +3 -0
  341. package/lib/components/ModelCompareV3/translations/it.json.mjs.map +1 -1
  342. package/lib/components/ModelCompareV3/translations/ja.json.js +3 -0
  343. package/lib/components/ModelCompareV3/translations/ja.json.js.map +1 -1
  344. package/lib/components/ModelCompareV3/translations/ja.json.mjs +3 -0
  345. package/lib/components/ModelCompareV3/translations/ja.json.mjs.map +1 -1
  346. package/lib/components/ModelCompareV3/translations/pt-BR.json.js +3 -0
  347. package/lib/components/ModelCompareV3/translations/pt-BR.json.js.map +1 -1
  348. package/lib/components/ModelCompareV3/translations/pt-BR.json.mjs +3 -0
  349. package/lib/components/ModelCompareV3/translations/pt-BR.json.mjs.map +1 -1
  350. package/lib/components/ModelCompareV3/translations/useModelCompareTranslation.d.ts +2 -2
  351. package/lib/components/ModelCompareV3/translations/zh-Hans.json.js +3 -0
  352. package/lib/components/ModelCompareV3/translations/zh-Hans.json.js.map +1 -1
  353. package/lib/components/ModelCompareV3/translations/zh-Hans.json.mjs +3 -0
  354. package/lib/components/ModelCompareV3/translations/zh-Hans.json.mjs.map +1 -1
  355. package/lib/components/ModelCompareV3/translations/zh-Hant-TW.json.js +3 -0
  356. package/lib/components/ModelCompareV3/translations/zh-Hant-TW.json.js.map +1 -1
  357. package/lib/components/ModelCompareV3/translations/zh-Hant-TW.json.mjs +3 -0
  358. package/lib/components/ModelCompareV3/translations/zh-Hant-TW.json.mjs.map +1 -1
  359. package/lib/components/ResourceCalculatorV1/ComputeResourceCalculator/ComputeResourceCalculator.constants.js +311 -15
  360. package/lib/components/ResourceCalculatorV1/ComputeResourceCalculator/ComputeResourceCalculator.constants.js.map +1 -1
  361. package/lib/components/ResourceCalculatorV1/ComputeResourceCalculator/ComputeResourceCalculator.constants.mjs +309 -15
  362. package/lib/components/ResourceCalculatorV1/ComputeResourceCalculator/ComputeResourceCalculator.constants.mjs.map +1 -1
  363. package/lib/components/ResourceCalculatorV1/ComputeResourceCalculator/ComputeResourceCalculator.js +38 -22
  364. package/lib/components/ResourceCalculatorV1/ComputeResourceCalculator/ComputeResourceCalculator.js.map +1 -1
  365. package/lib/components/ResourceCalculatorV1/ComputeResourceCalculator/ComputeResourceCalculator.mjs +38 -22
  366. package/lib/components/ResourceCalculatorV1/ComputeResourceCalculator/ComputeResourceCalculator.mjs.map +1 -1
  367. package/lib/components/ResourceCalculatorV1/ComputeResourceCalculator/ComputeResourceCalculator.types.d.ts +10 -2
  368. package/lib/components/ResourceCalculatorV1/ComputeResourceCalculator/ComputeResourceCalculator.types.js +2 -0
  369. package/lib/components/ResourceCalculatorV1/ComputeResourceCalculator/ComputeResourceCalculator.types.js.map +1 -1
  370. package/lib/components/ResourceCalculatorV1/ComputeResourceCalculator/ComputeResourceCalculator.types.mjs +2 -0
  371. package/lib/components/ResourceCalculatorV1/ComputeResourceCalculator/ComputeResourceCalculator.types.mjs.map +1 -1
  372. package/lib/components/ResourceCalculatorV1/ComputeResourceCalculator/components/HddSlots/HddSlots.d.ts +1 -1
  373. package/lib/components/ResourceCalculatorV1/ComputeResourceCalculator/components/HddSlots/HddSlots.js +5 -4
  374. package/lib/components/ResourceCalculatorV1/ComputeResourceCalculator/components/HddSlots/HddSlots.js.map +1 -1
  375. package/lib/components/ResourceCalculatorV1/ComputeResourceCalculator/components/HddSlots/HddSlots.mjs +5 -4
  376. package/lib/components/ResourceCalculatorV1/ComputeResourceCalculator/components/HddSlots/HddSlots.mjs.map +1 -1
  377. package/lib/components/ResourceCalculatorV1/ComputeResourceCalculator/components/InputCard/InputCard.js +2 -2
  378. package/lib/components/ResourceCalculatorV1/ComputeResourceCalculator/components/InputCard/InputCard.js.map +1 -1
  379. package/lib/components/ResourceCalculatorV1/ComputeResourceCalculator/components/InputCard/InputCard.mjs +2 -2
  380. package/lib/components/ResourceCalculatorV1/ComputeResourceCalculator/components/InputCard/InputCard.mjs.map +1 -1
  381. package/lib/components/ResourceCalculatorV1/ComputeResourceCalculator/components/InputCard/InputCard.styles.js +2 -0
  382. package/lib/components/ResourceCalculatorV1/ComputeResourceCalculator/components/InputCard/InputCard.styles.js.map +1 -1
  383. package/lib/components/ResourceCalculatorV1/ComputeResourceCalculator/components/InputCard/InputCard.styles.mjs +2 -0
  384. package/lib/components/ResourceCalculatorV1/ComputeResourceCalculator/components/InputCard/InputCard.styles.mjs.map +1 -1
  385. package/lib/components/ResourceCalculatorV1/ComputeResourceCalculator/components/InputCard/assets/attention.svg.js +1 -1
  386. package/lib/components/ResourceCalculatorV1/ComputeResourceCalculator/components/InputCard/assets/attention.svg.mjs +2 -2
  387. package/lib/components/ResourceCalculatorV1/ComputeResourceCalculator/components/ProgressBarChart/ProgressBarChart.js +1 -1
  388. package/lib/components/ResourceCalculatorV1/ComputeResourceCalculator/components/ProgressBarChart/ProgressBarChart.mjs +1 -1
  389. package/lib/components/ResourceCalculatorV1/ComputeResourceCalculator/components/ProgressBarChart/assets/attention.svg.js +1 -1
  390. package/lib/components/ResourceCalculatorV1/ComputeResourceCalculator/components/ProgressBarChart/assets/attention.svg.mjs +2 -2
  391. package/lib/components/ResourceCalculatorV1/ComputeResourceCalculator/useComputeResourceCalculator.js +1 -1
  392. package/lib/components/ResourceCalculatorV1/ComputeResourceCalculator/useComputeResourceCalculator.js.map +1 -1
  393. package/lib/components/ResourceCalculatorV1/ComputeResourceCalculator/useComputeResourceCalculator.mjs +1 -1
  394. package/lib/components/ResourceCalculatorV1/ComputeResourceCalculator/useComputeResourceCalculator.mjs.map +1 -1
  395. package/lib/components/ResourceCalculatorV1/assets/consoles/efg.png.js +27 -0
  396. package/lib/components/ResourceCalculatorV1/assets/consoles/efg.png.js.map +1 -0
  397. package/lib/components/ResourceCalculatorV1/assets/consoles/efg.png.mjs +3 -0
  398. package/lib/components/ResourceCalculatorV1/assets/consoles/efg.png.mjs.map +1 -0
  399. package/lib/components/ResourceCalculatorV1/assets/consoles/ucg-max.png.js +27 -0
  400. package/lib/components/ResourceCalculatorV1/assets/consoles/ucg-max.png.js.map +1 -0
  401. package/lib/components/ResourceCalculatorV1/assets/consoles/ucg-max.png.mjs +3 -0
  402. package/lib/components/ResourceCalculatorV1/assets/consoles/ucg-max.png.mjs.map +1 -0
  403. package/lib/components/ResourceCalculatorV1/translations/en.json.js +4 -1
  404. package/lib/components/ResourceCalculatorV1/translations/en.json.js.map +1 -1
  405. package/lib/components/ResourceCalculatorV1/translations/en.json.mjs +4 -1
  406. package/lib/components/ResourceCalculatorV1/translations/en.json.mjs.map +1 -1
  407. package/lib/components/ResourceCalculatorV1/translations/useResourceCalculatorTranslation.d.ts +2 -2
  408. package/lib/components/Search/Input/Input.js +1 -1
  409. package/lib/components/Search/Input/Input.mjs +1 -1
  410. package/lib/components/VideoPlayerNew/VideoPlayer.js +1 -1
  411. package/lib/components/VideoPlayerNew/VideoPlayer.mjs +1 -1
  412. package/lib/components/VideoPlayerNew/assets/close.svg.js +1 -1
  413. package/lib/components/VideoPlayerNew/assets/close.svg.mjs +2 -2
  414. package/lib/constants/icons/generic/close.svg.js +1 -1
  415. package/lib/constants/icons/generic/close.svg.mjs +2 -2
  416. package/lib/constants/icons/generic/index.js +1 -1
  417. package/lib/constants/icons/generic/index.mjs +1 -1
  418. package/lib/constants/icons/menu/index.d.ts +1 -0
  419. package/lib/constants/icons/menu/index.js +9 -0
  420. package/lib/constants/icons/menu/index.js.map +1 -1
  421. package/lib/constants/icons/menu/index.mjs +2 -0
  422. package/lib/constants/icons/menu/index.mjs.map +1 -1
  423. package/lib/{components/Explore/assets/MobileR.jpg.js → constants/icons/menu/powerAmp.svg.js} +6 -6
  424. package/lib/constants/icons/menu/powerAmp.svg.js.map +1 -0
  425. package/lib/constants/icons/menu/powerAmp.svg.mjs +3 -0
  426. package/lib/constants/icons/menu/powerAmp.svg.mjs.map +1 -0
  427. package/lib/constants/keyFeatureIcons.d.ts +2 -0
  428. package/lib/constants/keyFeatureIcons.js +6 -0
  429. package/lib/constants/keyFeatureIcons.js.map +1 -1
  430. package/lib/constants/keyFeatureIcons.mjs +6 -0
  431. package/lib/constants/keyFeatureIcons.mjs.map +1 -1
  432. package/lib/constants/proStoreCategories/mapping/index.d.ts +3 -1
  433. package/lib/constants/proStoreCategories/mapping/index.js +18 -8
  434. package/lib/constants/proStoreCategories/mapping/index.js.map +1 -1
  435. package/lib/constants/proStoreCategories/mapping/index.mjs +18 -8
  436. package/lib/constants/proStoreCategories/mapping/index.mjs.map +1 -1
  437. package/lib/constants/proStoreCategories/mapping/redirects.js +8 -1
  438. package/lib/constants/proStoreCategories/mapping/redirects.js.map +1 -1
  439. package/lib/constants/proStoreCategories/mapping/redirects.mjs +8 -1
  440. package/lib/constants/proStoreCategories/mapping/redirects.mjs.map +1 -1
  441. package/lib/constants/proStoreCategories/mapping/unifi.d.ts +4 -2
  442. package/lib/constants/proStoreCategories/mapping/unifi.js +3 -1
  443. package/lib/constants/proStoreCategories/mapping/unifi.js.map +1 -1
  444. package/lib/constants/proStoreCategories/mapping/unifi.mjs +3 -1
  445. package/lib/constants/proStoreCategories/mapping/unifi.mjs.map +1 -1
  446. package/lib/constants/proStoreCategories/translations/ar.json.js +3 -2
  447. package/lib/constants/proStoreCategories/translations/ar.json.js.map +1 -1
  448. package/lib/constants/proStoreCategories/translations/ar.json.mjs +3 -2
  449. package/lib/constants/proStoreCategories/translations/ar.json.mjs.map +1 -1
  450. package/lib/constants/proStoreCategories/translations/de.json.js +3 -2
  451. package/lib/constants/proStoreCategories/translations/de.json.js.map +1 -1
  452. package/lib/constants/proStoreCategories/translations/de.json.mjs +3 -2
  453. package/lib/constants/proStoreCategories/translations/de.json.mjs.map +1 -1
  454. package/lib/constants/proStoreCategories/translations/el.json.js +3 -2
  455. package/lib/constants/proStoreCategories/translations/el.json.js.map +1 -1
  456. package/lib/constants/proStoreCategories/translations/el.json.mjs +3 -2
  457. package/lib/constants/proStoreCategories/translations/el.json.mjs.map +1 -1
  458. package/lib/constants/proStoreCategories/translations/en.json.js +5 -1
  459. package/lib/constants/proStoreCategories/translations/en.json.js.map +1 -1
  460. package/lib/constants/proStoreCategories/translations/en.json.mjs +5 -2
  461. package/lib/constants/proStoreCategories/translations/en.json.mjs.map +1 -1
  462. package/lib/constants/proStoreCategories/translations/es.json.js +3 -2
  463. package/lib/constants/proStoreCategories/translations/es.json.js.map +1 -1
  464. package/lib/constants/proStoreCategories/translations/es.json.mjs +3 -2
  465. package/lib/constants/proStoreCategories/translations/es.json.mjs.map +1 -1
  466. package/lib/constants/proStoreCategories/translations/fr.json.js +4 -3
  467. package/lib/constants/proStoreCategories/translations/fr.json.js.map +1 -1
  468. package/lib/constants/proStoreCategories/translations/fr.json.mjs +4 -3
  469. package/lib/constants/proStoreCategories/translations/fr.json.mjs.map +1 -1
  470. package/lib/constants/proStoreCategories/translations/it.json.js +3 -2
  471. package/lib/constants/proStoreCategories/translations/it.json.js.map +1 -1
  472. package/lib/constants/proStoreCategories/translations/it.json.mjs +3 -2
  473. package/lib/constants/proStoreCategories/translations/it.json.mjs.map +1 -1
  474. package/lib/constants/proStoreCategories/translations/ja.json.js +3 -2
  475. package/lib/constants/proStoreCategories/translations/ja.json.js.map +1 -1
  476. package/lib/constants/proStoreCategories/translations/ja.json.mjs +3 -2
  477. package/lib/constants/proStoreCategories/translations/ja.json.mjs.map +1 -1
  478. package/lib/constants/proStoreCategories/translations/pt-BR.json.js +3 -2
  479. package/lib/constants/proStoreCategories/translations/pt-BR.json.js.map +1 -1
  480. package/lib/constants/proStoreCategories/translations/pt-BR.json.mjs +3 -2
  481. package/lib/constants/proStoreCategories/translations/pt-BR.json.mjs.map +1 -1
  482. package/lib/constants/proStoreCategories/translations/zh-Hans.json.js +4 -3
  483. package/lib/constants/proStoreCategories/translations/zh-Hans.json.js.map +1 -1
  484. package/lib/constants/proStoreCategories/translations/zh-Hans.json.mjs +4 -3
  485. package/lib/constants/proStoreCategories/translations/zh-Hans.json.mjs.map +1 -1
  486. package/lib/constants/proStoreCategories/translations/zh-Hant-TW.json.js +4 -3
  487. package/lib/constants/proStoreCategories/translations/zh-Hant-TW.json.js.map +1 -1
  488. package/lib/constants/proStoreCategories/translations/zh-Hant-TW.json.mjs +4 -3
  489. package/lib/constants/proStoreCategories/translations/zh-Hant-TW.json.mjs.map +1 -1
  490. package/lib/constants/shopify/keyFeatureIcons.js +8 -0
  491. package/lib/constants/shopify/keyFeatureIcons.js.map +1 -1
  492. package/lib/constants/shopify/keyFeatureIcons.mjs +6 -0
  493. package/lib/constants/shopify/keyFeatureIcons.mjs.map +1 -1
  494. package/lib/contexts/MenuContext/context.js +1 -1
  495. package/lib/contexts/MenuContext/context.js.map +1 -1
  496. package/lib/contexts/MenuContext/context.mjs +1 -1
  497. package/lib/contexts/MenuContext/context.mjs.map +1 -1
  498. package/lib/contexts/MenuContext/mapping.d.ts +3 -3
  499. package/lib/contexts/MenuContext/mapping.js +21 -7
  500. package/lib/contexts/MenuContext/mapping.js.map +1 -1
  501. package/lib/contexts/MenuContext/mapping.mjs +20 -7
  502. package/lib/contexts/MenuContext/mapping.mjs.map +1 -1
  503. package/lib/contexts/MenuContext/presets.d.ts +11 -4
  504. package/lib/contexts/MenuContext/presets.js +16 -12
  505. package/lib/contexts/MenuContext/presets.js.map +1 -1
  506. package/lib/contexts/MenuContext/presets.mjs +13 -13
  507. package/lib/contexts/MenuContext/presets.mjs.map +1 -1
  508. package/lib/contexts/MenuContext/types.d.ts +1 -1
  509. package/lib/contexts/MenuContext/types.js.map +1 -1
  510. package/lib/contexts/MenuContext/types.mjs.map +1 -1
  511. package/lib/contexts/MenuContext/utils.js +5 -1
  512. package/lib/contexts/MenuContext/utils.js.map +1 -1
  513. package/lib/contexts/MenuContext/utils.mjs +5 -1
  514. package/lib/contexts/MenuContext/utils.mjs.map +1 -1
  515. package/lib/helpers/index.d.ts +1 -0
  516. package/lib/helpers/index.js +11 -0
  517. package/lib/helpers/index.js.map +1 -1
  518. package/lib/helpers/index.mjs +1 -0
  519. package/lib/helpers/index.mjs.map +1 -1
  520. package/lib/helpers/product.d.ts +87 -0
  521. package/lib/helpers/product.js +346 -0
  522. package/lib/helpers/product.js.map +1 -0
  523. package/lib/helpers/product.mjs +335 -0
  524. package/lib/helpers/product.mjs.map +1 -0
  525. package/lib/types/index.d.ts +1 -0
  526. package/lib/types/index.js +2 -0
  527. package/lib/types/index.js.map +1 -1
  528. package/lib/types/index.mjs +1 -0
  529. package/lib/types/index.mjs.map +1 -1
  530. package/lib/types/product.d.ts +87 -0
  531. package/lib/types/product.js +14 -0
  532. package/lib/types/product.js.map +1 -0
  533. package/lib/types/product.mjs +13 -0
  534. package/lib/types/product.mjs.map +1 -0
  535. package/lib/utils/array.d.ts +4 -0
  536. package/lib/utils/array.js +10 -0
  537. package/lib/utils/array.js.map +1 -1
  538. package/lib/utils/array.mjs +10 -1
  539. package/lib/utils/array.mjs.map +1 -1
  540. package/lib/utils/money/allocators/fixedAmount.d.ts +26 -0
  541. package/lib/utils/money/allocators/fixedAmount.js +55 -0
  542. package/lib/utils/money/allocators/fixedAmount.js.map +1 -0
  543. package/lib/utils/money/allocators/fixedAmount.mjs +53 -0
  544. package/lib/utils/money/allocators/fixedAmount.mjs.map +1 -0
  545. package/lib/utils/money/allocators/index.d.ts +2 -0
  546. package/lib/utils/money/allocators/index.js +8 -0
  547. package/lib/utils/money/allocators/index.js.map +1 -0
  548. package/lib/utils/money/allocators/index.mjs +4 -0
  549. package/lib/utils/money/allocators/index.mjs.map +1 -0
  550. package/lib/utils/money/allocators/productAmount.d.ts +13 -0
  551. package/lib/utils/money/allocators/productAmount.js +110 -0
  552. package/lib/utils/money/allocators/productAmount.js.map +1 -0
  553. package/lib/utils/money/allocators/productAmount.mjs +108 -0
  554. package/lib/utils/money/allocators/productAmount.mjs.map +1 -0
  555. package/lib/utils/money/constants.d.ts +56 -25
  556. package/lib/utils/money/constants.js +72 -7
  557. package/lib/utils/money/constants.js.map +1 -1
  558. package/lib/utils/money/constants.mjs +70 -7
  559. package/lib/utils/money/constants.mjs.map +1 -1
  560. package/lib/utils/money/exchangeRate.d.ts +31 -0
  561. package/lib/utils/money/exchangeRate.js +27 -0
  562. package/lib/utils/money/exchangeRate.js.map +1 -0
  563. package/lib/utils/money/exchangeRate.mjs +23 -0
  564. package/lib/utils/money/exchangeRate.mjs.map +1 -0
  565. package/lib/utils/money/format.d.ts +10 -5
  566. package/lib/utils/money/format.js +22 -14
  567. package/lib/utils/money/format.js.map +1 -1
  568. package/lib/utils/money/format.mjs +23 -16
  569. package/lib/utils/money/format.mjs.map +1 -1
  570. package/lib/utils/money/index.d.ts +4 -1
  571. package/lib/utils/money/index.js +26 -8
  572. package/lib/utils/money/index.js.map +1 -1
  573. package/lib/utils/money/index.mjs +8 -4
  574. package/lib/utils/money/index.mjs.map +1 -1
  575. package/lib/utils/money/misc.d.ts +68 -28
  576. package/lib/utils/money/misc.js +35 -64
  577. package/lib/utils/money/misc.js.map +1 -1
  578. package/lib/utils/money/misc.mjs +32 -43
  579. package/lib/utils/money/misc.mjs.map +1 -1
  580. package/lib/utils/money/misc.private.d.ts +23 -0
  581. package/lib/utils/money/misc.private.js +46 -0
  582. package/lib/utils/money/misc.private.js.map +1 -0
  583. package/lib/utils/money/misc.private.mjs +21 -0
  584. package/lib/utils/money/misc.private.mjs.map +1 -0
  585. package/lib/utils/money/shipping.d.ts +5 -0
  586. package/lib/utils/money/shipping.js +8 -0
  587. package/lib/utils/money/shipping.js.map +1 -0
  588. package/lib/utils/money/shipping.mjs +6 -0
  589. package/lib/utils/money/shipping.mjs.map +1 -0
  590. package/lib/utils/money/tax.d.ts +38 -2
  591. package/lib/utils/money/tax.js +46 -10
  592. package/lib/utils/money/tax.js.map +1 -1
  593. package/lib/utils/money/tax.mjs +42 -11
  594. package/lib/utils/money/tax.mjs.map +1 -1
  595. package/lib/utils/money/tax.private.d.ts +17 -0
  596. package/lib/utils/money/tax.private.js +65 -0
  597. package/lib/utils/money/tax.private.js.map +1 -0
  598. package/lib/utils/money/tax.private.mjs +60 -0
  599. package/lib/utils/money/tax.private.mjs.map +1 -0
  600. package/lib/utils/money/types.d.ts +78 -3
  601. package/lib/utils/nextjs/navigationPresets.d.ts +5 -3
  602. package/lib/utils/nextjs/navigationPresets.js +13 -7
  603. package/lib/utils/nextjs/navigationPresets.js.map +1 -1
  604. package/lib/utils/nextjs/navigationPresets.mjs +14 -8
  605. package/lib/utils/nextjs/navigationPresets.mjs.map +1 -1
  606. package/lib/utils/number.d.ts +1 -1
  607. package/lib/utils/number.js +1 -1
  608. package/lib/utils/number.js.map +1 -1
  609. package/lib/utils/number.mjs +1 -1
  610. package/lib/utils/number.mjs.map +1 -1
  611. package/lib/utils/productSort.d.ts +41 -0
  612. package/lib/utils/productSort.js +66 -0
  613. package/lib/utils/productSort.js.map +1 -0
  614. package/lib/utils/productSort.mjs +59 -0
  615. package/lib/utils/productSort.mjs.map +1 -0
  616. package/package.json +1 -1
  617. package/lib/assets/AITheta.jpg +0 -0
  618. package/lib/assets/MobileR.jpg +0 -0
  619. package/lib/assets/ProAV.jpg +0 -0
  620. package/lib/assets/ai3602.jpg +0 -0
  621. package/lib/assets/cloudgatewayultra.jpg +0 -0
  622. package/lib/assets/dreamRouter.jpg +0 -0
  623. package/lib/assets/dreamWall.jpg +0 -0
  624. package/lib/assets/g5-ptz2.jpg +0 -0
  625. package/lib/assets/wideAngle2.jpg +0 -0
  626. package/lib/components/Explore/LensCompare/LensCompare.d.ts +0 -2
  627. package/lib/components/Explore/LensCompare/LensCompare.js +0 -111
  628. package/lib/components/Explore/LensCompare/LensCompare.js.map +0 -1
  629. package/lib/components/Explore/LensCompare/LensCompare.mjs +0 -109
  630. package/lib/components/Explore/LensCompare/LensCompare.mjs.map +0 -1
  631. package/lib/components/Explore/LensCompare/LensCompare.styles.d.ts +0 -16
  632. package/lib/components/Explore/LensCompare/LensCompare.styles.js +0 -153
  633. package/lib/components/Explore/LensCompare/LensCompare.styles.js.map +0 -1
  634. package/lib/components/Explore/LensCompare/LensCompare.styles.mjs +0 -132
  635. package/lib/components/Explore/LensCompare/LensCompare.styles.mjs.map +0 -1
  636. package/lib/components/Explore/LensCompare/LensCompare.types.d.ts +0 -9
  637. package/lib/components/Explore/LensCompare/LensCompare.utils.d.ts +0 -2
  638. package/lib/components/Explore/LensCompare/LensCompare.utils.js +0 -23
  639. package/lib/components/Explore/LensCompare/LensCompare.utils.js.map +0 -1
  640. package/lib/components/Explore/LensCompare/LensCompare.utils.mjs +0 -21
  641. package/lib/components/Explore/LensCompare/LensCompare.utils.mjs.map +0 -1
  642. package/lib/components/Explore/LensCompare/LensCompareData.d.ts +0 -29
  643. package/lib/components/Explore/LensCompare/LensCompareData.js +0 -68
  644. package/lib/components/Explore/LensCompare/LensCompareData.js.map +0 -1
  645. package/lib/components/Explore/LensCompare/LensCompareData.mjs +0 -58
  646. package/lib/components/Explore/LensCompare/LensCompareData.mjs.map +0 -1
  647. package/lib/components/Explore/LensCompare/assets/ai360.jpg.js.map +0 -1
  648. package/lib/components/Explore/LensCompare/assets/ai360.jpg.mjs +0 -3
  649. package/lib/components/Explore/LensCompare/assets/ai360.jpg.mjs.map +0 -1
  650. package/lib/components/Explore/LensCompare/assets/wideAngle.jpg.js +0 -27
  651. package/lib/components/Explore/LensCompare/assets/wideAngle.jpg.js.map +0 -1
  652. package/lib/components/Explore/LensCompare/assets/wideAngle.jpg.mjs +0 -3
  653. package/lib/components/Explore/LensCompare/assets/wideAngle.jpg.mjs.map +0 -1
  654. package/lib/components/Explore/assets/AITheta.jpg.js.map +0 -1
  655. package/lib/components/Explore/assets/AITheta.jpg.mjs +0 -3
  656. package/lib/components/Explore/assets/AITheta.jpg.mjs.map +0 -1
  657. package/lib/components/Explore/assets/MobileR.jpg.js.map +0 -1
  658. package/lib/components/Explore/assets/MobileR.jpg.mjs +0 -3
  659. package/lib/components/Explore/assets/MobileR.jpg.mjs.map +0 -1
  660. package/lib/components/Explore/assets/ProAV.jpg.js.map +0 -1
  661. package/lib/components/Explore/assets/ProAV.jpg.mjs +0 -3
  662. package/lib/components/Explore/assets/ProAV.jpg.mjs.map +0 -1
  663. package/lib/components/Explore/assets/baseStation-mobile.jpg.js.map +0 -1
  664. package/lib/components/Explore/assets/baseStation-mobile.jpg.mjs +0 -3
  665. package/lib/components/Explore/assets/baseStation-mobile.jpg.mjs.map +0 -1
  666. package/lib/components/Explore/assets/cloudgatewayultra.jpg.js +0 -27
  667. package/lib/components/Explore/assets/cloudgatewayultra.jpg.js.map +0 -1
  668. package/lib/components/Explore/assets/cloudgatewayultra.jpg.mjs +0 -3
  669. package/lib/components/Explore/assets/cloudgatewayultra.jpg.mjs.map +0 -1
  670. package/lib/components/Explore/assets/dreamRouter.jpg.js +0 -27
  671. package/lib/components/Explore/assets/dreamRouter.jpg.js.map +0 -1
  672. package/lib/components/Explore/assets/dreamRouter.jpg.mjs +0 -3
  673. package/lib/components/Explore/assets/dreamRouter.jpg.mjs.map +0 -1
  674. package/lib/components/Explore/assets/dreamWall.jpg.js +0 -27
  675. package/lib/components/Explore/assets/dreamWall.jpg.js.map +0 -1
  676. package/lib/components/Explore/assets/dreamWall.jpg.mjs +0 -3
  677. package/lib/components/Explore/assets/dreamWall.jpg.mjs.map +0 -1
  678. package/lib/components/Explore/assets/g4-ptz.jpg.js.map +0 -1
  679. package/lib/components/Explore/assets/g4-ptz.jpg.mjs +0 -3
  680. package/lib/components/Explore/assets/g4-ptz.jpg.mjs.map +0 -1
  681. package/lib/components/Explore/assets/g5-ptz.jpg.js.map +0 -1
  682. package/lib/components/Explore/assets/g5-ptz.jpg.mjs +0 -3
  683. package/lib/components/Explore/assets/g5-ptz.jpg.mjs.map +0 -1
  684. package/lib/components/Explore/assets/unifiExpress.jpg.js +0 -27
  685. package/lib/components/Explore/assets/unifiExpress.jpg.js.map +0 -1
  686. package/lib/components/Explore/assets/unifiExpress.jpg.mjs +0 -3
  687. package/lib/components/Explore/assets/unifiExpress.jpg.mjs.map +0 -1
  688. package/lib/utils/validations.d.ts +0 -15
  689. package/lib/utils/validations.js +0 -23
  690. package/lib/utils/validations.js.map +0 -1
  691. package/lib/utils/validations.mjs +0 -21
  692. package/lib/utils/validations.mjs.map +0 -1
  693. /package/lib/assets/{baseStation-mobile.jpg → baseStation--mobile.jpg} +0 -0
  694. /package/lib/assets/{g4-ptz.jpg → g4Ptz.jpg} +0 -0
  695. /package/lib/assets/{unifiExpress.jpg → ux.jpg} +0 -0
@@ -1,34 +1,12 @@
1
- import * as currencies from '@dinero.js/currencies';
2
- import { hasSubUnits, toUnit, down, dinero, toSnapshot, multiply, transformScale, add, subtract } from 'dinero.js';
1
+ import { hasSubUnits, dinero, toUnit, toSnapshot, multiply, transformScale, add, subtract } from 'dinero.js';
3
2
  import '../../types/index.mjs';
4
3
  import { assert } from '../errors.mjs';
5
- import { isFloat } from '../number.mjs';
4
+ import { isFloat, isInt } from '../number.mjs';
6
5
  import { capitalize } from '../string.mjs';
7
- import { isInt } from '../validations.mjs';
8
- import { financialRound, prettifyPriceLookup, smallestSubunitLookup } from './constants.mjs';
6
+ import { smallestSubunitLookup } from './constants.mjs';
7
+ import { dineroCurrenciesLookup, currencyLookup, floatToInt } from './misc.private.mjs';
9
8
  import { Currency } from '../../types/generated.mjs';
10
9
  "use strict";
11
- const currencyLookup = new Set(Object.keys(Currency).map(el => el.toString()));
12
- const currenciesMap = new Map(Object.values(currencies).map(currency2 => [currency2.code, currency2]));
13
- const floatToInt = (floatAmount, base, exponent) => financialRound(floatAmount * Math.pow(base, exponent));
14
- const prettifyTotal = total => {
15
- if (!hasSubUnits(total)) {
16
- return total;
17
- }
18
- const totalJson = total.toJSON();
19
- const minValueInclusiveToRoundDownFrom = prettifyPriceLookup.get(totalJson.currency.code);
20
- if (minValueInclusiveToRoundDownFrom == null || toUnit(total) < minValueInclusiveToRoundDownFrom) {
21
- return total;
22
- }
23
- const roundedUnitPrice = toUnit(total, {
24
- digits: 0,
25
- round: down
26
- });
27
- return dinero({
28
- amount: roundedUnitPrice * Math.pow(totalJson.currency.base, totalJson.currency.exponent),
29
- currency: totalJson.currency
30
- });
31
- };
32
10
  const toSmallestSubunit = total => {
33
11
  if (!hasSubUnits(total)) {
34
12
  return total;
@@ -38,17 +16,10 @@ const toSmallestSubunit = total => {
38
16
  if (roundToDigits == null || roundingMode == null) {
39
17
  return total;
40
18
  }
41
- const roundedUnitPrice = toUnit(total, {
42
- digits: roundToDigits,
43
- round: roundingMode
44
- });
45
- return dinero({
46
- amount: roundedUnitPrice * Math.pow(totalJson.currency.base, totalJson.currency.exponent),
47
- currency: totalJson.currency
48
- });
19
+ return roundDinero(total, roundingMode);
49
20
  };
50
21
  const getDineroCurrency = currency2 => {
51
- const dineroCurrency = currenciesMap.get(currency2);
22
+ const dineroCurrency = dineroCurrenciesLookup.get(currency2);
52
23
  assert(!!dineroCurrency, `Unsupported currency: "${currency2}"`);
53
24
  return dineroCurrency;
54
25
  };
@@ -57,18 +28,23 @@ const parseCurrencyCode = code => {
57
28
  assert(currencyLookup.has(normalizedCode), `Invalid currency code: ${normalizedCode}`);
58
29
  return Currency[normalizedCode];
59
30
  };
60
- const centsToMajorUnits = (amount2, currency2) => {
31
+ const centsToCurrencyUnit = (centsAmount, currency2) => {
61
32
  const dineroCurrency = getDineroCurrency(currency2);
62
- const price = dinero({
63
- amount: amount2,
33
+ const dineroObj = dinero({
34
+ amount: centsAmount,
64
35
  currency: dineroCurrency
65
36
  });
66
- const divider = Math.pow(10, dineroCurrency.exponent);
67
- return toSnapshot(price).amount / divider;
37
+ return dineroToCurrencyUnit(dineroObj);
38
+ };
39
+ const dineroToCurrencyUnit = dineroObj => {
40
+ return toUnit(dineroObj);
68
41
  };
69
42
  const parseFloatToDinero = (floatAmount, currency2) => {
70
- isFloat(floatAmount, "Amount");
71
43
  const dineroCurrency = getDineroCurrency(currency2);
44
+ return parseFloatToDineroRaw(floatAmount, dineroCurrency);
45
+ };
46
+ const parseFloatToDineroRaw = (floatAmount, dineroCurrency) => {
47
+ isFloat(floatAmount, "Amount");
72
48
  const scaleOfGivenAmount = String(floatAmount).split(".")[1]?.length ?? dineroCurrency.exponent;
73
49
  if (scaleOfGivenAmount == null || scaleOfGivenAmount > dineroCurrency.exponent) {
74
50
  throw new Error(`scaleOfGivenAmount is unsupported ${scaleOfGivenAmount}`);
@@ -112,6 +88,19 @@ const money = dinero2 => {
112
88
  };
113
89
  const addMany = (addends, defaultCurrency) => [...addends, getDinero(0, defaultCurrency)].reduce(add);
114
90
  const subtractMany = (subtractions, defaultCurrency) => [...subtractions, getDinero(0, defaultCurrency)].reduce(subtract);
115
- const stringAmountToDinero = (price, currency2) => parseFloatToDinero(parseFloat(price), currency2);
116
- export { addMany, amount, centsToMajorUnits, currency, getDinero, getDineroCurrency, money, multiplyByFullPercent, parseCurrencyCode, parseFloatToDinero, prettifyTotal, stringAmountToDinero, subtractMany, toSmallestSubunit };
91
+ const stringAmountToDinero = (price, currency2) =>
92
+ // FIXME: parseFloat seems dangerous O_O
93
+ parseFloatToDinero(parseFloat(price), currency2);
94
+ const roundDinero = (dinero2, roundingFn) => {
95
+ const roundedUnitPrice = toUnit(dinero2, {
96
+ digits: 0,
97
+ round: roundingFn
98
+ });
99
+ const snapshot = toSnapshot(dinero2);
100
+ return dinero2.create({
101
+ amount: roundedUnitPrice * snapshot.currency.base ** snapshot.currency.exponent,
102
+ currency: snapshot.currency
103
+ });
104
+ };
105
+ export { addMany, amount, centsToCurrencyUnit, currency, dineroToCurrencyUnit, getDinero, getDineroCurrency, money, multiplyByFullPercent, parseCurrencyCode, parseFloatToDinero, parseFloatToDineroRaw, roundDinero, stringAmountToDinero, subtractMany, toSmallestSubunit };
117
106
  //# sourceMappingURL=misc.mjs.map
@@ -1 +1 @@
1
- {"version":3,"file":"misc.mjs","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,QAAQ,CAAA,CAAEC,IAAKC,EAAA,IAAOA,EAAG,CAAAC,QAAA,EAAU,CACjD,CAAA;AAMA,MAAMC,gBAAgB,IAAIC,GAAA,CACxBP,MAAA,CAAOQ,MAAO,CAAAC,UAAU,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,cAAe,CAAAH,WAAA,GAAcI,IAAK,CAAAC,GAAA,CAAIJ,IAAM,EAAAC,QAAQ,CAAC,CAAA;AAUrD,MAAAI,aAAA,GAAiBC,KAA0C,IAAA;EAElE,IAAA,CAACC,WAAY,CAAAD,KAAK,CAAG,EAAA;IAChB,OAAAA,KAAA;EACT;EAEM,MAAAE,SAAA,GAAYF,MAAMG,MAAO,EAAA;EAE/B,MAAMC,mCAAmCC,mBAAoB,CAAAC,GAAA,CAC3DJ,UAAUZ,QAAS,CAAAC,IAAA,CACrB;EAGA,IACEa,gCAAoC,IAAA,IAAA,IACpCG,MAAO,CAAAP,KAAK,IAAII,gCAChB,EAAA;IACO,OAAAJ,KAAA;EACT;EAEM,MAAAQ,gBAAA,GAAmBD,OAAOP,KAAO,EAAA;IAAES,QAAQ,CAAG;IAAAC,KAAA,EAAOC;GAAM,CAAA;EAEjE,OAAOC,MAAO,CAAA;IACZC,MAAA,EAC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AA,KACG,CAAC,GAAGI,YAAc,EAAAf,SAAA,CAAU,CAAG,EAAAW,eAAe,CAAC,CAAA,CAAEC,OAAOI,QAAQ,CAAA;AAKxD,MAAAC,oBAAA,GAAuBA,CAAC5B,KAAerC,EAAAA,SAAAA,KAClDwC,mBAAmB0B,UAAW,CAAA7B,KAAK,GAAGrC,SAAQ,CAAA;"}
1
+ {"version":3,"file":"misc.mjs","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,WAAY,CAAAD,KAAK,CAAG,EAAA;IAChB,OAAAA,KAAA;EACT;EAEM,MAAAE,SAAA,GAAYF,MAAMG,MAAO,EAAA;EAEzB,MAAA,CAACC,aAAe,EAAAC,YAAY,CAChC,GAAAC,qBAAA,CAAsBC,IAAIL,SAAU,CAAAM,QAAA,CAASC,IAAI,CAAA,IAAK,EAAC;EAErD,IAAAL,aAAA,IAAiB,IAAQ,IAAAC,YAAA,IAAgB,IAAM,EAAA;IAC1C,OAAAL,KAA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fast lookup for our custom currency enum to check that given currency is valid
5
+ */
6
+ export declare const currencyLookup: Set<string>;
7
+ /**
8
+ * Dinero currency lookup to check that given currency is valid
9
+ */
10
+ export declare const dineroCurrenciesLookup: Map<string, currencies.Currency<number>>;
11
+ /**
12
+ * Private util to convert a float value into a int. Also applies financial rounding to the value if needed.
13
+ * Inspired by https://v2.dinerojs.com/docs/faq/how-can-i-create-dinero-objects-from-floats
14
+ * @example
15
+ * floatToInt(69.10, 10, 2); // 6910
16
+ * floatToInt(42, 10, 2); // 4200
17
+ * floatToInt(0.22, 10, 6); // 220000
18
+ */
19
+ export declare const floatToInt: (floatAmount: number, base: number, exponent: number) => number;
20
+ /**
21
+ * FIXME: is it private tho?!
22
+ */
23
+ export declare const decimalToDinero: (decimalAmount: string | number, currency: DinoCurrency) => import("dinero.js").Dinero<number>;
@@ -0,0 +1,46 @@
1
+ 'use strict';
2
+
3
+ var currencies = require('@dinero.js/currencies');
4
+ var dinero_js = require('dinero.js');
5
+ require('../../types/index.js');
6
+ var number = require('../number.js');
7
+ var constants = require('./constants.js');
8
+ var generated = require('../../types/generated.js');
9
+ function _interopNamespace(e) {
10
+ if (e && e.__esModule) return e;
11
+ var n = Object.create(null);
12
+ if (e) {
13
+ Object.keys(e).forEach(function (k) {
14
+ if (k !== 'default') {
15
+ var d = Object.getOwnPropertyDescriptor(e, k);
16
+ Object.defineProperty(n, k, d.get ? d : {
17
+ enumerable: true,
18
+ get: function () {
19
+ return e[k];
20
+ }
21
+ });
22
+ }
23
+ });
24
+ }
25
+ n["default"] = e;
26
+ return Object.freeze(n);
27
+ }
28
+ var currencies__namespace = /*#__PURE__*/_interopNamespace(currencies);
29
+ "use strict";
30
+ const currencyLookup = new Set(Object.keys(generated.Currency).map(el => el.toString()));
31
+ const dineroCurrenciesLookup = new Map(Object.values(currencies__namespace).map(currency => [currency.code, currency]));
32
+ const floatToInt = (floatAmount, base, exponent) => constants.Round.Financial(floatAmount * Math.pow(base, exponent));
33
+ const decimalToDinero = (decimalAmount, currency) => {
34
+ const parsedNumber = typeof decimalAmount === "number" ? decimalAmount : Number.parseFloat(decimalAmount);
35
+ number.isFloat(parsedNumber);
36
+ const parsedNumberInt = Number.parseInt((parsedNumber * Math.pow(10, currency.exponent)).toFixed(0));
37
+ return dinero_js.dinero({
38
+ amount: parsedNumberInt,
39
+ currency
40
+ });
41
+ };
42
+ exports.currencyLookup = currencyLookup;
43
+ exports.decimalToDinero = decimalToDinero;
44
+ exports.dineroCurrenciesLookup = dineroCurrenciesLookup;
45
+ exports.floatToInt = floatToInt;
46
+ //# sourceMappingURL=misc.private.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"misc.private.js","sources":["../../../src/utils/money/misc.private.ts"],"sourcesContent":["// #############################################################################\n// Internal helper functions not for consumption outside of store.core!\n// Wrote as separate files so that they can be easily unit tested without exposing them\n// #############################################################################\nimport * as currencies from \"@dinero.js/currencies\";\nimport { dinero } from \"dinero.js\";\n\nimport { Currency } from \"../../types\";\nimport { isFloat } from \"../number\";\nimport { Round } from \"./constants\";\nimport type { DinoCurrency } from \"./types\";\n\n/**\n * Fast lookup for our custom currency enum to check that given currency is valid\n */\nexport const currencyLookup = new Set(\n Object.keys(Currency).map((el) => el.toString()),\n);\n\n/**\n * Dinero currency lookup to check that given currency is valid\n */\nexport const dineroCurrenciesLookup = 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 * @example\n * floatToInt(69.10, 10, 2); // 6910\n * floatToInt(42, 10, 2); // 4200\n * floatToInt(0.22, 10, 6); // 220000\n */\nexport const floatToInt = (\n floatAmount: number,\n base: number,\n exponent: number,\n // FIXME: pass in the rounding method and or use roundDinero\n): number => Round.Financial(floatAmount * Math.pow(base, exponent));\n\n/**\n * FIXME: is it private tho?!\n */\nexport const decimalToDinero = (\n decimalAmount: string | number,\n currency: DinoCurrency,\n // FIXME: rounding method?!\n) => {\n const parsedNumber =\n typeof decimalAmount === \"number\"\n ? decimalAmount\n : Number.parseFloat(decimalAmount);\n isFloat(parsedNumber);\n\n const parsedNumberInt = Number.parseInt(\n (parsedNumber * Math.pow(10, currency.exponent)).toFixed(0),\n );\n return dinero({\n amount: parsedNumberInt,\n currency,\n });\n};\n"],"names":["currencyLookup","Set","Object","keys","Currency","map","el","toString","dineroCurrenciesLookup","Map","values","currencies","currency","code","floatToInt","floatAmount","base","exponent","Round","Financial","Math","pow","decimalToDinero","decimalAmount","parsedNumber","Number","parseFloat","isFloat","parsedNumberInt","parseInt","toFixed","dinero","amount"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAeO,MAAMA,iBAAiB,IAAIC,GAAA,CAChCC,MAAA,CAAOC,KAAKC,SAAAA,CAAAA,QAAQ,CAAA,CAAEC,IAAKC,EAAA,IAAOA,EAAG,CAAAC,QAAA,EAAU,CACjD,CAAA;AAKO,MAAMC,yBAAyB,IAAIC,GAAA,CACxCP,MAAA,CAAOQ,MAAO,CAAAC,qBAAU,CAAE,CAAAN,GAAA,CAAKO,QAAA,IAAa,CAACA,QAAA,CAASC,IAAM,EAAAD,QAAQ,CAAC,CACvE,CAAA;AAUO,MAAME,UAAa,GAAAA,CACxBC,WACA,EAAAC,IAAA,EACAC,QAEW,KAAAC,SAAA,CAAAA,KAAA,CAAMC,SAAU,CAAAJ,WAAA,GAAcK,IAAK,CAAAC,GAAA,CAAIL,IAAM,EAAAC,QAAQ,CAAC,CAAA;AAKtD,MAAAK,eAAA,GAAkBA,CAC7BC,aAAA,EACAX,QAEG,KAAA;EACH,MAAMY,eACJ,OAAOD,aAAA,KAAkB,WACrBA,aACA,GAAAE,MAAA,CAAOC,WAAWH,aAAa,CAAA;EACrCI,MAAA,CAAAA,OAAA,CAAQH,YAAY,CAAA;EAEpB,MAAMI,kBAAkBH,MAAO,CAAAI,QAAA,CAC5B,CAAAL,YAAA,GAAeJ,KAAKC,GAAI,CAAA,EAAA,EAAIT,SAASK,QAAQ,CAAA,EAAGa,QAAQ,CAAC,CAAA,CAC5D;EACA,OAAOC,gBAAO,CAAA;IACZC,MAAQ,EAAAJ,eAAA;IACRhB;EAAA,CACD,CAAA;AACH,CAAA;;;;"}
@@ -0,0 +1,21 @@
1
+ import * as currencies from '@dinero.js/currencies';
2
+ import { dinero } from 'dinero.js';
3
+ import '../../types/index.mjs';
4
+ import { isFloat } from '../number.mjs';
5
+ import { Round } from './constants.mjs';
6
+ import { Currency } from '../../types/generated.mjs';
7
+ "use strict";
8
+ const currencyLookup = new Set(Object.keys(Currency).map(el => el.toString()));
9
+ const dineroCurrenciesLookup = new Map(Object.values(currencies).map(currency => [currency.code, currency]));
10
+ const floatToInt = (floatAmount, base, exponent) => Round.Financial(floatAmount * Math.pow(base, exponent));
11
+ const decimalToDinero = (decimalAmount, currency) => {
12
+ const parsedNumber = typeof decimalAmount === "number" ? decimalAmount : Number.parseFloat(decimalAmount);
13
+ isFloat(parsedNumber);
14
+ const parsedNumberInt = Number.parseInt((parsedNumber * Math.pow(10, currency.exponent)).toFixed(0));
15
+ return dinero({
16
+ amount: parsedNumberInt,
17
+ currency
18
+ });
19
+ };
20
+ export { currencyLookup, decimalToDinero, dineroCurrenciesLookup, floatToInt };
21
+ //# sourceMappingURL=misc.private.mjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"misc.private.mjs","sources":["../../../src/utils/money/misc.private.ts"],"sourcesContent":["// #############################################################################\n// Internal helper functions not for consumption outside of store.core!\n// Wrote as separate files so that they can be easily unit tested without exposing them\n// #############################################################################\nimport * as currencies from \"@dinero.js/currencies\";\nimport { dinero } from \"dinero.js\";\n\nimport { Currency } from \"../../types\";\nimport { isFloat } from \"../number\";\nimport { Round } from \"./constants\";\nimport type { DinoCurrency } from \"./types\";\n\n/**\n * Fast lookup for our custom currency enum to check that given currency is valid\n */\nexport const currencyLookup = new Set(\n Object.keys(Currency).map((el) => el.toString()),\n);\n\n/**\n * Dinero currency lookup to check that given currency is valid\n */\nexport const dineroCurrenciesLookup = 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 * @example\n * floatToInt(69.10, 10, 2); // 6910\n * floatToInt(42, 10, 2); // 4200\n * floatToInt(0.22, 10, 6); // 220000\n */\nexport const floatToInt = (\n floatAmount: number,\n base: number,\n exponent: number,\n // FIXME: pass in the rounding method and or use roundDinero\n): number => Round.Financial(floatAmount * Math.pow(base, exponent));\n\n/**\n * FIXME: is it private tho?!\n */\nexport const decimalToDinero = (\n decimalAmount: string | number,\n currency: DinoCurrency,\n // FIXME: rounding method?!\n) => {\n const parsedNumber =\n typeof decimalAmount === \"number\"\n ? decimalAmount\n : Number.parseFloat(decimalAmount);\n isFloat(parsedNumber);\n\n const parsedNumberInt = Number.parseInt(\n (parsedNumber * Math.pow(10, currency.exponent)).toFixed(0),\n );\n return dinero({\n amount: parsedNumberInt,\n currency,\n });\n};\n"],"names":["currencyLookup","Set","Object","keys","Currency","map","el","toString","dineroCurrenciesLookup","Map","values","currencies","currency","code","floatToInt","floatAmount","base","exponent","Round","Financial","Math","pow","decimalToDinero","decimalAmount","parsedNumber","Number","parseFloat","isFloat","parsedNumberInt","parseInt","toFixed","dinero","amount"],"mappings":";;;;;;;AAeO,MAAMA,iBAAiB,IAAIC,GAAA,CAChCC,MAAA,CAAOC,KAAKC,QAAQ,CAAA,CAAEC,IAAKC,EAAA,IAAOA,EAAG,CAAAC,QAAA,EAAU,CACjD,CAAA;AAKO,MAAMC,yBAAyB,IAAIC,GAAA,CACxCP,MAAA,CAAOQ,MAAO,CAAAC,UAAU,CAAE,CAAAN,GAAA,CAAKO,QAAA,IAAa,CAACA,QAAA,CAASC,IAAM,EAAAD,QAAQ,CAAC,CACvE,CAAA;AAUO,MAAME,UAAa,GAAAA,CACxBC,WACA,EAAAC,IAAA,EACAC,QAEW,KAAAC,KAAA,CAAMC,SAAU,CAAAJ,WAAA,GAAcK,IAAK,CAAAC,GAAA,CAAIL,IAAM,EAAAC,QAAQ,CAAC,CAAA;AAKtD,MAAAK,eAAA,GAAkBA,CAC7BC,aAAA,EACAX,QAEG,KAAA;EACH,MAAMY,eACJ,OAAOD,aAAA,KAAkB,WACrBA,aACA,GAAAE,MAAA,CAAOC,WAAWH,aAAa,CAAA;EACrCI,OAAA,CAAQH,YAAY,CAAA;EAEpB,MAAMI,kBAAkBH,MAAO,CAAAI,QAAA,CAC5B,CAAAL,YAAA,GAAeJ,KAAKC,GAAI,CAAA,EAAA,EAAIT,SAASK,QAAQ,CAAA,EAAGa,QAAQ,CAAC,CAAA,CAC5D;EACA,OAAOC,MAAO,CAAA;IACZC,MAAQ,EAAAJ,eAAA;IACRhB;EAAA,CACD,CAAA;AACH,CAAA;"}
@@ -0,0 +1,5 @@
1
+ import type { Dino } from "./types";
2
+ /**
3
+ * Rounding for shipping price used only after applying
4
+ */
5
+ export declare const roundShippingPrice: (price: Dino) => Dino;
@@ -0,0 +1,8 @@
1
+ 'use strict';
2
+
3
+ var constants = require('./constants.js');
4
+ var misc = require('./misc.js');
5
+ "use strict";
6
+ const roundShippingPrice = price => misc.roundDinero(price, constants.Round.Shipping);
7
+ exports.roundShippingPrice = roundShippingPrice;
8
+ //# sourceMappingURL=shipping.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"shipping.js","sources":["../../../src/utils/money/shipping.ts"],"sourcesContent":["import { Round } from \"./constants\";\nimport { roundDinero } from \"./misc\";\nimport type { Dino } from \"./types\";\n\n/**\n * Rounding for shipping price used only after applying\n */\nexport const roundShippingPrice = (price: Dino) =>\n roundDinero(price, Round.Shipping);\n"],"names":["roundShippingPrice","price","roundDinero","Round","Shipping"],"mappings":";;;;;AAOO,MAAMA,qBAAsBC,KAAA,IACjCC,IAAY,CAAAA,WAAA,CAAAD,KAAA,EAAOE,gBAAMC,QAAQ,CAAA;"}
@@ -0,0 +1,6 @@
1
+ import { Round } from './constants.mjs';
2
+ import { roundDinero } from './misc.mjs';
3
+ "use strict";
4
+ const roundShippingPrice = price => roundDinero(price, Round.Shipping);
5
+ export { roundShippingPrice };
6
+ //# sourceMappingURL=shipping.mjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"shipping.mjs","sources":["../../../src/utils/money/shipping.ts"],"sourcesContent":["import { Round } from \"./constants\";\nimport { roundDinero } from \"./misc\";\nimport type { Dino } from \"./types\";\n\n/**\n * Rounding for shipping price used only after applying\n */\nexport const roundShippingPrice = (price: Dino) =>\n roundDinero(price, Round.Shipping);\n"],"names":["roundShippingPrice","price","roundDinero","Round","Shipping"],"mappings":";;;AAOO,MAAMA,qBAAsBC,KAAA,IACjCC,WAAY,CAAAD,KAAA,EAAOE,MAAMC,QAAQ,CAAA;"}
@@ -1,3 +1,39 @@
1
1
  import { type Dinero } from "dinero.js";
2
- export declare const allocateTaxAmount: (baseAmountObj: Dinero<number>, floatRate: number) => Dinero<number>;
3
- export declare const removeTaxAmount: (baseAmountWithTaxObj: Dinero<number>, floatRate: number) => Dinero<number>;
2
+ import type { StoreId } from "../../types";
3
+ import type { Cents, Dino, LineItemSummary, TaxRate } from "./types";
4
+ /**
5
+ * Function to calculate the tax amount for a given line item depending on the store's tax rate calculation strategy
6
+ */
7
+ export declare const calculateLineItemTax: ({ itemSummary, taxRate, storeId, }: {
8
+ itemSummary: LineItemSummary;
9
+ taxRate: TaxRate;
10
+ storeId: StoreId;
11
+ }) => Dinero<number>;
12
+ export declare const removeTaxAmount: (baseAmountWithTaxObj: Dinero<Cents>, taxRate: TaxRate) => Dinero<number>;
13
+ /**
14
+ * Will return a percentage tax rate from a decimal tax rate (usually returned by DB)
15
+ *
16
+ * Use for math-related calculations ONLY! Use `formatDecimalTaxRate` for display purposes e.g. invoices.
17
+ *
18
+ * @example convertDecimalTaxRateToPercentage("0.01") // 1
19
+ * @example convertDecimalTaxRateToPercentage("0.1023") // 10.23
20
+ * @example convertDecimalTaxRateToPercentage("0.12345678") // 12.345678
21
+ */
22
+ export declare const convertDecimalTaxRateToPercentage: (taxRate: string | number) => number;
23
+ export declare const decimalTaxRateToDinero: (taxRate: string | number) => Dino;
24
+ /**
25
+ * Will return a percentage string from a decimal tax rate (usually returned by DB).
26
+ *
27
+ * Use for display purposes e.g. invoices.
28
+ *
29
+ * @example formatDecimalTaxRate("0.01") // "1%"
30
+ * @example formatDecimalTaxRate("0.1023") // "10.23%"
31
+ * @example formatDecimalTaxRate("0.12345678") // "12.345678%"
32
+ */
33
+ export declare const formatDecimalTaxRate: <TaxRateFloat extends string | number>(taxRate: TaxRateFloat) => `${number}%`;
34
+ export declare const stringTaxRateToFloat: (rate: string) => number;
35
+ /**
36
+ * Calculate total Tax(LV: "PVN") for country, which consists of multiple tax entries
37
+ * Returning fixed to ${TAX_RATE_DINERO_CURRENCY.exponent} 4 decimal places, to for example 0.2100 represent 21.00%
38
+ */
39
+ export declare const calculateTotalTaxRate: (rates: number[]) => number;
@@ -1,22 +1,58 @@
1
1
  'use strict';
2
2
 
3
3
  var dinero_js = require('dinero.js');
4
+ var errors = require('../errors.js');
5
+ var number = require('../number.js');
6
+ var constants = require('./constants.js');
7
+ var tax_private = require('./tax.private.js');
4
8
  "use strict";
5
- const allocateTaxAmount = (baseAmountObj, floatRate) => {
6
- const rateScale = String(floatRate).split(".")[1]?.length;
7
- if (rateScale === void 0) {
8
- throw new Error(`rateScale is unsupported ${floatRate}`);
9
- }
10
- const rateInt = Math.round(floatRate * Math.pow(10, rateScale));
11
- return dinero_js.allocate(baseAmountObj, [rateInt, Math.pow(10, rateScale) - rateInt])[0];
9
+ const calculateLineItemTax = ({
10
+ itemSummary,
11
+ taxRate,
12
+ storeId
13
+ }) => {
14
+ return constants.storesWithPerItemTaxRate.has(storeId) ? tax_private.calculatePerQtyLineItemTax(itemSummary, taxRate) : tax_private.calculateWholeQtyLineItemTax(itemSummary, taxRate);
12
15
  };
13
- const removeTaxAmount = (baseAmountWithTaxObj, floatRate) => {
16
+ const removeTaxAmount = (baseAmountWithTaxObj, taxRate) => {
14
17
  const snapshot = dinero_js.toSnapshot(baseAmountWithTaxObj);
15
18
  return dinero_js.dinero({
16
19
  ...snapshot,
17
- amount: dinero_js.down(snapshot.amount / (1 + floatRate))
20
+ amount: dinero_js.down(snapshot.amount / (1 + taxRate))
18
21
  });
19
22
  };
20
- exports.allocateTaxAmount = allocateTaxAmount;
23
+ const convertDecimalTaxRateToPercentage = taxRate => {
24
+ const dineroObj = decimalTaxRateToDinero(taxRate);
25
+ const t = dinero_js.multiply(dineroObj, 100);
26
+ return dinero_js.toUnit(t, {
27
+ digits: constants.TAX_RATE_DINERO_CURRENCY.exponent,
28
+ round: dinero_js.halfEven
29
+ });
30
+ };
31
+ const decimalTaxRateToDinero = taxRate => {
32
+ const parsedNumber = typeof taxRate === "number" ? taxRate : Number.parseFloat(taxRate);
33
+ number.isFloat(parsedNumber);
34
+ const parsedNumberInt = Number.parseInt((parsedNumber * Math.pow(constants.TAX_RATE_DINERO_CURRENCY.base, constants.TAX_RATE_DINERO_CURRENCY.exponent)).toFixed(0));
35
+ return dinero_js.dinero({
36
+ amount: parsedNumberInt,
37
+ currency: constants.TAX_RATE_DINERO_CURRENCY
38
+ });
39
+ };
40
+ const formatDecimalTaxRate = taxRate => {
41
+ return `${convertDecimalTaxRateToPercentage(taxRate)}%`;
42
+ };
43
+ const stringTaxRateToFloat = rate => number.toFixedRate(+rate, constants.TAX_RATE_DINERO_CURRENCY.exponent, true);
44
+ const calculateTotalTaxRate = rates => {
45
+ const rateSum = rates.reduce((sum, rate) => sum + rate, 0);
46
+ const result = number.toFixedRate(rateSum, constants.TAX_RATE_DINERO_CURRENCY.exponent, true);
47
+ errors.assert(result >= 0, "Tax rate must be positive");
48
+ errors.assert(result < 1, "Tax rate must be less than 1");
49
+ return result;
50
+ };
51
+ exports.calculateLineItemTax = calculateLineItemTax;
52
+ exports.calculateTotalTaxRate = calculateTotalTaxRate;
53
+ exports.convertDecimalTaxRateToPercentage = convertDecimalTaxRateToPercentage;
54
+ exports.decimalTaxRateToDinero = decimalTaxRateToDinero;
55
+ exports.formatDecimalTaxRate = formatDecimalTaxRate;
21
56
  exports.removeTaxAmount = removeTaxAmount;
57
+ exports.stringTaxRateToFloat = stringTaxRateToFloat;
22
58
  //# sourceMappingURL=tax.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"tax.js","sources":["../../../src/utils/money/tax.ts"],"sourcesContent":["import { allocate, type Dinero, dinero, down, toSnapshot } from \"dinero.js\";\n\nexport const allocateTaxAmount = (\n baseAmountObj: Dinero<number>,\n floatRate: number,\n) => {\n // FIXME: currently the API returns rate as a floating number, but the dinero lib expects be a integer number with some\n // scale so for now we attempt calculate the scale from the float rate\n // @see https://v2.dinerojs.com/docs/api/mutations/allocate\n const rateScale = String(floatRate).split(\".\")[1]?.length;\n if (rateScale === undefined) {\n throw new Error(`rateScale is unsupported ${floatRate}`);\n }\n const rateInt = Math.round(floatRate * Math.pow(10, rateScale));\n // eslint-disable-next-line @typescript-eslint/no-non-null-assertion\n return allocate(baseAmountObj, [\n rateInt,\n Math.pow(10, rateScale) - rateInt,\n ])[0]!;\n};\n\nexport const removeTaxAmount = (\n baseAmountWithTaxObj: Dinero<number>,\n floatRate: number,\n) => {\n const snapshot = toSnapshot(baseAmountWithTaxObj);\n return dinero({\n ...snapshot,\n amount: down(snapshot.amount / (1 + floatRate)),\n });\n};\n"],"names":["allocateTaxAmount","baseAmountObj","floatRate","rateScale","String","split","length","Error","rateInt","Math","round","pow","allocate","removeTaxAmount","baseAmountWithTaxObj","snapshot","toSnapshot","dinero","amount","down"],"mappings":";;;;AAEa,MAAAA,iBAAA,GAAoBA,CAC/BC,aAAA,EACAC,SACG,KAAA;EAIG,MAAAC,SAAA,GAAYC,OAAOF,SAAS,CAAA,CAAEG,MAAM,GAAG,CAAA,CAAE,CAAC,CAAG,EAAAC,MAAA;EACnD,IAAIH,cAAc,KAAW,CAAA,EAAA;IAC3B,MAAM,IAAII,KAAA,CAAkC,4BAAAL,SAAW,EAAA,CAAA;EACzD;EACM,MAAAM,OAAA,GAAUC,KAAKC,KAAM,CAAAR,SAAA,GAAYO,KAAKE,GAAI,CAAA,EAAA,EAAIR,SAAS,CAAC,CAAA;EAE9D,OAAOS,SAAAA,CAAAA,SAASX,aAAe,EAAA,CAC7BO,OAAA,EACAC,IAAK,CAAAE,GAAA,CAAI,EAAI,EAAAR,SAAS,CAAI,GAAAK,OAAA,CAC3B,EAAE,CAAC,CAAA;AACN,CAAA;AAEa,MAAAK,eAAA,GAAkBA,CAC7BC,oBAAA,EACAZ,SACG,KAAA;EACG,MAAAa,QAAA,GAAWC,qBAAWF,oBAAoB,CAAA;EAChD,OAAOG,gBAAO,CAAA;IACZ,GAAGF,QAAA;IACHG,MAAQ,EAAAC,SAAA,CAAAA,IAAA,CAAKJ,QAAS,CAAAG,MAAA,IAAU,IAAIhB,SAAU,CAAA;EAAA,CAC/C,CAAA;AACH,CAAA;;"}
1
+ {"version":3,"file":"tax.js","sources":["../../../src/utils/money/tax.ts"],"sourcesContent":["import {\n type Dinero,\n dinero,\n // FIXME: move usage to rounding\n down,\n // FIXME: move usage to rounding\n halfEven,\n multiply,\n toSnapshot,\n toUnit,\n} from \"dinero.js\";\n\nimport type { StoreId } from \"../../types\";\nimport { assert } from \"../errors\";\nimport { isFloat, toFixedRate } from \"../number\";\nimport {\n storesWithPerItemTaxRate,\n TAX_RATE_DINERO_CURRENCY,\n} from \"./constants\";\nimport {\n calculatePerQtyLineItemTax,\n calculateWholeQtyLineItemTax,\n} from \"./tax.private\";\nimport type { Cents, Dino, LineItemSummary, TaxRate } from \"./types\";\n\n/**\n * Function to calculate the tax amount for a given line item depending on the store's tax rate calculation strategy\n */\nexport const calculateLineItemTax = ({\n itemSummary,\n taxRate,\n storeId,\n}: {\n itemSummary: LineItemSummary;\n taxRate: TaxRate;\n storeId: StoreId;\n}) => {\n return storesWithPerItemTaxRate.has(storeId)\n ? calculatePerQtyLineItemTax(itemSummary, taxRate)\n : calculateWholeQtyLineItemTax(itemSummary, taxRate);\n};\n\nexport const removeTaxAmount = (\n baseAmountWithTaxObj: Dinero<Cents>,\n taxRate: TaxRate,\n) => {\n const snapshot = toSnapshot(baseAmountWithTaxObj);\n return dinero({\n ...snapshot,\n amount: down(snapshot.amount / (1 + taxRate)),\n });\n};\n\n/**\n * Will return a percentage tax rate from a decimal tax rate (usually returned by DB)\n *\n * Use for math-related calculations ONLY! Use `formatDecimalTaxRate` for display purposes e.g. invoices.\n *\n * @example convertDecimalTaxRateToPercentage(\"0.01\") // 1\n * @example convertDecimalTaxRateToPercentage(\"0.1023\") // 10.23\n * @example convertDecimalTaxRateToPercentage(\"0.12345678\") // 12.345678\n */\nexport const convertDecimalTaxRateToPercentage = (\n taxRate: string | number,\n): number => {\n const dineroObj = decimalTaxRateToDinero(taxRate);\n const t = multiply(dineroObj, 100);\n return toUnit(t, {\n digits: TAX_RATE_DINERO_CURRENCY.exponent,\n round: halfEven,\n });\n};\n\nexport const decimalTaxRateToDinero = (taxRate: string | number): Dino => {\n const parsedNumber =\n typeof taxRate === \"number\" ? taxRate : Number.parseFloat(taxRate);\n isFloat(parsedNumber);\n\n const parsedNumberInt = Number.parseInt(\n (\n parsedNumber *\n Math.pow(TAX_RATE_DINERO_CURRENCY.base, TAX_RATE_DINERO_CURRENCY.exponent)\n ).toFixed(0),\n );\n return dinero({\n amount: parsedNumberInt,\n currency: TAX_RATE_DINERO_CURRENCY,\n });\n};\n\n/**\n * Will return a percentage string from a decimal tax rate (usually returned by DB).\n *\n * Use for display purposes e.g. invoices.\n *\n * @example formatDecimalTaxRate(\"0.01\") // \"1%\"\n * @example formatDecimalTaxRate(\"0.1023\") // \"10.23%\"\n * @example formatDecimalTaxRate(\"0.12345678\") // \"12.345678%\"\n */\nexport const formatDecimalTaxRate = <TaxRateFloat extends string | number>(\n taxRate: TaxRateFloat,\n): `${number}%` => {\n return `${convertDecimalTaxRateToPercentage(taxRate)}%`;\n};\n\nexport const stringTaxRateToFloat = (rate: string): number =>\n toFixedRate(+rate, TAX_RATE_DINERO_CURRENCY.exponent, true);\n\n/**\n * Calculate total Tax(LV: \"PVN\") for country, which consists of multiple tax entries\n * Returning fixed to ${TAX_RATE_DINERO_CURRENCY.exponent} 4 decimal places, to for example 0.2100 represent 21.00%\n */\nexport const calculateTotalTaxRate = (rates: number[]): number => {\n const rateSum = rates.reduce((sum, rate) => sum + rate, 0);\n const result = toFixedRate(rateSum, TAX_RATE_DINERO_CURRENCY.exponent, true);\n assert(result >= 0, \"Tax rate must be positive\");\n assert(result < 1, \"Tax rate must be less than 1\");\n return result;\n};\n"],"names":["calculateLineItemTax","itemSummary","taxRate","storeId","storesWithPerItemTaxRate","has","calculatePerQtyLineItemTax","calculateWholeQtyLineItemTax","removeTaxAmount","baseAmountWithTaxObj","snapshot","toSnapshot","dinero","amount","down","convertDecimalTaxRateToPercentage","dineroObj","decimalTaxRateToDinero","t","multiply","toUnit","digits","TAX_RATE_DINERO_CURRENCY","exponent","round","halfEven","parsedNumber","Number","parseFloat","isFloat","parsedNumberInt","parseInt","Math","pow","base","toFixed","currency","formatDecimalTaxRate","stringTaxRateToFloat","rate","toFixedRate","calculateTotalTaxRate","rates","rateSum","reduce","sum","result","assert"],"mappings":";;;;;;;;AA4BO,MAAMA,uBAAuBA,CAAC;EACnCC,WAAA;EACAC,OAAA;EACAC;AACF,CAIM,KAAA;EACG,OAAAC,kCAAA,CAAyBC,GAAI,CAAAF,OAAO,CACvC,GAAAG,WAAA,CAAAA,0BAAA,CAA2BL,aAAaC,OAAO,CAAA,GAC/CK,WAAAA,CAAAA,4BAA6B,CAAAN,WAAA,EAAaC,OAAO,CAAA;AACvD,CAAA;AAEa,MAAAM,eAAA,GAAkBA,CAC7BC,oBAAA,EACAP,OACG,KAAA;EACG,MAAAQ,QAAA,GAAWC,qBAAWF,oBAAoB,CAAA;EAChD,O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AAM/C,MAAAkB,qBAAA,GAAyBC,KAA4B,IAAA;EAC1D,MAAAC,OAAA,GAAUD,MAAME,MAAO,CAAA,CAACC,KAAKN,IAAS,KAAAM,GAAA,GAAMN,MAAM,CAAC,CAAA;EACzD,MAAMO,MAAS,GAAAN,MAAAA,CAAAA,WAAA,CAAYG,OAAS,EAAArB,SAAAA,CAAAA,wBAAA,CAAyBC,UAAU,IAAI,CAAA;EACpEwB,MAAAA,CAAAA,MAAA,CAAAD,MAAA,IAAU,GAAG,2BAA2B,CAAA;EACxCC,MAAAA,CAAAA,MAAA,CAAAD,MAAA,GAAS,GAAG,8BAA8B,CAAA;EAC1C,OAAAA,MAAA;AACT,CAAA;;;;;;;"}
@@ -1,19 +1,50 @@
1
- import { allocate, toSnapshot, dinero, down } from 'dinero.js';
1
+ import { toSnapshot, dinero, down, multiply, toUnit, halfEven } from 'dinero.js';
2
+ import { assert } from '../errors.mjs';
3
+ import { isFloat, toFixedRate } from '../number.mjs';
4
+ import { storesWithPerItemTaxRate, TAX_RATE_DINERO_CURRENCY } from './constants.mjs';
5
+ import { calculatePerQtyLineItemTax, calculateWholeQtyLineItemTax } from './tax.private.mjs';
2
6
  "use strict";
3
- const allocateTaxAmount = (baseAmountObj, floatRate) => {
4
- const rateScale = String(floatRate).split(".")[1]?.length;
5
- if (rateScale === void 0) {
6
- throw new Error(`rateScale is unsupported ${floatRate}`);
7
- }
8
- const rateInt = Math.round(floatRate * Math.pow(10, rateScale));
9
- return allocate(baseAmountObj, [rateInt, Math.pow(10, rateScale) - rateInt])[0];
7
+ const calculateLineItemTax = ({
8
+ itemSummary,
9
+ taxRate,
10
+ storeId
11
+ }) => {
12
+ return storesWithPerItemTaxRate.has(storeId) ? calculatePerQtyLineItemTax(itemSummary, taxRate) : calculateWholeQtyLineItemTax(itemSummary, taxRate);
10
13
  };
11
- const removeTaxAmount = (baseAmountWithTaxObj, floatRate) => {
14
+ const removeTaxAmount = (baseAmountWithTaxObj, taxRate) => {
12
15
  const snapshot = toSnapshot(baseAmountWithTaxObj);
13
16
  return dinero({
14
17
  ...snapshot,
15
- amount: down(snapshot.amount / (1 + floatRate))
18
+ amount: down(snapshot.amount / (1 + taxRate))
16
19
  });
17
20
  };
18
- export { allocateTaxAmount, removeTaxAmount };
21
+ const convertDecimalTaxRateToPercentage = taxRate => {
22
+ const dineroObj = decimalTaxRateToDinero(taxRate);
23
+ const t = multiply(dineroObj, 100);
24
+ return toUnit(t, {
25
+ digits: TAX_RATE_DINERO_CURRENCY.exponent,
26
+ round: halfEven
27
+ });
28
+ };
29
+ const decimalTaxRateToDinero = taxRate => {
30
+ const parsedNumber = typeof taxRate === "number" ? taxRate : Number.parseFloat(taxRate);
31
+ isFloat(parsedNumber);
32
+ const parsedNumberInt = Number.parseInt((parsedNumber * Math.pow(TAX_RATE_DINERO_CURRENCY.base, TAX_RATE_DINERO_CURRENCY.exponent)).toFixed(0));
33
+ return dinero({
34
+ amount: parsedNumberInt,
35
+ currency: TAX_RATE_DINERO_CURRENCY
36
+ });
37
+ };
38
+ const formatDecimalTaxRate = taxRate => {
39
+ return `${convertDecimalTaxRateToPercentage(taxRate)}%`;
40
+ };
41
+ const stringTaxRateToFloat = rate => toFixedRate(+rate, TAX_RATE_DINERO_CURRENCY.exponent, true);
42
+ const calculateTotalTaxRate = rates => {
43
+ const rateSum = rates.reduce((sum, rate) => sum + rate, 0);
44
+ const result = toFixedRate(rateSum, TAX_RATE_DINERO_CURRENCY.exponent, true);
45
+ assert(result >= 0, "Tax rate must be positive");
46
+ assert(result < 1, "Tax rate must be less than 1");
47
+ return result;
48
+ };
49
+ export { calculateLineItemTax, calculateTotalTaxRate, convertDecimalTaxRateToPercentage, decimalTaxRateToDinero, formatDecimalTaxRate, removeTaxAmount, stringTaxRateToFloat };
19
50
  //# sourceMappingURL=tax.mjs.map
@@ -1 +1 @@
1
- {"version":3,"file":"tax.mjs","sources":["../../../src/utils/money/tax.ts"],"sourcesContent":["import { allocate, type Dinero, dinero, down, toSnapshot } from \"dinero.js\";\n\nexport const allocateTaxAmount = (\n baseAmountObj: Dinero<number>,\n floatRate: number,\n) => {\n // FIXME: currently the API returns rate as a floating number, but the dinero lib expects be a integer number with some\n // scale so for now we attempt calculate the scale from the float rate\n // @see https://v2.dinerojs.com/docs/api/mutations/allocate\n const rateScale = String(floatRate).split(\".\")[1]?.length;\n if (rateScale === undefined) {\n throw new Error(`rateScale is unsupported ${floatRate}`);\n }\n const rateInt = Math.round(floatRate * Math.pow(10, rateScale));\n // eslint-disable-next-line @typescript-eslint/no-non-null-assertion\n return allocate(baseAmountObj, [\n rateInt,\n Math.pow(10, rateScale) - rateInt,\n ])[0]!;\n};\n\nexport const removeTaxAmount = (\n baseAmountWithTaxObj: Dinero<number>,\n floatRate: number,\n) => {\n const snapshot = toSnapshot(baseAmountWithTaxObj);\n return dinero({\n ...snapshot,\n amount: down(snapshot.amount / (1 + floatRate)),\n });\n};\n"],"names":["allocateTaxAmount","baseAmountObj","floatRate","rateScale","String","split","length","Error","rateInt","Math","round","pow","allocate","removeTaxAmount","baseAmountWithTaxObj","snapshot","toSnapshot","dinero","amount","down"],"mappings":";;AAEa,MAAAA,iBAAA,GAAoBA,CAC/BC,aAAA,EACAC,SACG,KAAA;EAIG,MAAAC,SAAA,GAAYC,OAAOF,SAAS,CAAA,CAAEG,MAAM,GAAG,CAAA,CAAE,CAAC,CAAG,EAAAC,MAAA;EACnD,IAAIH,cAAc,KAAW,CAAA,EAAA;IAC3B,MAAM,IAAII,KAAA,CAAkC,4BAAAL,SAAW,EAAA,CAAA;EACzD;EACM,MAAAM,OAAA,GAAUC,KAAKC,KAAM,CAAAR,SAAA,GAAYO,KAAKE,GAAI,CAAA,EAAA,EAAIR,SAAS,CAAC,CAAA;EAE9D,OAAOS,SAASX,aAAe,EAAA,CAC7BO,OAAA,EACAC,IAAK,CAAAE,GAAA,CAAI,EAAI,EAAAR,SAAS,CAAI,GAAAK,OAAA,CAC3B,EAAE,CAAC,CAAA;AACN,CAAA;AAEa,MAAAK,eAAA,GAAkBA,CAC7BC,oBAAA,EACAZ,SACG,KAAA;EACG,MAAAa,QAAA,GAAWC,WAAWF,oBAAoB,CAAA;EAChD,OAAOG,MAAO,CAAA;IACZ,GAAGF,QAAA;IACHG,MAAQ,EAAAC,IAAA,CAAKJ,QAAS,CAAAG,MAAA,IAAU,IAAIhB,SAAU,CAAA;EAAA,CAC/C,CAAA;AACH,CAAA;"}
1
+ {"version":3,"file":"tax.mjs","sources":["../../../src/utils/money/tax.ts"],"sourcesContent":["import {\n type Dinero,\n dinero,\n // FIXME: move usage to rounding\n down,\n // FIXME: move usage to rounding\n halfEven,\n multiply,\n toSnapshot,\n toUnit,\n} from \"dinero.js\";\n\nimport type { StoreId } from \"../../types\";\nimport { assert } from \"../errors\";\nimport { isFloat, toFixedRate } from \"../number\";\nimport {\n storesWithPerItemTaxRate,\n TAX_RATE_DINERO_CURRENCY,\n} from \"./constants\";\nimport {\n calculatePerQtyLineItemTax,\n calculateWholeQtyLineItemTax,\n} from \"./tax.private\";\nimport type { Cents, Dino, LineItemSummary, TaxRate } from \"./types\";\n\n/**\n * Function to calculate the tax amount for a given line item depending on the store's tax rate calculation strategy\n */\nexport const calculateLineItemTax = ({\n itemSummary,\n taxRate,\n storeId,\n}: {\n itemSummary: LineItemSummary;\n taxRate: TaxRate;\n storeId: StoreId;\n}) => {\n return storesWithPerItemTaxRate.has(storeId)\n ? calculatePerQtyLineItemTax(itemSummary, taxRate)\n : calculateWholeQtyLineItemTax(itemSummary, taxRate);\n};\n\nexport const removeTaxAmount = (\n baseAmountWithTaxObj: Dinero<Cents>,\n taxRate: TaxRate,\n) => {\n const snapshot = toSnapshot(baseAmountWithTaxObj);\n return dinero({\n ...snapshot,\n amount: down(snapshot.amount / (1 + taxRate)),\n });\n};\n\n/**\n * Will return a percentage tax rate from a decimal tax rate (usually returned by DB)\n *\n * Use for math-related calculations ONLY! Use `formatDecimalTaxRate` for display purposes e.g. invoices.\n *\n * @example convertDecimalTaxRateToPercentage(\"0.01\") // 1\n * @example convertDecimalTaxRateToPercentage(\"0.1023\") // 10.23\n * @example convertDecimalTaxRateToPercentage(\"0.12345678\") // 12.345678\n */\nexport const convertDecimalTaxRateToPercentage = (\n taxRate: string | number,\n): number => {\n const dineroObj = decimalTaxRateToDinero(taxRate);\n const t = multiply(dineroObj, 100);\n return toUnit(t, {\n digits: TAX_RATE_DINERO_CURRENCY.exponent,\n round: halfEven,\n });\n};\n\nexport const decimalTaxRateToDinero = (taxRate: string | number): Dino => {\n const parsedNumber =\n typeof taxRate === \"number\" ? taxRate : Number.parseFloat(taxRate);\n isFloat(parsedNumber);\n\n const parsedNumberInt = Number.parseInt(\n (\n parsedNumber *\n Math.pow(TAX_RATE_DINERO_CURRENCY.base, TAX_RATE_DINERO_CURRENCY.exponent)\n ).toFixed(0),\n );\n return dinero({\n amount: parsedNumberInt,\n currency: TAX_RATE_DINERO_CURRENCY,\n });\n};\n\n/**\n * Will return a percentage string from a decimal tax rate (usually returned by DB).\n *\n * Use for display purposes e.g. invoices.\n *\n * @example formatDecimalTaxRate(\"0.01\") // \"1%\"\n * @example formatDecimalTaxRate(\"0.1023\") // \"10.23%\"\n * @example formatDecimalTaxRate(\"0.12345678\") // \"12.345678%\"\n */\nexport const formatDecimalTaxRate = <TaxRateFloat extends string | number>(\n taxRate: TaxRateFloat,\n): `${number}%` => {\n return `${convertDecimalTaxRateToPercentage(taxRate)}%`;\n};\n\nexport const stringTaxRateToFloat = (rate: string): number =>\n toFixedRate(+rate, TAX_RATE_DINERO_CURRENCY.exponent, true);\n\n/**\n * Calculate total Tax(LV: \"PVN\") for country, which consists of multiple tax entries\n * Returning fixed to ${TAX_RATE_DINERO_CURRENCY.exponent} 4 decimal places, to for example 0.2100 represent 21.00%\n */\nexport const calculateTotalTaxRate = (rates: number[]): number => {\n const rateSum = rates.reduce((sum, rate) => sum + rate, 0);\n const result = toFixedRate(rateSum, TAX_RATE_DINERO_CURRENCY.exponent, true);\n assert(result >= 0, \"Tax rate must be positive\");\n assert(result < 1, \"Tax rate must be less than 1\");\n return result;\n};\n"],"names":["calculateLineItemTax","itemSummary","taxRate","storeId","storesWithPerItemTaxRate","has","calculatePerQtyLineItemTax","calculateWholeQtyLineItemTax","removeTaxAmount","baseAmountWithTaxObj","snapshot","toSnapshot","dinero","amount","down","convertDecimalTaxRateToPercentage","dineroObj","decimalTaxRateToDinero","t","multiply","toUnit","digits","TAX_RATE_DINERO_CURRENCY","exponent","round","halfEven","parsedNumber","Number","parseFloat","isFloat","parsedNumberInt","parseInt","Math","pow","base","toFixed","currency","formatDecimalTaxRate","stringTaxRateToFloat","rate","toFixedRate","calculateTotalTaxRate","rates","rateSum","reduce","sum","result","assert"],"mappings":";;;;;;AA4BO,MAAMA,uBAAuBA,CAAC;EACnCC,WAAA;EACAC,OAAA;EACAC;AACF,CAIM,KAAA;EACG,OAAAC,wBAAA,CAAyBC,GAAI,CAAAF,OAAO,CACvC,GAAAG,0BAAA,CAA2BL,aAAaC,OAAO,CAAA,GAC/CK,4BAA6B,CAAAN,WAAA,EAAaC,OAAO,CAAA;AACvD,CAAA;AAEa,MAAAM,eAAA,GAAkBA,CAC7BC,oBAAA,EACAP,OACG,KAAA;EACG,MAAAQ,QAAA,GAAWC,WAAWF,oBAAoB,CAAA;EAChD,OAAOG,MAAO,CAAA;IACZ,GAAGF,QAAA;IACHG,MAAQ,EAAAC,IAAA,CAAKJ,QAAS,CAAAG,MAAA,IAAU,IAAIX,OAAQ,CAAA;EAAA,CAC7C,CAAA;AACH,CAAA;AAWa,MAAAa,iCAAA,GACXb,OACW,IAAA;EACL,MAAAc,SAAA,GAAYC,uBAAuBf,OAAO,CAAA;EAC1C,MAAAgB,CAAA,GAAIC,QAAS,CAAAH,SAAA,EAAW,GAAG,CAAA;EACjC,OAAOI,OAAOF,CAAG,EAAA;IACfG,QAAQC,wBAAyB,CAAAC,QAAA;IACjCC,KAAO,EAAAC;EAAA,CACR,CAAA;AACH,CAAA;AAEa,MAAAR,sBAAA,GAA0Bf,OAAmC,IAAA;EACxE,MAAMwB,eACJ,OAAOxB,OAAA,KAAY,WAAWA,OAAU,GAAAyB,MAAA,CAAOC,WAAW1B,OAAO,CAAA;EACnE2B,OAAA,CAAQH,YAAY,CAAA;EAEpB,MAAMI,kBAAkBH,MAAO,CAAAI,QAAA,CAE3B,CAAAL,YAAA,GACAM,KAAKC,GAAI,CAAAX,wBAAA,CAAyBY,MAAMZ,wBAAyB,CAAAC,QAAQ,CACzE,EAAAY,OAAA,CAAQ,CAAC,CAAA,CACb;EACA,OAAOvB,MAAO,CAAA;IACZC,MAAQ,EAAAiB,eAAA;IACRM,QAAU,EAAAd;EAAA,CACX,CAAA;AACH,CAAA;AAWa,MAAAe,oBAAA,GACXnC,OACiB,IAAA;EACV,OAAA,GAAGa,iCAAkC,CAAAb,OAAO,CAAC,GAAA;AACtD,CAAA;AAEa,MAAAoC,oBAAA,GAAwBC,IACnC,IAAAC,WAAA,CAAY,CAACD,IAAM,EAAAjB,wBAAA,CAAyBC,UAAU,IAAI,CAAA;AAM/C,MAAAkB,qBAAA,GAAyBC,KAA4B,IAAA;EAC1D,MAAAC,OAAA,GAAUD,MAAME,MAAO,CAAA,CAACC,KAAKN,IAAS,KAAAM,GAAA,GAAMN,MAAM,CAAC,CAAA;EACzD,MAAMO,MAAS,GAAAN,WAAA,CAAYG,OAAS,EAAArB,wBAAA,CAAyBC,UAAU,IAAI,CAAA;EACpEwB,MAAA,CAAAD,MAAA,IAAU,GAAG,2BAA2B,CAAA;EACxCC,MAAA,CAAAD,MAAA,GAAS,GAAG,8BAA8B,CAAA;EAC1C,OAAAA,MAAA;AACT,CAAA;"}
@@ -0,0 +1,17 @@
1
+ import type { Dinero } from "dinero.js";
2
+ import type { Cents, LineItemSummary, SingleLineItemSummary, TaxRate } from "./types";
3
+ /**
4
+ * Private helper to convert a floating number to a dinero friendly allocation integer pair
5
+ * @see https://v2.dinerojs.com/docs/api/mutations/allocate
6
+ * @example
7
+ * taxRateToDineroAllocation(0.1) // [1, 9]
8
+ * taxRateToDineroAllocation(0.5) // [5, 5]
9
+ */
10
+ export declare const taxRateToDineroAllocation: (taxRate: TaxRate) => [number, number];
11
+ /**
12
+ * Reverse engineer the taxable amount from "whole item" taxable amount into "per item" taxable amount for custom tax
13
+ * rate calculations
14
+ */
15
+ export declare const allocatePerItemTaxableAmount: (itemSummary: LineItemSummary) => SingleLineItemSummary[];
16
+ export declare const calculateWholeQtyLineItemTax: (itemSummary: LineItemSummary, taxRate: TaxRate) => Dinero<Cents>;
17
+ export declare const calculatePerQtyLineItemTax: (itemSummary: LineItemSummary, taxRate: TaxRate) => Dinero<Cents>;