@ubnt/store.core 9.45.0-alpha.1 → 9.45.0-beta.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (1246) hide show
  1. package/CHANGELOG.md +364 -67
  2. package/lib/_virtual/_virtual_multi-entry.js +55 -48
  3. package/lib/_virtual/_virtual_multi-entry.js.map +1 -1
  4. package/lib/_virtual/_virtual_multi-entry.mjs +42 -46
  5. package/lib/_virtual/_virtual_multi-entry.mjs.map +1 -1
  6. package/lib/apis/smartcat.d.ts +4 -4
  7. package/lib/apis/smartcat.js +1 -1
  8. package/lib/apis/smartcat.js.map +1 -1
  9. package/lib/apis/smartcat.mjs +1 -1
  10. package/lib/apis/smartcat.mjs.map +1 -1
  11. package/lib/assets/apple.svg +8 -0
  12. package/lib/assets/attention.svg +5 -5
  13. package/lib/assets/attention2.svg +5 -5
  14. package/lib/assets/contact.svg +5 -0
  15. package/lib/assets/crestron.svg +3 -0
  16. package/lib/assets/door-hub-mini.jpg +0 -0
  17. package/lib/assets/door-hub.jpg +0 -0
  18. package/lib/assets/efg.png +0 -0
  19. package/lib/assets/envr.png +0 -0
  20. package/lib/assets/g2-reader-pro.jpg +0 -0
  21. package/lib/assets/g2-reader.jpg +0 -0
  22. package/lib/assets/g3-reader-flex.jpg +0 -0
  23. package/lib/assets/g3-reader-pro.jpg +0 -0
  24. package/lib/assets/g3-reader.jpg +0 -0
  25. package/lib/assets/g3-starter-kit-pro.jpg +0 -0
  26. package/lib/assets/g3-starter-kit.jpg +0 -0
  27. package/lib/assets/icons/menu/icon-globe.svg.js +27 -0
  28. package/lib/assets/icons/menu/icon-globe.svg.js.map +1 -0
  29. package/lib/assets/icons/menu/icon-globe.svg.mjs +3 -0
  30. package/lib/assets/icons/menu/icon-globe.svg.mjs.map +1 -0
  31. package/lib/assets/industrial.jpg +0 -0
  32. package/lib/assets/intercom.jpg +0 -0
  33. package/lib/assets/logoUnifi.svg +2 -10
  34. package/lib/assets/minus4.svg +8 -8
  35. package/lib/assets/minus5.svg +8 -8
  36. package/lib/assets/plus5.svg +9 -9
  37. package/lib/assets/plus6.svg +9 -9
  38. package/lib/assets/reader-lite.jpg +0 -0
  39. package/lib/assets/touchPass.svg +3 -0
  40. package/lib/assets/ucg-max.png +0 -0
  41. package/lib/assets/ucgUltra.jpg +0 -0
  42. package/lib/assets/ucgUltra2.jpg +0 -0
  43. package/lib/components/Accordion/Accordion.js +2 -2
  44. package/lib/components/Accordion/Accordion.js.map +1 -1
  45. package/lib/components/Accordion/Accordion.mjs +2 -2
  46. package/lib/components/Accordion/Accordion.mjs.map +1 -1
  47. package/lib/components/Badge/Badge.styles.js +0 -12
  48. package/lib/components/Badge/Badge.styles.js.map +1 -1
  49. package/lib/components/Badge/Badge.styles.mjs +0 -12
  50. package/lib/components/Badge/Badge.styles.mjs.map +1 -1
  51. package/lib/components/Badge/Badge.types.d.ts +1 -3
  52. package/lib/components/Badge/Badge.types.js +0 -2
  53. package/lib/components/Badge/Badge.types.js.map +1 -1
  54. package/lib/components/Badge/Badge.types.mjs +0 -2
  55. package/lib/components/Badge/Badge.types.mjs.map +1 -1
  56. package/lib/components/Button/Button.js +0 -7
  57. package/lib/components/Button/Button.js.map +1 -1
  58. package/lib/components/Button/Button.mjs +1 -8
  59. package/lib/components/Button/Button.mjs.map +1 -1
  60. package/lib/components/Button/CartButton.d.ts +1 -3
  61. package/lib/components/Button/CartButton.js +4 -9
  62. package/lib/components/Button/CartButton.js.map +1 -1
  63. package/lib/components/Button/CartButton.mjs +4 -8
  64. package/lib/components/Button/CartButton.mjs.map +1 -1
  65. package/lib/components/ButtonGroup/ButtonGroup.d.ts +1 -1
  66. package/lib/components/ButtonGroup/ButtonGroup.js +9 -16
  67. package/lib/components/ButtonGroup/ButtonGroup.js.map +1 -1
  68. package/lib/components/ButtonGroup/ButtonGroup.mjs +9 -16
  69. package/lib/components/ButtonGroup/ButtonGroup.mjs.map +1 -1
  70. package/lib/components/ButtonGroup/ButtonGroup.styles.d.ts +6 -10
  71. package/lib/components/ButtonGroup/ButtonGroup.styles.js +20 -60
  72. package/lib/components/ButtonGroup/ButtonGroup.styles.js.map +1 -1
  73. package/lib/components/ButtonGroup/ButtonGroup.styles.mjs +20 -60
  74. package/lib/components/ButtonGroup/ButtonGroup.styles.mjs.map +1 -1
  75. package/lib/components/ButtonGroup/ButtonGroup.types.d.ts +0 -5
  76. package/lib/components/CardSection/CardSection.styles.d.ts +1 -1
  77. package/lib/components/CategoryTabs/CategoryTabs.styles.d.ts +2 -4
  78. package/lib/components/CategoryTabs/CategoryTabs.styles.js +5 -8
  79. package/lib/components/CategoryTabs/CategoryTabs.styles.js.map +1 -1
  80. package/lib/components/CategoryTabs/CategoryTabs.styles.mjs +6 -7
  81. package/lib/components/CategoryTabs/CategoryTabs.styles.mjs.map +1 -1
  82. package/lib/components/Compare/Compare.styles.d.ts +5 -5
  83. package/lib/components/Container/Container.d.ts +1 -1
  84. package/lib/components/Container/Container.js +3 -4
  85. package/lib/components/Container/Container.js.map +1 -1
  86. package/lib/components/Container/Container.mjs +4 -5
  87. package/lib/components/Container/Container.mjs.map +1 -1
  88. package/lib/components/CustomImage/CustomImage.js +4 -4
  89. package/lib/components/CustomImage/CustomImage.js.map +1 -1
  90. package/lib/components/CustomImage/CustomImage.mjs +4 -4
  91. package/lib/components/CustomImage/CustomImage.mjs.map +1 -1
  92. package/lib/components/FeaturesSection_deprecated/FeaturesSection.js +1 -1
  93. package/lib/components/FeaturesSection_deprecated/FeaturesSection.js.map +1 -1
  94. package/lib/components/FeaturesSection_deprecated/FeaturesSection.mjs +1 -1
  95. package/lib/components/FeaturesSection_deprecated/FeaturesSection.mjs.map +1 -1
  96. package/lib/components/Gallery/Gallery.context.js.map +1 -1
  97. package/lib/components/Gallery/Gallery.context.mjs.map +1 -1
  98. package/lib/components/Gallery/GalleryItem/GalleryItem.js +1 -3
  99. package/lib/components/Gallery/GalleryItem/GalleryItem.js.map +1 -1
  100. package/lib/components/Gallery/GalleryItem/GalleryItem.mjs +1 -3
  101. package/lib/components/Gallery/GalleryItem/GalleryItem.mjs.map +1 -1
  102. package/lib/components/Header/AccountFrame/AccountFrame.js +3 -3
  103. package/lib/components/Header/AccountFrame/AccountFrame.js.map +1 -1
  104. package/lib/components/Header/AccountFrame/AccountFrame.mjs +3 -3
  105. package/lib/components/Header/AccountFrame/AccountFrame.mjs.map +1 -1
  106. package/lib/components/Header/AccountMenu/AccountMenu.js +4 -14
  107. package/lib/components/Header/AccountMenu/AccountMenu.js.map +1 -1
  108. package/lib/components/Header/AccountMenu/AccountMenu.mjs +5 -15
  109. package/lib/components/Header/AccountMenu/AccountMenu.mjs.map +1 -1
  110. package/lib/components/Header/CartModalV2/Item/Item.styles.d.ts +1 -1
  111. package/lib/components/Header/Header.js +18 -19
  112. package/lib/components/Header/Header.js.map +1 -1
  113. package/lib/components/Header/Header.mjs +15 -16
  114. package/lib/components/Header/Header.mjs.map +1 -1
  115. package/lib/components/Header/Header.styles.d.ts +12 -7
  116. package/lib/components/Header/Header.styles.js +32 -10
  117. package/lib/components/Header/Header.styles.js.map +1 -1
  118. package/lib/components/Header/Header.styles.mjs +31 -10
  119. package/lib/components/Header/Header.styles.mjs.map +1 -1
  120. package/lib/components/Header/Header.types.d.ts +6 -30
  121. package/lib/components/Header/Header.types.js +1 -2
  122. package/lib/components/Header/Header.types.js.map +1 -1
  123. package/lib/components/Header/Header.types.mjs +1 -2
  124. package/lib/components/Header/Header.types.mjs.map +1 -1
  125. package/lib/components/Header/IsolatedHeader.d.ts +0 -1
  126. package/lib/components/Header/IsolatedHeader.js +47 -47
  127. package/lib/components/Header/IsolatedHeader.js.map +1 -1
  128. package/lib/components/Header/IsolatedHeader.mjs +48 -49
  129. package/lib/components/Header/IsolatedHeader.mjs.map +1 -1
  130. package/lib/components/Header/LanguageFrame/LanguageFrame.js.map +1 -1
  131. package/lib/components/Header/LanguageFrame/LanguageFrame.mjs.map +1 -1
  132. package/lib/components/Header/MenuItem/MenuItem.styles.d.ts +1 -1
  133. package/lib/components/Header/MenuItem/MenuItem.styles.js +3 -3
  134. package/lib/components/Header/MenuItem/MenuItem.styles.js.map +1 -1
  135. package/lib/components/Header/MenuItem/MenuItem.styles.mjs +3 -3
  136. package/lib/components/Header/MenuItem/MenuItem.styles.mjs.map +1 -1
  137. package/lib/components/Header/MenuItem/MenuItem.types.d.ts +0 -1
  138. package/lib/components/Header/Navigation/MicrositeMenu/MicrositeMenu.js +2 -2
  139. package/lib/components/Header/Navigation/MicrositeMenu/MicrositeMenu.js.map +1 -1
  140. package/lib/components/Header/Navigation/MicrositeMenu/MicrositeMenu.mjs +2 -2
  141. package/lib/components/Header/Navigation/MicrositeMenu/MicrositeMenu.mjs.map +1 -1
  142. package/lib/components/Header/Navigation/MicrositeMenu/MicrositeMenu.styles.d.ts +1 -1
  143. package/lib/components/Header/Navigation/MicrositeMenu/MicrositeMenu.styles.js +5 -7
  144. package/lib/components/Header/Navigation/MicrositeMenu/MicrositeMenu.styles.js.map +1 -1
  145. package/lib/components/Header/Navigation/MicrositeMenu/MicrositeMenu.styles.mjs +5 -7
  146. package/lib/components/Header/Navigation/MicrositeMenu/MicrositeMenu.styles.mjs.map +1 -1
  147. package/lib/components/Header/Navigation/MobileMenu/MobileMenu.styles.d.ts +1 -1
  148. package/lib/components/Header/Navigation/ProMobileMenu/ProMobileMenu.d.ts +1 -1
  149. package/lib/components/Header/Navigation/ProMobileMenu/ProMobileMenu.js +103 -110
  150. package/lib/components/Header/Navigation/ProMobileMenu/ProMobileMenu.js.map +1 -1
  151. package/lib/components/Header/Navigation/ProMobileMenu/ProMobileMenu.mjs +104 -111
  152. package/lib/components/Header/Navigation/ProMobileMenu/ProMobileMenu.mjs.map +1 -1
  153. package/lib/components/Header/Navigation/ProMobileMenu/ProMobileMenu.styles.d.ts +0 -9
  154. package/lib/components/Header/Navigation/ProMobileMenu/ProMobileMenu.styles.js +1 -15
  155. package/lib/components/Header/Navigation/ProMobileMenu/ProMobileMenu.styles.js.map +1 -1
  156. package/lib/components/Header/Navigation/ProMobileMenu/ProMobileMenu.styles.mjs +2 -13
  157. package/lib/components/Header/Navigation/ProMobileMenu/ProMobileMenu.styles.mjs.map +1 -1
  158. package/lib/components/Header/Navigation/ProMobileMenu/ProMobileMenu.types.d.ts +6 -12
  159. package/lib/components/Header/ProHeader/ProHeader.d.ts +5 -9
  160. package/lib/components/Header/ProHeader/ProHeader.js +180 -265
  161. package/lib/components/Header/ProHeader/ProHeader.js.map +1 -1
  162. package/lib/components/Header/ProHeader/ProHeader.mjs +180 -264
  163. package/lib/components/Header/ProHeader/ProHeader.mjs.map +1 -1
  164. package/lib/components/Header/ProHeader/ProHeader.styles.d.ts +25 -30
  165. package/lib/components/Header/ProHeader/ProHeader.styles.js +66 -119
  166. package/lib/components/Header/ProHeader/ProHeader.styles.js.map +1 -1
  167. package/lib/components/Header/ProHeader/ProHeader.styles.mjs +65 -112
  168. package/lib/components/Header/ProHeader/ProHeader.styles.mjs.map +1 -1
  169. package/lib/components/Header/translations/ar.json.js +1 -4
  170. package/lib/components/Header/translations/ar.json.js.map +1 -1
  171. package/lib/components/Header/translations/ar.json.mjs +2 -4
  172. package/lib/components/Header/translations/ar.json.mjs.map +1 -1
  173. package/lib/components/Header/translations/de.json.js +1 -4
  174. package/lib/components/Header/translations/de.json.js.map +1 -1
  175. package/lib/components/Header/translations/de.json.mjs +2 -4
  176. package/lib/components/Header/translations/de.json.mjs.map +1 -1
  177. package/lib/components/Header/translations/el.json.js +1 -4
  178. package/lib/components/Header/translations/el.json.js.map +1 -1
  179. package/lib/components/Header/translations/el.json.mjs +2 -4
  180. package/lib/components/Header/translations/el.json.mjs.map +1 -1
  181. package/lib/components/Header/translations/en.json.js +1 -7
  182. package/lib/components/Header/translations/en.json.js.map +1 -1
  183. package/lib/components/Header/translations/en.json.mjs +2 -6
  184. package/lib/components/Header/translations/en.json.mjs.map +1 -1
  185. package/lib/components/Header/translations/es.json.js +1 -4
  186. package/lib/components/Header/translations/es.json.js.map +1 -1
  187. package/lib/components/Header/translations/es.json.mjs +2 -4
  188. package/lib/components/Header/translations/es.json.mjs.map +1 -1
  189. package/lib/components/Header/translations/fr.json.js +1 -4
  190. package/lib/components/Header/translations/fr.json.js.map +1 -1
  191. package/lib/components/Header/translations/fr.json.mjs +2 -4
  192. package/lib/components/Header/translations/fr.json.mjs.map +1 -1
  193. package/lib/components/Header/translations/it.json.js +1 -4
  194. package/lib/components/Header/translations/it.json.js.map +1 -1
  195. package/lib/components/Header/translations/it.json.mjs +2 -4
  196. package/lib/components/Header/translations/it.json.mjs.map +1 -1
  197. package/lib/components/Header/translations/ja.json.js +1 -4
  198. package/lib/components/Header/translations/ja.json.js.map +1 -1
  199. package/lib/components/Header/translations/ja.json.mjs +2 -4
  200. package/lib/components/Header/translations/ja.json.mjs.map +1 -1
  201. package/lib/components/Header/translations/pt-BR.json.js +1 -4
  202. package/lib/components/Header/translations/pt-BR.json.js.map +1 -1
  203. package/lib/components/Header/translations/pt-BR.json.mjs +2 -4
  204. package/lib/components/Header/translations/pt-BR.json.mjs.map +1 -1
  205. package/lib/components/Header/translations/zh-Hans.json.js +1 -4
  206. package/lib/components/Header/translations/zh-Hans.json.js.map +1 -1
  207. package/lib/components/Header/translations/zh-Hans.json.mjs +2 -4
  208. package/lib/components/Header/translations/zh-Hans.json.mjs.map +1 -1
  209. package/lib/components/Header/translations/zh-Hant-TW.json.js +1 -4
  210. package/lib/components/Header/translations/zh-Hant-TW.json.js.map +1 -1
  211. package/lib/components/Header/translations/zh-Hant-TW.json.mjs +2 -4
  212. package/lib/components/Header/translations/zh-Hant-TW.json.mjs.map +1 -1
  213. package/lib/components/Hero/Hero.js +1 -1
  214. package/lib/components/Hero/Hero.js.map +1 -1
  215. package/lib/components/Hero/Hero.mjs +1 -1
  216. package/lib/components/Hero/Hero.mjs.map +1 -1
  217. package/lib/components/Hero/Hero.styles.d.ts +2 -2
  218. package/lib/components/HeroFadeGallery/HeroFadeGallery.styles.d.ts +1 -1
  219. package/lib/components/HeroVideo/HeroVideo.js +5 -5
  220. package/lib/components/HeroVideo/HeroVideo.js.map +1 -1
  221. package/lib/components/HeroVideo/HeroVideo.mjs +5 -5
  222. package/lib/components/HeroVideo/HeroVideo.mjs.map +1 -1
  223. package/lib/components/HowToUseSection/HowToUseSection.styles.d.ts +2 -2
  224. package/lib/components/ImageCarousel/ImageCarousel.js.map +1 -1
  225. package/lib/components/ImageCarousel/ImageCarousel.mjs.map +1 -1
  226. package/lib/components/LandingPage/Cards/Cards.js +4 -4
  227. package/lib/components/LandingPage/Cards/Cards.js.map +1 -1
  228. package/lib/components/LandingPage/Cards/Cards.mjs +3 -3
  229. package/lib/components/LandingPage/Cards/Cards.mjs.map +1 -1
  230. package/lib/components/LandingPagePro/LandingPagePro.js +1 -4
  231. package/lib/components/LandingPagePro/LandingPagePro.js.map +1 -1
  232. package/lib/components/LandingPagePro/LandingPagePro.mjs +1 -4
  233. package/lib/components/LandingPagePro/LandingPagePro.mjs.map +1 -1
  234. package/lib/components/LandingPagePro/LandingPagePro.styles.d.ts +1 -1
  235. package/lib/components/LandingPageSidebar/LandingPageSidebar.js +8 -8
  236. package/lib/components/LandingPageSidebar/LandingPageSidebar.js.map +1 -1
  237. package/lib/components/LandingPageSidebar/LandingPageSidebar.mjs +8 -8
  238. package/lib/components/LandingPageSidebar/LandingPageSidebar.mjs.map +1 -1
  239. package/lib/components/LayoutRenderer/LayoutRenderer.styles.d.ts +1 -1
  240. package/lib/components/LayoutRendererV1/LayoutRenderer.styles.d.ts +3 -3
  241. package/lib/components/LayoutRendererV2/LayoutRenderer.styles.d.ts +3 -3
  242. package/lib/components/LoaderDots/LoaderDots.d.ts +1 -1
  243. package/lib/components/LoaderDots/LoaderDots.js +1 -3
  244. package/lib/components/LoaderDots/LoaderDots.js.map +1 -1
  245. package/lib/components/LoaderDots/LoaderDots.mjs +1 -3
  246. package/lib/components/LoaderDots/LoaderDots.mjs.map +1 -1
  247. package/lib/components/LoaderDots/LoaderDots.styles.d.ts +1 -2
  248. package/lib/components/LoaderDots/LoaderDots.styles.js +1 -11
  249. package/lib/components/LoaderDots/LoaderDots.styles.js.map +1 -1
  250. package/lib/components/LoaderDots/LoaderDots.styles.mjs +1 -11
  251. package/lib/components/LoaderDots/LoaderDots.styles.mjs.map +1 -1
  252. package/lib/components/LoaderDots/LoaderDots.types.d.ts +0 -2
  253. package/lib/components/MeetUniFiVideoPlayer/MeetUniFiVideoPlayer.js +4 -4
  254. package/lib/components/MeetUniFiVideoPlayer/MeetUniFiVideoPlayer.js.map +1 -1
  255. package/lib/components/MeetUniFiVideoPlayer/MeetUniFiVideoPlayer.mjs +4 -4
  256. package/lib/components/MeetUniFiVideoPlayer/MeetUniFiVideoPlayer.mjs.map +1 -1
  257. package/lib/components/MeetUniFiVideoPlayer/MeetUniFiVideoPlayer.styles.d.ts +1 -1
  258. package/lib/components/MicrositeHero/MicrositeHero.js +2 -2
  259. package/lib/components/MicrositeHero/MicrositeHero.js.map +1 -1
  260. package/lib/components/MicrositeHero/MicrositeHero.mjs +2 -2
  261. package/lib/components/MicrositeHero/MicrositeHero.mjs.map +1 -1
  262. package/lib/components/MicrositeSectionWrap/MicrositeSectionWrap.styles.d.ts +1 -1
  263. package/lib/components/Microsites/Microsites.types.js.map +1 -1
  264. package/lib/components/Microsites/Microsites.types.mjs.map +1 -1
  265. package/lib/components/MobileModal/MobileModal.js +1 -1
  266. package/lib/components/MobileModal/MobileModal.js.map +1 -1
  267. package/lib/components/MobileModal/MobileModal.mjs +1 -1
  268. package/lib/components/MobileModal/MobileModal.mjs.map +1 -1
  269. package/lib/{assets/icons → components/MobileModal/assets}/arrowDown.svg.js +1 -1
  270. package/lib/components/MobileModal/assets/arrowDown.svg.mjs +3 -0
  271. package/lib/components/ModelCompareV3/ModelComparePropertyValueGridItem.js +26 -37
  272. package/lib/components/ModelCompareV3/ModelComparePropertyValueGridItem.js.map +1 -1
  273. package/lib/components/ModelCompareV3/ModelComparePropertyValueGridItem.mjs +26 -37
  274. package/lib/components/ModelCompareV3/ModelComparePropertyValueGridItem.mjs.map +1 -1
  275. package/lib/components/ModelCompareV3/ModelCompareV3.js +1 -1
  276. package/lib/components/ModelCompareV3/ModelCompareV3.js.map +1 -1
  277. package/lib/components/ModelCompareV3/ModelCompareV3.mjs +1 -1
  278. package/lib/components/ModelCompareV3/ModelCompareV3.mjs.map +1 -1
  279. package/lib/components/ModelCompareV3/ModelCompareV3.types.d.ts +14 -7
  280. package/lib/components/ModelCompareV3/StickyGrid/StickyGridItem.js +8 -16
  281. package/lib/components/ModelCompareV3/StickyGrid/StickyGridItem.js.map +1 -1
  282. package/lib/components/ModelCompareV3/StickyGrid/StickyGridItem.mjs +8 -16
  283. package/lib/components/ModelCompareV3/StickyGrid/StickyGridItem.mjs.map +1 -1
  284. package/lib/components/ModelCompareV3/StickyGrid/context.d.ts +3 -3
  285. package/lib/components/ModelCompareV3/StickyGrid/context.js.map +1 -1
  286. package/lib/components/ModelCompareV3/StickyGrid/context.mjs.map +1 -1
  287. package/lib/components/ModelCompareV3/assets/Consoles/bigCompare/ucgUltra.jpg.js +5 -5
  288. package/lib/components/ModelCompareV3/assets/Consoles/bigCompare/ucgUltra.jpg.mjs +2 -2
  289. package/lib/components/ModelCompareV3/assets/Consoles/ucgUltra.jpg.js +1 -1
  290. package/lib/components/ModelCompareV3/assets/Consoles/ucgUltra.jpg.mjs +2 -2
  291. package/lib/components/ModelCompareV3/assets/DoorAccess/{readerLite.jpg.js → door-hub-mini.jpg.js} +2 -2
  292. package/lib/components/ModelCompareV3/assets/DoorAccess/door-hub-mini.jpg.js.map +1 -0
  293. package/lib/components/ModelCompareV3/assets/DoorAccess/door-hub-mini.jpg.mjs +3 -0
  294. package/lib/components/ModelCompareV3/assets/DoorAccess/door-hub-mini.jpg.mjs.map +1 -0
  295. package/lib/components/ModelCompareV3/assets/{WiFi/flagship.jpg.js → DoorAccess/door-hub.jpg.js} +2 -2
  296. package/lib/components/ModelCompareV3/assets/DoorAccess/door-hub.jpg.js.map +1 -0
  297. package/lib/components/ModelCompareV3/assets/DoorAccess/door-hub.jpg.mjs +3 -0
  298. package/lib/components/ModelCompareV3/assets/DoorAccess/door-hub.jpg.mjs.map +1 -0
  299. package/lib/components/ModelCompareV3/assets/DoorAccess/g2-reader-pro.jpg.js +27 -0
  300. package/lib/components/ModelCompareV3/assets/DoorAccess/g2-reader-pro.jpg.js.map +1 -0
  301. package/lib/components/ModelCompareV3/assets/DoorAccess/g2-reader-pro.jpg.mjs +3 -0
  302. package/lib/components/ModelCompareV3/assets/DoorAccess/g2-reader-pro.jpg.mjs.map +1 -0
  303. package/lib/components/ModelCompareV3/assets/DoorAccess/{AccessHub.jpg.js → g2-reader.jpg.js} +2 -2
  304. package/lib/components/ModelCompareV3/assets/DoorAccess/g2-reader.jpg.js.map +1 -0
  305. package/lib/components/ModelCompareV3/assets/DoorAccess/g2-reader.jpg.mjs +3 -0
  306. package/lib/components/ModelCompareV3/assets/DoorAccess/g2-reader.jpg.mjs.map +1 -0
  307. package/lib/components/ModelCompareV3/assets/DoorAccess/g3-reader-flex.jpg.js +27 -0
  308. package/lib/components/ModelCompareV3/assets/DoorAccess/g3-reader-flex.jpg.js.map +1 -0
  309. package/lib/components/ModelCompareV3/assets/DoorAccess/g3-reader-flex.jpg.mjs +3 -0
  310. package/lib/components/ModelCompareV3/assets/DoorAccess/g3-reader-flex.jpg.mjs.map +1 -0
  311. package/lib/components/ModelCompareV3/assets/DoorAccess/g3-reader-pro.jpg.js +27 -0
  312. package/lib/components/ModelCompareV3/assets/DoorAccess/g3-reader-pro.jpg.js.map +1 -0
  313. package/lib/components/ModelCompareV3/assets/DoorAccess/g3-reader-pro.jpg.mjs +3 -0
  314. package/lib/components/ModelCompareV3/assets/DoorAccess/g3-reader-pro.jpg.mjs.map +1 -0
  315. package/lib/components/ModelCompareV3/assets/{WiFi/wall.jpg.js → DoorAccess/g3-reader.jpg.js} +2 -2
  316. package/lib/components/ModelCompareV3/assets/DoorAccess/g3-reader.jpg.js.map +1 -0
  317. package/lib/components/ModelCompareV3/assets/DoorAccess/g3-reader.jpg.mjs +3 -0
  318. package/lib/components/ModelCompareV3/assets/DoorAccess/g3-reader.jpg.mjs.map +1 -0
  319. package/lib/components/ModelCompareV3/assets/DoorAccess/g3-starter-kit-pro.jpg.js +27 -0
  320. package/lib/components/ModelCompareV3/assets/DoorAccess/g3-starter-kit-pro.jpg.js.map +1 -0
  321. package/lib/components/ModelCompareV3/assets/DoorAccess/g3-starter-kit-pro.jpg.mjs +3 -0
  322. package/lib/components/ModelCompareV3/assets/DoorAccess/g3-starter-kit-pro.jpg.mjs.map +1 -0
  323. package/lib/components/ModelCompareV3/assets/DoorAccess/g3-starter-kit.jpg.js +27 -0
  324. package/lib/components/ModelCompareV3/assets/DoorAccess/g3-starter-kit.jpg.js.map +1 -0
  325. package/lib/components/ModelCompareV3/assets/DoorAccess/g3-starter-kit.jpg.mjs +3 -0
  326. package/lib/components/ModelCompareV3/assets/DoorAccess/g3-starter-kit.jpg.mjs.map +1 -0
  327. package/lib/components/ModelCompareV3/assets/DoorAccess/{g2Reader.jpg.js → intercom.jpg.js} +2 -2
  328. package/lib/components/ModelCompareV3/assets/DoorAccess/intercom.jpg.js.map +1 -0
  329. package/lib/components/ModelCompareV3/assets/DoorAccess/intercom.jpg.mjs +3 -0
  330. package/lib/components/ModelCompareV3/assets/DoorAccess/intercom.jpg.mjs.map +1 -0
  331. package/lib/components/ModelCompareV3/assets/DoorAccess/{g2ReaderPro.jpg.js → reader-lite.jpg.js} +2 -2
  332. package/lib/components/ModelCompareV3/assets/DoorAccess/reader-lite.jpg.js.map +1 -0
  333. package/lib/components/ModelCompareV3/assets/DoorAccess/reader-lite.jpg.mjs +3 -0
  334. package/lib/components/ModelCompareV3/assets/DoorAccess/reader-lite.jpg.mjs.map +1 -0
  335. package/lib/components/ModelCompareV3/assets/Switching/industrial.jpg.js +1 -1
  336. package/lib/components/ModelCompareV3/assets/Switching/industrial.jpg.mjs +2 -2
  337. package/lib/components/ModelCompareV3/assets/apple.svg.js +27 -0
  338. package/lib/components/ModelCompareV3/assets/apple.svg.js.map +1 -0
  339. package/lib/components/ModelCompareV3/assets/apple.svg.mjs +3 -0
  340. package/lib/components/ModelCompareV3/assets/apple.svg.mjs.map +1 -0
  341. package/lib/components/ModelCompareV3/assets/contact.svg.js +27 -0
  342. package/lib/components/ModelCompareV3/assets/contact.svg.js.map +1 -0
  343. package/lib/components/ModelCompareV3/assets/contact.svg.mjs +3 -0
  344. package/lib/components/ModelCompareV3/assets/contact.svg.mjs.map +1 -0
  345. package/lib/components/ModelCompareV3/assets/crestron.svg.js +27 -0
  346. package/lib/components/ModelCompareV3/assets/crestron.svg.js.map +1 -0
  347. package/lib/components/ModelCompareV3/assets/crestron.svg.mjs +3 -0
  348. package/lib/components/ModelCompareV3/assets/crestron.svg.mjs.map +1 -0
  349. package/lib/components/ModelCompareV3/data/AccessHubs.js +7 -5
  350. package/lib/components/ModelCompareV3/data/AccessHubs.js.map +1 -1
  351. package/lib/components/ModelCompareV3/data/AccessHubs.mjs +7 -5
  352. package/lib/components/ModelCompareV3/data/AccessHubs.mjs.map +1 -1
  353. package/lib/components/ModelCompareV3/data/CloudGateways.js +3 -3
  354. package/lib/components/ModelCompareV3/data/CloudGateways.mjs +2 -2
  355. package/lib/components/ModelCompareV3/data/EnterpriseSwitching.js +3 -2
  356. package/lib/components/ModelCompareV3/data/EnterpriseSwitching.js.map +1 -1
  357. package/lib/components/ModelCompareV3/data/EnterpriseSwitching.mjs +3 -2
  358. package/lib/components/ModelCompareV3/data/EnterpriseSwitching.mjs.map +1 -1
  359. package/lib/components/ModelCompareV3/data/ProfessionalMaxSwitching.js +10 -3
  360. package/lib/components/ModelCompareV3/data/ProfessionalMaxSwitching.js.map +1 -1
  361. package/lib/components/ModelCompareV3/data/ProfessionalMaxSwitching.mjs +10 -3
  362. package/lib/components/ModelCompareV3/data/ProfessionalMaxSwitching.mjs.map +1 -1
  363. package/lib/components/ModelCompareV3/data/Readers.js +15 -9
  364. package/lib/components/ModelCompareV3/data/Readers.js.map +1 -1
  365. package/lib/components/ModelCompareV3/data/Readers.mjs +15 -9
  366. package/lib/components/ModelCompareV3/data/Readers.mjs.map +1 -1
  367. package/lib/components/ModelCompareV3/data/StarterKit.js +6 -2
  368. package/lib/components/ModelCompareV3/data/StarterKit.js.map +1 -1
  369. package/lib/components/ModelCompareV3/data/StarterKit.mjs +6 -2
  370. package/lib/components/ModelCompareV3/data/StarterKit.mjs.map +1 -1
  371. package/lib/components/ModelCompareV3/data/Switching.js +3 -2
  372. package/lib/components/ModelCompareV3/data/Switching.js.map +1 -1
  373. package/lib/components/ModelCompareV3/data/Switching.mjs +3 -2
  374. package/lib/components/ModelCompareV3/data/Switching.mjs.map +1 -1
  375. package/lib/components/ModelCompareV3/data/index.d.ts +48 -50
  376. package/lib/components/ModelCompareV3/data/index.js +96 -102
  377. package/lib/components/ModelCompareV3/data/index.js.map +1 -1
  378. package/lib/components/ModelCompareV3/data/index.mjs +96 -102
  379. package/lib/components/ModelCompareV3/data/index.mjs.map +1 -1
  380. package/lib/components/ModelCompareV3/data/products/aggregation.js +7 -0
  381. package/lib/components/ModelCompareV3/data/products/aggregation.js.map +1 -1
  382. package/lib/components/ModelCompareV3/data/products/aggregation.mjs +7 -0
  383. package/lib/components/ModelCompareV3/data/products/aggregation.mjs.map +1 -1
  384. package/lib/components/ModelCompareV3/data/products/cloudKeyEnterprise.js +1 -1
  385. package/lib/components/ModelCompareV3/data/products/cloudKeyEnterprise.js.map +1 -1
  386. package/lib/components/ModelCompareV3/data/products/cloudKeyEnterprise.mjs +1 -1
  387. package/lib/components/ModelCompareV3/data/products/cloudKeyEnterprise.mjs.map +1 -1
  388. package/lib/components/ModelCompareV3/data/products/{wifiWall.d.ts → doorHub.d.ts} +1 -1
  389. package/lib/components/ModelCompareV3/data/products/{accessHub.js → doorHub.js} +21 -22
  390. package/lib/components/ModelCompareV3/data/products/doorHub.js.map +1 -0
  391. package/lib/components/ModelCompareV3/data/products/{accessHub.mjs → doorHub.mjs} +21 -22
  392. package/lib/components/ModelCompareV3/data/products/doorHub.mjs.map +1 -0
  393. package/lib/components/ModelCompareV3/data/products/{wifiFlagship.d.ts → doorHubMini.d.ts} +1 -1
  394. package/lib/components/ModelCompareV3/data/products/doorHubMini.js +69 -0
  395. package/lib/components/ModelCompareV3/data/products/doorHubMini.js.map +1 -0
  396. package/lib/components/ModelCompareV3/data/products/doorHubMini.mjs +61 -0
  397. package/lib/components/ModelCompareV3/data/products/doorHubMini.mjs.map +1 -0
  398. package/lib/components/ModelCompareV3/data/products/elevatorStarterKit.js +8 -0
  399. package/lib/components/ModelCompareV3/data/products/elevatorStarterKit.js.map +1 -1
  400. package/lib/components/ModelCompareV3/data/products/elevatorStarterKit.mjs +8 -0
  401. package/lib/components/ModelCompareV3/data/products/elevatorStarterKit.mjs.map +1 -1
  402. package/lib/components/ModelCompareV3/data/products/enterpriseAggregation.js +7 -0
  403. package/lib/components/ModelCompareV3/data/products/enterpriseAggregation.js.map +1 -1
  404. package/lib/components/ModelCompareV3/data/products/enterpriseAggregation.mjs +7 -0
  405. package/lib/components/ModelCompareV3/data/products/enterpriseAggregation.mjs.map +1 -1
  406. package/lib/components/ModelCompareV3/data/products/enterpriseCampus24PoE.js +7 -0
  407. package/lib/components/ModelCompareV3/data/products/enterpriseCampus24PoE.js.map +1 -1
  408. package/lib/components/ModelCompareV3/data/products/enterpriseCampus24PoE.mjs +7 -0
  409. package/lib/components/ModelCompareV3/data/products/enterpriseCampus24PoE.mjs.map +1 -1
  410. package/lib/components/ModelCompareV3/data/products/enterpriseCampus48PoE.js +7 -0
  411. package/lib/components/ModelCompareV3/data/products/enterpriseCampus48PoE.js.map +1 -1
  412. package/lib/components/ModelCompareV3/data/products/enterpriseCampus48PoE.mjs +7 -0
  413. package/lib/components/ModelCompareV3/data/products/enterpriseCampus48PoE.mjs.map +1 -1
  414. package/lib/components/ModelCompareV3/data/products/g2Reader.js +23 -8
  415. package/lib/components/ModelCompareV3/data/products/g2Reader.js.map +1 -1
  416. package/lib/components/ModelCompareV3/data/products/g2Reader.mjs +23 -8
  417. package/lib/components/ModelCompareV3/data/products/g2Reader.mjs.map +1 -1
  418. package/lib/components/ModelCompareV3/data/products/g2ReaderPro.js +25 -9
  419. package/lib/components/ModelCompareV3/data/products/g2ReaderPro.js.map +1 -1
  420. package/lib/components/ModelCompareV3/data/products/g2ReaderPro.mjs +25 -9
  421. package/lib/components/ModelCompareV3/data/products/g2ReaderPro.mjs.map +1 -1
  422. package/lib/components/ModelCompareV3/data/products/g2StarterKit.js +8 -0
  423. package/lib/components/ModelCompareV3/data/products/g2StarterKit.js.map +1 -1
  424. package/lib/components/ModelCompareV3/data/products/g2StarterKit.mjs +8 -0
  425. package/lib/components/ModelCompareV3/data/products/g2StarterKit.mjs.map +1 -1
  426. package/lib/components/ModelCompareV3/data/products/g2StarterKitPro.js +8 -0
  427. package/lib/components/ModelCompareV3/data/products/g2StarterKitPro.js.map +1 -1
  428. package/lib/components/ModelCompareV3/data/products/g2StarterKitPro.mjs +8 -0
  429. package/lib/components/ModelCompareV3/data/products/g2StarterKitPro.mjs.map +1 -1
  430. package/lib/components/ModelCompareV3/data/products/{wifiMegaCapacity.d.ts → g3Reader.d.ts} +1 -1
  431. package/lib/components/ModelCompareV3/data/products/g3Reader.js +104 -0
  432. package/lib/components/ModelCompareV3/data/products/g3Reader.js.map +1 -0
  433. package/lib/components/ModelCompareV3/data/products/g3Reader.mjs +96 -0
  434. package/lib/components/ModelCompareV3/data/products/g3Reader.mjs.map +1 -0
  435. package/lib/components/ModelCompareV3/data/products/{wifiFlexibleOutdoor.d.ts → g3ReaderFlex.d.ts} +1 -1
  436. package/lib/components/ModelCompareV3/data/products/g3ReaderFlex.js +104 -0
  437. package/lib/components/ModelCompareV3/data/products/g3ReaderFlex.js.map +1 -0
  438. package/lib/components/ModelCompareV3/data/products/g3ReaderFlex.mjs +96 -0
  439. package/lib/components/ModelCompareV3/data/products/g3ReaderFlex.mjs.map +1 -0
  440. package/lib/components/ModelCompareV3/data/products/g3ReaderPro.d.ts +2 -0
  441. package/lib/components/ModelCompareV3/data/products/g3ReaderPro.js +105 -0
  442. package/lib/components/ModelCompareV3/data/products/g3ReaderPro.js.map +1 -0
  443. package/lib/components/ModelCompareV3/data/products/g3ReaderPro.mjs +97 -0
  444. package/lib/components/ModelCompareV3/data/products/g3ReaderPro.mjs.map +1 -0
  445. package/lib/components/ModelCompareV3/data/products/g3StarterKit.d.ts +2 -0
  446. package/lib/components/ModelCompareV3/data/products/g3StarterKit.js +63 -0
  447. package/lib/components/ModelCompareV3/data/products/g3StarterKit.js.map +1 -0
  448. package/lib/components/ModelCompareV3/data/products/g3StarterKit.mjs +55 -0
  449. package/lib/components/ModelCompareV3/data/products/g3StarterKit.mjs.map +1 -0
  450. package/lib/components/ModelCompareV3/data/products/g3StarterKitPro.d.ts +2 -0
  451. package/lib/components/ModelCompareV3/data/products/g3StarterKitPro.js +62 -0
  452. package/lib/components/ModelCompareV3/data/products/g3StarterKitPro.js.map +1 -0
  453. package/lib/components/ModelCompareV3/data/products/g3StarterKitPro.mjs +54 -0
  454. package/lib/components/ModelCompareV3/data/products/g3StarterKitPro.mjs.map +1 -0
  455. package/lib/components/ModelCompareV3/data/products/gateAccessStarterKit.js +7 -0
  456. package/lib/components/ModelCompareV3/data/products/gateAccessStarterKit.js.map +1 -1
  457. package/lib/components/ModelCompareV3/data/products/gateAccessStarterKit.mjs +7 -0
  458. package/lib/components/ModelCompareV3/data/products/gateAccessStarterKit.mjs.map +1 -1
  459. package/lib/components/ModelCompareV3/data/products/highCapacityAggregation.js +7 -0
  460. package/lib/components/ModelCompareV3/data/products/highCapacityAggregation.js.map +1 -1
  461. package/lib/components/ModelCompareV3/data/products/highCapacityAggregation.mjs +7 -0
  462. package/lib/components/ModelCompareV3/data/products/highCapacityAggregation.mjs.map +1 -1
  463. package/lib/components/ModelCompareV3/data/products/industrial.js +1 -1
  464. package/lib/components/ModelCompareV3/data/products/industrial.mjs +1 -1
  465. package/lib/components/ModelCompareV3/data/products/intercom.d.ts +2 -0
  466. package/lib/components/ModelCompareV3/data/products/intercom.js +105 -0
  467. package/lib/components/ModelCompareV3/data/products/intercom.js.map +1 -0
  468. package/lib/components/ModelCompareV3/data/products/intercom.mjs +97 -0
  469. package/lib/components/ModelCompareV3/data/products/intercom.mjs.map +1 -0
  470. package/lib/components/ModelCompareV3/data/products/missionCritical.js +7 -0
  471. package/lib/components/ModelCompareV3/data/products/missionCritical.js.map +1 -1
  472. package/lib/components/ModelCompareV3/data/products/missionCritical.mjs +7 -0
  473. package/lib/components/ModelCompareV3/data/products/missionCritical.mjs.map +1 -1
  474. package/lib/components/ModelCompareV3/data/products/professionalMax16.js +7 -0
  475. package/lib/components/ModelCompareV3/data/products/professionalMax16.js.map +1 -1
  476. package/lib/components/ModelCompareV3/data/products/professionalMax16.mjs +7 -0
  477. package/lib/components/ModelCompareV3/data/products/professionalMax16.mjs.map +1 -1
  478. package/lib/components/ModelCompareV3/data/products/professionalMax16PoE.js +7 -0
  479. package/lib/components/ModelCompareV3/data/products/professionalMax16PoE.js.map +1 -1
  480. package/lib/components/ModelCompareV3/data/products/professionalMax16PoE.mjs +7 -0
  481. package/lib/components/ModelCompareV3/data/products/professionalMax16PoE.mjs.map +1 -1
  482. package/lib/components/ModelCompareV3/data/products/professionalMax24.js +7 -0
  483. package/lib/components/ModelCompareV3/data/products/professionalMax24.js.map +1 -1
  484. package/lib/components/ModelCompareV3/data/products/professionalMax24.mjs +7 -0
  485. package/lib/components/ModelCompareV3/data/products/professionalMax24.mjs.map +1 -1
  486. package/lib/components/ModelCompareV3/data/products/professionalMax24PoE.js +7 -0
  487. package/lib/components/ModelCompareV3/data/products/professionalMax24PoE.js.map +1 -1
  488. package/lib/components/ModelCompareV3/data/products/professionalMax24PoE.mjs +7 -0
  489. package/lib/components/ModelCompareV3/data/products/professionalMax24PoE.mjs.map +1 -1
  490. package/lib/components/ModelCompareV3/data/products/professionalMax48.js +7 -0
  491. package/lib/components/ModelCompareV3/data/products/professionalMax48.js.map +1 -1
  492. package/lib/components/ModelCompareV3/data/products/professionalMax48.mjs +7 -0
  493. package/lib/components/ModelCompareV3/data/products/professionalMax48.mjs.map +1 -1
  494. package/lib/components/ModelCompareV3/data/products/professionalMax48PoE.js +7 -0
  495. package/lib/components/ModelCompareV3/data/products/professionalMax48PoE.js.map +1 -1
  496. package/lib/components/ModelCompareV3/data/products/professionalMax48PoE.mjs +7 -0
  497. package/lib/components/ModelCompareV3/data/products/professionalMax48PoE.mjs.map +1 -1
  498. package/lib/components/ModelCompareV3/data/products/readerLite.js +23 -8
  499. package/lib/components/ModelCompareV3/data/products/readerLite.js.map +1 -1
  500. package/lib/components/ModelCompareV3/data/products/readerLite.mjs +23 -8
  501. package/lib/components/ModelCompareV3/data/products/readerLite.mjs.map +1 -1
  502. package/lib/components/ModelCompareV3/data/products/switchesEnterprise.js +8 -0
  503. package/lib/components/ModelCompareV3/data/products/switchesEnterprise.js.map +1 -1
  504. package/lib/components/ModelCompareV3/data/products/switchesEnterprise.mjs +8 -0
  505. package/lib/components/ModelCompareV3/data/products/switchesEnterprise.mjs.map +1 -1
  506. package/lib/components/ModelCompareV3/data/products/switchesProfessional.js +7 -0
  507. package/lib/components/ModelCompareV3/data/products/switchesProfessional.js.map +1 -1
  508. package/lib/components/ModelCompareV3/data/products/switchesProfessional.mjs +7 -0
  509. package/lib/components/ModelCompareV3/data/products/switchesProfessional.mjs.map +1 -1
  510. package/lib/components/ModelCompareV3/data/products/switchesProfessionalMax.js +10 -1
  511. package/lib/components/ModelCompareV3/data/products/switchesProfessionalMax.js.map +1 -1
  512. package/lib/components/ModelCompareV3/data/products/switchesProfessionalMax.mjs +10 -1
  513. package/lib/components/ModelCompareV3/data/products/switchesProfessionalMax.mjs.map +1 -1
  514. package/lib/components/ModelCompareV3/data/products/switchesStandard.js +7 -0
  515. package/lib/components/ModelCompareV3/data/products/switchesStandard.js.map +1 -1
  516. package/lib/components/ModelCompareV3/data/products/switchesStandard.mjs +7 -0
  517. package/lib/components/ModelCompareV3/data/products/switchesStandard.mjs.map +1 -1
  518. package/lib/components/ModelCompareV3/data/products/ucgUltra.js +1 -1
  519. package/lib/components/ModelCompareV3/data/products/ucgUltra.mjs +1 -1
  520. package/lib/components/ModelCompareV3/data/products/udw.js +0 -1
  521. package/lib/components/ModelCompareV3/data/products/udw.js.map +1 -1
  522. package/lib/components/ModelCompareV3/data/products/udw.mjs +0 -1
  523. package/lib/components/ModelCompareV3/data/products/udw.mjs.map +1 -1
  524. package/lib/components/ModelCompareV3/data/properties/appleTouchPassSupport.d.ts +2 -0
  525. package/lib/components/ModelCompareV3/data/properties/appleTouchPassSupport.js +18 -0
  526. package/lib/components/ModelCompareV3/data/properties/appleTouchPassSupport.js.map +1 -0
  527. package/lib/components/ModelCompareV3/data/properties/appleTouchPassSupport.mjs +10 -0
  528. package/lib/components/ModelCompareV3/data/properties/appleTouchPassSupport.mjs.map +1 -0
  529. package/lib/components/ModelCompareV3/data/properties/crestronNaxNvxCertified.d.ts +2 -0
  530. package/lib/components/ModelCompareV3/data/properties/crestronNaxNvxCertified.js +18 -0
  531. package/lib/components/ModelCompareV3/data/properties/crestronNaxNvxCertified.js.map +1 -0
  532. package/lib/components/ModelCompareV3/data/properties/crestronNaxNvxCertified.mjs +10 -0
  533. package/lib/components/ModelCompareV3/data/properties/crestronNaxNvxCertified.mjs.map +1 -0
  534. package/lib/components/ModelCompareV3/data/properties/{intercom.d.ts → directory.d.ts} +1 -1
  535. package/lib/components/ModelCompareV3/data/properties/directory.js +18 -0
  536. package/lib/components/ModelCompareV3/data/properties/directory.js.map +1 -0
  537. package/lib/components/ModelCompareV3/data/properties/directory.mjs +10 -0
  538. package/lib/components/ModelCompareV3/data/properties/directory.mjs.map +1 -0
  539. package/lib/components/ModelCompareV3/data/properties/index.d.ts +5 -2
  540. package/lib/components/ModelCompareV3/data/properties/index.js +10 -4
  541. package/lib/components/ModelCompareV3/data/properties/index.js.map +1 -1
  542. package/lib/components/ModelCompareV3/data/properties/index.mjs +5 -2
  543. package/lib/components/ModelCompareV3/data/properties/index.mjs.map +1 -1
  544. package/lib/components/ModelCompareV3/data/properties/twoWayIntercom.d.ts +2 -0
  545. package/lib/components/ModelCompareV3/data/properties/{intercom.js → twoWayIntercom.js} +5 -5
  546. package/lib/components/ModelCompareV3/data/properties/twoWayIntercom.js.map +1 -0
  547. package/lib/components/ModelCompareV3/data/properties/twoWayIntercom.mjs +10 -0
  548. package/lib/components/ModelCompareV3/data/properties/twoWayIntercom.mjs.map +1 -0
  549. package/lib/components/ModelCompareV3/translations/ar.json.js +75 -14
  550. package/lib/components/ModelCompareV3/translations/ar.json.js.map +1 -1
  551. package/lib/components/ModelCompareV3/translations/ar.json.mjs +75 -14
  552. package/lib/components/ModelCompareV3/translations/ar.json.mjs.map +1 -1
  553. package/lib/components/ModelCompareV3/translations/de.json.js +70 -9
  554. package/lib/components/ModelCompareV3/translations/de.json.js.map +1 -1
  555. package/lib/components/ModelCompareV3/translations/de.json.mjs +70 -9
  556. package/lib/components/ModelCompareV3/translations/de.json.mjs.map +1 -1
  557. package/lib/components/ModelCompareV3/translations/el.json.js +72 -11
  558. package/lib/components/ModelCompareV3/translations/el.json.js.map +1 -1
  559. package/lib/components/ModelCompareV3/translations/el.json.mjs +72 -11
  560. package/lib/components/ModelCompareV3/translations/el.json.mjs.map +1 -1
  561. package/lib/components/ModelCompareV3/translations/en.json.js +45 -65
  562. package/lib/components/ModelCompareV3/translations/en.json.js.map +1 -1
  563. package/lib/components/ModelCompareV3/translations/en.json.mjs +45 -65
  564. package/lib/components/ModelCompareV3/translations/en.json.mjs.map +1 -1
  565. package/lib/components/ModelCompareV3/translations/es.json.js +70 -9
  566. package/lib/components/ModelCompareV3/translations/es.json.js.map +1 -1
  567. package/lib/components/ModelCompareV3/translations/es.json.mjs +70 -9
  568. package/lib/components/ModelCompareV3/translations/es.json.mjs.map +1 -1
  569. package/lib/components/ModelCompareV3/translations/fr.json.js +70 -9
  570. package/lib/components/ModelCompareV3/translations/fr.json.js.map +1 -1
  571. package/lib/components/ModelCompareV3/translations/fr.json.mjs +70 -9
  572. package/lib/components/ModelCompareV3/translations/fr.json.mjs.map +1 -1
  573. package/lib/components/ModelCompareV3/translations/it.json.js +66 -5
  574. package/lib/components/ModelCompareV3/translations/it.json.js.map +1 -1
  575. package/lib/components/ModelCompareV3/translations/it.json.mjs +66 -5
  576. package/lib/components/ModelCompareV3/translations/it.json.mjs.map +1 -1
  577. package/lib/components/ModelCompareV3/translations/ja.json.js +72 -11
  578. package/lib/components/ModelCompareV3/translations/ja.json.js.map +1 -1
  579. package/lib/components/ModelCompareV3/translations/ja.json.mjs +72 -11
  580. package/lib/components/ModelCompareV3/translations/ja.json.mjs.map +1 -1
  581. package/lib/components/ModelCompareV3/translations/pt-BR.json.js +71 -10
  582. package/lib/components/ModelCompareV3/translations/pt-BR.json.js.map +1 -1
  583. package/lib/components/ModelCompareV3/translations/pt-BR.json.mjs +71 -10
  584. package/lib/components/ModelCompareV3/translations/pt-BR.json.mjs.map +1 -1
  585. package/lib/components/ModelCompareV3/translations/useModelCompareTranslation.d.ts +2 -2
  586. package/lib/components/ModelCompareV3/translations/zh-Hans.json.js +73 -12
  587. package/lib/components/ModelCompareV3/translations/zh-Hans.json.js.map +1 -1
  588. package/lib/components/ModelCompareV3/translations/zh-Hans.json.mjs +73 -12
  589. package/lib/components/ModelCompareV3/translations/zh-Hans.json.mjs.map +1 -1
  590. package/lib/components/ModelCompareV3/translations/zh-Hant-TW.json.js +78 -17
  591. package/lib/components/ModelCompareV3/translations/zh-Hant-TW.json.js.map +1 -1
  592. package/lib/components/ModelCompareV3/translations/zh-Hant-TW.json.mjs +78 -17
  593. package/lib/components/ModelCompareV3/translations/zh-Hant-TW.json.mjs.map +1 -1
  594. package/lib/components/PriceRangeSlider/PriceRangeSlider.types.d.ts +2 -2
  595. package/lib/components/PriceRangeSlider/PriceRangeSlider.types.js.map +1 -1
  596. package/lib/components/PriceRangeSlider/PriceRangeSlider.types.mjs.map +1 -1
  597. package/lib/components/ProductCard/ProductCard.js +1 -1
  598. package/lib/components/ProductCard/ProductCard.js.map +1 -1
  599. package/lib/components/ProductCard/ProductCard.mjs +2 -2
  600. package/lib/components/ProductCard/ProductCard.mjs.map +1 -1
  601. package/lib/components/ProductCardPopup/ProductCardPopup.js +2 -2
  602. package/lib/components/ProductCardPopup/ProductCardPopup.js.map +1 -1
  603. package/lib/components/ProductCardPopup/ProductCardPopup.mjs +2 -2
  604. package/lib/components/ProductCardPopup/ProductCardPopup.mjs.map +1 -1
  605. package/lib/components/ProductSectionNavigation/ProductSectionNavigation.styles.d.ts +1 -1
  606. package/lib/components/ProductSectionNavigationV2/ProductSectionNavigation.styles.d.ts +1 -1
  607. package/lib/components/ProductSectionTabs/ProductSectionTabs.js +1 -6
  608. package/lib/components/ProductSectionTabs/ProductSectionTabs.js.map +1 -1
  609. package/lib/components/ProductSectionTabs/ProductSectionTabs.mjs +1 -6
  610. package/lib/components/ProductSectionTabs/ProductSectionTabs.mjs.map +1 -1
  611. package/lib/components/ProductTechSpecs/ProductTechSpecs.styles.d.ts +2 -2
  612. package/lib/components/ProductWizard/ProductWizard.js +3 -3
  613. package/lib/components/ProductWizard/ProductWizard.js.map +1 -1
  614. package/lib/components/ProductWizard/ProductWizard.mjs +3 -3
  615. package/lib/components/ProductWizard/ProductWizard.mjs.map +1 -1
  616. package/lib/components/ProductWizardFootnotes/ProductWizardFootnotes.js +4 -17
  617. package/lib/components/ProductWizardFootnotes/ProductWizardFootnotes.js.map +1 -1
  618. package/lib/components/ProductWizardFootnotes/ProductWizardFootnotes.mjs +4 -17
  619. package/lib/components/ProductWizardFootnotes/ProductWizardFootnotes.mjs.map +1 -1
  620. package/lib/components/QuantityControls/QuantityControls.js +2 -2
  621. package/lib/components/QuantityControls/QuantityControls.js.map +1 -1
  622. package/lib/components/QuantityControls/QuantityControls.mjs +2 -2
  623. package/lib/components/QuantityControls/QuantityControls.mjs.map +1 -1
  624. package/lib/components/QuantityControls/QuantityControls.types.d.ts +1 -1
  625. package/lib/components/QuantityInput/QuantityInput.js +1 -6
  626. package/lib/components/QuantityInput/QuantityInput.js.map +1 -1
  627. package/lib/components/QuantityInput/QuantityInput.mjs +1 -6
  628. package/lib/components/QuantityInput/QuantityInput.mjs.map +1 -1
  629. package/lib/components/ResourceCalculatorV1/ComputeResourceCalculator/ComputeResourceCalculator.constants.js +800 -147
  630. package/lib/components/ResourceCalculatorV1/ComputeResourceCalculator/ComputeResourceCalculator.constants.js.map +1 -1
  631. package/lib/components/ResourceCalculatorV1/ComputeResourceCalculator/ComputeResourceCalculator.constants.mjs +797 -147
  632. package/lib/components/ResourceCalculatorV1/ComputeResourceCalculator/ComputeResourceCalculator.constants.mjs.map +1 -1
  633. package/lib/components/ResourceCalculatorV1/ComputeResourceCalculator/ComputeResourceCalculator.js +4 -4
  634. package/lib/components/ResourceCalculatorV1/ComputeResourceCalculator/ComputeResourceCalculator.js.map +1 -1
  635. package/lib/components/ResourceCalculatorV1/ComputeResourceCalculator/ComputeResourceCalculator.mjs +4 -4
  636. package/lib/components/ResourceCalculatorV1/ComputeResourceCalculator/ComputeResourceCalculator.mjs.map +1 -1
  637. package/lib/components/ResourceCalculatorV1/ComputeResourceCalculator/ComputeResourceCalculator.types.d.ts +5 -2
  638. package/lib/components/ResourceCalculatorV1/ComputeResourceCalculator/ComputeResourceCalculator.types.js +4 -0
  639. package/lib/components/ResourceCalculatorV1/ComputeResourceCalculator/ComputeResourceCalculator.types.js.map +1 -1
  640. package/lib/components/ResourceCalculatorV1/ComputeResourceCalculator/ComputeResourceCalculator.types.mjs +4 -0
  641. package/lib/components/ResourceCalculatorV1/ComputeResourceCalculator/ComputeResourceCalculator.types.mjs.map +1 -1
  642. package/lib/components/ResourceCalculatorV1/ComputeResourceCalculator/components/DeviceSelect/DeviceSelect.js +120 -34
  643. package/lib/components/ResourceCalculatorV1/ComputeResourceCalculator/components/DeviceSelect/DeviceSelect.js.map +1 -1
  644. package/lib/components/ResourceCalculatorV1/ComputeResourceCalculator/components/DeviceSelect/DeviceSelect.mjs +120 -34
  645. package/lib/components/ResourceCalculatorV1/ComputeResourceCalculator/components/DeviceSelect/DeviceSelect.mjs.map +1 -1
  646. package/lib/components/ResourceCalculatorV1/ComputeResourceCalculator/components/DeviceSelect/DeviceSelect.styles.d.ts +16 -2
  647. package/lib/components/ResourceCalculatorV1/ComputeResourceCalculator/components/DeviceSelect/DeviceSelect.styles.js +54 -12
  648. package/lib/components/ResourceCalculatorV1/ComputeResourceCalculator/components/DeviceSelect/DeviceSelect.styles.js.map +1 -1
  649. package/lib/components/ResourceCalculatorV1/ComputeResourceCalculator/components/DeviceSelect/DeviceSelect.styles.mjs +50 -11
  650. package/lib/components/ResourceCalculatorV1/ComputeResourceCalculator/components/DeviceSelect/DeviceSelect.styles.mjs.map +1 -1
  651. package/lib/components/ResourceCalculatorV1/ComputeResourceCalculator/components/DeviceSelect/assets/ArrowLeftPrimary.svg.js +5 -5
  652. package/lib/components/ResourceCalculatorV1/ComputeResourceCalculator/components/DeviceSelect/assets/ArrowRightPrimary.svg.js +5 -5
  653. package/lib/components/ResourceCalculatorV1/ComputeResourceCalculator/components/InputCard/InputCard.js +1 -1
  654. package/lib/components/ResourceCalculatorV1/ComputeResourceCalculator/components/InputCard/InputCard.mjs +1 -1
  655. package/lib/components/ResourceCalculatorV1/ComputeResourceCalculator/components/InputCard/InputSections/CounterSection.js +2 -2
  656. package/lib/components/ResourceCalculatorV1/ComputeResourceCalculator/components/InputCard/InputSections/CounterSection.mjs +2 -2
  657. package/lib/components/ResourceCalculatorV1/ComputeResourceCalculator/components/InputCard/assets/attention.svg.js +1 -1
  658. package/lib/components/ResourceCalculatorV1/ComputeResourceCalculator/components/InputCard/assets/attention.svg.mjs +2 -2
  659. package/lib/components/ResourceCalculatorV1/ComputeResourceCalculator/components/InputCard/assets/minus.svg.js +1 -1
  660. package/lib/components/ResourceCalculatorV1/ComputeResourceCalculator/components/InputCard/assets/minus.svg.mjs +2 -2
  661. package/lib/components/ResourceCalculatorV1/ComputeResourceCalculator/components/InputCard/assets/plus.svg.js +1 -1
  662. package/lib/components/ResourceCalculatorV1/ComputeResourceCalculator/components/InputCard/assets/plus.svg.mjs +2 -2
  663. package/lib/components/ResourceCalculatorV1/ComputeResourceCalculator/components/ProgressBarChart/ProgressBarChart.js +1 -1
  664. package/lib/components/ResourceCalculatorV1/ComputeResourceCalculator/components/ProgressBarChart/ProgressBarChart.mjs +1 -1
  665. package/lib/components/ResourceCalculatorV1/ComputeResourceCalculator/components/ProgressBarChart/assets/attention.svg.js +1 -1
  666. package/lib/components/ResourceCalculatorV1/ComputeResourceCalculator/components/ProgressBarChart/assets/attention.svg.mjs +2 -2
  667. package/lib/components/ResourceCalculatorV1/ComputeResourceCalculator/useComputeResourceCalculator.js +1 -1
  668. package/lib/components/ResourceCalculatorV1/ComputeResourceCalculator/useComputeResourceCalculator.js.map +1 -1
  669. package/lib/components/ResourceCalculatorV1/ComputeResourceCalculator/useComputeResourceCalculator.mjs +1 -1
  670. package/lib/components/ResourceCalculatorV1/ComputeResourceCalculator/useComputeResourceCalculator.mjs.map +1 -1
  671. package/lib/components/ResourceCalculatorV1/PoeCalculator/components/PoeConsumerConfigurator/PoeConsumerSelectModal/PoeConsumerSelectModal.js +2 -2
  672. package/lib/components/ResourceCalculatorV1/PoeCalculator/components/PoeConsumerConfigurator/PoeConsumerSelectModal/PoeConsumerSelectModal.mjs +2 -2
  673. package/lib/components/ResourceCalculatorV1/PoeCalculator/components/PoeConsumerConfigurator/assets/minus.svg.js +1 -1
  674. package/lib/components/ResourceCalculatorV1/PoeCalculator/components/PoeConsumerConfigurator/assets/minus.svg.mjs +2 -2
  675. package/lib/components/ResourceCalculatorV1/PoeCalculator/components/PoeConsumerConfigurator/assets/plus.svg.js +1 -1
  676. package/lib/components/ResourceCalculatorV1/PoeCalculator/components/PoeConsumerConfigurator/assets/plus.svg.mjs +2 -2
  677. package/lib/components/ResourceCalculatorV1/assets/consoles/efg.png.js +27 -0
  678. package/lib/components/ResourceCalculatorV1/assets/consoles/efg.png.js.map +1 -0
  679. package/lib/components/ResourceCalculatorV1/assets/consoles/efg.png.mjs +3 -0
  680. package/lib/components/ResourceCalculatorV1/assets/consoles/efg.png.mjs.map +1 -0
  681. package/lib/components/ResourceCalculatorV1/assets/consoles/envr.png.js +27 -0
  682. package/lib/components/ResourceCalculatorV1/assets/consoles/envr.png.js.map +1 -0
  683. package/lib/components/ResourceCalculatorV1/assets/consoles/envr.png.mjs +3 -0
  684. package/lib/components/ResourceCalculatorV1/assets/consoles/envr.png.mjs.map +1 -0
  685. package/lib/components/ResourceCalculatorV1/assets/consoles/ucg-max.png.js +27 -0
  686. package/lib/components/ResourceCalculatorV1/assets/consoles/ucg-max.png.js.map +1 -0
  687. package/lib/components/ResourceCalculatorV1/assets/consoles/ucg-max.png.mjs +3 -0
  688. package/lib/components/ResourceCalculatorV1/assets/consoles/ucg-max.png.mjs.map +1 -0
  689. package/lib/components/ResourceCalculatorV1/translations/en.json.js +9 -5
  690. package/lib/components/ResourceCalculatorV1/translations/en.json.js.map +1 -1
  691. package/lib/components/ResourceCalculatorV1/translations/en.json.mjs +9 -5
  692. package/lib/components/ResourceCalculatorV1/translations/en.json.mjs.map +1 -1
  693. package/lib/components/ResourceCalculatorV1/translations/useResourceCalculatorTranslation.d.ts +2 -2
  694. package/lib/components/ScrollWrapper/ScrollWrapper.d.ts +1 -1
  695. package/lib/components/ScrollWrapper/ScrollWrapper.js +8 -16
  696. package/lib/components/ScrollWrapper/ScrollWrapper.js.map +1 -1
  697. package/lib/components/ScrollWrapper/ScrollWrapper.mjs +8 -16
  698. package/lib/components/ScrollWrapper/ScrollWrapper.mjs.map +1 -1
  699. package/lib/components/ScrollWrapper/ScrollWrapper.styles.js +64 -87
  700. package/lib/components/ScrollWrapper/ScrollWrapper.styles.js.map +1 -1
  701. package/lib/components/ScrollWrapper/ScrollWrapper.styles.mjs +64 -87
  702. package/lib/components/ScrollWrapper/ScrollWrapper.styles.mjs.map +1 -1
  703. package/lib/components/ScrollWrapper/ScrollWrapper.types.d.ts +0 -2
  704. package/lib/components/Search/Input/Input.d.ts +1 -1
  705. package/lib/components/Search/Input/Input.js +4 -4
  706. package/lib/components/Search/Input/Input.js.map +1 -1
  707. package/lib/components/Search/Input/Input.mjs +4 -4
  708. package/lib/components/Search/Input/Input.mjs.map +1 -1
  709. package/lib/components/Search/Input/Input.styles.js +1 -0
  710. package/lib/components/Search/Input/Input.styles.js.map +1 -1
  711. package/lib/components/Search/Input/Input.styles.mjs +1 -0
  712. package/lib/components/Search/Input/Input.styles.mjs.map +1 -1
  713. package/lib/components/Search/Input/Input.types.d.ts +2 -3
  714. package/lib/components/StorageSliders/StorageSliders.context.js +14 -17
  715. package/lib/components/StorageSliders/StorageSliders.context.js.map +1 -1
  716. package/lib/components/StorageSliders/StorageSliders.context.mjs +14 -17
  717. package/lib/components/StorageSliders/StorageSliders.context.mjs.map +1 -1
  718. package/lib/components/StorybookUtils/StoryFaker.js.map +1 -1
  719. package/lib/components/StorybookUtils/StoryFaker.mjs.map +1 -1
  720. package/lib/components/VariantSelector/VariantSelector.js +4 -4
  721. package/lib/components/VariantSelector/VariantSelector.js.map +1 -1
  722. package/lib/components/VariantSelector/VariantSelector.mjs +4 -4
  723. package/lib/components/VariantSelector/VariantSelector.mjs.map +1 -1
  724. package/lib/components/VideoPlayerNew/VideoPlayer.js +14 -12
  725. package/lib/components/VideoPlayerNew/VideoPlayer.js.map +1 -1
  726. package/lib/components/VideoPlayerNew/VideoPlayer.mjs +14 -12
  727. package/lib/components/VideoPlayerNew/VideoPlayer.mjs.map +1 -1
  728. package/lib/components/index.d.ts +0 -1
  729. package/lib/components/index.js +30 -32
  730. package/lib/components/index.js.map +1 -1
  731. package/lib/components/index.mjs +30 -32
  732. package/lib/components/index.mjs.map +1 -1
  733. package/lib/constants/address.d.ts +1 -1
  734. package/lib/constants/address.js +34 -34
  735. package/lib/constants/address.js.map +1 -1
  736. package/lib/constants/address.mjs +34 -34
  737. package/lib/constants/address.mjs.map +1 -1
  738. package/lib/constants/icons/generic/carouselArrowRight.svg.js +5 -5
  739. package/lib/constants/icons/generic/index.js +3 -3
  740. package/lib/constants/icons/header/account.svg.js +5 -5
  741. package/lib/constants/icons/header/globe.svg.js +5 -5
  742. package/lib/constants/icons/header/index.js +9 -9
  743. package/lib/constants/icons/header/logoUnifi.svg.js +5 -5
  744. package/lib/constants/icons/menu/index.d.ts +1 -3
  745. package/lib/constants/icons/menu/index.js +9 -27
  746. package/lib/constants/icons/menu/index.js.map +1 -1
  747. package/lib/constants/icons/menu/index.mjs +2 -6
  748. package/lib/constants/icons/menu/index.mjs.map +1 -1
  749. package/lib/{assets/icons/cart-secondary.svg.js → constants/icons/menu/touchPass.svg.js} +6 -6
  750. package/lib/constants/icons/menu/touchPass.svg.js.map +1 -0
  751. package/lib/constants/icons/menu/touchPass.svg.mjs +3 -0
  752. package/lib/constants/icons/menu/touchPass.svg.mjs.map +1 -0
  753. package/lib/constants/icons/options/colors/black.svg.js +5 -5
  754. package/lib/constants/icons/options/colors/index.js +3 -3
  755. package/lib/constants/icons/options/styles/black.svg.js +5 -5
  756. package/lib/constants/icons/options/styles/index.js +3 -3
  757. package/lib/constants/optionIcons.js +6 -6
  758. package/lib/constants/optionIcons.mjs +4 -4
  759. package/lib/constants/postalCode.js +10 -10
  760. package/lib/constants/postalCode.js.map +1 -1
  761. package/lib/constants/postalCode.mjs +10 -10
  762. package/lib/constants/postalCode.mjs.map +1 -1
  763. package/lib/constants/proStoreCategories/mapping/filters.d.ts +0 -16
  764. package/lib/constants/proStoreCategories/mapping/filters.js +0 -16
  765. package/lib/constants/proStoreCategories/mapping/filters.js.map +1 -1
  766. package/lib/constants/proStoreCategories/mapping/filters.mjs +0 -16
  767. package/lib/constants/proStoreCategories/mapping/filters.mjs.map +1 -1
  768. package/lib/constants/proStoreCategories/mapping/index.d.ts +1 -2
  769. package/lib/constants/proStoreCategories/mapping/index.js +11 -20
  770. package/lib/constants/proStoreCategories/mapping/index.js.map +1 -1
  771. package/lib/constants/proStoreCategories/mapping/index.mjs +11 -20
  772. package/lib/constants/proStoreCategories/mapping/index.mjs.map +1 -1
  773. package/lib/constants/proStoreCategories/mapping/mapping.d.ts +0 -5
  774. package/lib/constants/proStoreCategories/mapping/uisp.d.ts +1 -0
  775. package/lib/constants/proStoreCategories/mapping/uisp.js +1 -0
  776. package/lib/constants/proStoreCategories/mapping/uisp.js.map +1 -1
  777. package/lib/constants/proStoreCategories/mapping/uisp.mjs +1 -0
  778. package/lib/constants/proStoreCategories/mapping/uisp.mjs.map +1 -1
  779. package/lib/constants/proStoreCategories/mapping/unifi.d.ts +0 -2
  780. package/lib/constants/proStoreCategories/mapping/unifi.js +0 -2
  781. package/lib/constants/proStoreCategories/mapping/unifi.js.map +1 -1
  782. package/lib/constants/proStoreCategories/mapping/unifi.mjs +0 -2
  783. package/lib/constants/proStoreCategories/mapping/unifi.mjs.map +1 -1
  784. package/lib/constants/proStoreCategories/translations/ar.json.js +5 -5
  785. package/lib/constants/proStoreCategories/translations/ar.json.mjs +5 -5
  786. package/lib/constants/proStoreCategories/translations/de.json.js +5 -5
  787. package/lib/constants/proStoreCategories/translations/de.json.mjs +5 -5
  788. package/lib/constants/proStoreCategories/translations/el.json.js +6 -6
  789. package/lib/constants/proStoreCategories/translations/el.json.mjs +6 -6
  790. package/lib/constants/proStoreCategories/translations/en.json.js +2 -5
  791. package/lib/constants/proStoreCategories/translations/en.json.js.map +1 -1
  792. package/lib/constants/proStoreCategories/translations/en.json.mjs +3 -5
  793. package/lib/constants/proStoreCategories/translations/en.json.mjs.map +1 -1
  794. package/lib/constants/proStoreCategories/translations/es.json.js +5 -5
  795. package/lib/constants/proStoreCategories/translations/es.json.mjs +5 -5
  796. package/lib/constants/proStoreCategories/translations/fr.json.js +2 -5
  797. package/lib/constants/proStoreCategories/translations/fr.json.js.map +1 -1
  798. package/lib/constants/proStoreCategories/translations/fr.json.mjs +3 -5
  799. package/lib/constants/proStoreCategories/translations/fr.json.mjs.map +1 -1
  800. package/lib/constants/proStoreCategories/translations/it.json.js +5 -5
  801. package/lib/constants/proStoreCategories/translations/it.json.mjs +5 -5
  802. package/lib/constants/proStoreCategories/translations/ja.json.js +5 -5
  803. package/lib/constants/proStoreCategories/translations/ja.json.mjs +5 -5
  804. package/lib/constants/proStoreCategories/translations/pt-BR.json.js +5 -5
  805. package/lib/constants/proStoreCategories/translations/pt-BR.json.mjs +5 -5
  806. package/lib/constants/proStoreCategories/translations/zh-Hans.json.js +2 -5
  807. package/lib/constants/proStoreCategories/translations/zh-Hans.json.js.map +1 -1
  808. package/lib/constants/proStoreCategories/translations/zh-Hans.json.mjs +3 -5
  809. package/lib/constants/proStoreCategories/translations/zh-Hans.json.mjs.map +1 -1
  810. package/lib/constants/proStoreCategories/translations/zh-Hant-TW.json.js +2 -5
  811. package/lib/constants/proStoreCategories/translations/zh-Hant-TW.json.js.map +1 -1
  812. package/lib/constants/proStoreCategories/translations/zh-Hant-TW.json.mjs +3 -5
  813. package/lib/constants/proStoreCategories/translations/zh-Hant-TW.json.mjs.map +1 -1
  814. package/lib/constants/proStoreFilters/mapping.d.ts +7 -33
  815. package/lib/constants/proStoreFilters/mapping.js +14 -108
  816. package/lib/constants/proStoreFilters/mapping.js.map +1 -1
  817. package/lib/constants/proStoreFilters/mapping.mjs +14 -108
  818. package/lib/constants/proStoreFilters/mapping.mjs.map +1 -1
  819. package/lib/constants/theme.js +0 -4
  820. package/lib/constants/theme.js.map +1 -1
  821. package/lib/constants/theme.mjs +0 -4
  822. package/lib/constants/theme.mjs.map +1 -1
  823. package/lib/contexts/MenuContext/context.js +27 -28
  824. package/lib/contexts/MenuContext/context.js.map +1 -1
  825. package/lib/contexts/MenuContext/context.mjs +27 -28
  826. package/lib/contexts/MenuContext/context.mjs.map +1 -1
  827. package/lib/contexts/MenuContext/mapping.js +15 -3
  828. package/lib/contexts/MenuContext/mapping.js.map +1 -1
  829. package/lib/contexts/MenuContext/mapping.mjs +14 -3
  830. package/lib/contexts/MenuContext/mapping.mjs.map +1 -1
  831. package/lib/contexts/MenuContext/presets.d.ts +1 -1
  832. package/lib/contexts/MenuContext/presets.js +4 -2
  833. package/lib/contexts/MenuContext/presets.js.map +1 -1
  834. package/lib/contexts/MenuContext/presets.mjs +4 -2
  835. package/lib/contexts/MenuContext/presets.mjs.map +1 -1
  836. package/lib/contexts/MenuContext/types.js.map +1 -1
  837. package/lib/contexts/MenuContext/types.mjs.map +1 -1
  838. package/lib/contexts/MenuContext/utils.d.ts +1 -6
  839. package/lib/contexts/MenuContext/utils.js +0 -16
  840. package/lib/contexts/MenuContext/utils.js.map +1 -1
  841. package/lib/contexts/MenuContext/utils.mjs +1 -16
  842. package/lib/contexts/MenuContext/utils.mjs.map +1 -1
  843. package/lib/contexts/index.d.ts +0 -1
  844. package/lib/contexts/index.js +0 -2
  845. package/lib/contexts/index.js.map +1 -1
  846. package/lib/contexts/index.mjs +0 -2
  847. package/lib/contexts/index.mjs.map +1 -1
  848. package/lib/helpers/index.d.ts +1 -0
  849. package/lib/helpers/index.js +11 -0
  850. package/lib/helpers/index.js.map +1 -1
  851. package/lib/helpers/index.mjs +1 -0
  852. package/lib/helpers/index.mjs.map +1 -1
  853. package/lib/helpers/product.d.ts +87 -0
  854. package/lib/helpers/product.js +346 -0
  855. package/lib/helpers/product.js.map +1 -0
  856. package/lib/helpers/product.mjs +335 -0
  857. package/lib/helpers/product.mjs.map +1 -0
  858. package/lib/helpers/ux.d.ts +11 -8
  859. package/lib/helpers/ux.js +4 -15
  860. package/lib/helpers/ux.js.map +1 -1
  861. package/lib/helpers/ux.mjs +4 -15
  862. package/lib/helpers/ux.mjs.map +1 -1
  863. package/lib/hooks/useScrollToY.js.map +1 -1
  864. package/lib/hooks/useScrollToY.mjs.map +1 -1
  865. package/lib/types/generated.d.ts +1 -1
  866. package/lib/types/generated.js.map +1 -1
  867. package/lib/types/generated.mjs.map +1 -1
  868. package/lib/types/index.d.ts +1 -0
  869. package/lib/types/index.js +2 -0
  870. package/lib/types/index.js.map +1 -1
  871. package/lib/types/index.mjs +1 -0
  872. package/lib/types/index.mjs.map +1 -1
  873. package/lib/types/product.d.ts +87 -0
  874. package/lib/types/product.js +14 -0
  875. package/lib/types/product.js.map +1 -0
  876. package/lib/types/product.mjs +13 -0
  877. package/lib/types/product.mjs.map +1 -0
  878. package/lib/utils/address.d.ts +278 -62
  879. package/lib/utils/address.js +11 -8
  880. package/lib/utils/address.js.map +1 -1
  881. package/lib/utils/address.mjs +11 -8
  882. package/lib/utils/address.mjs.map +1 -1
  883. package/lib/utils/array.d.ts +4 -0
  884. package/lib/utils/array.js +10 -0
  885. package/lib/utils/array.js.map +1 -1
  886. package/lib/utils/array.mjs +10 -1
  887. package/lib/utils/array.mjs.map +1 -1
  888. package/lib/utils/blackFriday.d.ts +20 -1
  889. package/lib/utils/blackFriday.js +84 -3
  890. package/lib/utils/blackFriday.js.map +1 -1
  891. package/lib/utils/blackFriday.mjs +74 -1
  892. package/lib/utils/blackFriday.mjs.map +1 -1
  893. package/lib/utils/collectionSlug.js +2 -2
  894. package/lib/utils/collectionSlug.js.map +1 -1
  895. package/lib/utils/collectionSlug.mjs +2 -2
  896. package/lib/utils/collectionSlug.mjs.map +1 -1
  897. package/lib/utils/errors.js.map +1 -1
  898. package/lib/utils/errors.mjs.map +1 -1
  899. package/lib/utils/index.d.ts +0 -1
  900. package/lib/utils/index.js +0 -2
  901. package/lib/utils/index.js.map +1 -1
  902. package/lib/utils/index.mjs +0 -2
  903. package/lib/utils/index.mjs.map +1 -1
  904. package/lib/utils/measures.js +0 -1
  905. package/lib/utils/measures.js.map +1 -1
  906. package/lib/utils/measures.mjs +0 -1
  907. package/lib/utils/measures.mjs.map +1 -1
  908. package/lib/utils/money/format.js.map +1 -1
  909. package/lib/utils/money/format.mjs.map +1 -1
  910. package/lib/utils/money/misc.js +1 -1
  911. package/lib/utils/money/misc.js.map +1 -1
  912. package/lib/utils/money/misc.mjs +1 -1
  913. package/lib/utils/money/misc.mjs.map +1 -1
  914. package/lib/utils/nextjs/ssr/transform-css-module.js.map +1 -1
  915. package/lib/utils/nextjs/ssr/transform-css-module.mjs.map +1 -1
  916. package/lib/utils/number.js.map +1 -1
  917. package/lib/utils/number.mjs.map +1 -1
  918. package/lib/utils/product.js +4 -4
  919. package/lib/utils/product.js.map +1 -1
  920. package/lib/utils/product.mjs +4 -4
  921. package/lib/utils/product.mjs.map +1 -1
  922. package/lib/utils/productSort.d.ts +41 -0
  923. package/lib/utils/productSort.js +67 -0
  924. package/lib/utils/productSort.js.map +1 -0
  925. package/lib/utils/productSort.mjs +60 -0
  926. package/lib/utils/productSort.mjs.map +1 -0
  927. package/lib/utils/tags.js +2 -2
  928. package/lib/utils/tags.js.map +1 -1
  929. package/lib/utils/tags.mjs +2 -2
  930. package/lib/utils/tags.mjs.map +1 -1
  931. package/lib/utils/validations/lastNameSuperRefinement.d.ts +11 -0
  932. package/lib/utils/validations/lastNameSuperRefinement.js +25 -0
  933. package/lib/utils/validations/lastNameSuperRefinement.js.map +1 -0
  934. package/lib/utils/validations/lastNameSuperRefinement.mjs +21 -0
  935. package/lib/utils/validations/lastNameSuperRefinement.mjs.map +1 -0
  936. package/package.json +1 -1
  937. package/lib/assets/AccessHub.jpg +0 -0
  938. package/lib/assets/cart-secondary.svg +0 -5
  939. package/lib/assets/consolidatedSpecialDevices.svg +0 -5
  940. package/lib/assets/doorAccess.svg +0 -5
  941. package/lib/assets/education.jpg +0 -0
  942. package/lib/assets/enterprise.jpg +0 -0
  943. package/lib/assets/flagship.jpg +0 -0
  944. package/lib/assets/flexible-outdoor.jpg +0 -0
  945. package/lib/assets/g2Reader.jpg +0 -0
  946. package/lib/assets/g2ReaderPro.jpg +0 -0
  947. package/lib/assets/hospitality.jpg +0 -0
  948. package/lib/assets/how-it-works.jpg +0 -0
  949. package/lib/assets/icon-location-pin.svg +0 -5
  950. package/lib/assets/icons/arrowDown.svg.mjs +0 -3
  951. package/lib/assets/icons/cart-secondary.svg.js.map +0 -1
  952. package/lib/assets/icons/cart-secondary.svg.mjs +0 -3
  953. package/lib/assets/icons/cart-secondary.svg.mjs.map +0 -1
  954. package/lib/assets/icons/menu/icon-location-pin.svg.js +0 -27
  955. package/lib/assets/icons/menu/icon-location-pin.svg.js.map +0 -1
  956. package/lib/assets/icons/menu/icon-location-pin.svg.mjs +0 -3
  957. package/lib/assets/icons/menu/icon-location-pin.svg.mjs.map +0 -1
  958. package/lib/assets/icons/zoomOut.svg.js +0 -27
  959. package/lib/assets/icons/zoomOut.svg.js.map +0 -1
  960. package/lib/assets/icons/zoomOut.svg.mjs +0 -3
  961. package/lib/assets/icons/zoomOut.svg.mjs.map +0 -1
  962. package/lib/assets/industrial2.jpg +0 -0
  963. package/lib/assets/mega-capacity.jpg +0 -0
  964. package/lib/assets/nextai-camera.jpg +0 -0
  965. package/lib/assets/nextai-cyber.jpg +0 -0
  966. package/lib/assets/overview.svg +0 -3
  967. package/lib/assets/readerLite.jpg +0 -0
  968. package/lib/assets/retail.jpg +0 -0
  969. package/lib/assets/sd-wan-sase.jpg +0 -0
  970. package/lib/assets/site-manager.jpg +0 -0
  971. package/lib/assets/stadium.jpg +0 -0
  972. package/lib/assets/tco-calculator.jpg +0 -0
  973. package/lib/assets/wall.jpg +0 -0
  974. package/lib/assets/zoomOut.svg +0 -3
  975. package/lib/components/Header/LogoIcon/LogoIcon.d.ts +0 -7
  976. package/lib/components/Header/LogoIcon/LogoIcon.js +0 -46
  977. package/lib/components/Header/LogoIcon/LogoIcon.js.map +0 -1
  978. package/lib/components/Header/LogoIcon/LogoIcon.mjs +0 -36
  979. package/lib/components/Header/LogoIcon/LogoIcon.mjs.map +0 -1
  980. package/lib/components/Header/LogoIcon/index.d.ts +0 -1
  981. package/lib/components/Header/LogoIcon/index.js +0 -6
  982. package/lib/components/Header/LogoIcon/index.js.map +0 -1
  983. package/lib/components/Header/LogoIcon/index.mjs +0 -3
  984. package/lib/components/Header/LogoIcon/index.mjs.map +0 -1
  985. package/lib/components/MicrositeHeader/MicrositeHeader.d.ts +0 -2
  986. package/lib/components/MicrositeHeader/MicrositeHeader.js +0 -35
  987. package/lib/components/MicrositeHeader/MicrositeHeader.js.map +0 -1
  988. package/lib/components/MicrositeHeader/MicrositeHeader.mjs +0 -33
  989. package/lib/components/MicrositeHeader/MicrositeHeader.mjs.map +0 -1
  990. package/lib/components/MicrositeHeader/MicrositeHeader.styles.d.ts +0 -2
  991. package/lib/components/MicrositeHeader/MicrositeHeader.styles.js +0 -29
  992. package/lib/components/MicrositeHeader/MicrositeHeader.styles.js.map +0 -1
  993. package/lib/components/MicrositeHeader/MicrositeHeader.styles.mjs +0 -20
  994. package/lib/components/MicrositeHeader/MicrositeHeader.styles.mjs.map +0 -1
  995. package/lib/components/MicrositeHeader/MicrositeHeader.types.d.ts +0 -5
  996. package/lib/components/MicrositeHeader/components/DropdownMenu/DropdownMenu.d.ts +0 -2
  997. package/lib/components/MicrositeHeader/components/DropdownMenu/DropdownMenu.js +0 -185
  998. package/lib/components/MicrositeHeader/components/DropdownMenu/DropdownMenu.js.map +0 -1
  999. package/lib/components/MicrositeHeader/components/DropdownMenu/DropdownMenu.mjs +0 -176
  1000. package/lib/components/MicrositeHeader/components/DropdownMenu/DropdownMenu.mjs.map +0 -1
  1001. package/lib/components/MicrositeHeader/components/DropdownMenu/DropdownMenu.styles.d.ts +0 -52
  1002. package/lib/components/MicrositeHeader/components/DropdownMenu/DropdownMenu.styles.js +0 -425
  1003. package/lib/components/MicrositeHeader/components/DropdownMenu/DropdownMenu.styles.js.map +0 -1
  1004. package/lib/components/MicrositeHeader/components/DropdownMenu/DropdownMenu.styles.mjs +0 -391
  1005. package/lib/components/MicrositeHeader/components/DropdownMenu/DropdownMenu.styles.mjs.map +0 -1
  1006. package/lib/components/MicrositeHeader/components/DropdownMenu/DropdownMenu.types.d.ts +0 -20
  1007. package/lib/components/MicrositeHeader/components/DropdownMenu/index.d.ts +0 -1
  1008. package/lib/components/MicrositeHeader/components/FirstLevelMenu/FirstLevelMenu.d.ts +0 -2
  1009. package/lib/components/MicrositeHeader/components/FirstLevelMenu/FirstLevelMenu.js +0 -209
  1010. package/lib/components/MicrositeHeader/components/FirstLevelMenu/FirstLevelMenu.js.map +0 -1
  1011. package/lib/components/MicrositeHeader/components/FirstLevelMenu/FirstLevelMenu.mjs +0 -198
  1012. package/lib/components/MicrositeHeader/components/FirstLevelMenu/FirstLevelMenu.mjs.map +0 -1
  1013. package/lib/components/MicrositeHeader/components/FirstLevelMenu/FirstLevelMenu.styles.d.ts +0 -22
  1014. package/lib/components/MicrositeHeader/components/FirstLevelMenu/FirstLevelMenu.styles.js +0 -148
  1015. package/lib/components/MicrositeHeader/components/FirstLevelMenu/FirstLevelMenu.styles.js.map +0 -1
  1016. package/lib/components/MicrositeHeader/components/FirstLevelMenu/FirstLevelMenu.styles.mjs +0 -126
  1017. package/lib/components/MicrositeHeader/components/FirstLevelMenu/FirstLevelMenu.styles.mjs.map +0 -1
  1018. package/lib/components/MicrositeHeader/components/FirstLevelMenu/FirstLevelMenu.types.d.ts +0 -10
  1019. package/lib/components/MicrositeHeader/components/FirstLevelMenu/index.d.ts +0 -1
  1020. package/lib/components/MicrositeHeader/components/FirstLevelMenu/index.js +0 -6
  1021. package/lib/components/MicrositeHeader/components/FirstLevelMenu/index.js.map +0 -1
  1022. package/lib/components/MicrositeHeader/components/FirstLevelMenu/index.mjs +0 -3
  1023. package/lib/components/MicrositeHeader/components/FirstLevelMenu/index.mjs.map +0 -1
  1024. package/lib/components/MicrositeHeader/components/SecondLevelMenu/SecondLevelMenu.d.ts +0 -2
  1025. package/lib/components/MicrositeHeader/components/SecondLevelMenu/SecondLevelMenu.js +0 -71
  1026. package/lib/components/MicrositeHeader/components/SecondLevelMenu/SecondLevelMenu.js.map +0 -1
  1027. package/lib/components/MicrositeHeader/components/SecondLevelMenu/SecondLevelMenu.mjs +0 -69
  1028. package/lib/components/MicrositeHeader/components/SecondLevelMenu/SecondLevelMenu.mjs.map +0 -1
  1029. package/lib/components/MicrositeHeader/components/SecondLevelMenu/SecondLevelMenu.styles.d.ts +0 -13
  1030. package/lib/components/MicrositeHeader/components/SecondLevelMenu/SecondLevelMenu.styles.js +0 -104
  1031. package/lib/components/MicrositeHeader/components/SecondLevelMenu/SecondLevelMenu.styles.js.map +0 -1
  1032. package/lib/components/MicrositeHeader/components/SecondLevelMenu/SecondLevelMenu.styles.mjs +0 -89
  1033. package/lib/components/MicrositeHeader/components/SecondLevelMenu/SecondLevelMenu.styles.mjs.map +0 -1
  1034. package/lib/components/MicrositeHeader/components/SecondLevelMenu/SecondLevelMenu.types.d.ts +0 -11
  1035. package/lib/components/MicrositeHeader/components/SecondLevelMenu/index.d.ts +0 -1
  1036. package/lib/components/MicrositeHeader/components/SecondLevelMenu/index.js +0 -6
  1037. package/lib/components/MicrositeHeader/components/SecondLevelMenu/index.js.map +0 -1
  1038. package/lib/components/MicrositeHeader/components/SecondLevelMenu/index.mjs +0 -3
  1039. package/lib/components/MicrositeHeader/components/SecondLevelMenu/index.mjs.map +0 -1
  1040. package/lib/components/MicrositeHeader/components/SiteMapColumns/SiteMapColumns.d.ts +0 -17
  1041. package/lib/components/MicrositeHeader/components/SiteMapColumns/SiteMapColumns.styles.d.ts +0 -13
  1042. package/lib/components/MicrositeHeader/components/SiteMapColumns/index.d.ts +0 -1
  1043. package/lib/components/MicrositeHeader/index.d.ts +0 -1
  1044. package/lib/components/MicrositeHeader/index.js +0 -6
  1045. package/lib/components/MicrositeHeader/index.js.map +0 -1
  1046. package/lib/components/MicrositeHeader/index.mjs +0 -3
  1047. package/lib/components/MicrositeHeader/index.mjs.map +0 -1
  1048. package/lib/components/ModelCompareV3/assets/DoorAccess/AccessHub.jpg.js.map +0 -1
  1049. package/lib/components/ModelCompareV3/assets/DoorAccess/AccessHub.jpg.mjs +0 -3
  1050. package/lib/components/ModelCompareV3/assets/DoorAccess/AccessHub.jpg.mjs.map +0 -1
  1051. package/lib/components/ModelCompareV3/assets/DoorAccess/g2Reader.jpg.js.map +0 -1
  1052. package/lib/components/ModelCompareV3/assets/DoorAccess/g2Reader.jpg.mjs +0 -3
  1053. package/lib/components/ModelCompareV3/assets/DoorAccess/g2Reader.jpg.mjs.map +0 -1
  1054. package/lib/components/ModelCompareV3/assets/DoorAccess/g2ReaderPro.jpg.js.map +0 -1
  1055. package/lib/components/ModelCompareV3/assets/DoorAccess/g2ReaderPro.jpg.mjs +0 -3
  1056. package/lib/components/ModelCompareV3/assets/DoorAccess/g2ReaderPro.jpg.mjs.map +0 -1
  1057. package/lib/components/ModelCompareV3/assets/DoorAccess/readerLite.jpg.js.map +0 -1
  1058. package/lib/components/ModelCompareV3/assets/DoorAccess/readerLite.jpg.mjs +0 -3
  1059. package/lib/components/ModelCompareV3/assets/DoorAccess/readerLite.jpg.mjs.map +0 -1
  1060. package/lib/components/ModelCompareV3/assets/WiFi/flagship.jpg.js.map +0 -1
  1061. package/lib/components/ModelCompareV3/assets/WiFi/flagship.jpg.mjs +0 -3
  1062. package/lib/components/ModelCompareV3/assets/WiFi/flagship.jpg.mjs.map +0 -1
  1063. package/lib/components/ModelCompareV3/assets/WiFi/flexible-outdoor.jpg.js +0 -27
  1064. package/lib/components/ModelCompareV3/assets/WiFi/flexible-outdoor.jpg.js.map +0 -1
  1065. package/lib/components/ModelCompareV3/assets/WiFi/flexible-outdoor.jpg.mjs +0 -3
  1066. package/lib/components/ModelCompareV3/assets/WiFi/flexible-outdoor.jpg.mjs.map +0 -1
  1067. package/lib/components/ModelCompareV3/assets/WiFi/mega-capacity.jpg.js +0 -27
  1068. package/lib/components/ModelCompareV3/assets/WiFi/mega-capacity.jpg.js.map +0 -1
  1069. package/lib/components/ModelCompareV3/assets/WiFi/mega-capacity.jpg.mjs +0 -3
  1070. package/lib/components/ModelCompareV3/assets/WiFi/mega-capacity.jpg.mjs.map +0 -1
  1071. package/lib/components/ModelCompareV3/assets/WiFi/wall.jpg.js.map +0 -1
  1072. package/lib/components/ModelCompareV3/assets/WiFi/wall.jpg.mjs +0 -3
  1073. package/lib/components/ModelCompareV3/assets/WiFi/wall.jpg.mjs.map +0 -1
  1074. package/lib/components/ModelCompareV3/data/Ptz.d.ts +0 -2
  1075. package/lib/components/ModelCompareV3/data/Ptz.js +0 -13
  1076. package/lib/components/ModelCompareV3/data/Ptz.js.map +0 -1
  1077. package/lib/components/ModelCompareV3/data/Ptz.mjs +0 -11
  1078. package/lib/components/ModelCompareV3/data/Ptz.mjs.map +0 -1
  1079. package/lib/components/ModelCompareV3/data/WiFi.d.ts +0 -2
  1080. package/lib/components/ModelCompareV3/data/WiFi.js +0 -23
  1081. package/lib/components/ModelCompareV3/data/WiFi.js.map +0 -1
  1082. package/lib/components/ModelCompareV3/data/WiFi.mjs +0 -21
  1083. package/lib/components/ModelCompareV3/data/WiFi.mjs.map +0 -1
  1084. package/lib/components/ModelCompareV3/data/products/accessHub.js.map +0 -1
  1085. package/lib/components/ModelCompareV3/data/products/accessHub.mjs.map +0 -1
  1086. package/lib/components/ModelCompareV3/data/products/wifiFlagship.js +0 -70
  1087. package/lib/components/ModelCompareV3/data/products/wifiFlagship.js.map +0 -1
  1088. package/lib/components/ModelCompareV3/data/products/wifiFlagship.mjs +0 -62
  1089. package/lib/components/ModelCompareV3/data/products/wifiFlagship.mjs.map +0 -1
  1090. package/lib/components/ModelCompareV3/data/products/wifiFlexibleOutdoor.js +0 -73
  1091. package/lib/components/ModelCompareV3/data/products/wifiFlexibleOutdoor.js.map +0 -1
  1092. package/lib/components/ModelCompareV3/data/products/wifiFlexibleOutdoor.mjs +0 -65
  1093. package/lib/components/ModelCompareV3/data/products/wifiFlexibleOutdoor.mjs.map +0 -1
  1094. package/lib/components/ModelCompareV3/data/products/wifiMegaCapacity.js +0 -73
  1095. package/lib/components/ModelCompareV3/data/products/wifiMegaCapacity.js.map +0 -1
  1096. package/lib/components/ModelCompareV3/data/products/wifiMegaCapacity.mjs +0 -65
  1097. package/lib/components/ModelCompareV3/data/products/wifiMegaCapacity.mjs.map +0 -1
  1098. package/lib/components/ModelCompareV3/data/products/wifiWall.js +0 -74
  1099. package/lib/components/ModelCompareV3/data/products/wifiWall.js.map +0 -1
  1100. package/lib/components/ModelCompareV3/data/products/wifiWall.mjs +0 -66
  1101. package/lib/components/ModelCompareV3/data/products/wifiWall.mjs.map +0 -1
  1102. package/lib/components/ModelCompareV3/data/properties/intercom.js.map +0 -1
  1103. package/lib/components/ModelCompareV3/data/properties/intercom.mjs +0 -10
  1104. package/lib/components/ModelCompareV3/data/properties/intercom.mjs.map +0 -1
  1105. package/lib/constants/icons/menu/consolidatedSpecialDevices.svg.js +0 -27
  1106. package/lib/constants/icons/menu/consolidatedSpecialDevices.svg.js.map +0 -1
  1107. package/lib/constants/icons/menu/consolidatedSpecialDevices.svg.mjs +0 -3
  1108. package/lib/constants/icons/menu/consolidatedSpecialDevices.svg.mjs.map +0 -1
  1109. package/lib/constants/icons/menu/doorAccess.svg.js +0 -27
  1110. package/lib/constants/icons/menu/doorAccess.svg.js.map +0 -1
  1111. package/lib/constants/icons/menu/doorAccess.svg.mjs +0 -3
  1112. package/lib/constants/icons/menu/doorAccess.svg.mjs.map +0 -1
  1113. package/lib/constants/icons/menu/overview.svg.js +0 -27
  1114. package/lib/constants/icons/menu/overview.svg.js.map +0 -1
  1115. package/lib/constants/icons/menu/overview.svg.mjs +0 -3
  1116. package/lib/constants/icons/menu/overview.svg.mjs.map +0 -1
  1117. package/lib/contexts/MicrositeMenuContext/assets/education.jpg.js +0 -27
  1118. package/lib/contexts/MicrositeMenuContext/assets/education.jpg.js.map +0 -1
  1119. package/lib/contexts/MicrositeMenuContext/assets/education.jpg.mjs +0 -3
  1120. package/lib/contexts/MicrositeMenuContext/assets/education.jpg.mjs.map +0 -1
  1121. package/lib/contexts/MicrositeMenuContext/assets/enterprise.jpg.js +0 -27
  1122. package/lib/contexts/MicrositeMenuContext/assets/enterprise.jpg.js.map +0 -1
  1123. package/lib/contexts/MicrositeMenuContext/assets/enterprise.jpg.mjs +0 -3
  1124. package/lib/contexts/MicrositeMenuContext/assets/enterprise.jpg.mjs.map +0 -1
  1125. package/lib/contexts/MicrositeMenuContext/assets/hospitality.jpg.js +0 -27
  1126. package/lib/contexts/MicrositeMenuContext/assets/hospitality.jpg.js.map +0 -1
  1127. package/lib/contexts/MicrositeMenuContext/assets/hospitality.jpg.mjs +0 -3
  1128. package/lib/contexts/MicrositeMenuContext/assets/hospitality.jpg.mjs.map +0 -1
  1129. package/lib/contexts/MicrositeMenuContext/assets/how-it-works.jpg.js +0 -27
  1130. package/lib/contexts/MicrositeMenuContext/assets/how-it-works.jpg.js.map +0 -1
  1131. package/lib/contexts/MicrositeMenuContext/assets/how-it-works.jpg.mjs +0 -3
  1132. package/lib/contexts/MicrositeMenuContext/assets/how-it-works.jpg.mjs.map +0 -1
  1133. package/lib/contexts/MicrositeMenuContext/assets/index.d.ts +0 -12
  1134. package/lib/contexts/MicrositeMenuContext/assets/index.js +0 -16
  1135. package/lib/contexts/MicrositeMenuContext/assets/index.js.map +0 -1
  1136. package/lib/contexts/MicrositeMenuContext/assets/index.mjs +0 -14
  1137. package/lib/contexts/MicrositeMenuContext/assets/index.mjs.map +0 -1
  1138. package/lib/contexts/MicrositeMenuContext/assets/industrial.jpg.js +0 -27
  1139. package/lib/contexts/MicrositeMenuContext/assets/industrial.jpg.js.map +0 -1
  1140. package/lib/contexts/MicrositeMenuContext/assets/industrial.jpg.mjs +0 -3
  1141. package/lib/contexts/MicrositeMenuContext/assets/industrial.jpg.mjs.map +0 -1
  1142. package/lib/contexts/MicrositeMenuContext/assets/nextai-camera.jpg.js +0 -27
  1143. package/lib/contexts/MicrositeMenuContext/assets/nextai-camera.jpg.js.map +0 -1
  1144. package/lib/contexts/MicrositeMenuContext/assets/nextai-camera.jpg.mjs +0 -3
  1145. package/lib/contexts/MicrositeMenuContext/assets/nextai-camera.jpg.mjs.map +0 -1
  1146. package/lib/contexts/MicrositeMenuContext/assets/nextai-cyber.jpg.js +0 -27
  1147. package/lib/contexts/MicrositeMenuContext/assets/nextai-cyber.jpg.js.map +0 -1
  1148. package/lib/contexts/MicrositeMenuContext/assets/nextai-cyber.jpg.mjs +0 -3
  1149. package/lib/contexts/MicrositeMenuContext/assets/nextai-cyber.jpg.mjs.map +0 -1
  1150. package/lib/contexts/MicrositeMenuContext/assets/retail.jpg.js +0 -27
  1151. package/lib/contexts/MicrositeMenuContext/assets/retail.jpg.js.map +0 -1
  1152. package/lib/contexts/MicrositeMenuContext/assets/retail.jpg.mjs +0 -3
  1153. package/lib/contexts/MicrositeMenuContext/assets/retail.jpg.mjs.map +0 -1
  1154. package/lib/contexts/MicrositeMenuContext/assets/sd-wan-sase.jpg.js +0 -27
  1155. package/lib/contexts/MicrositeMenuContext/assets/sd-wan-sase.jpg.js.map +0 -1
  1156. package/lib/contexts/MicrositeMenuContext/assets/sd-wan-sase.jpg.mjs +0 -3
  1157. package/lib/contexts/MicrositeMenuContext/assets/sd-wan-sase.jpg.mjs.map +0 -1
  1158. package/lib/contexts/MicrositeMenuContext/assets/site-manager.jpg.js +0 -27
  1159. package/lib/contexts/MicrositeMenuContext/assets/site-manager.jpg.js.map +0 -1
  1160. package/lib/contexts/MicrositeMenuContext/assets/site-manager.jpg.mjs +0 -3
  1161. package/lib/contexts/MicrositeMenuContext/assets/site-manager.jpg.mjs.map +0 -1
  1162. package/lib/contexts/MicrositeMenuContext/assets/stadium.jpg.js +0 -27
  1163. package/lib/contexts/MicrositeMenuContext/assets/stadium.jpg.js.map +0 -1
  1164. package/lib/contexts/MicrositeMenuContext/assets/stadium.jpg.mjs +0 -3
  1165. package/lib/contexts/MicrositeMenuContext/assets/stadium.jpg.mjs.map +0 -1
  1166. package/lib/contexts/MicrositeMenuContext/assets/tco-calculator.jpg.js +0 -27
  1167. package/lib/contexts/MicrositeMenuContext/assets/tco-calculator.jpg.js.map +0 -1
  1168. package/lib/contexts/MicrositeMenuContext/assets/tco-calculator.jpg.mjs +0 -3
  1169. package/lib/contexts/MicrositeMenuContext/assets/tco-calculator.jpg.mjs.map +0 -1
  1170. package/lib/contexts/MicrositeMenuContext/context.d.ts +0 -36
  1171. package/lib/contexts/MicrositeMenuContext/context.js +0 -100
  1172. package/lib/contexts/MicrositeMenuContext/context.js.map +0 -1
  1173. package/lib/contexts/MicrositeMenuContext/context.mjs +0 -96
  1174. package/lib/contexts/MicrositeMenuContext/context.mjs.map +0 -1
  1175. package/lib/contexts/MicrositeMenuContext/index.d.ts +0 -1
  1176. package/lib/contexts/MicrositeMenuContext/index.js +0 -8
  1177. package/lib/contexts/MicrositeMenuContext/index.js.map +0 -1
  1178. package/lib/contexts/MicrositeMenuContext/index.mjs +0 -3
  1179. package/lib/contexts/MicrositeMenuContext/index.mjs.map +0 -1
  1180. package/lib/contexts/MicrositeMenuContext/mapping.d.ts +0 -8
  1181. package/lib/contexts/MicrositeMenuContext/mapping.js +0 -513
  1182. package/lib/contexts/MicrositeMenuContext/mapping.js.map +0 -1
  1183. package/lib/contexts/MicrositeMenuContext/mapping.mjs +0 -468
  1184. package/lib/contexts/MicrositeMenuContext/mapping.mjs.map +0 -1
  1185. package/lib/contexts/MicrositeMenuContext/translations/ar.json.js +0 -8
  1186. package/lib/contexts/MicrositeMenuContext/translations/ar.json.js.map +0 -1
  1187. package/lib/contexts/MicrositeMenuContext/translations/ar.json.mjs +0 -3
  1188. package/lib/contexts/MicrositeMenuContext/translations/ar.json.mjs.map +0 -1
  1189. package/lib/contexts/MicrositeMenuContext/translations/de.json.js +0 -8
  1190. package/lib/contexts/MicrositeMenuContext/translations/de.json.js.map +0 -1
  1191. package/lib/contexts/MicrositeMenuContext/translations/de.json.mjs +0 -3
  1192. package/lib/contexts/MicrositeMenuContext/translations/de.json.mjs.map +0 -1
  1193. package/lib/contexts/MicrositeMenuContext/translations/el.json.js +0 -8
  1194. package/lib/contexts/MicrositeMenuContext/translations/el.json.js.map +0 -1
  1195. package/lib/contexts/MicrositeMenuContext/translations/el.json.mjs +0 -3
  1196. package/lib/contexts/MicrositeMenuContext/translations/el.json.mjs.map +0 -1
  1197. package/lib/contexts/MicrositeMenuContext/translations/en.json.js +0 -84
  1198. package/lib/contexts/MicrositeMenuContext/translations/en.json.js.map +0 -1
  1199. package/lib/contexts/MicrositeMenuContext/translations/en.json.mjs +0 -79
  1200. package/lib/contexts/MicrositeMenuContext/translations/en.json.mjs.map +0 -1
  1201. package/lib/contexts/MicrositeMenuContext/translations/es.json.js +0 -8
  1202. package/lib/contexts/MicrositeMenuContext/translations/es.json.js.map +0 -1
  1203. package/lib/contexts/MicrositeMenuContext/translations/es.json.mjs +0 -3
  1204. package/lib/contexts/MicrositeMenuContext/translations/es.json.mjs.map +0 -1
  1205. package/lib/contexts/MicrositeMenuContext/translations/fr.json.js +0 -8
  1206. package/lib/contexts/MicrositeMenuContext/translations/fr.json.js.map +0 -1
  1207. package/lib/contexts/MicrositeMenuContext/translations/fr.json.mjs +0 -3
  1208. package/lib/contexts/MicrositeMenuContext/translations/fr.json.mjs.map +0 -1
  1209. package/lib/contexts/MicrositeMenuContext/translations/it.json.js +0 -8
  1210. package/lib/contexts/MicrositeMenuContext/translations/it.json.js.map +0 -1
  1211. package/lib/contexts/MicrositeMenuContext/translations/it.json.mjs +0 -3
  1212. package/lib/contexts/MicrositeMenuContext/translations/it.json.mjs.map +0 -1
  1213. package/lib/contexts/MicrositeMenuContext/translations/ja.json.js +0 -8
  1214. package/lib/contexts/MicrositeMenuContext/translations/ja.json.js.map +0 -1
  1215. package/lib/contexts/MicrositeMenuContext/translations/ja.json.mjs +0 -3
  1216. package/lib/contexts/MicrositeMenuContext/translations/ja.json.mjs.map +0 -1
  1217. package/lib/contexts/MicrositeMenuContext/translations/pt-BR.json.js +0 -8
  1218. package/lib/contexts/MicrositeMenuContext/translations/pt-BR.json.js.map +0 -1
  1219. package/lib/contexts/MicrositeMenuContext/translations/pt-BR.json.mjs +0 -3
  1220. package/lib/contexts/MicrositeMenuContext/translations/pt-BR.json.mjs.map +0 -1
  1221. package/lib/contexts/MicrositeMenuContext/translations/zh-Hans.json.js +0 -8
  1222. package/lib/contexts/MicrositeMenuContext/translations/zh-Hans.json.js.map +0 -1
  1223. package/lib/contexts/MicrositeMenuContext/translations/zh-Hans.json.mjs +0 -3
  1224. package/lib/contexts/MicrositeMenuContext/translations/zh-Hans.json.mjs.map +0 -1
  1225. package/lib/contexts/MicrositeMenuContext/translations/zh-Hant-TW.json.js +0 -8
  1226. package/lib/contexts/MicrositeMenuContext/translations/zh-Hant-TW.json.js.map +0 -1
  1227. package/lib/contexts/MicrositeMenuContext/translations/zh-Hant-TW.json.mjs +0 -3
  1228. package/lib/contexts/MicrositeMenuContext/translations/zh-Hant-TW.json.mjs.map +0 -1
  1229. package/lib/contexts/MicrositeMenuContext/translations.d.ts +0 -7
  1230. package/lib/contexts/MicrositeMenuContext/translations.js +0 -47
  1231. package/lib/contexts/MicrositeMenuContext/translations.js.map +0 -1
  1232. package/lib/contexts/MicrositeMenuContext/translations.mjs +0 -25
  1233. package/lib/contexts/MicrositeMenuContext/translations.mjs.map +0 -1
  1234. package/lib/contexts/MicrositeMenuContext/types.d.ts +0 -100
  1235. package/lib/contexts/MicrositeMenuContext/types.js +0 -16
  1236. package/lib/contexts/MicrositeMenuContext/types.js.map +0 -1
  1237. package/lib/contexts/MicrositeMenuContext/types.mjs +0 -15
  1238. package/lib/contexts/MicrositeMenuContext/types.mjs.map +0 -1
  1239. package/lib/utils/sales.d.ts +0 -34
  1240. package/lib/utils/sales.js +0 -113
  1241. package/lib/utils/sales.js.map +0 -1
  1242. package/lib/utils/sales.mjs +0 -99
  1243. package/lib/utils/sales.mjs.map +0 -1
  1244. /package/lib/{assets/icons → components/MobileModal/assets}/arrowDown.svg.js.map +0 -0
  1245. /package/lib/{assets/icons → components/MobileModal/assets}/arrowDown.svg.mjs.map +0 -0
  1246. /package/lib/{utils/sales.test.d.ts → helpers/product.test.d.ts} +0 -0
