@ubnt/store.core 9.45.0-beta.3 → 9.45.0-beta.4

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 (273) hide show
  1. package/CHANGELOG.md +10 -0
  2. package/lib/_virtual/_virtual_multi-entry.js +2 -0
  3. package/lib/_virtual/_virtual_multi-entry.js.map +1 -1
  4. package/lib/_virtual/_virtual_multi-entry.mjs +2 -0
  5. package/lib/_virtual/_virtual_multi-entry.mjs.map +1 -1
  6. package/lib/apis/smartcat.d.ts +4 -4
  7. package/lib/apis/smartcat.js +1 -1
  8. package/lib/apis/smartcat.js.map +1 -1
  9. package/lib/apis/smartcat.mjs +1 -1
  10. package/lib/apis/smartcat.mjs.map +1 -1
  11. package/lib/assets/attention.svg +5 -5
  12. package/lib/assets/attention2.svg +5 -5
  13. package/lib/assets/poe2.svg +3 -2
  14. package/lib/assets/poe3.svg +2 -3
  15. package/lib/assets/port.svg +4 -2
  16. package/lib/assets/port2.svg +2 -4
  17. package/lib/assets/ucgMax.jpg +0 -0
  18. package/lib/assets/ucgMax2.jpg +0 -0
  19. package/lib/assets/ucgUltra.jpg +0 -0
  20. package/lib/assets/ucgUltra2.jpg +0 -0
  21. package/lib/assets/udmPro.jpg +0 -0
  22. package/lib/assets/udmPro2.jpg +0 -0
  23. package/lib/assets/udmProMax.jpg +0 -0
  24. package/lib/assets/udmProMax2.jpg +0 -0
  25. package/lib/assets/udmProSpecial.jpg +0 -0
  26. package/lib/assets/udmProSpecial2.jpg +0 -0
  27. package/lib/components/Accordion/Accordion.js +2 -2
  28. package/lib/components/Accordion/Accordion.js.map +1 -1
  29. package/lib/components/Accordion/Accordion.mjs +2 -2
  30. package/lib/components/Accordion/Accordion.mjs.map +1 -1
  31. package/lib/components/CustomImage/CustomImage.js +4 -4
  32. package/lib/components/CustomImage/CustomImage.js.map +1 -1
  33. package/lib/components/CustomImage/CustomImage.mjs +4 -4
  34. package/lib/components/CustomImage/CustomImage.mjs.map +1 -1
  35. package/lib/components/FeaturesSection_deprecated/FeaturesSection.js +1 -1
  36. package/lib/components/FeaturesSection_deprecated/FeaturesSection.js.map +1 -1
  37. package/lib/components/FeaturesSection_deprecated/FeaturesSection.mjs +1 -1
  38. package/lib/components/FeaturesSection_deprecated/FeaturesSection.mjs.map +1 -1
  39. package/lib/components/Gallery/Gallery.context.js.map +1 -1
  40. package/lib/components/Gallery/Gallery.context.mjs.map +1 -1
  41. package/lib/components/Gallery/GalleryItem/GalleryItem.js +3 -1
  42. package/lib/components/Gallery/GalleryItem/GalleryItem.js.map +1 -1
  43. package/lib/components/Gallery/GalleryItem/GalleryItem.mjs +3 -1
  44. package/lib/components/Gallery/GalleryItem/GalleryItem.mjs.map +1 -1
  45. package/lib/components/Header/AccountFrame/AccountFrame.js +3 -3
  46. package/lib/components/Header/AccountFrame/AccountFrame.js.map +1 -1
  47. package/lib/components/Header/AccountFrame/AccountFrame.mjs +3 -3
  48. package/lib/components/Header/AccountFrame/AccountFrame.mjs.map +1 -1
  49. package/lib/components/Header/AccountMenu/AccountMenu.js.map +1 -1
  50. package/lib/components/Header/AccountMenu/AccountMenu.mjs.map +1 -1
  51. package/lib/components/Header/Header.js +3 -3
  52. package/lib/components/Header/Header.js.map +1 -1
  53. package/lib/components/Header/Header.mjs +3 -3
  54. package/lib/components/Header/Header.mjs.map +1 -1
  55. package/lib/components/Header/Header.types.d.ts +1 -1
  56. package/lib/components/Header/Header.types.js.map +1 -1
  57. package/lib/components/Header/Header.types.mjs.map +1 -1
  58. package/lib/components/Header/LanguageFrame/LanguageFrame.js.map +1 -1
  59. package/lib/components/Header/LanguageFrame/LanguageFrame.mjs.map +1 -1
  60. package/lib/components/Header/Navigation/MicrositeMenu/MicrositeMenu.js +2 -2
  61. package/lib/components/Header/Navigation/MicrositeMenu/MicrositeMenu.js.map +1 -1
  62. package/lib/components/Header/Navigation/MicrositeMenu/MicrositeMenu.mjs +2 -2
  63. package/lib/components/Header/Navigation/MicrositeMenu/MicrositeMenu.mjs.map +1 -1
  64. package/lib/components/Header/ProHeader/ProHeader.js +11 -7
  65. package/lib/components/Header/ProHeader/ProHeader.js.map +1 -1
  66. package/lib/components/Header/ProHeader/ProHeader.mjs +11 -7
  67. package/lib/components/Header/ProHeader/ProHeader.mjs.map +1 -1
  68. package/lib/components/Hero/Hero.js +1 -1
  69. package/lib/components/Hero/Hero.js.map +1 -1
  70. package/lib/components/Hero/Hero.mjs +1 -1
  71. package/lib/components/Hero/Hero.mjs.map +1 -1
  72. package/lib/components/HeroVideo/HeroVideo.js +5 -5
  73. package/lib/components/HeroVideo/HeroVideo.js.map +1 -1
  74. package/lib/components/HeroVideo/HeroVideo.mjs +5 -5
  75. package/lib/components/HeroVideo/HeroVideo.mjs.map +1 -1
  76. package/lib/components/ImageCarousel/ImageCarousel.js.map +1 -1
  77. package/lib/components/ImageCarousel/ImageCarousel.mjs.map +1 -1
  78. package/lib/components/LandingPagePro/LandingPagePro.js +4 -1
  79. package/lib/components/LandingPagePro/LandingPagePro.js.map +1 -1
  80. package/lib/components/LandingPagePro/LandingPagePro.mjs +4 -1
  81. package/lib/components/LandingPagePro/LandingPagePro.mjs.map +1 -1
  82. package/lib/components/LandingPageSidebar/LandingPageSidebar.js +8 -8
  83. package/lib/components/LandingPageSidebar/LandingPageSidebar.js.map +1 -1
  84. package/lib/components/LandingPageSidebar/LandingPageSidebar.mjs +8 -8
  85. package/lib/components/LandingPageSidebar/LandingPageSidebar.mjs.map +1 -1
  86. package/lib/components/MeetUniFiVideoPlayer/MeetUniFiVideoPlayer.js +4 -4
  87. package/lib/components/MeetUniFiVideoPlayer/MeetUniFiVideoPlayer.js.map +1 -1
  88. package/lib/components/MeetUniFiVideoPlayer/MeetUniFiVideoPlayer.mjs +4 -4
  89. package/lib/components/MeetUniFiVideoPlayer/MeetUniFiVideoPlayer.mjs.map +1 -1
  90. package/lib/components/MicrositeHero/MicrositeHero.js +2 -2
  91. package/lib/components/MicrositeHero/MicrositeHero.js.map +1 -1
  92. package/lib/components/MicrositeHero/MicrositeHero.mjs +2 -2
  93. package/lib/components/MicrositeHero/MicrositeHero.mjs.map +1 -1
  94. package/lib/components/Microsites/Microsites.types.js.map +1 -1
  95. package/lib/components/Microsites/Microsites.types.mjs.map +1 -1
  96. package/lib/components/ModelCompareV3/ModelComparePropertyValueGridItem.js +37 -26
  97. package/lib/components/ModelCompareV3/ModelComparePropertyValueGridItem.js.map +1 -1
  98. package/lib/components/ModelCompareV3/ModelComparePropertyValueGridItem.mjs +37 -26
  99. package/lib/components/ModelCompareV3/ModelComparePropertyValueGridItem.mjs.map +1 -1
  100. package/lib/components/ModelCompareV3/ModelCompareV3.types.d.ts +1 -1
  101. package/lib/components/ModelCompareV3/StickyGrid/StickyGridItem.js +16 -8
  102. package/lib/components/ModelCompareV3/StickyGrid/StickyGridItem.js.map +1 -1
  103. package/lib/components/ModelCompareV3/StickyGrid/StickyGridItem.mjs +16 -8
  104. package/lib/components/ModelCompareV3/StickyGrid/StickyGridItem.mjs.map +1 -1
  105. package/lib/components/ModelCompareV3/StickyGrid/context.d.ts +3 -3
  106. package/lib/components/ModelCompareV3/StickyGrid/context.js.map +1 -1
  107. package/lib/components/ModelCompareV3/StickyGrid/context.mjs.map +1 -1
  108. package/lib/components/ModelCompareV3/assets/Consoles/bigCompare/ucgMax.jpg.js +5 -5
  109. package/lib/components/ModelCompareV3/assets/Consoles/bigCompare/ucgMax.jpg.mjs +2 -2
  110. package/lib/components/ModelCompareV3/assets/Consoles/bigCompare/ucgUltra.jpg.js +5 -5
  111. package/lib/components/ModelCompareV3/assets/Consoles/bigCompare/ucgUltra.jpg.mjs +2 -2
  112. package/lib/components/ModelCompareV3/assets/Consoles/bigCompare/udmPro.jpg.js +5 -5
  113. package/lib/components/ModelCompareV3/assets/Consoles/bigCompare/udmPro.jpg.mjs +2 -2
  114. package/lib/components/ModelCompareV3/assets/Consoles/bigCompare/udmProMax.jpg.js +5 -5
  115. package/lib/components/ModelCompareV3/assets/Consoles/bigCompare/udmProMax.jpg.mjs +2 -2
  116. package/lib/components/ModelCompareV3/assets/Consoles/bigCompare/udmProSpecial.jpg.js +5 -5
  117. package/lib/components/ModelCompareV3/assets/Consoles/bigCompare/udmProSpecial.jpg.mjs +2 -2
  118. package/lib/components/ModelCompareV3/assets/Consoles/ucgMax.jpg.js +1 -1
  119. package/lib/components/ModelCompareV3/assets/Consoles/ucgMax.jpg.mjs +2 -2
  120. package/lib/components/ModelCompareV3/assets/Consoles/ucgUltra.jpg.js +1 -1
  121. package/lib/components/ModelCompareV3/assets/Consoles/ucgUltra.jpg.mjs +2 -2
  122. package/lib/components/ModelCompareV3/assets/Consoles/udmPro.jpg.js +1 -1
  123. package/lib/components/ModelCompareV3/assets/Consoles/udmPro.jpg.mjs +2 -2
  124. package/lib/components/ModelCompareV3/assets/Consoles/udmProMax.jpg.js +1 -1
  125. package/lib/components/ModelCompareV3/assets/Consoles/udmProMax.jpg.mjs +2 -2
  126. package/lib/components/ModelCompareV3/assets/Consoles/udmProSpecial.jpg.js +1 -1
  127. package/lib/components/ModelCompareV3/assets/Consoles/udmProSpecial.jpg.mjs +2 -2
  128. package/lib/components/ModelCompareV3/assets/poe.svg.js +1 -1
  129. package/lib/components/ModelCompareV3/assets/poe.svg.mjs +2 -2
  130. package/lib/components/ModelCompareV3/assets/port.svg.js +1 -1
  131. package/lib/components/ModelCompareV3/assets/port.svg.mjs +2 -2
  132. package/lib/components/ModelCompareV3/data/CloudGateways.js +15 -15
  133. package/lib/components/ModelCompareV3/data/CloudGateways.mjs +10 -10
  134. package/lib/components/ModelCompareV3/data/products/ucgMax.js +1 -1
  135. package/lib/components/ModelCompareV3/data/products/ucgMax.mjs +1 -1
  136. package/lib/components/ModelCompareV3/data/products/ucgUltra.js +1 -1
  137. package/lib/components/ModelCompareV3/data/products/ucgUltra.mjs +1 -1
  138. package/lib/components/ModelCompareV3/data/products/udmPro.js +1 -1
  139. package/lib/components/ModelCompareV3/data/products/udmPro.mjs +1 -1
  140. package/lib/components/ModelCompareV3/data/products/udmProMax.js +1 -1
  141. package/lib/components/ModelCompareV3/data/products/udmProMax.mjs +1 -1
  142. package/lib/components/ModelCompareV3/data/products/udmProSpecial.js +1 -1
  143. package/lib/components/ModelCompareV3/data/products/udmProSpecial.mjs +1 -1
  144. package/lib/components/ModelCompareV3/data/properties/powerMethodPoe.js +1 -1
  145. package/lib/components/ModelCompareV3/data/properties/powerMethodPoe.mjs +1 -1
  146. package/lib/components/ModelCompareV3/data/properties/readerPowerMethod.js +1 -1
  147. package/lib/components/ModelCompareV3/data/properties/readerPowerMethod.mjs +1 -1
  148. package/lib/components/ModelCompareV3/data/properties/redundantRj45Port.js +1 -1
  149. package/lib/components/ModelCompareV3/data/properties/redundantRj45Port.mjs +1 -1
  150. package/lib/components/PriceRangeSlider/PriceRangeSlider.types.d.ts +2 -2
  151. package/lib/components/PriceRangeSlider/PriceRangeSlider.types.js.map +1 -1
  152. package/lib/components/PriceRangeSlider/PriceRangeSlider.types.mjs.map +1 -1
  153. package/lib/components/ProductCard/ProductCard.js +1 -1
  154. package/lib/components/ProductCard/ProductCard.js.map +1 -1
  155. package/lib/components/ProductCard/ProductCard.mjs +2 -2
  156. package/lib/components/ProductCard/ProductCard.mjs.map +1 -1
  157. package/lib/components/ProductCardPopup/ProductCardPopup.js +2 -2
  158. package/lib/components/ProductCardPopup/ProductCardPopup.js.map +1 -1
  159. package/lib/components/ProductCardPopup/ProductCardPopup.mjs +2 -2
  160. package/lib/components/ProductCardPopup/ProductCardPopup.mjs.map +1 -1
  161. package/lib/components/ProductSectionTabs/ProductSectionTabs.js +6 -1
  162. package/lib/components/ProductSectionTabs/ProductSectionTabs.js.map +1 -1
  163. package/lib/components/ProductSectionTabs/ProductSectionTabs.mjs +6 -1
  164. package/lib/components/ProductSectionTabs/ProductSectionTabs.mjs.map +1 -1
  165. package/lib/components/ProductWizard/ProductWizard.js +3 -3
  166. package/lib/components/ProductWizard/ProductWizard.js.map +1 -1
  167. package/lib/components/ProductWizard/ProductWizard.mjs +3 -3
  168. package/lib/components/ProductWizard/ProductWizard.mjs.map +1 -1
  169. package/lib/components/ProductWizardFootnotes/ProductWizardFootnotes.js +17 -4
  170. package/lib/components/ProductWizardFootnotes/ProductWizardFootnotes.js.map +1 -1
  171. package/lib/components/ProductWizardFootnotes/ProductWizardFootnotes.mjs +17 -4
  172. package/lib/components/ProductWizardFootnotes/ProductWizardFootnotes.mjs.map +1 -1
  173. package/lib/components/ResourceCalculatorV1/ComputeResourceCalculator/ComputeResourceCalculator.js +4 -4
  174. package/lib/components/ResourceCalculatorV1/ComputeResourceCalculator/ComputeResourceCalculator.js.map +1 -1
  175. package/lib/components/ResourceCalculatorV1/ComputeResourceCalculator/ComputeResourceCalculator.mjs +4 -4
  176. package/lib/components/ResourceCalculatorV1/ComputeResourceCalculator/ComputeResourceCalculator.mjs.map +1 -1
  177. package/lib/components/ResourceCalculatorV1/ComputeResourceCalculator/components/InputCard/InputCard.js +1 -1
  178. package/lib/components/ResourceCalculatorV1/ComputeResourceCalculator/components/InputCard/InputCard.mjs +1 -1
  179. package/lib/components/ResourceCalculatorV1/ComputeResourceCalculator/components/InputCard/assets/attention.svg.js +1 -1
  180. package/lib/components/ResourceCalculatorV1/ComputeResourceCalculator/components/InputCard/assets/attention.svg.mjs +2 -2
  181. package/lib/components/ResourceCalculatorV1/ComputeResourceCalculator/components/ProgressBarChart/ProgressBarChart.js +1 -1
  182. package/lib/components/ResourceCalculatorV1/ComputeResourceCalculator/components/ProgressBarChart/ProgressBarChart.mjs +1 -1
  183. package/lib/components/ResourceCalculatorV1/ComputeResourceCalculator/components/ProgressBarChart/assets/attention.svg.js +1 -1
  184. package/lib/components/ResourceCalculatorV1/ComputeResourceCalculator/components/ProgressBarChart/assets/attention.svg.mjs +2 -2
  185. package/lib/components/ResourceCalculatorV1/PoeCalculator/components/RecommendedPoeSwitches/RecommendedPoeSwitches.js +2 -2
  186. package/lib/components/ResourceCalculatorV1/PoeCalculator/components/RecommendedPoeSwitches/RecommendedPoeSwitches.mjs +2 -2
  187. package/lib/components/ResourceCalculatorV1/PoeCalculator/components/RecommendedPoeSwitches/assets/poe.svg.js +1 -1
  188. package/lib/components/ResourceCalculatorV1/PoeCalculator/components/RecommendedPoeSwitches/assets/poe.svg.mjs +2 -2
  189. package/lib/components/ResourceCalculatorV1/PoeCalculator/components/RecommendedPoeSwitches/assets/port.svg.js +1 -1
  190. package/lib/components/ResourceCalculatorV1/PoeCalculator/components/RecommendedPoeSwitches/assets/port.svg.mjs +2 -2
  191. package/lib/components/ScrollWrapper/ScrollWrapper.styles.js +87 -64
  192. package/lib/components/ScrollWrapper/ScrollWrapper.styles.js.map +1 -1
  193. package/lib/components/ScrollWrapper/ScrollWrapper.styles.mjs +87 -64
  194. package/lib/components/ScrollWrapper/ScrollWrapper.styles.mjs.map +1 -1
  195. package/lib/components/StorageSliders/StorageSliders.context.js +17 -14
  196. package/lib/components/StorageSliders/StorageSliders.context.js.map +1 -1
  197. package/lib/components/StorageSliders/StorageSliders.context.mjs +17 -14
  198. package/lib/components/StorageSliders/StorageSliders.context.mjs.map +1 -1
  199. package/lib/components/StorybookUtils/StoryFaker.js.map +1 -1
  200. package/lib/components/StorybookUtils/StoryFaker.mjs.map +1 -1
  201. package/lib/components/VariantSelector/VariantSelector.js +4 -4
  202. package/lib/components/VariantSelector/VariantSelector.js.map +1 -1
  203. package/lib/components/VariantSelector/VariantSelector.mjs +4 -4
  204. package/lib/components/VariantSelector/VariantSelector.mjs.map +1 -1
  205. package/lib/components/VideoPlayerNew/VideoPlayer.js +12 -14
  206. package/lib/components/VideoPlayerNew/VideoPlayer.js.map +1 -1
  207. package/lib/components/VideoPlayerNew/VideoPlayer.mjs +12 -14
  208. package/lib/components/VideoPlayerNew/VideoPlayer.mjs.map +1 -1
  209. package/lib/constants/address.d.ts +1 -1
  210. package/lib/constants/address.js +34 -34
  211. package/lib/constants/address.js.map +1 -1
  212. package/lib/constants/address.mjs +34 -34
  213. package/lib/constants/address.mjs.map +1 -1
  214. package/lib/constants/postalCode.js +10 -10
  215. package/lib/constants/postalCode.js.map +1 -1
  216. package/lib/constants/postalCode.mjs +10 -10
  217. package/lib/constants/postalCode.mjs.map +1 -1
  218. package/lib/contexts/MenuContext/context.js +27 -26
  219. package/lib/contexts/MenuContext/context.js.map +1 -1
  220. package/lib/contexts/MenuContext/context.mjs +27 -26
  221. package/lib/contexts/MenuContext/context.mjs.map +1 -1
  222. package/lib/helpers/ux.d.ts +0 -11
  223. package/lib/hooks/useScrollToY.js.map +1 -1
  224. package/lib/hooks/useScrollToY.mjs.map +1 -1
  225. package/lib/utils/blackFriday.d.ts +1 -20
  226. package/lib/utils/blackFriday.js +3 -84
  227. package/lib/utils/blackFriday.js.map +1 -1
  228. package/lib/utils/blackFriday.mjs +1 -74
  229. package/lib/utils/blackFriday.mjs.map +1 -1
  230. package/lib/utils/collectionSlug.js +2 -2
  231. package/lib/utils/collectionSlug.js.map +1 -1
  232. package/lib/utils/collectionSlug.mjs +2 -2
  233. package/lib/utils/collectionSlug.mjs.map +1 -1
  234. package/lib/utils/errors.js.map +1 -1
  235. package/lib/utils/errors.mjs.map +1 -1
  236. package/lib/utils/index.d.ts +1 -0
  237. package/lib/utils/index.js +2 -0
  238. package/lib/utils/index.js.map +1 -1
  239. package/lib/utils/index.mjs +2 -0
  240. package/lib/utils/index.mjs.map +1 -1
  241. package/lib/utils/measures.js +1 -0
  242. package/lib/utils/measures.js.map +1 -1
  243. package/lib/utils/measures.mjs +1 -0
  244. package/lib/utils/measures.mjs.map +1 -1
  245. package/lib/utils/money/format.js.map +1 -1
  246. package/lib/utils/money/format.mjs.map +1 -1
  247. package/lib/utils/money/misc.js +1 -1
  248. package/lib/utils/money/misc.js.map +1 -1
  249. package/lib/utils/money/misc.mjs +1 -1
  250. package/lib/utils/money/misc.mjs.map +1 -1
  251. package/lib/utils/nextjs/ssr/transform-css-module.js.map +1 -1
  252. package/lib/utils/nextjs/ssr/transform-css-module.mjs.map +1 -1
  253. package/lib/utils/number.js.map +1 -1
  254. package/lib/utils/number.mjs.map +1 -1
  255. package/lib/utils/product.js +4 -4
  256. package/lib/utils/product.js.map +1 -1
  257. package/lib/utils/product.mjs +4 -4
  258. package/lib/utils/product.mjs.map +1 -1
  259. package/lib/utils/sales.d.ts +34 -0
  260. package/lib/utils/sales.js +113 -0
  261. package/lib/utils/sales.js.map +1 -0
  262. package/lib/utils/sales.mjs +99 -0
  263. package/lib/utils/sales.mjs.map +1 -0
  264. package/lib/utils/sales.test.d.ts +1 -0
  265. package/lib/utils/tags.js +2 -2
  266. package/lib/utils/tags.js.map +1 -1
  267. package/lib/utils/tags.mjs +2 -2
  268. package/lib/utils/tags.mjs.map +1 -1
  269. package/package.json +1 -1
  270. package/lib/helpers/ux.js +0 -53
  271. package/lib/helpers/ux.js.map +0 -1
  272. package/lib/helpers/ux.mjs +0 -49
  273. package/lib/helpers/ux.mjs.map +0 -1
