@ubnt/store.core 9.2.0-money.3 → 9.2.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 (410) hide show
  1. package/CHANGELOG.md +15 -0
  2. package/lib/assets/efg.jpg +0 -0
  3. package/lib/assets/efg.svg +5 -0
  4. package/lib/assets/efgStacked.svg +3 -0
  5. package/lib/assets/gatewayEnterprise.jpg +0 -0
  6. package/lib/assets/gatewayLite.jpg +0 -0
  7. package/lib/assets/gatewayMax.jpg +0 -0
  8. package/lib/assets/gatewayProfessional.jpg +0 -0
  9. package/lib/assets/minus4.svg +8 -8
  10. package/lib/assets/minus5.svg +8 -8
  11. package/lib/assets/nextAi.svg +11 -0
  12. package/lib/assets/plus5.svg +9 -9
  13. package/lib/assets/plus6.svg +9 -9
  14. package/lib/assets/udmPro.jpg +0 -0
  15. package/lib/assets/udmPro2.jpg +0 -0
  16. package/lib/assets/udmProMax.jpg +0 -0
  17. package/lib/assets/udmProMax2.jpg +0 -0
  18. package/lib/assets/udmProSpecial.jpg +0 -0
  19. package/lib/assets/udmProSpecial2.jpg +0 -0
  20. package/lib/components/Header/ProHeader/ProHeader.styles.js +2 -0
  21. package/lib/components/Header/ProHeader/ProHeader.styles.js.map +1 -1
  22. package/lib/components/Header/ProHeader/ProHeader.styles.mjs +3 -1
  23. package/lib/components/Header/ProHeader/ProHeader.styles.mjs.map +1 -1
  24. package/lib/components/LandingPagePro/LandingPagePro.d.ts +0 -3
  25. package/lib/components/LandingPagePro/LandingPagePro.js +3 -3
  26. package/lib/components/LandingPagePro/LandingPagePro.js.map +1 -1
  27. package/lib/components/LandingPagePro/LandingPagePro.mjs +2 -2
  28. package/lib/components/LandingPagePro/LandingPagePro.mjs.map +1 -1
  29. package/lib/components/MicrositeHero/MicrositeHero.d.ts +1 -1
  30. package/lib/components/MicrositeHero/MicrositeHero.js +8 -2
  31. package/lib/components/MicrositeHero/MicrositeHero.js.map +1 -1
  32. package/lib/components/MicrositeHero/MicrositeHero.mjs +9 -3
  33. package/lib/components/MicrositeHero/MicrositeHero.mjs.map +1 -1
  34. package/lib/components/MicrositeHero/MicrositeHero.styles.d.ts +1 -0
  35. package/lib/components/MicrositeHero/MicrositeHero.styles.js +21 -5
  36. package/lib/components/MicrositeHero/MicrositeHero.styles.js.map +1 -1
  37. package/lib/components/MicrositeHero/MicrositeHero.styles.mjs +21 -6
  38. package/lib/components/MicrositeHero/MicrositeHero.styles.mjs.map +1 -1
  39. package/lib/components/MicrositeHero/MicrositeHero.types.d.ts +2 -0
  40. package/lib/components/MicrositeHero/MicrositeHero.types.js.map +1 -1
  41. package/lib/components/MicrositeHero/MicrositeHero.types.mjs.map +1 -1
  42. package/lib/components/ModelCompareV3/ModelCompareV3.types.d.ts +4 -1
  43. package/lib/components/ModelCompareV3/assets/Consoles/bigCompare/efg.jpg.js +27 -0
  44. package/lib/components/ModelCompareV3/assets/Consoles/bigCompare/efg.jpg.js.map +1 -0
  45. package/lib/components/ModelCompareV3/assets/Consoles/bigCompare/efg.jpg.mjs +3 -0
  46. package/lib/components/ModelCompareV3/assets/Consoles/bigCompare/efg.jpg.mjs.map +1 -0
  47. package/lib/components/ModelCompareV3/assets/Consoles/bigCompare/udmPro.jpg.js +5 -5
  48. package/lib/components/ModelCompareV3/assets/Consoles/bigCompare/udmPro.jpg.mjs +2 -2
  49. package/lib/components/ModelCompareV3/assets/Consoles/bigCompare/udmProMax.jpg.js +5 -5
  50. package/lib/components/ModelCompareV3/assets/Consoles/bigCompare/udmProMax.jpg.mjs +2 -2
  51. package/lib/components/ModelCompareV3/assets/Consoles/bigCompare/udmProSpecial.jpg.js +5 -5
  52. package/lib/components/ModelCompareV3/assets/Consoles/bigCompare/udmProSpecial.jpg.mjs +2 -2
  53. package/lib/components/ModelCompareV3/assets/Consoles/udmPro.jpg.js +1 -1
  54. package/lib/components/ModelCompareV3/assets/Consoles/udmPro.jpg.mjs +2 -2
  55. package/lib/components/ModelCompareV3/assets/Consoles/udmProMax.jpg.js +1 -1
  56. package/lib/components/ModelCompareV3/assets/Consoles/udmProMax.jpg.mjs +2 -2
  57. package/lib/components/ModelCompareV3/assets/Consoles/udmProSpecial.jpg.js +1 -1
  58. package/lib/components/ModelCompareV3/assets/Consoles/udmProSpecial.jpg.mjs +2 -2
  59. package/lib/components/ModelCompareV3/assets/Gateways/gatewayEnterprise.jpg.js +27 -0
  60. package/lib/components/ModelCompareV3/assets/Gateways/gatewayEnterprise.jpg.js.map +1 -0
  61. package/lib/components/ModelCompareV3/assets/Gateways/gatewayEnterprise.jpg.mjs +3 -0
  62. package/lib/components/ModelCompareV3/assets/Gateways/gatewayEnterprise.jpg.mjs.map +1 -0
  63. package/lib/components/ModelCompareV3/assets/nextAi.svg.js +27 -0
  64. package/lib/components/ModelCompareV3/assets/nextAi.svg.js.map +1 -0
  65. package/lib/components/ModelCompareV3/assets/nextAi.svg.mjs +3 -0
  66. package/lib/components/ModelCompareV3/assets/nextAi.svg.mjs.map +1 -0
  67. package/lib/components/ModelCompareV3/data/CloudGateways.js +17 -11
  68. package/lib/components/ModelCompareV3/data/CloudGateways.js.map +1 -1
  69. package/lib/components/ModelCompareV3/data/CloudGateways.mjs +14 -8
  70. package/lib/components/ModelCompareV3/data/CloudGateways.mjs.map +1 -1
  71. package/lib/components/ModelCompareV3/data/Gateway.js +10 -7
  72. package/lib/components/ModelCompareV3/data/Gateway.js.map +1 -1
  73. package/lib/components/ModelCompareV3/data/Gateway.mjs +10 -7
  74. package/lib/components/ModelCompareV3/data/Gateway.mjs.map +1 -1
  75. package/lib/components/ModelCompareV3/data/products/aggregation.js +1 -1
  76. package/lib/components/ModelCompareV3/data/products/aggregation.js.map +1 -1
  77. package/lib/components/ModelCompareV3/data/products/aggregation.mjs +1 -1
  78. package/lib/components/ModelCompareV3/data/products/aggregation.mjs.map +1 -1
  79. package/lib/components/ModelCompareV3/data/products/efg.d.ts +2 -0
  80. package/lib/components/ModelCompareV3/data/products/efg.js +133 -0
  81. package/lib/components/ModelCompareV3/data/products/efg.js.map +1 -0
  82. package/lib/components/ModelCompareV3/data/products/efg.mjs +123 -0
  83. package/lib/components/ModelCompareV3/data/products/efg.mjs.map +1 -0
  84. package/lib/components/ModelCompareV3/data/products/enterprise24PoE.js +1 -1
  85. package/lib/components/ModelCompareV3/data/products/enterprise24PoE.js.map +1 -1
  86. package/lib/components/ModelCompareV3/data/products/enterprise24PoE.mjs +1 -1
  87. package/lib/components/ModelCompareV3/data/products/enterprise24PoE.mjs.map +1 -1
  88. package/lib/components/ModelCompareV3/data/products/enterprise48PoE.js +1 -1
  89. package/lib/components/ModelCompareV3/data/products/enterprise48PoE.js.map +1 -1
  90. package/lib/components/ModelCompareV3/data/products/enterprise48PoE.mjs +1 -1
  91. package/lib/components/ModelCompareV3/data/products/enterprise48PoE.mjs.map +1 -1
  92. package/lib/components/ModelCompareV3/data/products/enterpriseXG24.js +1 -1
  93. package/lib/components/ModelCompareV3/data/products/enterpriseXG24.js.map +1 -1
  94. package/lib/components/ModelCompareV3/data/products/enterpriseXG24.mjs +1 -1
  95. package/lib/components/ModelCompareV3/data/products/enterpriseXG24.mjs.map +1 -1
  96. package/lib/components/ModelCompareV3/data/products/express.js +8 -0
  97. package/lib/components/ModelCompareV3/data/products/express.js.map +1 -1
  98. package/lib/components/ModelCompareV3/data/products/express.mjs +8 -0
  99. package/lib/components/ModelCompareV3/data/products/express.mjs.map +1 -1
  100. package/lib/components/ModelCompareV3/data/products/gatewayEnterprise.d.ts +2 -0
  101. package/lib/components/ModelCompareV3/data/products/gatewayEnterprise.js +87 -0
  102. package/lib/components/ModelCompareV3/data/products/gatewayEnterprise.js.map +1 -0
  103. package/lib/components/ModelCompareV3/data/products/gatewayEnterprise.mjs +79 -0
  104. package/lib/components/ModelCompareV3/data/products/gatewayEnterprise.mjs.map +1 -0
  105. package/lib/components/ModelCompareV3/data/products/gatewayLite.js +8 -7
  106. package/lib/components/ModelCompareV3/data/products/gatewayLite.js.map +1 -1
  107. package/lib/components/ModelCompareV3/data/products/gatewayLite.mjs +8 -7
  108. package/lib/components/ModelCompareV3/data/products/gatewayLite.mjs.map +1 -1
  109. package/lib/components/ModelCompareV3/data/products/gatewayMax.js +5 -5
  110. package/lib/components/ModelCompareV3/data/products/gatewayMax.js.map +1 -1
  111. package/lib/components/ModelCompareV3/data/products/gatewayMax.mjs +5 -5
  112. package/lib/components/ModelCompareV3/data/products/gatewayMax.mjs.map +1 -1
  113. package/lib/components/ModelCompareV3/data/products/gatewayProfessional.js +12 -11
  114. package/lib/components/ModelCompareV3/data/products/gatewayProfessional.js.map +1 -1
  115. package/lib/components/ModelCompareV3/data/products/gatewayProfessional.mjs +12 -11
  116. package/lib/components/ModelCompareV3/data/products/gatewayProfessional.mjs.map +1 -1
  117. package/lib/components/ModelCompareV3/data/products/missionCritical.js +1 -1
  118. package/lib/components/ModelCompareV3/data/products/missionCritical.js.map +1 -1
  119. package/lib/components/ModelCompareV3/data/products/missionCritical.mjs +1 -1
  120. package/lib/components/ModelCompareV3/data/products/missionCritical.mjs.map +1 -1
  121. package/lib/components/ModelCompareV3/data/products/professional24.js +1 -1
  122. package/lib/components/ModelCompareV3/data/products/professional24.js.map +1 -1
  123. package/lib/components/ModelCompareV3/data/products/professional24.mjs +1 -1
  124. package/lib/components/ModelCompareV3/data/products/professional24.mjs.map +1 -1
  125. package/lib/components/ModelCompareV3/data/products/professional24PoE.js +1 -1
  126. package/lib/components/ModelCompareV3/data/products/professional24PoE.js.map +1 -1
  127. package/lib/components/ModelCompareV3/data/products/professional24PoE.mjs +1 -1
  128. package/lib/components/ModelCompareV3/data/products/professional24PoE.mjs.map +1 -1
  129. package/lib/components/ModelCompareV3/data/products/professional48.js +1 -1
  130. package/lib/components/ModelCompareV3/data/products/professional48.js.map +1 -1
  131. package/lib/components/ModelCompareV3/data/products/professional48.mjs +1 -1
  132. package/lib/components/ModelCompareV3/data/products/professional48.mjs.map +1 -1
  133. package/lib/components/ModelCompareV3/data/products/professional48PoE.js +1 -1
  134. package/lib/components/ModelCompareV3/data/products/professional48PoE.js.map +1 -1
  135. package/lib/components/ModelCompareV3/data/products/professional48PoE.mjs +1 -1
  136. package/lib/components/ModelCompareV3/data/products/professional48PoE.mjs.map +1 -1
  137. package/lib/components/ModelCompareV3/data/products/professionalMax24.js +1 -1
  138. package/lib/components/ModelCompareV3/data/products/professionalMax24.js.map +1 -1
  139. package/lib/components/ModelCompareV3/data/products/professionalMax24.mjs +1 -1
  140. package/lib/components/ModelCompareV3/data/products/professionalMax24.mjs.map +1 -1
  141. package/lib/components/ModelCompareV3/data/products/professionalMax24PoE.js +1 -1
  142. package/lib/components/ModelCompareV3/data/products/professionalMax24PoE.js.map +1 -1
  143. package/lib/components/ModelCompareV3/data/products/professionalMax24PoE.mjs +1 -1
  144. package/lib/components/ModelCompareV3/data/products/professionalMax24PoE.mjs.map +1 -1
  145. package/lib/components/ModelCompareV3/data/products/professionalMax48.js +1 -1
  146. package/lib/components/ModelCompareV3/data/products/professionalMax48.js.map +1 -1
  147. package/lib/components/ModelCompareV3/data/products/professionalMax48.mjs +1 -1
  148. package/lib/components/ModelCompareV3/data/products/professionalMax48.mjs.map +1 -1
  149. package/lib/components/ModelCompareV3/data/products/professionalMax48PoE.js +1 -1
  150. package/lib/components/ModelCompareV3/data/products/professionalMax48PoE.js.map +1 -1
  151. package/lib/components/ModelCompareV3/data/products/professionalMax48PoE.mjs +1 -1
  152. package/lib/components/ModelCompareV3/data/products/professionalMax48PoE.mjs.map +1 -1
  153. package/lib/components/ModelCompareV3/data/products/standard16PoE.js +1 -1
  154. package/lib/components/ModelCompareV3/data/products/standard16PoE.js.map +1 -1
  155. package/lib/components/ModelCompareV3/data/products/standard16PoE.mjs +1 -1
  156. package/lib/components/ModelCompareV3/data/products/standard16PoE.mjs.map +1 -1
  157. package/lib/components/ModelCompareV3/data/products/standard24.js +1 -1
  158. package/lib/components/ModelCompareV3/data/products/standard24.js.map +1 -1
  159. package/lib/components/ModelCompareV3/data/products/standard24.mjs +1 -1
  160. package/lib/components/ModelCompareV3/data/products/standard24.mjs.map +1 -1
  161. package/lib/components/ModelCompareV3/data/products/standard24PoE.js +1 -1
  162. package/lib/components/ModelCompareV3/data/products/standard24PoE.js.map +1 -1
  163. package/lib/components/ModelCompareV3/data/products/standard24PoE.mjs +1 -1
  164. package/lib/components/ModelCompareV3/data/products/standard24PoE.mjs.map +1 -1
  165. package/lib/components/ModelCompareV3/data/products/standard48.js +1 -1
  166. package/lib/components/ModelCompareV3/data/products/standard48.js.map +1 -1
  167. package/lib/components/ModelCompareV3/data/products/standard48.mjs +1 -1
  168. package/lib/components/ModelCompareV3/data/products/standard48.mjs.map +1 -1
  169. package/lib/components/ModelCompareV3/data/products/standard48PoE.js +1 -1
  170. package/lib/components/ModelCompareV3/data/products/standard48PoE.js.map +1 -1
  171. package/lib/components/ModelCompareV3/data/products/standard48PoE.mjs +1 -1
  172. package/lib/components/ModelCompareV3/data/products/standard48PoE.mjs.map +1 -1
  173. package/lib/components/ModelCompareV3/data/products/switchesEnterprise.js +1 -1
  174. package/lib/components/ModelCompareV3/data/products/switchesEnterprise.js.map +1 -1
  175. package/lib/components/ModelCompareV3/data/products/switchesEnterprise.mjs +1 -1
  176. package/lib/components/ModelCompareV3/data/products/switchesEnterprise.mjs.map +1 -1
  177. package/lib/components/ModelCompareV3/data/products/switchesProfessional.js +1 -1
  178. package/lib/components/ModelCompareV3/data/products/switchesProfessional.js.map +1 -1
  179. package/lib/components/ModelCompareV3/data/products/switchesProfessional.mjs +1 -1
  180. package/lib/components/ModelCompareV3/data/products/switchesProfessional.mjs.map +1 -1
  181. package/lib/components/ModelCompareV3/data/products/switchesProfessionalMax.js +1 -1
  182. package/lib/components/ModelCompareV3/data/products/switchesProfessionalMax.js.map +1 -1
  183. package/lib/components/ModelCompareV3/data/products/switchesProfessionalMax.mjs +1 -1
  184. package/lib/components/ModelCompareV3/data/products/switchesProfessionalMax.mjs.map +1 -1
  185. package/lib/components/ModelCompareV3/data/products/switchesStandard.js +1 -1
  186. package/lib/components/ModelCompareV3/data/products/switchesStandard.js.map +1 -1
  187. package/lib/components/ModelCompareV3/data/products/switchesStandard.mjs +1 -1
  188. package/lib/components/ModelCompareV3/data/products/switchesStandard.mjs.map +1 -1
  189. package/lib/components/ModelCompareV3/data/products/ucgMax.js +7 -0
  190. package/lib/components/ModelCompareV3/data/products/ucgMax.js.map +1 -1
  191. package/lib/components/ModelCompareV3/data/products/ucgMax.mjs +7 -0
  192. package/lib/components/ModelCompareV3/data/products/ucgMax.mjs.map +1 -1
  193. package/lib/components/ModelCompareV3/data/products/ucgUltra.js +8 -0
  194. package/lib/components/ModelCompareV3/data/products/ucgUltra.js.map +1 -1
  195. package/lib/components/ModelCompareV3/data/products/ucgUltra.mjs +8 -0
  196. package/lib/components/ModelCompareV3/data/products/ucgUltra.mjs.map +1 -1
  197. package/lib/components/ModelCompareV3/data/products/udmPro.js +10 -2
  198. package/lib/components/ModelCompareV3/data/products/udmPro.js.map +1 -1
  199. package/lib/components/ModelCompareV3/data/products/udmPro.mjs +10 -2
  200. package/lib/components/ModelCompareV3/data/products/udmPro.mjs.map +1 -1
  201. package/lib/components/ModelCompareV3/data/products/udmProMax.js +10 -3
  202. package/lib/components/ModelCompareV3/data/products/udmProMax.js.map +1 -1
  203. package/lib/components/ModelCompareV3/data/products/udmProMax.mjs +10 -3
  204. package/lib/components/ModelCompareV3/data/products/udmProMax.mjs.map +1 -1
  205. package/lib/components/ModelCompareV3/data/products/udmProSpecial.js +10 -2
  206. package/lib/components/ModelCompareV3/data/products/udmProSpecial.js.map +1 -1
  207. package/lib/components/ModelCompareV3/data/products/udmProSpecial.mjs +10 -2
  208. package/lib/components/ModelCompareV3/data/products/udmProSpecial.mjs.map +1 -1
  209. package/lib/components/ModelCompareV3/data/products/udr.js +8 -0
  210. package/lib/components/ModelCompareV3/data/products/udr.js.map +1 -1
  211. package/lib/components/ModelCompareV3/data/products/udr.mjs +8 -0
  212. package/lib/components/ModelCompareV3/data/products/udr.mjs.map +1 -1
  213. package/lib/components/ModelCompareV3/data/products/udw.js +8 -0
  214. package/lib/components/ModelCompareV3/data/products/udw.js.map +1 -1
  215. package/lib/components/ModelCompareV3/data/products/udw.mjs +8 -0
  216. package/lib/components/ModelCompareV3/data/products/udw.mjs.map +1 -1
  217. package/lib/components/ModelCompareV3/data/properties/index.d.ts +2 -0
  218. package/lib/components/ModelCompareV3/data/properties/index.js +4 -0
  219. package/lib/components/ModelCompareV3/data/properties/index.js.map +1 -1
  220. package/lib/components/ModelCompareV3/data/properties/index.mjs +2 -0
  221. package/lib/components/ModelCompareV3/data/properties/index.mjs.map +1 -1
  222. package/lib/components/ModelCompareV3/data/properties/nextAiInspection.d.ts +2 -0
  223. package/lib/components/ModelCompareV3/data/properties/nextAiInspection.js +19 -0
  224. package/lib/components/ModelCompareV3/data/properties/nextAiInspection.js.map +1 -0
  225. package/lib/components/ModelCompareV3/data/properties/nextAiInspection.mjs +11 -0
  226. package/lib/components/ModelCompareV3/data/properties/nextAiInspection.mjs.map +1 -0
  227. package/lib/components/ModelCompareV3/translations/en.json.js +21 -36
  228. package/lib/components/ModelCompareV3/translations/en.json.js.map +1 -1
  229. package/lib/components/ModelCompareV3/translations/en.json.mjs +21 -36
  230. package/lib/components/ModelCompareV3/translations/en.json.mjs.map +1 -1
  231. package/lib/components/ModelCompareV3/translations/useModelCompareTranslation.d.ts +2 -2
  232. package/lib/components/ResourceCalculatorV1/ComputeResourceCalculator/components/InputCard/InputSections/CounterSection.js +2 -2
  233. package/lib/components/ResourceCalculatorV1/ComputeResourceCalculator/components/InputCard/InputSections/CounterSection.mjs +2 -2
  234. package/lib/components/ResourceCalculatorV1/ComputeResourceCalculator/components/InputCard/assets/minus.svg.js +1 -1
  235. package/lib/components/ResourceCalculatorV1/ComputeResourceCalculator/components/InputCard/assets/minus.svg.mjs +2 -2
  236. package/lib/components/ResourceCalculatorV1/ComputeResourceCalculator/components/InputCard/assets/plus.svg.js +1 -1
  237. package/lib/components/ResourceCalculatorV1/ComputeResourceCalculator/components/InputCard/assets/plus.svg.mjs +2 -2
  238. package/lib/components/ResourceCalculatorV1/PoeCalculator/components/PoeConsumerConfigurator/PoeConsumerSelectModal/PoeConsumerSelectModal.js +2 -2
  239. package/lib/components/ResourceCalculatorV1/PoeCalculator/components/PoeConsumerConfigurator/PoeConsumerSelectModal/PoeConsumerSelectModal.mjs +2 -2
  240. package/lib/components/ResourceCalculatorV1/PoeCalculator/components/PoeConsumerConfigurator/assets/minus.svg.js +1 -1
  241. package/lib/components/ResourceCalculatorV1/PoeCalculator/components/PoeConsumerConfigurator/assets/minus.svg.mjs +2 -2
  242. package/lib/components/ResourceCalculatorV1/PoeCalculator/components/PoeConsumerConfigurator/assets/plus.svg.js +1 -1
  243. package/lib/components/ResourceCalculatorV1/PoeCalculator/components/PoeConsumerConfigurator/assets/plus.svg.mjs +2 -2
  244. package/lib/constants/icons/menu/efg.svg.js +27 -0
  245. package/lib/constants/icons/menu/efg.svg.js.map +1 -0
  246. package/lib/constants/icons/menu/efg.svg.mjs +3 -0
  247. package/lib/constants/icons/menu/efg.svg.mjs.map +1 -0
  248. package/lib/constants/icons/menu/efgStacked.svg.js +27 -0
  249. package/lib/constants/icons/menu/efgStacked.svg.js.map +1 -0
  250. package/lib/constants/icons/menu/efgStacked.svg.mjs +3 -0
  251. package/lib/constants/icons/menu/efgStacked.svg.mjs.map +1 -0
  252. package/lib/constants/icons/menu/index.d.ts +2 -0
  253. package/lib/constants/icons/menu/index.js +18 -0
  254. package/lib/constants/icons/menu/index.js.map +1 -1
  255. package/lib/constants/icons/menu/index.mjs +4 -0
  256. package/lib/constants/icons/menu/index.mjs.map +1 -1
  257. package/lib/constants/icons/options/colors/black.svg.js +5 -5
  258. package/lib/constants/icons/options/colors/index.js +3 -3
  259. package/lib/constants/icons/options/styles/black.svg.js +5 -5
  260. package/lib/constants/icons/options/styles/index.js +3 -3
  261. package/lib/constants/optionIcons.js +6 -6
  262. package/lib/constants/optionIcons.mjs +4 -4
  263. package/lib/constants/proStoreCategories/mapping/index.d.ts +13 -12
  264. package/lib/constants/proStoreCategories/mapping/index.js +5 -0
  265. package/lib/constants/proStoreCategories/mapping/index.js.map +1 -1
  266. package/lib/constants/proStoreCategories/mapping/index.mjs +5 -0
  267. package/lib/constants/proStoreCategories/mapping/index.mjs.map +1 -1
  268. package/lib/constants/proStoreCategories/mapping/unifi.d.ts +1 -0
  269. package/lib/constants/proStoreCategories/mapping/unifi.js +1 -0
  270. package/lib/constants/proStoreCategories/mapping/unifi.js.map +1 -1
  271. package/lib/constants/proStoreCategories/mapping/unifi.mjs +1 -0
  272. package/lib/constants/proStoreCategories/mapping/unifi.mjs.map +1 -1
  273. package/lib/constants/proStoreCategories/translations/ar.json.js +29 -24
  274. package/lib/constants/proStoreCategories/translations/ar.json.js.map +1 -1
  275. package/lib/constants/proStoreCategories/translations/ar.json.mjs +29 -25
  276. package/lib/constants/proStoreCategories/translations/ar.json.mjs.map +1 -1
  277. package/lib/constants/proStoreCategories/translations/de.json.js +29 -24
  278. package/lib/constants/proStoreCategories/translations/de.json.js.map +1 -1
  279. package/lib/constants/proStoreCategories/translations/de.json.mjs +29 -25
  280. package/lib/constants/proStoreCategories/translations/de.json.mjs.map +1 -1
  281. package/lib/constants/proStoreCategories/translations/el.json.js +29 -24
  282. package/lib/constants/proStoreCategories/translations/el.json.js.map +1 -1
  283. package/lib/constants/proStoreCategories/translations/el.json.mjs +29 -25
  284. package/lib/constants/proStoreCategories/translations/el.json.mjs.map +1 -1
  285. package/lib/constants/proStoreCategories/translations/en.json.js +20 -19
  286. package/lib/constants/proStoreCategories/translations/en.json.js.map +1 -1
  287. package/lib/constants/proStoreCategories/translations/en.json.mjs +20 -19
  288. package/lib/constants/proStoreCategories/translations/en.json.mjs.map +1 -1
  289. package/lib/constants/proStoreCategories/translations/es.json.js +29 -24
  290. package/lib/constants/proStoreCategories/translations/es.json.js.map +1 -1
  291. package/lib/constants/proStoreCategories/translations/es.json.mjs +29 -25
  292. package/lib/constants/proStoreCategories/translations/es.json.mjs.map +1 -1
  293. package/lib/constants/proStoreCategories/translations/fr.json.js +29 -24
  294. package/lib/constants/proStoreCategories/translations/fr.json.js.map +1 -1
  295. package/lib/constants/proStoreCategories/translations/fr.json.mjs +29 -25
  296. package/lib/constants/proStoreCategories/translations/fr.json.mjs.map +1 -1
  297. package/lib/constants/proStoreCategories/translations/it.json.js +29 -24
  298. package/lib/constants/proStoreCategories/translations/it.json.js.map +1 -1
  299. package/lib/constants/proStoreCategories/translations/it.json.mjs +29 -25
  300. package/lib/constants/proStoreCategories/translations/it.json.mjs.map +1 -1
  301. package/lib/constants/proStoreCategories/translations/ja.json.js +29 -24
  302. package/lib/constants/proStoreCategories/translations/ja.json.js.map +1 -1
  303. package/lib/constants/proStoreCategories/translations/ja.json.mjs +29 -25
  304. package/lib/constants/proStoreCategories/translations/ja.json.mjs.map +1 -1
  305. package/lib/constants/proStoreCategories/translations/pt-BR.json.js +29 -24
  306. package/lib/constants/proStoreCategories/translations/pt-BR.json.js.map +1 -1
  307. package/lib/constants/proStoreCategories/translations/pt-BR.json.mjs +29 -25
  308. package/lib/constants/proStoreCategories/translations/pt-BR.json.mjs.map +1 -1
  309. package/lib/constants/proStoreCategories/translations/zh-Hans.json.js +29 -24
  310. package/lib/constants/proStoreCategories/translations/zh-Hans.json.js.map +1 -1
  311. package/lib/constants/proStoreCategories/translations/zh-Hans.json.mjs +29 -25
  312. package/lib/constants/proStoreCategories/translations/zh-Hans.json.mjs.map +1 -1
  313. package/lib/constants/proStoreCategories/translations/zh-Hant-TW.json.js +29 -24
  314. package/lib/constants/proStoreCategories/translations/zh-Hant-TW.json.js.map +1 -1
  315. package/lib/constants/proStoreCategories/translations/zh-Hant-TW.json.mjs +29 -25
  316. package/lib/constants/proStoreCategories/translations/zh-Hant-TW.json.mjs.map +1 -1
  317. package/lib/contexts/MenuContext/mapping.js +14 -0
  318. package/lib/contexts/MenuContext/mapping.js.map +1 -1
  319. package/lib/contexts/MenuContext/mapping.mjs +13 -0
  320. package/lib/contexts/MenuContext/mapping.mjs.map +1 -1
  321. package/lib/types/constants.d.ts +5 -1
  322. package/lib/types/constants.js +1 -0
  323. package/lib/types/constants.js.map +1 -1
  324. package/lib/types/constants.mjs +1 -0
  325. package/lib/types/constants.mjs.map +1 -1
  326. package/lib/utils/address.d.ts +2 -2
  327. package/lib/utils/address.js +8 -5
  328. package/lib/utils/address.js.map +1 -1
  329. package/lib/utils/address.mjs +8 -5
  330. package/lib/utils/address.mjs.map +1 -1
  331. package/lib/utils/money/constants.d.ts +25 -56
  332. package/lib/utils/money/constants.js +7 -68
  333. package/lib/utils/money/constants.js.map +1 -1
  334. package/lib/utils/money/constants.mjs +7 -66
  335. package/lib/utils/money/constants.mjs.map +1 -1
  336. package/lib/utils/money/format.d.ts +5 -10
  337. package/lib/utils/money/format.js +14 -22
  338. package/lib/utils/money/format.js.map +1 -1
  339. package/lib/utils/money/format.mjs +16 -23
  340. package/lib/utils/money/format.mjs.map +1 -1
  341. package/lib/utils/money/index.d.ts +1 -5
  342. package/lib/utils/money/index.js +8 -27
  343. package/lib/utils/money/index.js.map +1 -1
  344. package/lib/utils/money/index.mjs +4 -9
  345. package/lib/utils/money/index.mjs.map +1 -1
  346. package/lib/utils/money/misc.d.ts +28 -68
  347. package/lib/utils/money/misc.js +64 -35
  348. package/lib/utils/money/misc.js.map +1 -1
  349. package/lib/utils/money/misc.mjs +43 -32
  350. package/lib/utils/money/misc.mjs.map +1 -1
  351. package/lib/utils/money/tax.d.ts +2 -38
  352. package/lib/utils/money/tax.js +10 -46
  353. package/lib/utils/money/tax.js.map +1 -1
  354. package/lib/utils/money/tax.mjs +11 -42
  355. package/lib/utils/money/tax.mjs.map +1 -1
  356. package/lib/utils/money/types.d.ts +3 -64
  357. package/lib/utils/number.d.ts +1 -1
  358. package/lib/utils/number.js +1 -1
  359. package/lib/utils/number.js.map +1 -1
  360. package/lib/utils/number.mjs +1 -1
  361. package/lib/utils/number.mjs.map +1 -1
  362. package/lib/utils/validations/stateRegistrationNumberSuperRefinement.js +1 -0
  363. package/lib/utils/validations/stateRegistrationNumberSuperRefinement.js.map +1 -1
  364. package/lib/utils/validations/stateRegistrationNumberSuperRefinement.mjs +1 -0
  365. package/lib/utils/validations/stateRegistrationNumberSuperRefinement.mjs.map +1 -1
  366. package/lib/utils/validations/taxIdSuperRefinement.js +1 -0
  367. package/lib/utils/validations/taxIdSuperRefinement.js.map +1 -1
  368. package/lib/utils/validations/taxIdSuperRefinement.mjs +1 -0
  369. package/lib/utils/validations/taxIdSuperRefinement.mjs.map +1 -1
  370. package/lib/utils/validations.d.ts +15 -0
  371. package/lib/utils/validations.js +23 -0
  372. package/lib/utils/validations.js.map +1 -0
  373. package/lib/utils/validations.mjs +21 -0
  374. package/lib/utils/validations.mjs.map +1 -0
  375. package/package.json +1 -1
  376. package/lib/utils/money/allocators/fixedAmount.d.ts +0 -26
  377. package/lib/utils/money/allocators/fixedAmount.js +0 -55
  378. package/lib/utils/money/allocators/fixedAmount.js.map +0 -1
  379. package/lib/utils/money/allocators/fixedAmount.mjs +0 -53
  380. package/lib/utils/money/allocators/fixedAmount.mjs.map +0 -1
  381. package/lib/utils/money/allocators/index.d.ts +0 -1
  382. package/lib/utils/money/allocators/index.js +0 -6
  383. package/lib/utils/money/allocators/index.js.map +0 -1
  384. package/lib/utils/money/allocators/index.mjs +0 -3
  385. package/lib/utils/money/allocators/index.mjs.map +0 -1
  386. package/lib/utils/money/dinero.d.ts +0 -5
  387. package/lib/utils/money/dinero.js +0 -101
  388. package/lib/utils/money/dinero.js.map +0 -1
  389. package/lib/utils/money/dinero.mjs +0 -3
  390. package/lib/utils/money/dinero.mjs.map +0 -1
  391. package/lib/utils/money/exchangeRate.d.ts +0 -30
  392. package/lib/utils/money/exchangeRate.js +0 -27
  393. package/lib/utils/money/exchangeRate.js.map +0 -1
  394. package/lib/utils/money/exchangeRate.mjs +0 -23
  395. package/lib/utils/money/exchangeRate.mjs.map +0 -1
  396. package/lib/utils/money/misc.private.d.ts +0 -23
  397. package/lib/utils/money/misc.private.js +0 -46
  398. package/lib/utils/money/misc.private.js.map +0 -1
  399. package/lib/utils/money/misc.private.mjs +0 -21
  400. package/lib/utils/money/misc.private.mjs.map +0 -1
  401. package/lib/utils/money/shipping.d.ts +0 -5
  402. package/lib/utils/money/shipping.js +0 -8
  403. package/lib/utils/money/shipping.js.map +0 -1
  404. package/lib/utils/money/shipping.mjs +0 -6
  405. package/lib/utils/money/shipping.mjs.map +0 -1
  406. package/lib/utils/money/tax.private.d.ts +0 -17
  407. package/lib/utils/money/tax.private.js +0 -65
  408. package/lib/utils/money/tax.private.js.map +0 -1
  409. package/lib/utils/money/tax.private.mjs +0 -60
  410. package/lib/utils/money/tax.private.mjs.map +0 -1