@@ -1 +1 @@
1
- {"version":3,"file":"errors.mjs","sources":["../../src/utils/errors.ts"],"sourcesContent":["/**\n * Throw on falsy helper\n */\nexport function assert(\n condition: boolean,\n message = \"'condition' is falsy.\",\n ErrorClass: new (message: string) => void = Error,\n): asserts condition {\n if (!condition) {\n throw new ErrorClass(message);\n }\n}\n\n/**\n * Ensures that the path where this function is used will never be reached.\n * Useful for exhausted switch..case..default checks\n * For more info see https://tinytip.co/tips/ts-switch-assert-unreachable/\n * @throws {Error}\n */\n//eslint-disable-next-line @typescript-eslint/no-unused-vars\nexport function assertUnreachable(_value: never): never {\n throw new Error(\"Statement should be unreachable\");\n}\n\n/**\n * Similar `assertUnreachable` but instead of throwing an error if called it just calls adds type-guards for some cases\n * where we want switch-case type-safety but still want some controlled fallback mechanism. Especially useful in\n * scenario's where we work with \"unknowns\" from errors, api-responses, etc\n *\n * @example\n * enum MyEnum {\n * A = 'a',\n * B = 'b'\n * }\n *\n * switch (myEnumLikeInput) {\n * case MyEnum.A: return 'a';\n * // Explicitly missing \"case MyEnum.B: ...\"\n * default: {\n * checkUnreachable(myEnumLikeInput); // Typescript fill show error \"Argument of type 'MyEnum' is not assignable to parameter of type 'never'.\" as we didn't process `MyEnum.B`\n * return 'c';\n * }\n * }\n */\n// eslint-disable-next-line @typescript-eslint/no-empty-function, @typescript-eslint/no-unused-vars\nexport function checkUnreachable(_value: never): void {\n /* Intentional empty function as just for type assertion */\n}\n\n/**\n * Semi-util that needs to be used together with Difference util type to ensure that in type-system two given objects\n * are the same shape\n *\n * @example\n * assertTypeEquality<Difference<{a: string}, {a: string}>>(); // OK\n * assertTypeEquality<Difference<{a: string, b: number}, {a: string, c: boolean}>>(); // Throws error\n */\n// @ts-expect-error Ignore unused generic parameter\n// eslint-disable-next-line @typescript-eslint/no-unused-vars\nexport function assertTypeEquality<T extends never>(): void {\n /* Intentional empty function as just for type assertion */\n}\n"],"names":["assert","condition","message","ErrorClass","Error","assertUnreachable","_value","checkUnreachable","assertTypeEquality"],"mappings":";;AAGO,SAASA,MACdA,CAAAC,SAAA,EACAC,OAAU,GAAA,uBAAA,EACVC,aAA4CC,KACzB,EAAA;EACnB,IAAI,CAACH,SAAW,EAAA;IACR,MAAA,IAAIE,WAAWD,OAAO,CAAA;EAC9B;AACF;AASO,SAASG,kBAAkBC,MAAsB,EAAA;EAChD,MAAA,IAAIF,MAAM,iCAAiC,CAAA;AACnD;AAuBO,SAASG,iBAAiBD,MAAqB,EAAA,CAEtD;AAYO,SAASE,kBAA4CA,CAAA,EAAA,CAE5D;"}
1
+ {"version":3,"file":"errors.mjs","sources":["../../src/utils/errors.ts"],"sourcesContent":["/**\n * Throw on falsy helper\n */\nexport function assert(\n condition: boolean,\n message = \"'condition' is falsy.\",\n ErrorClass: new (message: string) => void = Error,\n): asserts condition {\n if (!condition) {\n throw new ErrorClass(message);\n }\n}\n\n/**\n * Ensures that the path where this function is used will never be reached.\n * Useful for exhausted switch..case..default checks\n * For more info see https://tinytip.co/tips/ts-switch-assert-unreachable/\n * @throws {Error}\n */\n//eslint-disable-next-line @typescript-eslint/no-unused-vars\nexport function assertUnreachable(_value: never): never {\n throw new Error(\"Statement should be unreachable\");\n}\n\n/**\n * Similar `assertUnreachable` but instead of throwing an error if called it just calls adds type-guards for some cases\n * where we want switch-case type-safety but still want some controlled fallback mechanism. Especially useful in\n * scenario's where we work with \"unknowns\" from errors, api-responses, etc\n *\n * @example\n * enum MyEnum {\n * A = 'a',\n * B = 'b'\n * }\n *\n * switch (myEnumLikeInput) {\n * case MyEnum.A: return 'a';\n * // Explicitly missing \"case MyEnum.B: ...\"\n * default: {\n * checkUnreachable(myEnumLikeInput); // Typescript fill show error \"Argument of type 'MyEnum' is not assignable to parameter of type 'never'.\" as we didn't process `MyEnum.B`\n * return 'c';\n * }\n * }\n */\n// eslint-disable-next-line @typescript-eslint/no-empty-function, @typescript-eslint/no-unused-vars\nexport function checkUnreachable(_value: never): void {}\n\n/**\n * Semi-util that needs to be used together with Difference util type to ensure that in type-system two given objects\n * are the same shape\n *\n * @example\n * assertTypeEquality<Difference<{a: string}, {a: string}>>(); // OK\n * assertTypeEquality<Difference<{a: string, b: number}, {a: string, c: boolean}>>(); // Throws error\n */\n// @ts-expect-error Ignore unused generic parameter\n// eslint-disable-next-line @typescript-eslint/no-unused-vars\nexport function assertTypeEquality<T extends never>(): void {}\n"],"names":["assert","condition","message","ErrorClass","Error","assertUnreachable","_value","checkUnreachable","assertTypeEquality"],"mappings":";;AAGO,SAASA,MACdA,CAAAC,SAAA,EACAC,OAAU,GAAA,uBAAA,EACVC,aAA4CC,KACzB,EAAA;EACnB,IAAI,CAACH,SAAW,EAAA;IACR,MAAA,IAAIE,WAAWD,OAAO,CAAA;EAC9B;AACF;AASO,SAASG,kBAAkBC,MAAsB,EAAA;EAChD,MAAA,IAAIF,MAAM,iCAAiC,CAAA;AACnD;AAuBO,SAASG,iBAAiBD,MAAqB,EAAA,CAAC;AAYhD,SAASE,kBAA4CA,CAAA,EAAA,CAAC;"}
@@ -21,4 +21,3 @@ export * as imageOptimizer from "./imageOptimizer";
21
21
  export * as styles from "./styles";