@@ -1,88 +1,7 @@
1
1
  'use strict';
2
2
 
3
- var dayjs = require('dayjs');
4
- var duration = require('dayjs/plugin/duration');
5
- var timezone = require('dayjs/plugin/timezone');
6
- var utc = require('dayjs/plugin/utc');
7
- require('../types/index.js');
8
- var generated = require('../types/generated.js');
9
- function _interopDefault(e) {
10
- return e && e.__esModule ? e : {
11
- default: e
12
- };
13
- }
14
- var dayjs__default = /*#__PURE__*/_interopDefault(dayjs);
15
- var duration__default = /*#__PURE__*/_interopDefault(duration);
16
- var timezone__default = /*#__PURE__*/_interopDefault(timezone);
17
- var utc__default = /*#__PURE__*/_interopDefault(utc);
3
+ var sales = require('./sales.js');
18
4
  "use strict";
19
- dayjs.extend(timezone__default["default"]);
20
- dayjs.extend(duration__default["default"]);
21
- dayjs.extend(utc__default["default"]);
22
- const getStoreTimeZone = storeId => {
23
- switch (storeId) {
24
- case generated.StoreId.Br:
25
- return {
26
- label: "UTC-3",
27
- timezone: "America/Fortaleza"
28
- };
29
- case generated.StoreId.Uk:
30
- return {
31
- label: "GMT",
32
- timezone: "Etc/GMT"
33
- };
34
- case generated.StoreId.Eu:
35
- case generated.StoreId.Za:
36
- return {
37
- label: "EET",
38
- timezone: "EET"
39
- };
40
- case generated.StoreId.Me:
41
- return {
42
- label: "GST",
43
- timezone: "Asia/Dubai"
44
- };
45
- case generated.StoreId.Sg:
46
- return {
47
- label: "SGT",
48
- timezone: "Asia/Singapore"
49
- };
50
- case generated.StoreId.Tw:
51
- return {
52
- label: "CST",
53
- timezone: "Asia/Shanghai"
54
- };
55
- case generated.StoreId.Jp:
56
- return {
57
- label: "JST",
58
- timezone: "Asia/Tokyo"
59
- };
60
- case generated.StoreId.Ca:
61
- case generated.StoreId.Us:
62
- default:
63
- return {
64
- label: "PST",
65
- timezone: "US/Pacific"
66
- };
67
- }
68
- };
69
- const getTimeUntilEndOfBlackFridayByStore = storeId => {
70
- const {
71
- timezone: storeTimezone
72
- } = getStoreTimeZone(storeId);
73
- const now = dayjs__default["default"]().tz(storeTimezone);
74
- const endOfBlackFriday = dayjs__default["default"].tz("2024-12-02 23:59:59", storeTimezone);
75
- if (now.isAfter(endOfBlackFriday)) {
76
- return null;
77
- }
78
- const diff = dayjs__default["default"].duration(endOfBlackFriday.diff(now));
79
- return {
80
- days: diff.days(),
81
- hours: diff.hours(),
82
- minutes: diff.minutes(),
83
- seconds: diff.seconds()
84
- };
85
- };
86
- exports.getStoreTimeZone = getStoreTimeZone;
87
- exports.getTimeUntilEndOfBlackFridayByStore = getTimeUntilEndOfBlackFridayByStore;
5
+ exports.getStoreTimeZone = sales.getStoreTimeZone;
6
+ exports.getTimeUntilEndOfBlackFridayByStore = sales.getTimeUntilEndOfBlackFridayByStore;
88
7
  //# sourceMappingURL=blackFriday.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"blackFriday.js","sources":["../../src/utils/blackFriday.ts"],"sourcesContent":["import dayjs, { extend } from \"dayjs\";\nimport duration from \"dayjs/plugin/duration\";\nimport timezone from \"dayjs/plugin/timezone\";\nimport utc from \"dayjs/plugin/utc\";\n\nimport { StoreId } from \"../types\";\n\nextend(timezone);\nextend(duration);\nextend(utc);\n\n/**\n * Returns label and timezone for a given store according\n * to IANA timezone database\n */\nexport const getStoreTimeZone = (\n storeId: StoreId,\n): {\n label: string;\n timezone: string;\n} => {\n switch (storeId) {\n case StoreId.Br:\n return {\n label: \"UTC-3\",\n timezone: \"America/Fortaleza\",\n };\n case StoreId.Uk:\n return {\n label: \"GMT\",\n timezone: \"Etc/GMT\",\n };\n case StoreId.Eu:\n case StoreId.Za:\n return {\n label: \"EET\",\n timezone: \"EET\",\n };\n case StoreId.Me:\n return {\n label: \"GST\",\n timezone: \"Asia/Dubai\",\n };\n case StoreId.Sg:\n return {\n label: \"SGT\",\n timezone: \"Asia/Singapore\",\n };\n case StoreId.Tw:\n return {\n label: \"CST\",\n timezone: \"Asia/Shanghai\",\n };\n case StoreId.Jp:\n return {\n label: \"JST\",\n timezone: \"Asia/Tokyo\",\n };\n case StoreId.Ca:\n case StoreId.Us:\n default:\n return {\n label: \"PST\",\n timezone: \"US/Pacific\",\n };\n }\n};\n\nexport interface TimeLeft {\n days: number;\n hours: number;\n minutes: number;\n seconds: number;\n}\n\n/**\n * Returns the time left until the end of Black Friday for a given store\n * @returns {TimeLeft | null} TimeLeft object if it is still Black Friday, null otherwise\n */\nexport const getTimeUntilEndOfBlackFridayByStore = (\n storeId: StoreId,\n): TimeLeft | null => {\n const { timezone: storeTimezone } = getStoreTimeZone(storeId);\n\n const now = dayjs().tz(storeTimezone); // Current time in the store's timezone\n\n const endOfBlackFriday = dayjs.tz(\"2024-12-02 23:59:59\", storeTimezone); // Black Friday end in the store's timezone\n\n // If it is passed the end of Black Friday, return null\n if (now.isAfter(endOfBlackFriday)) {\n return null;\n }\n\n const diff = dayjs.duration(endOfBlackFriday.diff(now));\n\n return {\n days: diff.days(),\n hours: diff.hours(),\n minutes: diff.minutes(),\n seconds: diff.seconds(),\n };\n};\n"],"names":["extend","timezone","duration","utc","getStoreTimeZone","storeId","StoreId","Br","label","Uk","Eu","Za","Me","Sg","Tw","Jp","Ca","Us","getTimeUntilEndOfBlackFridayByStore","storeTimezone","now","dayjs","tz","endOfBlackFriday","isAfter","diff","days","hours","minutes","seconds"],"mappings":";;;;;;;;;;;;;;;;;;AAOAA,KAAA,CAAAA,MAAA,CAAOC,iBAAQ,CAAA,SAAA,CAAA,CAAA;AACfD,KAAA,CAAAA,MAAA,CAAOE,iBAAQ,CAAA,SAAA,CAAA,CAAA;AACfF,KAAA,CAAAA,MAAA,CAAOG,YAAG,CAAA,SAAA,CAAA,CAAA;AAMG,MAAAC,gBAAA,GACXC,OAIG,IAAA;EACH,QAAQA,OAAS;IACf,KAAKC,SAAQ,CAAAA,OAAA,CAAAC,EAAA;MACJ,OAAA;QACLC,KAAO,EAAA,OAAA;QACPP,QAAU,EAAA;MAAA,CACZ;IACF,KAAKK,SAAQ,CAAAA,OAAA,CAAAG,EAAA;MACJ,OAAA;QACLD,KAAO,EAAA,KAAA;QACPP,QAAU,EAAA;MAAA,CACZ;IACF,KAAKK,SAAAA,CAAAA,OAAQ,CAAAI,EAAA;IACb,KAAKJ,SAAQ,CAAAA,OAAA,CAAAK,EAAA;MACJ,OAAA;QACLH,KAAO,EAAA,KAAA;QACPP,QAAU,EAAA;MAAA,CACZ;IACF,KAAKK,SAAQ,CAAAA,OAAA,CAAAM,EAAA;MACJ,OAAA;QACLJ,KAAO,EAAA,KAAA;QACPP,QAAU,EAAA;MAAA,CACZ;IACF,KAAKK,SAAQ,CAAAA,OAAA,CAAAO,EAAA;MACJ,OAAA;QACLL,KAAO,EAAA,KAAA;QACPP,QAAU,EAAA;MAAA,CACZ;IACF,KAAKK,SAAQ,CAAAA,OAAA,CAAAQ,EAAA;MACJ,OAAA;QACLN,KAAO,EAAA,KAAA;QACPP,QAAU,EAAA;MAAA,CACZ;IACF,KAAKK,SAAQ,CAAAA,OAAA,CAAAS,EAAA;MACJ,OAAA;QACLP,KAAO,EAAA,KAAA;QACPP,QAAU,EAAA;MAAA,CACZ;IACF,KAAKK,SAAAA,CAAAA,OAAQ,CAAAU,EAAA;IACb,KAAKV,SAAAA,CAAAA,OAAQ,CAAAW,EAAA;IACb;MACS,OAAA;QACLT,KAAO,EAAA,KAAA;QACPP,QAAU,EAAA;MAAA,CACZ;EACJ;AACF,CAAA;AAaa,MAAAiB,mCAAA,GACXb,OACoB,IAAA;EACpB,MAAM;IAAEJ,QAAA,EAAUkB;EAAc,CAAA,GAAIf,iBAAiBC,OAAO,CAAA;EAE5D,MAAMe,GAAM,GAAAC,cAAA,CAAA,SAAA,CAAA,CAAA,CAAQ,CAAAC,EAAA,CAAGH,aAAa,CAAA;EAEpC,MAAMI,gBAAmB,GAAAF,cAAA,CAAA,SAAA,CAAA,CAAMC,EAAG,CAAA,qBAAA,EAAuBH,aAAa,CAAA;EAGlE,IAAAC,GAAA,CAAII,OAAQ,CAAAD,gBAAgB,CAAG,EAAA;IAC1B,OAAA,IAAA;EACT;EAEA,MAAME,OAAOJ,cAAAA,CAAAA,SAAAA,CAAM,CAAAnB,QAAA,CAASqB,gBAAiB,CAAAE,IAAA,CAAKL,GAAG,CAAC,CAAA;EAE/C,OAAA;IACLM,IAAA,EAAMD,KAAKC,IAAK,CAAA,CAAA;IAChBC,KAAA,EAAOF,KAAKE,KAAM,CAAA,CAAA;IAClBC,OAAA,EAASH,KAAKG,OAAQ,CAAA,CAAA;IACtBC,OAAA,EAASJ,KAAKI,OAAQ,CAAA;EAAA,CACxB;AACF,CAAA;;"}
1
+ {"version":3,"file":"blackFriday.js","sources":[],"sourcesContent":[],"names":[],"mappings":";;;;;"}
@@ -1,76 +1,3 @@
1
- import dayjs, { extend } from 'dayjs';
2
- import duration from 'dayjs/plugin/duration';
3
- import timezone from 'dayjs/plugin/timezone';
4
- import utc from 'dayjs/plugin/utc';
5
- import '../types/index.mjs';
6
- import { StoreId } from '../types/generated.mjs';
1
+ export { getStoreTimeZone, getTimeUntilEndOfBlackFridayByStore } from './sales.mjs';
7
2
  "use strict";