@@ -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,CAA2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IAAM,EAAAjB,wBAAA,CAAyBC,UAAU,IAAI,CAAA;AAM/C,MAAAkB,qBAAA,GAAyBC,KAA4B,IAAA;EAC1D,MAAAC,OAAA,GAAUD,MAAME,MAAO,CAAA,CAACC,KAAKN,IAAS,KAAAM,GAAA,GAAMN,MAAM,CAAC,CAAA;EACzD,MAAMO,MAAS,GAAAN,WAAA,CAAYG,OAAS,EAAArB,wBAAA,CAAyBC,UAAU,IAAI,CAAA;EACpEwB,MAAA,CAAAD,MAAA,IAAU,GAAG,2BAA2B,CAAA;EACxCC,MAAA,CAAAD,MAAA,GAAS,GAAG,8BAA8B,CAAA;EAC1C,OAAAA,MAAA;AACT,CAAA;"}
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,71 +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
- * (itemPrice * quantity) - discountAmount
52
- */
53
- taxableAmount: Cents;
54
- /**
55
- * Total discount amount (only) applied for the given item quantity.
56
- * No taxes are included. Calculated by `total_raw_price * <discount-allocation-percentage>`
57
- */
58
- discountAmount: Cents;
59
- currency: Currency;
60
- /**
61
- * Item quantity that is always bigger than zero!
62
- */
63
- quantity: number;
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
- }
@@ -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,CAAYC,IAAc,EAAAC,KAAA,EAAeC,QAAoB,EAAA;EAE3EJ,OAAA,CAAQE,MAAM,MAAM,CAAA;EAEd,MAAAG,SAAA,GAAYH,IAAK,CAA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A,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,EACTC,aAA4CC,SACnB,EAAA;EACzB,IAAI,OAAOH,KAAU,KAAA,QAAA,IAAYI,MAAO,CAAAC,KAAA,CAAML,KAAK,CAAG,EAAA;IAEpD,MA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AZ,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,CAAAC,KAAA,EACAC,MAAS,GAAA,OAAA,EACTC,aAA4CC,SACnB,EAAA;EACzB,IAAI,OAAOH,KAAU,KAAA,QAAA,IAAYI,MAAO,CAAAC,KAA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E5C,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,IAAIE,UAAW,CAAA,GAAGD,MAAM,4BAA4BD,KAAO,EAAA,CAAA;EACnE;AACF;AAWO,SAASO,KACdA,CAAAP,KAAA,EACAC,MAAS,GAAA,OAAA,E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6 +19,7 @@ const createStateRegistrationNumberSuperRefinement = ({
19
19
  switch (addressUsageType) {
20
20
  case constants.AddressUsageType.Billing:
21
21
  return;
22
+ case constants.AddressUsageType.ReturnShipping:
22
23
  case constants.AddressUsageType.Shipping:
23
24
  break;
24
25
  default:
@@ -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.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","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,SAAiB,CAAAA,gBAAA,CAAAE,QAAA;MACpB;IACF;MACEC,MAAA,CAAAA,iBAAA,CAAkBR,gBAAgB,CAAA;EACtC;EAGA,IAAI,EAAEE,OAAY,KAAAO,qBAAA,CAAYC,EAAM,IAAAP,IAAA,KAASQ,SAAAA,CAAAA,YAAYC,QAAW,CAAA,EAAA;IAClE;EACF;EAGA,IAAIX,4BAA4BJ,QAAU,EAAA;IACxC;EACF;EAGI,IAAA,CAACI,yBAAyBY,MAAQ,EAAA;IACpC,OAAOT,IAAIU,QAAS,CAAA;MAClBC,IAAA,EAAM,CAAC,yBAAyB,CAAA;MAChCC,MAAMC,GAAa,CAAAA,YAAA,CAAAC,SAAA;MACnBf,IAAM,EAAA,QAAA;MACNgB,OAAS,EAAA,CAAA;MACTC,SAAW,EAAA;IAAA,CACZ,CAAA;EACH;EAGA,IAAI,CAACtB,oBAAA,CAAqBuB,IAAK,CAAApB,uBAAuB,CAAG,EAAA;IAChD,OAAAqB,KAAA,CAAAA,iBAAA,CACLlB,GAAA,EACA,yBAAA,EACAmB,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;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;;"}
@@ -17,6 +17,7 @@ const createStateRegistrationNumberSuperRefinement = ({
17
17
  switch (addressUsageType) {
18
18
  case AddressUsageType.Billing:
19
19
  return;
20
+ case AddressUsageType.ReturnShipping:
20
21
  case AddressUsageType.Shipping:
21
22
  break;
22
23
  default:
@@ -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.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","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,QAAA;MACpB;IACF;MACEC,iBAAA,CAAkBR,gBAAgB,CAAA;EACtC;EAGA,IAAI,EAAEE,OAAY,KAAAO,WAAA,CAAYC,EAAM,IAAAP,IAAA,KAASQ,YAAYC,QAAW,CAAA,EAAA;IAClE;EACF;EAGA,IAAIX,4BAA4BJ,QAAU,EAAA;IACxC;EACF;EAGI,IAAA,CAACI,yBAAyBY,MAAQ,EAAA;IACpC,OAAOT,IAAIU,QAAS,CAAA;MAClBC,IAAA,EAAM,CAAC,yBAAyB,CAAA;MAChCC,MAAMC,YAAa,CAAAC,SAAA;MACnBf,IAAM,EAAA,QAAA;MACNgB,OAAS,EAAA,CAAA;MACTC,SAAW,EAAA;IAAA,CACZ,CAAA;EACH;EAGA,IAAI,CAACtB,oBAAA,CAAqBuB,IAAK,CAAApB,uBAAuB,CAAG,EAAA;IAChD,OAAAqB,iBAAA,CACLlB,GAAA,EACA,yBAAA,EACAmB,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;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;"}
@@ -21,6 +21,7 @@ const createTaxIdSuperRefinement = ({
21
21
  switch (addressUsageType) {
22
22
  case constants.AddressUsageType.Billing:
23
23
  return;
24
+ case constants.AddressUsageType.ReturnShipping:
24
25
  case constants.AddressUsageType.Shipping:
25
26
  break;
26
27
  default:
@@ -1 +1 @@
1
- {"version":3,"file":"taxIdSuperRefinement.js","sources":["../../../src/utils/validations/taxIdSuperRefinement.ts"],"sourcesContent":["import type { SuperRefinement } from \"zod\";\nimport { ZodIssueCode } from \"zod\";\n\nimport type { AddressType, CountryCode, Nullish } from \"../../types\";\nimport { AddressUsageType, ValidateTaxStatus } from \"../../types\";\nimport { assertUnreachable, checkUnreachable } from \"../errors\";\nimport {\n getTaxCountry,\n getTaxLabelTypeByCountry,\n getValidationMappingByType,\n hasTaxNumberPatternValidation,\n isValidTaxNumberPattern,\n} from \"../tax\";\nimport { TaxLabelType } from \"../tax/types\";\nimport { addCustomZodIssue, CustomZodIssueCode } from \"../zod\";\n\nexport type ValidateTaxIdExternally = (opts: {\n type: AddressType;\n countryCode: CountryCode;\n province: Nullish<string>;\n taxId: string;\n}) => Promise<Nullish<ValidateTaxStatus>>;\n\nexport const createTaxIdSuperRefinement =\n ({\n addressUsageType,\n validateTaxIdExternally,\n }: {\n addressUsageType: AddressUsageType;\n validateTaxIdExternally?: ValidateTaxIdExternally;\n }): SuperRefinement<{\n type: AddressType;\n country: CountryCode;\n province?: Nullish<string>;\n taxId?: Nullish<string>;\n }> =>\n async ({ type, country, province, taxId }, ctx) => {\n switch (addressUsageType) {\n // Exit early because tax ID 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.Shipping:\n break;\n default:\n assertUnreachable(addressUsageType);\n }\n\n const taxCountryCode = getTaxCountry({\n country,\n province,\n });\n\n // Doesn't require strict validation\n if (!hasTaxNumberPatternValidation(type, taxCountryCode)) {\n return;\n }\n\n const mapping = getValidationMappingByType(type);\n const { isOptional } = mapping[taxCountryCode];\n\n if (!taxId && isOptional) {\n return;\n }\n\n // Ensure that we have tax ID before passing it to the validation\n if (!taxId) {\n return ctx.addIssue({\n path: [\"taxId\"],\n code: ZodIssueCode.too_small,\n type: \"string\",\n minimum: 1,\n inclusive: true,\n });\n }\n\n const taxLabelType = getTaxLabelTypeByCountry(country, {\n type: \"specific\",\n addressType: type,\n });\n const shouldUppercaseTaxLabel = [\n TaxLabelType.Gst,\n TaxLabelType.Vat,\n TaxLabelType.Cpf,\n TaxLabelType.Cnpj,\n ].includes(taxLabelType);\n const label = shouldUppercaseTaxLabel\n ? taxLabelType.toUpperCase()\n : taxLabelType;\n\n // If the pattern is invalid, error\n if (!isValidTaxNumberPattern(type, taxCountryCode, taxId)) {\n return addCustomZodIssue(ctx, \"taxId\", CustomZodIssueCode.TaxFormat, {\n label,\n });\n }\n\n if (!validateTaxIdExternally) {\n return;\n }\n\n // Additionally validate tax id externally depending on environment\n const taxStatus = await validateTaxIdExternally({\n type,\n countryCode: country,\n province,\n taxId,\n });\n\n switch (taxStatus) {\n case ValidateTaxStatus.Invalid: {\n addCustomZodIssue(ctx, \"taxId\", CustomZodIssueCode.TaxInvalid, {\n label,\n });\n break;\n }\n\n case ValidateTaxStatus.Unavailable: {\n addCustomZodIssue(ctx, \"taxId\", CustomZodIssueCode.TaxUnavailable, {\n label,\n });\n break;\n }\n\n case ValidateTaxStatus.Valid:\n case ValidateTaxStatus.NotValidated:\n case null:\n case undefined: {\n // Do nothing;\n break;\n }\n\n default: {\n // Do nothing as well (but in a type safe way)\n checkUnreachable(taxStatus);\n }\n }\n };\n"],"names":["createTaxIdSuperRefinement","addressUsageType","validateTaxIdExternally","type","country","province","taxId","ctx","AddressUsageType","Billing","Shipping","assertUnreachable","taxCountryCode","getTaxCountry","hasTaxNumberPatternValidation","mapping","getValidationMappingByType","isOptional","addIssue","path","code","ZodIssueCode","too_small","minimum","inclusive","taxLabelType","getTaxLabelTypeByCountry","addressType","shouldUppercaseTaxLabel","TaxLabelType","Gst","Vat","Cpf","Cnpj","includes","label","toUpperCase","isValidTaxNumberPattern","addCustomZodIssue","CustomZodIssueCode","TaxFormat","taxStatus","countryCode","ValidateTaxStatus","Invalid","TaxInvalid","Unavailable","TaxUnavailable","Valid","NotValidated","checkUnreachable"],"mappings":";;;;;;;;;;;AAuBO,MAAMA,6BACXA,CAAC;EACCC,gBAAA;EACAC;AACF,CAAA,KASA,OAAO;EAAEC,IAAA;EAAMC;EAASC,QAAU;EAAAC;GAASC,GAAQ,KA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C,IAAM,EAAAS,cAAA,EAAgBN,KAAK,CAAG,EAAA;IACzD,OAAOgC,KAAkB,CAAAA,iBAAA,CAAA/B,GAAA,EAAK,OAAS,EAAAgC,KAAAA,CAAAA,kBAAA,CAAmBC,SAAW,EAAA;MACnEL;IAAA,CACD,CAAA;EACH;EAEA,IAAI,CAACjC,uBAAyB,EAAA;IAC5B;EACF;EAGM,MAAAuC,SAAA,GAAY,MAAMvC,uBAAwB,CAAA;IAC9CC,IAAA;IACAuC,WAAa,EAAAtC,OAAA;IACbC,QAAA;IACAC;EAAA,CACD,CAAA;EAED,QAAQmC,SAAW;IACjB,KAAKE,SAAAA,CAAAA,kBAAkBC,OAAS;MAAA;QACZN,KAAAA,CAAAA,iBAAA,CAAA/B,GAAA,EAAK,OAAS,EAAAgC,KAAAA,CAAAA,kBAAA,CAAmBM,UAAY,EAAA;UAC7DV;QAAA,CACD,CAAA;QACD;MACF;IAEA,KAAKQ,SAAAA,CAAAA,kBAAkBG,WAAa;MAAA;QAChBR,KAAAA,CAAAA,iBAAA,CAAA/B,GAAA,EAAK,OAAS,EAAAgC,KAAAA,CAAAA,kBAAA,CAAmBQ,cAAgB,EAAA;UACjEZ;QAAA,CACD,CAAA;QACD;MACF;IAEA,KAAKQ,SAAAA,CAAAA,iBAAkB,CAAAK,KAAA;IACvB,KAAKL,SAAAA,CAAAA,iBAAkB,CAAAM,YAAA;IACvB,KAAK,IAAA;IACL,KAAK,KAAW,CAAA;MAAA;QAEd;MACF;IAEA;MAAS;QAEPC,MAAA,CAAAA,gBAAA,CAAiBT,SAAS,CAAA;MAC5B;EACF;AACF,CAAA;"}
1
+ {"version":3,"file":"taxIdSuperRefinement.js","sources":["../../../src/utils/validations/taxIdSuperRefinement.ts"],"sourcesContent":["import type { SuperRefinement } from \"zod\";\nimport { ZodIssueCode } from \"zod\";\n\nimport type { AddressType, CountryCode, Nullish } from \"../../types\";\nimport { AddressUsageType, ValidateTaxStatus } from \"../../types\";\nimport { assertUnreachable, checkUnreachable } from \"../errors\";\nimport {\n getTaxCountry,\n getTaxLabelTypeByCountry,\n getValidationMappingByType,\n hasTaxNumberPatternValidation,\n isValidTaxNumberPattern,\n} from \"../tax\";\nimport { TaxLabelType } from \"../tax/types\";\nimport { addCustomZodIssue, CustomZodIssueCode } from \"../zod\";\n\nexport type ValidateTaxIdExternally = (opts: {\n type: AddressType;\n countryCode: CountryCode;\n province: Nullish<string>;\n taxId: string;\n}) => Promise<Nullish<ValidateTaxStatus>>;\n\nexport const createTaxIdSuperRefinement =\n ({\n addressUsageType,\n validateTaxIdExternally,\n }: {\n addressUsageType: AddressUsageType;\n validateTaxIdExternally?: ValidateTaxIdExternally;\n }): SuperRefinement<{\n type: AddressType;\n country: CountryCode;\n province?: Nullish<string>;\n taxId?: Nullish<string>;\n }> =>\n async ({ type, country, province, taxId }, ctx) => {\n switch (addressUsageType) {\n // Exit early because tax ID 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 const taxCountryCode = getTaxCountry({\n country,\n province,\n });\n\n // Doesn't require strict validation\n if (!hasTaxNumberPatternValidation(type, taxCountryCode)) {\n return;\n }\n\n const mapping = getValidationMappingByType(type);\n const { isOptional } = mapping[taxCountryCode];\n\n if (!taxId && isOptional) {\n return;\n }\n\n // Ensure that we have tax ID before passing it to the validation\n if (!taxId) {\n return ctx.addIssue({\n path: [\"taxId\"],\n code: ZodIssueCode.too_small,\n type: \"string\",\n minimum: 1,\n inclusive: true,\n });\n }\n\n const taxLabelType = getTaxLabelTypeByCountry(country, {\n type: \"specific\",\n addressType: type,\n });\n const shouldUppercaseTaxLabel = [\n TaxLabelType.Gst,\n TaxLabelType.Vat,\n TaxLabelType.Cpf,\n TaxLabelType.Cnpj,\n ].includes(taxLabelType);\n const label = shouldUppercaseTaxLabel\n ? taxLabelType.toUpperCase()\n : taxLabelType;\n\n // If the pattern is invalid, error\n if (!isValidTaxNumberPattern(type, taxCountryCode, taxId)) {\n return addCustomZodIssue(ctx, \"taxId\", CustomZodIssueCode.TaxFormat, {\n label,\n });\n }\n\n if (!validateTaxIdExternally) {\n return;\n }\n\n // Additionally validate tax id externally depending on environment\n const taxStatus = await validateTaxIdExternally({\n type,\n countryCode: country,\n province,\n taxId,\n });\n\n switch (taxStatus) {\n case ValidateTaxStatus.Invalid: {\n addCustomZodIssue(ctx, \"taxId\", CustomZodIssueCode.TaxInvalid, {\n label,\n });\n break;\n }\n\n case ValidateTaxStatus.Unavailable: {\n addCustomZodIssue(ctx, \"taxId\", CustomZodIssueCode.TaxUnavailable, {\n label,\n });\n break;\n }\n\n case ValidateTaxStatus.Valid:\n case ValidateTaxStatus.NotValidated:\n case null:\n case undefined: {\n // Do nothing;\n break;\n }\n\n default: {\n // Do nothing as well (but in a type safe way)\n checkUnreachable(taxStatus);\n }\n }\n };\n"],"names":["createTaxIdSuperRefinement","addressUsageType","validateTaxIdExternally","type","country","province","taxId","ctx","AddressUsageType","Billing","ReturnShipping","Shipping","assertUnreachable","taxCountryCode","getTaxCountry","hasTaxNumberPatternValidation","mapping","getValidationMappingByType","isOptional","addIssue","path","code","ZodIssueCode","too_small","minimum","inclusive","taxLabelType","getTaxLabelTypeByCountry","addressType","shouldUppercaseTaxLabel","TaxLabelType","Gst","Vat","Cpf","Cnpj","includes","label","toUpperCase","isValidTaxNumberPattern","addCustomZodIssue","CustomZodIssueCode","TaxFormat","taxStatus","countryCode","ValidateTaxStatus","Invalid","TaxInvalid","Unavailable","TaxUnavailable","Valid","NotValidated","checkUnreachable"],"mappings":";;;;;;;;;;;AAuBO,MAAMA,6BACXA,CAAC;EACCC,gBAAA;EACAC;AACF,CAAA,KASA,OAAO;EAAEC,IAAA;EAAMC;EAASC,QAAU;EAAAC;GAASC,GAAQ,KAAA;EACjD,QAAQN,gBAAkB;IAExB,KAAKO,SAAiB,CAAAA,gBAAA,CA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AAU,cAAA,EAAgBP,KAAK,CAAG,EAAA;IACzD,OAAOiC,KAAkB,CAAAA,iBAAA,CAAAhC,GAAA,EAAK,OAAS,EAAAiC,KAAAA,CAAAA,kBAAA,CAAmBC,SAAW,EAAA;MACnEL;IAAA,CACD,CAAA;EACH;EAEA,IAAI,CAAClC,uBAAyB,EAAA;IAC5B;EACF;EAGM,MAAAwC,SAAA,GAAY,MAAMxC,uBAAwB,CAAA;IAC9CC,IAAA;IACAwC,WAAa,EAAAvC,OAAA;IACbC,QAAA;IACAC;EAAA,CACD,CAAA;EAED,QAAQoC,SAAW;IACjB,KAAKE,SAAAA,CAAAA,kBAAkBC,OAAS;MAAA;QACZN,KAAAA,CAAAA,iBAAA,CAAAhC,GAAA,EAAK,OAAS,EAAAiC,KAAAA,CAAAA,kBAAA,CAAmBM,UAAY,EAAA;UAC7DV;QAAA,CACD,CAAA;QACD;MACF;IAEA,KAAKQ,SAAAA,CAAAA,kBAAkBG,WAAa;MAAA;QAChBR,KAAAA,CAAAA,iBAAA,CAAAhC,GAAA,EAAK,OAAS,EAAAiC,KAAAA,CAAAA,kBAAA,CAAmBQ,cAAgB,EAAA;UACjEZ;QAAA,CACD,CAAA;QACD;MACF;IAEA,KAAKQ,SAAAA,CAAAA,iBAAkB,CAAAK,KAAA;IACvB,KAAKL,SAAAA,CAAAA,iBAAkB,CAAAM,YAAA;IACvB,KAAK,IAAA;IACL,KAAK,KAAW,CAAA;MAAA;QAEd;MACF;IAEA;MAAS;QAEPC,MAAA,CAAAA,gBAAA,CAAiBT,SAAS,CAAA;MAC5B;EACF;AACF,CAAA;"}
@@ -19,6 +19,7 @@ const createTaxIdSuperRefinement = ({
19
19
  switch (addressUsageType) {
20
20
  case AddressUsageType.Billing:
21
21
  return;
22
+ case AddressUsageType.ReturnShipping:
22
23
  case AddressUsageType.Shipping:
23
24
  break;
24
25
  default:
@@ -1 +1 @@
1
- {"version":3,"file":"taxIdSuperRefinement.mjs","sources":["../../../src/utils/validations/taxIdSuperRefinement.ts"],"sourcesContent":["import type { SuperRefinement } from \"zod\";\nimport { ZodIssueCode } from \"zod\";\n\nimport type { AddressType, CountryCode, Nullish } from \"../../types\";\nimport { AddressUsageType, ValidateTaxStatus } from \"../../types\";\nimport { assertUnreachable, checkUnreachable } from \"../errors\";\nimport {\n getTaxCountry,\n getTaxLabelTypeByCountry,\n getValidationMappingByType,\n hasTaxNumberPatternValidation,\n isValidTaxNumberPattern,\n} from \"../tax\";\nimport { TaxLabelType } from \"../tax/types\";\nimport { addCustomZodIssue, CustomZodIssueCode } from \"../zod\";\n\nexport type ValidateTaxIdExternally = (opts: {\n type: AddressType;\n countryCode: CountryCode;\n province: Nullish<string>;\n taxId: string;\n}) => Promise<Nullish<ValidateTaxStatus>>;\n\nexport const createTaxIdSuperRefinement =\n ({\n addressUsageType,\n validateTaxIdExternally,\n }: {\n addressUsageType: AddressUsageType;\n validateTaxIdExternally?: ValidateTaxIdExternally;\n }): SuperRefinement<{\n type: AddressType;\n country: CountryCode;\n province?: Nullish<string>;\n taxId?: Nullish<string>;\n }> =>\n async ({ type, country, province, taxId }, ctx) => {\n switch (addressUsageType) {\n // Exit early because tax ID 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.Shipping:\n break;\n default:\n assertUnreachable(addressUsageType);\n }\n\n const taxCountryCode = getTaxCountry({\n country,\n province,\n });\n\n // Doesn't require strict validation\n if (!hasTaxNumberPatternValidation(type, taxCountryCode)) {\n return;\n }\n\n const mapping = getValidationMappingByType(type);\n const { isOptional } = mapping[taxCountryCode];\n\n if (!taxId && isOptional) {\n return;\n }\n\n // Ensure that we have tax ID before passing it to the validation\n if (!taxId) {\n return ctx.addIssue({\n path: [\"taxId\"],\n code: ZodIssueCode.too_small,\n type: \"string\",\n minimum: 1,\n inclusive: true,\n });\n }\n\n const taxLabelType = getTaxLabelTypeByCountry(country, {\n type: \"specific\",\n addressType: type,\n });\n const shouldUppercaseTaxLabel = [\n TaxLabelType.Gst,\n TaxLabelType.Vat,\n TaxLabelType.Cpf,\n TaxLabelType.Cnpj,\n ].includes(taxLabelType);\n const label = shouldUppercaseTaxLabel\n ? taxLabelType.toUpperCase()\n : taxLabelType;\n\n // If the pattern is invalid, error\n if (!isValidTaxNumberPattern(type, taxCountryCode, taxId)) {\n return addCustomZodIssue(ctx, \"taxId\", CustomZodIssueCode.TaxFormat, {\n label,\n });\n }\n\n if (!validateTaxIdExternally) {\n return;\n }\n\n // Additionally validate tax id externally depending on environment\n const taxStatus = await validateTaxIdExternally({\n type,\n countryCode: country,\n province,\n taxId,\n });\n\n switch (taxStatus) {\n case ValidateTaxStatus.Invalid: {\n addCustomZodIssue(ctx, \"taxId\", CustomZodIssueCode.TaxInvalid, {\n label,\n });\n break;\n }\n\n case ValidateTaxStatus.Unavailable: {\n addCustomZodIssue(ctx, \"taxId\", CustomZodIssueCode.TaxUnavailable, {\n label,\n });\n break;\n }\n\n case ValidateTaxStatus.Valid:\n case ValidateTaxStatus.NotValidated:\n case null:\n case undefined: {\n // Do nothing;\n break;\n }\n\n default: {\n // Do nothing as well (but in a type safe way)\n checkUnreachable(taxStatus);\n }\n }\n };\n"],"names":["createTaxIdSuperRefinement","addressUsageType","validateTaxIdExternally","type","country","province","taxId","ctx","AddressUsageType","Billing","Shipping","assertUnreachable","taxCountryCode","getTaxCountry","hasTaxNumberPatternValidation","mapping","getValidationMappingByType","isOptional","addIssue","path","code","ZodIssueCode","too_small","minimum","inclusive","taxLabelType","getTaxLabelTypeByCountry","addressType","shouldUppercaseTaxLabel","TaxLabelType","Gst","Vat","Cpf","Cnpj","includes","label","toUpperCase","isValidTaxNumberPattern","addCustomZodIssue","CustomZodIssueCode","TaxFormat","taxStatus","countryCode","ValidateTaxStatus","Invalid","TaxInvalid","Unavailable","TaxUnavailable","Valid","NotValidated","checkUnreachable"],"mappings":";;;;;;;;;AAuBO,MAAMA,6BACXA,CAAC;EACCC,gBAAA;EACAC;AACF,C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AA,EAAK,OAAS,EAAAgC,kBAAA,CAAmBC,SAAW,EAAA;MACnEL;IAAA,CACD,CAAA;EACH;EAEA,IAAI,CAACjC,uBAAyB,EAAA;IAC5B;EACF;EAGM,MAAAuC,SAAA,GAAY,MAAMvC,uBAAwB,CAAA;IAC9CC,IAAA;IACAuC,WAAa,EAAAtC,OAAA;IACbC,QAAA;IACAC;EAAA,CACD,CAAA;EAED,QAAQmC,SAAW;IACjB,KAAKE,kBAAkBC,OAAS;MAAA;QACZN,iBAAA,CAAA/B,GAAA,EAAK,OAAS,EAAAgC,kBAAA,CAAmBM,UAAY,EAAA;UAC7DV;QAAA,CACD,CAAA;QACD;MACF;IAEA,KAAKQ,kBAAkBG,WAAa;MAAA;QAChBR,iBAAA,CAAA/B,GAAA,EAAK,OAAS,EAAAgC,kBAAA,CAAmBQ,cAAgB,EAAA;UACjEZ;QAAA,CACD,CAAA;QACD;MACF;IAEA,KAAKQ,iBAAkB,CAAAK,KAAA;IACvB,KAAKL,iBAAkB,CAAAM,YAAA;IACvB,KAAK,IAAA;IACL,KAAK,KAAW,CAAA;MAAA;QAEd;MACF;IAEA;MAAS;QAEPC,gBAAA,CAAiBT,SAAS,CAAA;MAC5B;EACF;AACF,CAAA;"}
1
+ {"version":3,"file":"taxIdSuperRefinement.mjs","sources":["../../../src/utils/validations/taxIdSuperRefinement.ts"],"sourcesContent":["import type { SuperRefinement } from \"zod\";\nimport { ZodIssueCode } from \"zod\";\n\nimport type { AddressType, CountryCode, Nullish } from \"../../types\";\nimport { AddressUsageType, ValidateTaxStatus } from \"../../types\";\nimport { assertUnreachable, checkUnreachable } from \"../errors\";\nimport {\n getTaxCountry,\n getTaxLabelTypeByCountry,\n getValidationMappingByType,\n hasTaxNumberPatternValidation,\n isValidTaxNumberPattern,\n} from \"../tax\";\nimport { TaxLabelType } from \"../tax/types\";\nimport { addCustomZodIssue, CustomZodIssueCode } from \"../zod\";\n\nexport type ValidateTaxIdExternally = (opts: {\n type: AddressType;\n countryCode: CountryCode;\n province: Nullish<string>;\n taxId: string;\n}) => Promise<Nullish<ValidateTaxStatus>>;\n\nexport const createTaxIdSuperRefinement =\n ({\n addressUsageType,\n validateTaxIdExternally,\n }: {\n addressUsageType: AddressUsageType;\n validateTaxIdExternally?: ValidateTaxIdExternally;\n }): SuperRefinement<{\n type: AddressType;\n country: CountryCode;\n province?: Nullish<string>;\n taxId?: Nullish<string>;\n }> =>\n async ({ type, country, province, taxId }, ctx) => {\n switch (addressUsageType) {\n // Exit early because tax ID 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 const taxCountryCode = getTaxCountry({\n country,\n province,\n });\n\n // Doesn't require strict validation\n if (!hasTaxNumberPatternValidation(type, taxCountryCode)) {\n return;\n }\n\n const mapping = getValidationMappingByType(type);\n const { isOptional } = mapping[taxCountryCode];\n\n if (!taxId && isOptional) {\n return;\n }\n\n // Ensure that we have tax ID before passing it to the validation\n if (!taxId) {\n return ctx.addIssue({\n path: [\"taxId\"],\n code: ZodIssueCode.too_small,\n type: \"string\",\n minimum: 1,\n inclusive: true,\n });\n }\n\n const taxLabelType = getTaxLabelTypeByCountry(country, {\n type: \"specific\",\n addressType: type,\n });\n const shouldUppercaseTaxLabel = [\n TaxLabelType.Gst,\n TaxLabelType.Vat,\n TaxLabelType.Cpf,\n TaxLabelType.Cnpj,\n ].includes(taxLabelType);\n const label = shouldUppercaseTaxLabel\n ? taxLabelType.toUpperCase()\n : taxLabelType;\n\n // If the pattern is invalid, error\n if (!isValidTaxNumberPattern(type, taxCountryCode, taxId)) {\n return addCustomZodIssue(ctx, \"taxId\", CustomZodIssueCode.TaxFormat, {\n label,\n });\n }\n\n if (!validateTaxIdExternally) {\n return;\n }\n\n // Additionally validate tax id externally depending on environment\n const taxStatus = await validateTaxIdExternally({\n type,\n countryCode: country,\n province,\n taxId,\n });\n\n switch (taxStatus) {\n case ValidateTaxStatus.Invalid: {\n addCustomZodIssue(ctx, \"taxId\", CustomZodIssueCode.TaxInvalid, {\n label,\n });\n break;\n }\n\n case ValidateTaxStatus.Unavailable: {\n addCustomZodIssue(ctx, \"taxId\", CustomZodIssueCode.TaxUnavailable, {\n label,\n });\n break;\n }\n\n case ValidateTaxStatus.Valid:\n case ValidateTaxStatus.NotValidated:\n case null:\n case undefined: {\n // Do nothing;\n break;\n }\n\n default: {\n // Do nothing as well (but in a type safe way)\n checkUnreachable(taxStatus);\n }\n }\n };\n"],"names":["createTaxIdSuperRefinement","addressUsageType","validateTaxIdExternally","type","country","province","taxId","ctx","AddressUsageType","Billing","ReturnShipping","Shipping","assertUnreachable","taxCountryCode","getTaxCountry","hasTaxNumberPatternValidation","mapping","getValidationMappingByType","isOptional","addIssue","path","code","ZodIssueCode","too_small","minimum","inclusive","taxLabelType","getTaxLabelTypeByCountry","addressType","shouldUppercaseTaxLabel","TaxLabelType","Gst","Vat","Cpf","Cnpj","includes","label","toUpperCase","isValidTaxNumberPattern","addCustomZodIssue","CustomZodIssueCode","TaxFormat","taxStatus","countryCode","ValidateTaxStatus","Invalid","TaxInvalid","Unavailable","TaxUnavailable","Valid","NotValidated","checkUnreachable"],"mappings":";;;;;;;;;AAuBO,MAAMA,6BACXA,CAAC;EACCC,gBAAA;EACAC;AACF,CAAA,KASA,OAAO;EAAEC,IAAA;EAAMC;EAASC,QAAU;EAAAC;GAASC,GAAQ,KAAA;EACjD,QAAQN,gBAAkB;IAExB,KAAKO,gBAAiB,CAAAC,OAAA;MACpB;IAEF,KAAKD,gBAAiB,CAAAE,cAAA;IACtB,KAAKF,gBAAiB,CAAAG,QAAA;MACpB;IACF;MACEC,iBAAA,CAAkBX,gBAAgB,CAAA;EACtC;EAEA,MAAMY,iBAAiBC,aAAc,CAAA;IACnCV,OAAA;IACAC;EAAA,CACD,CAAA;EAGD,IAAI,CAACU,6BAAA,CAA8BZ,IAAM,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EAAK,OAAS,EAAAiC,kBAAA,CAAmBM,UAAY,EAAA;UAC7DV;QAAA,CACD,CAAA;QACD;MACF;IAEA,KAAKQ,kBAAkBG,WAAa;MAAA;QAChBR,iBAAA,CAAAhC,GAAA,EAAK,OAAS,EAAAiC,kBAAA,CAAmBQ,cAAgB,EAAA;UACjEZ;QAAA,CACD,CAAA;QACD;MACF;IAEA,KAAKQ,iBAAkB,CAAAK,KAAA;IACvB,KAAKL,iBAAkB,CAAAM,YAAA;IACvB,KAAK,IAAA;IACL,KAAK,KAAW,CAAA;MAAA;QAEd;MACF;IAEA;MAAS;QAEPC,gBAAA,CAAiBT,SAAS,CAAA;MAC5B;EACF;AACF,CAAA;"}
@@ -0,0 +1,15 @@
1
+ /**
2
+ * Util to easily parse that any given input is a finite number (not NaN, Infinity, -Infinity, etc.)
3
+ * @throws If given input is not a finite number
4
+ */
5
+ export declare function isFiniteNumber(value: unknown, entity?: string, ErrorClass?: new (message: string) => void): asserts value is number;
6
+ /**
7
+ * Custom isInt validation function that returns a more fine-grained error message otherwise for type safety alone a
8
+ * Number.isSafeInteger would be sufficient.
9
+ *
10
+ * Code inspired from graphql-scalars library.
11
+ * @see
12
+ * https://github.com/Urigo/graphql-scalars/blob/c4fa3d27b965e39ceda6c33fc18041f112ecce49/src/scalars/utilities.ts#L20-L32
13
+ * @throws If given input is not a valid integer
14
+ */
15
+ export declare function isInt(value: unknown, entity?: string, ErrorClass?: new (message: string) => void): asserts value is number;
@@ -0,0 +1,23 @@
1
+ 'use strict';
2
+ "use strict";
3
+
4
+ function isFiniteNumber(value, entity = "Value", ErrorClass = TypeError) {
5
+ if (typeof value !== "number" || Number.isNaN(value)) {
6
+ throw new ErrorClass(`${entity} is not a number: ${value}`);
7
+ }
8
+ if (!Number.isFinite(value)) {
9
+ throw new ErrorClass(`${entity} is not a finite number: ${value}`);
10
+ }
11
+ }
12
+ function isInt(value, entity = "Value", ErrorClass = TypeError) {
13
+ isFiniteNumber(value, entity, ErrorClass);
14
+ if (!Number.isInteger(value)) {
15
+ throw new ErrorClass(`${entity} is not an integer: ${value}`);
16
+ }
17
+ if (!Number.isSafeInteger(value)) {
18
+ throw new ErrorClass(`${entity} is not a safe integer: ${value}`);
19
+ }
20
+ }
21
+ exports.isFiniteNumber = isFiniteNumber;
22
+ exports.isInt = isInt;
23
+ //# sourceMappingURL=validations.js.map