22
22
  export * as storeId from "./storeId";
23
23
  export * as blackFriday from "./blackFriday";
24
- export * as sales from "./sales";
@@ -23,7 +23,6 @@ var imageOptimizer$1 = require('./imageOptimizer.js');
23
23
  var styles$1 = require('./styles.js');
24
24
  var storeId$1 = require('./storeId.js');
25
25
  var blackFriday$1 = require('./blackFriday.js');
26
- var sales$1 = require('./sales.js');
27
26
  "use strict";
28
27
  exports.url = url$1;
29
28
  exports.money = misc;
@@ -48,5 +47,4 @@ exports.imageOptimizer = imageOptimizer$1;
48
47
  exports.styles = styles$1;
49
48
  exports.storeId = storeId$1;
50
49
  exports.blackFriday = blackFriday$1;
51
- exports.sales = sales$1;
52
50
  //# sourceMappingURL=index.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"index.js","sources":[],"sourcesContent":[],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;"}
1
+ {"version":3,"file":"index.js","sources":[],"sourcesContent":[],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;"}
@@ -44,7 +44,5 @@ import * as storeId$1 from './storeId.mjs';
44
44
  export { storeId$1 as storeId };
45
45
  import * as blackFriday$1 from './blackFriday.mjs';
46
46
  export { blackFriday$1 as blackFriday };
47
- import * as sales$1 from './sales.mjs';
48
- export { sales$1 as sales };
49
47
  "use strict";
50
48
  //# sourceMappingURL=index.mjs.map
@@ -1 +1 @@
1
- {"version":3,"file":"index.mjs","sources":[],"sourcesContent":[],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;"}
1
+ {"version":3,"file":"index.mjs","sources":[],"sourcesContent":[],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;"}
@@ -35,7 +35,6 @@ const dineroBigint = dinero_js.createDinero({
35
35
  });
36
36
  const DINERO_WEIGHT_G = {
37
37
  code: "WEIGHT_G",
38
- // eslint-disable-next-line sonarjs/inconsistent-function-call
39
38
  base: big_js.Big(10),
40
39
  exponent: big_js.Big(0)
41
40
  };
@@ -1 +1 @@
1
- {"version":3,"file":"measures.js","sources":["../../src/utils/measures.ts"],"sourcesContent":["import { Big } from \"big.js\";\nimport type {\n LengthSystems,\n LengthUnits,\n MassSystems,\n MassUnits,\n} from \"convert-units\";\nimport configureMeasurements, { length, mass } from \"convert-units\";\nimport type { Calculator, ComparisonOperator, Transformer } from \"dinero.js\";\nimport { createDinero, toFormat } from \"dinero.js\";\n\nimport { UnitSystem } from \"../types\";\nimport { assert, assertUnreachable } from \"./errors\";\n\n// Measures: The names of the measures being used\ntype Measures = \"length\" | \"mass\";\n// Systems: The systems being used across all measures\ntype Systems = LengthSystems | MassSystems;\n// Units: All the units across all measures and their systems\ntype Units = LengthUnits | MassUnits;\n\nexport const convert = configureMeasurements<Measures, Systems, Units>({\n length,\n mass,\n});\n\nconst calculator: Calculator<Big> = {\n add: (a, b) => a.plus(b),\n compare: (a, b) => a.cmp(b) as unknown as ComparisonOperator,\n decrement: (v) => v.minus(new Big(1)),\n increment: (v) => v.plus(new Big(1)),\n integerDivide: (a, b) => a.div(b).round(0, Big.roundDown),\n modulo: (a, b) => a.mod(b),\n multiply: (a, b) => a.times(b),\n power: (a, b) => a.pow(Number(b)),\n subtract: (a, b) => a.minus(b),\n zero: () => new Big(0),\n toNumber: () => NaN,\n};\n\nconst dineroBigint = createDinero({ calculator });\n\n// type ConvertMassFromTo =\n// | { from: Unit.G; to: Unit.Kg }\n// | { from: Unit.Kg; to: Unit. }\n// | { from: Unit.G; to: Unit.Kg }\n// | { from: Unit.G; to: Unit.Kg }\n// | { from: Unit.G; to: Unit.Kg }\n// | { from: Unit.G; to: Unit.Kg }\n// export const convertMass = (value: number, {from, to}: ConvertMassFromTo) => {\n// return convert(value).from(from).to(to)\n// }\n\nconst DINERO_WEIGHT_G = {\n code: \"WEIGHT_G\",\n // eslint-disable-next-line sonarjs/inconsistent-function-call\n base: Big(10),\n exponent: Big(0),\n};\nconst DINERO_WEIGHT_OZ = {\n code: \"WEIGHT_OZ\",\n base: Big(10),\n exponent: Big(6),\n};\n\ntype TransformerOptions = Parameters<Transformer<Big>>[0];\nconst transformer = ({ currency, dineroObject }: TransformerOptions) => {\n const exponent = currency.exponent;\n const multiplier = Big(0.1).pow(exponent.toNumber());\n\n const jsonObject = dineroObject.toJSON();\n const formattedWeight = jsonObject.amount\n .mul(multiplier)\n .toFixed(exponent.toNumber());\n\n return formattedWeight.toString();\n};\n\n/**\n * In database we store weight in \"weird\" format.\n * For metric we store weight in grams as is.\n * For imperial we store weight in oz with \"virtual scale/exponent\" => 6.\n * e.g. 1_000_000 => '1'\n * e.g. 300_000 => '0.3'\n *\n * Database weight is stored either in g or oz\n */\nexport const transformDatabaseWeightToFormat = (\n databaseWeight: string,\n system: UnitSystem,\n): string => {\n switch (system) {\n case UnitSystem.Metric:\n return toFormat(\n dineroBigint({\n amount: Big(databaseWeight),\n currency: DINERO_WEIGHT_G,\n }),\n transformer,\n );\n case UnitSystem.Imperial: {\n return toFormat(\n dineroBigint({\n amount: Big(databaseWeight),\n currency: DINERO_WEIGHT_OZ,\n }),\n transformer,\n );\n }\n default:\n assertUnreachable(system);\n }\n};\n\n/**\n * Executes transformDatabaseWeightToFormat and returns it as number if safe integer\n *\n * Database weight is stored either in g or oz\n */\nexport const transformDatabaseWeightToNumber = (\n databaseWeight: string,\n system: UnitSystem,\n): number => {\n const formattedBig = Big(\n transformDatabaseWeightToFormat(databaseWeight, system),\n );\n\n assert(\n formattedBig.lte(Number.MAX_SAFE_INTEGER),\n \"Weight is not in safe integer range\",\n );\n return parseFloat(formattedBig.toString());\n};\n\n/**\n * Prepares floating number to be stored in database as normalized bigint\n *\n * Database weights are stored either in g or oz\n */\nexport const transformNumberToDatabaseWeight = (\n numberWeight: number,\n system: UnitSystem,\n): string => {\n switch (system) {\n case UnitSystem.Metric: {\n /**\n * convert(1).from(oz).to(g) is 28.34952g.\n * We are stripping sub-gram measures, because database is storing grams\n */\n const numberWeightInt = parseInt(numberWeight.toFixed(0));\n\n assert(\n !!Number.isSafeInteger(numberWeightInt),\n \"Number is not safe integer\",\n );\n\n return numberWeightInt.toString();\n }\n case UnitSystem.Imperial: {\n const weightBig = Big(numberWeight);\n const multiplier = Big(10).pow(DINERO_WEIGHT_OZ.exponent.toNumber());\n return weightBig.mul(multiplier).toFixed(0);\n }\n default:\n assertUnreachable(system);\n }\n};\n\n/**\n * Shorthand function to transform weight number to formatted string.\n *\n * ! Use only with base weights g/oz\n */\nexport const transformBaseWeightNumberToFormat = (\n databaseWeight: number,\n system: UnitSystem,\n): string =>\n transformDatabaseWeightToFormat(\n transformNumberToDatabaseWeight(databaseWeight, system),\n system,\n );\n"],"names":["convert","configureMeasurements","length","mass","calculator","add","a","b","plus","compare","cmp","decrement","v","minus","Big","increment","integerDivide","div","round","roundDown","modulo","mod","multiply","times","power","pow","Number","subtract","zero","toNumber","NaN","dineroBigint","createDinero","DINERO_WEIGHT_G","code","base","exponent","DINERO_WEIGHT_OZ","transformer","currency","dineroObject","multiplier","jsonObject","toJSON","formattedWeight","amount","mul","toFixed","toString","transformDatabaseWeightToFormat","databaseWeight","system","UnitSystem","Metric","toFormat","Imperial","assertUnreachable","transformDatabaseWeightToNumber","formattedBig","assert","lte","MAX_SAFE_INTEGER","parseFloat","transformNumberToDatabaseWeight","numberWeight","numberWeightInt","parseInt","isSafeInteger","weightBig","transformBaseWeightNumberToFormat"],"mappings":";;;;;;;;;;;;;;;AAqBO,MAAMA,UAAUC,8BAAAA,CAAAA,SAAAA,CAAgD,CAAA;EAAAC,MAAA,EACrEA,qBAAA,CAAAA,MAAA;EAAAC,IAAA,EACAA,qBAAA,CAAAA;AACF,CAAC,CAAA;AAED,MAAMC,UAA8B,GAAA;EAClCC,KAAKA,CAACC,CAAA,EAAGC,CAAM,KAAAD,CAAA,CAAEE,KAAKD,CAAC,CAAA;EACvBE,SAASA,CAACH,CAAA,EAAGC,CAAM,KAAAD,CAAA,CAAEI,IAAIH,CAAC,CAAA;EAC1BI,SAAA,EAAYC,CAAM,IAAAA,CAAA,CAAEC,MAAM,IAAIC,MAAAA,CAAAA,GAAA,CAAI,CAAC,CAAC,CAAA;EACpCC,SAAA,EAAYH,CAAM,IAAAA,CAAA,CAAEJ,KAAK,IAAIM,MAAAA,CAAAA,GAAA,CAAI,CAAC,CAAC,CAAA;EACnCE,aAAA,EAAeA,CAACV,CAAA,EAAGC,CAAM,KAAAD,CAAA,CAAEW,GAAI,CAAAV,CAAC,CAAE,CAAAW,KAAA,CAAM,CAAG,EAAAJ,MAAAA,CAAAA,GAAA,CAAIK,SAAS,CAAA;EACxDC,QAAQA,CAACd,CAAA,EAAGC,CAAM,KAAAD,CAAA,CAAEe,IAAId,CAAC,CA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QAAU;MAAA;QAClB,MAAAa,SAAA,GAAYtD,WAAIkD,YAAY,CAAA;QAC5B,MAAAvB,UAAA,GAAa3B,WAAI,EAAE,CAAA,CAAEW,IAAIY,gBAAiB,CAAAD,QAAA,CAASP,UAAU,CAAA;QACnE,OAAOuC,SAAU,CAAAtB,GAAA,CAAIL,UAAU,CAAA,CAAEM,QAAQ,CAAC,CAAA;MAC5C;IACA;MACES,MAAA,CAAAA,iBAAA,CAAkBL,MAAM,CAAA;EAC5B;AACF,CAAA;AAOa,MAAAkB,iCAAA,GAAoCA,CAC/CnB,cAAA,EACAC,MAEA,KAAAF,+BAAA,CACEc,+BAAA,CAAgCb,gBAAgBC,MAAM,CAAA,EACtDA,MACF,CAAA;;;;;"}
1
+ {"version":3,"file":"measures.js","sources":["../../src/utils/measures.ts"],"sourcesContent":["import { Big } from \"big.js\";\nimport type {\n LengthSystems,\n LengthUnits,\n MassSystems,\n MassUnits,\n} from \"convert-units\";\nimport configureMeasurements, { length, mass } from \"convert-units\";\nimport type { Calculator, ComparisonOperator, Transformer } from \"dinero.js\";\nimport { createDinero, toFormat } from \"dinero.js\";\n\nimport { UnitSystem } from \"../types\";\nimport { assert, assertUnreachable } from \"./errors\";\n\n// Measures: The names of the measures being used\ntype Measures = \"length\" | \"mass\";\n// Systems: The systems being used across all measures\ntype Systems = LengthSystems | MassSystems;\n// Units: All the units across all measures and their systems\ntype Units = LengthUnits | MassUnits;\n\nexport const convert = configureMeasurements<Measures, Systems, Units>({\n length,\n mass,\n});\n\nconst calculator: Calculator<Big> = {\n add: (a, b) => a.plus(b),\n compare: (a, b) => a.cmp(b) as unknown as ComparisonOperator,\n decrement: (v) => v.minus(new Big(1)),\n increment: (v) => v.plus(new Big(1)),\n integerDivide: (a, b) => a.div(b).round(0, Big.roundDown),\n modulo: (a, b) => a.mod(b),\n multiply: (a, b) => a.times(b),\n power: (a, b) => a.pow(Number(b)),\n subtract: (a, b) => a.minus(b),\n zero: () => new Big(0),\n toNumber: () => NaN,\n};\n\nconst dineroBigint = createDinero({ calculator });\n\n// type ConvertMassFromTo =\n// | { from: Unit.G; to: Unit.Kg }\n// | { from: Unit.Kg; to: Unit. }\n// | { from: Unit.G; to: Unit.Kg }\n// | { from: Unit.G; to: Unit.Kg }\n// | { from: Unit.G; to: Unit.Kg }\n// | { from: Unit.G; to: Unit.Kg }\n// export const convertMass = (value: number, {from, to}: ConvertMassFromTo) => {\n// return convert(value).from(from).to(to)\n// }\n\nconst DINERO_WEIGHT_G = {\n code: \"WEIGHT_G\",\n base: Big(10),\n exponent: Big(0),\n};\nconst DINERO_WEIGHT_OZ = {\n code: \"WEIGHT_OZ\",\n base: Big(10),\n exponent: Big(6),\n};\n\ntype TransformerOptions = Parameters<Transformer<Big>>[0];\nconst transformer = ({ currency, dineroObject }: TransformerOptions) => {\n const exponent = currency.exponent;\n const multiplier = Big(0.1).pow(exponent.toNumber());\n\n const jsonObject = dineroObject.toJSON();\n const formattedWeight = jsonObject.amount\n .mul(multiplier)\n .toFixed(exponent.toNumber());\n\n return formattedWeight.toString();\n};\n\n/**\n * In database we store weight in \"weird\" format.\n * For metric we store weight in grams as is.\n * For imperial we store weight in oz with \"virtual scale/exponent\" => 6.\n * e.g. 1_000_000 => '1'\n * e.g. 300_000 => '0.3'\n *\n * Database weight is stored either in g or oz\n */\nexport const transformDatabaseWeightToFormat = (\n databaseWeight: string,\n system: UnitSystem,\n): string => {\n switch (system) {\n case UnitSystem.Metric:\n return toFormat(\n dineroBigint({\n amount: Big(databaseWeight),\n currency: DINERO_WEIGHT_G,\n }),\n transformer,\n );\n case UnitSystem.Imperial: {\n return toFormat(\n dineroBigint({\n amount: Big(databaseWeight),\n currency: DINERO_WEIGHT_OZ,\n }),\n transformer,\n );\n }\n default:\n assertUnreachable(system);\n }\n};\n\n/**\n * Executes transformDatabaseWeightToFormat and returns it as number if safe integer\n *\n * Database weight is stored either in g or oz\n */\nexport const transformDatabaseWeightToNumber = (\n databaseWeight: string,\n system: UnitSystem,\n): number => {\n const formattedBig = Big(\n transformDatabaseWeightToFormat(databaseWeight, system),\n );\n\n assert(\n formattedBig.lte(Number.MAX_SAFE_INTEGER),\n \"Weight is not in safe integer range\",\n );\n return parseFloat(formattedBig.toString());\n};\n\n/**\n * Prepares floating number to be stored in database as normalized bigint\n *\n * Database weights are stored either in g or oz\n */\nexport const transformNumberToDatabaseWeight = (\n numberWeight: number,\n system: UnitSystem,\n): string => {\n switch (system) {\n case UnitSystem.Metric: {\n /**\n * convert(1).from(oz).to(g) is 28.34952g.\n * We are stripping sub-gram measures, because database is storing grams\n */\n const numberWeightInt = parseInt(numberWeight.toFixed(0));\n\n assert(\n !!Number.isSafeInteger(numberWeightInt),\n \"Number is not safe integer\",\n );\n\n return numberWeightInt.toString();\n }\n case UnitSystem.Imperial: {\n const weightBig = Big(numberWeight);\n const multiplier = Big(10).pow(DINERO_WEIGHT_OZ.exponent.toNumber());\n return weightBig.mul(multiplier).toFixed(0);\n }\n default:\n assertUnreachable(system);\n }\n};\n\n/**\n * Shorthand function to transform weight number to formatted string.\n *\n * ! Use only with base weights g/oz\n */\nexport const transformBaseWeightNumberToFormat = (\n databaseWeight: number,\n system: UnitSystem,\n): string =>\n transformDatabaseWeightToFormat(\n transformNumberToDatabaseWeight(databaseWeight, system),\n system,\n );\n"],"names":["convert","configureMeasurements","length","mass","calculator","add","a","b","plus","compare","cmp","decrement","v","minus","Big","increment","integerDivide","div","round","roundDown","modulo","mod","multiply","times","power","pow","Number","subtract","zero","toNumber","NaN","dineroBigint","createDinero","DINERO_WEIGHT_G","code","base","exponent","DINERO_WEIGHT_OZ","transformer","currency","dineroObject","multiplier","jsonObject","toJSON","formattedWeight","amount","mul","toFixed","toString","transformDatabaseWeightToFormat","databaseWeight","system","UnitSystem","Metric","toFormat","Imperial","assertUnreachable","transformDatabaseWeightToNumber","formattedBig","assert","lte","MAX_SAFE_INTEGER","parseFloat","transformNumberToDatabaseWeight","numberWeight","numberWeightInt","parseInt","isSafeInteger","weightBig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Cb,gBAAgBC,MAAM,CAAA,EACtDA,MACF,CAAA;;;;;"}
@@ -27,7 +27,6 @@ const dineroBigint = createDinero({
27
27
  });
28
28
  const DINERO_WEIGHT_G = {
29
29
  code: "WEIGHT_G",
30
- // eslint-disable-next-line sonarjs/inconsistent-function-call
31
30
  base: Big(10),
32
31
  exponent: Big(0)
33
32
  };
@@ -1 +1 @@
1
- {"version":3,"file":"measures.mjs","sources":["../../src/utils/measures.ts"],"sourcesContent":["import { Big } from \"big.js\";\nimport type {\n LengthSystems,\n LengthUnits,\n MassSystems,\n MassUnits,\n} from \"convert-units\";\nimport configureMeasurements, { length, mass } from \"convert-units\";\nimport type { Calculator, ComparisonOperator, Transformer } from \"dinero.js\";\nimport { createDinero, toFormat } from \"dinero.js\";\n\nimport { UnitSystem } from \"../types\";\nimport { assert, assertUnreachable } from \"./errors\";\n\n// Measures: The names of the measures being used\ntype Measures = \"length\" | \"mass\";\n// Systems: The systems being used across all measures\ntype Systems = LengthSystems | MassSystems;\n// Units: All the units across all measures and their systems\ntype Units = LengthUnits | MassUnits;\n\nexport const convert = configureMeasurements<Measures, Systems, Units>({\n length,\n mass,\n});\n\nconst calculator: Calculator<Big> = {\n add: (a, b) => a.plus(b),\n compare: (a, b) => a.cmp(b) as unknown as ComparisonOperator,\n decrement: (v) => v.minus(new Big(1)),\n increment: (v) => v.plus(new Big(1)),\n integerDivide: (a, b) => a.div(b).round(0, Big.roundDown),\n modulo: (a, b) => a.mod(b),\n multiply: (a, b) => a.times(b),\n power: (a, b) => a.pow(Number(b)),\n subtract: (a, b) => a.minus(b),\n zero: () => new Big(0),\n toNumber: () => NaN,\n};\n\nconst dineroBigint = createDinero({ calculator });\n\n// type ConvertMassFromTo =\n// | { from: Unit.G; to: Unit.Kg }\n// | { from: Unit.Kg; to: Unit. }\n// | { from: Unit.G; to: Unit.Kg }\n// | { from: Unit.G; to: Unit.Kg }\n// | { from: Unit.G; to: Unit.Kg }\n// | { from: Unit.G; to: Unit.Kg }\n// export const convertMass = (value: number, {from, to}: ConvertMassFromTo) => {\n// return convert(value).from(from).to(to)\n// }\n\nconst DINERO_WEIGHT_G = {\n code: \"WEIGHT_G\",\n // eslint-disable-next-line sonarjs/inconsistent-function-call\n base: Big(10),\n exponent: Big(0),\n};\nconst DINERO_WEIGHT_OZ = {\n code: \"WEIGHT_OZ\",\n base: Big(10),\n exponent: Big(6),\n};\n\ntype TransformerOptions = Parameters<Transformer<Big>>[0];\nconst transformer = ({ currency, dineroObject }: TransformerOptions) => {\n const exponent = currency.exponent;\n const multiplier = Big(0.1).pow(exponent.toNumber());\n\n const jsonObject = dineroObject.toJSON();\n const formattedWeight = jsonObject.amount\n .mul(multiplier)\n .toFixed(exponent.toNumber());\n\n return formattedWeight.toString();\n};\n\n/**\n * In database we store weight in \"weird\" format.\n * For metric we store weight in grams as is.\n * For imperial we store weight in oz with \"virtual scale/exponent\" => 6.\n * e.g. 1_000_000 => '1'\n * e.g. 300_000 => '0.3'\n *\n * Database weight is stored either in g or oz\n */\nexport const transformDatabaseWeightToFormat = (\n databaseWeight: string,\n system: UnitSystem,\n): string => {\n switch (system) {\n case UnitSystem.Metric:\n return toFormat(\n dineroBigint({\n amount: Big(databaseWeight),\n currency: DINERO_WEIGHT_G,\n }),\n transformer,\n );\n case UnitSystem.Imperial: {\n return toFormat(\n dineroBigint({\n amount: Big(databaseWeight),\n currency: DINERO_WEIGHT_OZ,\n }),\n transformer,\n );\n }\n default:\n assertUnreachable(system);\n }\n};\n\n/**\n * Executes transformDatabaseWeightToFormat and returns it as number if safe integer\n *\n * Database weight is stored either in g or oz\n */\nexport const transformDatabaseWeightToNumber = (\n databaseWeight: string,\n system: UnitSystem,\n): number => {\n const formattedBig = Big(\n transformDatabaseWeightToFormat(databaseWeight, system),\n );\n\n assert(\n formattedBig.lte(Number.MAX_SAFE_INTEGER),\n \"Weight is not in safe integer range\",\n );\n return parseFloat(formattedBig.toString());\n};\n\n/**\n * Prepares floating number to be stored in database as normalized bigint\n *\n * Database weights are stored either in g or oz\n */\nexport const transformNumberToDatabaseWeight = (\n numberWeight: number,\n system: UnitSystem,\n): string => {\n switch (system) {\n case UnitSystem.Metric: {\n /**\n * convert(1).from(oz).to(g) is 28.34952g.\n * We are stripping sub-gram measures, because database is storing grams\n */\n const numberWeightInt = parseInt(numberWeight.toFixed(0));\n\n assert(\n !!Number.isSafeInteger(numberWeightInt),\n \"Number is not safe integer\",\n );\n\n return numberWeightInt.toString();\n }\n case UnitSystem.Imperial: {\n const weightBig = Big(numberWeight);\n const multiplier = Big(10).pow(DINERO_WEIGHT_OZ.exponent.toNumber());\n return weightBig.mul(multiplier).toFixed(0);\n }\n default:\n assertUnreachable(system);\n }\n};\n\n/**\n * Shorthand function to transform weight number to formatted string.\n *\n * ! Use only with base weights g/oz\n */\nexport const transformBaseWeightNumberToFormat = (\n databaseWeight: number,\n system: UnitSystem,\n): string =>\n transformDatabaseWeightToFormat(\n transformNumberToDatabaseWeight(databaseWeight, system),\n system,\n );\n"],"names":["convert","configureMeasurements","length","mass","calculator","add","a","b","plus","compare","cmp","decrement","v","minus","Big","increment","integerDivide","div","round","roundDown","modulo","mod","multiply","times","power","pow","Number","subtract","zero","toNumber","NaN","dineroBigint","createDinero","DINERO_WEIGHT_G","code","base","exponent","DINERO_WEIGHT_OZ","transformer","currency","dineroObject","multiplier","jsonObject","toJSON","formattedWeight","amount","mul","toFixed","toString","transformDatabaseWeightToFormat","databaseWeight","system","UnitSystem","Metric","toFormat","Imperial","assertUnreachable","transformDatabaseWeightToNumber","formattedBig","assert","lte","MAX_SAFE_INTEGER","parseFloat","transformNumberToDatabaseWeight","numberWeight","numberWeightInt","parseInt","isSafeInteger","weightBig","transformBaseWeightNumberToFormat"],"mappings":";;;;;;;AAqBO,MAAMA,UAAUC,qBAAgD,CAAA;EACrEC,MAAA;EACAC;AACF,CAAC,CAAA;AAED,MAAMC,UAA8B,GAAA;EAClCC,KAAKA,CAACC,CAAA,EAAGC,CAAM,KAAAD,CAAA,CA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AAA,GAAkCA,CAC7CC,YAAA,EACAb,MACW,KAAA;EACX,QAAQA,MAAQ;IACd,KAAKC,WAAWC,MAAQ;MAAA;QAKtB,MAAMY,eAAkB,GAAAC,QAAA,CAASF,YAAa,CAAAjB,OAAA,CAAQ,CAAC,CAAC,CAAA;QAExDY,MAAA,CACE,CAAC,CAACjC,MAAO,CAAAyC,aAAA,CAAcF,eAAe,CAAA,EACtC,4BAAA,CACF;QAEA,OAAOA,gBAAgBjB,QAAS,EAAA;MAClC;IACA,KAAKI,WAAWG,QAAU;MAAA;QAClB,MAAAa,SAAA,GAAYtD,IAAIkD,YAAY,CAAA;QAC5B,MAAAvB,UAAA,GAAa3B,IAAI,EAAE,CAAA,CAAEW,IAAIY,gBAAiB,CAAAD,QAAA,CAASP,UAAU,CAAA;QACnE,OAAOuC,SAAU,CAAAtB,GAAA,CAAIL,UAAU,CAAA,CAAEM,QAAQ,CAAC,CAAA;MAC5C;IACA;MACES,iBAAA,CAAkBL,MAAM,CAAA;EAC5B;AACF,CAAA;AAOa,MAAAkB,iCAAA,GAAoCA,CAC/CnB,cAAA,EACAC,MAEA,KAAAF,+BAAA,CACEc,+BAAA,CAAgCb,gBAAgBC,MAAM,CAAA,EACtDA,MACF,CAAA;"}
1
+ {"version":3,"file":"measures.mjs","sources":["../../src/utils/measures.ts"],"sourcesContent":["import { Big } from \"big.js\";\nimport type {\n LengthSystems,\n LengthUnits,\n MassSystems,\n MassUnits,\n} from \"convert-units\";\nimport configureMeasurements, { length, mass } from \"convert-units\";\nimport type { Calculator, ComparisonOperator, Transformer } from \"dinero.js\";\nimport { createDinero, toFormat } from \"dinero.js\";\n\nimport { UnitSystem } from \"../types\";\nimport { assert, assertUnreachable } from \"./errors\";\n\n// Measures: The names of the measures being used\ntype Measures = \"length\" | \"mass\";\n// Systems: The systems being used across all measures\ntype Systems = LengthSystems | MassSystems;\n// Units: All the units across all measures and their systems\ntype Units = LengthUnits | MassUnits;\n\nexport const convert = configureMeasurements<Measures, Systems, Units>({\n length,\n mass,\n});\n\nconst calculator: Calculator<Big> = {\n add: (a, b) => a.plus(b),\n compare: (a, b) => a.cmp(b) as unknown as ComparisonOperator,\n decrement: (v) => v.minus(new Big(1)),\n increment: (v) => v.plus(new Big(1)),\n integerDivide: (a, b) => a.div(b).round(0, Big.roundDown),\n modulo: (a, b) => a.mod(b),\n multiply: (a, b) => a.times(b),\n power: (a, b) => a.pow(Number(b)),\n subtract: (a, b) => a.minus(b),\n zero: () => new Big(0),\n toNumber: () => NaN,\n};\n\nconst dineroBigint = createDinero({ calculator });\n\n// type ConvertMassFromTo =\n// | { from: Unit.G; to: Unit.Kg }\n// | { from: Unit.Kg; to: Unit. }\n// | { from: Unit.G; to: Unit.Kg }\n// | { from: Unit.G; to: Unit.Kg }\n// | { from: Unit.G; to: Unit.Kg }\n// | { from: Unit.G; to: Unit.Kg }\n// export const convertMass = (value: number, {from, to}: ConvertMassFromTo) => {\n// return convert(value).from(from).to(to)\n// }\n\nconst DINERO_WEIGHT_G = {\n code: \"WEIGHT_G\",\n base: Big(10),\n exponent: Big(0),\n};\nconst DINERO_WEIGHT_OZ = {\n code: \"WEIGHT_OZ\",\n base: Big(10),\n exponent: Big(6),\n};\n\ntype TransformerOptions = Parameters<Transformer<Big>>[0];\nconst transformer = ({ currency, dineroObject }: TransformerOptions) => {\n const exponent = currency.exponent;\n const multiplier = Big(0.1).pow(exponent.toNumber());\n\n const jsonObject = dineroObject.toJSON();\n const formattedWeight = jsonObject.amount\n .mul(multiplier)\n .toFixed(exponent.toNumber());\n\n return formattedWeight.toString();\n};\n\n/**\n * In database we store weight in \"weird\" format.\n * For metric we store weight in grams as is.\n * For imperial we store weight in oz with \"virtual scale/exponent\" => 6.\n * e.g. 1_000_000 => '1'\n * e.g. 300_000 => '0.3'\n *\n * Database weight is stored either in g or oz\n */\nexport const transformDatabaseWeightToFormat = (\n databaseWeight: string,\n system: UnitSystem,\n): string => {\n switch (system) {\n case UnitSystem.Metric:\n return toFormat(\n dineroBigint({\n amount: Big(databaseWeight),\n currency: DINERO_WEIGHT_G,\n }),\n transformer,\n );\n case UnitSystem.Imperial: {\n return toFormat(\n dineroBigint({\n amount: Big(databaseWeight),\n currency: DINERO_WEIGHT_OZ,\n }),\n transformer,\n );\n }\n default:\n assertUnreachable(system);\n }\n};\n\n/**\n * Executes transformDatabaseWeightToFormat and returns it as number if safe integer\n *\n * Database weight is stored either in g or oz\n */\nexport const transformDatabaseWeightToNumber = (\n databaseWeight: string,\n system: UnitSystem,\n): number => {\n const formattedBig = Big(\n transformDatabaseWeightToFormat(databaseWeight, system),\n );\n\n assert(\n formattedBig.lte(Number.MAX_SAFE_INTEGER),\n \"Weight is not in safe integer range\",\n );\n return parseFloat(formattedBig.toString());\n};\n\n/**\n * Prepares floating number to be stored in database as normalized bigint\n *\n * Database weights are stored either in g or oz\n */\nexport const transformNumberToDatabaseWeight = (\n numberWeight: number,\n system: UnitSystem,\n): string => {\n switch (system) {\n case UnitSystem.Metric: {\n /**\n * convert(1).from(oz).to(g) is 28.34952g.\n * We are stripping sub-gram measures, because database is storing grams\n */\n const numberWeightInt = parseInt(numberWeight.toFixed(0));\n\n assert(\n !!Number.isSafeInteger(numberWeightInt),\n \"Number is not safe integer\",\n );\n\n return numberWeightInt.toString();\n }\n case UnitSystem.Imperial: {\n const weightBig = Big(numberWeight);\n const multiplier = Big(10).pow(DINERO_WEIGHT_OZ.exponent.toNumber());\n return weightBig.mul(multiplier).toFixed(0);\n }\n default:\n assertUnreachable(system);\n }\n};\n\n/**\n * Shorthand function to transform weight number to formatted string.\n *\n * ! Use only with base weights g/oz\n */\nexport const transformBaseWeightNumberToFormat = (\n databaseWeight: number,\n system: UnitSystem,\n): string =>\n transformDatabaseWeightToFormat(\n transformNumberToDatabaseWeight(databaseWeight, system),\n system,\n );\n"],"names":["convert","configureMeasurements","length","mass","calculator","add","a","b","plus","compare","cmp","decrement","v","minus","Big","increment","integerDivide","div","round","roundDown","modulo","mod","multiply","times","power","pow","Number","subtract","zero","toNumber","NaN","dineroBigint","createDinero","DINERO_WEIGHT_G","code","base","exponent","DINERO_WEIGHT_OZ","transformer","currency","dineroObject","multiplier","jsonObject","toJSON","formattedWeight","amount","mul","toFixed","toString","transformDatabaseWeightToFormat","databaseWeight","system","UnitSystem","Metric","toFormat","Imperial","assertUnreachable","transformDatabaseWeightToNumber","formattedBig","assert","lte","MAX_SAFE_INTEGER","parseFloat","transformNumberToDatabaseWeight","numberWeight","numberWeightInt","parseInt","isSafeInteger","weightBig","transformBaseWeightNumberToFormat"],"mappings":";;;;;;;AAqBO,MAAMA,UAAUC,qBAAgD,CAAA;EACrEC,MAAA;EACAC;AACF,CAAC,CAAA;AAED,MAAMC,UAA8B,GAAA;EAClCC,KAAKA,CAACC,CAAA,EAAGC,CAAM,KAAAD,CAAA,CAAEE,KAAKD,CAAC,CAAA;EACvBE,SAASA,CAACH,CAAA,EAAGC,CAAM,KAAAD,CAAA,CAAEI,IAAIH,CAAC,CAAA;EAC1BI,SAAA,EAAYC,CAAM,IAAAA,CAAA,CAAEC,MAAM,IAAIC,GAAA,CAAI,CAAC,CAAC,CAAA;EACpCC,SAAA,EAAYH,CAAM,IAAAA,CAAA,CAAEJ,KAAK,IAAIM,GAAA,CAAI,CAAC,CAAC,CAAA;EACnCE,aAAA,EAAeA,CAACV,CAAA,EAAGC,CAAM,KAAAD,CAAA,CAAEW,GAAI,CAAAV,CAAC,CAAE,CAAAW,KAAA,CAAM,CAAG,EAAAJ,GAAA,CAAIK,SAAS,CAAA;EACxDC,QAAQA,CAACd,CAAA,EAAGC,CAAM,KAAAD,CAAA,CAAEe,IAAId,CAAC,CAAA;EACzBe,UAAUA,CAAChB,CAAA,EAAGC,CAAM,KAAAD,CAAA,CAAEiB,MAAMhB,CAAC,CAAA;EAC7BiB,KAAA,EAAOA,CAAClB,CAAG,EAAAC,CAAA,KAAMD,EAAEmB,GAAI,CAAAC,MAAA,CAAOnB,CAAC,CAAC,CAAA;EAChCoB,UAAUA,CA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,gBAAgBC,MAAM,CAAA,EACtDA,MACF,CAAA;"}
@@ -1 +1 @@
1
- {"version":3,"file":"format.js","sources":["../../../src/utils/money/format.ts"],"sourcesContent":["import { CAD, EUR, GBP } from \"@dinero.js/currencies\";\nimport { hasSubUnits, toFormat, toUnit } from \"dinero.js\";\n\nimport type { Currency, Nullish } from \"../../types\";\nimport { assert } from \"../errors\";\nimport {\n localizedCurrencyLookup,\n prettifyPriceLookup,\n Round,\n} from \"./constants\";\nimport { getDinero, roundDinero } from \"./misc\";\nimport type { Dino, LocalizedCurrency, Money } from \"./types\";\n\nexport const getLocalizedCurrency = (\n currencyCode: Nullish<Currency>,\n): LocalizedCurrency | undefined => {\n return currencyCode ? localizedCurrencyLookup.get(currencyCode) : undefined;\n};\n\n// #############################################################################\n// Formatter\n// #############################################################################\nconst currencyFormatterCache = new Map<string, Intl.NumberFormat>();\n/**\n * Function to get a Int.NumberFormat instance that can be reused to format currency over using\n * `Number.toLocaleString(...)` function, which makes more sense to use as we usually just display 1 or 2 currencies\n * MAX, so reusing the formatted makes a lot of sense\n * @see https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Number/toLocaleString#performance\n */\nconst getCurrencyFormatter = (\n locale: string,\n currencyCode: string,\n): Intl.NumberFormat => {\n const cacheKey = `${locale}_${currencyCode}`;\n\n let formatter = currencyFormatterCache.get(cacheKey);\n if (formatter) {\n return formatter;\n }\n\n formatter = new Intl.NumberFormat(locale, {\n style: \"currency\",\n currency: currencyCode,\n /**\n * Explicitly define default behavior - just in case some runtime overrides it\n * @see https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Intl/NumberFormat/NumberFormat#currencysign\n * @see https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Intl/NumberFormat/NumberFormat#currencydisplay\n */\n currencySign: \"standard\",\n currencyDisplay: \"symbol\",\n });\n currencyFormatterCache.set(cacheKey, formatter);\n\n return formatter;\n};\n\nexport type FormatPriceOptions = {\n /**\n * Optionally remove trailing zeroes (only if all of them are 0)\n * @default false\n * @example\n * \"420,66 €\" => \"420,66 €\"\n * \"420,60 €\" => \"420,60 €\"\n * \"420,00 €\" => \"420 €\"\n */\n removeTrailingZeros?: boolean;\n /**\n * Optionally return currency rounded down to the nearest dollar-equivalent of a the given currency. Doesn't apply any\n * rounding just \"trims\" end decimal values\n *\n * ! Only use for display purposes where monetary precision is not required!\n *\n * @default false\n * @example\n * \"420,66 €\" => \"420 €\"\n * \"420,60 €\" => \"420 €\"\n * \"420,00 €\" => \"420 €\"\n */\n removeFractions?: boolean;\n};\n\n/**\n * Currency formatter based on dinero currency types and browser internationalizing functions\n *\n * Based on:\n * @see https://v2.dinerojs.com/docs/guides/formatting-in-a-multilingual-site#building-a-custom-internationalization-formatter\n * @protected\n * @deprecated Use `formatPrice` instead as this functions is for INTERNAL USE ONLY! (function not actual deprecated,\n * just marked so it discourages usage of it)\n */\nexport function formatPriceRaw(\n dinero: Dino,\n locale: string,\n options?: FormatPriceOptions,\n): string {\n return toFormat(dinero, ({ amount, currency }) => {\n const formatter = getCurrencyFormatter(locale, currency.code);\n const formatted = formatter.format(amount);\n\n return options?.removeFractions || options?.removeTrailingZeros\n ? /**\n * Regex to handle complex removing trailing zeros from currency\n * - Dynamically create regex based on currency as their exponent changes\n * - Also handles some currencies (e.g. EUR) having trailing currency symbol\n *\n * TODO: improve how we detect \"decimal separator\" for formatted currency, at least right now we have tests for it and doesn't seem like an issue\n */\n formatted.replace(\n // For some reason `\\.` need to be double-escaped `\\\\` when creating the regex from template string\n new RegExp(\n `(\\\\.|,)${\n // Depending options remove all trailing digits or just zeros, this way we don't need to do any rounding\n options?.removeFractions ? \"\\\\d\" : 0\n }{0,${currency.exponent}}(\\\\s\\\\D)?$`,\n ),\n // In the replaced using \"last capture group\" (if-exists) so we restore the trailing currency sign\n \"$2\",\n )\n : formatted;\n });\n}\n\n/**\n * Currency formatter based on dinero currency types and browser internationalizing functions\n *\n * In reality just a wrapper around `formatPriceRaw` that does the real formatting\n */\nexport const formatPrice = (\n money: Money,\n options?: FormatPriceOptions,\n): string => {\n const localizedCurrency = getLocalizedCurrency(money.currency);\n assert(!!localizedCurrency, `Currency ${money.currency} not supported`);\n\n // eslint-disable-next-line sonarjs/deprecation\n return formatPriceRaw(\n getDinero(money.amount, money.currency),\n localizedCurrency.locale,\n options,\n );\n};\n\n/**\n * Prettify numbers depending on the currency using rounding down.\n * ! Should only be used to prettify storefront product prices after currency conversion but nothing else !\n */\nexport const prettifyTotal = (total: Dino): Dino => {\n const totalJson = total.toJSON();\n\n switch (totalJson.currency.code) {\n // @see: https://ubiquiti.atlassian.net/browse/NEP-3846\n case EUR.code:\n case GBP.code:\n case CAD.code: {\n const totalAsFloat = toUnit(total);\n\n if (totalAsFloat < 10) {\n return roundDinero(total, Round.PrettifyDecimalCents);\n } else if (totalAsFloat < 20) {\n return roundDinero(total, Round.PrettifyHalfUnitCents);\n } else if (totalAsFloat < 50) {\n return roundDinero(total, Round.Prettify);\n } else {\n return roundDinero(total, Round.PrettifyFull059);\n }\n }\n default: {\n // Nothing to round\n if (!hasSubUnits(total)) {\n return total;\n }\n\n const minValueInclusiveToRoundDownFrom = prettifyPriceLookup.get(\n totalJson.currency.code,\n );\n\n // Don't round if currency unsupported or value is below min threshold\n if (\n minValueInclusiveToRoundDownFrom == null ||\n toUnit(total) < minValueInclusiveToRoundDownFrom\n ) {\n return total;\n }\n\n return roundDinero(total, Round.Prettify);\n }\n }\n};\n"],"names":["getLocalizedCurrency","currencyCode","localizedCurrencyLookup","get","currencyFormatterCache","Map","getCurrencyFormatter","locale","cacheKey","formatter","Intl","NumberFormat","style","currency","currencySign","currencyDisplay","set","formatPriceRaw","dinero","options","toFormat","amount","code","formatted","format","removeFractions","removeTrailingZeros","replace","RegExp","exponent","formatPrice","money","localizedCurrency","assert","getDinero","prettifyTotal","total","totalJson","toJSON","EUR","GBP","CAD","totalAsFloat","toUnit","roundDinero","Round","PrettifyDecimalCents","P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A,KAAA,CAAMG,QAAQ,CAAA;QAAA,CACnC,MAAA;UACE,OAAAJ,gBAAA,CAAYR,KAAO,EAAAS,SAAA,CAAAA,KAAA,CAAMI,eAAe,CAAA;QACjD;MACF;IACA;MAAS;QAEH,IAAA,CAACC,SAAAA,CAAAA,WAAY,CAAAd,KAAK,CAAG,EAAA;UAChB,OAAAA,KAAA;QACT;QAEA,MAAMe,mCAAmCC,SAAAA,CAAAA,mBAAoB,CAAAjD,GAAA,CAC3DkC,UAAUxB,QAAS,CAAAS,IAAA,CACrB;QAGA,IACE6B,gCAAoC,IAAA,IAAA,IACpCR,SAAO,CAAAA,MAAA,CAAAP,KAAK,IAAIe,gCAChB,EAAA;UACO,OAAAf,KAAA;QACT;QAEO,OAAAQ,gBAAA,CAAYR,KAAO,EAAAS,SAAA,CAAAA,KAAA,CAAMG,QAAQ,CAAA;MAC1C;EACF;AACF,CAAA;;;;"}
1
+ {"version":3,"file":"format.js","sources":["../../../src/utils/money/format.ts"],"sourcesContent":["import { CAD, EUR, GBP } from \"@dinero.js/currencies\";\nimport { hasSubUnits, toFormat, toUnit } from \"dinero.js\";\n\nimport type { Currency, Nullish } from \"../../types\";\nimport { assert } from \"../errors\";\nimport {\n localizedCurrencyLookup,\n prettifyPriceLookup,\n Round,\n} from \"./constants\";\nimport { getDinero, roundDinero } from \"./misc\";\nimport type { Dino, LocalizedCurrency, Money } from \"./types\";\n\nexport const getLocalizedCurrency = (\n currencyCode: Nullish<Currency>,\n): LocalizedCurrency | undefined => {\n return currencyCode ? localizedCurrencyLookup.get(currencyCode) : undefined;\n};\n\n// #############################################################################\n// Formatter\n// #############################################################################\nconst currencyFormatterCache = new Map<string, Intl.NumberFormat>();\n/**\n * Function to get a Int.NumberFormat instance that can be reused to format currency over using\n * `Number.toLocaleString(...)` function, which makes more sense to use as we usually just display 1 or 2 currencies\n * MAX, so reusing the formatted makes a lot of sense\n * @see https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Number/toLocaleString#performance\n */\nconst getCurrencyFormatter = (\n locale: string,\n currencyCode: string,\n): Intl.NumberFormat => {\n const cacheKey = `${locale}_${currencyCode}`;\n\n let formatter = currencyFormatterCache.get(cacheKey);\n if (formatter) {\n return formatter;\n }\n\n formatter = new Intl.NumberFormat(locale, {\n style: \"currency\",\n currency: currencyCode,\n /**\n * Explicitly define default behavior - just in case some runtime overrides it\n * @see https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Intl/NumberFormat/NumberFormat#currencysign\n * @see https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Intl/NumberFormat/NumberFormat#currencydisplay\n */\n currencySign: \"standard\",\n currencyDisplay: \"symbol\",\n });\n currencyFormatterCache.set(cacheKey, formatter);\n\n return formatter;\n};\n\nexport type FormatPriceOptions = {\n /**\n * Optionally remove trailing zeroes (only if all of them are 0)\n * @default false\n * @example\n * \"420,66 €\" => \"420,66 €\"\n * \"420,60 €\" => \"420,60 €\"\n * \"420,00 €\" => \"420 €\"\n */\n removeTrailingZeros?: boolean;\n /**\n * Optionally return currency rounded down to the nearest dollar-equivalent of a the given currency. Doesn't apply any\n * rounding just \"trims\" end decimal values\n *\n * ! Only use for display purposes where monetary precision is not required!\n *\n * @default false\n * @example\n * \"420,66 €\" => \"420 €\"\n * \"420,60 €\" => \"420 €\"\n * \"420,00 €\" => \"420 €\"\n */\n removeFractions?: boolean;\n};\n\n/**\n * Currency formatter based on dinero currency types and browser internationalizing functions\n *\n * Based on:\n * @see https://v2.dinerojs.com/docs/guides/formatting-in-a-multilingual-site#building-a-custom-internationalization-formatter\n * @protected\n * @deprecated Use `formatPrice` instead as this functions is for INTERNAL USE ONLY! (function not actual deprecated,\n * just marked so it discourages usage of it)\n */\nexport function formatPriceRaw(\n dinero: Dino,\n locale: string,\n options?: FormatPriceOptions,\n): string {\n return toFormat(dinero, ({ amount, currency }) => {\n const formatter = getCurrencyFormatter(locale, currency.code);\n const formatted = formatter.format(amount);\n\n return options?.removeFractions || options?.removeTrailingZeros\n ? /**\n * Regex to handle complex removing trailing zeros from currency\n * - Dynamically create regex based on currency as their exponent changes\n * - Also handles some currencies (e.g. EUR) having trailing currency symbol\n *\n * TODO: improve how we detect \"decimal separator\" for formatted currency, at least right now we have tests for it and doesn't seem like an issue\n */\n formatted.replace(\n // For some reason `\\.` need to be double-escaped `\\\\` when creating the regex from template string\n new RegExp(\n `(\\\\.|,)${\n // Depending options remove all trailing digits or just zeros, this way we don't need to do any rounding\n options?.removeFractions ? \"\\\\d\" : 0\n }{0,${currency.exponent}}(\\\\s\\\\D)?$`,\n ),\n // In the replaced using \"last capture group\" (if-exists) so we restore the trailing currency sign\n \"$2\",\n )\n : formatted;\n });\n}\n\n/**\n * Currency formatter based on dinero currency types and browser internationalizing functions\n *\n * In reality just a wrapper around `formatPriceRaw` that does the real formatting\n */\nexport const formatPrice = (\n money: Money,\n options?: FormatPriceOptions,\n): string => {\n const localizedCurrency = getLocalizedCurrency(money.currency);\n assert(!!localizedCurrency, `Currency ${money.currency} not supported`);\n\n return formatPriceRaw(\n getDinero(money.amount, money.currency),\n localizedCurrency.locale,\n options,\n );\n};\n\n/**\n * Prettify numbers depending on the currency using rounding down.\n * ! Should only be used to prettify storefront product prices after currency conversion but nothing else !\n */\nexport const prettifyTotal = (total: Dino): Dino => {\n const totalJson = total.toJSON();\n\n switch (totalJson.currency.code) {\n // @see: https://ubiquiti.atlassian.net/browse/NEP-3846\n case EUR.code:\n case GBP.code:\n case CAD.code: {\n const totalAsFloat = toUnit(total);\n\n if (totalAsFloat < 10) {\n return roundDinero(total, Round.PrettifyDecimalCents);\n } else if (totalAsFloat < 20) {\n return roundDinero(total, Round.PrettifyHalfUnitCents);\n } else if (totalAsFloat < 50) {\n return roundDinero(total, Round.Prettify);\n } else {\n return roundDinero(total, Round.PrettifyFull059);\n }\n }\n default: {\n // Nothing to round\n if (!hasSubUnits(total)) {\n return total;\n }\n\n const minValueInclusiveToRoundDownFrom = prettifyPriceLookup.get(\n totalJson.currency.code,\n );\n\n // Don't round if currency unsupported or value is below min threshold\n if (\n minValueInclusiveToRoundDownFrom == null ||\n toUnit(total) < minValueInclusiveToRoundDownFrom\n ) {\n return total;\n }\n\n return roundDinero(total, Round.Prettify);\n }\n }\n};\n"],"names":["getLocalizedCurrency","currencyCode","localizedCurrencyLookup","get","currencyFormatterCache","Map","getCurrencyFormatter","locale","cacheKey","formatter","Intl","NumberFormat","style","currency","currencySign","currencyDisplay","set","formatPriceRaw","dinero","options","toFormat","amount","code","formatted","format","removeFractions","removeTrailingZeros","replace","RegExp","exponent","formatPrice","money","localizedCurrency","assert","getDinero","prettifyTotal","total","totalJson","toJSON","EUR","GBP","CAD","totalAsFloat","toUnit","roundDinero","Round","PrettifyDecimalCents","PrettifyHalfUnitCents","Prettify","PrettifyFull059","hasSubUnits","minValueInclusiveToRoundDownFrom","prettifyPriceLookup"],"mappings":";;;;;;;;AAaa,MAAAA,oBAAA,GACXC,YACkC,IAAA;EAClC,OAAOA,YAAe,GAAAC,SAAAA,CAAAA,uBAAA,CAAwBC,GAAI,CAAAF,YAAY,CAAI,GAAA,KAAA,CAAA;AACpE,CAAA;AAKA,MAAMG,sBAAA,GAAA,mBAA6BC,GAA+B,EAAA;AAOlE,MAAMC,oBAAA,GAAuBA,CAC3BC,MAAA,EACAN,YACsB,KAAA;EACtB,MAAMO,QAAW,GAAA,GAAGD,MAAM,IAAIN,YAAY,EAAA;EAEtC,IAAAQ,SAAA,GAAYL,sBAAuB,CAAAD,GAAA,CAAIK,QAAQ,CAAA;EACnD,IAAIC,SAAW,EAAA;IACN,OAAAA,SAAA;EACT;EAEYA,SAAA,GAAA,IAAIC,IAAK,CAAAC,YAAA,CAAaJ,MAAQ,EAAA;IACxCK,KAAO,EAAA,UAAA;IACPC,QAAU,EAAAZ,YAAA;IAAA;AAAA;AAAA;AAAA;AAAA;IAMVa,YAAc,EAAA,UAAA;IACdC,eAAiB,EAAA;EAAA,CAClB,CAAA;EACsB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,IAAA;IACT,KAAKkB,UAAAA,CAAAA,GAAI,CAAAlB,IAAA;IACT,KAAKmB,UAAAA,CAAAA,IAAInB,IAAM;MAAA;QACP,MAAAoB,YAAA,GAAeC,iBAAOP,KAAK,CAAA;QAEjC,IAAIM,eAAe,EAAI,EAAA;UACd,OAAAE,gBAAA,CAAYR,KAAO,EAAAS,SAAA,CAAAA,KAAA,CAAMC,oBAAoB,CAAA;QAAA,CACtD,MAAA,IAAWJ,eAAe,EAAI,EAAA;UACrB,OAAAE,gBAAA,CAAYR,KAAO,EAAAS,SAAA,CAAAA,KAAA,CAAME,qBAAqB,CAAA;QAAA,CACvD,MAAA,IAAWL,eAAe,EAAI,EAAA;UACrB,OAAAE,gBAAA,CAAYR,KAAO,EAAAS,SAAA,CAAAA,KAAA,CAAMG,QAAQ,CAAA;QAAA,CACnC,MAAA;UACE,OAAAJ,gBAAA,CAAYR,KAAO,EAAAS,SAAA,CAAAA,KAAA,CAAMI,eAAe,CAAA;QACjD;MACF;IACA;MAAS;QAEH,IAAA,CAACC,SAAAA,CAAAA,WAAY,CAAAd,KAAK,CAAG,EAAA;UAChB,OAAAA,KAAA;QACT;QAEA,MAAMe,mCAAmCC,SAAAA,CAAAA,mBAAoB,CAAAjD,GAAA,CAC3DkC,UAAUxB,QAAS,CAAAS,IAAA,CACrB;QAGA,IACE6B,gCAAoC,IAAA,IAAA,IACpCR,SAAO,CAAAA,MAAA,CAAAP,KAAK,IAAIe,gCAChB,EAAA;UACO,OAAAf,KAAA;QACT;QAEO,OAAAQ,gBAAA,CAAYR,KAAO,EAAAS,SAAA,CAAAA,KAAA,CAAMG,QAAQ,CAAA;MAC1C;EACF;AACF,CAAA;;;;"}
@@ -1 +1 @@
1
- {"version":3,"file":"format.mjs","sources":["../../../src/utils/money/format.ts"],"sourcesContent":["import { CAD, EUR, GBP } from \"@dinero.js/currencies\";\nimport { hasSubUnits, toFormat, toUnit } from \"dinero.js\";\n\nimport type { Currency, Nullish } from \"../../types\";\nimport { assert } from \"../errors\";\nimport {\n localizedCurrencyLookup,\n prettifyPriceLookup,\n Round,\n} from \"./constants\";\nimport { getDinero, roundDinero } from \"./misc\";\nimport type { Dino, LocalizedCurrency, Money } from \"./types\";\n\nexport const getLocalizedCurrency = (\n currencyCode: Nullish<Currency>,\n): LocalizedCurrency | undefined => {\n return currencyCode ? localizedCurrencyLookup.get(currencyCode) : undefined;\n};\n\n// #############################################################################\n// Formatter\n// #############################################################################\nconst currencyFormatterCache = new Map<string, Intl.NumberFormat>();\n/**\n * Function to get a Int.NumberFormat instance that can be reused to format currency over using\n * `Number.toLocaleString(...)` function, which makes more sense to use as we usually just display 1 or 2 currencies\n * MAX, so reusing the formatted makes a lot of sense\n * @see https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Number/toLocaleString#performance\n */\nconst getCurrencyFormatter = (\n locale: string,\n currencyCode: string,\n): Intl.NumberFormat => {\n const cacheKey = `${locale}_${currencyCode}`;\n\n let formatter = currencyFormatterCache.get(cacheKey);\n if (formatter) {\n return formatter;\n }\n\n formatter = new Intl.NumberFormat(locale, {\n style: \"currency\",\n currency: currencyCode,\n /**\n * Explicitly define default behavior - just in case some runtime overrides it\n * @see https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Intl/NumberFormat/NumberFormat#currencysign\n * @see https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Intl/NumberFormat/NumberFormat#currencydisplay\n */\n currencySign: \"standard\",\n currencyDisplay: \"symbol\",\n });\n currencyFormatterCache.set(cacheKey, formatter);\n\n return formatter;\n};\n\nexport type FormatPriceOptions = {\n /**\n * Optionally remove trailing zeroes (only if all of them are 0)\n * @default false\n * @example\n * \"420,66 €\" => \"420,66 €\"\n * \"420,60 €\" => \"420,60 €\"\n * \"420,00 €\" => \"420 €\"\n */\n removeTrailingZeros?: boolean;\n /**\n * Optionally return currency rounded down to the nearest dollar-equivalent of a the given currency. Doesn't apply any\n * rounding just \"trims\" end decimal values\n *\n * ! Only use for display purposes where monetary precision is not required!\n *\n * @default false\n * @example\n * \"420,66 €\" => \"420 €\"\n * \"420,60 €\" => \"420 €\"\n * \"420,00 €\" => \"420 €\"\n */\n removeFractions?: boolean;\n};\n\n/**\n * Currency formatter based on dinero currency types and browser internationalizing functions\n *\n * Based on:\n * @see https://v2.dinerojs.com/docs/guides/formatting-in-a-multilingual-site#building-a-custom-internationalization-formatter\n * @protected\n * @deprecated Use `formatPrice` instead as this functions is for INTERNAL USE ONLY! (function not actual deprecated,\n * just marked so it discourages usage of it)\n */\nexport function formatPriceRaw(\n dinero: Dino,\n locale: string,\n options?: FormatPriceOptions,\n): string {\n return toFormat(dinero, ({ amount, currency }) => {\n const formatter = getCurrencyFormatter(locale, currency.code);\n const formatted = formatter.format(amount);\n\n return options?.removeFractions || options?.removeTrailingZeros\n ? /**\n * Regex to handle complex removing trailing zeros from currency\n * - Dynamically create regex based on currency as their exponent changes\n * - Also handles some currencies (e.g. EUR) having trailing currency symbol\n *\n * TODO: improve how we detect \"decimal separator\" for formatted currency, at least right now we have tests for it and doesn't seem like an issue\n */\n formatted.replace(\n // For some reason `\\.` need to be double-escaped `\\\\` when creating the regex from template string\n new RegExp(\n `(\\\\.|,)${\n // Depending options remove all trailing digits or just zeros, this way we don't need to do any rounding\n options?.removeFractions ? \"\\\\d\" : 0\n }{0,${currency.exponent}}(\\\\s\\\\D)?$`,\n ),\n // In the replaced using \"last capture group\" (if-exists) so we restore the trailing currency sign\n \"$2\",\n )\n : formatted;\n });\n}\n\n/**\n * Currency formatter based on dinero currency types and browser internationalizing functions\n *\n * In reality just a wrapper around `formatPriceRaw` that does the real formatting\n */\nexport const formatPrice = (\n money: Money,\n options?: FormatPriceOptions,\n): string => {\n const localizedCurrency = getLocalizedCurrency(money.currency);\n assert(!!localizedCurrency, `Currency ${money.currency} not supported`);\n\n // eslint-disable-next-line sonarjs/deprecation\n return formatPriceRaw(\n getDinero(money.amount, money.currency),\n localizedCurrency.locale,\n options,\n );\n};\n\n/**\n * Prettify numbers depending on the currency using rounding down.\n * ! Should only be used to prettify storefront product prices after currency conversion but nothing else !\n */\nexport const prettifyTotal = (total: Dino): Dino => {\n const totalJson = total.toJSON();\n\n switch (totalJson.currency.code) {\n // @see: https://ubiquiti.atlassian.net/browse/NEP-3846\n case EUR.code:\n case GBP.code:\n case CAD.code: {\n const totalAsFloat = toUnit(total);\n\n if (totalAsFloat < 10) {\n return roundDinero(total, Round.PrettifyDecimalCents);\n } else if (totalAsFloat < 20) {\n return roundDinero(total, Round.PrettifyHalfUnitCents);\n } else if (totalAsFloat < 50) {\n return roundDinero(total, Round.Prettify);\n } else {\n return roundDinero(total, Round.PrettifyFull059);\n }\n }\n default: {\n // Nothing to round\n if (!hasSubUnits(total)) {\n return total;\n }\n\n const minValueInclusiveToRoundDownFrom = prettifyPriceLookup.get(\n totalJson.currency.code,\n );\n\n // Don't round if currency unsupported or value is below min threshold\n if (\n minValueInclusiveToRoundDownFrom == null ||\n toUnit(total) < minValueInclusiveToRoundDownFrom\n ) {\n return total;\n }\n\n return roundDinero(total, Round.Prettify);\n }\n }\n};\n"],"names":["getLocalizedCurrency","currencyCode","localizedCurrencyLookup","get","currencyFormatterCache","Map","getCurrencyFormatter","locale","cacheKey","formatter","Intl","NumberFormat","style","currency","currencySign","currencyDisplay","set","formatPriceRaw","dinero","options","toFormat","amount","code","formatted","format","removeFractions","removeTrailingZeros","replace","RegExp","exponent","formatPrice","money","localizedCurrency","assert","getDinero","prettifyTotal","total","totalJson","toJSON","EUR","GBP","CAD","totalAsFloat","toUnit","roundDinero","Round","PrettifyDecimalCents","PrettifyHalfUnitCents","Prettify","PrettifyFull059","hasSubUnits","minValueInclusiveToRoundDownFrom","prettifyPriceLookup"],"mappings":";;;;;;AAaa,MAAAA,oBAAA,GACXC,YACkC,IAAA;EAClC,OAAOA,YAAe,GAAAC,uBAAA,CAAwBC,GAAI,CAAAF,YAAY,CAAI,GAAA,KAAA,CAAA;AACpE,CA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AAAP,KAAK,IAAIe,gCAChB,EAAA;UACO,OAAAf,KAAA;QACT;QAEO,OAAAQ,WAAA,CAAYR,KAAO,EAAAS,KAAA,CAAMG,QAAQ,CAAA;MAC1C;EACF;AACF,CAAA;"}
1
+ {"version":3,"file":"format.mjs","sources":["../../../src/utils/money/format.ts"],"sourcesContent":["import { CAD, EUR, GBP } from \"@dinero.js/currencies\";\nimport { hasSubUnits, toFormat, toUnit } from \"dinero.js\";\n\nimport type { Currency, Nullish } from \"../../types\";\nimport { assert } from \"../errors\";\nimport {\n localizedCurrencyLookup,\n prettifyPriceLookup,\n Round,\n} from \"./constants\";\nimport { getDinero, roundDinero } from \"./misc\";\nimport type { Dino, LocalizedCurrency, Money } from \"./types\";\n\nexport const getLocalizedCurrency = (\n currencyCode: Nullish<Currency>,\n): LocalizedCurrency | undefined => {\n return currencyCode ? localizedCurrencyLookup.get(currencyCode) : undefined;\n};\n\n// #############################################################################\n// Formatter\n// #############################################################################\nconst currencyFormatterCache = new Map<string, Intl.NumberFormat>();\n/**\n * Function to get a Int.NumberFormat instance that can be reused to format currency over using\n * `Number.toLocaleString(...)` function, which makes more sense to use as we usually just display 1 or 2 currencies\n * MAX, so reusing the formatted makes a lot of sense\n * @see https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Number/toLocaleString#performance\n */\nconst getCurrencyFormatter = (\n locale: string,\n currencyCode: string,\n): Intl.NumberFormat => {\n const cacheKey = `${locale}_${currencyCode}`;\n\n let formatter = currencyFormatterCache.get(cacheKey);\n if (formatter) {\n return formatter;\n }\n\n formatter = new Intl.NumberFormat(locale, {\n style: \"currency\",\n currency: currencyCode,\n /**\n * Explicitly define default behavior - just in case some runtime overrides it\n * @see https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Intl/NumberFormat/NumberFormat#currencysign\n * @see https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Intl/NumberFormat/NumberFormat#currencydisplay\n */\n currencySign: \"standard\",\n currencyDisplay: \"symbol\",\n });\n currencyFormatterCache.set(cacheKey, formatter);\n\n return formatter;\n};\n\nexport type FormatPriceOptions = {\n /**\n * Optionally remove trailing zeroes (only if all of them are 0)\n * @default false\n * @example\n * \"420,66 €\" => \"420,66 €\"\n * \"420,60 €\" => \"420,60 €\"\n * \"420,00 €\" => \"420 €\"\n */\n removeTrailingZeros?: boolean;\n /**\n * Optionally return currency rounded down to the nearest dollar-equivalent of a the given currency. Doesn't apply any\n * rounding just \"trims\" end decimal values\n *\n * ! Only use for display purposes where monetary precision is not required!\n *\n * @default false\n * @example\n * \"420,66 €\" => \"420 €\"\n * \"420,60 €\" => \"420 €\"\n * \"420,00 €\" => \"420 €\"\n */\n removeFractions?: boolean;\n};\n\n/**\n * Currency formatter based on dinero currency types and browser internationalizing functions\n *\n * Based on:\n * @see https://v2.dinerojs.com/docs/guides/formatting-in-a-multilingual-site#building-a-custom-internationalization-formatter\n * @protected\n * @deprecated Use `formatPrice` instead as this functions is for INTERNAL USE ONLY! (function not actual deprecated,\n * just marked so it discourages usage of it)\n */\nexport function formatPriceRaw(\n dinero: Dino,\n locale: string,\n options?: FormatPriceOptions,\n): string {\n return toFormat(dinero, ({ amount, currency }) => {\n const formatter = getCurrencyFormatter(locale, currency.code);\n const formatted = formatter.format(amount);\n\n return options?.removeFractions || options?.removeTrailingZeros\n ? /**\n * Regex to handle complex removing trailing zeros from currency\n * - Dynamically create regex based on currency as their exponent changes\n * - Also handles some currencies (e.g. EUR) having trailing currency symbol\n *\n * TODO: improve how we detect \"decimal separator\" for formatted currency, at least right now we have tests for it and doesn't seem like an issue\n */\n formatted.replace(\n // For some reason `\\.` need to be double-escaped `\\\\` when creating the regex from template string\n new RegExp(\n `(\\\\.|,)${\n // Depending options remove all trailing digits or just zeros, this way we don't need to do any rounding\n options?.removeFractions ? \"\\\\d\" : 0\n }{0,${currency.exponent}}(\\\\s\\\\D)?$`,\n ),\n // In the replaced using \"last capture group\" (if-exists) so we restore the trailing currency sign\n \"$2\",\n )\n : formatted;\n });\n}\n\n/**\n * Currency formatter based on dinero currency types and browser internationalizing functions\n *\n * In reality just a wrapper around `formatPriceRaw` that does the real formatting\n */\nexport const formatPrice = (\n money: Money,\n options?: FormatPriceOptions,\n): string => {\n const localizedCurrency = getLocalizedCurrency(money.currency);\n assert(!!localizedCurrency, `Currency ${money.currency} not supported`);\n\n return formatPriceRaw(\n getDinero(money.amount, money.currency),\n localizedCurrency.locale,\n options,\n );\n};\n\n/**\n * Prettify numbers depending on the currency using rounding down.\n * ! Should only be used to prettify storefront product prices after currency conversion but nothing else !\n */\nexport const prettifyTotal = (total: Dino): Dino => {\n const totalJson = total.toJSON();\n\n switch (totalJson.currency.code) {\n // @see: https://ubiquiti.atlassian.net/browse/NEP-3846\n case EUR.code:\n case GBP.code:\n case CAD.code: {\n const totalAsFloat = toUnit(total);\n\n if (totalAsFloat < 10) {\n return roundDinero(total, Round.PrettifyDecimalCents);\n } else if (totalAsFloat < 20) {\n return roundDinero(total, Round.PrettifyHalfUnitCents);\n } else if (totalAsFloat < 50) {\n return roundDinero(total, Round.Prettify);\n } else {\n return roundDinero(total, Round.PrettifyFull059);\n }\n }\n default: {\n // Nothing to round\n if (!hasSubUnits(total)) {\n return total;\n }\n\n const minValueInclusiveToRoundDownFrom = prettifyPriceLookup.get(\n totalJson.currency.code,\n );\n\n // Don't round if currency unsupported or value is below min threshold\n if (\n minValueInclusiveToRoundDownFrom == null ||\n toUnit(total) < minValueInclusiveToRoundDownFrom\n ) {\n return total;\n }\n\n return roundDinero(total, Round.Prettify);\n }\n }\n};\n"],"names":["getLocalizedCurrency","currencyCode","localizedCurrencyLookup","get","currencyFormatterCache","Map","getCurrencyFormatter","locale","cacheKey","formatter","Intl","NumberFormat","style","currency","currencySign","currencyDisplay","set","formatPriceRaw","dinero","options","toFormat","amount","code","formatted","format","removeFractions","removeTrailingZeros","replace","RegExp","exponent","formatPrice","money","localizedCurrency","assert","getDinero","prettifyTotal","total","totalJson","toJSON","EUR","GBP","CAD","totalAsFloat","toUnit","roundDinero","Round","PrettifyDecimalCents","PrettifyHalfUnitCents","Prettify","PrettifyFull059","hasSubUnits","minValueInclusiveToRoundDownFrom","prettifyPriceLookup"],"mappings":";;;;;;AAaa,MAAAA,oBAAA,GACXC,YACkC,IAAA;EAClC,OAAOA,YAAe,GAAAC,uBAAA,CAAwBC,GAAI,CAAAF,YAAY,CAAI,GAAA,KAAA,CAAA;AACpE,CAAA;AAKA,MAAMG,sBAAA,GAAA,mBAA6BC,GAA+B,EAAA;AAOlE,MAAMC,oBAAA,GAAuBA,CAC3BC,MAAA,EACAN,YACsB,KAAA;EACtB,MAAMO,QAAW,GAAA,GAAGD,MAAM,IAAIN,YAAY,EAAA;EAEtC,IAAAQ,SAAA,GAAYL,sBAAuB,CAAAD,GAAA,CAAIK,QAAQ,CAAA;EACnD,IAAIC,SAAW,EAAA;IACN,OAAAA,SAAA;EACT;EAEYA,SAAA,GAAA,IAAIC,IAAK,CAAAC,YAAA,CAAaJ,MAAQ,EAAA;IACxCK,KAAO,EAAA,UAAA;IACPC,QAAU,EAAAZ,YAAA;IAAA;AAAA;AAAA;AAAA;AAAA;IAMVa,YAAc,EAAA,UAAA;IACdC,eAAiB,EAAA;EAAA,CAClB,CAAA;EACsBX,sBAAA,CAAAY,GAAA,CAAIR,UAAUC,SAAS,CAAA;EAEvC,OAAAA,SAAA;AACT,CAAA;AAoCgB,SAAAQ,cAAAA,CACdC,MACA,EAAAX,MAAA,EACAY,OACQ,EAAA;EACR,OAAOC,SAASF,MAAQ,EAAA,CAAC;IAAEG,MAAA;IAAQR;GAAe,KAAA;IAChD,MAAMJ,SAAY,GAAAH,oBAAA,CAAqBC,MAAQ,EAAAM,QAAA,CAASS,IAAI,CAAA;IACtD,MAAAC,SAAA,GAAYd,SAAU,CAAAe,MAAA,CAAOH,MAAM,CAAA;IAElC,OAAAF,OAAA,EAASM,mBAAmBN,OAAS,EAAAO,mBAAA;IAAA;AAAA;AA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AAJ,WAAA,CAAYR,KAAO,EAAAS,KAAA,CAAMI,eAAe,CAAA;QACjD;MACF;IACA;MAAS;QAEH,IAAA,CAACC,WAAY,CAAAd,KAAK,CAAG,EAAA;UAChB,OAAAA,KAAA;QACT;QAEA,MAAMe,mCAAmCC,mBAAoB,CAAAjD,GAAA,CAC3DkC,UAAUxB,QAAS,CAAAS,IAAA,CACrB;QAGA,IACE6B,gCAAoC,IAAA,IAAA,IACpCR,MAAO,CAAAP,KAAK,IAAIe,gCAChB,EAAA;UACO,OAAAf,KAAA;QACT;QAEO,OAAAQ,WAAA,CAAYR,KAAO,EAAAS,KAAA,CAAMG,QAAQ,CAAA;MAC1C;EACF;AACF,CAAA;"}
@@ -88,7 +88,7 @@ const money = dinero2 => {
88
88
  currency: parseCurrencyCode(currency2.code)
89
89
  };
90
90
  };
91
- const addMany = (addends, defaultCurrency) => addends.reduce(dinero_js.add, getDinero(0, defaultCurrency));
91
+ const addMany = (addends, defaultCurrency) => [...addends, getDinero(0, defaultCurrency)].reduce(dinero_js.add);
92
92
  const subtractMany = (subtractions, defaultCurrency) => [...subtractions, getDinero(0, defaultCurrency)].reduce(dinero_js.subtract);
93
93
  const stringAmountToDinero = (price, currency2) =>
94
94
  // FIXME: parseFloat seems dangerous O_O
@@ -1 +1 @@
1
- {"version":3,"file":"misc.js","sources":["../../../src/utils/money/misc.ts"],"sourcesContent":["import {\n add,\n dinero,\n hasSubUnits,\n multiply,\n subtract,\n toSnapshot,\n toUnit,\n transformScale,\n} from \"dinero.js\";\n\nimport { Currency } from \"../../types\";\nimport { assert } from \"../errors\";\nimport { isFloat, isInt } from \"../number\";\nimport { capitalize } from \"../string\";\nimport { smallestSubunitLookup } from \"./constants\";\nimport {\n currencyLookup,\n dineroCurrenciesLookup,\n floatToInt,\n} from \"./misc.private\";\nimport type { Cents, Dino, DinoCurrency, Money, RoundingFn } from \"./types\";\n\n/**\n * Some currencies have subunits in their currency spec that are not used in reality. This causes Dinero to return incorrect subunit values for those currencies.\n * This util rounds down any unused subunits to closest subunit resolution.\n *\n * ! Not to be confused with prettifyTotal\n */\nexport const toSmallestSubunit = (total: Dino): Dino => {\n // Nothing to round\n if (!hasSubUnits(total)) {\n return total;\n }\n\n const totalJson = total.toJSON();\n\n const [roundToDigits, roundingMode] =\n smallestSubunitLookup.get(totalJson.currency.code) ?? [];\n\n if (roundToDigits == null || roundingMode == null) {\n return total;\n }\n\n return roundDinero(total, roundingMode);\n};\n\n/**\n * Find Dinero.js currency instance from our Currency enum.\n * @throws Throws an error if currency is not found!\n *\n * @example\n * getDineroCurrency(Currency.Usd); // => Dinero.js currency instance\n * getDineroCurrency(\"invalid\"); // => throws AssertionError\n */\nexport const getDineroCurrency = (currency: Currency): DinoCurrency => {\n const dineroCurrency = dineroCurrenciesLookup.get(currency);\n assert(!!dineroCurrency, `Unsupported currency: \"${currency}\"`);\n return dineroCurrency;\n};\n\n/**\n * Convert Dinero currency (case-insensitive) to local currency type\n * @throws Throws an error if currency is not found!\n *\n * @example\n * parseCurrencyCode('usd') // Currency.Usd\n * parseCurrencyCode('JPY') // Currency.Jpy\n * parseCurrencyCode('invalid') // throws AssertionError\n */\nexport const parseCurrencyCode = (code: string): Currency => {\n const normalizedCode = capitalize(code.toLowerCase());\n assert(\n currencyLookup.has(normalizedCode),\n `Invalid currency code: ${normalizedCode}`,\n );\n return Currency[normalizedCode as keyof typeof Currency];\n};\n\n/**\n * Utility to quickly convert cents to a to currency float amount number\n *\n * @example\n * centsToCurrencyUnit(100, \"USD\") // 1\n * centsToCurrencyUnit(1, \"USD\") // 0.01\n * centsToCurrencyUnit(420, \"USD\") // 4.2\n * centsToCurrencyUnit(420, \"JPY\") // 420\n * FIXME: worth moving to a combined method of centsToCurrencyUnit & dineroToCurrencyUnit that accepts Money|Dino as input\n */\nexport const centsToCurrencyUnit = (\n centsAmount: Cents,\n currency: Currency,\n): number => {\n const dineroCurrency = getDineroCurrency(currency);\n const dineroObj = dinero({ amount: centsAmount, currency: dineroCurrency });\n return dineroToCurrencyUnit(dineroObj);\n};\n\n/**\n * Utility to quickly convert dinero instance to a to currency amount number\n *\n * @example\n * dineroToCurrencyUnit(getDinero(100, Currency.Usd)) // 1\n * dineroToCurrencyUnit(getDinero(1, Currency.Usd)) // 0.01\n * dineroToCurrencyUnit(getDinero(420, Currency.Usd)) // 4.2\n */\nexport const dineroToCurrencyUnit = (dineroObj: Dino): number => {\n return toUnit(dineroObj);\n};\n\n/**\n * Parse arbitrary float amount in a given currency to a dinero object.\n * Wrapper around `parseFloatToDineroRaw` for easier usage.\n *\n * Doesn't work on string float amounts!\n * @example\n * parseFloatToDinero(420, Currency.Usd); // => Dinero.js instance\n */\nexport const parseFloatToDinero = (floatAmount: number, currency: Currency) => {\n const dineroCurrency = getDineroCurrency(currency);\n return parseFloatToDineroRaw(floatAmount, dineroCurrency);\n};\n\n/**\n * Parse arbitrary float amount in a given dinero like currency object to a dinero object.\n * ! Typically use `parseFloatToDinero` instead of this method ! But this one is useful for custom currencies (e.g. custom exchange rates)\n */\nexport const parseFloatToDineroRaw = (\n floatAmount: number,\n dineroCurrency: DinoCurrency,\n) => {\n isFloat(floatAmount, \"Amount\");\n\n /**\n * Try to determine given input scale after comma, if not found, use currency default as that would indicate that\n * given input was an integer instead of a float\n *\n * FIXME: Won't work correctly if some currencies use dot/comma separation for decimal digits:\n * At least MacOS shows 4 different kind of formats to numbers.\n * 1. \"1234567,89\"\n * 2. \"1,234,567,89\"\n * 3. \"1.234.567,89\"\n * 4. \"1 234 567,89\"\n * Have to research if there are any more standards we should try to parse support\n */\n const scaleOfGivenAmount =\n String(floatAmount).split(\".\")[1]?.length ?? dineroCurrency.exponent;\n\n if (\n scaleOfGivenAmount == null ||\n scaleOfGivenAmount > dineroCurrency.exponent\n ) {\n throw new Error(`scaleOfGivenAmount is unsupported ${scaleOfGivenAmount}`);\n }\n const rateInt = floatToInt(\n floatAmount,\n dineroCurrency.base,\n dineroCurrency.exponent,\n );\n return dinero({\n amount: rateInt,\n currency: dineroCurrency,\n });\n};\n\n/**\n * Shorthand for dinero constructor\n *\n * @example\n * getDinero(100, Currency.Usd); // => Dinero.js instance (representing $1)\n */\nexport const getDinero = (amount: Cents, currency: Currency): Dino => {\n // TODO: verify if this is even needed, as dinero might already handle this\n isInt(amount, \"Amount\");\n return dinero({ amount, currency: getDineroCurrency(currency) });\n};\n\n/**\n * Shorthand to get amount from dinero instance\n *\n * FIXME: There is potential issue because we are not trimming scale:\n * multiply(getDinero(100, Currency.Usd), { amount: 100 + percentIncrease, scale: 2 })\n * will result in amount:10600, scale:4 (2*2), because dinero is rounding to safest scale.\n * @see https://v2.dinerojs.com/docs/core-concepts/scale#trimming-scale\n *\n * We should call something like: transformScale(d, currency.exponent)\n * @see https://v2.dinerojs.com/docs/api/conversions/transform-scale\n *\n * @example\n * amount(getDinero(100, Currency.Usd)); // 100\n */\nexport const amount = (dinero: Dino): Cents => {\n return toSnapshot(dinero).amount;\n};\n\n/**\n * Method to multiply dinero amount by full percent.\n * It also transforms scale back to currency exponent.\n * Where in case 20.34*1.06=21,5604, it will round to 21.56\n *\n * Will convert 0.01 - 12% to 0, but thats edge case we can tolerate, because\n * of dinero version we do not control rounding\n */\nexport const multiplyByFullPercent = (\n dinero: Dino,\n percentIncrease: number,\n): Dino => {\n assert(\n percentIncrease >= -100 && percentIncrease <= 100,\n \"Range should be in [-100, 100]\",\n );\n // (106 / 10^2 = 1.06)\n const multiplyResult = multiply(dinero, {\n amount: 100 + percentIncrease,\n scale: 2,\n });\n return transformScale(\n multiplyResult,\n multiplyResult.toJSON().currency.exponent,\n );\n};\n\n/**\n * Shorthand to get currency from dinero instance\n *\n * @example\n * currency(getDinero(100, Currency.Usd)); // Currency.Usd\n */\nexport const currency = (dinero: Dino): Currency => {\n return parseCurrencyCode(toSnapshot(dinero).currency.code);\n};\n\n/**\n * Shorthand to get our GraphQL Money type from dinero instance\n *\n * @example\n * money(getDinero(100, Currency.Usd)); // { amount: 100, currency: Currency.Usd }\n */\nexport const money = (dinero: Dino): Money => {\n const { amount, currency } = toSnapshot(dinero);\n\n return {\n amount,\n currency: parseCurrencyCode(currency.code),\n };\n};\n\n/**\n * Helper to quickly add multiple dinero instances with same currency\n *\n * @example\n * addMany([getDinero(100, Currency.Usd), getDinero(200, Currency.Usd)], Currency.Usd); // => Dinero.js instance (representing $3)\n */\nexport const addMany = (addends: Array<Dino>, defaultCurrency: Currency) =>\n addends.reduce(add, getDinero(0, defaultCurrency));\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 // eslint-disable-next-line sonarjs/reduce-initial-value\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 /**\n * Rounding to mitigate floating precision errors:\n *\n * 8.2 * 10 ** 2 = 819.9999999999999\n * 2.2 * 10 ** 2 = 220.00000000000003\n */\n amount: Math.round(\n roundedUnitPrice * snapshot.currency.base ** snapshot.currency.exponent,\n ),\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","Math"],"mappings":";;;;;;;;;;;AA6Ba,MAAAA,iBAAA,GAAqBC,KAAsB,IAAA;EAElD,IAAA,CAACC,SAAAA,CAAAA,WAAY,CAAAD,KAAK,CAAG,EAAA;IAChB,OAAAA,KAAA;EACT;EAEM,MAAAE,SAAA,GAAYF,MAAMG,MAAO,EAAA;EAEzB,MAAA,CAACC,aAAe,EAAAC,YAAY,CAChC,GAAAC,SAAA,CAAAA,qBAAA,CAAsBC,IAAIL,SAAU,CAAAM,QAAA,CAASC,IAAI,CAAA,IAAK,EAAC;EAErD,IAAAL,aAAA,IAAiB,IAAQ,IAAAC,YAAA,IAAgB,IAAM,EAAA;IAC1C,OAAAL,KAAA;EACT;EAEO,OAAAU,WAAA,CAAYV,OAAOK,YAAY,CAAA;AACxC,CAAA;AAUa,MAAAM,iBAAA,GAAqBH,SAAqC,IAAA;EAC/D,MAAAI,cAAA,GAAiBC,YAAAA,CAAAA,sBAAuB,CAAAN,GAAA,CAAIC,SAAQ,CAAA;EAC1DM,MAAA,CAAAA,MAAA,CAAO,CAAC,CAACF,cAAgB,EAAA,0BAA0BJ,SAAQ,GAAG,CAAA;EACvD,OAAAI,cAAA;AACT,CAAA;AAWa,MAAAG,iBAAA,GAAqBN,IAA2B,IAAA;EAC3D,MAAMO,cAAiB,GAAAC,MAAA,CAAAA,UAAA,CAAWR,IAAK,CAAAS,WAAA,CAAa,CAAA,CAAA;EACpDJ,MAAA,CAAAA,MAAA,CACEK,YAAA,CAAAA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AQa,MAAA2C,OAAA,GAAUA,CAACC,OAAA,EAAsBC,eAC5C,KAAAD,OAAA,CAAQE,OAAOC,SAAAA,CAAAA,GAAK,EAAAd,SAAA,CAAU,CAAG,EAAAY,eAAe,CAAC,CAAA;AAK5C,MAAMG,YAAe,GAAAA,CAC1BC,YACA,EAAAJ,eAAA,KAEG,CAAC,GAAGI,YAAc,EAAAhB,SAAA,CAAU,CAAG,EAAAY,eAAe,CAAC,CAAA,CAAEC,OAAOI,SAAAA,CAAAA,QAAQ,CAAA;AAKxD,MAAAC,oBAAA,GAAuBA,CAACC,KAAerD,EAAAA,SAAAA;AAAA;AAElDqB,kBAAmB,CAAAiC,UAAA,CAAWD,KAAK,CAAA,EAAGrD,SAAQ,CAAA;AAUnC,MAAAE,WAAA,GAAcA,CAACe,OAAAA,EAAcsC,UAAiC,KAAA;EACnE,MAAAC,gBAAA,GAAmBpC,iBAAOH,OAAQ,EAAA;IAAEwC,QAAQ,CAAG;IAAAC,KAAA,EAAOH;GAAY,CAAA;EAElE,MAAAI,QAAA,GAAWvB,qBAAWnB,OAAM,CAAA;EAElC,OAAOA,QAAO2C,MAAO,CAAA;IAAA;AAAA;AAAA;AAAA;AAAA;AAAA;IAOnB1C,QAAQ2C,IAAK,CAAAH,KAAA,CACXF,gBAAmB,GAAAG,QAAA,CAAS3D,QAAS,CAAAiC,IAAA,IAAQ0B,SAAS3D,QAAS,CAAA6B,QACjE,CAAA;IACA7B,UAAU2D,QAAS,CAAA3D;EAAA,CACpB,CAAA;AACH,CAAA;;;;;;;;;;;;;;;;"}
1
+ {"version":3,"file":"misc.js","sources":["../../../src/utils/money/misc.ts"],"sourcesContent":["import {\n add,\n dinero,\n hasSubUnits,\n multiply,\n subtract,\n toSnapshot,\n toUnit,\n transformScale,\n} from \"dinero.js\";\n\nimport { Currency } from \"../../types\";\nimport { assert } from \"../errors\";\nimport { isFloat, isInt } from \"../number\";\nimport { capitalize } from \"../string\";\nimport { smallestSubunitLookup } from \"./constants\";\nimport {\n currencyLookup,\n dineroCurrenciesLookup,\n floatToInt,\n} from \"./misc.private\";\nimport type { Cents, Dino, DinoCurrency, Money, RoundingFn } from \"./types\";\n\n/**\n * Some currencies have subunits in their currency spec that are not used in reality. This causes Dinero to return incorrect subunit values for those currencies.\n * This util rounds down any unused subunits to closest subunit resolution.\n *\n * ! Not to be confused with prettifyTotal\n */\nexport const toSmallestSubunit = (total: Dino): Dino => {\n // Nothing to round\n if (!hasSubUnits(total)) {\n return total;\n }\n\n const totalJson = total.toJSON();\n\n const [roundToDigits, roundingMode] =\n smallestSubunitLookup.get(totalJson.currency.code) ?? [];\n\n if (roundToDigits == null || roundingMode == null) {\n return total;\n }\n\n return roundDinero(total, roundingMode);\n};\n\n/**\n * Find Dinero.js currency instance from our Currency enum.\n * @throws Throws an error if currency is not found!\n *\n * @example\n * getDineroCurrency(Currency.Usd); // => Dinero.js currency instance\n * getDineroCurrency(\"invalid\"); // => throws AssertionError\n */\nexport const getDineroCurrency = (currency: Currency): DinoCurrency => {\n const dineroCurrency = dineroCurrenciesLookup.get(currency);\n assert(!!dineroCurrency, `Unsupported currency: \"${currency}\"`);\n return dineroCurrency;\n};\n\n/**\n * Convert Dinero currency (case-insensitive) to local currency type\n * @throws Throws an error if currency is not found!\n *\n * @example\n * parseCurrencyCode('usd') // Currency.Usd\n * parseCurrencyCode('JPY') // Currency.Jpy\n * parseCurrencyCode('invalid') // throws AssertionError\n */\nexport const parseCurrencyCode = (code: string): Currency => {\n const normalizedCode = capitalize(code.toLowerCase());\n assert(\n currencyLookup.has(normalizedCode),\n `Invalid currency code: ${normalizedCode}`,\n );\n return Currency[normalizedCode as keyof typeof Currency];\n};\n\n/**\n * Utility to quickly convert cents to a to currency float amount number\n *\n * @example\n * centsToCurrencyUnit(100, \"USD\") // 1\n * centsToCurrencyUnit(1, \"USD\") // 0.01\n * centsToCurrencyUnit(420, \"USD\") // 4.2\n * centsToCurrencyUnit(420, \"JPY\") // 420\n * FIXME: worth moving to a combined method of centsToCurrencyUnit & dineroToCurrencyUnit that accepts Money|Dino as input\n */\nexport const centsToCurrencyUnit = (\n centsAmount: Cents,\n currency: Currency,\n): number => {\n const dineroCurrency = getDineroCurrency(currency);\n const dineroObj = dinero({ amount: centsAmount, currency: dineroCurrency });\n return dineroToCurrencyUnit(dineroObj);\n};\n\n/**\n * Utility to quickly convert dinero instance to a to currency amount number\n *\n * @example\n * dineroToCurrencyUnit(getDinero(100, Currency.Usd)) // 1\n * dineroToCurrencyUnit(getDinero(1, Currency.Usd)) // 0.01\n * dineroToCurrencyUnit(getDinero(420, Currency.Usd)) // 4.2\n */\nexport const dineroToCurrencyUnit = (dineroObj: Dino): number => {\n return toUnit(dineroObj);\n};\n\n/**\n * Parse arbitrary float amount in a given currency to a dinero object.\n * Wrapper around `parseFloatToDineroRaw` for easier usage.\n *\n * Doesn't work on string float amounts!\n * @example\n * parseFloatToDinero(420, Currency.Usd); // => Dinero.js instance\n */\nexport const parseFloatToDinero = (floatAmount: number, currency: Currency) => {\n const dineroCurrency = getDineroCurrency(currency);\n return parseFloatToDineroRaw(floatAmount, dineroCurrency);\n};\n\n/**\n * Parse arbitrary float amount in a given dinero like currency object to a dinero object.\n * ! Typically use `parseFloatToDinero` instead of this method ! But this one is useful for custom currencies (e.g. custom exchange rates)\n */\nexport const parseFloatToDineroRaw = (\n floatAmount: number,\n dineroCurrency: DinoCurrency,\n) => {\n isFloat(floatAmount, \"Amount\");\n\n /**\n * Try to determine given input scale after comma, if not found, use currency default as that would indicate that\n * given input was an integer instead of a float\n *\n * FIXME: Won't work correctly if some currencies use dot/comma separation for decimal digits:\n * At least MacOS shows 4 different kind of formats to numbers.\n * 1. \"1234567,89\"\n * 2. \"1,234,567,89\"\n * 3. \"1.234.567,89\"\n * 4. \"1 234 567,89\"\n * Have to research if there are any more standards we should try to parse support\n */\n const scaleOfGivenAmount =\n String(floatAmount).split(\".\")[1]?.length ?? dineroCurrency.exponent;\n\n if (\n scaleOfGivenAmount == null ||\n scaleOfGivenAmount > dineroCurrency.exponent\n ) {\n throw new Error(`scaleOfGivenAmount is unsupported ${scaleOfGivenAmount}`);\n }\n const rateInt = floatToInt(\n floatAmount,\n dineroCurrency.base,\n dineroCurrency.exponent,\n );\n return dinero({\n amount: rateInt,\n currency: dineroCurrency,\n });\n};\n\n/**\n * Shorthand for dinero constructor\n *\n * @example\n * getDinero(100, Currency.Usd); // => Dinero.js instance (representing $1)\n */\nexport const getDinero = (amount: Cents, currency: Currency): Dino => {\n // TODO: verify if this is even needed, as dinero might already handle this\n isInt(amount, \"Amount\");\n return dinero({ amount, currency: getDineroCurrency(currency) });\n};\n\n/**\n * Shorthand to get amount from dinero instance\n *\n * FIXME: There is potential issue because we are not trimming scale:\n * multiply(getDinero(100, Currency.Usd), { amount: 100 + percentIncrease, scale: 2 })\n * will result in amount:10600, scale:4 (2*2), because dinero is rounding to safest scale.\n * @see https://v2.dinerojs.com/docs/core-concepts/scale#trimming-scale\n *\n * We should call something like: transformScale(d, currency.exponent)\n * @see https://v2.dinerojs.com/docs/api/conversions/transform-scale\n *\n * @example\n * amount(getDinero(100, Currency.Usd)); // 100\n */\nexport const amount = (dinero: Dino): Cents => {\n return toSnapshot(dinero).amount;\n};\n\n/**\n * Method to multiply dinero amount by full percent.\n * It also transforms scale back to currency exponent.\n * Where in case 20.34*1.06=21,5604, it will round to 21.56\n *\n * Will convert 0.01 - 12% to 0, but thats edge case we can tolerate, because\n * of dinero version we do not control rounding\n */\nexport const multiplyByFullPercent = (\n dinero: Dino,\n percentIncrease: number,\n): Dino => {\n assert(\n percentIncrease >= -100 && percentIncrease <= 100,\n \"Range should be in [-100, 100]\",\n );\n // (106 / 10^2 = 1.06)\n const multiplyResult = multiply(dinero, {\n amount: 100 + percentIncrease,\n scale: 2,\n });\n return transformScale(\n multiplyResult,\n multiplyResult.toJSON().currency.exponent,\n );\n};\n\n/**\n * Shorthand to get currency from dinero instance\n *\n * @example\n * currency(getDinero(100, Currency.Usd)); // Currency.Usd\n */\nexport const currency = (dinero: Dino): Currency => {\n return parseCurrencyCode(toSnapshot(dinero).currency.code);\n};\n\n/**\n * Shorthand to get our GraphQL Money type from dinero instance\n *\n * @example\n * money(getDinero(100, Currency.Usd)); // { amount: 100, currency: Currency.Usd }\n */\nexport const money = (dinero: Dino): Money => {\n const { amount, currency } = toSnapshot(dinero);\n\n return {\n amount,\n currency: parseCurrencyCode(currency.code),\n };\n};\n\n/**\n * Helper to quickly add multiple dinero instances with same currency\n *\n * @example\n * addMany([getDinero(100, Currency.Usd), getDinero(200, Currency.Usd)], Currency.Usd); // => Dinero.js instance (representing $3)\n */\nexport const addMany = (addends: Array<Dino>, defaultCurrency: Currency) =>\n [...addends, getDinero(0, defaultCurrency)].reduce(add);\n\n/**\n * Helper to quickly subtract multiple dinero instances with same currency\n */\nexport const subtractMany = (\n subtractions: Array<Dino>,\n defaultCurrency: Currency,\n) => [...subtractions, getDinero(0, defaultCurrency)].reduce(subtract);\n\n/**\n * Helper to quickly get dinero object from string\n */\nexport const stringAmountToDinero = (price: string, currency: Currency) =>\n // FIXME: parseFloat seems dangerous O_O\n parseFloatToDinero(parseFloat(price), currency);\n\n/**\n * Helper to quickly round dinero object to closest integer by a given rounding function\n * FIXME: add tests\n *\n * @example\n * roundDinero(getDinero(120, Currency.Usd), Math.floor); // => Dinero.js instance (representing $1)\n * roundDinero(getDinero(120, Currency.Usd), Math.ceil); // => Dinero.js instance (representing $2)\n */\nexport const roundDinero = (dinero: Dino, roundingFn: RoundingFn): Dino => {\n const roundedUnitPrice = toUnit(dinero, { digits: 0, round: roundingFn });\n\n const snapshot = toSnapshot(dinero);\n\n return dinero.create({\n /**\n * Rounding to mitigate floating precision errors:\n *\n * 8.2 * 10 ** 2 = 819.9999999999999\n * 2.2 * 10 ** 2 = 220.00000000000003\n */\n amount: Math.round(\n roundedUnitPrice * snapshot.currency.base ** snapshot.currency.exponent,\n ),\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","Math"],"mappings":";;;;;;;;;;;AA6Ba,MAAAA,iBAAA,GAAqBC,KAAsB,IAAA;EAElD,IAAA,CAACC,SAAAA,CAAAA,WAAY,CAAAD,KAAK,CAAG,EAAA;IAChB,OAAAA,KAAA;EACT;EAEM,MAAAE,SAAA,GAAYF,MAAMG,MAAO,EAAA;EAEzB,MAAA,CAACC,aAAe,EAAAC,YAAY,CAChC,GAAAC,SAAA,CAAAA,qBAAA,CAAsBC,IAAIL,SAAU,CAAAM,QAAA,CAASC,IAAI,CAAA,IAAK,EAAC;EAErD,IAAAL,aAAA,IAAiB,IAAQ,IAAAC,YAAA,IAAgB,IAAM,EAAA;IAC1C,OAAAL,KAAA;EACT;EAEO,OAAAU,WAAA,CAAYV,OAAOK,YAAY,CAAA;AACxC,CAAA;AAUa,MAAAM,iBAAA,GAAqBH,SAAqC,IAAA;EAC/D,MAAAI,cAAA,GAAiBC,YAAAA,CAAAA,sBAAuB,CAAAN,GAAA,CAAIC,SAAQ,CAAA;EAC1DM,MAAA,CAAAA,MAAA,CAAO,CAAC,CAACF,cAAgB,EAAA,0BAA0BJ,SAAQ,GAAG,CAAA;EACvD,OAAAI,cAAA;AACT,CAAA;AAWa,MAAAG,iBAAA,GAAqBN,IAA2B,IAAA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addends.reduce(add, getDinero(0, defaultCurrency));
89
+ const addMany = (addends, defaultCurrency) => [...addends, getDinero(0, defaultCurrency)].reduce(add);
90
90
  const subtractMany = (subtractions, defaultCurrency) => [...subtractions, getDinero(0, defaultCurrency)].reduce(subtract);
91
91
  const stringAmountToDinero = (price, currency2) =>
92
92
  // FIXME: parseFloat seems dangerous O_O
@@ -1 +1 @@
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.reduce(add, getDinero(0, defaultCurrency));\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 // eslint-disable-next-line sonarjs/reduce-initial-value\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 /**\n * Rounding to mitigate floating precision errors:\n *\n * 8.2 * 10 ** 2 = 819.9999999999999\n * 2.2 * 10 ** 2 = 220.00000000000003\n */\n amount: Math.round(\n roundedUnitPrice * snapshot.currency.base ** snapshot.currency.exponent,\n ),\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","Math"],"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,CA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AAAiC,IAAA,IAAQ0B,SAAS3D,QAAS,CAAA6B,QACjE,CAAA;IACA7B,UAAU2D,QAAS,CAAA3D;EAAA,CACpB,CAAA;AACH,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 /**\n * Rounding to mitigate floating precision errors:\n *\n * 8.2 * 10 ** 2 = 819.9999999999999\n * 2.2 * 10 ** 2 = 220.00000000000003\n */\n amount: Math.round(\n roundedUnitPrice * snapshot.currency.base ** snapshot.currency.exponent,\n ),\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","Math"],"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,KA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1 @@
1
- {"version":3,"file":"transform-css-module.js","sources":["../../../../src/utils/nextjs/ssr/transform-css-module.ts"],"sourcesContent":["import type { PluginObj } from \"@babel/core\";\nimport * as t from \"@babel/types\";\nimport crypto from \"node:crypto\";\n\nfunction generateMd5(input: string): string {\n // eslint-disable-next-line sonarjs/hashing\n return crypto.createHash(\"md5\").update(input).digest(\"hex\");\n}\n\ntype Plugin = PluginObj<{\n // Store the name of the default import identifier for \"style-inject.es.js\"\n defaultImportName: null | string;\n}>;\n\n/**\n * FIXME: Currently this plugin won't:\n * - Handle existing source maps correctly and would strip from the output: \"//#\n * sourceMappingURL=BubbleContainer.module.css.js.map\"\n */\nexport const transformCssModule = (): Plugin => {\n return {\n visitor: {\n // Step 0: Setup state\n Program(_path, state) {\n state[\"defaultImportName\"] = null;\n },\n // Step 1: Find the default import from \"style-inject.es.js\"\n ImportDeclaration(path, state) {\n // Skip, if the default import name is already found (assuming there is only one per-file)\n if (state[\"defaultImportName\"]) {\n return;\n }\n\n // Look for imports for \"style-inject.es.js\" file\n const importSource = path.node.source.value;\n if (!importSource.endsWith(\"style-inject.es.js\")) {\n return;\n }\n\n // Check for default import specifier\n const defaultSpecifier = path.node.specifiers.find((specifier) =>\n t.isImportDefaultSpecifier(specifier),\n ) as t.ImportDefaultSpecifier | undefined;\n\n // Store the default import name\n if (defaultSpecifier) {\n // Fail if two instances of file is found\n state[\"defaultImportName\"] = defaultSpecifier.local.name;\n } else {\n throw new Error(\n \"Import for `style-inject.es.js` file not found in file\",\n );\n }\n },\n\n // Step 2: Find all calls to the imported identifier\n CallExpression(path, state) {\n // Ignore if the default import name is not found\n if (!state[\"defaultImportName\"]) {\n return;\n }\n\n // Check if the callee is the default import identifier\n const callee = path.node.callee;\n if (\n t.isIdentifier(callee) &&\n callee.name === state[\"defaultImportName\"]\n ) {\n const args = path.node.arguments;\n\n // If arguments are not between 1 and 2, fail\n if (!(args.length >= 1 && args.length <= 2)) {\n throw new Error(\"Unexpected number of arguments\");\n }\n\n /**\n * Validates that the function arguments are:\n * 1. needs to be a string literal or variable holding string\n * 2. (optional) string literal\n */\n if (\n !(\n (t.isStringLiteral(args[0]) || t.isIdentifier(args[0])) &&\n (!args[1] || t.isStringLiteral(args[1]))\n )\n ) {\n throw new Error(\"Unexpected argument types\");\n }\n\n // CSS string\n let cssString: string = \"\";\n\n // Try to remove duplicate string literal as first argument and instead re-use the a already generated variable\n if (t.isStringLiteral(args[0])) {\n cssString = args[0].value;\n\n let reusedVariable = null;\n path.scope.path.traverse({\n VariableDeclarator(variablePath) {\n const { id, init } = variablePath.node;\n\n // Match variables initialized with the same string value.\n if (t.isStringLiteral(init, { value: cssString })) {\n reusedVariable = id;\n variablePath.stop(); // Stop traversing once a match is found.\n }\n },\n });\n\n // Replace the string literal with the existing variable reference.\n if (reusedVariable) {\n path.node.arguments[0] = reusedVariable;\n }\n } else if (t.isIdentifier(args[0])) {\n // Extract value from variable\n const binding = path.scope.getBinding(args[0].name);\n if (\n binding &&\n t.isVariableDeclarator(binding.path.node) &&\n t.isStringLiteral(binding.path.node.init)\n ) {\n cssString = binding.path.node.init.value;\n }\n }\n\n if (!cssString) {\n throw new Error(\"Invalid first argument value\");\n }\n\n // Generate MD5 hash of the first argument's value\n // TODO: Looked into that styled-components use murmurhash. Also it's possible to use sha1 for longer key\n // (less % of collision)\n const hash = generateMd5(cssString);\n\n // Add the hash as the second argument\n const hashArg = t.stringLiteral(hash);\n if (args.length > 1) {\n // If a second argument exists, replace it\n args[1] = hashArg;\n } else {\n // Otherwise, add it as a new second argument\n args.push(hashArg);\n }\n }\n },\n },\n } satisfies Plugin;\n};\n"],"names":["generateMd5","input","crypto","createHash","update","digest","transformCssModule","visitor","Program","_path","state","ImportDeclaration","path","importSource","node","source","value","endsWith","defaultSpecifier","specifiers","find","specifier","t","isImportDefaultSpecifier","local","name","Error","CallExpression","callee","isIdentifier","args","arguments","length","isStringLiteral","cssString","reusedVariable","scope","traverse","VariableDeclarator","variablePath","id","init","stop","binding","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AC,CAAC,CAAG,EAAA;YAElC,MAAMa,UAAU/B,IAAK,CAAAwB,KAAA,CAAMQ,WAAWd,IAAK,CAAA,CAAC,EAAEL,IAAI,CAAA;YAClD,IACEkB,OACA,IAAArB,YAAA,CAAEuB,oBAAqB,CAAAF,OAAA,CAAQ/B,IAAK,CAAAE,IAAI,CACxC,IAAAQ,YAAA,CAAEW,eAAgB,CAAAU,OAAA,CAAQ/B,IAAK,CAAAE,IAAA,CAAK2B,IAAI,CACxC,EAAA;cACYP,SAAA,GAAAS,OAAA,CAAQ/B,IAAK,CAAAE,IAAA,CAAK2B,IAAK,CAAAzB,KAAA;YACrC;UACF;UAEA,IAAI,CAACkB,SAAW,EAAA;YACR,MAAA,IAAIR,MAAM,8BAA8B,CAAA;UAChD;UAKM,MAAAoB,IAAA,GAAO9C,YAAYkC,SAAS,CAAA;UAG5B,MAAAa,OAAA,GAAUzB,YAAE,CAAA0B,aAAA,CAAcF,IAAI,CAAA;UAChC,IAAAhB,IAAA,CAAKE,SAAS,CAAG,EAAA;YAEnBF,IAAA,CAAK,CAAC,CAAI,GAAAiB,OAAA;UAAA,CACL,MAAA;YAELjB,IAAA,CAAKmB,KAAKF,OAAO,CAAA;UACnB;QACF;MACF;IACF;EAAA,CACF;AACF,CAAA;"}
1
+ {"version":3,"file":"transform-css-module.js","sources":["../../../../src/utils/nextjs/ssr/transform-css-module.ts"],"sourcesContent":["import type { PluginObj } from \"@babel/core\";\nimport * as t from \"@babel/types\";\nimport crypto from \"node:crypto\";\n\nfunction generateMd5(input: string): string {\n return crypto.createHash(\"md5\").update(input).digest(\"hex\");\n}\n\ntype Plugin = PluginObj<{\n // Store the name of the default import identifier for \"style-inject.es.js\"\n defaultImportName: null | string;\n}>;\n\n/**\n * FIXME: Currently this plugin won't:\n * - Handle existing source maps correctly and would strip from the output: \"//#\n * sourceMappingURL=BubbleContainer.module.css.js.map\"\n */\nexport const transformCssModule = (): Plugin => {\n return {\n visitor: {\n // Step 0: Setup state\n Program(_path, state) {\n state[\"defaultImportName\"] = null;\n },\n // Step 1: Find the default import from \"style-inject.es.js\"\n ImportDeclaration(path, state) {\n // Skip, if the default import name is already found (assuming there is only one per-file)\n if (state[\"defaultImportName\"]) {\n return;\n }\n\n // Look for imports for \"style-inject.es.js\" file\n const importSource = path.node.source.value;\n if (!importSource.endsWith(\"style-inject.es.js\")) {\n return;\n }\n\n // Check for default import specifier\n const defaultSpecifier = path.node.specifiers.find((specifier) =>\n t.isImportDefaultSpecifier(specifier),\n ) as t.ImportDefaultSpecifier | undefined;\n\n // Store the default import name\n if (defaultSpecifier) {\n // Fail if two instances of file is found\n state[\"defaultImportName\"] = defaultSpecifier.local.name;\n } else {\n throw new Error(\n \"Import for `style-inject.es.js` file not found in file\",\n );\n }\n },\n\n // Step 2: Find all calls to the imported identifier\n CallExpression(path, state) {\n // Ignore if the default import name is not found\n if (!state[\"defaultImportName\"]) {\n return;\n }\n\n // Check if the callee is the default import identifier\n const callee = path.node.callee;\n if (\n t.isIdentifier(callee) &&\n callee.name === state[\"defaultImportName\"]\n ) {\n const args = path.node.arguments;\n\n // If arguments are not between 1 and 2, fail\n if (!(args.length >= 1 && args.length <= 2)) {\n throw new Error(\"Unexpected number of arguments\");\n }\n\n /**\n * Validates that the function arguments are:\n * 1. needs to be a string literal or variable holding string\n * 2. (optional) string literal\n */\n if (\n !(\n (t.isStringLiteral(args[0]) || t.isIdentifier(args[0])) &&\n (!args[1] || t.isStringLiteral(args[1]))\n )\n ) {\n throw new Error(\"Unexpected argument types\");\n }\n\n // CSS string\n let cssString: string = \"\";\n\n // Try to remove duplicate string literal as first argument and instead re-use the a already generated variable\n if (t.isStringLiteral(args[0])) {\n cssString = args[0].value;\n\n let reusedVariable = null;\n path.scope.path.traverse({\n VariableDeclarator(variablePath) {\n const { id, init } = variablePath.node;\n\n // Match variables initialized with the same string value.\n if (t.isStringLiteral(init, { value: cssString })) {\n reusedVariable = id;\n variablePath.stop(); // Stop traversing once a match is found.\n }\n },\n });\n\n // Replace the string literal with the existing variable reference.\n if (reusedVariable) {\n path.node.arguments[0] = reusedVariable;\n }\n } else if (t.isIdentifier(args[0])) {\n // Extract value from variable\n const binding = path.scope.getBinding(args[0].name);\n if (\n binding &&\n t.isVariableDeclarator(binding.path.node) &&\n t.isStringLiteral(binding.path.node.init)\n ) {\n cssString = binding.path.node.init.value;\n }\n }\n\n if (!cssString) {\n throw new Error(\"Invalid first argument value\");\n }\n\n // Generate MD5 hash of the first argument's value\n // TODO: Looked into that styled-components use murmurhash. Also it's possible to use sha1 for longer key\n // (less % of collision)\n const hash = generateMd5(cssString);\n\n // Add the hash as the second argument\n const hashArg = t.stringLiteral(hash);\n if (args.length > 1) {\n // If a second argument exists, replace it\n args[1] = hashArg;\n } else {\n // Otherwise, add it as a new second argument\n args.push(hashArg);\n }\n }\n },\n },\n } satisfies Plugin;\n};\n"],"names":["generateMd5","input","crypto","createHash","update","digest","transformCssModule","visitor","Program","_path","state","ImportDeclaration","path","importSource","node","source","value","endsWith","defaultSpecifier","specifiers","find","specifier","t","isImportDefaultSpecifier","local","name","Error","CallExpression","callee","isIdentifier","args","arguments","length","isStringLiteral","cssString","reusedVariable","scope","traverse","VariableDeclarator","variablePath","id","init","stop","binding","getBinding","isVariableDeclarator","hash","hashArg","stringLiteral","push"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAIA,SAASA,YAAYC,KAAuB,EAAA;EACnC,OAAAC,eAAA,CAAA,SAAA,CAAA,CAAOC,WAAW,KAAK,CAAA,CAAEC,OAAOH,KAAK,CAAA,CAAEI,OAAO,KAAK,CAAA;AAC5D;AAYO,MAAMC,qBAAqBA,CAAA,KAAc;EACvC,OAAA;IACLC,OAAS,EAAA;MAAA;MAEPC,OAAAA,CAAQC,OAAOC,KAAO,EAAA;QACpBA,KAAA,CAAM,mBAAmB,CAAI,GAAA,IAAA;MAC/B,CAAA;MAAA;MAEAC,iBAAAA,CAAkBC,MAAMF,KAAO,EAAA;QAEzB,IAAA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AA;UAChD;UAKM,MAAAoB,IAAA,GAAO9C,YAAYkC,SAAS,CAAA;UAG5B,MAAAa,OAAA,GAAUzB,YAAE,CAAA0B,aAAA,CAAcF,IAAI,CAAA;UAChC,IAAAhB,IAAA,CAAKE,SAAS,CAAG,EAAA;YAEnBF,IAAA,CAAK,CAAC,CAAI,GAAAiB,OAAA;UAAA,CACL,MAAA;YAELjB,IAAA,CAAKmB,KAAKF,OAAO,CAAA;UACnB;QACF;MACF;IACF;EAAA,CACF;AACF,CAAA;"}
@@ -1 +1 @@
1
- {"version":3,"file":"transform-css-module.mjs","sources":["../../../../src/utils/nextjs/ssr/transform-css-module.ts"],"sourcesContent":["import type { PluginObj } from \"@babel/core\";\nimport * as t from \"@babel/types\";\nimport crypto from \"node:crypto\";\n\nfunction generateMd5(input: string): string {\n // eslint-disable-next-line sonarjs/hashing\n return crypto.createHash(\"md5\").update(input).digest(\"hex\");\n}\n\ntype Plugin = PluginObj<{\n // Store the name of the default import identifier for \"style-inject.es.js\"\n defaultImportName: null | string;\n}>;\n\n/**\n * FIXME: Currently this plugin won't:\n * - Handle existing source maps correctly and would strip from the output: \"//#\n * sourceMappingURL=BubbleContainer.module.css.js.map\"\n */\nexport const transformCssModule = (): Plugin => {\n return {\n visitor: {\n // Step 0: Setup state\n Program(_path, state) {\n state[\"defaultImportName\"] = null;\n },\n // Step 1: Find the default import from \"style-inject.es.js\"\n ImportDeclaration(path, state) {\n // Skip, if the default import name is already found (assuming there is only one per-file)\n if (state[\"defaultImportName\"]) {\n return;\n }\n\n // Look for imports for \"style-inject.es.js\" file\n const importSource = path.node.source.value;\n if (!importSource.endsWith(\"style-inject.es.js\")) {\n return;\n }\n\n // Check for default import specifier\n const defaultSpecifier = path.node.specifiers.find((specifier) =>\n t.isImportDefaultSpecifier(specifier),\n ) as t.ImportDefaultSpecifier | undefined;\n\n // Store the default import name\n if (defaultSpecifier) {\n // Fail if two instances of file is found\n state[\"defaultImportName\"] = defaultSpecifier.local.name;\n } else {\n throw new Error(\n \"Import for `style-inject.es.js` file not found in file\",\n );\n }\n },\n\n // Step 2: Find all calls to the imported identifier\n CallExpression(path, state) {\n // Ignore if the default import name is not found\n if (!state[\"defaultImportName\"]) {\n return;\n }\n\n // Check if the callee is the default import identifier\n const callee = path.node.callee;\n if (\n t.isIdentifier(callee) &&\n callee.name === state[\"defaultImportName\"]\n ) {\n const args = path.node.arguments;\n\n // If arguments are not between 1 and 2, fail\n if (!(args.length >= 1 && args.length <= 2)) {\n throw new Error(\"Unexpected number of arguments\");\n }\n\n /**\n * Validates that the function arguments are:\n * 1. needs to be a string literal or variable holding string\n * 2. (optional) string literal\n */\n if (\n !(\n (t.isStringLiteral(args[0]) || t.isIdentifier(args[0])) &&\n (!args[1] || t.isStringLiteral(args[1]))\n )\n ) {\n throw new Error(\"Unexpected argument types\");\n }\n\n // CSS string\n let cssString: string = \"\";\n\n // Try to remove duplicate string literal as first argument and instead re-use the a already generated variable\n if (t.isStringLiteral(args[0])) {\n cssString = args[0].value;\n\n let reusedVariable = null;\n path.scope.path.traverse({\n VariableDeclarator(variablePath) {\n const { id, init } = variablePath.node;\n\n // Match variables initialized with the same string value.\n if (t.isStringLiteral(init, { value: cssString })) {\n reusedVariable = id;\n variablePath.stop(); // Stop traversing once a match is found.\n }\n },\n });\n\n // Replace the string literal with the existing variable reference.\n if (reusedVariable) {\n path.node.arguments[0] = reusedVariable;\n }\n } else if (t.isIdentifier(args[0])) {\n // Extract value from variable\n const binding = path.scope.getBinding(args[0].name);\n if (\n binding &&\n t.isVariableDeclarator(binding.path.node) &&\n t.isStringLiteral(binding.path.node.init)\n ) {\n cssString = binding.path.node.init.value;\n }\n }\n\n if (!cssString) {\n throw new Error(\"Invalid first argument value\");\n }\n\n // Generate MD5 hash of the first argument's value\n // TODO: Looked into that styled-components use murmurhash. Also it's possible to use sha1 for longer key\n // (less % of collision)\n const hash = generateMd5(cssString);\n\n // Add the hash as the second argument\n const hashArg = t.stringLiteral(hash);\n if (args.length > 1) {\n // If a second argument exists, replace it\n args[1] = hashArg;\n } else {\n // Otherwise, add it as a new second argument\n args.push(hashArg);\n }\n }\n },\n },\n } satisfies Plugin;\n};\n"],"names":["generateMd5","input","crypto","createHash","update","digest","transformCssModule","visitor","Program","_path","state","ImportDeclaration","path","importSource","node","source","value","endsWith","defaultSpecifier","specifiers","find","specifier","t","isImportDefaultSpecifier","local","name","Error","CallExpression","callee","isIdentifier","args","arguments","length","isStringLiteral","cssString","reusedVariable","scope","traverse","VariableDeclarator","variablePath","id","init","stop","binding","getBinding","isVariableDeclarator","hash","hashArg","stringLiteral","push"],"mappings":";;;AAIA,SAASA,YAAYC,KAAuB,EAAA;EAEnC,OAAAC,MAAA,CAAOC,WAAW,KAAK,CAAA,CAAEC,OAAOH,KAAK,CAAA,CAAEI,OAAO,KAAK,CAAA;AAC5D;AAYO,MAAMC,qBAAqBA,CAAA,KAAc;EACvC,OAAA;IACLC,OAAS,EAAA;MAAA;MAEPC,OAAAA,CAAQC,OAAOC,KAAO,EAAA;QACpBA,KAAA,CAAM,mBAAmB,CAAI,GAAA,IAAA;MAC/B,CAAA;MAAA;MAEAC,iBAAAA,CAAkBC,MAAMF,KAAO,EAAA;QAEzB,IAAAA,KAAA,CAAM,mBAAmB,CAAG,EAAA;UAC9B;QACF;QAGM,MAAAG,YAAA,GAAeD,IAAK,CAAAE,IAAA,CAAKC,MAAO,CAAAC,KAAA;QACtC,IAAI,CAACH,YAAA,CAAaI,QAAS,CAAA,oBAAoB,CAAG,EAAA;UAChD;QACF;QAGM,MAAAC,gBAAA,GAAmBN,IAAK,CAAAE,IAAA,CAAKK,UAAW,CAAAC,IAAA,CAAMC,SAAA,IAClDC,CAAE,CAAAC,wBAAA,CAAyBF,SAAS,CAAA,CACtC;QAGA,IAAIH,gBAAkB,EAAA;UAEdR,KAAA,CAAA,mBAAmB,CAAI,GAAAQ,gBAAA,CAAiBM,KAAM,CAAAC,IAAA;QAAA,CAC/C,MAAA;UACL,MAAM,IAAIC,K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AAAkB;gBAAA,CAAW,CAAG,EAAA;kBAChCC,cAAA,GAAAK,EAAA;kBACjBD,YAAA,CAAaG,IAAK,CAAA,CAAA;gBACpB;cACF;YAAA,CACD,CAAA;YAGD,IAAIP,cAAgB,EAAA;cACbvB,IAAA,CAAAE,IAAA,CAAKiB,SAAU,CAAA,CAAC,CAAI,GAAAI,cAAA;YAC3B;qBACSb,CAAE,CAAAO,YAAA,CAAaC,IAAK,CAAA,CAAC,CAAC,CAAG,EAAA;YAElC,MAAMa,UAAU/B,IAAK,CAAAwB,KAAA,CAAMQ,WAAWd,IAAK,CAAA,CAAC,EAAEL,IAAI,CAAA;YAClD,IACEkB,OACA,IAAArB,CAAA,CAAEuB,oBAAqB,CAAAF,OAAA,CAAQ/B,IAAK,CAAAE,IAAI,CACxC,IAAAQ,CAAA,CAAEW,eAAgB,CAAAU,OAAA,CAAQ/B,IAAK,CAAAE,IAAA,CAAK2B,IAAI,CACxC,EAAA;cACYP,SAAA,GAAAS,OAAA,CAAQ/B,IAAK,CAAAE,IAAA,CAAK2B,IAAK,CAAAzB,KAAA;YACrC;UACF;UAEA,IAAI,CAACkB,SAAW,EAAA;YACR,MAAA,IAAIR,MAAM,8BAA8B,CAAA;UAChD;UAKM,MAAAoB,IAAA,GAAO9C,YAAYkC,SAAS,CAAA;UAG5B,MAAAa,OAAA,GAAUzB,CAAE,CAAA0B,aAAA,CAAcF,IAAI,CAAA;UAChC,IAAAhB,IAAA,CAAKE,SAAS,CAAG,EAAA;YAEnBF,IAAA,CAAK,CAAC,CAAI,GAAAiB,OAAA;UAAA,CACL,MAAA;YAELjB,IAAA,CAAKmB,KAAKF,OAAO,CAAA;UACnB;QACF;MACF;IACF;EAAA,CACF;AACF,CAAA;"}
1
+ {"version":3,"file":"transform-css-module.mjs","sources":["../../../../src/utils/nextjs/ssr/transform-css-module.ts"],"sourcesContent":["import type { PluginObj } from \"@babel/core\";\nimport * as t from \"@babel/types\";\nimport crypto from \"node:crypto\";\n\nfunction generateMd5(input: string): string {\n return crypto.createHash(\"md5\").update(input).digest(\"hex\");\n}\n\ntype Plugin = PluginObj<{\n // Store the name of the default import identifier for \"style-inject.es.js\"\n defaultImportName: null | string;\n}>;\n\n/**\n * FIXME: Currently this plugin won't:\n * - Handle existing source maps correctly and would strip from the output: \"//#\n * sourceMappingURL=BubbleContainer.module.css.js.map\"\n */\nexport const transformCssModule = (): Plugin => {\n return {\n visitor: {\n // Step 0: Setup state\n Program(_path, state) {\n state[\"defaultImportName\"] = null;\n },\n // Step 1: Find the default import from \"style-inject.es.js\"\n ImportDeclaration(path, state) {\n // Skip, if the default import name is already found (assuming there is only one per-file)\n if (state[\"defaultImportName\"]) {\n return;\n }\n\n // Look for imports for \"style-inject.es.js\" file\n const importSource = path.node.source.value;\n if (!importSource.endsWith(\"style-inject.es.js\")) {\n return;\n }\n\n // Check for default import specifier\n const defaultSpecifier = path.node.specifiers.find((specifier) =>\n t.isImportDefaultSpecifier(specifier),\n ) as t.ImportDefaultSpecifier | undefined;\n\n // Store the default import name\n if (defaultSpecifier) {\n // Fail if two instances of file is found\n state[\"defaultImportName\"] = defaultSpecifier.local.name;\n } else {\n throw new Error(\n \"Import for `style-inject.es.js` file not found in file\",\n );\n }\n },\n\n // Step 2: Find all calls to the imported identifier\n CallExpression(path, state) {\n // Ignore if the default import name is not found\n if (!state[\"defaultImportName\"]) {\n return;\n }\n\n // Check if the callee is the default import identifier\n const callee = path.node.callee;\n if (\n t.isIdentifier(callee) &&\n callee.name === state[\"defaultImportName\"]\n ) {\n const args = path.node.arguments;\n\n // If arguments are not between 1 and 2, fail\n if (!(args.length >= 1 && args.length <= 2)) {\n throw new Error(\"Unexpected number of arguments\");\n }\n\n /**\n * Validates that the function arguments are:\n * 1. needs to be a string literal or variable holding string\n * 2. (optional) string literal\n */\n if (\n !(\n (t.isStringLiteral(args[0]) || t.isIdentifier(args[0])) &&\n (!args[1] || t.isStringLiteral(args[1]))\n )\n ) {\n throw new Error(\"Unexpected argument types\");\n }\n\n // CSS string\n let cssString: string = \"\";\n\n // Try to remove duplicate string literal as first argument and instead re-use the a already generated variable\n if (t.isStringLiteral(args[0])) {\n cssString = args[0].value;\n\n let reusedVariable = null;\n path.scope.path.traverse({\n VariableDeclarator(variablePath) {\n const { id, init } = variablePath.node;\n\n // Match variables initialized with the same string value.\n if (t.isStringLiteral(init, { value: cssString })) {\n reusedVariable = id;\n variablePath.stop(); // Stop traversing once a match is found.\n }\n },\n });\n\n // Replace the string literal with the existing variable reference.\n if (reusedVariable) {\n path.node.arguments[0] = reusedVariable;\n }\n } else if (t.isIdentifier(args[0])) {\n // Extract value from variable\n const binding = path.scope.getBinding(args[0].name);\n if (\n binding &&\n t.isVariableDeclarator(binding.path.node) &&\n t.isStringLiteral(binding.path.node.init)\n ) {\n cssString = binding.path.node.init.value;\n }\n }\n\n if (!cssString) {\n throw new Error(\"Invalid first argument value\");\n }\n\n // Generate MD5 hash of the first argument's value\n // TODO: Looked into that styled-components use murmurhash. Also it's possible to use sha1 for longer key\n // (less % of collision)\n const hash = generateMd5(cssString);\n\n // Add the hash as the second argument\n const hashArg = t.stringLiteral(hash);\n if (args.length > 1) {\n // If a second argument exists, replace it\n args[1] = hashArg;\n } else {\n // Otherwise, add it as a new second argument\n args.push(hashArg);\n }\n }\n },\n },\n } satisfies Plugin;\n};\n"],"names":["generateMd5","input","crypto","createHash","update","digest","transformCssModule","visitor","Program","_path","state","ImportDeclaration","path","importSource","node","source","value","endsWith","defaultSpecifier","specifiers","find","specifier","t","isImportDefaultSpecifier","local","name","Error","CallExpression","callee","isIdentifier","args","arguments","length","isStringLiteral","cssString","reusedVariable","scope","traverse","VariableDeclarator","variablePath","id","init","stop","binding","getBinding","isVariableDeclarator","hash","hashArg","stringLiteral","push"],"mappings":";;;AAIA,SAASA,YAAYC,KAAuB,EAAA;EACnC,OAAAC,MAAA,CAAOC,WAAW,KAAK,CAAA,CAAEC,OAAOH,KAAK,CAAA,CAAEI,OAAO,KAAK,CAAA;AAC5D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