8
- extend(timezone);
9
- extend(duration);
10
- extend(utc);
11
- const getStoreTimeZone = storeId => {
12
- switch (storeId) {
13
- case StoreId.Br:
14
- return {
15
- label: "UTC-3",
16
- timezone: "America/Fortaleza"
17
- };
18
- case StoreId.Uk:
19
- return {
20
- label: "GMT",
21
- timezone: "Etc/GMT"
22
- };
23
- case StoreId.Eu:
24
- case StoreId.Za:
25
- return {
26
- label: "EET",
27
- timezone: "EET"
28
- };
29
- case StoreId.Me:
30
- return {
31
- label: "GST",
32
- timezone: "Asia/Dubai"
33
- };
34
- case StoreId.Sg:
35
- return {
36
- label: "SGT",
37
- timezone: "Asia/Singapore"
38
- };
39
- case StoreId.Tw:
40
- return {
41
- label: "CST",
42
- timezone: "Asia/Shanghai"
43
- };
44
- case StoreId.Jp:
45
- return {
46
- label: "JST",
47
- timezone: "Asia/Tokyo"
48
- };
49
- case StoreId.Ca:
50
- case StoreId.Us:
51
- default:
52
- return {
53
- label: "PST",
54
- timezone: "US/Pacific"
55
- };
56
- }
57
- };
58
- const getTimeUntilEndOfBlackFridayByStore = storeId => {
59
- const {
60
- timezone: storeTimezone
61
- } = getStoreTimeZone(storeId);
62
- const now = dayjs().tz(storeTimezone);
63
- const endOfBlackFriday = dayjs.tz("2024-12-02 23:59:59", storeTimezone);
64
- if (now.isAfter(endOfBlackFriday)) {
65
- return null;
66
- }
67
- const diff = dayjs.duration(endOfBlackFriday.diff(now));
68
- return {
69
- days: diff.days(),
70
- hours: diff.hours(),
71
- minutes: diff.minutes(),
72
- seconds: diff.seconds()
73
- };
74
- };
75
- export { getStoreTimeZone, getTimeUntilEndOfBlackFridayByStore };
76
3
  //# sourceMappingURL=blackFriday.mjs.map
@@ -1 +1 @@
1
- {"version":3,"file":"blackFriday.mjs","sources":["../../src/utils/blackFriday.ts"],"sourcesContent":["import dayjs, { extend } from \"dayjs\";\nimport duration from \"dayjs/plugin/duration\";\nimport timezone from \"dayjs/plugin/timezone\";\nimport utc from \"dayjs/plugin/utc\";\n\nimport { StoreId } from \"../types\";\n\nextend(timezone);\nextend(duration);\nextend(utc);\n\n/**\n * Returns label and timezone for a given store according\n * to IANA timezone database\n */\nexport const getStoreTimeZone = (\n storeId: StoreId,\n): {\n label: string;\n timezone: string;\n} => {\n switch (storeId) {\n case StoreId.Br:\n return {\n label: \"UTC-3\",\n timezone: \"America/Fortaleza\",\n };\n case StoreId.Uk:\n return {\n label: \"GMT\",\n timezone: \"Etc/GMT\",\n };\n case StoreId.Eu:\n case StoreId.Za:\n return {\n label: \"EET\",\n timezone: \"EET\",\n };\n case StoreId.Me:\n return {\n label: \"GST\",\n timezone: \"Asia/Dubai\",\n };\n case StoreId.Sg:\n return {\n label: \"SGT\",\n timezone: \"Asia/Singapore\",\n };\n case StoreId.Tw:\n return {\n label: \"CST\",\n timezone: \"Asia/Shanghai\",\n };\n case StoreId.Jp:\n return {\n label: \"JST\",\n timezone: \"Asia/Tokyo\",\n };\n case StoreId.Ca:\n case StoreId.Us:\n default:\n return {\n label: \"PST\",\n timezone: \"US/Pacific\",\n };\n }\n};\n\nexport interface TimeLeft {\n days: number;\n hours: number;\n minutes: number;\n seconds: number;\n}\n\n/**\n * Returns the time left until the end of Black Friday for a given store\n * @returns {TimeLeft | null} TimeLeft object if it is still Black Friday, null otherwise\n */\nexport const getTimeUntilEndOfBlackFridayByStore = (\n storeId: StoreId,\n): TimeLeft | null => {\n const { timezone: storeTimezone } = getStoreTimeZone(storeId);\n\n const now = dayjs().tz(storeTimezone); // Current time in the store's timezone\n\n const endOfBlackFriday = dayjs.tz(\"2024-12-02 23:59:59\", storeTimezone); // Black Friday end in the store's timezone\n\n // If it is passed the end of Black Friday, return null\n if (now.isAfter(endOfBlackFriday)) {\n return null;\n }\n\n const diff = dayjs.duration(endOfBlackFriday.diff(now));\n\n return {\n days: diff.days(),\n hours: diff.hours(),\n minutes: diff.minutes(),\n seconds: diff.seconds(),\n };\n};\n"],"names":["extend","timezone","duration","utc","getStoreTimeZone","storeId","StoreId","Br","label","Uk","Eu","Za","Me","Sg","Tw","Jp","Ca","Us","getTimeUntilEndOfBlackFridayByStore","storeTimezone","now","dayjs","tz","endOfBlackFriday","isAfter","diff","days","hours","minutes","seconds"],"mappings":";;;;;;;AAOAA,MAAA,CAAOC,QAAQ,CAAA;AACfD,MAAA,CAAOE,QAAQ,CAAA;AACfF,MAAA,CAAOG,GAAG,CAAA;AAMG,MAAAC,gBAAA,GACXC,OAIG,IAAA;EACH,QAAQA,OAAS;IACf,KAAKC,OAAQ,CAAAC,EAAA;MACJ,OAAA;QACLC,KAAO,EAAA,OAAA;QACPP,QAAU,EAAA;MAAA,CACZ;IACF,KAAKK,OAAQ,CAAAG,EAAA;MACJ,OAAA;QACLD,KAAO,EAAA,KAAA;QACPP,QAAU,EAAA;MAAA,CACZ;IACF,KAAKK,OAAQ,CAAAI,EAAA;IACb,KAAKJ,OAAQ,CAAAK,EAAA;MACJ,OAAA;QACLH,KAAO,EAAA,KAAA;QACPP,QAAU,EAAA;MAAA,CACZ;IACF,KAAKK,OAAQ,CAAAM,EAAA;MACJ,OAAA;QACLJ,KAAO,EAAA,KAAA;QACPP,QAAU,EAAA;MAAA,CACZ;IACF,KAAKK,OAAQ,CAAAO,EAAA;MACJ,OAAA;QACLL,KAAO,EAAA,KAAA;QACPP,QAAU,EAAA;MAAA,CACZ;IACF,KAAKK,OAAQ,CAAAQ,EAAA;MACJ,OAAA;QACLN,KAAO,EAAA,KAAA;QACPP,QAAU,EAAA;MAAA,CACZ;IACF,KAAKK,OAAQ,CAAAS,EAAA;MACJ,OAAA;QACLP,KAAO,EAAA,KAAA;QACPP,QAAU,EAAA;MAAA,CACZ;IACF,KAAKK,OAAQ,CAAAU,EAAA;IACb,KAAKV,OAAQ,CAAAW,EAAA;IACb;MACS,OAAA;QACLT,KAAO,EAAA,KAAA;QACPP,QAAU,EAAA;MAAA,CACZ;EACJ;AACF,CAAA;AAaa,MAAAiB,mCAAA,GACXb,OACoB,IAAA;EACpB,MAAM;IAAEJ,QAAA,EAAUkB;EAAc,CAAA,GAAIf,iBAAiBC,OAAO,CAAA;EAE5D,MAAMe,GAAM,GAAAC,KAAA,CAAA,CAAQ,CAAAC,EAAA,CAAGH,aAAa,CAAA;EAEpC,MAAMI,gBAAmB,GAAAF,KAAA,CAAMC,EAAG,CAAA,qBAAA,EAAuBH,aAAa,CAAA;EAGlE,IAAAC,GAAA,CAAII,OAAQ,CAAAD,gBAAgB,CAAG,EAAA;IAC1B,OAAA,IAAA;EACT;EAEA,MAAME,OAAOJ,KAAM,CAAAnB,QAAA,CAASqB,gBAAiB,CAAAE,IAAA,CAAKL,GAAG,CAAC,CAAA;EAE/C,OAAA;IACLM,IAAA,EAAMD,KAAKC,IAAK,CAAA,CAAA;IAChBC,KAAA,EAAOF,KAAKE,KAAM,CAAA,CAAA;IAClBC,OAAA,EAASH,KAAKG,OAAQ,CAAA,CAAA;IACtBC,OAAA,EAASJ,KAAKI,OAAQ,CAAA;EAAA,CACxB;AACF,CAAA;"}
1
+ {"version":3,"file":"blackFriday.mjs","sources":[],"sourcesContent":[],"names":[],"mappings":";"}
@@ -6,8 +6,8 @@ const getCollectionSlugFromPath = path => {
6
6
  if (!path) {
7
7
  return "";
8
8
  }
9
- const match = path.match(COLLECTION_SLUG_REGEX);
10
- return match?.[2] || "";
9
+ const match = COLLECTION_SLUG_REGEX.exec(path);
10
+ return match?.[2] ?? "";
11
11
  };
12
12
  exports.getCollectionSlugFromPath = getCollectionSlugFromPath;
13
13
  //# sourceMappingURL=collectionSlug.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"collectionSlug.js","sources":["../../src/utils/collectionSlug.ts"],"sourcesContent":["import type { Nullish } from \"../types\";\n\nconst COLLECTION_SLUG_REGEX = /(\\/)?collections\\/(.*)/;\n\n/**\n * Extracts the collection slug from a path\n */\nexport const getCollectionSlugFromPath = (path: Nullish<string>): string => {\n if (!path) {\n return \"\";\n }\n\n const match = path.match(COLLECTION_SLUG_REGEX);\n return match?.[2] || \"\";\n};\n"],"names":["COLLECTION_SLUG_REGEX","getCollectionSlugFromPath","path","match"],"mappings":";;;AAEA,MAAMA,qBAAwB,GAAA,wBAAA;AAKjB,MAAAC,yBAAA,GAA6BC,IAAkC,IAAA;EAC1E,IAAI,CAACA,IAAM,EAAA;IACF,OAAA,EAAA;EACT;EAEM,MAAAC,KAAA,GAAQD,IAAK,CAAAC,KAAA,CAAMH,qBAAqB,CAAA;EACvC,OAAAG,KAAA,GAAQ,CAAC,CAAK,IAAA,EAAA;AACvB,CAAA;"}
1
+ {"version":3,"file":"collectionSlug.js","sources":["../../src/utils/collectionSlug.ts"],"sourcesContent":["import type { Nullish } from \"../types\";\n\nconst COLLECTION_SLUG_REGEX = /(\\/)?collections\\/(.*)/;\n\n/**\n * Extracts the collection slug from a path\n */\nexport const getCollectionSlugFromPath = (path: Nullish<string>): string => {\n if (!path) {\n return \"\";\n }\n\n const match = COLLECTION_SLUG_REGEX.exec(path);\n return match?.[2] ?? \"\";\n};\n"],"names":["COLLECTION_SLUG_REGEX","getCollectionSlugFromPath","path","match","exec"],"mappings":";;;AAEA,MAAMA,qBAAwB,GAAA,wBAAA;AAKjB,MAAAC,yBAAA,GAA6BC,IAAkC,IAAA;EAC1E,IAAI,CAACA,IAAM,EAAA;IACF,OAAA,EAAA;EACT;EAEM,MAAAC,KAAA,GAAQH,qBAAsB,CAAAI,IAAA,CAAKF,IAAI,CAAA;EACtC,OAAAC,KAAA,GAAQ,CAAC,CAAK,IAAA,EAAA;AACvB,CAAA;"}
@@ -5,8 +5,8 @@ const getCollectionSlugFromPath = path => {
5
5
  if (!path) {
6
6
  return "";
7
7
  }
8
- const match = path.match(COLLECTION_SLUG_REGEX);
9
- return match?.[2] || "";
8
+ const match = COLLECTION_SLUG_REGEX.exec(path);
9
+ return match?.[2] ?? "";
10
10
  };
11
11
  export { getCollectionSlugFromPath };
12
12
  //# sourceMappingURL=collectionSlug.mjs.map
