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

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (429) hide show
  1. package/CHANGELOG.md +2 -154
  2. package/lib/_virtual/_virtual_multi-entry.js +12 -27
  3. package/lib/_virtual/_virtual_multi-entry.js.map +1 -1
  4. package/lib/_virtual/_virtual_multi-entry.mjs +10 -14
  5. package/lib/_virtual/_virtual_multi-entry.mjs.map +1 -1
  6. package/lib/apis/smartcat.js +1 -4
  7. package/lib/apis/smartcat.js.map +1 -1
  8. package/lib/apis/smartcat.mjs +1 -4
  9. package/lib/apis/smartcat.mjs.map +1 -1
  10. package/lib/{components/ResourceCalculatorV1/assets/consoles/ucg-max.png.js → assets/icons/menu/icon-globe.svg.js} +6 -6
  11. package/lib/assets/icons/menu/icon-globe.svg.js.map +1 -0
  12. package/lib/assets/icons/menu/icon-globe.svg.mjs +3 -0
  13. package/lib/assets/icons/menu/icon-globe.svg.mjs.map +1 -0
  14. package/lib/components/CategoryTabs/CategoryTabs.styles.d.ts +1 -1
  15. package/lib/components/CategoryTabs/CategoryTabs.types.d.ts +1 -1
  16. package/lib/components/CloserLookSection/CloserLookSection.js.map +1 -1
  17. package/lib/components/CloserLookSection/CloserLookSection.mjs.map +1 -1
  18. package/lib/components/Compare/Compare.styles.d.ts +5 -5
  19. package/lib/components/Container/Container.d.ts +1 -1
  20. package/lib/components/Container/Container.js +3 -4
  21. package/lib/components/Container/Container.js.map +1 -1
  22. package/lib/components/Container/Container.mjs +4 -5
  23. package/lib/components/Container/Container.mjs.map +1 -1
  24. package/lib/components/CustomImage/CustomImage.js.map +1 -1
  25. package/lib/components/CustomImage/CustomImage.mjs.map +1 -1
  26. package/lib/components/FeaturesSection_deprecated/FeaturesSection.js.map +1 -1
  27. package/lib/components/FeaturesSection_deprecated/FeaturesSection.mjs.map +1 -1
  28. package/lib/components/Footer/hooks/useFooterContent.d.ts +3 -1
  29. package/lib/components/Footer/hooks/useFooterContent.js +8 -1
  30. package/lib/components/Footer/hooks/useFooterContent.js.map +1 -1
  31. package/lib/components/Footer/hooks/useFooterContent.mjs +8 -1
  32. package/lib/components/Footer/hooks/useFooterContent.mjs.map +1 -1
  33. package/lib/components/Footer/translations/ar.json.js +1 -1
  34. package/lib/components/Footer/translations/ar.json.mjs +1 -1
  35. package/lib/components/Footer/translations/de.json.js +1 -1
  36. package/lib/components/Footer/translations/de.json.mjs +1 -1
  37. package/lib/components/Footer/translations/el.json.js +1 -1
  38. package/lib/components/Footer/translations/el.json.mjs +1 -1
  39. package/lib/components/Footer/translations/en.json.js +1 -0
  40. package/lib/components/Footer/translations/en.json.js.map +1 -1
  41. package/lib/components/Footer/translations/en.json.mjs +1 -0
  42. package/lib/components/Footer/translations/en.json.mjs.map +1 -1
  43. package/lib/components/Footer/translations/es.json.js +1 -1
  44. package/lib/components/Footer/translations/es.json.mjs +1 -1
  45. package/lib/components/Footer/translations/fr.json.js +4 -4
  46. package/lib/components/Footer/translations/fr.json.mjs +4 -4
  47. package/lib/components/Footer/translations/it.json.js +1 -1
  48. package/lib/components/Footer/translations/it.json.mjs +1 -1
  49. package/lib/components/Footer/translations/ja.json.js +2 -2
  50. package/lib/components/Footer/translations/ja.json.mjs +2 -2
  51. package/lib/components/Footer/translations/pt-BR.json.js +1 -1
  52. package/lib/components/Footer/translations/pt-BR.json.mjs +1 -1
  53. package/lib/components/Footer/translations/zh-Hans.json.js +4 -4
  54. package/lib/components/Footer/translations/zh-Hans.json.mjs +4 -4
  55. package/lib/components/Footer/translations/zh-Hant-TW.json.js +1 -1
  56. package/lib/components/Footer/translations/zh-Hant-TW.json.mjs +1 -1
  57. package/lib/components/GridGallery/GridGallery.js.map +1 -1
  58. package/lib/components/GridGallery/GridGallery.mjs.map +1 -1
  59. package/lib/components/Header/AccountMenu/AccountMenu.js +12 -20
  60. package/lib/components/Header/AccountMenu/AccountMenu.js.map +1 -1
  61. package/lib/components/Header/AccountMenu/AccountMenu.mjs +14 -22
  62. package/lib/components/Header/AccountMenu/AccountMenu.mjs.map +1 -1
  63. package/lib/components/Header/AccountMenu/megaphone.http.service.js +1 -4
  64. package/lib/components/Header/AccountMenu/megaphone.http.service.js.map +1 -1
  65. package/lib/components/Header/AccountMenu/megaphone.http.service.mjs +1 -4
  66. package/lib/components/Header/AccountMenu/megaphone.http.service.mjs.map +1 -1
  67. package/lib/components/Header/CartModalV2/CartModal.js.map +1 -1
  68. package/lib/components/Header/CartModalV2/CartModal.mjs.map +1 -1
  69. package/lib/components/Header/Header.js.map +1 -1
  70. package/lib/components/Header/Header.mjs.map +1 -1
  71. package/lib/components/Header/Header.styles.d.ts +2 -2
  72. package/lib/components/Header/Header.types.d.ts +4 -8
  73. package/lib/components/Header/Header.types.js +1 -2
  74. package/lib/components/Header/Header.types.js.map +1 -1
  75. package/lib/components/Header/Header.types.mjs +1 -2
  76. package/lib/components/Header/Header.types.mjs.map +1 -1
  77. package/lib/components/Header/LanguageFrame/LanguageFrame.js.map +1 -1
  78. package/lib/components/Header/LanguageFrame/LanguageFrame.mjs.map +1 -1
  79. package/lib/components/Header/LanguageFrame/Mobile/Mobile.js.map +1 -1
  80. package/lib/components/Header/LanguageFrame/Mobile/Mobile.mjs.map +1 -1
  81. package/lib/components/Header/MenuItem/MenuItem.styles.d.ts +1 -1
  82. package/lib/components/Header/MenuItem/MenuItem.styles.js +1 -1
  83. package/lib/components/Header/MenuItem/MenuItem.styles.js.map +1 -1
  84. package/lib/components/Header/MenuItem/MenuItem.styles.mjs +1 -1
  85. package/lib/components/Header/MenuItem/MenuItem.styles.mjs.map +1 -1
  86. package/lib/components/Header/Navigation/MicrositeMenu/MicrositeMenu.styles.d.ts +1 -1
  87. package/lib/components/Header/Navigation/MobileMenu/MobileMenu.styles.d.ts +1 -1
  88. package/lib/components/Header/Navigation/ProMobileMenu/ProMobileMenu.d.ts +1 -1
  89. package/lib/components/Header/Navigation/ProMobileMenu/ProMobileMenu.js +63 -85
  90. package/lib/components/Header/Navigation/ProMobileMenu/ProMobileMenu.js.map +1 -1
  91. package/lib/components/Header/Navigation/ProMobileMenu/ProMobileMenu.mjs +64 -86
  92. package/lib/components/Header/Navigation/ProMobileMenu/ProMobileMenu.mjs.map +1 -1
  93. package/lib/components/Header/Navigation/ProMobileMenu/ProMobileMenu.styles.d.ts +0 -6
  94. package/lib/components/Header/Navigation/ProMobileMenu/ProMobileMenu.styles.js +1 -11
  95. package/lib/components/Header/Navigation/ProMobileMenu/ProMobileMenu.styles.js.map +1 -1
  96. package/lib/components/Header/Navigation/ProMobileMenu/ProMobileMenu.styles.mjs +2 -10
  97. package/lib/components/Header/Navigation/ProMobileMenu/ProMobileMenu.styles.mjs.map +1 -1
  98. package/lib/components/Header/Navigation/ProMobileMenu/ProMobileMenu.types.d.ts +1 -5
  99. package/lib/components/Header/Overlay/Overlay.js.map +1 -1
  100. package/lib/components/Header/Overlay/Overlay.mjs.map +1 -1
  101. package/lib/components/Header/ProHeader/ProHeader.d.ts +4 -2
  102. package/lib/components/Header/ProHeader/ProHeader.js +36 -145
  103. package/lib/components/Header/ProHeader/ProHeader.js.map +1 -1
  104. package/lib/components/Header/ProHeader/ProHeader.mjs +39 -146
  105. package/lib/components/Header/ProHeader/ProHeader.mjs.map +1 -1
  106. package/lib/components/Header/ProHeader/ProHeader.styles.d.ts +1 -4
  107. package/lib/components/Header/ProHeader/ProHeader.styles.js +18 -20
  108. package/lib/components/Header/ProHeader/ProHeader.styles.js.map +1 -1
  109. package/lib/components/Header/ProHeader/ProHeader.styles.mjs +19 -18
  110. package/lib/components/Header/ProHeader/ProHeader.styles.mjs.map +1 -1
  111. package/lib/components/Header/translations/en.json.js +1 -4
  112. package/lib/components/Header/translations/en.json.js.map +1 -1
  113. package/lib/components/Header/translations/en.json.mjs +2 -4
  114. package/lib/components/Header/translations/en.json.mjs.map +1 -1
  115. package/lib/components/Hero/Hero.styles.d.ts +2 -2
  116. package/lib/components/HeroFadeGallery/HeroFadeGallery.styles.d.ts +1 -1
  117. package/lib/components/HowToUseSection/HowToUseSection.styles.d.ts +2 -2
  118. package/lib/components/ImageSequence/ImageSequence.js.map +1 -1
  119. package/lib/components/ImageSequence/ImageSequence.mjs.map +1 -1
  120. package/lib/components/LandingPage/Cards/Card/Card.js.map +1 -1
  121. package/lib/components/LandingPage/Cards/Card/Card.mjs.map +1 -1
  122. package/lib/components/LandingPage/Cards/Cards.js.map +1 -1
  123. package/lib/components/LandingPage/Cards/Cards.mjs.map +1 -1
  124. package/lib/components/LandingPagePro/LandingPagePro.d.ts +0 -3
  125. package/lib/components/LandingPagePro/LandingPagePro.js +3 -3
  126. package/lib/components/LandingPagePro/LandingPagePro.js.map +1 -1
  127. package/lib/components/LandingPagePro/LandingPagePro.mjs +2 -2
  128. package/lib/components/LandingPagePro/LandingPagePro.mjs.map +1 -1
  129. package/lib/components/LandingPagePro/LandingPagePro.styles.d.ts +1 -1
  130. package/lib/components/LayoutRenderer/LayoutRenderer.styles.d.ts +1 -1
  131. package/lib/components/LayoutRendererV1/LayoutRenderer.styles.d.ts +3 -3
  132. package/lib/components/LayoutRendererV2/LayoutRenderer.styles.d.ts +3 -3
  133. package/lib/components/MicrositeIntroductionBlock/MicrositeIntroductionBlock.js.map +1 -1
  134. package/lib/components/MicrositeIntroductionBlock/MicrositeIntroductionBlock.mjs.map +1 -1
  135. package/lib/components/MicrositeMediaGrid/MicrositeMediaGrid.js.map +1 -1
  136. package/lib/components/MicrositeMediaGrid/MicrositeMediaGrid.mjs.map +1 -1
  137. package/lib/components/MicrositeProductGrid/MicrositeProductGrid.js.map +1 -1
  138. package/lib/components/MicrositeProductGrid/MicrositeProductGrid.mjs.map +1 -1
  139. package/lib/components/MicrositeSectionWrap/MicrositeSectionWrap.styles.d.ts +1 -1
  140. package/lib/components/Microsites/MicrositeProductPage.js +39 -0
  141. package/lib/components/Microsites/MicrositeProductPage.js.map +1 -1
  142. package/lib/components/Microsites/MicrositeProductPage.mjs +39 -0
  143. package/lib/components/Microsites/MicrositeProductPage.mjs.map +1 -1
  144. package/lib/components/ModelCompareV3/StickyGrid/StickyGridHeader.js.map +1 -1
  145. package/lib/components/ModelCompareV3/StickyGrid/StickyGridHeader.mjs.map +1 -1
  146. package/lib/components/ProductCompare/ProductCompare.js.map +1 -1
  147. package/lib/components/ProductCompare/ProductCompare.mjs.map +1 -1
  148. package/lib/components/ProductSectionNavigation/ProductSectionNavigation.styles.d.ts +1 -1
  149. package/lib/components/ProductSectionNavigationV2/ProductSectionNavigation.styles.d.ts +1 -1
  150. package/lib/components/ProductTechSpecs/ProductTechSpecs.styles.d.ts +1 -1
  151. package/lib/components/QuantityControls/QuantityControls.js.map +1 -1
  152. package/lib/components/QuantityControls/QuantityControls.mjs.map +1 -1
  153. package/lib/components/RelatedProducts/RelatedProducts.js.map +1 -1
  154. package/lib/components/RelatedProducts/RelatedProducts.mjs.map +1 -1
  155. package/lib/components/ResourceCalculatorV1/ComputeResourceCalculator/ComputeResourceCalculator.constants.js +17 -313
  156. package/lib/components/ResourceCalculatorV1/ComputeResourceCalculator/ComputeResourceCalculator.constants.js.map +1 -1
  157. package/lib/components/ResourceCalculatorV1/ComputeResourceCalculator/ComputeResourceCalculator.constants.mjs +17 -311
  158. package/lib/components/ResourceCalculatorV1/ComputeResourceCalculator/ComputeResourceCalculator.constants.mjs.map +1 -1
  159. package/lib/components/ResourceCalculatorV1/ComputeResourceCalculator/ComputeResourceCalculator.types.d.ts +2 -3
  160. package/lib/components/ResourceCalculatorV1/ComputeResourceCalculator/ComputeResourceCalculator.types.js +0 -2
  161. package/lib/components/ResourceCalculatorV1/ComputeResourceCalculator/ComputeResourceCalculator.types.js.map +1 -1
  162. package/lib/components/ResourceCalculatorV1/ComputeResourceCalculator/ComputeResourceCalculator.types.mjs +0 -2
  163. package/lib/components/ResourceCalculatorV1/ComputeResourceCalculator/ComputeResourceCalculator.types.mjs.map +1 -1
  164. package/lib/components/ResourceCalculatorV1/ComputeResourceCalculator/components/DeviceSelect/DeviceSelect.js +34 -120
  165. package/lib/components/ResourceCalculatorV1/ComputeResourceCalculator/components/DeviceSelect/DeviceSelect.js.map +1 -1
  166. package/lib/components/ResourceCalculatorV1/ComputeResourceCalculator/components/DeviceSelect/DeviceSelect.mjs +34 -120
  167. package/lib/components/ResourceCalculatorV1/ComputeResourceCalculator/components/DeviceSelect/DeviceSelect.mjs.map +1 -1
  168. package/lib/components/ResourceCalculatorV1/ComputeResourceCalculator/components/DeviceSelect/DeviceSelect.styles.d.ts +2 -16
  169. package/lib/components/ResourceCalculatorV1/ComputeResourceCalculator/components/DeviceSelect/DeviceSelect.styles.js +12 -54
  170. package/lib/components/ResourceCalculatorV1/ComputeResourceCalculator/components/DeviceSelect/DeviceSelect.styles.js.map +1 -1
  171. package/lib/components/ResourceCalculatorV1/ComputeResourceCalculator/components/DeviceSelect/DeviceSelect.styles.mjs +11 -50
  172. package/lib/components/ResourceCalculatorV1/ComputeResourceCalculator/components/DeviceSelect/DeviceSelect.styles.mjs.map +1 -1
  173. package/lib/components/ResourceCalculatorV1/ComputeResourceCalculator/components/DeviceSelect/assets/ArrowLeftPrimary.svg.js +5 -5
  174. package/lib/components/ResourceCalculatorV1/ComputeResourceCalculator/components/DeviceSelect/assets/ArrowRightPrimary.svg.js +5 -5
  175. package/lib/components/ResourceCalculatorV1/ComputeResourceCalculator/components/InputCard/InputCard.js +1 -1
  176. package/lib/components/ResourceCalculatorV1/ComputeResourceCalculator/components/InputCard/InputCard.js.map +1 -1
  177. package/lib/components/ResourceCalculatorV1/ComputeResourceCalculator/components/InputCard/InputCard.mjs +1 -1
  178. package/lib/components/ResourceCalculatorV1/ComputeResourceCalculator/components/InputCard/InputCard.mjs.map +1 -1
  179. package/lib/components/ResourceCalculatorV1/ComputeResourceCalculator/components/InputCard/InputCard.styles.js +0 -2
  180. package/lib/components/ResourceCalculatorV1/ComputeResourceCalculator/components/InputCard/InputCard.styles.js.map +1 -1
  181. package/lib/components/ResourceCalculatorV1/ComputeResourceCalculator/components/InputCard/InputCard.styles.mjs +0 -2
  182. package/lib/components/ResourceCalculatorV1/ComputeResourceCalculator/components/InputCard/InputCard.styles.mjs.map +1 -1
  183. package/lib/components/ResourceCalculatorV1/ComputeResourceCalculator/useComputeResourceCalculator.js +1 -1
  184. package/lib/components/ResourceCalculatorV1/ComputeResourceCalculator/useComputeResourceCalculator.js.map +1 -1
  185. package/lib/components/ResourceCalculatorV1/ComputeResourceCalculator/useComputeResourceCalculator.mjs +1 -1
  186. package/lib/components/ResourceCalculatorV1/ComputeResourceCalculator/useComputeResourceCalculator.mjs.map +1 -1
  187. package/lib/components/ResourceCalculatorV1/PoeCalculator/components/PoeConsumerConfigurator/PoeConsumerSelectModal/PoeConsumerSelectModal.js +2 -2
  188. package/lib/components/ResourceCalculatorV1/PoeCalculator/components/PoeConsumerConfigurator/PoeConsumerSelectModal/PoeConsumerSelectModal.js.map +1 -1
  189. package/lib/components/ResourceCalculatorV1/PoeCalculator/components/PoeConsumerConfigurator/PoeConsumerSelectModal/PoeConsumerSelectModal.mjs +2 -2
  190. package/lib/components/ResourceCalculatorV1/PoeCalculator/components/PoeConsumerConfigurator/PoeConsumerSelectModal/PoeConsumerSelectModal.mjs.map +1 -1
  191. package/lib/components/ResourceCalculatorV1/ResourceCalculator.js +2 -1
  192. package/lib/components/ResourceCalculatorV1/ResourceCalculator.js.map +1 -1
  193. package/lib/components/ResourceCalculatorV1/ResourceCalculator.mjs +2 -1
  194. package/lib/components/ResourceCalculatorV1/ResourceCalculator.mjs.map +1 -1
  195. package/lib/components/{HorizontalOptionSelect → ResourceCalculatorV1/components/HorizontalOptionSelect}/HorizontalOptionSelect.d.ts +1 -1
  196. package/lib/components/{HorizontalOptionSelect → ResourceCalculatorV1/components/HorizontalOptionSelect}/HorizontalOptionSelect.js +1 -3
  197. package/lib/components/ResourceCalculatorV1/components/HorizontalOptionSelect/HorizontalOptionSelect.js.map +1 -0
  198. package/lib/components/{HorizontalOptionSelect → ResourceCalculatorV1/components/HorizontalOptionSelect}/HorizontalOptionSelect.mjs +1 -3
  199. package/lib/components/ResourceCalculatorV1/components/HorizontalOptionSelect/HorizontalOptionSelect.mjs.map +1 -0
  200. package/lib/components/{HorizontalOptionSelect → ResourceCalculatorV1/components/HorizontalOptionSelect}/HorizontalOptionSelect.styles.d.ts +0 -1
  201. package/lib/components/{HorizontalOptionSelect → ResourceCalculatorV1/components/HorizontalOptionSelect}/HorizontalOptionSelect.styles.js +7 -10
  202. package/lib/components/ResourceCalculatorV1/components/HorizontalOptionSelect/HorizontalOptionSelect.styles.js.map +1 -0
  203. package/lib/components/{HorizontalOptionSelect → ResourceCalculatorV1/components/HorizontalOptionSelect}/HorizontalOptionSelect.styles.mjs +7 -10
  204. package/lib/components/ResourceCalculatorV1/components/HorizontalOptionSelect/HorizontalOptionSelect.styles.mjs.map +1 -0
  205. package/lib/components/{HorizontalOptionSelect → ResourceCalculatorV1/components/HorizontalOptionSelect}/HorizontalOptionSelect.types.d.ts +0 -1
  206. package/lib/components/ResourceCalculatorV1/components/index.d.ts +1 -0
  207. package/lib/components/ResourceCalculatorV1/components/index.js +5 -0
  208. package/lib/components/{Header/Navigation/ProMenu → ResourceCalculatorV1/components}/index.js.map +1 -1
  209. package/lib/components/ResourceCalculatorV1/components/index.mjs +3 -0
  210. package/lib/components/ResourceCalculatorV1/translations/en.json.js +4 -6
  211. package/lib/components/ResourceCalculatorV1/translations/en.json.js.map +1 -1
  212. package/lib/components/ResourceCalculatorV1/translations/en.json.mjs +4 -6
  213. package/lib/components/ResourceCalculatorV1/translations/en.json.mjs.map +1 -1
  214. package/lib/components/ResourceCalculatorV1/translations/useResourceCalculatorTranslation.d.ts +2 -2
  215. package/lib/components/ReverseLoopingVideo/ReverseLoopingVideo.js.map +1 -1
  216. package/lib/components/ReverseLoopingVideo/ReverseLoopingVideo.mjs.map +1 -1
  217. package/lib/components/ScrollWrapper/ScrollWrapper.js.map +1 -1
  218. package/lib/components/ScrollWrapper/ScrollWrapper.mjs.map +1 -1
  219. package/lib/components/StorageSliders/Slider/Slider.js.map +1 -1
  220. package/lib/components/StorageSliders/Slider/Slider.mjs.map +1 -1
  221. package/lib/components/StorageSliders/StorageSliders.context.js.map +1 -1
  222. package/lib/components/StorageSliders/StorageSliders.context.mjs.map +1 -1
  223. package/lib/components/VariantSelector/Variant/Compatibility/Compatibility.js.map +1 -1
  224. package/lib/components/VariantSelector/Variant/Compatibility/Compatibility.mjs.map +1 -1
  225. package/lib/components/VariantSelector/Variant/Variant.js.map +1 -1
  226. package/lib/components/VariantSelector/Variant/Variant.mjs.map +1 -1
  227. package/lib/components/index.d.ts +0 -1
  228. package/lib/components/index.js +0 -2
  229. package/lib/components/index.js.map +1 -1
  230. package/lib/components/index.mjs +0 -2
  231. package/lib/components/index.mjs.map +1 -1
  232. package/lib/constants/proStoreCategories/mapping/index.d.ts +0 -1
  233. package/lib/constants/proStoreCategories/mapping/index.js +10 -15
  234. package/lib/constants/proStoreCategories/mapping/index.js.map +1 -1
  235. package/lib/constants/proStoreCategories/mapping/index.mjs +10 -15
  236. package/lib/constants/proStoreCategories/mapping/index.mjs.map +1 -1
  237. package/lib/constants/proStoreCategories/mapping/unifi.d.ts +1 -2
  238. package/lib/constants/proStoreCategories/mapping/unifi.js +0 -1
  239. package/lib/constants/proStoreCategories/mapping/unifi.js.map +1 -1
  240. package/lib/constants/proStoreCategories/mapping/unifi.mjs +0 -1
  241. package/lib/constants/proStoreCategories/mapping/unifi.mjs.map +1 -1
  242. package/lib/constants/proStoreCategories/translations/en.json.js +0 -3
  243. package/lib/constants/proStoreCategories/translations/en.json.js.map +1 -1
  244. package/lib/constants/proStoreCategories/translations/en.json.mjs +1 -3
  245. package/lib/constants/proStoreCategories/translations/en.json.mjs.map +1 -1
  246. package/lib/constants/proStoreCategories/translations/fr.json.js +1 -1
  247. package/lib/constants/proStoreCategories/translations/fr.json.mjs +1 -1
  248. package/lib/constants/proStoreCategories/translations/zh-Hans.json.js +1 -1
  249. package/lib/constants/proStoreCategories/translations/zh-Hans.json.mjs +1 -1
  250. package/lib/constants/proStoreCategories/translations/zh-Hant-TW.json.js +1 -1
  251. package/lib/constants/proStoreCategories/translations/zh-Hant-TW.json.mjs +1 -1
  252. package/lib/constants/url.d.ts +2 -1
  253. package/lib/constants/url.js +1 -0
  254. package/lib/constants/url.js.map +1 -1
  255. package/lib/constants/url.mjs +1 -0
  256. package/lib/constants/url.mjs.map +1 -1
  257. package/lib/contexts/MenuContext/context.js +1 -1
  258. package/lib/contexts/MenuContext/context.js.map +1 -1
  259. package/lib/contexts/MenuContext/context.mjs +1 -1
  260. package/lib/contexts/MenuContext/context.mjs.map +1 -1
  261. package/lib/contexts/MenuContext/utils.js +1 -0
  262. package/lib/contexts/MenuContext/utils.js.map +1 -1
  263. package/lib/contexts/MenuContext/utils.mjs +1 -0
  264. package/lib/contexts/MenuContext/utils.mjs.map +1 -1
  265. package/lib/helpers/index.d.ts +0 -1
  266. package/lib/helpers/index.js +0 -11
  267. package/lib/helpers/index.js.map +1 -1
  268. package/lib/helpers/index.mjs +0 -1
  269. package/lib/helpers/index.mjs.map +1 -1
  270. package/lib/helpers/ux.d.ts +1 -9
  271. package/lib/helpers/ux.js +0 -15
  272. package/lib/helpers/ux.js.map +1 -1
  273. package/lib/helpers/ux.mjs +1 -15
  274. package/lib/helpers/ux.mjs.map +1 -1
  275. package/lib/hooks/useHasTouch.js.map +1 -1
  276. package/lib/hooks/useHasTouch.mjs.map +1 -1
  277. package/lib/hooks/useHorizontalScroll.js.map +1 -1
  278. package/lib/hooks/useHorizontalScroll.mjs.map +1 -1
  279. package/lib/types/index.d.ts +0 -1
  280. package/lib/types/index.js +0 -2
  281. package/lib/types/index.js.map +1 -1
  282. package/lib/types/index.mjs +0 -1
  283. package/lib/types/index.mjs.map +1 -1
  284. package/lib/utils/array.d.ts +0 -4
  285. package/lib/utils/array.js +0 -10
  286. package/lib/utils/array.js.map +1 -1
  287. package/lib/utils/array.mjs +1 -10
  288. package/lib/utils/array.mjs.map +1 -1
  289. package/lib/utils/money/constants.d.ts +25 -56
  290. package/lib/utils/money/constants.js +7 -72
  291. package/lib/utils/money/constants.js.map +1 -1
  292. package/lib/utils/money/constants.mjs +7 -70
  293. package/lib/utils/money/constants.mjs.map +1 -1
  294. package/lib/utils/money/format.d.ts +5 -10
  295. package/lib/utils/money/format.js +14 -22
  296. package/lib/utils/money/format.js.map +1 -1
  297. package/lib/utils/money/format.mjs +16 -23
  298. package/lib/utils/money/format.mjs.map +1 -1
  299. package/lib/utils/money/index.d.ts +1 -4
  300. package/lib/utils/money/index.js +8 -26
  301. package/lib/utils/money/index.js.map +1 -1
  302. package/lib/utils/money/index.mjs +4 -8
  303. package/lib/utils/money/index.mjs.map +1 -1
  304. package/lib/utils/money/misc.d.ts +28 -68
  305. package/lib/utils/money/misc.js +64 -35
  306. package/lib/utils/money/misc.js.map +1 -1
  307. package/lib/utils/money/misc.mjs +43 -32
  308. package/lib/utils/money/misc.mjs.map +1 -1
  309. package/lib/utils/money/tax.d.ts +2 -38
  310. package/lib/utils/money/tax.js +10 -46
  311. package/lib/utils/money/tax.js.map +1 -1
  312. package/lib/utils/money/tax.mjs +11 -42
  313. package/lib/utils/money/tax.mjs.map +1 -1
  314. package/lib/utils/money/types.d.ts +3 -78
  315. package/lib/utils/number.d.ts +1 -1
  316. package/lib/utils/number.js +1 -1
  317. package/lib/utils/number.js.map +1 -1
  318. package/lib/utils/number.mjs +1 -1
  319. package/lib/utils/number.mjs.map +1 -1
  320. package/lib/utils/validations/postalCodeSuperRefinement.js +3 -0
  321. package/lib/utils/validations/postalCodeSuperRefinement.js.map +1 -1
  322. package/lib/utils/validations/postalCodeSuperRefinement.mjs +3 -0
  323. package/lib/utils/validations/postalCodeSuperRefinement.mjs.map +1 -1
  324. package/lib/utils/validations/stateRegistrationNumberSuperRefinement.js +2 -0
  325. package/lib/utils/validations/stateRegistrationNumberSuperRefinement.js.map +1 -1
  326. package/lib/utils/validations/stateRegistrationNumberSuperRefinement.mjs +2 -0
  327. package/lib/utils/validations/stateRegistrationNumberSuperRefinement.mjs.map +1 -1
  328. package/lib/utils/validations/taxIdSuperRefinement.js +2 -0
  329. package/lib/utils/validations/taxIdSuperRefinement.js.map +1 -1
  330. package/lib/utils/validations/taxIdSuperRefinement.mjs +2 -0
  331. package/lib/utils/validations/taxIdSuperRefinement.mjs.map +1 -1
  332. package/lib/utils/validations.d.ts +15 -0
  333. package/lib/utils/validations.js +23 -0
  334. package/lib/utils/validations.js.map +1 -0
  335. package/lib/utils/validations.mjs +21 -0
  336. package/lib/utils/validations.mjs.map +1 -0
  337. package/lib/utils/variant.js.map +1 -1
  338. package/lib/utils/variant.mjs.map +1 -1
  339. package/lib/utils/wattage.js.map +1 -1
  340. package/lib/utils/wattage.mjs.map +1 -1
  341. package/package.json +1 -1
  342. package/lib/assets/efg.png +0 -0
  343. package/lib/assets/icon-location-pin.svg +0 -5
  344. package/lib/assets/icons/menu/icon-location-pin.svg.js +0 -27
  345. package/lib/assets/icons/menu/icon-location-pin.svg.js.map +0 -1
  346. package/lib/assets/icons/menu/icon-location-pin.svg.mjs +0 -3
  347. package/lib/assets/icons/menu/icon-location-pin.svg.mjs.map +0 -1
  348. package/lib/assets/ucg-max.png +0 -0
  349. package/lib/components/Header/Navigation/ProMenu/ProMenu.d.ts +0 -2
  350. package/lib/components/Header/Navigation/ProMenu/ProMenu.js +0 -109
  351. package/lib/components/Header/Navigation/ProMenu/ProMenu.js.map +0 -1
  352. package/lib/components/Header/Navigation/ProMenu/ProMenu.mjs +0 -87
  353. package/lib/components/Header/Navigation/ProMenu/ProMenu.mjs.map +0 -1
  354. package/lib/components/Header/Navigation/ProMenu/ProMenu.styles.d.ts +0 -24
  355. package/lib/components/Header/Navigation/ProMenu/ProMenu.styles.js +0 -154
  356. package/lib/components/Header/Navigation/ProMenu/ProMenu.styles.js.map +0 -1
  357. package/lib/components/Header/Navigation/ProMenu/ProMenu.styles.mjs +0 -138
  358. package/lib/components/Header/Navigation/ProMenu/ProMenu.styles.mjs.map +0 -1
  359. package/lib/components/Header/Navigation/ProMenu/ProMenu.types.d.ts +0 -13
  360. package/lib/components/Header/Navigation/ProMenu/index.d.ts +0 -1
  361. package/lib/components/Header/Navigation/ProMenu/index.js +0 -6
  362. package/lib/components/Header/Navigation/ProMenu/index.mjs +0 -3
  363. package/lib/components/HorizontalOptionSelect/HorizontalOptionSelect.js.map +0 -1
  364. package/lib/components/HorizontalOptionSelect/HorizontalOptionSelect.mjs.map +0 -1
  365. package/lib/components/HorizontalOptionSelect/HorizontalOptionSelect.styles.js.map +0 -1
  366. package/lib/components/HorizontalOptionSelect/HorizontalOptionSelect.styles.mjs.map +0 -1
  367. package/lib/components/ResourceCalculatorV1/assets/consoles/efg.png.js +0 -27
  368. package/lib/components/ResourceCalculatorV1/assets/consoles/efg.png.js.map +0 -1
  369. package/lib/components/ResourceCalculatorV1/assets/consoles/efg.png.mjs +0 -3
  370. package/lib/components/ResourceCalculatorV1/assets/consoles/efg.png.mjs.map +0 -1
  371. package/lib/components/ResourceCalculatorV1/assets/consoles/ucg-max.png.js.map +0 -1
  372. package/lib/components/ResourceCalculatorV1/assets/consoles/ucg-max.png.mjs +0 -3
  373. package/lib/components/ResourceCalculatorV1/assets/consoles/ucg-max.png.mjs.map +0 -1
  374. package/lib/helpers/product.d.ts +0 -87
  375. package/lib/helpers/product.js +0 -346
  376. package/lib/helpers/product.js.map +0 -1
  377. package/lib/helpers/product.mjs +0 -335
  378. package/lib/helpers/product.mjs.map +0 -1
  379. package/lib/types/product.d.ts +0 -87
  380. package/lib/types/product.js +0 -14
  381. package/lib/types/product.js.map +0 -1
  382. package/lib/types/product.mjs +0 -13
  383. package/lib/types/product.mjs.map +0 -1
  384. package/lib/utils/money/allocators/fixedAmount.d.ts +0 -26
  385. package/lib/utils/money/allocators/fixedAmount.js +0 -55
  386. package/lib/utils/money/allocators/fixedAmount.js.map +0 -1
  387. package/lib/utils/money/allocators/fixedAmount.mjs +0 -53
  388. package/lib/utils/money/allocators/fixedAmount.mjs.map +0 -1
  389. package/lib/utils/money/allocators/index.d.ts +0 -2
  390. package/lib/utils/money/allocators/index.js +0 -8
  391. package/lib/utils/money/allocators/index.js.map +0 -1
  392. package/lib/utils/money/allocators/index.mjs +0 -4
  393. package/lib/utils/money/allocators/index.mjs.map +0 -1
  394. package/lib/utils/money/allocators/productAmount.d.ts +0 -13
  395. package/lib/utils/money/allocators/productAmount.js +0 -110
  396. package/lib/utils/money/allocators/productAmount.js.map +0 -1
  397. package/lib/utils/money/allocators/productAmount.mjs +0 -108
  398. package/lib/utils/money/allocators/productAmount.mjs.map +0 -1
  399. package/lib/utils/money/exchangeRate.d.ts +0 -31
  400. package/lib/utils/money/exchangeRate.js +0 -27
  401. package/lib/utils/money/exchangeRate.js.map +0 -1
  402. package/lib/utils/money/exchangeRate.mjs +0 -23
  403. package/lib/utils/money/exchangeRate.mjs.map +0 -1
  404. package/lib/utils/money/misc.private.d.ts +0 -23
  405. package/lib/utils/money/misc.private.js +0 -46
  406. package/lib/utils/money/misc.private.js.map +0 -1
  407. package/lib/utils/money/misc.private.mjs +0 -21
  408. package/lib/utils/money/misc.private.mjs.map +0 -1
  409. package/lib/utils/money/shipping.d.ts +0 -5
  410. package/lib/utils/money/shipping.js +0 -8
  411. package/lib/utils/money/shipping.js.map +0 -1
  412. package/lib/utils/money/shipping.mjs +0 -6
  413. package/lib/utils/money/shipping.mjs.map +0 -1
  414. package/lib/utils/money/tax.private.d.ts +0 -17
  415. package/lib/utils/money/tax.private.js +0 -65
  416. package/lib/utils/money/tax.private.js.map +0 -1
  417. package/lib/utils/money/tax.private.mjs +0 -60
  418. package/lib/utils/money/tax.private.mjs.map +0 -1
  419. package/lib/utils/productSort.d.ts +0 -41
  420. package/lib/utils/productSort.js +0 -66
  421. package/lib/utils/productSort.js.map +0 -1
  422. package/lib/utils/productSort.mjs +0 -59
  423. package/lib/utils/productSort.mjs.map +0 -1
  424. /package/lib/components/{HorizontalOptionSelect → ResourceCalculatorV1/components/HorizontalOptionSelect}/index.d.ts +0 -0
  425. /package/lib/components/{HorizontalOptionSelect → ResourceCalculatorV1/components/HorizontalOptionSelect}/index.js +0 -0
  426. /package/lib/components/{HorizontalOptionSelect → ResourceCalculatorV1/components/HorizontalOptionSelect}/index.js.map +0 -0
  427. /package/lib/components/{HorizontalOptionSelect → ResourceCalculatorV1/components/HorizontalOptionSelect}/index.mjs +0 -0
  428. /package/lib/components/{HorizontalOptionSelect → ResourceCalculatorV1/components/HorizontalOptionSelect}/index.mjs.map +0 -0
  429. /package/lib/components/{Header/Navigation/ProMenu → ResourceCalculatorV1/components}/index.mjs.map +0 -0
