@ubnt/store.core 9.9.0-alpha.9 → 9.9.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 (295) hide show
  1. package/CHANGELOG.md +0 -30
  2. package/lib/_virtual/_virtual_multi-entry.js +0 -2
  3. package/lib/_virtual/_virtual_multi-entry.js.map +1 -1
  4. package/lib/_virtual/_virtual_multi-entry.mjs +0 -2
  5. package/lib/_virtual/_virtual_multi-entry.mjs.map +1 -1
  6. package/lib/assets/attention.svg +5 -5
  7. package/lib/assets/attention2.svg +5 -5
  8. package/lib/assets/pause.svg +3 -3
  9. package/lib/assets/pause2.svg +3 -3
  10. package/lib/assets/socialMedia/{x.svg.js → twitter.svg.js} +6 -6
  11. package/lib/assets/socialMedia/twitter.svg.js.map +1 -0
  12. package/lib/assets/socialMedia/twitter.svg.mjs +3 -0
  13. package/lib/assets/socialMedia/twitter.svg.mjs.map +1 -0
  14. package/lib/assets/twitter.svg +3 -0
  15. package/lib/assets/ucgMax.jpg +0 -0
  16. package/lib/assets/ucgMax2.jpg +0 -0
  17. package/lib/components/Footer/Footer.d.ts +1 -1
  18. package/lib/components/Footer/Footer.js +74 -192
  19. package/lib/components/Footer/Footer.js.map +1 -1
  20. package/lib/components/Footer/Footer.mjs +76 -174
  21. package/lib/components/Footer/Footer.mjs.map +1 -1
  22. package/lib/components/Footer/Footer.styles.d.ts +5 -17
  23. package/lib/components/Footer/Footer.styles.js +44 -91
  24. package/lib/components/Footer/Footer.styles.js.map +1 -1
  25. package/lib/components/Footer/Footer.styles.mjs +44 -87
  26. package/lib/components/Footer/Footer.styles.mjs.map +1 -1
  27. package/lib/components/Footer/Footer.types.d.ts +0 -40
  28. package/lib/components/Footer/Footer.types.js +0 -16
  29. package/lib/components/Footer/Footer.types.js.map +1 -1
  30. package/lib/components/Footer/Footer.types.mjs +0 -15
  31. package/lib/components/Footer/Footer.types.mjs.map +1 -1
  32. package/lib/components/Footer/index.js +1 -3
  33. package/lib/components/Footer/index.js.map +1 -1
  34. package/lib/components/Footer/index.mjs +1 -1
  35. package/lib/components/Header/AccountMenu/AccountMenu.js +3 -6
  36. package/lib/components/Header/AccountMenu/AccountMenu.js.map +1 -1
  37. package/lib/components/Header/AccountMenu/AccountMenu.mjs +3 -6
  38. package/lib/components/Header/AccountMenu/AccountMenu.mjs.map +1 -1
  39. package/lib/components/Header/Navigation/MobileMenu/MobileMenu.js +6 -11
  40. package/lib/components/Header/Navigation/MobileMenu/MobileMenu.js.map +1 -1
  41. package/lib/components/Header/Navigation/MobileMenu/MobileMenu.mjs +6 -11
  42. package/lib/components/Header/Navigation/MobileMenu/MobileMenu.mjs.map +1 -1
  43. package/lib/components/Header/Navigation/ProMobileMenu/ProMobileMenu.js +4 -8
  44. package/lib/components/Header/Navigation/ProMobileMenu/ProMobileMenu.js.map +1 -1
  45. package/lib/components/Header/Navigation/ProMobileMenu/ProMobileMenu.mjs +4 -8
  46. package/lib/components/Header/Navigation/ProMobileMenu/ProMobileMenu.mjs.map +1 -1
  47. package/lib/components/Header/ProHeader/ProHeader.js +2 -19
  48. package/lib/components/Header/ProHeader/ProHeader.js.map +1 -1
  49. package/lib/components/Header/ProHeader/ProHeader.mjs +2 -19
  50. package/lib/components/Header/ProHeader/ProHeader.mjs.map +1 -1
  51. package/lib/components/Header/ProHeader/ProHeader.styles.d.ts +0 -1
  52. package/lib/components/Header/ProHeader/ProHeader.styles.js +0 -6
  53. package/lib/components/Header/ProHeader/ProHeader.styles.js.map +1 -1
  54. package/lib/components/Header/ProHeader/ProHeader.styles.mjs +0 -6
  55. package/lib/components/Header/ProHeader/ProHeader.styles.mjs.map +1 -1
  56. package/lib/components/LandingPagePro/LandingPagePro.d.ts +0 -3
  57. package/lib/components/LandingPagePro/LandingPagePro.js +3 -3
  58. package/lib/components/LandingPagePro/LandingPagePro.js.map +1 -1
  59. package/lib/components/LandingPagePro/LandingPagePro.mjs +2 -2
  60. package/lib/components/LandingPagePro/LandingPagePro.mjs.map +1 -1
  61. package/lib/components/MicrositeVideoSlideshow/MicrositeVideoSlideshow.js +1 -1
  62. package/lib/components/MicrositeVideoSlideshow/MicrositeVideoSlideshow.mjs +1 -1
  63. package/lib/components/MicrositeVideoSlideshow/assets/pause.svg.js +1 -1
  64. package/lib/components/MicrositeVideoSlideshow/assets/pause.svg.mjs +2 -2
  65. package/lib/components/ModelCompareV3/assets/Consoles/bigCompare/ucgMax.jpg.js +5 -5
  66. package/lib/components/ModelCompareV3/assets/Consoles/bigCompare/ucgMax.jpg.mjs +2 -2
  67. package/lib/components/ModelCompareV3/assets/Consoles/ucgMax.jpg.js +1 -1
  68. package/lib/components/ModelCompareV3/assets/Consoles/ucgMax.jpg.mjs +2 -2
  69. package/lib/components/ModelCompareV3/data/CloudGateways.js +3 -3
  70. package/lib/components/ModelCompareV3/data/CloudGateways.mjs +2 -2
  71. package/lib/components/ModelCompareV3/data/products/ucgMax.js +1 -1
  72. package/lib/components/ModelCompareV3/data/products/ucgMax.mjs +1 -1
  73. package/lib/components/ResourceCalculatorV1/ComputeResourceCalculator/ComputeResourceCalculator.constants.js +1 -6
  74. package/lib/components/ResourceCalculatorV1/ComputeResourceCalculator/ComputeResourceCalculator.constants.js.map +1 -1
  75. package/lib/components/ResourceCalculatorV1/ComputeResourceCalculator/ComputeResourceCalculator.constants.mjs +1 -6
  76. package/lib/components/ResourceCalculatorV1/ComputeResourceCalculator/ComputeResourceCalculator.constants.mjs.map +1 -1
  77. package/lib/components/ResourceCalculatorV1/ComputeResourceCalculator/components/InputCard/InputCard.js +2 -2
  78. package/lib/components/ResourceCalculatorV1/ComputeResourceCalculator/components/InputCard/InputCard.js.map +1 -1
  79. package/lib/components/ResourceCalculatorV1/ComputeResourceCalculator/components/InputCard/InputCard.mjs +2 -2
  80. package/lib/components/ResourceCalculatorV1/ComputeResourceCalculator/components/InputCard/InputCard.mjs.map +1 -1
  81. package/lib/components/ResourceCalculatorV1/ComputeResourceCalculator/components/InputCard/InputCard.styles.js +0 -2
  82. package/lib/components/ResourceCalculatorV1/ComputeResourceCalculator/components/InputCard/InputCard.styles.js.map +1 -1
  83. package/lib/components/ResourceCalculatorV1/ComputeResourceCalculator/components/InputCard/InputCard.styles.mjs +0 -2
  84. package/lib/components/ResourceCalculatorV1/ComputeResourceCalculator/components/InputCard/InputCard.styles.mjs.map +1 -1
  85. package/lib/components/ResourceCalculatorV1/ComputeResourceCalculator/components/InputCard/assets/attention.svg.js +1 -1
  86. package/lib/components/ResourceCalculatorV1/ComputeResourceCalculator/components/InputCard/assets/attention.svg.mjs +2 -2
  87. package/lib/components/ResourceCalculatorV1/ComputeResourceCalculator/components/ProgressBarChart/ProgressBarChart.js +1 -1
  88. package/lib/components/ResourceCalculatorV1/ComputeResourceCalculator/components/ProgressBarChart/ProgressBarChart.mjs +1 -1
  89. package/lib/components/ResourceCalculatorV1/ComputeResourceCalculator/components/ProgressBarChart/assets/attention.svg.js +1 -1
  90. package/lib/components/ResourceCalculatorV1/ComputeResourceCalculator/components/ProgressBarChart/assets/attention.svg.mjs +2 -2
  91. package/lib/components/VideoPlayerNew/VideoPlayer.js +1 -1
  92. package/lib/components/VideoPlayerNew/VideoPlayer.mjs +1 -1
  93. package/lib/components/VideoPlayerNew/assets/pause.svg.js +1 -1
  94. package/lib/components/VideoPlayerNew/assets/pause.svg.mjs +2 -2
  95. package/lib/constants/footerContent.d.ts +145 -0
  96. package/lib/constants/footerContent.js +313 -0
  97. package/lib/constants/footerContent.js.map +1 -0
  98. package/lib/constants/footerContent.mjs +293 -0
  99. package/lib/constants/footerContent.mjs.map +1 -0
  100. package/lib/constants/proStoreCategories/mapping/index.d.ts +0 -3
  101. package/lib/constants/proStoreCategories/mapping/index.js +10 -20
  102. package/lib/constants/proStoreCategories/mapping/index.js.map +1 -1
  103. package/lib/constants/proStoreCategories/mapping/index.mjs +10 -20
  104. package/lib/constants/proStoreCategories/mapping/index.mjs.map +1 -1
  105. package/lib/constants/proStoreCategories/mapping/unifi.d.ts +1 -3
  106. package/lib/constants/proStoreCategories/mapping/unifi.js +0 -2
  107. package/lib/constants/proStoreCategories/mapping/unifi.js.map +1 -1
  108. package/lib/constants/proStoreCategories/mapping/unifi.mjs +0 -2
  109. package/lib/constants/proStoreCategories/mapping/unifi.mjs.map +1 -1
  110. package/lib/constants/proStoreCategories/translations/ar.json.js +1 -1
  111. package/lib/constants/proStoreCategories/translations/ar.json.mjs +1 -1
  112. package/lib/constants/proStoreCategories/translations/de.json.js +1 -1
  113. package/lib/constants/proStoreCategories/translations/de.json.mjs +1 -1
  114. package/lib/constants/proStoreCategories/translations/el.json.js +1 -1
  115. package/lib/constants/proStoreCategories/translations/el.json.mjs +1 -1
  116. package/lib/constants/proStoreCategories/translations/en.json.js +0 -5
  117. package/lib/constants/proStoreCategories/translations/en.json.js.map +1 -1
  118. package/lib/constants/proStoreCategories/translations/en.json.mjs +1 -5
  119. package/lib/constants/proStoreCategories/translations/en.json.mjs.map +1 -1
  120. package/lib/constants/proStoreCategories/translations/es.json.js +1 -1
  121. package/lib/constants/proStoreCategories/translations/es.json.mjs +1 -1
  122. package/lib/constants/proStoreCategories/translations/fr.json.js +2 -2
  123. package/lib/constants/proStoreCategories/translations/fr.json.mjs +2 -2
  124. package/lib/constants/proStoreCategories/translations/it.json.js +1 -1
  125. package/lib/constants/proStoreCategories/translations/it.json.mjs +1 -1
  126. package/lib/constants/proStoreCategories/translations/ja.json.js +1 -1
  127. package/lib/constants/proStoreCategories/translations/ja.json.mjs +1 -1
  128. package/lib/constants/proStoreCategories/translations/pt-BR.json.js +1 -1
  129. package/lib/constants/proStoreCategories/translations/pt-BR.json.mjs +1 -1
  130. package/lib/constants/proStoreCategories/translations/zh-Hans.json.js +2 -2
  131. package/lib/constants/proStoreCategories/translations/zh-Hans.json.mjs +2 -2
  132. package/lib/constants/proStoreCategories/translations/zh-Hant-TW.json.js +2 -2
  133. package/lib/constants/proStoreCategories/translations/zh-Hant-TW.json.mjs +2 -2
  134. package/lib/constants/url.d.ts +4 -4
  135. package/lib/constants/url.js +4 -4
  136. package/lib/constants/url.js.map +1 -1
  137. package/lib/constants/url.mjs +4 -4
  138. package/lib/constants/url.mjs.map +1 -1
  139. package/lib/contexts/MenuContext/mapping.js +0 -41
  140. package/lib/contexts/MenuContext/mapping.js.map +1 -1
  141. package/lib/contexts/MenuContext/mapping.mjs +0 -41
  142. package/lib/contexts/MenuContext/mapping.mjs.map +1 -1
  143. package/lib/contexts/MenuContext/presets.js.map +1 -1
  144. package/lib/contexts/MenuContext/presets.mjs.map +1 -1
  145. package/lib/utils/address.d.ts +61 -61
  146. package/lib/utils/index.d.ts +0 -1
  147. package/lib/utils/index.js +0 -2
  148. package/lib/utils/index.js.map +1 -1
  149. package/lib/utils/index.mjs +0 -2
  150. package/lib/utils/index.mjs.map +1 -1
  151. package/lib/utils/money/constants.d.ts +25 -56
  152. package/lib/utils/money/constants.js +7 -72
  153. package/lib/utils/money/constants.js.map +1 -1
  154. package/lib/utils/money/constants.mjs +7 -70
  155. package/lib/utils/money/constants.mjs.map +1 -1
  156. package/lib/utils/money/format.d.ts +5 -10
  157. package/lib/utils/money/format.js +14 -22
  158. package/lib/utils/money/format.js.map +1 -1
  159. package/lib/utils/money/format.mjs +16 -23
  160. package/lib/utils/money/format.mjs.map +1 -1
  161. package/lib/utils/money/index.d.ts +1 -4
  162. package/lib/utils/money/index.js +8 -26
  163. package/lib/utils/money/index.js.map +1 -1
  164. package/lib/utils/money/index.mjs +4 -8
  165. package/lib/utils/money/index.mjs.map +1 -1
  166. package/lib/utils/money/misc.d.ts +28 -68
  167. package/lib/utils/money/misc.js +64 -35
  168. package/lib/utils/money/misc.js.map +1 -1
  169. package/lib/utils/money/misc.mjs +43 -32
  170. package/lib/utils/money/misc.mjs.map +1 -1
  171. package/lib/utils/money/tax.d.ts +2 -38
  172. package/lib/utils/money/tax.js +10 -46
  173. package/lib/utils/money/tax.js.map +1 -1
  174. package/lib/utils/money/tax.mjs +11 -42
  175. package/lib/utils/money/tax.mjs.map +1 -1
  176. package/lib/utils/money/types.d.ts +3 -78
  177. package/lib/utils/number.d.ts +1 -1
  178. package/lib/utils/number.js +1 -1
  179. package/lib/utils/number.js.map +1 -1
  180. package/lib/utils/number.mjs +1 -1
  181. package/lib/utils/number.mjs.map +1 -1
  182. package/lib/utils/validations.d.ts +15 -0
  183. package/lib/utils/validations.js +23 -0
  184. package/lib/utils/validations.js.map +1 -0
  185. package/lib/utils/validations.mjs +21 -0
  186. package/lib/utils/validations.mjs.map +1 -0
  187. package/package.json +1 -1
  188. package/lib/assets/socialMedia/x.svg.js.map +0 -1
  189. package/lib/assets/socialMedia/x.svg.mjs +0 -3
  190. package/lib/assets/socialMedia/x.svg.mjs.map +0 -1
  191. package/lib/assets/x.svg +0 -3
  192. package/lib/components/Footer/hooks/useFooterContent.d.ts +0 -94
  193. package/lib/components/Footer/hooks/useFooterContent.js +0 -384
  194. package/lib/components/Footer/hooks/useFooterContent.js.map +0 -1
  195. package/lib/components/Footer/hooks/useFooterContent.mjs +0 -348
  196. package/lib/components/Footer/hooks/useFooterContent.mjs.map +0 -1
  197. package/lib/components/Footer/translations/ar.json.js +0 -47
  198. package/lib/components/Footer/translations/ar.json.js.map +0 -1
  199. package/lib/components/Footer/translations/ar.json.mjs +0 -42
  200. package/lib/components/Footer/translations/ar.json.mjs.map +0 -1
  201. package/lib/components/Footer/translations/de.json.js +0 -47
  202. package/lib/components/Footer/translations/de.json.js.map +0 -1
  203. package/lib/components/Footer/translations/de.json.mjs +0 -42
  204. package/lib/components/Footer/translations/de.json.mjs.map +0 -1
  205. package/lib/components/Footer/translations/el.json.js +0 -47
  206. package/lib/components/Footer/translations/el.json.js.map +0 -1
  207. package/lib/components/Footer/translations/el.json.mjs +0 -42
  208. package/lib/components/Footer/translations/el.json.mjs.map +0 -1
  209. package/lib/components/Footer/translations/en.json.js +0 -46
  210. package/lib/components/Footer/translations/en.json.js.map +0 -1
  211. package/lib/components/Footer/translations/en.json.mjs +0 -41
  212. package/lib/components/Footer/translations/en.json.mjs.map +0 -1
  213. package/lib/components/Footer/translations/es.json.js +0 -47
  214. package/lib/components/Footer/translations/es.json.js.map +0 -1
  215. package/lib/components/Footer/translations/es.json.mjs +0 -42
  216. package/lib/components/Footer/translations/es.json.mjs.map +0 -1
  217. package/lib/components/Footer/translations/fr.json.js +0 -47
  218. package/lib/components/Footer/translations/fr.json.js.map +0 -1
  219. package/lib/components/Footer/translations/fr.json.mjs +0 -42
  220. package/lib/components/Footer/translations/fr.json.mjs.map +0 -1
  221. package/lib/components/Footer/translations/it.json.js +0 -47
  222. package/lib/components/Footer/translations/it.json.js.map +0 -1
  223. package/lib/components/Footer/translations/it.json.mjs +0 -42
  224. package/lib/components/Footer/translations/it.json.mjs.map +0 -1
  225. package/lib/components/Footer/translations/ja.json.js +0 -47
  226. package/lib/components/Footer/translations/ja.json.js.map +0 -1
  227. package/lib/components/Footer/translations/ja.json.mjs +0 -42
  228. package/lib/components/Footer/translations/ja.json.mjs.map +0 -1
  229. package/lib/components/Footer/translations/pt-BR.json.js +0 -47
  230. package/lib/components/Footer/translations/pt-BR.json.js.map +0 -1
  231. package/lib/components/Footer/translations/pt-BR.json.mjs +0 -42
  232. package/lib/components/Footer/translations/pt-BR.json.mjs.map +0 -1
  233. package/lib/components/Footer/translations/zh-Hans.json.js +0 -47
  234. package/lib/components/Footer/translations/zh-Hans.json.js.map +0 -1
  235. package/lib/components/Footer/translations/zh-Hans.json.mjs +0 -42
  236. package/lib/components/Footer/translations/zh-Hans.json.mjs.map +0 -1
  237. package/lib/components/Footer/translations/zh-Hant-TW.json.js +0 -47
  238. package/lib/components/Footer/translations/zh-Hant-TW.json.js.map +0 -1
  239. package/lib/components/Footer/translations/zh-Hant-TW.json.mjs +0 -42
  240. package/lib/components/Footer/translations/zh-Hant-TW.json.mjs.map +0 -1
  241. package/lib/components/Tooltip/Tooltip.d.ts +0 -2
  242. package/lib/components/Tooltip/Tooltip.js +0 -45
  243. package/lib/components/Tooltip/Tooltip.js.map +0 -1
  244. package/lib/components/Tooltip/Tooltip.mjs +0 -43
  245. package/lib/components/Tooltip/Tooltip.mjs.map +0 -1
  246. package/lib/components/Tooltip/Tooltip.styles.d.ts +0 -32
  247. package/lib/components/Tooltip/Tooltip.styles.js +0 -44
  248. package/lib/components/Tooltip/Tooltip.styles.js.map +0 -1
  249. package/lib/components/Tooltip/Tooltip.styles.mjs +0 -34
  250. package/lib/components/Tooltip/Tooltip.styles.mjs.map +0 -1
  251. package/lib/components/Tooltip/index.d.ts +0 -1
  252. package/lib/components/Tooltip/index.js +0 -6
  253. package/lib/components/Tooltip/index.js.map +0 -1
  254. package/lib/components/Tooltip/index.mjs +0 -3
  255. package/lib/components/Tooltip/index.mjs.map +0 -1
  256. package/lib/utils/money/allocators/fixedAmount.d.ts +0 -26
  257. package/lib/utils/money/allocators/fixedAmount.js +0 -55
  258. package/lib/utils/money/allocators/fixedAmount.js.map +0 -1
  259. package/lib/utils/money/allocators/fixedAmount.mjs +0 -53
  260. package/lib/utils/money/allocators/fixedAmount.mjs.map +0 -1
  261. package/lib/utils/money/allocators/index.d.ts +0 -2
  262. package/lib/utils/money/allocators/index.js +0 -8
  263. package/lib/utils/money/allocators/index.js.map +0 -1
  264. package/lib/utils/money/allocators/index.mjs +0 -4
  265. package/lib/utils/money/allocators/index.mjs.map +0 -1
  266. package/lib/utils/money/allocators/productAmount.d.ts +0 -13
  267. package/lib/utils/money/allocators/productAmount.js +0 -110
  268. package/lib/utils/money/allocators/productAmount.js.map +0 -1
  269. package/lib/utils/money/allocators/productAmount.mjs +0 -108
  270. package/lib/utils/money/allocators/productAmount.mjs.map +0 -1
  271. package/lib/utils/money/exchangeRate.d.ts +0 -31
  272. package/lib/utils/money/exchangeRate.js +0 -27
  273. package/lib/utils/money/exchangeRate.js.map +0 -1
  274. package/lib/utils/money/exchangeRate.mjs +0 -23
  275. package/lib/utils/money/exchangeRate.mjs.map +0 -1
  276. package/lib/utils/money/misc.private.d.ts +0 -23
  277. package/lib/utils/money/misc.private.js +0 -46
  278. package/lib/utils/money/misc.private.js.map +0 -1
  279. package/lib/utils/money/misc.private.mjs +0 -21
  280. package/lib/utils/money/misc.private.mjs.map +0 -1
  281. package/lib/utils/money/shipping.d.ts +0 -5
  282. package/lib/utils/money/shipping.js +0 -8
  283. package/lib/utils/money/shipping.js.map +0 -1
  284. package/lib/utils/money/shipping.mjs +0 -6
  285. package/lib/utils/money/shipping.mjs.map +0 -1
  286. package/lib/utils/money/tax.private.d.ts +0 -17
  287. package/lib/utils/money/tax.private.js +0 -65
  288. package/lib/utils/money/tax.private.js.map +0 -1
  289. package/lib/utils/money/tax.private.mjs +0 -60
  290. package/lib/utils/money/tax.private.mjs.map +0 -1
  291. package/lib/utils/typeGuards.d.ts +0 -1
  292. package/lib/utils/typeGuards.js +0 -6
  293. package/lib/utils/typeGuards.js.map +0 -1
  294. package/lib/utils/typeGuards.mjs +0 -5
  295. package/lib/utils/typeGuards.mjs.map +0 -1