@@ -1 +1 @@
1
- {"version":3,"file":"collectionSlug.mjs","sources":["../../src/utils/collectionSlug.ts"],"sourcesContent":["import type { Nullish } from \"../types\";\n\nconst COLLECTION_SLUG_REGEX = /(\\/)?collections\\/(.*)/;\n\n/**\n * Extracts the collection slug from a path\n */\nexport const getCollectionSlugFromPath = (path: Nullish<string>): string => {\n if (!path) {\n return \"\";\n }\n\n const match = path.match(COLLECTION_SLUG_REGEX);\n return match?.[2] || \"\";\n};\n"],"names":["COLLECTION_SLUG_REGEX","getCollectionSlugFromPath","path","match"],"mappings":";;AAEA,MAAMA,qBAAwB,GAAA,wBAAA;AAKjB,MAAAC,yBAAA,GAA6BC,IAAkC,IAAA;EAC1E,IAAI,CAACA,IAAM,EAAA;IACF,OAAA,EAAA;EACT;EAEM,MAAAC,KAAA,GAAQD,IAAK,CAAAC,KAAA,CAAMH,qBAAqB,CAAA;EACvC,OAAAG,KAAA,GAAQ,CAAC,CAAK,IAAA,EAAA;AACvB,CAAA;"}
1
+ {"version":3,"file":"collectionSlug.mjs","sources":["../../src/utils/collectionSlug.ts"],"sourcesContent":["import type { Nullish } from \"../types\";\n\nconst COLLECTION_SLUG_REGEX = /(\\/)?collections\\/(.*)/;\n\n/**\n * Extracts the collection slug from a path\n */\nexport const getCollectionSlugFromPath = (path: Nullish<string>): string => {\n if (!path) {\n return \"\";\n }\n\n const match = COLLECTION_SLUG_REGEX.exec(path);\n return match?.[2] ?? \"\";\n};\n"],"names":["COLLECTION_SLUG_REGEX","getCollectionSlugFromPath","path","match","exec"],"mappings":";;AAEA,MAAMA,qBAAwB,GAAA,wBAAA;AAKjB,MAAAC,yBAAA,GAA6BC,IAAkC,IAAA;EAC1E,IAAI,CAACA,IAAM,EAAA;IACF,OAAA,EAAA;EACT;EAEM,MAAAC,KAAA,GAAQH,qBAAsB,CAAAI,IAAA,CAAKF,IAAI,CAAA;EACtC,OAAAC,KAAA,GAAQ,CAAC,CAAK,IAAA,EAAA;AACvB,CAAA;"}
@@ -1 +1 @@
1
- {"version":3,"file":"errors.js","sources":["../../src/utils/errors.ts"],"sourcesContent":["/**\n * Throw on falsy helper\n */\nexport function assert(\n condition: boolean,\n message = \"'condition' is falsy.\",\n ErrorClass: new (message: string) => void = Error,\n): asserts condition {\n if (!condition) {\n throw new ErrorClass(message);\n }\n}\n\n/**\n * Ensures that the path where this function is used will never be reached.\n * Useful for exhausted switch..case..default checks\n * For more info see https://tinytip.co/tips/ts-switch-assert-unreachable/\n * @throws {Error}\n */\n//eslint-disable-next-line @typescript-eslint/no-unused-vars\nexport function assertUnreachable(_value: never): never {\n throw new Error(\"Statement should be unreachable\");\n}\n\n/**\n * Similar `assertUnreachable` but instead of throwing an error if called it just calls adds type-guards for some cases\n * where we want switch-case type-safety but still want some controlled fallback mechanism. Especially useful in\n * scenario's where we work with \"unknowns\" from errors, api-responses, etc\n *\n * @example\n * enum MyEnum {\n * A = 'a',\n * B = 'b'\n * }\n *\n * switch (myEnumLikeInput) {\n * case MyEnum.A: return 'a';\n * // Explicitly missing \"case MyEnum.B: ...\"\n * default: {\n * checkUnreachable(myEnumLikeInput); // Typescript fill show error \"Argument of type 'MyEnum' is not assignable to parameter of type 'never'.\" as we didn't process `MyEnum.B`\n * return 'c';\n * }\n * }\n */\n// eslint-disable-next-line @typescript-eslint/no-empty-function, @typescript-eslint/no-unused-vars\nexport function checkUnreachable(_value: never): void {}\n\n/**\n * Semi-util that needs to be used together with Difference util type to ensure that in type-system two given objects\n * are the same shape\n *\n * @example\n * assertTypeEquality<Difference<{a: string}, {a: string}>>(); // OK\n * assertTypeEquality<Difference<{a: string, b: number}, {a: string, c: boolean}>>(); // Throws error\n */\n// @ts-expect-error Ignore unused generic parameter\n// eslint-disable-next-line @typescript-eslint/no-unused-vars\nexport function assertTypeEquality<T extends never>(): void {}\n"],"names":["assert","condition","message","ErrorClass","Error","assertUnreachable","_value","checkUnreachable","assertTypeEquality"],"mappings":";;;AAGO,SAASA,MACdA,CAAAC,SAAA,EACAC,OAAU,GAAA,uBAAA,EACVC,aAA4CC,KACzB,EAAA;EACnB,IAAI,CAACH,SAAW,EAAA;IACR,MAAA,IAAIE,WAAWD,OAAO,CAAA;EAC9B;AACF;AASO,SAASG,kBAAkBC,MAAsB,EAAA;EAChD,MAAA,IAAIF,MAAM,iCAAiC,CAAA;AACnD;AAuBO,SAASG,iBAAiBD,MAAqB,EAAA,CAAC;AAYhD,SAASE,kBAA4CA,CAAA,EAAA,CAAC;;;;"}
1
+ {"version":3,"file":"errors.js","sources":["../../src/utils/errors.ts"],"sourcesContent":["/**\n * Throw on falsy helper\n */\nexport function assert(\n condition: boolean,\n message = \"'condition' is falsy.\",\n ErrorClass: new (message: string) => void = Error,\n): asserts condition {\n if (!condition) {\n throw new ErrorClass(message);\n }\n}\n\n/**\n * Ensures that the path where this function is used will never be reached.\n * Useful for exhausted switch..case..default checks\n * For more info see https://tinytip.co/tips/ts-switch-assert-unreachable/\n * @throws {Error}\n */\n//eslint-disable-next-line @typescript-eslint/no-unused-vars\nexport function assertUnreachable(_value: never): never {\n throw new Error(\"Statement should be unreachable\");\n}\n\n/**\n * Similar `assertUnreachable` but instead of throwing an error if called it just calls adds type-guards for some cases\n * where we want switch-case type-safety but still want some controlled fallback mechanism. Especially useful in\n * scenario's where we work with \"unknowns\" from errors, api-responses, etc\n *\n * @example\n * enum MyEnum {\n * A = 'a',\n * B = 'b'\n * }\n *\n * switch (myEnumLikeInput) {\n * case MyEnum.A: return 'a';\n * // Explicitly missing \"case MyEnum.B: ...\"\n * default: {\n * checkUnreachable(myEnumLikeInput); // Typescript fill show error \"Argument of type 'MyEnum' is not assignable to parameter of type 'never'.\" as we didn't process `MyEnum.B`\n * return 'c';\n * }\n * }\n */\n// eslint-disable-next-line @typescript-eslint/no-empty-function, @typescript-eslint/no-unused-vars\nexport function checkUnreachable(_value: never): void {\n /* Intentional empty function as just for type assertion */\n}\n\n/**\n * Semi-util that needs to be used together with Difference util type to ensure that in type-system two given objects\n * are the same shape\n *\n * @example\n * assertTypeEquality<Difference<{a: string}, {a: string}>>(); // OK\n * assertTypeEquality<Difference<{a: string, b: number}, {a: string, c: boolean}>>(); // Throws error\n */\n// @ts-expect-error Ignore unused generic parameter\n// eslint-disable-next-line @typescript-eslint/no-unused-vars\nexport function assertTypeEquality<T extends never>(): void {\n /* Intentional empty function as just for type assertion */\n}\n"],"names":["assert","condition","message","ErrorClass","Error","assertUnreachable","_value","checkUnreachable","assertTypeEquality"],"mappings":";;;AAGO,SAASA,MACdA,CAAAC,SAAA,EACAC,OAAU,GAAA,uBAAA,EACVC,aAA4CC,KACzB,EAAA;EACnB,IAAI,CAACH,SAAW,EAAA;IACR,MAAA,IAAIE,WAAWD,OAAO,CAAA;EAC9B;AACF;AASO,SAASG,kBAAkBC,MAAsB,EAAA;EAChD,MAAA,IAAIF,MAAM,iCAAiC,CAAA;AACnD;AAuBO,SAASG,iBAAiBD,MAAqB,EAAA,CAEtD;AAYO,SAASE,kBAA4CA,CAAA,EAAA,CAE5D;;;;"}
@@ -1 +1 @@
1
- {"version":3,"file":"errors.mjs","sources":["../../src/utils/errors.ts"],"sourcesContent":["/**\n * Throw on falsy helper\n */\nexport function assert(\n condition: boolean,\n message = \"'condition' is falsy.\",\n ErrorClass: new (message: string) => void = Error,\n): asserts condition {\n if (!condition) {\n throw new ErrorClass(message);\n }\n}\n\n/**\n * Ensures that the path where this function is used will never be reached.\n * Useful for exhausted switch..case..default checks\n * For more info see https://tinytip.co/tips/ts-switch-assert-unreachable/\n * @throws {Error}\n */\n//eslint-disable-next-line @typescript-eslint/no-unused-vars\nexport function assertUnreachable(_value: never): never {\n throw new Error(\"Statement should be unreachable\");\n}\n\n/**\n * Similar `assertUnreachable` but instead of throwing an error if called it just calls adds type-guards for some cases\n * where we want switch-case type-safety but still want some controlled fallback mechanism. Especially useful in\n * scenario's where we work with \"unknowns\" from errors, api-responses, etc\n *\n * @example\n * enum MyEnum {\n * A = 'a',\n * B = 'b'\n * }\n *\n * switch (myEnumLikeInput) {\n * case MyEnum.A: return 'a';\n * // Explicitly missing \"case MyEnum.B: ...\"\n * default: {\n * checkUnreachable(myEnumLikeInput); // Typescript fill show error \"Argument of type 'MyEnum' is not assignable to parameter of type 'never'.\" as we didn't process `MyEnum.B`\n * return 'c';\n * }\n * }\n */\n// eslint-disable-next-line @typescript-eslint/no-empty-function, @typescript-eslint/no-unused-vars\nexport function checkUnreachable(_value: never): void {}\n\n/**\n * Semi-util that needs to be used together with Difference util type to ensure that in type-system two given objects\n * are the same shape\n *\n * @example\n * assertTypeEquality<Difference<{a: string}, {a: string}>>(); // OK\n * assertTypeEquality<Difference<{a: string, b: number}, {a: string, c: boolean}>>(); // Throws error\n */\n// @ts-expect-error Ignore unused generic parameter\n// eslint-disable-next-line @typescript-eslint/no-unused-vars\nexport function assertTypeEquality<T extends never>(): void {}\n"],"names":["assert","condition","message","ErrorClass","Error","assertUnreachable","_value","checkUnreachable","assertTypeEquality"],"mappings":";;AAGO,SAASA,MACdA,CAAAC,SAAA,EACAC,OAAU,GAAA,uBAAA,EACVC,aAA4CC,KACzB,EAAA;EACnB,IAAI,CAACH,SAAW,EAAA;IACR,MAAA,IAAIE,WAAWD,OAAO,CAAA;EAC9B;AACF;AASO,SAASG,kBAAkBC,MAAsB,EAAA;EAChD,MAAA,IAAIF,MAAM,iCAAiC,CAAA;AACnD;AAuBO,SAASG,iBAAiBD,MAAqB,EAAA,CAAC;AAYhD,SAASE,kBAA4CA,CAAA,EAAA,CAAC;"}
1
+ {"version":3,"file":"errors.mjs","sources":["../../src/utils/errors.ts"],"sourcesContent":["/**\n * Throw on falsy helper\n */\nexport function assert(\n condition: boolean,\n message = \"'condition' is falsy.\",\n ErrorClass: new (message: string) => void = Error,\n): asserts condition {\n if (!condition) {\n throw new ErrorClass(message);\n }\n}\n\n/**\n * Ensures that the path where this function is used will never be reached.\n * Useful for exhausted switch..case..default checks\n * For more info see https://tinytip.co/tips/ts-switch-assert-unreachable/\n * @throws {Error}\n */\n//eslint-disable-next-line @typescript-eslint/no-unused-vars\nexport function assertUnreachable(_value: never): never {\n throw new Error(\"Statement should be unreachable\");\n}\n\n/**\n * Similar `assertUnreachable` but instead of throwing an error if called it just calls adds type-guards for some cases\n * where we want switch-case type-safety but still want some controlled fallback mechanism. Especially useful in\n * scenario's where we work with \"unknowns\" from errors, api-responses, etc\n *\n * @example\n * enum MyEnum {\n * A = 'a',\n * B = 'b'\n * }\n *\n * switch (myEnumLikeInput) {\n * case MyEnum.A: return 'a';\n * // Explicitly missing \"case MyEnum.B: ...\"\n * default: {\n * checkUnreachable(myEnumLikeInput); // Typescript fill show error \"Argument of type 'MyEnum' is not assignable to parameter of type 'never'.\" as we didn't process `MyEnum.B`\n * return 'c';\n * }\n * }\n */\n// eslint-disable-next-line @typescript-eslint/no-empty-function, @typescript-eslint/no-unused-vars\nexport function checkUnreachable(_value: never): void {\n /* Intentional empty function as just for type assertion */\n}\n\n/**\n * Semi-util that needs to be used together with Difference util type to ensure that in type-system two given objects\n * are the same shape\n *\n * @example\n * assertTypeEquality<Difference<{a: string}, {a: string}>>(); // OK\n * assertTypeEquality<Difference<{a: string, b: number}, {a: string, c: boolean}>>(); // Throws error\n */\n// @ts-expect-error Ignore unused generic parameter\n// eslint-disable-next-line @typescript-eslint/no-unused-vars\nexport function assertTypeEquality<T extends never>(): void {\n /* Intentional empty function as just for type assertion */\n}\n"],"names":["assert","condition","message","ErrorClass","Error","assertUnreachable","_value","checkUnreachable","assertTypeEquality"],"mappings":";;AAGO,SAASA,MACdA,CAAAC,SAAA,EACAC,OAAU,GAAA,uBAAA,EACVC,aAA4CC,KACzB,EAAA;EACnB,IAAI,CAACH,SAAW,EAAA;IACR,MAAA,IAAIE,WAAWD,OAAO,CAAA;EAC9B;AACF;AASO,SAASG,kBAAkBC,MAAsB,EAAA;EAChD,MAAA,IAAIF,MAAM,iCAAiC,CAAA;AACnD;AAuBO,SAASG,iBAAiBD,MAAqB,EAAA,CAEtD;AAYO,SAASE,kBAA4CA,CAAA,EAAA,CAE5D;"}
@@ -21,3 +21,4 @@ export * as imageOptimizer from "./imageOptimizer";
21
21
  export * as styles from "./styles";
22
22
  export * as storeId from "./storeId";
23
23
  export * as blackFriday from "./blackFriday";
24
+ export * as sales from "./sales";
@@ -23,6 +23,7 @@ var imageOptimizer$1 = require('./imageOptimizer.js');
23
23
  var styles$1 = require('./styles.js');
24
24
  var storeId$1 = require('./storeId.js');
25
25
  var blackFriday$1 = require('./blackFriday.js');
26
+ var sales$1 = require('./sales.js');
26
27
  "use strict";
27
28
  exports.url = url$1;
28
29
  exports.money = misc;
@@ -47,4 +48,5 @@ exports.imageOptimizer = imageOptimizer$1;
47
48
  exports.styles = styles$1;
48
49
  exports.storeId = storeId$1;
49
50
  exports.blackFriday = blackFriday$1;
51
+ exports.sales = sales$1;
50
52
  //# sourceMappingURL=index.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"index.js","sources":[],"sourcesContent":[],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;"}