@@ -1,58 +1,22 @@
1
1
  'use strict';
2
2
 
3
3
  var dinero_js = require('dinero.js');
4
- var errors = require('../errors.js');
5
- var number = require('../number.js');
6
- var constants = require('./constants.js');
7
- var tax_private = require('./tax.private.js');
8
4
  "use strict";
9
- const calculateLineItemTax = ({
10
- itemSummary,
11
- taxRate,
12
- storeId
13
- }) => {
14
- return constants.storesWithPerItemTaxRate.has(storeId) ? tax_private.calculatePerQtyLineItemTax(itemSummary, taxRate) : tax_private.calculateWholeQtyLineItemTax(itemSummary, taxRate);
5
+ const allocateTaxAmount = (baseAmountObj, floatRate) => {
6
+ const rateScale = String(floatRate).split(".")[1]?.length;
7
+ if (rateScale === void 0) {
8
+ throw new Error(`rateScale is unsupported ${floatRate}`);
9
+ }
10
+ const rateInt = Math.round(floatRate * Math.pow(10, rateScale));
11
+ return dinero_js.allocate(baseAmountObj, [rateInt, Math.pow(10, rateScale) - rateInt])[0];
15
12
  };
16
- const removeTaxAmount = (baseAmountWithTaxObj, taxRate) => {
13
+ const removeTaxAmount = (baseAmountWithTaxObj, floatRate) => {
17
14
  const snapshot = dinero_js.toSnapshot(baseAmountWithTaxObj);
18
15
  return dinero_js.dinero({
19
16
  ...snapshot,
20
- amount: dinero_js.down(snapshot.amount / (1 + taxRate))
17
+ amount: dinero_js.down(snapshot.amount / (1 + floatRate))
21
18
  });
22
19
  };
23
- const convertDecimalTaxRateToPercentage = taxRate => {
24
- const dineroObj = decimalTaxRateToDinero(taxRate);
25
- const t = dinero_js.multiply(dineroObj, 100);
26
- return dinero_js.toUnit(t, {
27
- digits: constants.TAX_RATE_DINERO_CURRENCY.exponent,
28
- round: dinero_js.halfEven
29
- });
30
- };
31
- const decimalTaxRateToDinero = taxRate => {
32
- const parsedNumber = typeof taxRate === "number" ? taxRate : Number.parseFloat(taxRate);
33
- number.isFloat(parsedNumber);
34
- const parsedNumberInt = Number.parseInt((parsedNumber * Math.pow(constants.TAX_RATE_DINERO_CURRENCY.base, constants.TAX_RATE_DINERO_CURRENCY.exponent)).toFixed(0));
35
- return dinero_js.dinero({
36
- amount: parsedNumberInt,
37
- currency: constants.TAX_RATE_DINERO_CURRENCY
38
- });
39
- };
40
- const formatDecimalTaxRate = taxRate => {
41
- return `${convertDecimalTaxRateToPercentage(taxRate)}%`;
42
- };
43
- const stringTaxRateToFloat = rate => number.toFixedRate(+rate, constants.TAX_RATE_DINERO_CURRENCY.exponent, true);
44
- const calculateTotalTaxRate = rates => {
45
- const rateSum = rates.reduce((sum, rate) => sum + rate, 0);
46
- const result = number.toFixedRate(rateSum, constants.TAX_RATE_DINERO_CURRENCY.exponent, true);
47
- errors.assert(result >= 0, "Tax rate must be positive");
48
- errors.assert(result < 1, "Tax rate must be less than 1");
49
- return result;
50
- };
51
- exports.calculateLineItemTax = calculateLineItemTax;
52
- exports.calculateTotalTaxRate = calculateTotalTaxRate;
53
- exports.convertDecimalTaxRateToPercentage = convertDecimalTaxRateToPercentage;
54
- exports.decimalTaxRateToDinero = decimalTaxRateToDinero;
55
- exports.formatDecimalTaxRate = formatDecimalTaxRate;
20
+ exports.allocateTaxAmount = allocateTaxAmount;
56
21
  exports.removeTaxAmount = removeTaxAmount;
57
- exports.stringTaxRateToFloat = stringTaxRateToFloat;
58
22
  //# sourceMappingURL=tax.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"tax.js","sources":["../../../src/utils/money/tax.ts"],"sourcesContent":["import {\n type Dinero,\n dinero,\n // FIXME: move usage to rounding\n down,\n // FIXME: move usage to rounding\n halfEven,\n multiply,\n toSnapshot,\n toUnit,\n} from \"dinero.js\";\n\nimport type { StoreId } from \"../../types\";\nimport { assert } from \"../errors\";\nimport { isFloat, toFixedRate } from \"../number\";\nimport {\n storesWithPerItemTaxRate,\n TAX_RATE_DINERO_CURRENCY,\n} from \"./constants\";\nimport {\n calculatePerQtyLineItemTax,\n calculateWholeQtyLineItemTax,\n} from \"./tax.private\";\nimport type { Cents, Dino, LineItemSummary, TaxRate } from \"./types\";\n\n/**\n * Function to calculate the tax amount for a given line item depending on the store's tax rate calculation strategy\n */\nexport const calculateLineItemTax = ({\n itemSummary,\n taxRate,\n storeId,\n}: {\n itemSummary: LineItemSummary;\n taxRate: TaxRate;\n storeId: StoreId;\n}) => {\n return storesWithPerItemTaxRate.has(storeId)\n ? calculatePerQtyLineItemTax(itemSummary, taxRate)\n : calculateWholeQtyLineItemTax(itemSummary, taxRate);\n};\n\nexport const removeTaxAmount = (\n baseAmountWithTaxObj: Dinero<Cents>,\n taxRate: TaxRate,\n) => {\n const snapshot = toSnapshot(baseAmountWithTaxObj);\n return dinero({\n ...snapshot,\n amount: down(snapshot.amount / (1 + taxRate)),\n });\n};\n\n/**\n * Will return a percentage tax rate from a decimal tax rate (usually returned by DB)\n *\n * Use for math-related calculations ONLY! Use `formatDecimalTaxRate` for display purposes e.g. invoices.\n *\n * @example convertDecimalTaxRateToPercentage(\"0.01\") // 1\n * @example convertDecimalTaxRateToPercentage(\"0.1023\") // 10.23\n * @example convertDecimalTaxRateToPercentage(\"0.12345678\") // 12.345678\n */\nexport const convertDecimalTaxRateToPercentage = (\n taxRate: string | number,\n): number => {\n const dineroObj = decimalTaxRateToDinero(taxRate);\n const t = multiply(dineroObj, 100);\n return toUnit(t, {\n digits: TAX_RATE_DINERO_CURRENCY.exponent,\n round: halfEven,\n });\n};\n\nexport const decimalTaxRateToDinero = (taxRate: string | number): Dino => {\n const parsedNumber =\n typeof taxRate === \"number\" ? taxRate : Number.parseFloat(taxRate);\n isFloat(parsedNumber);\n\n const parsedNumberInt = Number.parseInt(\n (\n parsedNumber *\n Math.pow(TAX_RATE_DINERO_CURRENCY.base, TAX_RATE_DINERO_CURRENCY.exponent)\n ).toFixed(0),\n );\n return dinero({\n amount: parsedNumberInt,\n currency: TAX_RATE_DINERO_CURRENCY,\n });\n};\n\n/**\n * Will return a percentage string from a decimal tax rate (usually returned by DB).\n *\n * Use for display purposes e.g. invoices.\n *\n * @example formatDecimalTaxRate(\"0.01\") // \"1%\"\n * @example formatDecimalTaxRate(\"0.1023\") // \"10.23%\"\n * @example formatDecimalTaxRate(\"0.12345678\") // \"12.345678%\"\n */\nexport const formatDecimalTaxRate = <TaxRateFloat extends string | number>(\n taxRate: TaxRateFloat,\n): `${number}%` => {\n return `${convertDecimalTaxRateToPercentage(taxRate)}%`;\n};\n\nexport const stringTaxRateToFloat = (rate: string): number =>\n toFixedRate(+rate, TAX_RATE_DINERO_CURRENCY.exponent, true);\n\n/**\n * Calculate total Tax(LV: \"PVN\") for country, which consists of multiple tax entries\n * Returning fixed to ${TAX_RATE_DINERO_CURRENCY.exponent} 4 decimal places, to for example 0.2100 represent 21.00%\n */\nexport const calculateTotalTaxRate = (rates: number[]): number => {\n const rateSum = rates.reduce((sum, rate) => sum + rate, 0);\n const result = toFixedRate(rateSum, TAX_RATE_DINERO_CURRENCY.exponent, true);\n assert(result >= 0, \"Tax rate must be positive\");\n assert(result < 1, \"Tax rate must be less than 1\");\n return result;\n};\n"],"names":["calculateLineItemTax","itemSummary","taxRate","storeId","storesWithPerItemTaxRate","has","calculatePerQtyLineItemTax","calculateWholeQtyLineItemTax","removeTaxAmount","baseAmountWithTaxObj","snapshot","toSnapshot","dinero","amount","down","convertDecimalTaxRateToPercentage","dineroObj","decimalTaxRateToDinero","t","multiply","toUnit","digits","TAX_RATE_DINERO_CURRENCY","exponent","round","halfEven","parsedNumber","Number","parseFloat","isFloat","parsedNumberInt","parseInt","Math","pow","base","toFixed","currency","formatDecimalTaxRate","stringTaxRateToFloat","rate","toFixedRate","calculateTotalTaxRate","rates","rateSum","reduce","sum","result","assert"],"mappings":";;;;;;;;AA4BO,MAAMA,uBAAuBA,CAAC;EACnCC,WAAA;EACAC,OAAA;EACAC;AACF,CAIM,KAAA;EACG,OAAAC,kCAAA,CAAyBC,GAAI,CAAAF,OAAO,CACvC,GAAAG,WAAA,CAAAA,0BAAA,CAA2BL,aAAaC,OAAO,CAAA,GAC/CK,WAAAA,CAAAA,4BAA6B,CAAAN,WAAA,EAAaC,OAAO,CAAA;AACvD,CAAA;AAEa,MAAAM,eAAA,GAAkBA,CAC7BC,oBAAA,EACAP,OACG,KAAA;EACG,MAAAQ,QAAA,GAAWC,qBAAWF,oBAAoB,CAAA;EAChD,OAAOG,gBAAO,CAAA;IACZ,GAAGF,QAAA;IACHG,MAAQ,EAAAC,SAAA,CAAAA,IAAA,CAAKJ,QAAS,CAAAG,MAAA,IAAU,IAAIX,OAAQ,CAAA;EAAA,CAC7C,CAAA;AACH,CAAA;AAWa,MAAAa,iCAAA,GACXb,OACW,IAAA;EACL,MAAAc,SAAA,GAAYC,uBAAuBf,OAAO,CAAA;EAC1C,MAAAgB,CAAA,GAAIC,SAAAA,CAAAA,QAAS,CAAAH,SAAA,EAAW,GAAG,CAAA;EACjC,OAAOI,SAAAA,CAAAA,OAAOF,CAAG,EAAA;IACfG,QAAQC,SAAyB,CAAAA,wBAAA,CAAAC,QAAA;IACjCC,KAAO,EAAAC,SAAA,CAAAA;EAAA,CACR,CAAA;AACH,CAAA;AAEa,MAAAR,sBAAA,GAA0Bf,OAAmC,IAAA;EACxE,MAAMwB,eACJ,OAAOxB,OAAA,KAAY,WAAWA,OAAU,GAAAyB,MAAA,CAAOC,WAAW1B,OAAO,CAAA;EACnE2B,MAAA,CAAAA,OAAA,CAAQH,YAAY,CAAA;EAEpB,MAAMI,kBAAkBH,MAAO,CAAAI,QAAA,CAE3B,CAAAL,YAAA,GACAM,KAAKC,GAAI,CAAAX,SAAA,CAAAA,wBAAA,CAAyBY,MAAMZ,SAAAA,CAAAA,wBAAyB,CAAAC,QAAQ,CACzE,EAAAY,OAAA,CAAQ,CAAC,CAAA,CACb;EACA,OAAOvB,gBAAO,CAAA;IACZC,MAAQ,EAAAiB,eAAA;IACRM,QAAU,EAAAd,SAAA,CAAAA;EAAA,CACX,CAAA;AACH,CAAA;AAWa,MAAAe,oBAAA,GACXnC,OACiB,IAAA;EACV,OAAA,GAAGa,iCAAkC,CAAAb,OAAO,CAAC,GAAA;AACtD,CAAA;AAEa,MAAAoC,oBAAA,GAAwBC,IACnC,IAAAC,MAAA,CAAAA,WAAA,CAAY,CAACD,IAAM,EAAAjB,SAAA,CAAAA,wBAAA,CAAyBC,UAAU,IAAI,CAAA;AAM/C,MAAAkB,qBAAA,GAAyBC,KAA4B,IAAA;EAC1D,MAAAC,OAAA,GAAUD,MAAME,MAAO,CAAA,CAACC,KAAKN,IAAS,KAAAM,GAAA,GAAMN,MAAM,CAAC,CAAA;EACzD,MAAMO,MAAS,GAAAN,MAAAA,CAAAA,WAAA,CAAYG,OAAS,EAAArB,SAAAA,CAAAA,wBAAA,CAAyBC,UAAU,IAAI,CAAA;EACpEwB,MAAAA,CAAAA,MAAA,CAAAD,MAAA,IAAU,GAAG,2BAA2B,CAAA;EACxCC,MAAAA,CAAAA,MAAA,CAAAD,MAAA,GAAS,GAAG,8BAA8B,CAAA;EAC1C,OAAAA,MAAA;AACT,CAAA;;;;;;;"}
1
+ {"version":3,"file":"tax.js","sources":["../../../src/utils/money/tax.ts"],"sourcesContent":["import { allocate, type Dinero, dinero, down, toSnapshot } from \"dinero.js\";\n\nexport const allocateTaxAmount = (\n baseAmountObj: Dinero<number>,\n floatRate: number,\n) => {\n // FIXME: currently the API returns rate as a floating number, but the dinero lib expects be a integer number with some\n // scale so for now we attempt calculate the scale from the float rate\n // @see https://v2.dinerojs.com/docs/api/mutations/allocate\n const rateScale = String(floatRate).split(\".\")[1]?.length;\n if (rateScale === undefined) {\n throw new Error(`rateScale is unsupported ${floatRate}`);\n }\n const rateInt = Math.round(floatRate * Math.pow(10, rateScale));\n // eslint-disable-next-line @typescript-eslint/no-non-null-assertion\n return allocate(baseAmountObj, [\n rateInt,\n Math.pow(10, rateScale) - rateInt,\n ])[0]!;\n};\n\nexport const removeTaxAmount = (\n baseAmountWithTaxObj: Dinero<number>,\n floatRate: number,\n) => {\n const snapshot = toSnapshot(baseAmountWithTaxObj);\n return dinero({\n ...snapshot,\n amount: down(snapshot.amount / (1 + floatRate)),\n });\n};\n"],"names":["allocateTaxAmount","baseAmountObj","floatRate","rateScale","String","split","length","Error","rateInt","Math","round","pow","allocate","removeTaxAmount","baseAmountWithTaxObj","snapshot","toSnapshot","dinero","amount","down"],"mappings":";;;;AAEa,MAAAA,iBAAA,GAAoBA,CAC/BC,aAAA,EACAC,SACG,KAAA;EAIG,MAAAC,SAAA,GAAYC,OAAOF,SAAS,CAAA,CAAEG,MAAM,GAAG,CAAA,CAAE,CAAC,CAAG,EAAAC,MAAA;EACnD,IAAIH,cAAc,KAAW,CAAA,EAAA;IAC3B,MAAM,IAAII,KAAA,CAAkC,4BAAAL,SAAW,EAAA,CAAA;EACzD;EACM,MAAAM,OAAA,GAAUC,KAAKC,KAAM,CAAAR,SAAA,GAAYO,KAAKE,GAAI,CAAA,EAAA,EAAIR,SAAS,CAAC,CAAA;EAE9D,OAAOS,SAAAA,CAAAA,SAASX,aAAe,EAAA,CAC7BO,OAAA,EACAC,IAAK,CAAAE,GAAA,CAAI,EAAI,EAAAR,SAAS,CAAI,GAAAK,OAAA,CAC3B,EAAE,CAAC,CAAA;AACN,CAAA;AAEa,MAAAK,eAAA,GAAkBA,CAC7BC,oBAAA,EACAZ,SACG,KAAA;EACG,MAAAa,QAAA,GAAWC,qBAAWF,oBAAoB,CAAA;EAChD,OAAOG,gBAAO,CAAA;IACZ,GAAGF,QAAA;IACHG,MAAQ,EAAAC,SAAA,CAAAA,IAAA,CAAKJ,QAAS,CAAAG,MAAA,IAAU,IAAIhB,SAAU,CAAA;EAAA,CAC/C,CAAA;AACH,CAAA;;"}
@@ -1,50 +1,19 @@
1
- import { toSnapshot, dinero, down, multiply, toUnit, halfEven } from 'dinero.js';
2
- import { assert } from '../errors.mjs';
3
- import { isFloat, toFixedRate } from '../number.mjs';
4
- import { storesWithPerItemTaxRate, TAX_RATE_DINERO_CURRENCY } from './constants.mjs';
5
- import { calculatePerQtyLineItemTax, calculateWholeQtyLineItemTax } from './tax.private.mjs';
1
+ import { allocate, toSnapshot, dinero, down } from 'dinero.js';
6
2
  "use strict";
7
- const calculateLineItemTax = ({
8
- itemSummary,
9
- taxRate,
10
- storeId
11
- }) => {
12
- return storesWithPerItemTaxRate.has(storeId) ? calculatePerQtyLineItemTax(itemSummary, taxRate) : calculateWholeQtyLineItemTax(itemSummary, taxRate);
3
+ const allocateTaxAmount = (baseAmountObj, floatRate) => {
4
+ const rateScale = String(floatRate).split(".")[1]?.length;
5
+ if (rateScale === void 0) {
6
+ throw new Error(`rateScale is unsupported ${floatRate}`);
7
+ }
8
+ const rateInt = Math.round(floatRate * Math.pow(10, rateScale));
9
+ return allocate(baseAmountObj, [rateInt, Math.pow(10, rateScale) - rateInt])[0];
13
10
  };
14
- const removeTaxAmount = (baseAmountWithTaxObj, taxRate) => {
11
+ const removeTaxAmount = (baseAmountWithTaxObj, floatRate) => {
15
12
  const snapshot = toSnapshot(baseAmountWithTaxObj);
16
13
  return dinero({
17
14
  ...snapshot,
18
- amount: down(snapshot.amount / (1 + taxRate))
15
+ amount: down(snapshot.amount / (1 + floatRate))
19
16
  });
20
17
  };
21
- const convertDecimalTaxRateToPercentage = taxRate => {
22
- const dineroObj = decimalTaxRateToDinero(taxRate);
23
- const t = multiply(dineroObj, 100);
24
- return toUnit(t, {
25
- digits: TAX_RATE_DINERO_CURRENCY.exponent,
26
- round: halfEven
27
- });
28
- };
29
- const decimalTaxRateToDinero = taxRate => {
30
- const parsedNumber = typeof taxRate === "number" ? taxRate : Number.parseFloat(taxRate);
31
- isFloat(parsedNumber);
32
- const parsedNumberInt = Number.parseInt((parsedNumber * Math.pow(TAX_RATE_DINERO_CURRENCY.base, TAX_RATE_DINERO_CURRENCY.exponent)).toFixed(0));
33
- return dinero({
34
- amount: parsedNumberInt,
35
- currency: TAX_RATE_DINERO_CURRENCY
36
- });
37
- };
38
- const formatDecimalTaxRate = taxRate => {
39
- return `${convertDecimalTaxRateToPercentage(taxRate)}%`;
40
- };
41
- const stringTaxRateToFloat = rate => toFixedRate(+rate, TAX_RATE_DINERO_CURRENCY.exponent, true);
42
- const calculateTotalTaxRate = rates => {
43
- const rateSum = rates.reduce((sum, rate) => sum + rate, 0);
44
- const result = toFixedRate(rateSum, TAX_RATE_DINERO_CURRENCY.exponent, true);
45
- assert(result >= 0, "Tax rate must be positive");
46
- assert(result < 1, "Tax rate must be less than 1");
47
- return result;
48
- };
49
- export { calculateLineItemTax, calculateTotalTaxRate, convertDecimalTaxRateToPercentage, decimalTaxRateToDinero, formatDecimalTaxRate, removeTaxAmount, stringTaxRateToFloat };
18
+ export { allocateTaxAmount, removeTaxAmount };
50
19
  //# sourceMappingURL=tax.mjs.map
@@ -1 +1 @@
1
- {"version":3,"file":"tax.mjs","sources":["../../../src/utils/money/tax.ts"],"sourcesContent":["import {\n type Dinero,\n dinero,\n // FIXME: move usage to rounding\n down,\n // FIXME: move usage to rounding\n halfEven,\n multiply,\n toSnapshot,\n toUnit,\n} from \"dinero.js\";\n\nimport type { StoreId } from \"../../types\";\nimport { assert } from \"../errors\";\nimport { isFloat, toFixedRate } from \"../number\";\nimport {\n storesWithPerItemTaxRate,\n TAX_RATE_DINERO_CURRENCY,\n} from \"./constants\";\nimport {\n calculatePerQtyLineItemTax,\n calculateWholeQtyLineItemTax,\n} from \"./tax.private\";\nimport type { Cents, Dino, LineItemSummary, TaxRate } from \"./types\";\n\n/**\n * Function to calculate the tax amount for a given line item depending on the store's tax rate calculation strategy\n */\nexport const calculateLineItemTax = ({\n itemSummary,\n taxRate,\n storeId,\n}: {\n itemSummary: LineItemSummary;\n taxRate: TaxRate;\n storeId: StoreId;\n}) => {\n return storesWithPerItemTaxRate.has(storeId)\n ? calculatePerQtyLineItemTax(itemSummary, taxRate)\n : calculateWholeQtyLineItemTax(itemSummary, taxRate);\n};\n\nexport const removeTaxAmount = (\n baseAmountWithTaxObj: Dinero<Cents>,\n taxRate: TaxRate,\n) => {\n const snapshot = toSnapshot(baseAmountWithTaxObj);\n return dinero({\n ...snapshot,\n amount: down(snapshot.amount / (1 + taxRate)),\n });\n};\n\n/**\n * Will return a percentage tax rate from a decimal tax rate (usually returned by DB)\n *\n * Use for math-related calculations ONLY! Use `formatDecimalTaxRate` for display purposes e.g. invoices.\n *\n * @example convertDecimalTaxRateToPercentage(\"0.01\") // 1\n * @example convertDecimalTaxRateToPercentage(\"0.1023\") // 10.23\n * @example convertDecimalTaxRateToPercentage(\"0.12345678\") // 12.345678\n */\nexport const convertDecimalTaxRateToPercentage = (\n taxRate: string | number,\n): number => {\n const dineroObj = decimalTaxRateToDinero(taxRate);\n const t = multiply(dineroObj, 100);\n return toUnit(t, {\n digits: TAX_RATE_DINERO_CURRENCY.exponent,\n round: halfEven,\n });\n};\n\nexport const decimalTaxRateToDinero = (taxRate: string | number): Dino => {\n const parsedNumber =\n typeof taxRate === \"number\" ? taxRate : Number.parseFloat(taxRate);\n isFloat(parsedNumber);\n\n const parsedNumberInt = Number.parseInt(\n (\n parsedNumber *\n Math.pow(TAX_RATE_DINERO_CURRENCY.base, TAX_RATE_DINERO_CURRENCY.exponent)\n ).toFixed(0),\n );\n return dinero({\n amount: parsedNumberInt,\n currency: TAX_RATE_DINERO_CURRENCY,\n });\n};\n\n/**\n * Will return a percentage string from a decimal tax rate (usually returned by DB).\n *\n * Use for display purposes e.g. invoices.\n *\n * @example formatDecimalTaxRate(\"0.01\") // \"1%\"\n * @example formatDecimalTaxRate(\"0.1023\") // \"10.23%\"\n * @example formatDecimalTaxRate(\"0.12345678\") // \"12.345678%\"\n */\nexport const formatDecimalTaxRate = <TaxRateFloat extends string | number>(\n taxRate: TaxRateFloat,\n): `${number}%` => {\n return `${convertDecimalTaxRateToPercentage(taxRate)}%`;\n};\n\nexport const stringTaxRateToFloat = (rate: string): number =>\n toFixedRate(+rate, TAX_RATE_DINERO_CURRENCY.exponent, true);\n\n/**\n * Calculate total Tax(LV: \"PVN\") for country, which consists of multiple tax entries\n * Returning fixed to ${TAX_RATE_DINERO_CURRENCY.exponent} 4 decimal places, to for example 0.2100 represent 21.00%\n */\nexport const calculateTotalTaxRate = (rates: number[]): number => {\n const rateSum = rates.reduce((sum, rate) => sum + rate, 0);\n const result = toFixedRate(rateSum, TAX_RATE_DINERO_CURRENCY.exponent, true);\n assert(result >= 0, \"Tax rate must be positive\");\n assert(result < 1, \"Tax rate must be less than 1\");\n return result;\n};\n"],"names":["calculateLineItemTax","itemSummary","taxRate","storeId","storesWithPerItemTaxRate","has","calculatePerQtyLineItemTax","calculateWholeQtyLineItemTax","removeTaxAmount","baseAmountWithTaxObj","snapshot","toSnapshot","dinero","amount","down","convertDecimalTaxRateToPercentage","dineroObj","decimalTaxRateToDinero","t","multiply","toUnit","digits","TAX_RATE_DINERO_CURRENCY","exponent","round","halfEven","parsedNumber","Number","parseFloat","isFloat","parsedNumberInt","parseInt","Math","pow","base","toFixed","currency","formatDecimalTaxRate","stringTaxRateToFloat","rate","toFixedRate","calculateTotalTaxRate","rates","rateSum","reduce","sum","result","assert"],"mappings":";;;;;;AA4BO,MAAMA,uBAAuBA,CAAC;EACnCC,WAAA;EACAC,OAAA;EACAC;AACF,CAIM,KAAA;EACG,OAAAC,wBAAA,CAAyBC,GAAI,CAAAF,OAAO,CACvC,GAAAG,0BAAA,CAA2BL,aAAaC,OAAO,CAAA,GAC/CK,4BAA6B,CAAAN,WAAA,EAAaC,OAAO,CAAA;AACvD,CAAA;AAEa,M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;EAC1D,MAAAC,OAAA,GAAUD,MAAME,MAAO,CAAA,CAACC,KAAKN,IAAS,KAAAM,GAAA,GAAMN,MAAM,CAAC,CAAA;EACzD,MAAMO,MAAS,GAAAN,WAAA,CAAYG,OAAS,EAAArB,wBAAA,CAAyBC,UAAU,IAAI,CAAA;EACpEwB,MAAA,CAAAD,MAAA,IAAU,GAAG,2BAA2B,CAAA;EACxCC,MAAA,CAAAD,MAAA,GAAS,GAAG,8BAA8B,CAAA;EAC1C,OAAAA,MAAA;AACT,CAAA;"}
1
+ {"version":3,"file":"tax.mjs","sources":["../../../src/utils/money/tax.ts"],"sourcesContent":["import { allocate, type Dinero, dinero, down, toSnapshot } from \"dinero.js\";\n\nexport const allocateTaxAmount = (\n baseAmountObj: Dinero<number>,\n floatRate: number,\n) => {\n // FIXME: currently the API returns rate as a floating number, but the dinero lib expects be a integer number with some\n // scale so for now we attempt calculate the scale from the float rate\n // @see https://v2.dinerojs.com/docs/api/mutations/allocate\n const rateScale = String(floatRate).split(\".\")[1]?.length;\n if (rateScale === undefined) {\n throw new Error(`rateScale is unsupported ${floatRate}`);\n }\n const rateInt = Math.round(floatRate * Math.pow(10, rateScale));\n // eslint-disable-next-line @typescript-eslint/no-non-null-assertion\n return allocate(baseAmountObj, [\n rateInt,\n Math.pow(10, rateScale) - rateInt,\n ])[0]!;\n};\n\nexport const removeTaxAmount = (\n baseAmountWithTaxObj: Dinero<number>,\n floatRate: number,\n) => {\n const snapshot = toSnapshot(baseAmountWithTaxObj);\n return dinero({\n ...snapshot,\n amount: down(snapshot.amount / (1 + floatRate)),\n });\n};\n"],"names":["allocateTaxAmount","baseAmountObj","floatRate","rateScale","String","split","length","Error","rateInt","Math","round","pow","allocate","removeTaxAmount","baseAmountWithTaxObj","snapshot","toSnapshot","dinero","amount","down"],"mappings":";;AAEa,MAAAA,iBAAA,GAAoBA,CAC/BC,aAAA,EACAC,SACG,KAAA;EAIG,MAAAC,SAAA,GAAYC,OAAOF,SAAS,CAAA,CAAEG,MAAM,GAAG,CAAA,CAAE,CAAC,CAAG,EAAAC,MAAA;EACnD,IAAIH,cAAc,KAAW,CAAA,EAAA;IAC3B,MAAM,IAAII,KAAA,CAAkC,4BAAAL,SAAW,EAAA,CAAA;EACzD;EACM,MAAAM,OAAA,GAAUC,KAAKC,KAAM,CAAAR,SAAA,GAAYO,KAAKE,GAAI,CAAA,EAAA,EAAIR,SAAS,CAAC,CAAA;EAE9D,OAAOS,SAASX,aAAe,EAAA,CAC7BO,OAAA,EACAC,IAAK,CAAAE,GAAA,CAAI,EAAI,EAAAR,SAAS,CAAI,GAAAK,OAAA,CAC3B,EAAE,CAAC,CAAA;AACN,CAAA;AAEa,MAAAK,eAAA,GAAkBA,CAC7BC,oBAAA,EACAZ,SACG,KAAA;EACG,MAAAa,QAAA,GAAWC,WAAWF,oBAAoB,CAAA;EAChD,OAAOG,MAAO,CAAA;IACZ,GAAGF,QAAA;IACHG,MAAQ,EAAAC,IAAA,CAAKJ,QAAS,CAAAG,MAAA,IAAU,IAAIhB,SAAU,CAAA;EAAA,CAC/C,CAAA;AACH,CAAA;"}
@@ -1,85 +1,10 @@
1
- import type { Dinero, Currency as DineroCurrency } from "dinero.js";
2
- import type { Currency } from "../../types";
3
- /**
4
- * Floating point number of item tax rate
5
- * Number in range of 0>rate<1 (non-inclusive boundaries)
6
- * @example
7
- * 0.09 // 9%
8
- */
9
- export type TaxRate = number;
10
- /**
11
- * Shorthand for Dinero.js instance with number as the amount
12
- */
13
- export type Dino = Dinero<number>;
14
- /**
15
- * Shorthand for Dinero.js currency instance representing either a currency or custom currency such as tax-rate or shipping
16
- */
17
- export type DinoCurrency = DineroCurrency<number>;
18
- /**
19
- * Cents representation of specific currency
20
- * As a helper to easily understand the code, we use `Cents` as a type alias for `number` as historically we have had
21
- * mistakes by the team where we have used as dollar instead of `Cents` and vice versa.
22
- * @example
23
- * 100 // in USD this is $1.00
24
- * 100 // in YEN this is ¥100
25
- */
26
- export type Cents = number;
27
- /**
28
- * Type definition for a rounding function that can be used to round fractions
29
- */
30
- export type RoundingFn = (float: number) => Cents;
31
- /**
32
- * Convenient way to represent a money on the API level
33
- * When working with dinero you typically will convert this to a Dinero instance
34
- */
35
- export interface Money {
36
- amount: Cents;
37
- currency: Currency;
38
- }
1
+ import type { Currency as DineroCurrency } from "dinero.js";
39
2
  /**
40
3
  * Attempt to type out some locales `language-TERRITORY` which "we" as store care about
41
4
  * @see https://unicode-org.github.io/cldr-staging/charts/38/supplemental/territory_language_information.html
42
5
  */
43
6
  export type Locale = "ar-AE" | "ar-SA" | "bg-BG" | "bn-BD" | "bn-IN" | "cs-CZ" | "da-DK" | "de-AT" | "de-CH" | "de-DE" | "el-GR" | "en-AU" | "en-BR" | "en-CA" | "en-GB" | "en-IE" | "en-IN" | "en-JP" | "en-NZ" | "en-SG" | "en-US" | "en-ZA" | "es-AR" | "es-CL" | "es-CO" | "es-ES" | "es-MX" | "es-US" | "fi-FI" | "fr-BE" | "fr-CA" | "fr-CH" | "fr-FR" | "he-IL" | "hi-IN" | "hr-HR" | "hu-HU" | "id-ID" | "it-CH" | "it-IT" | "ja-JP" | "ko-KR" | "nl-BE" | "nl-NL" | "no-NO" | "pl-PL" | "pt-BR" | "pt-PT" | "ro-RO" | "ru-RU" | "sk-SK" | "sv-SE" | "ta-IN" | "ta-LK" | "th-TH" | "tr-TR" | "zh-CN" | "zh-HK" | "zh-TW" | string;
44
- export type LocalizedCurrency = {
45
- currency: DinoCurrency;
7
+ export type CurrencyObj = {
8
+ currency: DineroCurrency<number>;
46
9
  locale: Locale;
47
10
  };
48
- export interface LineItemSummary {
49
- itemPrice: Cents;
50
- /**
51
- * Item quantity that is always bigger than zero!
52
- */
53
- quantity: number;
54
- currency: Currency;
55
- /**
56
- * Total discount amount (only) applied for the given item quantity.
57
- * No taxes are included. Calculated by `total_raw_price * <discount-allocation-percentage>`
58
- */
59
- discountAmount: Cents;
60
- /**
61
- * subtotal - discountAmount
62
- */
63
- taxableAmount: Cents;
64
- }
65
- /**
66
- * Pretty much the same as PreTaxItemSummary but with quantity always set to 1 (for clearer type hinting and reasoning
67
- * around the topic)
68
- */
69
- export interface SingleLineItemSummary extends LineItemSummary {
70
- quantity: 1;
71
- }
72
- export interface FullLineItemSummary extends LineItemSummary {
73
- /**
74
- * Total price for the given item quantity. Calculated by `(itemPrice * quantity)`
75
- */
76
- subtotal: Cents;
77
- /**
78
- * Total tax amount for the given item quantity.
79
- */
80
- tax: Cents;
81
- /**
82
- * Total price for the given item quantity. Calculated by `subtotal - discountAmount + tax`
83
- */
84
- total: Cents;
85
- }
@@ -31,7 +31,7 @@ export declare function isFloat(value: unknown, entity?: string, ErrorClass?: ne
31
31
  * toFixed(1.2345, 0) // => "1"
32
32
  * toFixed(1.23, 4) // => "1.2300"
33
33
  */
34
- export declare function toFixedRate(rate: number, scale: number, asNumber?: boolean): string;
34
+ export declare function toFixedRate(rate: number, scale: number): string;
35
35
  export declare function toFixedRate(rate: number, scale: number, asNumber: true): number;
36
36
  /**
37
37
  * Util to convert a float number to a string. Using this rather than simple template string to have a consistent way of
@@ -21,7 +21,7 @@ function isInt(value, entity = "Value", ErrorClass = TypeError) {
21
21
  function isFloat(value, entity = "Value", ErrorClass = TypeError) {
22
22
  isFiniteNumber(value, entity, ErrorClass);
23
23
  }
24
- function toFixedRate(rate, scale, asNumber) {
24
+ function toFixedRate(rate, scale = 0, asNumber = false) {
25
25
  isFloat(rate, "Rate");
26
26
  const fixedRate = rate.toFixed(scale);
27
27
  return asNumber ? +fixedRate : fixedRate;
@@ -1 +1 @@
1
- {"version":3,"file":"number.js","sources":["../../src/utils/number.ts"],"sourcesContent":["/**\n * Util to easily parse that any given input is a finite number (not NaN, Infinity, -Infinity, etc.)\n * @throws If given input is not a finite number\n */\nexport function isFiniteNumber(\n value: unknown,\n entity = \"Value\",\n ErrorClass: new (message: string) => void = TypeError,\n): asserts value is number {\n if (typeof value !== \"number\" || Number.isNaN(value)) {\n // eslint-disable-next-line @typescript-eslint/no-throw-literal\n throw new ErrorClass(`${entity} is not a number: ${value}`);\n }\n\n if (!Number.isFinite(value)) {\n // eslint-disable-next-line @typescript-eslint/no-throw-literal\n throw new ErrorClass(`${entity} is not a finite number: ${value}`);\n }\n}\n\n/**\n * Custom isInt validation function that returns a more fine-grained error message otherwise for type safety alone a\n * Number.isSafeInteger would be sufficient.\n *\n * Code inspired from graphql-scalars library.\n * @see\n * https://github.com/Urigo/graphql-scalars/blob/c4fa3d27b965e39ceda6c33fc18041f112ecce49/src/scalars/utilities.ts#L20-L32\n * @throws If given input is not a valid integer\n */\nexport function isInt(\n value: unknown,\n entity = \"Value\",\n ErrorClass: new (message: string) => void = TypeError,\n): asserts value is number {\n isFiniteNumber(value, entity, ErrorClass);\n\n if (!Number.isInteger(value)) {\n // eslint-disable-next-line @typescript-eslint/no-throw-literal\n throw new ErrorClass(`${entity} is not an integer: ${value}`);\n }\n\n if (!Number.isSafeInteger(value)) {\n // eslint-disable-next-line @typescript-eslint/no-throw-literal\n throw new ErrorClass(`${entity} is not a safe integer: ${value}`);\n }\n}\n\n/**\n * Custom isFloat validation function that returns a more fine-grained error message otherwise for type safety alone a\n * Number.parseFloat would be sufficient.\n *\n * Code inspired from graphql-scalars library.\n * @see\n * https://github.com/Urigo/graphql-scalars/blob/c4fa3d27b965e39ceda6c33fc18041f112ecce49/src/scalars/utilities.ts#L34-L38\n * @throws If given input is not a valid float\n */\nexport function isFloat(\n value: unknown,\n entity = \"Value\",\n ErrorClass: new (message: string) => void = TypeError,\n): asserts value is number {\n isFiniteNumber(value, entity, ErrorClass);\n}\n\n/**\n * Returns a string representing a number in fixed-point notation.\n * Overload: Returns the rate parsed as a number\n * @example\n * toFixed(1.2345, 2) // => \"1.23\"\n * toFixed(1.2345, 0) // => \"1\"\n * toFixed(1.23, 4) // => \"1.2300\"\n */\nexport function toFixedRate(\n rate: number,\n scale: number,\n asNumber?: boolean,\n): string;\nexport function toFixedRate(\n rate: number,\n scale: number,\n asNumber: true,\n): number;\nexport function toFixedRate(rate: number, scale: number, asNumber?: boolean) {\n // Verify rate\n isFloat(rate, \"Rate\");\n\n const fixedRate = rate.toFixed(scale);\n\n return asNumber ? +fixedRate : fixedRate;\n}\n\n/**\n * Util to convert a float number to a string. Using this rather than simple template string to have a consistent way of\n * doing it. Removes any redundant trailing zeros.\n * @example\n * numberToString(1.23) // => \"1.23\"\n * numberToString(10.00) // => \"10\"\n * @throws If given input is not a valid number\n */\nexport const numberToString = (num: number): string => {\n isFloat(num);\n return num.toString(10);\n};\n\n/**\n * @see https://stackoverflow.com/a/35000557\n */\nexport const findClosestNumber = <T extends number>(\n haystack: T[],\n needle: number,\n): T => {\n return haystack.reduce((prev, curr) =>\n Math.abs(curr - needle) < Math.abs(prev - needle) ? curr : prev,\n );\n};\n\n/**\n * Splits number into array by max value provided.\n * E.g. splitNumberBy(100, 30) => [30, 30, 30, 10]\n */\nexport const splitNumberBy = (value: number, by: number) => {\n const chunks = new Array(Math.floor(value / by)).fill(by);\n const remainder = value % by;\n\n if (remainder > 0) {\n chunks.push(remainder);\n }\n\n return chunks;\n};\n\n/**\n * Clamp value to a given range\n */\nexport const clamp = (val: number, min: number, max: number) => {\n const trueMin = Math.min(min, max);\n const trueMax = Math.max(min, max);\n\n return Math.min(trueMax, Math.max(trueMin, val));\n};\n\n/**\n * Interpolate a number to a new range\n *\n * @example\n * linearInterpolate(5, [0, 10], [0, 100]); // 50\n */\nexport const linearInterpolate = (\n inputY: number,\n [fromMin, fromMax]: [number, number],\n [toMin, toMax]: [number, number],\n clampResult = true,\n) => {\n const percent = (inputY - fromMin) / (fromMax - fromMin);\n const outputX = percent * (toMax - toMin) + toMin;\n\n return clampResult ? clamp(outputX, toMin, toMax) : outputX;\n};\n\n/**\n * Increase value and start over once the range is overflown\n */\nexport const incrementLoopValue = (\n value: number,\n [min, max]: [number, number],\n) => {\n if (value === max) {\n return min;\n }\n return value + 1;\n};\n"],"names":["isFiniteNumber","value","entity","ErrorClass","TypeError","Number","isNaN","isFinite","isInt","isInteger","isSafeInteger","isFloat","toFixedRate","rate","scale","asNumber","fixedRate","toFixed","numberToString","num","toString","findClosestNumber","haystack","needle","reduce","prev","curr","Math","abs","splitNumberBy","by","chunks","Array","floor","fill","remainder","push","clamp","val","min","max","trueMin","trueMax","linearInterpolate","inputY","fromMin","fromMax","toMin","toMax","clampResult","percent","outputX","incrementLoopValue"],"mappings":";;;AAIO,SAASA,cACdA,CAAAC,KAAA,EACAC,MAAS,GAAA,OAAA,EACTC,aAA4CC,SACnB,EAAA;EACzB,IAAI,OAAOH,KAAU,KAAA,QAAA,IAAYI,MAAO,CAAAC,KAAA,CAAML,KAAK,CAAG,EAAA;IAEpD,MAAM,IAAIE,UAAW,CAAA,GAAGD,MAAM,qBAAqBD,KAAO,EAAA,CAAA;EAC5D;EAEA,IAAI,CAACI,MAAA,CAAOE,QAAS,CAAAN,KAAK,CAAG,EAAA;IAE3B,MAAM,IAAIE,UAAW,CAAA,GAAGD,MAAM,4BAA4BD,KAAO,EAAA,CAAA;EACnE;AACF;AAWO,SAASO,KACdA,CAAAP,KAAA,EACAC,MAAS,GAAA,OAAA,EACTC,aAA4CC,SACnB,EAAA;EACVJ,cAAA,CAAAC,KAAA,EAAOC,QAAQC,UAAU,CAAA;EAExC,IAAI,CAACE,MAAA,CAAOI,SAAU,CAAAR,KAAK,CAAG,EAAA;IAE5B,MAAM,IAAIE,UAAW,CAAA,GAAGD,MAAM,uBAAuBD,KAAO,EAAA,CAAA;EAC9D;EAEA,IAAI,CAACI,MAAA,CAAOK,aAAc,CAAAT,KAAK,CAAG,EAAA;IAEhC,MAAM,IAAIE,UAAW,CAAA,GAAGD,MAAM,2BAA2BD,KAAO,EAAA,CAAA;EAClE;AACF;AAWO,SAASU,OACdA,CAAAV,KAAA,EACAC,MAAS,GAAA,OAAA,EACTC,aAA4CC,SACnB,EAAA;EACVJ,cAAA,CAAAC,KAAA,EAAOC,QAAQC,UAAU,CAAA;AAC1C;AAoBgB,SAAAS,WAAAA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AAG,OAAA,EAASf,KAAKa,GAAI,CAAAC,OAAA,EAASH,GAAG,CAAC,CAAA;AACjD,CAAA;AAQO,MAAMK,iBAAoB,GAAAA,CAC/BC,MACA,EAAA,CAACC,OAAS,EAAAC,OAAO,CACjB,EAAA,CAACC,KAAO,EAAAC,KAAK,CACb,EAAAC,WAAA,GAAc,IACX,KAAA;EACG,MAAAC,OAAA,GAAA,CAAWN,MAAS,GAAAC,OAAA,KAAYC,OAAU,GAAAD,OAAA,CAAA;EAC1C,MAAAM,OAAA,GAAUD,OAAW,IAAAF,KAAA,GAAQD,KAAS,CAAA,GAAAA,KAAA;EAE5C,OAAOE,WAAc,GAAAZ,KAAA,CAAMc,OAAS,EAAAJ,KAAA,EAAOC,KAAK,CAAI,GAAAG,OAAA;AACtD,CAAA;AAKO,MAAMC,qBAAqBA,CAChCnD,KAAA,EACA,CAACsC,GAAA,EAAKC,GAAG,CACN,KAAA;EACH,IAAIvC,UAAUuC,GAAK,EAAA;IACV,OAAAD,GAAA;EACT;EACA,OAAOtC,KAAQ,GAAA,CAAA;AACjB,CAAA;;;;;;;;;;"}
1
+ {"version":3,"file":"number.js","sources":["../../src/utils/number.ts"],"sourcesContent":["/**\n * Util to easily parse that any given input is a finite number (not NaN, Infinity, -Infinity, etc.)\n * @throws If given input is not a finite number\n */\nexport function isFiniteNumber(\n value: unknown,\n entity = \"Value\",\n ErrorClass: new (message: string) => void = TypeError,\n): asserts value is number {\n if (typeof value !== \"number\" || Number.isNaN(value)) {\n // eslint-disable-next-line @typescript-eslint/no-throw-literal\n throw new ErrorClass(`${entity} is not a number: ${value}`);\n }\n\n if (!Number.isFinite(value)) {\n // eslint-disable-next-line @typescript-eslint/no-throw-literal\n throw new ErrorClass(`${entity} is not a finite number: ${value}`);\n }\n}\n\n/**\n * Custom isInt validation function that returns a more fine-grained error message otherwise for type safety alone a\n * Number.isSafeInteger would be sufficient.\n *\n * Code inspired from graphql-scalars library.\n * @see\n * https://github.com/Urigo/graphql-scalars/blob/c4fa3d27b965e39ceda6c33fc18041f112ecce49/src/scalars/utilities.ts#L20-L32\n * @throws If given input is not a valid integer\n */\nexport function isInt(\n value: unknown,\n entity = \"Value\",\n ErrorClass: new (message: string) => void = TypeError,\n): asserts value is number {\n isFiniteNumber(value, entity, ErrorClass);\n\n if (!Number.isInteger(value)) {\n // eslint-disable-next-line @typescript-eslint/no-throw-literal\n throw new ErrorClass(`${entity} is not an integer: ${value}`);\n }\n\n if (!Number.isSafeInteger(value)) {\n // eslint-disable-next-line @typescript-eslint/no-throw-literal\n throw new ErrorClass(`${entity} is not a safe integer: ${value}`);\n }\n}\n\n/**\n * Custom isFloat validation function that returns a more fine-grained error message otherwise for type safety alone a\n * Number.parseFloat would be sufficient.\n *\n * Code inspired from graphql-scalars library.\n * @see\n * https://github.com/Urigo/graphql-scalars/blob/c4fa3d27b965e39ceda6c33fc18041f112ecce49/src/scalars/utilities.ts#L34-L38\n * @throws If given input is not a valid float\n */\nexport function isFloat(\n value: unknown,\n entity = \"Value\",\n ErrorClass: new (message: string) => void = TypeError,\n): asserts value is number {\n isFiniteNumber(value, entity, ErrorClass);\n}\n\n/**\n * Returns a string representing a number in fixed-point notation.\n * Overload: Returns the rate parsed as a number\n * @example\n * toFixed(1.2345, 2) // => \"1.23\"\n * toFixed(1.2345, 0) // => \"1\"\n * toFixed(1.23, 4) // => \"1.2300\"\n */\nexport function toFixedRate(rate: number, scale: number): string;\nexport function toFixedRate(\n rate: number,\n scale: number,\n asNumber: true,\n): number;\nexport function toFixedRate(rate: number, scale = 0, asNumber = false) {\n // Verify rate\n isFloat(rate, \"Rate\");\n\n const fixedRate = rate.toFixed(scale);\n\n return asNumber ? +fixedRate : fixedRate;\n}\n\n/**\n * Util to convert a float number to a string. Using this rather than simple template string to have a consistent way of\n * doing it. Removes any redundant trailing zeros.\n * @example\n * numberToString(1.23) // => \"1.23\"\n * numberToString(10.00) // => \"10\"\n * @throws If given input is not a valid number\n */\nexport const numberToString = (num: number): string => {\n isFloat(num);\n return num.toString(10);\n};\n\n/**\n * @see https://stackoverflow.com/a/35000557\n */\nexport const findClosestNumber = <T extends number>(\n haystack: T[],\n needle: number,\n): T => {\n return haystack.reduce((prev, curr) =>\n Math.abs(curr - needle) < Math.abs(prev - needle) ? curr : prev,\n );\n};\n\n/**\n * Splits number into array by max value provided.\n * E.g. splitNumberBy(100, 30) => [30, 30, 30, 10]\n */\nexport const splitNumberBy = (value: number, by: number) => {\n const chunks = new Array(Math.floor(value / by)).fill(by);\n const remainder = value % by;\n\n if (remainder > 0) {\n chunks.push(remainder);\n }\n\n return chunks;\n};\n\n/**\n * Clamp value to a given range\n */\nexport const clamp = (val: number, min: number, max: number) => {\n const trueMin = Math.min(min, max);\n const trueMax = Math.max(min, max);\n\n return Math.min(trueMax, Math.max(trueMin, val));\n};\n\n/**\n * Interpolate a number to a new range\n *\n * @example\n * linearInterpolate(5, [0, 10], [0, 100]); // 50\n */\nexport const linearInterpolate = (\n inputY: number,\n [fromMin, fromMax]: [number, number],\n [toMin, toMax]: [number, number],\n clampResult = true,\n) => {\n const percent = (inputY - fromMin) / (fromMax - fromMin);\n const outputX = percent * (toMax - toMin) + toMin;\n\n return clampResult ? clamp(outputX, toMin, toMax) : outputX;\n};\n\n/**\n * Increase value and start over once the range is overflown\n */\nexport const incrementLoopValue = (\n value: number,\n [min, max]: [number, number],\n) => {\n if (value === max) {\n return min;\n }\n return value + 1;\n};\n"],"names":["isFiniteNumber","value","entity","ErrorClass","TypeError","Number","isNaN","isFinite","isInt","isInteger","isSafeInteger","isFloat","toFixedRate","rate","scale","asNumber","fixedRate","toFixed","numberToString","num","toString","findClosestNumber","haystack","needle","reduce","prev","curr","Math","abs","splitNumberBy","by","chunks","Array","floor","fill","remainder","push","clamp","val","min","max","trueMin","trueMax","linearInterpolate","inputY","fromMin","fromMax","toMin","toMax","clampResult","percent","outputX","incrementLoopValue"],"mappings":";;;AAIO,SAASA,cACdA,CAAAC,KAAA,EACAC,MAAS,GAAA,OAAA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U,GAAAD,OAAA,CAAA;EAC1C,MAAAM,OAAA,GAAUD,OAAW,IAAAF,KAAA,GAAQD,KAAS,CAAA,GAAAA,KAAA;EAE5C,OAAOE,WAAc,GAAAZ,KAAA,CAAMc,OAAS,EAAAJ,KAAA,EAAOC,KAAK,CAAI,GAAAG,OAAA;AACtD,CAAA;AAKO,MAAMC,qBAAqBA,CAChCnD,KAAA,EACA,CAACsC,GAAA,EAAKC,GAAG,CACN,KAAA;EACH,IAAIvC,UAAUuC,GAAK,EAAA;IACV,OAAAD,GAAA;EACT;EACA,OAAOtC,KAAQ,GAAA,CAAA;AACjB,CAAA;;;;;;;;;;"}
@@ -20,7 +20,7 @@ function isInt(value, entity = "Value", ErrorClass = TypeError) {
20
20
  function isFloat(value, entity = "Value", ErrorClass = TypeError) {
21
21
  isFiniteNumber(value, entity, ErrorClass);
22
22
  }
23
- function toFixedRate(rate, scale, asNumber) {
23
+ function toFixedRate(rate, scale = 0, asNumber = false) {
24
24
  isFloat(rate, "Rate");
25
25
  const fixedRate = rate.toFixed(scale);
26
26
  return asNumber ? +fixedRate : fixedRate;
@@ -1 +1 @@
1
- {"version":3,"file":"number.mjs","sources":["../../src/utils/number.ts"],"sourcesContent":["/**\n * Util to easily parse that any given input is a finite number (not NaN, Infinity, -Infinity, etc.)\n * @throws If given input is not a finite number\n */\nexport function isFiniteNumber(\n value: unknown,\n entity = \"Value\",\n ErrorClass: new (message: string) => void = TypeError,\n): asserts value is number {\n if (typeof value !== \"number\" || Number.isNaN(value)) {\n // eslint-disable-next-line @typescript-eslint/no-throw-literal\n throw new ErrorClass(`${entity} is not a number: ${value}`);\n }\n\n if (!Number.isFinite(value)) {\n // eslint-disable-next-line @typescript-eslint/no-throw-literal\n throw new ErrorClass(`${entity} is not a finite number: ${value}`);\n }\n}\n\n/**\n * Custom isInt validation function that returns a more fine-grained error message otherwise for type safety alone a\n * Number.isSafeInteger would be sufficient.\n *\n * Code inspired from graphql-scalars library.\n * @see\n * https://github.com/Urigo/graphql-scalars/blob/c4fa3d27b965e39ceda6c33fc18041f112ecce49/src/scalars/utilities.ts#L20-L32\n * @throws If given input is not a valid integer\n */\nexport function isInt(\n value: unknown,\n entity = \"Value\",\n ErrorClass: new (message: string) => void = TypeError,\n): asserts value is number {\n isFiniteNumber(value, entity, ErrorClass);\n\n if (!Number.isInteger(value)) {\n // eslint-disable-next-line @typescript-eslint/no-throw-literal\n throw new ErrorClass(`${entity} is not an integer: ${value}`);\n }\n\n if (!Number.isSafeInteger(value)) {\n // eslint-disable-next-line @typescript-eslint/no-throw-literal\n throw new ErrorClass(`${entity} is not a safe integer: ${value}`);\n }\n}\n\n/**\n * Custom isFloat validation function that returns a more fine-grained error message otherwise for type safety alone a\n * Number.parseFloat would be sufficient.\n *\n * Code inspired from graphql-scalars library.\n * @see\n * https://github.com/Urigo/graphql-scalars/blob/c4fa3d27b965e39ceda6c33fc18041f112ecce49/src/scalars/utilities.ts#L34-L38\n * @throws If given input is not a valid float\n */\nexport function isFloat(\n value: unknown,\n entity = \"Value\",\n ErrorClass: new (message: string) => void = TypeError,\n): asserts value is number {\n isFiniteNumber(value, entity, ErrorClass);\n}\n\n/**\n * Returns a string representing a number in fixed-point notation.\n * Overload: Returns the rate parsed as a number\n * @example\n * toFixed(1.2345, 2) // => \"1.23\"\n * toFixed(1.2345, 0) // => \"1\"\n * toFixed(1.23, 4) // => \"1.2300\"\n */\nexport function toFixedRate(\n rate: number,\n scale: number,\n asNumber?: boolean,\n): string;\nexport function toFixedRate(\n rate: number,\n scale: number,\n asNumber: true,\n): number;\nexport function toFixedRate(rate: number, scale: number, asNumber?: boolean) {\n // Verify rate\n isFloat(rate, \"Rate\");\n\n const fixedRate = rate.toFixed(scale);\n\n return asNumber ? +fixedRate : fixedRate;\n}\n\n/**\n * Util to convert a float number to a string. Using this rather than simple template string to have a consistent way of\n * doing it. Removes any redundant trailing zeros.\n * @example\n * numberToString(1.23) // => \"1.23\"\n * numberToString(10.00) // => \"10\"\n * @throws If given input is not a valid number\n */\nexport const numberToString = (num: number): string => {\n isFloat(num);\n return num.toString(10);\n};\n\n/**\n * @see https://stackoverflow.com/a/35000557\n */\nexport const findClosestNumber = <T extends number>(\n haystack: T[],\n needle: number,\n): T => {\n return haystack.reduce((prev, curr) =>\n Math.abs(curr - needle) < Math.abs(prev - needle) ? curr : prev,\n );\n};\n\n/**\n * Splits number into array by max value provided.\n * E.g. splitNumberBy(100, 30) => [30, 30, 30, 10]\n */\nexport const splitNumberBy = (value: number, by: number) => {\n const chunks = new Array(Math.floor(value / by)).fill(by);\n const remainder = value % by;\n\n if (remainder > 0) {\n chunks.push(remainder);\n }\n\n return chunks;\n};\n\n/**\n * Clamp value to a given range\n */\nexport const clamp = (val: number, min: number, max: number) => {\n const trueMin = Math.min(min, max);\n const trueMax = Math.max(min, max);\n\n return Math.min(trueMax, Math.max(trueMin, val));\n};\n\n/**\n * Interpolate a number to a new range\n *\n * @example\n * linearInterpolate(5, [0, 10], [0, 100]); // 50\n */\nexport const linearInterpolate = (\n inputY: number,\n [fromMin, fromMax]: [number, number],\n [toMin, toMax]: [number, number],\n clampResult = true,\n) => {\n const percent = (inputY - fromMin) / (fromMax - fromMin);\n const outputX = percent * (toMax - toMin) + toMin;\n\n return clampResult ? clamp(outputX, toMin, toMax) : outputX;\n};\n\n/**\n * Increase value and start over once the range is overflown\n */\nexport const incrementLoopValue = (\n value: number,\n [min, max]: [number, number],\n) => {\n if (value === max) {\n return min;\n }\n return value + 1;\n};\n"],"names":["isFiniteNumber","value","entity","ErrorClass","TypeError","Number","isNaN","isFinite","isInt","isInteger","isSafeInteger","isFloat","toFixedRate","rate","scale","asNumber","fixedRate","toFixed","numberToString","num","toString","findClosestNumber","haystack","needle","reduce","prev","curr","Math","abs","splitNumberBy","by","chunks","Array","floor","fill","remainder","push","clamp","val","min","max","trueMin","trueMax","linearInterpolate","inputY","fromMin","fromMax","toMin","toMax","clampResult","percent","outputX","incrementLoopValue"],"mappings":";;AAIO,SAASA,cACdA,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AAC,OAAA,KAAYC,OAAU,GAAAD,OAAA,CAAA;EAC1C,MAAAM,OAAA,GAAUD,OAAW,IAAAF,KAAA,GAAQD,KAAS,CAAA,GAAAA,KAAA;EAE5C,OAAOE,WAAc,GAAAZ,KAAA,CAAMc,OAAS,EAAAJ,KAAA,EAAOC,KAAK,CAAI,GAAAG,OAAA;AACtD,CAAA;AAKO,MAAMC,qBAAqBA,CAChCnD,KAAA,EACA,CAACsC,GAAA,EAAKC,GAAG,CACN,KAAA;EACH,IAAIvC,UAAUuC,GAAK,EAAA;IACV,OAAAD,GAAA;EACT;EACA,OAAOtC,KAAQ,GAAA,CAAA;AACjB,CAAA;"}
1
+ {"version":3,"file":"number.mjs","sources":["../../src/utils/number.ts"],"sourcesContent":["/**\n * Util to easily parse that any given input is a finite number (not NaN, Infinity, -Infinity, etc.)\n * @throws If given input is not a finite number\n */\nexport function isFiniteNumber(\n value: unknown,\n entity = \"Value\",\n ErrorClass: new (message: string) => void = TypeError,\n): asserts value is number {\n if (typeof value !== \"number\" || Number.isNaN(value)) {\n // eslint-disable-next-line @typescript-eslint/no-throw-literal\n throw new ErrorClass(`${entity} is not a number: ${value}`);\n }\n\n if (!Number.isFinite(value)) {\n // eslint-disable-next-line @typescript-eslint/no-throw-literal\n throw new ErrorClass(`${entity} is not a finite number: ${value}`);\n }\n}\n\n/**\n * Custom isInt validation function that returns a more fine-grained error message otherwise for type safety alone a\n * Number.isSafeInteger would be sufficient.\n *\n * Code inspired from graphql-scalars library.\n * @see\n * https://github.com/Urigo/graphql-scalars/blob/c4fa3d27b965e39ceda6c33fc18041f112ecce49/src/scalars/utilities.ts#L20-L32\n * @throws If given input is not a valid integer\n */\nexport function isInt(\n value: unknown,\n entity = \"Value\",\n ErrorClass: new (message: string) => void = TypeError,\n): asserts value is number {\n isFiniteNumber(value, entity, ErrorClass);\n\n if (!Number.isInteger(value)) {\n // eslint-disable-next-line @typescript-eslint/no-throw-literal\n throw new ErrorClass(`${entity} is not an integer: ${value}`);\n }\n\n if (!Number.isSafeInteger(value)) {\n // eslint-disable-next-line @typescript-eslint/no-throw-literal\n throw new ErrorClass(`${entity} is not a safe integer: ${value}`);\n }\n}\n\n/**\n * Custom isFloat validation function that returns a more fine-grained error message otherwise for type safety alone a\n * Number.parseFloat would be sufficient.\n *\n * Code inspired from graphql-scalars library.\n * @see\n * https://github.com/Urigo/graphql-scalars/blob/c4fa3d27b965e39ceda6c33fc18041f112ecce49/src/scalars/utilities.ts#L34-L38\n * @throws If given input is not a valid float\n */\nexport function isFloat(\n value: unknown,\n entity = \"Value\",\n ErrorClass: new (message: string) => void = TypeError,\n): asserts value is number {\n isFiniteNumber(value, entity, ErrorClass);\n}\n\n/**\n * Returns a string representing a number in fixed-point notation.\n * Overload: Returns the rate parsed as a number\n * @example\n * toFixed(1.2345, 2) // => \"1.23\"\n * toFixed(1.2345, 0) // => \"1\"\n * toFixed(1.23, 4) // => \"1.2300\"\n */\nexport function toFixedRate(rate: number, scale: number): string;\nexport function toFixedRate(\n rate: number,\n scale: number,\n asNumber: true,\n): number;\nexport function toFixedRate(rate: number, scale = 0, asNumber = false) {\n // Verify rate\n isFloat(rate, \"Rate\");\n\n const fixedRate = rate.toFixed(scale);\n\n return asNumber ? +fixedRate : fixedRate;\n}\n\n/**\n * Util to convert a float number to a string. Using this rather than simple template string to have a consistent way of\n * doing it. Removes any redundant trailing zeros.\n * @example\n * numberToString(1.23) // => \"1.23\"\n * numberToString(10.00) // => \"10\"\n * @throws If given input is not a valid number\n */\nexport const numberToString = (num: number): string => {\n isFloat(num);\n return num.toString(10);\n};\n\n/**\n * @see https://stackoverflow.com/a/35000557\n */\nexport const findClosestNumber = <T extends number>(\n haystack: T[],\n needle: number,\n): T => {\n return haystack.reduce((prev, curr) =>\n Math.abs(curr - needle) < Math.abs(prev - needle) ? curr : prev,\n );\n};\n\n/**\n * Splits number into array by max value provided.\n * E.g. splitNumberBy(100, 30) => [30, 30, 30, 10]\n */\nexport const splitNumberBy = (value: number, by: number) => {\n const chunks = new Array(Math.floor(value / by)).fill(by);\n const remainder = value % by;\n\n if (remainder > 0) {\n chunks.push(remainder);\n }\n\n return chunks;\n};\n\n/**\n * Clamp value to a given range\n */\nexport const clamp = (val: number, min: number, max: number) => {\n const trueMin = Math.min(min, max);\n const trueMax = Math.max(min, max);\n\n return Math.min(trueMax, Math.max(trueMin, val));\n};\n\n/**\n * Interpolate a number to a new range\n *\n * @example\n * linearInterpolate(5, [0, 10], [0, 100]); // 50\n */\nexport const linearInterpolate = (\n inputY: number,\n [fromMin, fromMax]: [number, number],\n [toMin, toMax]: [number, number],\n clampResult = true,\n) => {\n const percent = (inputY - fromMin) / (fromMax - fromMin);\n const outputX = percent * (toMax - toMin) + toMin;\n\n return clampResult ? clamp(outputX, toMin, toMax) : outputX;\n};\n\n/**\n * Increase value and start over once the range is overflown\n */\nexport const incrementLoopValue = (\n value: number,\n [min, max]: [number, number],\n) => {\n if (value === max) {\n return min;\n }\n return value + 1;\n};\n"],"names":["isFiniteNumber","value","entity","ErrorClass","TypeError","Number","isNaN","isFinite","isInt","isInteger","isSafeInteger","isFloat","toFixedRate","rate","scale","asNumber","fixedRate","toFixed","numberToString","num","toString","findClosestNumber","haystack","needle","reduce","prev","curr","Math","abs","splitNumberBy","by","chunks","Array","floor","fill","remainder","push","clamp","val","min","max","trueMin","trueMax","linearInterpolate","inputY","fromMin","fromMax","toMin","toMax","clampResult","percent","outputX","incrementLoopValue"],"mappings":";;AAIO,SAASA,cACdA,CAAAC,KAAA,EACAC,MAAS,GAAA,OAAA,EACTC,aAA4CC,SACnB,EAAA;EACzB,IAAI,OAAOH,KAAU,KAAA,QAAA,IAAYI,MAAO,CAAAC,KAAA,CAAML,KAAK,CAAG,EAAA;IAEpD,MAAM,IAAIE,UAAW,CAAA,GAAGD,MAAM,qBAAqBD,KAAO,EAAA,CAAA;EAC5D;EAEA,IAAI,CAACI,MAAA,CAAOE,QAAS,CAAAN,KAAK,CAAG,EAAA;IAE3B,MAAM,IA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G,CACN,KAAA;EACH,IAAIvC,UAAUuC,GAAK,EAAA;IACV,OAAAD,GAAA;EACT;EACA,OAAOtC,KAAQ,GAAA,CAAA;AACjB,CAAA;"}
@@ -29,6 +29,9 @@ const postalCodeSuperRefinement = ({
29
29
  return zod$1.addCustomZodIssue(ctx, "postalCode", zod$1.CustomZodIssueCode.PostalCode);
30
30
  }
31
31
  switch (country$1) {
32
+ /**
33
+ * We additionally validate that the postal code matches the selected province
34
+ */
32
35
  case generated.CountryCode.Ca:
33
36
  {
34
37
  if (province && postalCode$1) {
@@ -1 +1 @@
1
- {"version":3,"file":"postalCodeSuperRefinement.js","sources":["../../../src/utils/validations/postalCodeSuperRefinement.ts"],"sourcesContent":["import type { SuperRefinement } from \"zod\";\nimport { ZodIssueCode } from \"zod\";\n\nimport {\n CA_POSTAL_CODE_PROVINCE_FIRST_CHARACTER,\n COUNTRY_CODE_POSTAL_CODE,\n} from \"../../constants/postalCode\";\nimport { CountryCode } from \"../../types\";\nimport type { Nullish } from \"../../types\";\nimport { countryHasPostalCode } from \"../country\";\nimport { addCustomZodIssue, CustomZodIssueCode } from \"../zod\";\n\n/**\n * Validate Postal Code (based on other address fields - country/province)\n * - If country requires postal code, validate postal code\n * - If country does not require postal code, ignore\n * - If country requires postal code, but no postal code, error\n * - If country requires postal code, but invalid postal code, error\n */\nexport const postalCodeSuperRefinement: SuperRefinement<{\n country: CountryCode;\n postalCode?: Nullish<string>;\n province?: Nullish<string>;\n}> = ({ country, postalCode, province }, ctx) => {\n /**\n * Exit early for countries that do not need validation\n */\n if (!countryHasPostalCode(country)) {\n return;\n }\n\n /**\n * First check if postal code is missing for countries that require it\n * Return short length error\n */\n if (!postalCode || !postalCode?.length) {\n return ctx.addIssue({\n path: [\"postalCode\"],\n code: ZodIssueCode.too_small,\n type: \"string\",\n minimum: 1,\n inclusive: true,\n });\n }\n\n /**\n * If there is, validate country against provided postal code regex\n */\n const countryPostalCodeRegex = COUNTRY_CODE_POSTAL_CODE[country]?.regex;\n if (countryPostalCodeRegex && !countryPostalCodeRegex.test(postalCode)) {\n return addCustomZodIssue(ctx, \"postalCode\", CustomZodIssueCode.PostalCode);\n }\n\n /**\n * Extra validations there might be per country regarding postal code\n */\n switch (country) {\n /**\n * We additionally validate that the postal code matches the selected province\n */\n case CountryCode.Ca: {\n if (province && postalCode) {\n const firstPostalCodeChar = postalCode[0];\n if (!firstPostalCodeChar) {\n return addCustomZodIssue(\n ctx,\n \"postalCode\",\n CustomZodIssueCode.PostalCode,\n );\n }\n\n const validRegionPostalCode = Object.entries(\n CA_POSTAL_CODE_PROVINCE_FIRST_CHARACTER,\n ).some(\n ([character, provinceCodes]) =>\n character.toUpperCase() === firstPostalCodeChar.toUpperCase() &&\n provinceCodes.includes(province),\n );\n\n if (!validRegionPostalCode) {\n return addCustomZodIssue(\n ctx,\n \"postalCode\",\n CustomZodIssueCode.PostalCode,\n );\n }\n }\n\n break;\n }\n default:\n break;\n }\n};\n"],"names":["postalCodeSuperRefinement","country","postalCode","province","ctx","countryHasPostalCode","length","addIssue","path","code","ZodIssueCode","too_small","type","minimum","inclusive","countryPostalCodeRegex","COUNTRY_CODE_POSTAL_CODE","regex","test","addCustomZodIssue","CustomZodIssueCode","PostalCode","CountryCode","Ca","firstPostalCodeChar","validRegionPostalCode","Object","entries","CA_POSTAL_CODE_PROVINCE_FIRST_CHARACTER","some","character","provinceCodes","toUpperCase","includes"],"mappings":";;;;;;;;;AAmBO,MAAMA,4BAIRA,CAAC;EAAAC,OAAA,EAAEA;cAASC,YAAY;EAAAC;AAAA,GAAYC,GAAQ,KAAA;EAI3C,IAAA,CAACC,OAAAA,CAAAA,oBAAqB,CAAAJ,SAAO,CAAG,EAAA;IAClC;EACF;EAMA,IAAI,CAACC,YAAA,IAAc,CAACA,YAAA,EAAYI,MAAQ,EAAA;IACtC,OAAOF,IAAIG,QAAS,CAAA;MAClBC,IAAA,EAAM,CAAC,YAAY,CAAA;MACnBC,MAAMC,GAAa,CAAAA,YAAA,CAAAC,SAAA;MACnBC,IAAM,EAAA,QAAA;MACNC,OAAS,EAAA,CAAA;MACTC,SAAW,EAAA;IAAA,CACZ,CAAA;EACH;EAKM,MAAAC,sBAAA,GAAyBC,UAAAA,CAAAA,wBAAyB,CAAAf,SAAO,CAAG,EAAAgB,KAAA;EAClE,IAAIF,sBAA0B,IAAA,CAACA,sBAAuB,CAAAG,IAAA,CAAKhB,YAAU,CAAG,EAAA;IACtE,OAAOiB,KAAkB,CAAAA,iBAAA,CAAAf,GAAA,EAAK,YAAc,EAAAgB,KAAA,CAAAA,kBAAA,CAAmBC,UAAU,CAAA;EAC3E;EAKA,QAAQpB,SAAS;IAIf,KAAKqB,SAAAA,CAAAA,YAAYC,EAAI;MAAA;QACnB,IAAIpB,YAAYD,YAAY,EAAA;UACpB,MAAAsB,mBAAA,GAAsBtB,aAAW,CAAC,CAAA;UACxC,IAAI,CAACsB,mBAAqB,EAAA;YACjB,OAAAL,KAAA,CAAAA,iBAAA,CACLf,GAAA,EACA,YAAA,EACAgB,KAAAA,CAAAA,kBAAmB,CAAAC,UAAA,CACrB;UACF;UAEA,MAAMI,wBAAwBC,MAAO,CAAAC,OAAA,CACnCC,UAAA,CAAAA,uCAAA,CACA,CAAAC,IAAA,CACA,CAAC,CAACC,SAAW,EAAAC,aAAa,CACxB,KAAAD,SAAA,CAAUE,WAAY,CAAA,CAAA,KAAMR,mBAAoB,CAAAQ,WAAA,CAChD,CAAA,IAAAD,aAAA,CAAcE,SAAS9B,QAAQ,CAAA,CACnC;UAEA,IAAI,CAACsB,qBAAuB,EAAA;YACnB,OAAAN,KAAA,CAAAA,iBAAA,CACLf,GAAA,EACA,YAAA,EACAgB,KAAAA,CAAAA,kBAAmB,CAAAC,UAAA,CACrB;UACF;QACF;QAEA;MACF;IACA;MACE;EACJ;AACF,CAAA;"}
1
+ {"version":3,"file":"postalCodeSuperRefinement.js","sources":["../../../src/utils/validations/postalCodeSuperRefinement.ts"],"sourcesContent":["import type { SuperRefinement } from \"zod\";\nimport { ZodIssueCode } from \"zod\";\n\nimport {\n CA_POSTAL_CODE_PROVINCE_FIRST_CHARACTER,\n COUNTRY_CODE_POSTAL_CODE,\n} from \"../../constants/postalCode\";\nimport { CountryCode } from \"../../types\";\nimport type { Nullish } from \"../../types\";\nimport { countryHasPostalCode } from \"../country\";\nimport { addCustomZodIssue, CustomZodIssueCode } from \"../zod\";\n\n/**\n * Validate Postal Code (based on other address fields - country/province)\n * - If country requires postal code, validate postal code\n * - If country does not require postal code, ignore\n * - If country requires postal code, but no postal code, error\n * - If country requires postal code, but invalid postal code, error\n */\nexport const postalCodeSuperRefinement: SuperRefinement<{\n country: CountryCode;\n postalCode?: Nullish<string>;\n province?: Nullish<string>;\n}> = ({ country, postalCode, province }, ctx) => {\n /**\n * Exit early for countries that do not need validation\n */\n if (!countryHasPostalCode(country)) {\n return;\n }\n\n /**\n * First check if postal code is missing for countries that require it\n * Return short length error\n */\n if (!postalCode || !postalCode?.length) {\n return ctx.addIssue({\n path: [\"postalCode\"],\n code: ZodIssueCode.too_small,\n type: \"string\",\n minimum: 1,\n inclusive: true,\n });\n }\n\n /**\n * If there is, validate country against provided postal code regex\n */\n const countryPostalCodeRegex = COUNTRY_CODE_POSTAL_CODE[country]?.regex;\n if (countryPostalCodeRegex && !countryPostalCodeRegex.test(postalCode)) {\n return addCustomZodIssue(ctx, \"postalCode\", CustomZodIssueCode.PostalCode);\n }\n\n /**\n * Extra validations there might be per country regarding postal code\n */\n switch (country) {\n /**\n * We additionally validate that the postal code matches the selected province\n */\n case CountryCode.Ca: {\n if (province && postalCode) {\n const firstPostalCodeChar = postalCode[0];\n if (!firstPostalCodeChar) {\n return addCustomZodIssue(\n ctx,\n \"postalCode\",\n CustomZodIssueCode.PostalCode,\n );\n }\n\n const validRegionPostalCode = Object.entries(\n CA_POSTAL_CODE_PROVINCE_FIRST_CHARACTER,\n ).some(\n ([character, provinceCodes]) =>\n character.toUpperCase() === firstPostalCodeChar.toUpperCase() &&\n provinceCodes.includes(province),\n );\n\n if (!validRegionPostalCode) {\n return addCustomZodIssue(\n ctx,\n \"postalCode\",\n CustomZodIssueCode.PostalCode,\n );\n }\n }\n\n break;\n }\n default:\n break;\n }\n};\n"],"names":["postalCodeSuperRefinement","country","postalCode","province","ctx","countryHasPostalCode","length","addIssue","path","code","ZodIssueCode","too_small","type","minimum","inclusive","countryPostalCodeRegex","COUNTRY_CODE_POSTAL_CODE","regex","test","addCustomZodIssue","CustomZodIssueCode","PostalCode","CountryCode","Ca","firstPostalCodeChar","validRegionPostalCode","Object","entries","CA_POSTAL_CODE_PROVINCE_FIRST_CHARACTER","some","character","provinceCodes","toUpperCase","includes"],"mappings":";;;;;;;;;AAmBO,MAAMA,4BAIRA,CAAC;EAAAC,OAAA,EAAEA;cAASC,YAAY;EAAAC;AAAA,GAAYC,GAAQ,KAAA;EAI3C,IAAA,CAACC,OAAAA,CAAAA,oBAAqB,CAAAJ,SAAO,CAAG,EAAA;IAClC;EACF;EAMA,IAAI,CAACC,YAAA,IAAc,CAACA,YAAA,EAAYI,MAAQ,EAAA;IACtC,OAAOF,IAAIG,QAAS,CAAA;MAClBC,IAAA,EAAM,CAAC,YAAY,CAAA;MACnBC,MAAMC,GAAa,CAAAA,YAAA,CAAAC,SAAA;MACnBC,IAAM,EAAA,QAAA;MACNC,OAAS,EAAA,CAAA;MACTC,SAAW,EAAA;IAAA,CACZ,CAAA;EACH;EAKM,MAAAC,sBAAA,GAAyBC,UAAAA,CAAAA,wBAAyB,CAAAf,SAAO,CAAG,EAAAgB,KAAA;EAClE,IAAIF,sBAA0B,IAAA,CAACA,sBAAuB,CAAAG,IAAA,CAAKhB,YAAU,CAAG,EAAA;IACtE,OAAOiB,KAAkB,CAAAA,iBAAA,CAAAf,GAAA,EAAK,YAAc,EAAAgB,KAAA,CAAAA,kBAAA,CAAmBC,UAAU,CAAA;EAC3E;EAKA,QAAQpB,SAAS;IAAA;AAAA;AAAA;IAIf,KAAKqB,SAAAA,CAAAA,YAAYC,EAAI;MAAA;QACnB,IAAIpB,YAAYD,YAAY,EAAA;UACpB,MAAAsB,mBAAA,GAAsBtB,aAAW,CAAC,CAAA;UACxC,IAAI,CAACsB,mBAAqB,EAAA;YACjB,OAAAL,KAAA,CAAAA,iBAAA,CACLf,GAAA,EACA,YAAA,EACAgB,KAAAA,CAAAA,kBAAmB,CAAAC,UAAA,CACrB;UACF;UAEA,MAAMI,wBAAwBC,MAAO,CAAAC,OAAA,CACnCC,UAAA,CAAAA,uCAAA,CACA,CAAAC,IAAA,CACA,CAAC,CAACC,SAAW,EAAAC,aAAa,CACxB,KAAAD,SAAA,CAAUE,WAAY,CAAA,CAAA,KAAMR,mBAAoB,CAAAQ,WAAA,CAChD,CAAA,IAAAD,aAAA,CAAcE,SAAS9B,QAAQ,CAAA,CACnC;UAEA,IAAI,CAACsB,qBAAuB,EAAA;YACnB,OAAAN,KAAA,CAAAA,iBAAA,CACLf,GAAA,EACA,YAAA,EACAgB,KAAAA,CAAAA,kBAAmB,CAAAC,UAAA,CACrB;UACF;QACF;QAEA;MACF;IACA;MACE;EACJ;AACF,CAAA;"}
@@ -27,6 +27,9 @@ const postalCodeSuperRefinement = ({
27
27
  return addCustomZodIssue(ctx, "postalCode", CustomZodIssueCode.PostalCode);
28
28
  }
29
29
  switch (country) {
30
+ /**
31
+ * We additionally validate that the postal code matches the selected province
32
+ */
30
33
  case CountryCode.Ca:
31
34
  {
32
35
  if (province && postalCode) {
@@ -1 +1 @@
1
- {"version":3,"file":"postalCodeSuperRefinement.mjs","sources":["../../../src/utils/validations/postalCodeSuperRefinement.ts"],"sourcesContent":["import type { SuperRefinement } from \"zod\";\nimport { ZodIssueCode } from \"zod\";\n\nimport {\n CA_POSTAL_CODE_PROVINCE_FIRST_CHARACTER,\n COUNTRY_CODE_POSTAL_CODE,\n} from \"../../constants/postalCode\";\nimport { CountryCode } from \"../../types\";\nimport type { Nullish } from \"../../types\";\nimport { countryHasPostalCode } from \"../country\";\nimport { addCustomZodIssue, CustomZodIssueCode } from \"../zod\";\n\n/**\n * Validate Postal Code (based on other address fields - country/province)\n * - If country requires postal code, validate postal code\n * - If country does not require postal code, ignore\n * - If country requires postal code, but no postal code, error\n * - If country requires postal code, but invalid postal code, error\n */\nexport const postalCodeSuperRefinement: SuperRefinement<{\n country: CountryCode;\n postalCode?: Nullish<string>;\n province?: Nullish<string>;\n}> = ({ country, postalCode, province }, ctx) => {\n /**\n * Exit early for countries that do not need validation\n */\n if (!countryHasPostalCode(country)) {\n return;\n }\n\n /**\n * First check if postal code is missing for countries that require it\n * Return short length error\n */\n if (!postalCode || !postalCode?.length) {\n return ctx.addIssue({\n path: [\"postalCode\"],\n code: ZodIssueCode.too_small,\n type: \"string\",\n minimum: 1,\n inclusive: true,\n });\n }\n\n /**\n * If there is, validate country against provided postal code regex\n */\n const countryPostalCodeRegex = COUNTRY_CODE_POSTAL_CODE[country]?.regex;\n if (countryPostalCodeRegex && !countryPostalCodeRegex.test(postalCode)) {\n return addCustomZodIssue(ctx, \"postalCode\", CustomZodIssueCode.PostalCode);\n }\n\n /**\n * Extra validations there might be per country regarding postal code\n */\n switch (country) {\n /**\n * We additionally validate that the postal code matches the selected province\n */\n case CountryCode.Ca: {\n if (province && postalCode) {\n const firstPostalCodeChar = postalCode[0];\n if (!firstPostalCodeChar) {\n return addCustomZodIssue(\n ctx,\n \"postalCode\",\n CustomZodIssueCode.PostalCode,\n );\n }\n\n const validRegionPostalCode = Object.entries(\n CA_POSTAL_CODE_PROVINCE_FIRST_CHARACTER,\n ).some(\n ([character, provinceCodes]) =>\n character.toUpperCase() === firstPostalCodeChar.toUpperCase() &&\n provinceCodes.includes(province),\n );\n\n if (!validRegionPostalCode) {\n return addCustomZodIssue(\n ctx,\n \"postalCode\",\n CustomZodIssueCode.PostalCode,\n );\n }\n }\n\n break;\n }\n default:\n break;\n }\n};\n"],"names":["postalCodeSuperRefinement","country","postalCode","province","ctx","countryHasPostalCode","length","addIssue","path","code","ZodIssueCode","too_small","type","minimum","inclusive","countryPostalCodeRegex","COUNTRY_CODE_POSTAL_CODE","regex","test","addCustomZodIssue","CustomZodIssueCode","PostalCode","CountryCode","Ca","firstPostalCodeChar","validRegionPostalCode","Object","entries","CA_POSTAL_CODE_PROVINCE_FIRST_CHARACTER","some","character","provinceCodes","toUpperCase","includes"],"mappings":";;;;;;;AAmBO,MAAMA,4BAIRA,CAAC;EAAEC;EAASC,UAAY;EAAAC;AAAA,GAAYC,GAAQ,KAAA;EAI3C,IAAA,CAACC,oBAAqB,CAAAJ,OAAO,CAAG,EAAA;IAClC;EACF;EAMA,IAAI,CAACC,UAAA,IAAc,CAACA,UAAA,EAAYI,MAAQ,EAAA;IACtC,OAAOF,IAAIG,QAAS,CAAA;MAClBC,IAAA,EAAM,CAAC,YAAY,CAAA;MACnBC,MAAMC,YAAa,CAAAC,SAAA;MACnBC,IAAM,EAAA,QAAA;MACNC,OAAS,EAAA,CAAA;MACTC,SAAW,EAAA;IAAA,CACZ,CAAA;EACH;EAKM,MAAAC,sBAAA,GAAyBC,wBAAyB,CAAAf,OAAO,CAAG,EAAAgB,KAAA;EAClE,IAAIF,sBAA0B,IAAA,CAACA,sBAAuB,CAAAG,IAAA,CAAKhB,UAAU,CAAG,EAAA;IACtE,OAAOiB,iBAAkB,CAAAf,GAAA,EAAK,YAAc,EAAAgB,kBAAA,CAAmBC,UAAU,CAAA;EAC3E;EAKA,QAAQpB,OAAS;IAIf,KAAKqB,YAAYC,EAAI;MAAA;QACnB,IAAIpB,YAAYD,UAAY,EAAA;UACpB,MAAAsB,mBAAA,GAAsBtB,WAAW,CAAC,CAAA;UACxC,IAAI,CAACsB,mBAAqB,EAAA;YACjB,OAAAL,iBAAA,CACLf,GAAA,EACA,YAAA,EACAgB,kBAAmB,CAAAC,UAAA,CACrB;UACF;UAEA,MAAMI,wBAAwBC,MAAO,CAAAC,OAAA,CACnCC,uCAAA,CACA,CAAAC,IAAA,CACA,CAAC,CAACC,SAAW,EAAAC,aAAa,CACxB,KAAAD,SAAA,CAAUE,WAAY,CAAA,CAAA,KAAMR,mBAAoB,CAAAQ,WAAA,CAChD,CAAA,IAAAD,aAAA,CAAcE,SAAS9B,QAAQ,CAAA,CACnC;UAEA,IAAI,CAACsB,qBAAuB,EAAA;YACnB,OAAAN,iBAAA,CACLf,GAAA,EACA,YAAA,EACAgB,kBAAmB,CAAAC,UAAA,CACrB;UACF;QACF;QAEA;MACF;IACA;MACE;EACJ;AACF,CAAA;"}
1
+ {"version":3,"file":"postalCodeSuperRefinement.mjs","sources":["../../../src/utils/validations/postalCodeSuperRefinement.ts"],"sourcesContent":["import type { SuperRefinement } from \"zod\";\nimport { ZodIssueCode } from \"zod\";\n\nimport {\n CA_POSTAL_CODE_PROVINCE_FIRST_CHARACTER,\n COUNTRY_CODE_POSTAL_CODE,\n} from \"../../constants/postalCode\";\nimport { CountryCode } from \"../../types\";\nimport type { Nullish } from \"../../types\";\nimport { countryHasPostalCode } from \"../country\";\nimport { addCustomZodIssue, CustomZodIssueCode } from \"../zod\";\n\n/**\n * Validate Postal Code (based on other address fields - country/province)\n * - If country requires postal code, validate postal code\n * - If country does not require postal code, ignore\n * - If country requires postal code, but no postal code, error\n * - If country requires postal code, but invalid postal code, error\n */\nexport const postalCodeSuperRefinement: SuperRefinement<{\n country: CountryCode;\n postalCode?: Nullish<string>;\n province?: Nullish<string>;\n}> = ({ country, postalCode, province }, ctx) => {\n /**\n * Exit early for countries that do not need validation\n */\n if (!countryHasPostalCode(country)) {\n return;\n }\n\n /**\n * First check if postal code is missing for countries that require it\n * Return short length error\n */\n if (!postalCode || !postalCode?.length) {\n return ctx.addIssue({\n path: [\"postalCode\"],\n code: ZodIssueCode.too_small,\n type: \"string\",\n minimum: 1,\n inclusive: true,\n });\n }\n\n /**\n * If there is, validate country against provided postal code regex\n */\n const countryPostalCodeRegex = COUNTRY_CODE_POSTAL_CODE[country]?.regex;\n if (countryPostalCodeRegex && !countryPostalCodeRegex.test(postalCode)) {\n return addCustomZodIssue(ctx, \"postalCode\", CustomZodIssueCode.PostalCode);\n }\n\n /**\n * Extra validations there might be per country regarding postal code\n */\n switch (country) {\n /**\n * We additionally validate that the postal code matches the selected province\n */\n case CountryCode.Ca: {\n if (province && postalCode) {\n const firstPostalCodeChar = postalCode[0];\n if (!firstPostalCodeChar) {\n return addCustomZodIssue(\n ctx,\n \"postalCode\",\n CustomZodIssueCode.PostalCode,\n );\n }\n\n const validRegionPostalCode = Object.entries(\n CA_POSTAL_CODE_PROVINCE_FIRST_CHARACTER,\n ).some(\n ([character, provinceCodes]) =>\n character.toUpperCase() === firstPostalCodeChar.toUpperCase() &&\n provinceCodes.includes(province),\n );\n\n if (!validRegionPostalCode) {\n return addCustomZodIssue(\n ctx,\n \"postalCode\",\n CustomZodIssueCode.PostalCode,\n );\n }\n }\n\n break;\n }\n default:\n break;\n }\n};\n"],"names":["postalCodeSuperRefinement","country","postalCode","province","ctx","countryHasPostalCode","length","addIssue","path","code","ZodIssueCode","too_small","type","minimum","inclusive","countryPostalCodeRegex","COUNTRY_CODE_POSTAL_CODE","regex","test","addCustomZodIssue","CustomZodIssueCode","PostalCode","CountryCode","Ca","firstPostalCodeChar","validRegionPostalCode","Object","entries","CA_POSTAL_CODE_PROVINCE_FIRST_CHARACTER","some","character","provinceCodes","toUpperCase","includes"],"mappings":";;;;;;;AAmBO,MAAMA,4BAIRA,CAAC;EAAEC;EAASC,UAAY;EAAAC;AAAA,GAAYC,GAAQ,KAAA;EAI3C,IAAA,CAACC,oBAAqB,CAAAJ,OAAO,CAAG,EAAA;IAClC;EACF;EAMA,IAAI,CAACC,UAAA,IAAc,CAACA,UAAA,EAAYI,MAAQ,EAAA;IACtC,OAAOF,IAAIG,QAAS,CAAA;MAClBC,IAAA,EAAM,CAAC,YAAY,CAAA;MACnBC,MAAMC,YAAa,CAAAC,SAAA;MACnBC,IAAM,EAAA,QAAA;MACNC,OAAS,EAAA,CAAA;MACTC,SAAW,EAAA;IAAA,CACZ,CAAA;EACH;EAKM,MAAAC,sBAAA,GAAyBC,wBAAyB,CAAAf,OAAO,CAAG,EAAAgB,KAAA;EAClE,IAAIF,sBAA0B,IAAA,CAACA,sBAAuB,CAAAG,IAAA,CAAKhB,UAAU,CAAG,EAAA;IACtE,OAAOiB,iBAAkB,CAAAf,GAAA,EAAK,YAAc,EAAAgB,kBAAA,CAAmBC,UAAU,CAAA;EAC3E;EAKA,QAAQpB,OAAS;IAAA;AAAA;AAAA;IAIf,KAAKqB,YAAYC,EAAI;MAAA;QACnB,IAAIpB,YAAYD,UAAY,EAAA;UACpB,MAAAsB,mBAAA,GAAsBtB,WAAW,CAAC,CAAA;UACxC,IAAI,CAACsB,mBAAqB,EAAA;YACjB,OAAAL,iBAAA,CACLf,GAAA,EACA,YAAA,EACAgB,kBAAmB,CAAAC,UAAA,CACrB;UACF;UAEA,MAAMI,wBAAwBC,MAAO,CAAAC,OAAA,CACnCC,uCAAA,CACA,CAAAC,IAAA,CACA,CAAC,CAACC,SAAW,EAAAC,aAAa,CACxB,KAAAD,SAAA,CAAUE,WAAY,CAAA,CAAA,KAAMR,mBAAoB,CAAAQ,WAAA,CAChD,CAAA,IAAAD,aAAA,CAAcE,SAAS9B,QAAQ,CAAA,CACnC;UAEA,IAAI,CAACsB,qBAAuB,EAAA;YACnB,OAAAN,iBAAA,CACLf,GAAA,EACA,YAAA,EACAgB,kBAAmB,CAAAC,UAAA,CACrB;UACF;QACF;QAEA;MACF;IACA;MACE;EACJ;AACF,CAAA;"}
@@ -17,8 +17,10 @@ const createStateRegistrationNumberSuperRefinement = ({
17
17
  type
18
18
  }, ctx) => {
19
19
  switch (addressUsageType) {
20
+ // Exit early because state registration number is generally not needed for billing addresses.
20
21
  case constants.AddressUsageType.Billing:
21
22
  return;
23
+ // Don't do anything and proceed with the validation logic below.
22
24
  case constants.AddressUsageType.ReturnShipping:
23
25
  case constants.AddressUsageType.Shipping:
24
26
  break;
@@ -1 +1 @@
1
- {"version":3,"file":"stateRegistrationNumberSuperRefinement.js","sources":["../../../src/utils/validations/stateRegistrationNumberSuperRefinement.ts"],"sourcesContent":["import { type SuperRefinement, ZodIssueCode } from \"zod\";\n\nimport type { Nullish } from \"../../types\";\nimport { AddressType, AddressUsageType, CountryCode } from \"../../types\";\nimport { assertUnreachable } from \"../errors\";\nimport { addCustomZodIssue, CustomZodIssueCode } from \"../zod\";\n\nexport const EXEMPTED = \"EXEMPTED\";\nconst IS_DIGITS_ONLY_REGEX = /^\\d+$/;\n\nexport const createStateRegistrationNumberSuperRefinement =\n ({\n addressUsageType,\n }: {\n addressUsageType: AddressUsageType;\n }): SuperRefinement<{\n stateRegistrationNumber?: Nullish<string>;\n country: CountryCode;\n type: AddressType;\n }> =>\n ({ stateRegistrationNumber, country, type }, ctx) => {\n switch (addressUsageType) {\n // Exit early because state registration number is generally not needed for billing addresses.\n case AddressUsageType.Billing:\n return;\n // Don't do anything and proceed with the validation logic below.\n case AddressUsageType.ReturnShipping:\n case AddressUsageType.Shipping:\n break;\n default:\n assertUnreachable(addressUsageType);\n }\n\n // Only relevant for Brazil business addresses.\n if (!(country === CountryCode.Br && type === AddressType.Business)) {\n return;\n }\n\n // Exempted state registration numbers are valid.\n if (stateRegistrationNumber === EXEMPTED) {\n return;\n }\n\n // Handle cases when the value is too small.\n if (!stateRegistrationNumber?.length) {\n return ctx.addIssue({\n path: [\"stateRegistrationNumber\"],\n code: ZodIssueCode.too_small,\n type: \"string\",\n minimum: 1,\n inclusive: true,\n });\n }\n\n // It should be only digits.\n if (!IS_DIGITS_ONLY_REGEX.test(stateRegistrationNumber)) {\n return addCustomZodIssue(\n ctx,\n \"stateRegistrationNumber\",\n CustomZodIssueCode.DigitsOnly,\n );\n }\n };\n"],"names":["EXEMPTED","IS_DIGITS_ONLY_REGEX","createStateRegistrationNumberSuperRefinement","addressUsageType","stateRegistrationNumber","country","type","ctx","AddressUsageType","Billing","ReturnShipping","Shipping","assertUnreachable","CountryCode","Br","AddressType","Business","length","addIssue","path","code","ZodIssueCode","too_small","minimum","inclusive","test","addCustomZodIssue","CustomZodIssueCode","DigitsOnly"],"mappings":";;;;;;;;;AAOO,MAAMA,QAAW,GAAA,UAAA;AACxB,MAAMC,oBAAuB,GAAA,OAAA;AAEtB,MAAMC,+CACXA,CAAC;EACCC;AACF,CAAA,KAOA,CAAC;EAAEC,uBAAA;EAAyBC,OAAS;EAAAC;AAAA,GAAQC,GAAQ,KAAA;EACnD,QAAQJ,gBAAkB;IAExB,KAAKK,SAAiB,CAAAA,gBAAA,CAAAC,OAAA;MACpB;IAEF,KAAKD,SAAAA,CAAAA,gBAAiB,CAAAE,cAAA;IACtB,KAAKF,SAAiB,CAAAA,gBAAA,CAAAG,QAAA;MACpB;IACF;MACEC,MAAA,CAAAA,iBAAA,CAAkBT,gBAAgB,CAAA;EACtC;EAGA,IAAI,EAAEE,OAAY,KAAAQ,qBAAA,CAAYC,EAAM,IAAAR,IAAA,KAASS,SAAAA,CAAAA,YAAYC,QAAW,CAAA,EAAA;IAClE;EACF;EAGA,IAAIZ,4BAA4BJ,QAAU,EAAA;IACxC;EACF;EAGI,IAAA,CAACI,yBAAyBa,MAAQ,EAAA;IACpC,OAAOV,IAAIW,QAAS,CAAA;MAClBC,IAAA,EAAM,CAAC,yBAAyB,CAAA;MAChCC,MAAMC,GAAa,CAAAA,YAAA,CAAAC,SAAA;MACnBhB,IAAM,EAAA,QAAA;MACNiB,OAAS,EAAA,CAAA;MACTC,SAAW,EAAA;IAAA,CACZ,CAAA;EACH;EAGA,IAAI,CAACvB,oBAAA,CAAqBwB,IAAK,CAAArB,uBAAuB,CAAG,EAAA;IAChD,OAAAsB,KAAA,CAAAA,iBAAA,CACLnB,GAAA,EACA,yBAAA,EACAoB,KAAAA,CAAAA,kBAAmB,CAAAC,UAAA,CACrB;EACF;AACF,CAAA;;"}
1
+ {"version":3,"file":"stateRegistrationNumberSuperRefinement.js","sources":["../../../src/utils/validations/stateRegistrationNumberSuperRefinement.ts"],"sourcesContent":["import { type SuperRefinement, ZodIssueCode } from \"zod\";\n\nimport type { Nullish } from \"../../types\";\nimport { AddressType, AddressUsageType, CountryCode } from \"../../types\";\nimport { assertUnreachable } from \"../errors\";\nimport { addCustomZodIssue, CustomZodIssueCode } from \"../zod\";\n\nexport const EXEMPTED = \"EXEMPTED\";\nconst IS_DIGITS_ONLY_REGEX = /^\\d+$/;\n\nexport const createStateRegistrationNumberSuperRefinement =\n ({\n addressUsageType,\n }: {\n addressUsageType: AddressUsageType;\n }): SuperRefinement<{\n stateRegistrationNumber?: Nullish<string>;\n country: CountryCode;\n type: AddressType;\n }> =>\n ({ stateRegistrationNumber, country, type }, ctx) => {\n switch (addressUsageType) {\n // Exit early because state registration number is generally not needed for billing addresses.\n case AddressUsageType.Billing:\n return;\n // Don't do anything and proceed with the validation logic below.\n case AddressUsageType.ReturnShipping:\n case AddressUsageType.Shipping:\n break;\n default:\n assertUnreachable(addressUsageType);\n }\n\n // Only relevant for Brazil business addresses.\n if (!(country === CountryCode.Br && type === AddressType.Business)) {\n return;\n }\n\n // Exempted state registration numbers are valid.\n if (stateRegistrationNumber === EXEMPTED) {\n return;\n }\n\n // Handle cases when the value is too small.\n if (!stateRegistrationNumber?.length) {\n return ctx.addIssue({\n path: [\"stateRegistrationNumber\"],\n code: ZodIssueCode.too_small,\n type: \"string\",\n minimum: 1,\n inclusive: true,\n });\n }\n\n // It should be only digits.\n if (!IS_DIGITS_ONLY_REGEX.test(stateRegistrationNumber)) {\n return addCustomZodIssue(\n ctx,\n \"stateRegistrationNumber\",\n CustomZodIssueCode.DigitsOnly,\n );\n }\n };\n"],"names":["EXEMPTED","IS_DIGITS_ONLY_REGEX","createStateRegistrationNumberSuperRefinement","addressUsageType","stateRegistrationNumber","country","type","ctx","AddressUsageType","Billing","ReturnShipping","Shipping","assertUnreachable","CountryCode","Br","AddressType","Business","length","addIssue","path","code","ZodIssueCode","too_small","minimum","inclusive","test","addCustomZodIssue","CustomZodIssueCode","DigitsOnly"],"mappings":";;;;;;;;;AAOO,MAAMA,QAAW,GAAA,UAAA;AACxB,MAAMC,oBAAuB,GAAA,OAAA;AAEtB,MAAMC,+CACXA,CAAC;EACCC;AACF,CAAA,KAOA,CAAC;EAAEC,uBAAA;EAAyBC,OAAS;EAAAC;AAAA,GAAQC,GAAQ,KAAA;EACnD,QAAQJ,gBAAkB;IAAA;IAExB,KAAKK,SAAiB,CAAAA,gBAAA,CAAAC,OAAA;MACpB;IAAA;IAEF,KAAKD,SAAAA,CAAAA,gBAAiB,CAAAE,cAAA;IACtB,KAAKF,SAAiB,CAAAA,gBAAA,CAAAG,QAAA;MACpB;IACF;MACEC,MAAA,CAAAA,iBAAA,CAAkBT,gBAAgB,CAAA;EACtC;EAGA,IAAI,EAAEE,OAAY,KAAAQ,qBAAA,CAAYC,EAAM,IAAAR,IAAA,KAASS,SAAAA,CAAAA,YAAYC,QAAW,CAAA,EAAA;IAClE;EACF;EAGA,IAAIZ,4BAA4BJ,QAAU,EAAA;IACxC;EACF;EAGI,IAAA,CAACI,yBAAyBa,MAAQ,EAAA;IACpC,OAAOV,IAAIW,QAAS,CAAA;MAClBC,IAAA,EAAM,CAAC,yBAAyB,CAAA;MAChCC,MAAMC,GAAa,CAAAA,YAAA,CAAAC,SAAA;MACnBhB,IAAM,EAAA,QAAA;MACNiB,OAAS,EAAA,CAAA;MACTC,SAAW,EAAA;IAAA,CACZ,CAAA;EACH;EAGA,IAAI,CAACvB,oBAAA,CAAqBwB,IAAK,CAAArB,uBAAuB,CAAG,EAAA;IAChD,OAAAsB,KAAA,CAAAA,iBAAA,CACLnB,GAAA,EACA,yBAAA,EACAoB,KAAAA,CAAAA,kBAAmB,CAAAC,UAAA,CACrB;EACF;AACF,CAAA;;"}
@@ -15,8 +15,10 @@ const createStateRegistrationNumberSuperRefinement = ({
15
15
  type
16
16
  }, ctx) => {
17
17
  switch (addressUsageType) {
18
+ // Exit early because state registration number is generally not needed for billing addresses.
18
19
  case AddressUsageType.Billing:
19
20
  return;
21
+ // Don't do anything and proceed with the validation logic below.
20
22
  case AddressUsageType.ReturnShipping:
21
23
  case AddressUsageType.Shipping:
22
24
  break;
@@ -1 +1 @@
1
- {"version":3,"file":"stateRegistrationNumberSuperRefinement.mjs","sources":["../../../src/utils/validations/stateRegistrationNumberSuperRefinement.ts"],"sourcesContent":["import { type SuperRefinement, ZodIssueCode } from \"zod\";\n\nimport type { Nullish } from \"../../types\";\nimport { AddressType, AddressUsageType, CountryCode } from \"../../types\";\nimport { assertUnreachable } from \"../errors\";\nimport { addCustomZodIssue, CustomZodIssueCode } from \"../zod\";\n\nexport const EXEMPTED = \"EXEMPTED\";\nconst IS_DIGITS_ONLY_REGEX = /^\\d+$/;\n\nexport const createStateRegistrationNumberSuperRefinement =\n ({\n addressUsageType,\n }: {\n addressUsageType: AddressUsageType;\n }): SuperRefinement<{\n stateRegistrationNumber?: Nullish<string>;\n country: CountryCode;\n type: AddressType;\n }> =>\n ({ stateRegistrationNumber, country, type }, ctx) => {\n switch (addressUsageType) {\n // Exit early because state registration number is generally not needed for billing addresses.\n case AddressUsageType.Billing:\n return;\n // Don't do anything and proceed with the validation logic below.\n case AddressUsageType.ReturnShipping:\n case AddressUsageType.Shipping:\n break;\n default:\n assertUnreachable(addressUsageType);\n }\n\n // Only relevant for Brazil business addresses.\n if (!(country === CountryCode.Br && type === AddressType.Business)) {\n return;\n }\n\n // Exempted state registration numbers are valid.\n if (stateRegistrationNumber === EXEMPTED) {\n return;\n }\n\n // Handle cases when the value is too small.\n if (!stateRegistrationNumber?.length) {\n return ctx.addIssue({\n path: [\"stateRegistrationNumber\"],\n code: ZodIssueCode.too_small,\n type: \"string\",\n minimum: 1,\n inclusive: true,\n });\n }\n\n // It should be only digits.\n if (!IS_DIGITS_ONLY_REGEX.test(stateRegistrationNumber)) {\n return addCustomZodIssue(\n ctx,\n \"stateRegistrationNumber\",\n CustomZodIssueCode.DigitsOnly,\n );\n }\n };\n"],"names":["EXEMPTED","IS_DIGITS_ONLY_REGEX","createStateRegistrationNumberSuperRefinement","addressUsageType","stateRegistrationNumber","country","type","ctx","AddressUsageType","Billing","ReturnShipping","Shipping","assertUnreachable","CountryCode","Br","AddressType","Business","length","addIssue","path","code","ZodIssueCode","too_small","minimum","inclusive","test","addCustomZodIssue","CustomZodIssueCode","DigitsOnly"],"mappings":";;;;;;;AAOO,MAAMA,QAAW,GAAA,UAAA;AACxB,MAAMC,oBAAuB,GAAA,OAAA;AAEtB,MAAMC,+CACXA,CAAC;EACCC;AACF,CAAA,KAOA,CAAC;EAAEC,uBAAA;EAAyBC,OAAS;EAAAC;AAAA,GAAQC,GAAQ,KAAA;EACnD,QAAQJ,gBAAkB;IAExB,KAAKK,gBAAiB,CAAAC,OAAA;MACpB;IAEF,KAAKD,gBAAiB,CAAAE,cAAA;IACtB,KAAKF,gBAAiB,CAAAG,QAAA;MACpB;IACF;MACEC,iBAAA,CAAkBT,gBAAgB,CAAA;EACtC;EAGA,IAAI,EAAEE,OAAY,KAAAQ,WAAA,CAAYC,EAAM,IAAAR,IAAA,KAASS,YAAYC,QAAW,CAAA,EAAA;IAClE;EACF;EAGA,IAAIZ,4BAA4BJ,QAAU,EAAA;IACxC;EACF;EAGI,IAAA,CAACI,yBAAyBa,MAAQ,EAAA;IACpC,OAAOV,IAAIW,QAAS,CAAA;MAClBC,IAAA,EAAM,CAAC,yBAAyB,CAAA;MAChCC,MAAMC,YAAa,CAAAC,SAAA;MACnBhB,IAAM,EAAA,QAAA;MACNiB,OAAS,EAAA,CAAA;MACTC,SAAW,EAAA;IAAA,CACZ,CAAA;EACH;EAGA,IAAI,CAACvB,oBAAA,CAAqBwB,IAAK,CAAArB,uBAAuB,CAAG,EAAA;IAChD,OAAAsB,iBAAA,CACLnB,GAAA,EACA,yBAAA,EACAoB,kBAAmB,CAAAC,UAAA,CACrB;EACF;AACF,CAAA;"}
1
+ {"version":3,"file":"stateRegistrationNumberSuperRefinement.mjs","sources":["../../../src/utils/validations/stateRegistrationNumberSuperRefinement.ts"],"sourcesContent":["import { type SuperRefinement, ZodIssueCode } from \"zod\";\n\nimport type { Nullish } from \"../../types\";\nimport { AddressType, AddressUsageType, CountryCode } from \"../../types\";\nimport { assertUnreachable } from \"../errors\";\nimport { addCustomZodIssue, CustomZodIssueCode } from \"../zod\";\n\nexport const EXEMPTED = \"EXEMPTED\";\nconst IS_DIGITS_ONLY_REGEX = /^\\d+$/;\n\nexport const createStateRegistrationNumberSuperRefinement =\n ({\n addressUsageType,\n }: {\n addressUsageType: AddressUsageType;\n }): SuperRefinement<{\n stateRegistrationNumber?: Nullish<string>;\n country: CountryCode;\n type: AddressType;\n }> =>\n ({ stateRegistrationNumber, country, type }, ctx) => {\n switch (addressUsageType) {\n // Exit early because state registration number is generally not needed for billing addresses.\n case AddressUsageType.Billing:\n return;\n // Don't do anything and proceed with the validation logic below.\n case AddressUsageType.ReturnShipping:\n case AddressUsageType.Shipping:\n break;\n default:\n assertUnreachable(addressUsageType);\n }\n\n // Only relevant for Brazil business addresses.\n if (!(country === CountryCode.Br && type === AddressType.Business)) {\n return;\n }\n\n // Exempted state registration numbers are valid.\n if (stateRegistrationNumber === EXEMPTED) {\n return;\n }\n\n // Handle cases when the value is too small.\n if (!stateRegistrationNumber?.length) {\n return ctx.addIssue({\n path: [\"stateRegistrationNumber\"],\n code: ZodIssueCode.too_small,\n type: \"string\",\n minimum: 1,\n inclusive: true,\n });\n }\n\n // It should be only digits.\n if (!IS_DIGITS_ONLY_REGEX.test(stateRegistrationNumber)) {\n return addCustomZodIssue(\n ctx,\n \"stateRegistrationNumber\",\n CustomZodIssueCode.DigitsOnly,\n );\n }\n };\n"],"names":["EXEMPTED","IS_DIGITS_ONLY_REGEX","createStateRegistrationNumberSuperRefinement","addressUsageType","stateRegistrationNumber","country","type","ctx","AddressUsageType","Billing","ReturnShipping","Shipping","assertUnreachable","CountryCode","Br","AddressType","Business","length","addIssue","path","code","ZodIssueCode","too_small","minimum","inclusive","test","addCustomZodIssue","CustomZodIssueCode","DigitsOnly"],"mappings":";;;;;;;AAOO,MAAMA,QAAW,GAAA,UAAA;AACxB,MAAMC,oBAAuB,GAAA,OAAA;AAEtB,MAAMC,+CACXA,CAAC;EACCC;AACF,CAAA,KAOA,CAAC;EAAEC,uBAAA;EAAyBC,OAAS;EAAAC;AAAA,GAAQC,GAAQ,KAAA;EACnD,QAAQJ,gBAAkB;IAAA;IAExB,KAAKK,gBAAiB,CAAAC,OAAA;MACpB;IAAA;IAEF,KAAKD,gBAAiB,CAAAE,cAAA;IACtB,KAAKF,gBAAiB,CAAAG,QAAA;MACpB;IACF;MACEC,iBAAA,CAAkBT,gBAAgB,CAAA;EACtC;EAGA,IAAI,EAAEE,OAAY,KAAAQ,WAAA,CAAYC,EAAM,IAAAR,IAAA,KAASS,YAAYC,QAAW,CAAA,EAAA;IAClE;EACF;EAGA,IAAIZ,4BAA4BJ,QAAU,EAAA;IACxC;EACF;EAGI,IAAA,CAACI,yBAAyBa,MAAQ,EAAA;IACpC,OAAOV,IAAIW,QAAS,CAAA;MAClBC,IAAA,EAAM,CAAC,yBAAyB,CAAA;MAChCC,MAAMC,YAAa,CAAAC,SAAA;MACnBhB,IAAM,EAAA,QAAA;MACNiB,OAAS,EAAA,CAAA;MACTC,SAAW,EAAA;IAAA,CACZ,CAAA;EACH;EAGA,IAAI,CAACvB,oBAAA,CAAqBwB,IAAK,CAAArB,uBAAuB,CAAG,EAAA;IAChD,OAAAsB,iBAAA,CACLnB,GAAA,EACA,yBAAA,EACAoB,kBAAmB,CAAAC,UAAA,CACrB;EACF;AACF,CAAA;"}
@@ -19,8 +19,10 @@ const createTaxIdSuperRefinement = ({
19
19
  taxId
20
20
  }, ctx) => {
21
21
  switch (addressUsageType) {
22
+ // Exit early because tax ID is generally not needed for billing addresses.
22
23
  case constants.AddressUsageType.Billing:
23
24
  return;
25
+ // Don't do anything and proceed with the validation logic below.
24
26
  case constants.AddressUsageType.ReturnShipping:
25
27
  case constants.AddressUsageType.Shipping:
26
28
  break;