@@ -1,21 +0,0 @@
1
- import * as currencies from '@dinero.js/currencies';
2
- import { dinero } from 'dinero.js';
3
- import '../../types/index.mjs';
4
- import { isFloat } from '../number.mjs';
5
- import { Round } from './constants.mjs';
6
- import { Currency } from '../../types/generated.mjs';
7
- "use strict";
8
- const currencyLookup = new Set(Object.keys(Currency).map(el => el.toString()));
9
- const dineroCurrenciesLookup = new Map(Object.values(currencies).map(currency => [currency.code, currency]));
10
- const floatToInt = (floatAmount, base, exponent) => Round.Financial(floatAmount * Math.pow(base, exponent));
11
- const decimalToDinero = (decimalAmount, currency) => {
12
- const parsedNumber = typeof decimalAmount === "number" ? decimalAmount : Number.parseFloat(decimalAmount);
13
- isFloat(parsedNumber);
14
- const parsedNumberInt = Number.parseInt((parsedNumber * Math.pow(10, currency.exponent)).toFixed(0));
15
- return dinero({
16
- amount: parsedNumberInt,
17
- currency
18
- });
19
- };
20
- export { currencyLookup, decimalToDinero, dineroCurrenciesLookup, floatToInt };
21
- //# sourceMappingURL=misc.private.mjs.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"misc.private.mjs","sources":["../../../src/utils/money/misc.private.ts"],"sourcesContent":["// #############################################################################\n// Internal helper functions not for consumption outside of store.core!\n// Wrote as separate files so that they can be easily unit tested without exposing them\n// #############################################################################\nimport * as currencies from \"@dinero.js/currencies\";\nimport { dinero } from \"dinero.js\";\n\nimport { Currency } from \"../../types\";\nimport { isFloat } from \"../number\";\nimport { Round } from \"./constants\";\nimport type { DinoCurrency } from \"./types\";\n\n/**\n * Fast lookup for our custom currency enum to check that given currency is valid\n */\nexport const currencyLookup = new Set(\n Object.keys(Currency).map((el) => el.toString()),\n);\n\n/**\n * Dinero currency lookup to check that given currency is valid\n */\nexport const dineroCurrenciesLookup = new Map(\n Object.values(currencies).map((currency) => [currency.code, currency]),\n);\n\n/**\n * Private util to convert a float value into a int. Also applies financial rounding to the value if needed.\n * Inspired by https://v2.dinerojs.com/docs/faq/how-can-i-create-dinero-objects-from-floats\n * @example\n * floatToInt(69.10, 10, 2); // 6910\n * floatToInt(42, 10, 2); // 4200\n * floatToInt(0.22, 10, 6); // 220000\n */\nexport const floatToInt = (\n floatAmount: number,\n base: number,\n exponent: number,\n // FIXME: pass in the rounding method and or use roundDinero\n): number => Round.Financial(floatAmount * Math.pow(base, exponent));\n\n/**\n * FIXME: is it private tho?!\n */\nexport const decimalToDinero = (\n decimalAmount: string | number,\n currency: DinoCurrency,\n // FIXME: rounding method?!\n) => {\n const parsedNumber =\n typeof decimalAmount === \"number\"\n ? decimalAmount\n : Number.parseFloat(decimalAmount);\n isFloat(parsedNumber);\n\n const parsedNumberInt = Number.parseInt(\n (parsedNumber * Math.pow(10, currency.exponent)).toFixed(0),\n );\n return dinero({\n amount: parsedNumberInt,\n currency,\n });\n};\n"],"names":["currencyLookup","Set","Object","keys","Currency","map","el","toString","dineroCurrenciesLookup","Map","values","currencies","currency","code","floatToInt","floatAmount","base","exponent","Round","Financial","Math","pow","decimalToDinero","decimalAmount","parsedNumber","Number","parseFloat","isFloat","parsedNumberInt","parseInt","toFixed","dinero","amount"],"mappings":";;;;;;;AAeO,MAAMA,iBAAiB,IAAIC,GAAA,CAChCC,MAAA,CAAOC,KAAKC,QAAQ,CAAA,CAAEC,IAAKC,EAAA,IAAOA,EAAG,CAAAC,QAAA,EAAU,CACjD,CAAA;AAKO,MAAMC,yBAAyB,IAAIC,GAAA,CACxCP,MAAA,CAAOQ,MAAO,CAAAC,UAAU,CAAE,CAAAN,GAAA,CAAKO,QAAA,IAAa,CAACA,QAAA,CAASC,IAAM,EAAAD,QAAQ,CAAC,CACvE,CAAA;AAUO,MAAME,UAAa,GAAAA,CACxBC,WACA,EAAAC,IAAA,EACAC,QAEW,KAAAC,KAAA,CAAMC,SAAU,CAAAJ,WAAA,GAAcK,IAAK,CAAAC,GAAA,CAAIL,IAAM,EAAAC,QAAQ,CAAC,CAAA;AAKtD,MAAAK,eAAA,GAAkBA,CAC7BC,aAAA,EACAX,QAEG,KAAA;EACH,MAAMY,eACJ,OAAOD,aAAA,KAAkB,WACrBA,aACA,GAAAE,MAAA,CAAOC,WAAWH,aAAa,CAAA;EACrCI,OAAA,CAAQH,YAAY,CAAA;EAEpB,MAAMI,kBAAkBH,MAAO,CAAAI,QAAA,CAC5B,CAAAL,YAAA,GAAeJ,KAAKC,GAAI,CAAA,EAAA,EAAIT,SAASK,QAAQ,CAAA,EAAGa,QAAQ,CAAC,CAAA,CAC5D;EACA,OAAOC,MAAO,CAAA;IACZC,MAAQ,EAAAJ,eAAA;IACRhB;EAAA,CACD,CAAA;AACH,CAAA;"}
@@ -1,5 +0,0 @@
1
- import type { Dino } from "./types";
2
- /**
3
- * Rounding for shipping price used only after applying
4
- */
5
- export declare const roundShippingPrice: (price: Dino) => Dino;
@@ -1,8 +0,0 @@
1
- 'use strict';
2
-
3
- var constants = require('./constants.js');
4
- var misc = require('./misc.js');
5
- "use strict";
6
- const roundShippingPrice = price => misc.roundDinero(price, constants.Round.Shipping);
7
- exports.roundShippingPrice = roundShippingPrice;
8
- //# sourceMappingURL=shipping.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"shipping.js","sources":["../../../src/utils/money/shipping.ts"],"sourcesContent":["import { Round } from \"./constants\";\nimport { roundDinero } from \"./misc\";\nimport type { Dino } from \"./types\";\n\n/**\n * Rounding for shipping price used only after applying\n */\nexport const roundShippingPrice = (price: Dino) =>\n roundDinero(price, Round.Shipping);\n"],"names":["roundShippingPrice","price","roundDinero","Round","Shipping"],"mappings":";;;;;AAOO,MAAMA,qBAAsBC,KAAA,IACjCC,IAAY,CAAAA,WAAA,CAAAD,KAAA,EAAOE,gBAAMC,QAAQ,CAAA;"}
@@ -1,6 +0,0 @@
1
- import { Round } from './constants.mjs';
2
- import { roundDinero } from './misc.mjs';
3
- "use strict";
4
- const roundShippingPrice = price => roundDinero(price, Round.Shipping);
5
- export { roundShippingPrice };
6
- //# sourceMappingURL=shipping.mjs.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"shipping.mjs","sources":["../../../src/utils/money/shipping.ts"],"sourcesContent":["import { Round } from \"./constants\";\nimport { roundDinero } from \"./misc\";\nimport type { Dino } from \"./types\";\n\n/**\n * Rounding for shipping price used only after applying\n */\nexport const roundShippingPrice = (price: Dino) =>\n roundDinero(price, Round.Shipping);\n"],"names":["roundShippingPrice","price","roundDinero","Round","Shipping"],"mappings":";;;AAOO,MAAMA,qBAAsBC,KAAA,IACjCC,WAAY,CAAAD,KAAA,EAAOE,MAAMC,QAAQ,CAAA;"}
@@ -1,17 +0,0 @@
1
- import type { Dinero } from "dinero.js";
2
- import type { Cents, LineItemSummary, SingleLineItemSummary, TaxRate } from "./types";
3
- /**
4
- * Private helper to convert a floating number to a dinero friendly allocation integer pair
5
- * @see https://v2.dinerojs.com/docs/api/mutations/allocate
6
- * @example
7
- * taxRateToDineroAllocation(0.1) // [1, 9]
8
- * taxRateToDineroAllocation(0.5) // [5, 5]
9
- */
10
- export declare const taxRateToDineroAllocation: (taxRate: TaxRate) => [number, number];
11
- /**
12
- * Reverse engineer the taxable amount from "whole item" taxable amount into "per item" taxable amount for custom tax
13
- * rate calculations
14
- */
15
- export declare const allocatePerItemTaxableAmount: (itemSummary: LineItemSummary) => SingleLineItemSummary[];
16
- export declare const calculateWholeQtyLineItemTax: (itemSummary: LineItemSummary, taxRate: TaxRate) => Dinero<Cents>;
17
- export declare const calculatePerQtyLineItemTax: (itemSummary: LineItemSummary, taxRate: TaxRate) => Dinero<Cents>;
@@ -1,65 +0,0 @@
1
- 'use strict';
2
-
3
- var dinero_js = require('dinero.js');
4
- var errors = require('../errors.js');
5
- var fixedAmount = require('./allocators/fixedAmount.js');
6
- var misc = require('./misc.js');
7
- "use strict";
8
- const taxRateToDineroAllocation = taxRate => {
9
- if (taxRate <= 0 || taxRate >= 1) {
10
- throw new RangeError("Unsupported rate, expected in range of 0>rate<1");
11
- }
12
- const rateScale = String(taxRate).split(".")[1]?.length;
13
- errors.assert(rateScale !== void 0, "rateScale is undefined");
14
- const rateInt = Math.round(taxRate * Math.pow(10, rateScale));
15
- return [rateInt, Math.pow(10, rateScale) - rateInt];
16
- };
17
- const allocatePerItemTaxableAmount = itemSummary => {
18
- if (itemSummary.quantity === 1) {
19
- return [itemSummary];
20
- }
21
- const preDiscountAmount = dinero_js.add(misc.getDinero(itemSummary.taxableAmount, itemSummary.currency), misc.getDinero(itemSummary.discountAmount, itemSummary.currency));
22
- const allocator = new fixedAmount.FixedAmountAllocator({
23
- initialAllocateAmount: itemSummary.discountAmount,
24
- initialTotalAmount: misc.amount(preDiscountAmount),
25
- currency: itemSummary.currency
26
- });
27
- return Array.from({
28
- length: itemSummary.quantity
29
- }, () => {
30
- const discountAllocatedAmount = allocator.allocate(itemSummary.itemPrice, itemSummary.currency);
31
- const taxableAmount = dinero_js.subtract(misc.getDinero(itemSummary.itemPrice, itemSummary.currency), discountAllocatedAmount);
32
- return {
33
- itemPrice: itemSummary.itemPrice,
34
- taxableAmount: misc.amount(taxableAmount),
35
- discountAmount: misc.amount(discountAllocatedAmount),
36
- currency: itemSummary.currency,
37
- quantity: 1
38
- };
39
- });
40
- };
41
- const calculateWholeQtyLineItemTax = (itemSummary, taxRate) => {
42
- if (taxRate === 0) {
43
- return misc.getDinero(0, itemSummary.currency);
44
- }
45
- const [taxAmount] = dinero_js.allocate(misc.getDinero(itemSummary.taxableAmount, itemSummary.currency), taxRateToDineroAllocation(taxRate));
46
- errors.assert(taxAmount !== void 0, "taxAmount is undefined");
47
- return taxAmount;
48
- };
49
- const calculatePerQtyLineItemTax = (itemSummary, taxRate) => {
50
- if (taxRate === 0) {
51
- return misc.getDinero(0, itemSummary.currency);
52
- }
53
- const singleItemSummaries = allocatePerItemTaxableAmount(itemSummary);
54
- let totalTaxAmount = misc.getDinero(0, itemSummary.currency);
55
- singleItemSummaries.forEach(itemSummary2 => {
56
- const taxAmount = calculateWholeQtyLineItemTax(itemSummary2, taxRate);
57
- totalTaxAmount = dinero_js.add(totalTaxAmount, taxAmount);
58
- });
59
- return totalTaxAmount;
60
- };
61
- exports.allocatePerItemTaxableAmount = allocatePerItemTaxableAmount;
62
- exports.calculatePerQtyLineItemTax = calculatePerQtyLineItemTax;
63
- exports.calculateWholeQtyLineItemTax = calculateWholeQtyLineItemTax;
64
- exports.taxRateToDineroAllocation = taxRateToDineroAllocation;
65
- //# sourceMappingURL=tax.private.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"tax.private.js","sources":["../../../src/utils/money/tax.private.ts"],"sourcesContent":["// #############################################################################\n// Internal helper functions not for consumption outside of store.core!\n// Wrote as separate files so that they can be easily unit tested without exposing them\n// #############################################################################\nimport type { Dinero } from \"dinero.js\";\nimport { add, allocate, subtract } from \"dinero.js\";\n\nimport { assert } from \"../errors\";\nimport { FixedAmountAllocator } from \"./allocators/fixedAmount\";\nimport { amount, getDinero } from \"./misc\";\nimport type {\n Cents,\n LineItemSummary,\n SingleLineItemSummary,\n TaxRate,\n} from \"./types\";\n\n/**\n * Private helper to convert a floating number to a dinero friendly allocation integer pair\n * @see https://v2.dinerojs.com/docs/api/mutations/allocate\n * @example\n * taxRateToDineroAllocation(0.1) // [1, 9]\n * taxRateToDineroAllocation(0.5) // [5, 5]\n */\nexport const taxRateToDineroAllocation = (\n taxRate: TaxRate,\n): [number, number] => {\n if (taxRate <= 0 || taxRate >= 1) {\n throw new RangeError(\"Unsupported rate, expected in range of 0>rate<1\");\n }\n\n // Get the scale of the rate\n const rateScale = String(taxRate).split(\".\")[1]?.length;\n assert(rateScale !== undefined, \"rateScale is undefined\");\n\n // Convert to integers\n const rateInt = Math.round(taxRate * Math.pow(10, rateScale));\n return [rateInt, Math.pow(10, rateScale) - rateInt];\n};\n\n/**\n * Reverse engineer the taxable amount from \"whole item\" taxable amount into \"per item\" taxable amount for custom tax\n * rate calculations\n */\nexport const allocatePerItemTaxableAmount = (\n itemSummary: LineItemSummary,\n): SingleLineItemSummary[] => {\n /**\n * If the item quantity is 1, we can just return the item summary as is\n */\n if (itemSummary.quantity === 1) {\n return [itemSummary as SingleLineItemSummary];\n }\n\n // Reverse engineer price before discount\n const preDiscountAmount = add(\n getDinero(itemSummary.taxableAmount, itemSummary.currency),\n getDinero(itemSummary.discountAmount, itemSummary.currency),\n );\n\n const allocator = new FixedAmountAllocator({\n initialAllocateAmount: itemSummary.discountAmount,\n initialTotalAmount: amount(preDiscountAmount),\n currency: itemSummary.currency,\n });\n\n // Iterate over the amount of qty to reverse engineer the discount price\n return Array.from({ length: itemSummary.quantity }, () => {\n const discountAllocatedAmount = allocator.allocate(\n itemSummary.itemPrice,\n itemSummary.currency,\n );\n\n const taxableAmount = subtract(\n getDinero(itemSummary.itemPrice, itemSummary.currency),\n discountAllocatedAmount,\n );\n\n return {\n itemPrice: itemSummary.itemPrice,\n taxableAmount: amount(taxableAmount),\n discountAmount: amount(discountAllocatedAmount),\n currency: itemSummary.currency,\n quantity: 1,\n } as SingleLineItemSummary;\n });\n};\n\nexport const calculateWholeQtyLineItemTax = (\n itemSummary: LineItemSummary,\n taxRate: TaxRate,\n): Dinero<Cents> => {\n // Nothing to calculate\n if (taxRate === 0) {\n return getDinero(0, itemSummary.currency);\n }\n\n /**\n * FIXME: look into approach with multiply and different scale for control over rounding, currently we just inherit\n * what dinero gives us which cause unexpected rounding issue\n */\n const [taxAmount] = allocate(\n getDinero(itemSummary.taxableAmount, itemSummary.currency),\n taxRateToDineroAllocation(taxRate),\n );\n\n assert(taxAmount !== undefined, \"taxAmount is undefined\");\n return taxAmount;\n};\n\nexport const calculatePerQtyLineItemTax = (\n itemSummary: LineItemSummary,\n taxRate: TaxRate,\n): Dinero<Cents> => {\n // Nothing to calculate\n if (taxRate === 0) {\n return getDinero(0, itemSummary.currency);\n }\n\n // Split the item summary into per individual item qty summaries\n const singleItemSummaries = allocatePerItemTaxableAmount(itemSummary);\n\n // Calculate individual item qty tax and sum them up\n let totalTaxAmount = getDinero(0, itemSummary.currency);\n\n singleItemSummaries.forEach((itemSummary) => {\n // Probably a bit confusing at first, but calling the whole qty tax calculation function here as we can safely use\n // it as item summary is always a single item summary here\n const taxAmount = calculateWholeQtyLineItemTax(itemSummary, taxRate);\n totalTaxAmount = add(totalTaxAmount, taxAmount);\n });\n\n return totalTaxAmount;\n};\n"],"names":["taxRateToDineroAllocation","taxRate","RangeError","rateScale","String","split","length","assert","rateInt","Math","round","pow","allocatePerItemTaxableAmount","itemSummary","quantity","preDiscountAmount","add","getDinero","taxableAmount","currency","discountAmount","allocator","FixedAmountAllocator","initialAllocateAmount","initialTotalAmount","amount","Array","from","discountAllocatedAmount","allocate","itemPrice","subtract","calculateWholeQtyLineItemTax","taxAmount","calculatePerQtyLineItemTax","singleItemSummaries","totalTaxAmount","forEach"],"mappings":";;;;;;;AAwBa,MAAAA,yBAAA,GACXC,OACqB,IAAA;EACjB,IAAAA,OAAA,IAAW,CAAK,IAAAA,OAAA,IAAW,CAAG,EAAA;IAC1B,MAAA,IAAIC,WAAW,iDAAiD,CAAA;EACxE;EAGM,MAAAC,SAAA,GAAYC,OAAOH,OAAO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}
@@ -1,60 +0,0 @@
1
- import { add, subtract, allocate } from 'dinero.js';
2
- import { assert } from '../errors.mjs';
3
- import { FixedAmountAllocator } from './allocators/fixedAmount.mjs';
4
- import { getDinero, amount } from './misc.mjs';
5
- "use strict";
6
- const taxRateToDineroAllocation = taxRate => {
7
- if (taxRate <= 0 || taxRate >= 1) {
8
- throw new RangeError("Unsupported rate, expected in range of 0>rate<1");
9
- }
10
- const rateScale = String(taxRate).split(".")[1]?.length;
11
- assert(rateScale !== void 0, "rateScale is undefined");
12
- const rateInt = Math.round(taxRate * Math.pow(10, rateScale));
13
- return [rateInt, Math.pow(10, rateScale) - rateInt];
14
- };
15
- const allocatePerItemTaxableAmount = itemSummary => {
16
- if (itemSummary.quantity === 1) {
17
- return [itemSummary];
18
- }
19
- const preDiscountAmount = add(getDinero(itemSummary.taxableAmount, itemSummary.currency), getDinero(itemSummary.discountAmount, itemSummary.currency));
20
- const allocator = new FixedAmountAllocator({
21
- initialAllocateAmount: itemSummary.discountAmount,
22
- initialTotalAmount: amount(preDiscountAmount),
23
- currency: itemSummary.currency
24
- });
25
- return Array.from({
26
- length: itemSummary.quantity
27
- }, () => {
28
- const discountAllocatedAmount = allocator.allocate(itemSummary.itemPrice, itemSummary.currency);
29
- const taxableAmount = subtract(getDinero(itemSummary.itemPrice, itemSummary.currency), discountAllocatedAmount);
30
- return {
31
- itemPrice: itemSummary.itemPrice,
32
- taxableAmount: amount(taxableAmount),
33
- discountAmount: amount(discountAllocatedAmount),
34
- currency: itemSummary.currency,
35
- quantity: 1
36
- };
37
- });
38
- };
39
- const calculateWholeQtyLineItemTax = (itemSummary, taxRate) => {
40
- if (taxRate === 0) {
41
- return getDinero(0, itemSummary.currency);
42
- }
43
- const [taxAmount] = allocate(getDinero(itemSummary.taxableAmount, itemSummary.currency), taxRateToDineroAllocation(taxRate));
44
- assert(taxAmount !== void 0, "taxAmount is undefined");
45
- return taxAmount;
46
- };
47
- const calculatePerQtyLineItemTax = (itemSummary, taxRate) => {
48
- if (taxRate === 0) {
49
- return getDinero(0, itemSummary.currency);
50
- }
51
- const singleItemSummaries = allocatePerItemTaxableAmount(itemSummary);
52
- let totalTaxAmount = getDinero(0, itemSummary.currency);
53
- singleItemSummaries.forEach(itemSummary2 => {
54
- const taxAmount = calculateWholeQtyLineItemTax(itemSummary2, taxRate);
55
- totalTaxAmount = add(totalTaxAmount, taxAmount);
56
- });
57
- return totalTaxAmount;
58
- };
59
- export { allocatePerItemTaxableAmount, calculatePerQtyLineItemTax, calculateWholeQtyLineItemTax, taxRateToDineroAllocation };
60
- //# sourceMappingURL=tax.private.mjs.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"tax.private.mjs","sources":["../../../src/utils/money/tax.private.ts"],"sourcesContent":["// #############################################################################\n// Internal helper functions not for consumption outside of store.core!\n// Wrote as separate files so that they can be easily unit tested without exposing them\n// #############################################################################\nimport type { Dinero } from \"dinero.js\";\nimport { add, allocate, subtract } from \"dinero.js\";\n\nimport { assert } from \"../errors\";\nimport { FixedAmountAllocator } from \"./allocators/fixedAmount\";\nimport { amount, getDinero } from \"./misc\";\nimport type {\n Cents,\n LineItemSummary,\n SingleLineItemSummary,\n TaxRate,\n} from \"./types\";\n\n/**\n * Private helper to convert a floating number to a dinero friendly allocation integer pair\n * @see https://v2.dinerojs.com/docs/api/mutations/allocate\n * @example\n * taxRateToDineroAllocation(0.1) // [1, 9]\n * taxRateToDineroAllocation(0.5) // [5, 5]\n */\nexport const taxRateToDineroAllocation = (\n taxRate: TaxRate,\n): [number, number] => {\n if (taxRate <= 0 || taxRate >= 1) {\n throw new RangeError(\"Unsupported rate, expected in range of 0>rate<1\");\n }\n\n // Get the scale of the rate\n const rateScale = String(taxRate).split(\".\")[1]?.length;\n assert(rateScale !== undefined, \"rateScale is undefined\");\n\n // Convert to integers\n const rateInt = Math.round(taxRate * Math.pow(10, rateScale));\n return [rateInt, Math.pow(10, rateScale) - rateInt];\n};\n\n/**\n * Reverse engineer the taxable amount from \"whole item\" taxable amount into \"per item\" taxable amount for custom tax\n * rate calculations\n */\nexport const allocatePerItemTaxableAmount = (\n itemSummary: LineItemSummary,\n): SingleLineItemSummary[] => {\n /**\n * If the item quantity is 1, we can just return the item summary as is\n */\n if (itemSummary.quantity === 1) {\n return [itemSummary as SingleLineItemSummary];\n }\n\n // Reverse engineer price before discount\n const preDiscountAmount = add(\n getDinero(itemSummary.taxableAmount, itemSummary.currency),\n getDinero(itemSummary.discountAmount, itemSummary.currency),\n );\n\n const allocator = new FixedAmountAllocator({\n initialAllocateAmount: itemSummary.discountAmount,\n initialTotalAmount: amount(preDiscountAmount),\n currency: itemSummary.currency,\n });\n\n // Iterate over the amount of qty to reverse engineer the discount price\n return Array.from({ length: itemSummary.quantity }, () => {\n const discountAllocatedAmount = allocator.allocate(\n itemSummary.itemPrice,\n itemSummary.currency,\n );\n\n const taxableAmount = subtract(\n getDinero(itemSummary.itemPrice, itemSummary.currency),\n discountAllocatedAmount,\n );\n\n return {\n itemPrice: itemSummary.itemPrice,\n taxableAmount: amount(taxableAmount),\n discountAmount: amount(discountAllocatedAmount),\n currency: itemSummary.currency,\n quantity: 1,\n } as SingleLineItemSummary;\n });\n};\n\nexport const calculateWholeQtyLineItemTax = (\n itemSummary: LineItemSummary,\n taxRate: TaxRate,\n): Dinero<Cents> => {\n // Nothing to calculate\n if (taxRate === 0) {\n return getDinero(0, itemSummary.currency);\n }\n\n /**\n * FIXME: look into approach with multiply and different scale for control over rounding, currently we just inherit\n * what dinero gives us which cause unexpected rounding issue\n */\n const [taxAmount] = allocate(\n getDinero(itemSummary.taxableAmount, itemSummary.currency),\n taxRateToDineroAllocation(taxRate),\n );\n\n assert(taxAmount !== undefined, \"taxAmount is undefined\");\n return taxAmount;\n};\n\nexport const calculatePerQtyLineItemTax = (\n itemSummary: LineItemSummary,\n taxRate: TaxRate,\n): Dinero<Cents> => {\n // Nothing to calculate\n if (taxRate === 0) {\n return getDinero(0, itemSummary.currency);\n }\n\n // Split the item summary into per individual item qty summaries\n const singleItemSummaries = allocatePerItemTaxableAmount(itemSummary);\n\n // Calculate individual item qty tax and sum them up\n let totalTaxAmount = getDinero(0, itemSummary.currency);\n\n singleItemSummaries.forEach((itemSummary) => {\n // Probably a bit confusing at first, but calling the whole qty tax calculation function here as we can safely use\n // it as item summary is always a single item summary here\n const taxAmount = calculateWholeQtyLineItemTax(itemSummary, taxRate);\n totalTaxAmount = add(totalTaxAmount, taxAmount);\n });\n\n return totalTaxAmount;\n};\n"],"names":["taxRateToDineroAllocation","taxRate","RangeError","rateScale","String","split","length","assert","rateInt","Math","round","pow","allocatePerItemTaxableAmount","itemSummary","quantity","preDiscountAmount","add","getDinero","taxableAmount","currency","discountAmount","allocator","FixedAmountAllocator","initialAllocateAmount","initialTotalAmount","amount","Array","from","discountAllocatedAmount","allocate","itemPrice","subtract","calculateWholeQtyLineItemTax","taxAmount","calculatePerQtyLineItemTax","singleItemSummaries","totalTaxAmount","forEach"],"mappings":";;;;;AAwBa,MAAAA,yBAAA,GACXC,OACqB,IAAA;EACjB,IAAAA,OAAA,IAAW,CAAK,IAAAA,OAAA,IAAW,CAAG,EAAA;IAC1B,MAAA,IAAIC,WAAW,iDAAiD,CAAA;EACxE;EAGM,MAAAC,SAAA,GAAYC,OAAOH,OAAO,CAAA,CAAEI,MAAM,GAAG,CAAA,CAAE,CAAC,CAAG,EAAAC,MAAA;EAC1CC,MAAA,CAAAJ,SAAA,KAAc,QAAW,wBAAwB,CAAA;EAGlD,MAAAK,OAAA,GAAUC,KAAKC,KAAM,CAAAT,OAAA,GAAUQ,KAAKE,GAAI,CAAA,EAAA,EAAIR,SAAS,CAAC,CAAA;EAC5D,OAAO,CAACK,OAAS,EAAAC,IAAA,CAAKE,IAAI,EAAI,EAAAR,SAAS,IAAIK,OAAO,CAAA;AACpD,CAAA;AAMa,MAAAI,4BAAA,GACXC,WAC4B,IAAA;EAIxB,IAAAA,WAAA,CAAYC,aAAa,CAAG,EAAA;IAC9B,OAAO,CAACD,WAAoC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AA,CACnC;EAEOM,MAAA,CAAA0B,SAAA,KAAc,QAAW,wBAAwB,CAAA;EACjD,OAAAA,SAAA;AACT,CAAA;AAEa,MAAAC,0BAAA,GAA6BA,CACxCrB,WAAA,EACAZ,OACkB,KAAA;EAElB,IAAIA,YAAY,CAAG,EAAA;IACV,OAAAgB,SAAA,CAAU,CAAG,EAAAJ,WAAA,CAAYM,QAAQ,CAAA;EAC1C;EAGM,MAAAgB,mBAAA,GAAsBvB,6BAA6BC,WAAW,CAAA;EAGpE,IAAIuB,cAAiB,GAAAnB,SAAA,CAAU,CAAG,EAAAJ,WAAA,CAAYM,QAAQ,CAAA;EAElCgB,mBAAA,CAAAE,OAAA,CAASxB,YAAgB,IAAA;IAGrC,MAAAoB,SAAA,GAAYD,4BAA6BnB,CAAAA,YAAAA,EAAaZ,OAAO,CAAA;IAClDmC,cAAA,GAAApB,GAAA,CAAIoB,gBAAgBH,SAAS,CAAA;EAAA,CAC/C,CAAA;EAEM,OAAAG,cAAA;AACT,CAAA;"}
@@ -1 +0,0 @@
1
- export declare const isNonNullish: <T>(entry: T | null | undefined) => entry is T;
@@ -1,6 +0,0 @@
1
- 'use strict';
2
- "use strict";
3
-
4
- const isNonNullish = entry => entry !== null && entry !== void 0;
5
- exports.isNonNullish = isNonNullish;
6
- //# sourceMappingURL=typeGuards.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"typeGuards.js","sources":["../../src/utils/typeGuards.ts"],"sourcesContent":["export const isNonNullish = <T>(entry: T | null | undefined): entry is T =>\n entry !== null && entry !== undefined;\n"],"names":["isNonNullish","entry"],"mappings":";;;AAAO,MAAMA,YAAe,GAAIC,KAC9B,IAAAA,KAAA,KAAU,QAAQA,KAAU,KAAA,KAAA,CAAA;"}
@@ -1,5 +0,0 @@
1
- "use strict";
2
-
3
- const isNonNullish = entry => entry !== null && entry !== void 0;
4
- export { isNonNullish };
5
- //# sourceMappingURL=typeGuards.mjs.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"typeGuards.mjs","sources":["../../src/utils/typeGuards.ts"],"sourcesContent":["export const isNonNullish = <T>(entry: T | null | undefined): entry is T =>\n entry !== null && entry !== undefined;\n"],"names":["isNonNullish","entry"],"mappings":";;AAAO,MAAMA,YAAe,GAAIC,KAC9B,IAAAA,KAAA,KAAU,QAAQA,KAAU,KAAA,KAAA,CAAA;"}