1
+ {"version":3,"file":"index.js","sources":[],"sourcesContent":[],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;"}
@@ -44,5 +44,7 @@ import * as storeId$1 from './storeId.mjs';
44
44
  export { storeId$1 as storeId };
45
45
  import * as blackFriday$1 from './blackFriday.mjs';
46
46
  export { blackFriday$1 as blackFriday };
47
+ import * as sales$1 from './sales.mjs';
48
+ export { sales$1 as sales };
47
49
  "use strict";
48
50
  //# sourceMappingURL=index.mjs.map
@@ -1 +1 @@
1
- {"version":3,"file":"index.mjs","sources":[],"sourcesContent":[],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;"}
1
+ {"version":3,"file":"index.mjs","sources":[],"sourcesContent":[],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;"}
@@ -35,6 +35,7 @@ const dineroBigint = dinero_js.createDinero({
35
35
  });
36
36
  const DINERO_WEIGHT_G = {
37
37
  code: "WEIGHT_G",
38
+ // eslint-disable-next-line sonarjs/inconsistent-function-call
38
39
  base: big_js.Big(10),
39
40
  exponent: big_js.Big(0)
40
41
  };
@@ -1 +1 @@
1
- {"version":3,"file":"measures.js","sources":["../../src/utils/measures.ts"],"sourcesContent":["import { Big } from \"big.js\";\nimport type {\n LengthSystems,\n LengthUnits,\n MassSystems,\n MassUnits,\n} from \"convert-units\";\nimport configureMeasurements, { length, mass } from \"convert-units\";\nimport type { Calculator, ComparisonOperator, Transformer } from \"dinero.js\";\nimport { createDinero, toFormat } from \"dinero.js\";\n\nimport { UnitSystem } from \"../types\";\nimport { assert, assertUnreachable } from \"./errors\";\n\n// Measures: The names of the measures being used\ntype Measures = \"length\" | \"mass\";\n// Systems: The systems being used across all measures\ntype Systems = LengthSystems | MassSystems;\n// Units: All the units across all measures and their systems\ntype Units = LengthUnits | MassUnits;\n\nexport const convert = configureMeasurements<Measures, Systems, Units>({\n length,\n mass,\n});\n\nconst calculator: Calculator<Big> = {\n add: (a, b) => a.plus(b),\n compare: (a, b) => a.cmp(b) as unknown as ComparisonOperator,\n decrement: (v) => v.minus(new Big(1)),\n increment: (v) => v.plus(new Big(1)),\n integerDivide: (a, b) => a.div(b).round(0, Big.roundDown),\n modulo: (a, b) => a.mod(b),\n multiply: (a, b) => a.times(b),\n power: (a, b) => a.pow(Number(b)),\n subtract: (a, b) => a.minus(b),\n zero: () => new Big(0),\n toNumber: () => NaN,\n};\n\nconst dineroBigint = createDinero({ calculator });\n\n// type ConvertMassFromTo =\n// | { from: Unit.G; to: Unit.Kg }\n// | { from: Unit.Kg; to: Unit. }\n// | { from: Unit.G; to: Unit.Kg }\n// | { from: Unit.G; to: Unit.Kg }\n// | { from: Unit.G; to: Unit.Kg }\n// | { from: Unit.G; to: Unit.Kg }\n// export const convertMass = (value: number, {from, to}: ConvertMassFromTo) => {\n// return convert(value).from(from).to(to)\n// }\n\nconst DINERO_WEIGHT_G = {\n code: \"WEIGHT_G\",\n base: Big(10),\n exponent: Big(0),\n};\nconst DINERO_WEIGHT_OZ = {\n code: \"WEIGHT_OZ\",\n base: Big(10),\n exponent: Big(6),\n};\n\ntype TransformerOptions = Parameters<Transformer<Big>>[0];\nconst transformer = ({ currency, dineroObject }: TransformerOptions) => {\n const exponent = currency.exponent;\n const multiplier = Big(0.1).pow(exponent.toNumber());\n\n const jsonObject = dineroObject.toJSON();\n const formattedWeight = jsonObject.amount\n .mul(multiplier)\n .toFixed(exponent.toNumber());\n\n return formattedWeight.toString();\n};\n\n/**\n * In database we store weight in \"weird\" format.\n * For metric we store weight in grams as is.\n * For imperial we store weight in oz with \"virtual scale/exponent\" => 6.\n * e.g. 1_000_000 => '1'\n * e.g. 300_000 => '0.3'\n *\n * Database weight is stored either in g or oz\n */\nexport const transformDatabaseWeightToFormat = (\n databaseWeight: string,\n system: UnitSystem,\n): string => {\n switch (system) {\n case UnitSystem.Metric:\n return toFormat(\n dineroBigint({\n amount: Big(databaseWeight),\n currency: DINERO_WEIGHT_G,\n }),\n transformer,\n );\n case UnitSystem.Imperial: {\n return toFormat(\n dineroBigint({\n amount: Big(databaseWeight),\n currency: DINERO_WEIGHT_OZ,\n }),\n transformer,\n );\n }\n default:\n assertUnreachable(system);\n }\n};\n\n/**\n * Executes transformDatabaseWeightToFormat and returns it as number if safe integer\n *\n * Database weight is stored either in g or oz\n */\nexport const transformDatabaseWeightToNumber = (\n databaseWeight: string,\n system: UnitSystem,\n): number => {\n const formattedBig = Big(\n transformDatabaseWeightToFormat(databaseWeight, system),\n );\n\n assert(\n formattedBig.lte(Number.MAX_SAFE_INTEGER),\n \"Weight is not in safe integer range\",\n );\n return parseFloat(formattedBig.toString());\n};\n\n/**\n * Prepares floating number to be stored in database as normalized bigint\n *\n * Database weights are stored either in g or oz\n */\nexport const transformNumberToDatabaseWeight = (\n numberWeight: number,\n system: UnitSystem,\n): string => {\n switch (system) {\n case UnitSystem.Metric: {\n /**\n * convert(1).from(oz).to(g) is 28.34952g.\n * We are stripping sub-gram measures, because database is storing grams\n */\n const numberWeightInt = parseInt(numberWeight.toFixed(0));\n\n assert(\n !!Number.isSafeInteger(numberWeightInt),\n \"Number is not safe integer\",\n );\n\n return numberWeightInt.toString();\n }\n case UnitSystem.Imperial: {\n const weightBig = Big(numberWeight);\n const multiplier = Big(10).pow(DINERO_WEIGHT_OZ.exponent.toNumber());\n return weightBig.mul(multiplier).toFixed(0);\n }\n default:\n assertUnreachable(system);\n }\n};\n\n/**\n * Shorthand function to transform weight number to formatted string.\n *\n * ! Use only with base weights g/oz\n */\nexport const transformBaseWeightNumberToFormat = (\n databaseWeight: number,\n system: UnitSystem,\n): string =>\n transformDatabaseWeightToFormat(\n transformNumberToDatabaseWeight(databaseWeight, system),\n system,\n );\n"],"names":["convert","configureMeasurements","length","mass","calculator","add","a","b","plus","compare","cmp","decrement","v","minus","Big","increment","integerDivide","div","round","roundDown","modulo","mod","multiply","times","power","pow","Number","subtract","zero","toNumber","NaN","dineroBigint","createDinero","DINERO_WEIGHT_G","code","base","exponent","DINERO_WEIGHT_OZ","transformer","currency","dineroObject","multiplier","jsonObject","toJSON","formattedWeight","amount","mul","toFixed","toString","transformDatabaseWeightToFormat","databaseWeight","system","UnitSystem","Metric","toFormat","Imperial","assertUnreachable","transformDatabaseWeightToNumber","formattedBig","assert","lte","MAX_SAFE_INTEGER","parseFloat","transformNumberToDatabaseWeight","numberWeight","numberWeightInt","parseInt","isSafeInteger","weightBig","transformBaseWeightNumberToFormat"],"mappings":";;;;;;;;;;;;;;;AAqBO,MAAMA,UAAUC,8BAAAA,CAAAA,SAAAA,CAAgD,CAAA;EAAAC,MAAA,EACrEA,qBAAA,CAAAA,MAAA;EAAAC,IAAA,EACAA,qBAAA,CAAAA;AACF,CAAC,CAAA;AAED,MAAMC,UAA8B,GAAA;EAClCC,KAAKA,CAACC,CAAA,EAAGC,CAAM,KAAAD,CAAA,CAAEE,KAAKD,CAAC,CAAA;EACvBE,SAASA,CAACH,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mC,gBAAgB,CAAA,EACxC,qCAAA,CACF;EACO,OAAAC,UAAA,CAAWJ,YAAa,CAAAV,QAAA,CAAA,CAAU,CAAA;AAC3C,CAAA;AAOa,MAAAe,+BAAA,GAAkCA,CAC7CC,YAAA,EACAb,MACW,KAAA;EACX,QAAQA,MAAQ;IACd,KAAKC,SAAAA,CAAAA,WAAWC,MAAQ;MAAA;QAKtB,MAAMY,eAAkB,GAAAC,QAAA,CAASF,YAAa,CAAAjB,OAAA,CAAQ,CAAC,CAAC,CAAA;QAExDY,MAAA,CAAAA,MAAA,CACE,CAAC,CAACjC,MAAO,CAAAyC,aAAA,CAAcF,eAAe,CAAA,EACtC,4BAAA,CACF;QAEA,OAAOA,gBAAgBjB,QAAS,EAAA;MAClC;IACA,KAAKI,SAAAA,CAAAA,WAAWG,QAAU;MAAA;QAClB,MAAAa,SAAA,GAAYtD,WAAIkD,YAAY,CAAA;QAC5B,MAAAvB,UAAA,GAAa3B,WAAI,EAAE,CAAA,CAAEW,IAAIY,gBAAiB,CAAAD,QAAA,CAASP,UAAU,CAAA;QACnE,OAAOuC,SAAU,CAAAtB,GAAA,CAAIL,UAAU,CAAA,CAAEM,QAAQ,CAAC,CAAA;MAC5C;IACA;MACES,MAAA,CAAAA,iBAAA,CAAkBL,MAAM,CAAA;EAC5B;AACF,CAAA;AAOa,MAAAkB,iCAAA,GAAoCA,CAC/CnB,cAAA,EACAC,MAEA,KAAAF,+BAAA,CACEc,+BAAA,CAAgCb,gBAAgBC,MAAM,CAAA,EACtDA,MACF,CAAA;;;;;"}
1
+ {"version":3,"file":"measures.js","sources":["../../src/utils/measures.ts"],"sourcesContent":["import { Big } from \"big.js\";\nimport type {\n LengthSystems,\n LengthUnits,\n MassSystems,\n MassUnits,\n} from \"convert-units\";\nimport configureMeasurements, { length, mass } from \"convert-units\";\nimport type { Calculator, ComparisonOperator, Transformer } from \"dinero.js\";\nimport { createDinero, toFormat } from \"dinero.js\";\n\nimport { UnitSystem } from \"../types\";\nimport { assert, assertUnreachable } from \"./errors\";\n\n// Measures: The names of the measures being used\ntype Measures = \"length\" | \"mass\";\n// Systems: The systems being used across all measures\ntype Systems = LengthSystems | MassSystems;\n// Units: All the units across all measures and their systems\ntype Units = LengthUnits | MassUnits;\n\nexport const convert = configureMeasurements<Measures, Systems, Units>({\n length,\n mass,\n});\n\nconst calculator: Calculator<Big> = {\n add: (a, b) => a.plus(b),\n compare: (a, b) => a.cmp(b) as unknown as ComparisonOperator,\n decrement: (v) => v.minus(new Big(1)),\n increment: (v) => v.plus(new Big(1)),\n integerDivide: (a, b) => a.div(b).round(0, Big.roundDown),\n modulo: (a, b) => a.mod(b),\n multiply: (a, b) => a.times(b),\n power: (a, b) => a.pow(Number(b)),\n subtract: (a, b) => a.minus(b),\n zero: () => new Big(0),\n toNumber: () => NaN,\n};\n\nconst dineroBigint = createDinero({ calculator });\n\n// type ConvertMassFromTo =\n// | { from: Unit.G; to: Unit.Kg }\n// | { from: Unit.Kg; to: Unit. }\n// | { from: Unit.G; to: Unit.Kg }\n// | { from: Unit.G; to: Unit.Kg }\n// | { from: Unit.G; to: Unit.Kg }\n// | { from: Unit.G; to: Unit.Kg }\n// export const convertMass = (value: number, {from, to}: ConvertMassFromTo) => {\n// return convert(value).from(from).to(to)\n// }\n\nconst DINERO_WEIGHT_G = {\n code: \"WEIGHT_G\",\n // eslint-disable-next-line sonarjs/inconsistent-function-call\n base: Big(10),\n exponent: Big(0),\n};\nconst DINERO_WEIGHT_OZ = {\n code: \"WEIGHT_OZ\",\n base: Big(10),\n exponent: Big(6),\n};\n\ntype TransformerOptions = Parameters<Transformer<Big>>[0];\nconst transformer = ({ currency, dineroObject }: TransformerOptions) => {\n const exponent = currency.exponent;\n const multiplier = Big(0.1).pow(exponent.toNumber());\n\n const jsonObject = dineroObject.toJSON();\n const formattedWeight = jsonObject.amount\n .mul(multiplier)\n .toFixed(exponent.toNumber());\n\n return formattedWeight.toString();\n};\n\n/**\n * In database we store weight in \"weird\" format.\n * For metric we store weight in grams as is.\n * For imperial we store weight in oz with \"virtual scale/exponent\" => 6.\n * e.g. 1_000_000 => '1'\n * e.g. 300_000 => '0.3'\n *\n * Database weight is stored either in g or oz\n */\nexport const transformDatabaseWeightToFormat = (\n databaseWeight: string,\n system: UnitSystem,\n): string => {\n switch (system) {\n case UnitSystem.Metric:\n return toFormat(\n dineroBigint({\n amount: Big(databaseWeight),\n currency: DINERO_WEIGHT_G,\n }),\n transformer,\n );\n case UnitSystem.Imperial: {\n return toFormat(\n dineroBigint({\n amount: Big(databaseWeight),\n currency: DINERO_WEIGHT_OZ,\n }),\n transformer,\n );\n }\n default:\n assertUnreachable(system);\n }\n};\n\n/**\n * Executes transformDatabaseWeightToFormat and returns it as number if safe integer\n *\n * Database weight is stored either in g or oz\n */\nexport const transformDatabaseWeightToNumber = (\n databaseWeight: string,\n system: UnitSystem,\n): number => {\n const formattedBig = Big(\n transformDatabaseWeightToFormat(databaseWeight, system),\n );\n\n assert(\n formattedBig.lte(Number.MAX_SAFE_INTEGER),\n \"Weight is not in safe integer range\",\n );\n return parseFloat(formattedBig.toString());\n};\n\n/**\n * Prepares floating number to be stored in database as normalized bigint\n *\n * Database weights are stored either in g or oz\n */\nexport const transformNumberToDatabaseWeight = (\n numberWeight: number,\n system: UnitSystem,\n): string => {\n switch (system) {\n case UnitSystem.Metric: {\n /**\n * convert(1).from(oz).to(g) is 28.34952g.\n * We are stripping sub-gram measures, because database is storing grams\n */\n const numberWeightInt = parseInt(numberWeight.toFixed(0));\n\n assert(\n !!Number.isSafeInteger(numberWeightInt),\n \"Number is not safe integer\",\n );\n\n return numberWeightInt.toString();\n }\n case UnitSystem.Imperial: {\n const weightBig = Big(numberWeight);\n const multiplier = Big(10).pow(DINERO_WEIGHT_OZ.exponent.toNumber());\n return weightBig.mul(multiplier).toFixed(0);\n }\n default:\n assertUnreachable(system);\n }\n};\n\n/**\n * Shorthand function to transform weight number to formatted string.\n *\n * ! Use only with base weights g/oz\n */\nexport const transformBaseWeightNumberToFormat = (\n databaseWeight: number,\n system: UnitSystem,\n): string =>\n transformDatabaseWeightToFormat(\n transformNumberToDatabaseWeight(databaseWeight, system),\n system,\n );\n"],"names":["convert","configureMeasurements","length","mass","calculator","add","a","b","plus","compare","cmp","decrement","v","minus","Big","increment","integerDivide","div","round","roundDown","modulo","mod","multiply","times","power","pow","Number","subtract","zero","toNumber","NaN","dineroBigint","createDinero","DINERO_WEIGHT_G","code","base","exponent","DINERO_WEIGHT_OZ","transformer","currency","dineroObject","multiplier","jsonObject","toJSON","formattedWeight","amount","mul","toFixed","toString","transformDatabaseWeightToFormat","databaseWeight","system","UnitSystem","Metric","toFormat","Imperial","assertUnreachable","transformDatabaseWeightToNumber","formattedBig","assert","lte","MAX_SAFE_INTEGER","parseFloat","transformNumberToDatabaseWeight","numberWeight","numberWeightInt","parseInt","isSafeInteger","weightBig","transformBaseWeightNumberToFormat"],"mappings":";;;;;;;;;;;;;;;AAqBO,MAAMA,UAAUC,8BAAAA,CAAAA,SAAAA,CAAgD,CAAA;EAAAC,MAAA,EACrEA,qBAAA,CAAAA,MAAA;EAAAC,IAAA,EACAA,qBAAA,CAAAA;AACF,CAAC,CAAA;AAED,MAAMC,UAA8B,GAAA;EAClCC,KAAKA,CAACC,CAAA,EAAGC,CAAM,KAAAD,CAAA,CAAEE,KAAKD,CAAC,CAAA;EACvBE,SAASA,CAACH,CAAA,EAAGC,CAAM,KAAAD,CAAA,CAAEI,IAAIH,CAAC,CAAA;EAC1BI,SAAA,EAAYC,CAAM,IAAAA,CAAA,CAAEC,MAAM,IAAIC,MAAAA,CAAAA,GAAA,CAAI,CAAC,CAAC,CAAA;EACpCC,SAAA,EAAYH,CAAM,IAAAA,CAAA,CAAEJ,KAAK,IAAIM,MAAAA,CAAAA,GAAA,CAAI,CAAC,CAAC,CAAA;EACnCE,aAAA,EAAeA,CAACV,CAAA,EAAGC,CAAM,KAAAD,CAAA,CAAEW,GAAI,CAAAV,CAAC,CAAE,CAAAW,KAAA,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,MAAO,CAAAyC,aAAA,CAAcF,eAAe,CAAA,EACtC,4BAAA,CACF;QAEA,OAAOA,gBAAgBjB,QAAS,EAAA;MAClC;IACA,KAAKI,SAAAA,CAAAA,WAAWG,QAAU;MAAA;QAClB,MAAAa,SAAA,GAAYtD,WAAIkD,YAAY,CAAA;QAC5B,MAAAvB,UAAA,GAAa3B,WAAI,EAAE,CAAA,CAAEW,IAAIY,gBAAiB,CAAAD,QAAA,CAASP,UAAU,CAAA;QACnE,OAAOuC,SAAU,CAAAtB,GAAA,CAAIL,UAAU,CAAA,CAAEM,QAAQ,CAAC,CAAA;MAC5C;IACA;MACES,MAAA,CAAAA,iBAAA,CAAkBL,MAAM,CAAA;EAC5B;AACF,CAAA;AAOa,MAAAkB,iCAAA,GAAoCA,CAC/CnB,cAAA,EACAC,MAEA,KAAAF,+BAAA,CACEc,+BAAA,CAAgCb,gBAAgBC,MAAM,CAAA,EACtDA,MACF,CAAA;;;;;"}
@@ -27,6 +27,7 @@ const dineroBigint = createDinero({
27
27
  });
28
28
  const DINERO_WEIGHT_G = {
29
29
  code: "WEIGHT_G",
30
+ // eslint-disable-next-line sonarjs/inconsistent-function-call
30
31
  base: Big(10),
31
32
  exponent: Big(0)
32
33
  };
@@ -1 +1 @@
1
- {"version":3,"file":"measures.mjs","sources":["../../src/utils/measures.ts"],"sourcesContent":["import { Big } from \"big.js\";\nimport type {\n LengthSystems,\n LengthUnits,\n MassSystems,\n MassUnits,\n} from \"convert-units\";\nimport configureMeasurements, { length, mass } from \"convert-units\";\nimport type { Calculator, ComparisonOperator, Transformer } from \"dinero.js\";\nimport { createDinero, toFormat } from \"dinero.js\";\n\nimport { UnitSystem } from \"../types\";\nimport { assert, assertUnreachable } from \"./errors\";\n\n// Measures: The names of the measures being used\ntype Measures = \"length\" | \"mass\";\n// Systems: The systems being used across all measures\ntype Systems = LengthSystems | MassSystems;\n// Units: All the units across all measures and their systems\ntype Units = LengthUnits | MassUnits;\n\nexport const convert = configureMeasurements<Measures, Systems, Units>({\n length,\n mass,\n});\n\nconst calculator: Calculator<Big> = {\n add: (a, b) => a.plus(b),\n compare: (a, b) => a.cmp(b) as unknown as ComparisonOperator,\n decrement: (v) => v.minus(new Big(1)),\n increment: (v) => v.plus(new Big(1)),\n integerDivide: (a, b) => a.div(b).round(0, Big.roundDown),\n modulo: (a, b) => a.mod(b),\n multiply: (a, b) => a.times(b),\n power: (a, b) => a.pow(Number(b)),\n subtract: (a, b) => a.minus(b),\n zero: () => new Big(0),\n toNumber: () => NaN,\n};\n\nconst dineroBigint = createDinero({ calculator });\n\n// type ConvertMassFromTo =\n// | { from: Unit.G; to: Unit.Kg }\n// | { from: Unit.Kg; to: Unit. }\n// | { from: Unit.G; to: Unit.Kg }\n// | { from: Unit.G; to: Unit.Kg }\n// | { from: Unit.G; to: Unit.Kg }\n// | { from: Unit.G; to: Unit.Kg }\n// export const convertMass = (value: number, {from, to}: ConvertMassFromTo) => {\n// return convert(value).from(from).to(to)\n// }\n\nconst DINERO_WEIGHT_G = {\n code: \"WEIGHT_G\",\n base: Big(10),\n exponent: Big(0),\n};\nconst DINERO_WEIGHT_OZ = {\n code: \"WEIGHT_OZ\",\n base: Big(10),\n exponent: Big(6),\n};\n\ntype TransformerOptions = Parameters<Transformer<Big>>[0];\nconst transformer = ({ currency, dineroObject }: TransformerOptions) => {\n const exponent = currency.exponent;\n const multiplier = Big(0.1).pow(exponent.toNumber());\n\n const jsonObject = dineroObject.toJSON();\n const formattedWeight = jsonObject.amount\n .mul(multiplier)\n .toFixed(exponent.toNumber());\n\n return formattedWeight.toString();\n};\n\n/**\n * In database we store weight in \"weird\" format.\n * For metric we store weight in grams as is.\n * For imperial we store weight in oz with \"virtual scale/exponent\" => 6.\n * e.g. 1_000_000 => '1'\n * e.g. 300_000 => '0.3'\n *\n * Database weight is stored either in g or oz\n */\nexport const transformDatabaseWeightToFormat = (\n databaseWeight: string,\n system: UnitSystem,\n): string => {\n switch (system) {\n case UnitSystem.Metric:\n return toFormat(\n dineroBigint({\n amount: Big(databaseWeight),\n currency: DINERO_WEIGHT_G,\n }),\n transformer,\n );\n case UnitSystem.Imperial: {\n return toFormat(\n dineroBigint({\n amount: Big(databaseWeight),\n currency: DINERO_WEIGHT_OZ,\n }),\n transformer,\n );\n }\n default:\n assertUnreachable(system);\n }\n};\n\n/**\n * Executes transformDatabaseWeightToFormat and returns it as number if safe integer\n *\n * Database weight is stored either in g or oz\n */\nexport const transformDatabaseWeightToNumber = (\n databaseWeight: string,\n system: UnitSystem,\n): number => {\n const formattedBig = Big(\n transformDatabaseWeightToFormat(databaseWeight, system),\n );\n\n assert(\n formattedBig.lte(Number.MAX_SAFE_INTEGER),\n \"Weight is not in safe integer range\",\n );\n return parseFloat(formattedBig.toString());\n};\n\n/**\n * Prepares floating number to be stored in database as normalized bigint\n *\n * Database weights are stored either in g or oz\n */\nexport const transformNumberToDatabaseWeight = (\n numberWeight: number,\n system: UnitSystem,\n): string => {\n switch (system) {\n case UnitSystem.Metric: {\n /**\n * convert(1).from(oz).to(g) is 28.34952g.\n * We are stripping sub-gram measures, because database is storing grams\n */\n const numberWeightInt = parseInt(numberWeight.toFixed(0));\n\n assert(\n !!Number.isSafeInteger(numberWeightInt),\n \"Number is not safe integer\",\n );\n\n return numberWeightInt.toString();\n }\n case UnitSystem.Imperial: {\n const weightBig = Big(numberWeight);\n const multiplier = Big(10).pow(DINERO_WEIGHT_OZ.exponent.toNumber());\n return weightBig.mul(multiplier).toFixed(0);\n }\n default:\n assertUnreachable(system);\n }\n};\n\n/**\n * Shorthand function to transform weight number to formatted string.\n *\n * ! Use only with base weights g/oz\n */\nexport const transformBaseWeightNumberToFormat = (\n databaseWeight: number,\n system: UnitSystem,\n): string =>\n transformDatabaseWeightToFormat(\n transformNumberToDatabaseWeight(databaseWeight, system),\n system,\n );\n"],"names":["convert","configureMeasurements","length","mass","calculator","add","a","b","plus","compare","cmp","decrement","v","minus","Big","increment","integerDivide","div","round","roundDown","modulo","mod","multiply","times","power","pow","Number","subtract","zero","toNumber","NaN","dineroBigint","createDinero","DINERO_WEIGHT_G","code","base","exponent","DINERO_WEIGHT_OZ","transformer","currency","dineroObject","multiplier","jsonObject","toJSON","formattedWeight","amount","mul","toFixed","toString","transformDatabaseWeightToFormat","databaseWeight","system","UnitSystem","Metric","toFormat","Imperial","assertUnreachable","transformDatabaseWeightToNumber","formattedBig","assert","lte","MAX_SAFE_INTEGER","parseFloat","transformNumberToDatabaseWeight","numberWeight","numberWeightInt","parseInt","isSafeInteger","weightBig","transformBaseWeightNumberToFormat"],"mappings":";;;;;;;AAqBO,MAAMA,UAAUC,qBAAgD,CAAA;EACrEC,MAAA;EACAC;AACF,CAAC,CAAA;AAED,MAAMC,UAA8B,GAAA;EAClCC,KAAKA,CAACC,CAAA,EAAGC,CAAM,KAAAD,CAAA,CAAEE,KAAKD,CAAC,CAAA;EACvBE,SAASA,CAACH,CAAA,EAAGC,CAAM,KAAAD,CAAA,CAAEI,IAAIH,CAAC,CAAA;EAC1BI,SAAA,EAAYC,CAAM,IAAAA,CAAA,CAAEC,MAAM,IAAIC,GAAA,CAAI,CAAC,CAAC,CAAA;EACpCC,SAAA,EAAYH,CAAM,IAAAA,CAAA,CAAEJ,KAAK,IAAIM,GAAA,CAAI,CAAC,CAAC,CAAA;EACnCE,aAAA,EAAeA,CAACV,CAAA,EAAGC,CAAM,KAAAD,CAAA,CAAEW,GAAI,CAAAV,CAAC,CAAE,CAAAW,KAAA,CAAM,CAAG,EAAAJ,GAAA,CAAIK,SAAS,CAAA;EACxDC,QAAQA,CAACd,CAAA,EAAGC,CAAM,KAAAD,CAAA,CAAEe,IAAId,CAAC,CAAA;EACzBe,UAAUA,CAAChB,CAAA,EAAGC,CAAM,KAAAD,CAAA,CAAEiB,MAAMhB,CAAC,CAAA;EAC7BiB,KAAA,EAAOA,CAAClB,CAAG,EAAAC,CAAA,KAAMD,EAAEmB,GAAI,CAAAC,MAAA,CAAOnB,CAAC,CAAC,CAAA;EAChCoB,UAAU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AgCb,gBAAgBC,MAAM,CAAA,EACtDA,MACF,CAAA;"}
1
+ {"version":3,"file":"measures.mjs","sources":["../../src/utils/measures.ts"],"sourcesContent":["import { Big } from \"big.js\";\nimport type {\n LengthSystems,\n LengthUnits,\n MassSystems,\n MassUnits,\n} from \"convert-units\";\nimport configureMeasurements, { length, mass } from \"convert-units\";\nimport type { Calculator, ComparisonOperator, Transformer } from \"dinero.js\";\nimport { createDinero, toFormat } from \"dinero.js\";\n\nimport { UnitSystem } from \"../types\";\nimport { assert, assertUnreachable } from \"./errors\";\n\n// Measures: The names of the measures being used\ntype Measures = \"length\" | \"mass\";\n// Systems: The systems being used across all measures\ntype Systems = LengthSystems | MassSystems;\n// Units: All the units across all measures and their systems\ntype Units = LengthUnits | MassUnits;\n\nexport const convert = configureMeasurements<Measures, Systems, Units>({\n length,\n mass,\n});\n\nconst calculator: Calculator<Big> = {\n add: (a, b) => a.plus(b),\n compare: (a, b) => a.cmp(b) as unknown as ComparisonOperator,\n decrement: (v) => v.minus(new Big(1)),\n increment: (v) => v.plus(new Big(1)),\n integerDivide: (a, b) => a.div(b).round(0, Big.roundDown),\n modulo: (a, b) => a.mod(b),\n multiply: (a, b) => a.times(b),\n power: (a, b) => a.pow(Number(b)),\n subtract: (a, b) => a.minus(b),\n zero: () => new Big(0),\n toNumber: () => NaN,\n};\n\nconst dineroBigint = createDinero({ calculator });\n\n// type ConvertMassFromTo =\n// | { from: Unit.G; to: Unit.Kg }\n// | { from: Unit.Kg; to: Unit. }\n// | { from: Unit.G; to: Unit.Kg }\n// | { from: Unit.G; to: Unit.Kg }\n// | { from: Unit.G; to: Unit.Kg }\n// | { from: Unit.G; to: Unit.Kg }\n// export const convertMass = (value: number, {from, to}: ConvertMassFromTo) => {\n// return convert(value).from(from).to(to)\n// }\n\nconst DINERO_WEIGHT_G = {\n code: \"WEIGHT_G\",\n // eslint-disable-next-line sonarjs/inconsistent-function-call\n base: Big(10),\n exponent: Big(0),\n};\nconst DINERO_WEIGHT_OZ = {\n code: \"WEIGHT_OZ\",\n base: Big(10),\n exponent: Big(6),\n};\n\ntype TransformerOptions = Parameters<Transformer<Big>>[0];\nconst transformer = ({ currency, dineroObject }: TransformerOptions) => {\n const exponent = currency.exponent;\n const multiplier = Big(0.1).pow(exponent.toNumber());\n\n const jsonObject = dineroObject.toJSON();\n const formattedWeight = jsonObject.amount\n .mul(multiplier)\n .toFixed(exponent.toNumber());\n\n return formattedWeight.toString();\n};\n\n/**\n * In database we store weight in \"weird\" format.\n * For metric we store weight in grams as is.\n * For imperial we store weight in oz with \"virtual scale/exponent\" => 6.\n * e.g. 1_000_000 => '1'\n * e.g. 300_000 => '0.3'\n *\n * Database weight is stored either in g or oz\n */\nexport const transformDatabaseWeightToFormat = (\n databaseWeight: string,\n system: UnitSystem,\n): string => {\n switch (system) {\n case UnitSystem.Metric:\n return toFormat(\n dineroBigint({\n amount: Big(databaseWeight),\n currency: DINERO_WEIGHT_G,\n }),\n transformer,\n );\n case UnitSystem.Imperial: {\n return toFormat(\n dineroBigint({\n amount: Big(databaseWeight),\n currency: DINERO_WEIGHT_OZ,\n }),\n transformer,\n );\n }\n default:\n assertUnreachable(system);\n }\n};\n\n/**\n * Executes transformDatabaseWeightToFormat and returns it as number if safe integer\n *\n * Database weight is stored either in g or oz\n */\nexport const transformDatabaseWeightToNumber = (\n databaseWeight: string,\n system: UnitSystem,\n): number => {\n const formattedBig = Big(\n transformDatabaseWeightToFormat(databaseWeight, system),\n );\n\n assert(\n formattedBig.lte(Number.MAX_SAFE_INTEGER),\n \"Weight is not in safe integer range\",\n );\n return parseFloat(formattedBig.toString());\n};\n\n/**\n * Prepares floating number to be stored in database as normalized bigint\n *\n * Database weights are stored either in g or oz\n */\nexport const transformNumberToDatabaseWeight = (\n numberWeight: number,\n system: UnitSystem,\n): string => {\n switch (system) {\n case UnitSystem.Metric: {\n /**\n * convert(1).from(oz).to(g) is 28.34952g.\n * We are stripping sub-gram measures, because database is storing grams\n */\n const numberWeightInt = parseInt(numberWeight.toFixed(0));\n\n assert(\n !!Number.isSafeInteger(numberWeightInt),\n \"Number is not safe integer\",\n );\n\n return numberWeightInt.toString();\n }\n case UnitSystem.Imperial: {\n const weightBig = Big(numberWeight);\n const multiplier = Big(10).pow(DINERO_WEIGHT_OZ.exponent.toNumber());\n return weightBig.mul(multiplier).toFixed(0);\n }\n default:\n assertUnreachable(system);\n }\n};\n\n/**\n * Shorthand function to transform weight number to formatted string.\n *\n * ! Use only with base weights g/oz\n */\nexport const transformBaseWeightNumberToFormat = (\n databaseWeight: number,\n system: UnitSystem,\n): string =>\n transformDatabaseWeightToFormat(\n transformNumberToDatabaseWeight(databaseWeight, system),\n system,\n );\n"],"names":["convert","configureMeasurements","length","mass","calculator","add","a","b","plus","compare","cmp","decrement","v","minus","Big","increment","integerDivide","div","round","roundDown","modulo","mod","multiply","times","power","pow","Number","subtract","zero","toNumber","NaN","dineroBigint","createDinero","DINERO_WEIGHT_G","code","base","exponent","DINERO_WEIGHT_OZ","transformer","currency","dineroObject","multiplier","jsonObject","toJSON","formattedWeight","amount","mul","toFixed","toString","transformDatabaseWeightToFormat","databaseWeight","system","UnitSystem","Metric","toFormat","Imperial","assertUnreachable","transformDatabaseWeightToNumber","formattedBig","assert","lte","MAX_SAFE_INTEGER","parseFloat","transformNumberToDatabaseWeight","numberWeight","numberWeightInt","parseInt","isSafeInteger","weightBig","transformBaseWeightNumberToFormat"],"mappings":";;;;;;;AAqBO,MAAMA,UAAUC,qBAAgD,CAAA;EACrEC,MAAA;EACAC;AACF,CAAC,CAAA;AAED,MAAMC,UAA8B,GAAA;EAClCC,KAAKA,CAACC,CAAA,EAAGC,CAAM,KAAAD,CAAA,CAAEE,KAAKD,CAAC,CAAA;EACvBE,SAASA,CAACH,CAAA,EAAGC,CAAM,KAAAD,CAAA,CAAEI,IAAIH,CAAC,CAAA;EAC1BI,SAAA,EAAYC,CAAM,IAAAA,CAAA,CAAEC,MAAM,IAAIC,GAAA,CAAI,CAAC,CAAC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DY,MAAA,CACE,CAAC,CAACjC,MAAO,CAAAyC,aAAA,CAAcF,eAAe,CAAA,EACtC,4BAAA,CACF;QAEA,OAAOA,gBAAgBjB,QAAS,EAAA;MAClC;IACA,KAAKI,WAAWG,QAAU;MAAA;QAClB,MAAAa,SAAA,GAAYtD,IAAIkD,YAAY,CAAA;QAC5B,MAAAvB,UAAA,GAAa3B,IAAI,EAAE,CAAA,CAAEW,IAAIY,gBAAiB,CAAAD,QAAA,CAASP,UAAU,CAAA;QACnE,OAAOuC,SAAU,CAAAtB,GAAA,CAAIL,UAAU,CAAA,CAAEM,QAAQ,CAAC,CAAA;MAC5C;IACA;MACES,iBAAA,CAAkBL,MAAM,CAAA;EAC5B;AACF,CAAA;AAOa,MAAAkB,iCAAA,GAAoCA,CAC/CnB,cAAA,EACAC,MAEA,KAAAF,+BAAA,CACEc,+BAAA,CAAgCb,gBAAgBC,MAAM,CAAA,EACtDA,MACF,CAAA;"}
@@ -1 +1 @@
1
- {"version":3,"file":"format.js","sources":["../../../src/utils/money/format.ts"],"sourcesContent":["import { CAD, EUR, GBP } from \"@dinero.js/currencies\";\nimport { hasSubUnits, toFormat, toUnit } from \"dinero.js\";\n\nimport type { Currency, Nullish } from \"../../types\";\nimport { assert } from \"../errors\";\nimport {\n localizedCurrencyLookup,\n prettifyPriceLookup,\n Round,\n} from \"./constants\";\nimport { getDinero, roundDinero } from \"./misc\";\nimport type { Dino, LocalizedCurrency, Money } from \"./types\";\n\nexport const getLocalizedCurrency = (\n currencyCode: Nullish<Currency>,\n): LocalizedCurrency | undefined => {\n return currencyCode ? localizedCurrencyLookup.get(currencyCode) : undefined;\n};\n\n// #############################################################################\n// Formatter\n// #############################################################################\nconst currencyFormatterCache = new Map<string, Intl.NumberFormat>();\n/**\n * Function to get a Int.NumberFormat instance that can be reused to format currency over using\n * `Number.toLocaleString(...)` function, which makes more sense to use as we usually just display 1 or 2 currencies\n * MAX, so reusing the formatted makes a lot of sense\n * @see https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Number/toLocaleString#performance\n */\nconst getCurrencyFormatter = (\n locale: string,\n currencyCode: string,\n): Intl.NumberFormat => {\n const cacheKey = `${locale}_${currencyCode}`;\n\n let formatter = currencyFormatterCache.get(cacheKey);\n if (formatter) {\n return formatter;\n }\n\n formatter = new Intl.NumberFormat(locale, {\n style: \"currency\",\n currency: currencyCode,\n /**\n * Explicitly define default behavior - just in case some runtime overrides it\n * @see https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Intl/NumberFormat/NumberFormat#currencysign\n * @see https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Intl/NumberFormat/NumberFormat#currencydisplay\n */\n currencySign: \"standard\",\n currencyDisplay: \"symbol\",\n });\n currencyFormatterCache.set(cacheKey, formatter);\n\n return formatter;\n};\n\nexport type FormatPriceOptions = {\n /**\n * Optionally remove trailing zeroes (only if all of them are 0)\n * @default false\n * @example\n * \"420,66 €\" => \"420,66 €\"\n * \"420,60 €\" => \"420,60 €\"\n * \"420,00 €\" => \"420 €\"\n */\n removeTrailingZeros?: boolean;\n /**\n * Optionally return currency rounded down to the nearest dollar-equivalent of a the given currency. Doesn't apply any\n * rounding just \"trims\" end decimal values\n *\n * ! Only use for display purposes where monetary precision is not required!\n *\n * @default false\n * @example\n * \"420,66 €\" => \"420 €\"\n * \"420,60 €\" => \"420 €\"\n * \"420,00 €\" => \"420 €\"\n */\n removeFractions?: boolean;\n};\n\n/**\n * Currency formatter based on dinero currency types and browser internationalizing functions\n *\n * Based on:\n * @see https://v2.dinerojs.com/docs/guides/formatting-in-a-multilingual-site#building-a-custom-internationalization-formatter\n * @protected\n * @deprecated Use `formatPrice` instead as this functions is for INTERNAL USE ONLY! (function not actual deprecated,\n * just marked so it discourages usage of it)\n */\nexport function formatPriceRaw(\n dinero: Dino,\n locale: string,\n options?: FormatPriceOptions,\n): string {\n return toFormat(dinero, ({ amount, currency }) => {\n const formatter = getCurrencyFormatter(locale, currency.code);\n const formatted = formatter.format(amount);\n\n return options?.removeFractions || options?.removeTrailingZeros\n ? /**\n * Regex to handle complex removing trailing zeros from currency\n * - Dynamically create regex based on currency as their exponent changes\n * - Also handles some currencies (e.g. EUR) having trailing currency symbol\n *\n * TODO: improve how we detect \"decimal separator\" for formatted currency, at least right now we have tests for it and doesn't seem like an issue\n */\n formatted.replace(\n // For some reason `\\.` need to be double-escaped `\\\\` when creating the regex from template string\n new RegExp(\n `(\\\\.|,)${\n // Depending options remove all trailing digits or just zeros, this way we don't need to do any rounding\n options?.removeFractions ? \"\\\\d\" : 0\n }{0,${currency.exponent}}(\\\\s\\\\D)?$`,\n ),\n // In the replaced using \"last capture group\" (if-exists) so we restore the trailing currency sign\n \"$2\",\n )\n : formatted;\n });\n}\n\n/**\n * Currency formatter based on dinero currency types and browser internationalizing functions\n *\n * In reality just a wrapper around `formatPriceRaw` that does the real formatting\n */\nexport const formatPrice = (\n money: Money,\n options?: FormatPriceOptions,\n): string => {\n const localizedCurrency = getLocalizedCurrency(money.currency);\n assert(!!localizedCurrency, `Currency ${money.currency} not supported`);\n\n return formatPriceRaw(\n getDinero(money.amount, money.currency),\n localizedCurrency.locale,\n options,\n );\n};\n\n/**\n * Prettify numbers depending on the currency using rounding down.\n * ! Should only be used to prettify storefront product prices after currency conversion but nothing else !\n */\nexport const prettifyTotal = (total: Dino): Dino => {\n const totalJson = total.toJSON();\n\n switch (totalJson.currency.code) {\n // @see: https://ubiquiti.atlassian.net/browse/NEP-3846\n case EUR.code:\n case GBP.code:\n case CAD.code: {\n const totalAsFloat = toUnit(total);\n\n if (totalAsFloat < 10) {\n return roundDinero(total, Round.PrettifyDecimalCents);\n } else if (totalAsFloat < 20) {\n return roundDinero(total, Round.PrettifyHalfUnitCents);\n } else if (totalAsFloat < 50) {\n return roundDinero(total, Round.Prettify);\n } else {\n return roundDinero(total, Round.PrettifyFull059);\n }\n }\n default: {\n // Nothing to round\n if (!hasSubUnits(total)) {\n return total;\n }\n\n const minValueInclusiveToRoundDownFrom = prettifyPriceLookup.get(\n totalJson.currency.code,\n );\n\n // Don't round if currency unsupported or value is below min threshold\n if (\n minValueInclusiveToRoundDownFrom == null ||\n toUnit(total) < minValueInclusiveToRoundDownFrom\n ) {\n return total;\n }\n\n return roundDinero(total, Round.Prettify);\n }\n }\n};\n"],"names":["getLocalizedCurrency","currencyCode","localizedCurrencyLookup","get","currencyFormatterCache","Map","getCurrencyFormatter","locale","cacheKey","formatter","Intl","NumberFormat","style","currency","currencySign","currencyDisplay","set","formatPriceRaw","dinero","options","toFormat","amount","code","formatted","format","removeFractions","removeTrailingZeros","replace","RegExp","exponent","formatPrice","money","localizedCurrency","assert","getDinero","prettifyTotal","total","totalJson","toJSON","EUR","GBP","CAD","totalAsFloat","toUnit","roundDinero","Round","PrettifyDecimalCents","PrettifyHalfUnitCents","Prettify","PrettifyFull059","hasSubUnits","minValueInclusiveToRoundDownFrom","prettifyPriceLookup"],"mappings":";;;;;;;;AAaa,MAAAA,oBAAA,GACXC,YACkC,IAAA;EAClC,OAAOA,YAAe,GAAAC,SAAAA,CAAAA,uBAAA,CAAwBC,GAAI,CAAAF,YAAY,CAAI,GAAA,KAAA,CAAA;AACpE,CAAA;AAKA,MAAMG,sBAAA,GAAA,mBAA6BC,GAA+B,EAAA;AAOlE,MAAMC,oBAAA,GAAuBA,CAC3BC,MAAA,EACAN,YACsB,KAAA;EACtB,MAAMO,QAAW,GAAA,GAAGD,MAAM,IAAIN,YAAY,EAAA;EAEtC,IAAAQ,SAAA,GAAYL,sBAAuB,CAAAD,GAAA,CAAIK,QAAQ,CAAA;EACnD,IAAIC,SAAW,EAAA;IACN,OAAAA,SAAA;EACT;EAEYA,SAAA,GAAA,IAAIC,IAAK,CAAAC,YAAA,CAAaJ,MAAQ,EAAA;IACxCK,KAAO,EAAA,UAAA;IACPC,QAAU,EAAAZ,YAAA;IAAA;AAAA;AAAA;AAAA;AAAA;IAMVa,YAAc,EAAA,UAAA;IACdC,e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AAKiB,UAAAA,CAAAA,GAAI,CAAAjB,IAAA;IACT,KAAKkB,UAAAA,CAAAA,GAAI,CAAAlB,IAAA;IACT,KAAKmB,UAAAA,CAAAA,IAAInB,IAAM;MAAA;QACP,MAAAoB,YAAA,GAAeC,iBAAOP,KAAK,CAAA;QAEjC,IAAIM,eAAe,EAAI,EAAA;UACd,OAAAE,gBAAA,CAAYR,KAAO,EAAAS,SAAA,CAAAA,KAAA,CAAMC,oBAAoB,CAAA;QAAA,CACtD,MAAA,IAAWJ,eAAe,EAAI,EAAA;UACrB,OAAAE,gBAAA,CAAYR,KAAO,EAAAS,SAAA,CAAAA,KAAA,CAAME,qBAAqB,CAAA;QAAA,CACvD,MAAA,IAAWL,eAAe,EAAI,EAAA;UACrB,OAAAE,gBAAA,CAAYR,KAAO,EAAAS,SAAA,CAAAA,KAAA,CAAMG,QAAQ,CAAA;QAAA,CACnC,MAAA;UACE,OAAAJ,gBAAA,CAAYR,KAAO,EAAAS,SAAA,CAAAA,KAAA,CAAMI,eAAe,CAAA;QACjD;MACF;IACA;MAAS;QAEH,IAAA,CAACC,SAAAA,CAAAA,WAAY,CAAAd,KAAK,CAAG,EAAA;UAChB,OAAAA,KAAA;QACT;QAEA,MAAMe,mCAAmCC,SAAAA,CAAAA,mBAAoB,CAAAjD,GAAA,CAC3DkC,UAAUxB,QAAS,CAAAS,IAAA,CACrB;QAGA,IACE6B,gCAAoC,IAAA,IAAA,IACpCR,SAAO,CAAAA,MAAA,CAAAP,KAAK,IAAIe,gCAChB,EAAA;UACO,OAAAf,KAAA;QACT;QAEO,OAAAQ,gBAAA,CAAYR,KAAO,EAAAS,SAAA,CAAAA,KAAA,CAAMG,QAAQ,CAAA;MAC1C;EACF;AACF,CAAA;;;;"}
1
+ {"version":3,"file":"format.js","sources":["../../../src/utils/money/format.ts"],"sourcesContent":["import { CAD, EUR, GBP } from \"@dinero.js/currencies\";\nimport { hasSubUnits, toFormat, toUnit } from \"dinero.js\";\n\nimport type { Currency, Nullish } from \"../../types\";\nimport { assert } from \"../errors\";\nimport {\n localizedCurrencyLookup,\n prettifyPriceLookup,\n Round,\n} from \"./constants\";\nimport { getDinero, roundDinero } from \"./misc\";\nimport type { Dino, LocalizedCurrency, Money } from \"./types\";\n\nexport const getLocalizedCurrency = (\n currencyCode: Nullish<Currency>,\n): LocalizedCurrency | undefined => {\n return currencyCode ? localizedCurrencyLookup.get(currencyCode) : undefined;\n};\n\n// #############################################################################\n// Formatter\n// #############################################################################\nconst currencyFormatterCache = new Map<string, Intl.NumberFormat>();\n/**\n * Function to get a Int.NumberFormat instance that can be reused to format currency over using\n * `Number.toLocaleString(...)` function, which makes more sense to use as we usually just display 1 or 2 currencies\n * MAX, so reusing the formatted makes a lot of sense\n * @see https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Number/toLocaleString#performance\n */\nconst getCurrencyFormatter = (\n locale: string,\n currencyCode: string,\n): Intl.NumberFormat => {\n const cacheKey = `${locale}_${currencyCode}`;\n\n let formatter = currencyFormatterCache.get(cacheKey);\n if (formatter) {\n return formatter;\n }\n\n formatter = new Intl.NumberFormat(locale, {\n style: \"currency\",\n currency: currencyCode,\n /**\n * Explicitly define default behavior - just in case some runtime overrides it\n * @see https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Intl/NumberFormat/NumberFormat#currencysign\n * @see https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Intl/NumberFormat/NumberFormat#currencydisplay\n */\n currencySign: \"standard\",\n currencyDisplay: \"symbol\",\n });\n currencyFormatterCache.set(cacheKey, formatter);\n\n return formatter;\n};\n\nexport type FormatPriceOptions = {\n /**\n * Optionally remove trailing zeroes (only if all of them are 0)\n * @default false\n * @example\n * \"420,66 €\" => \"420,66 €\"\n * \"420,60 €\" => \"420,60 €\"\n * \"420,00 €\" => \"420 €\"\n */\n removeTrailingZeros?: boolean;\n /**\n * Optionally return currency rounded down to the nearest dollar-equivalent of a the given currency. Doesn't apply any\n * rounding just \"trims\" end decimal values\n *\n * ! Only use for display purposes where monetary precision is not required!\n *\n * @default false\n * @example\n * \"420,66 €\" => \"420 €\"\n * \"420,60 €\" => \"420 €\"\n * \"420,00 €\" => \"420 €\"\n */\n removeFractions?: boolean;\n};\n\n/**\n * Currency formatter based on dinero currency types and browser internationalizing functions\n *\n * Based on:\n * @see https://v2.dinerojs.com/docs/guides/formatting-in-a-multilingual-site#building-a-custom-internationalization-formatter\n * @protected\n * @deprecated Use `formatPrice` instead as this functions is for INTERNAL USE ONLY! (function not actual deprecated,\n * just marked so it discourages usage of it)\n */\nexport function formatPriceRaw(\n dinero: Dino,\n locale: string,\n options?: FormatPriceOptions,\n): string {\n return toFormat(dinero, ({ amount, currency }) => {\n const formatter = getCurrencyFormatter(locale, currency.code);\n const formatted = formatter.format(amount);\n\n return options?.removeFractions || options?.removeTrailingZeros\n ? /**\n * Regex to handle complex removing trailing zeros from currency\n * - Dynamically create regex based on currency as their exponent changes\n * - Also handles some currencies (e.g. EUR) having trailing currency symbol\n *\n * TODO: improve how we detect \"decimal separator\" for formatted currency, at least right now we have tests for it and doesn't seem like an issue\n */\n formatted.replace(\n // For some reason `\\.` need to be double-escaped `\\\\` when creating the regex from template string\n new RegExp(\n `(\\\\.|,)${\n // Depending options remove all trailing digits or just zeros, this way we don't need to do any rounding\n options?.removeFractions ? \"\\\\d\" : 0\n }{0,${currency.exponent}}(\\\\s\\\\D)?$`,\n ),\n // In the replaced using \"last capture group\" (if-exists) so we restore the trailing currency sign\n \"$2\",\n )\n : formatted;\n });\n}\n\n/**\n * Currency formatter based on dinero currency types and browser internationalizing functions\n *\n * In reality just a wrapper around `formatPriceRaw` that does the real formatting\n */\nexport const formatPrice = (\n money: Money,\n options?: FormatPriceOptions,\n): string => {\n const localizedCurrency = getLocalizedCurrency(money.currency);\n assert(!!localizedCurrency, `Currency ${money.currency} not supported`);\n\n // eslint-disable-next-line sonarjs/deprecation\n return formatPriceRaw(\n getDinero(money.amount, money.currency),\n localizedCurrency.locale,\n options,\n );\n};\n\n/**\n * Prettify numbers depending on the currency using rounding down.\n * ! Should only be used to prettify storefront product prices after currency conversion but nothing else !\n */\nexport const prettifyTotal = (total: Dino): Dino => {\n const totalJson = total.toJSON();\n\n switch (totalJson.currency.code) {\n // @see: https://ubiquiti.atlassian.net/browse/NEP-3846\n case EUR.code:\n case GBP.code:\n case CAD.code: {\n const totalAsFloat = toUnit(total);\n\n if (totalAsFloat < 10) {\n return roundDinero(total, Round.PrettifyDecimalCents);\n } else if (totalAsFloat < 20) {\n return roundDinero(total, Round.PrettifyHalfUnitCents);\n } else if (totalAsFloat < 50) {\n return roundDinero(total, Round.Prettify);\n } else {\n return roundDinero(total, Round.PrettifyFull059);\n }\n }\n default: {\n // Nothing to round\n if (!hasSubUnits(total)) {\n return total;\n }\n\n const minValueInclusiveToRoundDownFrom = prettifyPriceLookup.get(\n totalJson.currency.code,\n );\n\n // Don't round if currency unsupported or value is below min threshold\n if (\n minValueInclusiveToRoundDownFrom == null ||\n toUnit(total) < minValueInclusiveToRoundDownFrom\n ) {\n return total;\n }\n\n return roundDinero(total, Round.Prettify);\n }\n }\n};\n"],"names":["getLocalizedCurrency","currencyCode","localizedCurrencyLookup","get","currencyFormatterCache","Map","getCurrencyFormatter","locale","cacheKey","formatter","Intl","NumberFormat","style","currency","currencySign","currencyDisplay","set","formatPriceRaw","dinero","options","toFormat","amount","code","formatted","format","removeFractions","removeTrailingZeros","replace","RegExp","exponent","formatPrice","money","localizedCurrency","assert","getDinero","prettifyTotal","total","totalJson","toJSON","EUR","GBP","CAD","totalAsFloat","toUnit","roundDinero","Round","PrettifyDecimalCents","PrettifyHalfUnitCents","Prettify","PrettifyFull059","hasSubUnits","minValueInclusiveToRoundDownFrom","prettifyPriceLookup"],"mappings":";;;;;;;;AAaa,MAAAA,oBAAA,GACXC,YACkC,IAAA;EAClC,OAAOA,YAAe,GAAAC,SAAAA,CAAAA,uBAAA,CAAwBC,GAAI,CAAAF,YA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,EAAA;UAChB,OAAAA,KAAA;QACT;QAEA,MAAMe,mCAAmCC,SAAAA,CAAAA,mBAAoB,CAAAjD,GAAA,CAC3DkC,UAAUxB,QAAS,CAAAS,IAAA,CACrB;QAGA,IACE6B,gCAAoC,IAAA,IAAA,IACpCR,SAAO,CAAAA,MAAA,CAAAP,KAAK,IAAIe,gCAChB,EAAA;UACO,OAAAf,KAAA;QACT;QAEO,OAAAQ,gBAAA,CAAYR,KAAO,EAAAS,SAAA,CAAAA,KAAA,CAAMG,QAAQ,CAAA;MAC1C;EACF;AACF,CAAA;;;;"}
@@ -1 +1 @@
1
- {"version":3,"file":"format.mjs","sources":["../../../src/utils/money/format.ts"],"sourcesContent":["import { CAD, EUR, GBP } from \"@dinero.js/currencies\";\nimport { hasSubUnits, toFormat, toUnit } from \"dinero.js\";\n\nimport type { Currency, Nullish } from \"../../types\";\nimport { assert } from \"../errors\";\nimport {\n localizedCurrencyLookup,\n prettifyPriceLookup,\n Round,\n} from \"./constants\";\nimport { getDinero, roundDinero } from \"./misc\";\nimport type { Dino, LocalizedCurrency, Money } from \"./types\";\n\nexport const getLocalizedCurrency = (\n currencyCode: Nullish<Currency>,\n): LocalizedCurrency | undefined => {\n return currencyCode ? localizedCurrencyLookup.get(currencyCode) : undefined;\n};\n\n// #############################################################################\n// Formatter\n// #############################################################################\nconst currencyFormatterCache = new Map<string, Intl.NumberFormat>();\n/**\n * Function to get a Int.NumberFormat instance that can be reused to format currency over using\n * `Number.toLocaleString(...)` function, which makes more sense to use as we usually just display 1 or 2 currencies\n * MAX, so reusing the formatted makes a lot of sense\n * @see https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Number/toLocaleString#performance\n */\nconst getCurrencyFormatter = (\n locale: string,\n currencyCode: string,\n): Intl.NumberFormat => {\n const cacheKey = `${locale}_${currencyCode}`;\n\n let formatter = currencyFormatterCache.get(cacheKey);\n if (formatter) {\n return formatter;\n }\n\n formatter = new Intl.NumberFormat(locale, {\n style: \"currency\",\n currency: currencyCode,\n /**\n * Explicitly define default behavior - just in case some runtime overrides it\n * @see https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Intl/NumberFormat/NumberFormat#currencysign\n * @see https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Intl/NumberFormat/NumberFormat#currencydisplay\n */\n currencySign: \"standard\",\n currencyDisplay: \"symbol\",\n });\n currencyFormatterCache.set(cacheKey, formatter);\n\n return formatter;\n};\n\nexport type FormatPriceOptions = {\n /**\n * Optionally remove trailing zeroes (only if all of them are 0)\n * @default false\n * @example\n * \"420,66 €\" => \"420,66 €\"\n * \"420,60 €\" => \"420,60 €\"\n * \"420,00 €\" => \"420 €\"\n */\n removeTrailingZeros?: boolean;\n /**\n * Optionally return currency rounded down to the nearest dollar-equivalent of a the given currency. Doesn't apply any\n * rounding just \"trims\" end decimal values\n *\n * ! Only use for display purposes where monetary precision is not required!\n *\n * @default false\n * @example\n * \"420,66 €\" => \"420 €\"\n * \"420,60 €\" => \"420 €\"\n * \"420,00 €\" => \"420 €\"\n */\n removeFractions?: boolean;\n};\n\n/**\n * Currency formatter based on dinero currency types and browser internationalizing functions\n *\n * Based on:\n * @see https://v2.dinerojs.com/docs/guides/formatting-in-a-multilingual-site#building-a-custom-internationalization-formatter\n * @protected\n * @deprecated Use `formatPrice` instead as this functions is for INTERNAL USE ONLY! (function not actual deprecated,\n * just marked so it discourages usage of it)\n */\nexport function formatPriceRaw(\n dinero: Dino,\n locale: string,\n options?: FormatPriceOptions,\n): string {\n return toFormat(dinero, ({ amount, currency }) => {\n const formatter = getCurrencyFormatter(locale, currency.code);\n const formatted = formatter.format(amount);\n\n return options?.removeFractions || options?.removeTrailingZeros\n ? /**\n * Regex to handle complex removing trailing zeros from currency\n * - Dynamically create regex based on currency as their exponent changes\n * - Also handles some currencies (e.g. EUR) having trailing currency symbol\n *\n * TODO: improve how we detect \"decimal separator\" for formatted currency, at least right now we have tests for it and doesn't seem like an issue\n */\n formatted.replace(\n // For some reason `\\.` need to be double-escaped `\\\\` when creating the regex from template string\n new RegExp(\n `(\\\\.|,)${\n // Depending options remove all trailing digits or just zeros, this way we don't need to do any rounding\n options?.removeFractions ? \"\\\\d\" : 0\n }{0,${currency.exponent}}(\\\\s\\\\D)?$`,\n ),\n // In the replaced using \"last capture group\" (if-exists) so we restore the trailing currency sign\n \"$2\",\n )\n : formatted;\n });\n}\n\n/**\n * Currency formatter based on dinero currency types and browser internationalizing functions\n *\n * In reality just a wrapper around `formatPriceRaw` that does the real formatting\n */\nexport const formatPrice = (\n money: Money,\n options?: FormatPriceOptions,\n): string => {\n const localizedCurrency = getLocalizedCurrency(money.currency);\n assert(!!localizedCurrency, `Currency ${money.currency} not supported`);\n\n return formatPriceRaw(\n getDinero(money.amount, money.currency),\n localizedCurrency.locale,\n options,\n );\n};\n\n/**\n * Prettify numbers depending on the currency using rounding down.\n * ! Should only be used to prettify storefront product prices after currency conversion but nothing else !\n */\nexport const prettifyTotal = (total: Dino): Dino => {\n const totalJson = total.toJSON();\n\n switch (totalJson.currency.code) {\n // @see: https://ubiquiti.atlassian.net/browse/NEP-3846\n case EUR.code:\n case GBP.code:\n case CAD.code: {\n const totalAsFloat = toUnit(total);\n\n if (totalAsFloat < 10) {\n return roundDinero(total, Round.PrettifyDecimalCents);\n } else if (totalAsFloat < 20) {\n return roundDinero(total, Round.PrettifyHalfUnitCents);\n } else if (totalAsFloat < 50) {\n return roundDinero(total, Round.Prettify);\n } else {\n return roundDinero(total, Round.PrettifyFull059);\n }\n }\n default: {\n // Nothing to round\n if (!hasSubUnits(total)) {\n return total;\n }\n\n const minValueInclusiveToRoundDownFrom = prettifyPriceLookup.get(\n totalJson.currency.code,\n );\n\n // Don't round if currency unsupported or value is below min threshold\n if (\n minValueInclusiveToRoundDownFrom == null ||\n toUnit(total) < minValueInclusiveToRoundDownFrom\n ) {\n return total;\n }\n\n return roundDinero(total, Round.Prettify);\n }\n }\n};\n"],"names":["getLocalizedCurrency","currencyCode","localizedCurrencyLookup","get","currencyFormatterCache","Map","getCurrencyFormatter","locale","cacheKey","formatter","Intl","NumberFormat","style","currency","currencySign","currencyDisplay","set","formatPriceRaw","dinero","options","toFormat","amount","code","formatted","format","removeFractions","removeTrailingZeros","replace","RegExp","exponent","formatPrice","money","localizedCurrency","assert","getDinero","prettifyTotal","total","totalJson","toJSON","EUR","GBP","CAD","totalAsFloat","toUnit","roundDinero","Round","PrettifyDecimalCents","PrettifyHalfUnitCents","Prettify","PrettifyFull059","hasSubUnits","minValueInclusiveToRoundDownFrom","prettifyPriceLookup"],"mappings":";;;;;;AAaa,MAAAA,oBAAA,GACXC,YACkC,IAAA;EAClC,OAAOA,YAAe,GAAAC,uBAAA,CAAwBC,GAAI,CAAAF,YAAY,CAAI,GAAA,KAAA,CAAA;AACpE,CAAA;AAKA,MAAMG,sBAAA,GAAA,mBAA6BC,GAA+B,EAAA;AAOlE,MAAMC,oBAAA,GAAuBA,CAC3BC,MAAA,EACAN,YACsB,KAAA;EACtB,MAAMO,QAAW,GAAA,GAAGD,MAAM,IAAIN,YAAY,EAAA;EAEtC,IAAAQ,SAAA,GAAYL,sBAAuB,CAAAD,GAAA,CAAIK,QAAQ,CAAA;EACnD,IAAIC,SAAW,EAAA;IACN,OAAAA,SAAA;EACT;EAEYA,SAAA,GAAA,IAAIC,IAAK,CAAAC,YAAA,CAAaJ,MAAQ,EAAA;IACxCK,KAAO,EAAA,UAAA;IACPC,QAAU,EAAAZ,YAAA;IAAA;AAAA;AAAA;AAAA;AAAA;IAMVa,YAAc,EAAA,UAAA;IACdC,eAAiB,EAAA;EAAA,CAClB,CAAA;EACsBX,sBAAA,CAAAY,GAAA,CAAIR,UAAUC,SAAS,CAAA;EAEvC,OAAAA,SAAA;AACT,CAAA;AAoCgB,SAAAQ,cAAAA,CACdC,MACA,EAAAX,MAAA,EACAY,OACQ,EAAA;EACR,OAAOC,SAASF,MAAQ,EAAA,CAAC;IAAEG,MAAA;IAAQR;G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IAAWJ,eAAe,EAAI,EAAA;UACrB,OAAAE,WAAA,CAAYR,KAAO,EAAAS,KAAA,CAAME,qBAAqB,CAAA;QAAA,CACvD,MAAA,IAAWL,eAAe,EAAI,EAAA;UACrB,OAAAE,WAAA,CAAYR,KAAO,EAAAS,KAAA,CAAMG,QAAQ,CAAA;QAAA,CACnC,MAAA;UACE,OAAAJ,WAAA,CAAYR,KAAO,EAAAS,KAAA,CAAMI,eAAe,CAAA;QACjD;MACF;IACA;MAAS;QAEH,IAAA,CAACC,WAAY,CAAAd,KAAK,CAAG,EAAA;UAChB,OAAAA,KAAA;QACT;QAEA,MAAMe,mCAAmCC,mBAAoB,CAAAjD,GAAA,CAC3DkC,UAAUxB,QAAS,CAAAS,IAAA,CACrB;QAGA,IACE6B,gCAAoC,IAAA,IAAA,IACpCR,MAAO,CAAAP,KAAK,IAAIe,gCAChB,EAAA;UACO,OAAAf,KAAA;QACT;QAEO,OAAAQ,WAAA,CAAYR,KAAO,EAAAS,KAAA,CAAMG,QAAQ,CAAA;MAC1C;EACF;AACF,CAAA;"}
1
+ {"version":3,"file":"format.mjs","sources":["../../../src/utils/money/format.ts"],"sourcesContent":["import { CAD, EUR, GBP } from \"@dinero.js/currencies\";\nimport { hasSubUnits, toFormat, toUnit } from \"dinero.js\";\n\nimport type { Currency, Nullish } from \"../../types\";\nimport { assert } from \"../errors\";\nimport {\n localizedCurrencyLookup,\n prettifyPriceLookup,\n Round,\n} from \"./constants\";\nimport { getDinero, roundDinero } from \"./misc\";\nimport type { Dino, LocalizedCurrency, Money } from \"./types\";\n\nexport const getLocalizedCurrency = (\n currencyCode: Nullish<Currency>,\n): LocalizedCurrency | undefined => {\n return currencyCode ? localizedCurrencyLookup.get(currencyCode) : undefined;\n};\n\n// #############################################################################\n// Formatter\n// #############################################################################\nconst currencyFormatterCache = new Map<string, Intl.NumberFormat>();\n/**\n * Function to get a Int.NumberFormat instance that can be reused to format currency over using\n * `Number.toLocaleString(...)` function, which makes more sense to use as we usually just display 1 or 2 currencies\n * MAX, so reusing the formatted makes a lot of sense\n * @see https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Number/toLocaleString#performance\n */\nconst getCurrencyFormatter = (\n locale: string,\n currencyCode: string,\n): Intl.NumberFormat => {\n const cacheKey = `${locale}_${currencyCode}`;\n\n let formatter = currencyFormatterCache.get(cacheKey);\n if (formatter) {\n return formatter;\n }\n\n formatter = new Intl.NumberFormat(locale, {\n style: \"currency\",\n currency: currencyCode,\n /**\n * Explicitly define default behavior - just in case some runtime overrides it\n * @see https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Intl/NumberFormat/NumberFormat#currencysign\n * @see https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Intl/NumberFormat/NumberFormat#currencydisplay\n */\n currencySign: \"standard\",\n currencyDisplay: \"symbol\",\n });\n currencyFormatterCache.set(cacheKey, formatter);\n\n return formatter;\n};\n\nexport type FormatPriceOptions = {\n /**\n * Optionally remove trailing zeroes (only if all of them are 0)\n * @default false\n * @example\n * \"420,66 €\" => \"420,66 €\"\n * \"420,60 €\" => \"420,60 €\"\n * \"420,00 €\" => \"420 €\"\n */\n removeTrailingZeros?: boolean;\n /**\n * Optionally return currency rounded down to the nearest dollar-equivalent of a the given currency. Doesn't apply any\n * rounding just \"trims\" end decimal values\n *\n * ! Only use for display purposes where monetary precision is not required!\n *\n * @default false\n * @example\n * \"420,66 €\" => \"420 €\"\n * \"420,60 €\" => \"420 €\"\n * \"420,00 €\" => \"420 €\"\n */\n removeFractions?: boolean;\n};\n\n/**\n * Currency formatter based on dinero currency types and browser internationalizing functions\n *\n * Based on:\n * @see https://v2.dinerojs.com/docs/guides/formatting-in-a-multilingual-site#building-a-custom-internationalization-formatter\n * @protected\n * @deprecated Use `formatPrice` instead as this functions is for INTERNAL USE ONLY! (function not actual deprecated,\n * just marked so it discourages usage of it)\n */\nexport function formatPriceRaw(\n dinero: Dino,\n locale: string,\n options?: FormatPriceOptions,\n): string {\n return toFormat(dinero, ({ amount, currency }) => {\n const formatter = getCurrencyFormatter(locale, currency.code);\n const formatted = formatter.format(amount);\n\n return options?.removeFractions || options?.removeTrailingZeros\n ? /**\n * Regex to handle complex removing trailing zeros from currency\n * - Dynamically create regex based on currency as their exponent changes\n * - Also handles some currencies (e.g. EUR) having trailing currency symbol\n *\n * TODO: improve how we detect \"decimal separator\" for formatted currency, at least right now we have tests for it and doesn't seem like an issue\n */\n formatted.replace(\n // For some reason `\\.` need to be double-escaped `\\\\` when creating the regex from template string\n new RegExp(\n `(\\\\.|,)${\n // Depending options remove all trailing digits or just zeros, this way we don't need to do any rounding\n options?.removeFractions ? \"\\\\d\" : 0\n }{0,${currency.exponent}}(\\\\s\\\\D)?$`,\n ),\n // In the replaced using \"last capture group\" (if-exists) so we restore the trailing currency sign\n \"$2\",\n )\n : formatted;\n });\n}\n\n/**\n * Currency formatter based on dinero currency types and browser internationalizing functions\n *\n * In reality just a wrapper around `formatPriceRaw` that does the real formatting\n */\nexport const formatPrice = (\n money: Money,\n options?: FormatPriceOptions,\n): string => {\n const localizedCurrency = getLocalizedCurrency(money.currency);\n assert(!!localizedCurrency, `Currency ${money.currency} not supported`);\n\n // eslint-disable-next-line sonarjs/deprecation\n return formatPriceRaw(\n getDinero(money.amount, money.currency),\n localizedCurrency.locale,\n options,\n );\n};\n\n/**\n * Prettify numbers depending on the currency using rounding down.\n * ! Should only be used to prettify storefront product prices after currency conversion but nothing else !\n */\nexport const prettifyTotal = (total: Dino): Dino => {\n const totalJson = total.toJSON();\n\n switch (totalJson.currency.code) {\n // @see: https://ubiquiti.atlassian.net/browse/NEP-3846\n case EUR.code:\n case GBP.code:\n case CAD.code: {\n const totalAsFloat = toUnit(total);\n\n if (totalAsFloat < 10) {\n return roundDinero(total, Round.PrettifyDecimalCents);\n } else if (totalAsFloat < 20) {\n return roundDinero(total, Round.PrettifyHalfUnitCents);\n } else if (totalAsFloat < 50) {\n return roundDinero(total, Round.Prettify);\n } else {\n return roundDinero(total, Round.PrettifyFull059);\n }\n }\n default: {\n // Nothing to round\n if (!hasSubUnits(total)) {\n return total;\n }\n\n const minValueInclusiveToRoundDownFrom = prettifyPriceLookup.get(\n totalJson.currency.code,\n );\n\n // Don't round if currency unsupported or value is below min threshold\n if (\n minValueInclusiveToRoundDownFrom == null ||\n toUnit(total) < minValueInclusiveToRoundDownFrom\n ) {\n return total;\n }\n\n return roundDinero(total, Round.Prettify);\n }\n }\n};\n"],"names":["getLocalizedCurrency","currencyCode","localizedCurrencyLookup","get","currencyFormatterCache","Map","getCurrencyFormatter","locale","cacheKey","formatter","Intl","NumberFormat","style","currency","currencySign","currencyDisplay","set","formatPriceRaw","dinero","options","toFormat","amount","code","formatted","format","removeFractions","removeTrailingZeros","replace","RegExp","exponent","formatPrice","money","localizedCurrency","assert","getDinero","prettifyTotal","total","totalJson","toJSON","EUR","GBP","CAD","totalAsFloat","toUnit","roundDinero","Round","PrettifyDecimalCents","PrettifyHalfUnitCents","Prettify","PrettifyFull059","hasSubUnits","minValueInclusiveToRoundDownFrom","prettifyPriceLookup"],"mappings":";;;;;;AAaa,MAAAA,oBAAA,GACXC,YACkC,IAAA;EAClC,OAAOA,YAAe,GAAAC,uBAAA,CAAwBC,GAAI,CAAAF,YAAY,CAAI,GAAA,KAAA,CAAA;AACpE,CAAA;AAKA,MAAMG,sBAAA,GAAA,mBAA6BC,GAA+B,EAAA;AAOlE,MAAMC,oBAAA,GAAuBA,CAC3BC,MAAA,EACAN,YACsB,KAAA;EACtB,MAAMO,QAAW,GAAA,GAAGD,MAAM,IAAIN,YAAY,EAAA;EAEtC,IAAAQ,SAAA,GAAYL,sBAAuB,CAAAD,GAAA,CAAIK,QAAQ,CAAA;EACnD,IAAIC,SAAW,EAAA;IACN,OAAAA,SAAA;EACT;EAEYA,SAAA,GAAA,IAAIC,IAAK,CAAAC,YAAA,CAAaJ,MAAQ,EAAA;IACxCK,KAAO,EAAA,UAAA;IACPC,QAAU,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EAAA;EAEvB,QAAAD,SAAA,CAAUxB,SAASS,IAAM;IAAA;IAE/B,KAAKiB,GAAI,CAAAjB,IAAA;IACT,KAAKkB,GAAI,CAAAlB,IAAA;IACT,KAAKmB,IAAInB,IAAM;MAAA;QACP,MAAAoB,YAAA,GAAeC,OAAOP,KAAK,CAAA;QAEjC,IAAIM,eAAe,EAAI,EAAA;UACd,OAAAE,WAAA,CAAYR,KAAO,EAAAS,KAAA,CAAMC,oBAAoB,CAAA;QAAA,CACtD,MAAA,IAAWJ,eAAe,EAAI,EAAA;UACrB,OAAAE,WAAA,CAAYR,KAAO,EAAAS,KAAA,CAAME,qBAAqB,CAAA;QAAA,CACvD,MAAA,IAAWL,eAAe,EAAI,EAAA;UACrB,OAAAE,WAAA,CAAYR,KAAO,EAAAS,KAAA,CAAMG,QAAQ,CAAA;QAAA,CACnC,MAAA;UACE,OAAAJ,WAAA,CAAYR,KAAO,EAAAS,KAAA,CAAMI,eAAe,CAAA;QACjD;MACF;IACA;MAAS;QAEH,IAAA,CAACC,WAAY,CAAAd,KAAK,CAAG,EAAA;UAChB,OAAAA,KAAA;QACT;QAEA,MAAMe,mCAAmCC,mBAAoB,CAAAjD,GAAA,CAC3DkC,UAAUxB,QAAS,CAAAS,IAAA,CACrB;QAGA,IACE6B,gCAAoC,IAAA,IAAA,IACpCR,MAAO,CAAAP,KAAK,IAAIe,gCAChB,EAAA;UACO,OAAAf,KAAA;QACT;QAEO,OAAAQ,WAAA,CAAYR,KAAO,EAAAS,KAAA,CAAMG,QAAQ,CAAA;MAC1C;EACF;AACF,CAAA;"}
@@ -88,7 +88,7 @@ const money = dinero2 => {
88
88
  currency: parseCurrencyCode(currency2.code)
89
89
  };
90
90
  };
91
- const addMany = (addends, defaultCurrency) => [...addends, getDinero(0, defaultCurrency)].reduce(dinero_js.add);
91
+ const addMany = (addends, defaultCurrency) => addends.reduce(dinero_js.add, getDinero(0, defaultCurrency));
92
92
  const subtractMany = (subtractions, defaultCurrency) => [...subtractions, getDinero(0, defaultCurrency)].reduce(dinero_js.subtract);
93
93
  const stringAmountToDinero = (price, currency2) =>
94
94
  // FIXME: parseFloat seems dangerous O_O