@justifi/webcomponents 4.2.1-rc.4 → 4.4.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (380) hide show
  1. package/LICENSE +21 -0
  2. package/dist/cjs/{Api-11362403.js → Api-7303478d.js} +3 -2
  3. package/dist/cjs/Api-7303478d.js.map +1 -0
  4. package/dist/cjs/business-form-schema-63b311b2.js +132 -0
  5. package/dist/cjs/business-form-schema-63b311b2.js.map +1 -0
  6. package/dist/cjs/form-control-select_2.cjs.entry.js +61 -0
  7. package/dist/cjs/form-control-select_2.cjs.entry.js.map +1 -0
  8. package/dist/cjs/{index-34312a38.js → index-83b2ec02.js} +136 -20
  9. package/dist/cjs/index-83b2ec02.js.map +1 -0
  10. package/dist/cjs/{index.esm-bcf90c56.js → index.esm-7e12ce07.js} +301 -14
  11. package/dist/cjs/index.esm-7e12ce07.js.map +1 -0
  12. package/dist/cjs/justifi-bank-account-form.cjs.entry.js +8 -3
  13. package/dist/cjs/justifi-bank-account-form.cjs.entry.js.map +1 -1
  14. package/dist/cjs/justifi-billing-form_2.cjs.entry.js +5 -5
  15. package/dist/cjs/justifi-billing-form_2.cjs.entry.js.map +1 -1
  16. package/dist/cjs/justifi-business-address-form.cjs.entry.js +37 -0
  17. package/dist/cjs/justifi-business-address-form.cjs.entry.js.map +1 -0
  18. package/dist/cjs/justifi-business-form.cjs.entry.js +751 -0
  19. package/dist/cjs/justifi-business-form.cjs.entry.js.map +1 -0
  20. package/dist/cjs/justifi-business-generic-info_3.cjs.entry.js +148 -0
  21. package/dist/cjs/justifi-business-generic-info_3.cjs.entry.js.map +1 -0
  22. package/dist/cjs/justifi-card-form.cjs.entry.js +8 -3
  23. package/dist/cjs/justifi-card-form.cjs.entry.js.map +1 -1
  24. package/dist/cjs/justifi-payment-form.cjs.entry.js +24 -7
  25. package/dist/cjs/justifi-payment-form.cjs.entry.js.map +1 -1
  26. package/dist/cjs/justifi-payment-method-form.cjs.entry.js +22 -17
  27. package/dist/cjs/justifi-payment-method-form.cjs.entry.js.map +1 -1
  28. package/dist/cjs/justifi-payments-list.cjs.entry.js +75 -4038
  29. package/dist/cjs/justifi-payments-list.cjs.entry.js.map +1 -1
  30. package/dist/cjs/justifi-payouts-list.cjs.entry.js +113 -0
  31. package/dist/cjs/justifi-payouts-list.cjs.entry.js.map +1 -0
  32. package/dist/cjs/loader.cjs.js +3 -12
  33. package/dist/cjs/loader.cjs.js.map +1 -1
  34. package/dist/cjs/select-input_2.cjs.entry.js +6 -6
  35. package/dist/cjs/select-input_2.cjs.entry.js.map +1 -1
  36. package/dist/cjs/{state-options-efeaa587.js → state-options-83b52cd1.js} +1 -1
  37. package/dist/{esm/state-options-188acc34.js.map → cjs/state-options-83b52cd1.js.map} +1 -1
  38. package/dist/cjs/utils-4ee7e080.js +3979 -0
  39. package/dist/cjs/utils-4ee7e080.js.map +1 -0
  40. package/dist/cjs/webcomponents.cjs.js +3 -6
  41. package/dist/cjs/webcomponents.cjs.js.map +1 -1
  42. package/dist/collection/api/Api.js +3 -2
  43. package/dist/collection/api/Api.js.map +1 -1
  44. package/dist/collection/api/Payout.js +33 -0
  45. package/dist/collection/api/Payout.js.map +1 -0
  46. package/dist/collection/api/index.js +1 -0
  47. package/dist/collection/api/index.js.map +1 -1
  48. package/dist/collection/api/mockData/MockPayments.js +1 -1
  49. package/dist/collection/collection-manifest.json +18 -12
  50. package/dist/collection/components/bank-account-form/bank-account-form.js +38 -10
  51. package/dist/collection/components/bank-account-form/bank-account-form.js.map +1 -1
  52. package/dist/collection/components/bank-account-form/bank-account-form.stories.js +2 -0
  53. package/dist/collection/components/bank-account-form/bank-account-form.stories.js.map +1 -1
  54. package/dist/collection/components/bank-account-form/test/bank-account-form.e2e.js +1 -1
  55. package/dist/collection/components/bank-account-form/test/bank-account-form.spec.js +3 -3
  56. package/dist/collection/components/billing-form/billing-form-schema.js +1 -1
  57. package/dist/collection/components/billing-form/billing-form.css +212 -39
  58. package/dist/collection/components/billing-form/billing-form.js +16 -10
  59. package/dist/collection/components/billing-form/billing-form.js.map +1 -1
  60. package/dist/collection/components/billing-form/test/billing-form.spec.js +51 -24
  61. package/dist/collection/components/billing-form/test/billing-form.spec.js.map +1 -1
  62. package/dist/collection/components/{business-address/business-address-schema.js → business-form/business-address/business-address-form-schema.js} +2 -2
  63. package/dist/collection/components/business-form/business-address/business-address-form-schema.js.map +1 -0
  64. package/dist/collection/components/business-form/business-address/business-address-form.css +2532 -0
  65. package/dist/collection/components/business-form/business-address/business-address-form.js +98 -0
  66. package/dist/collection/components/business-form/business-address/business-address-form.js.map +1 -0
  67. package/dist/collection/components/business-form/business-address/test/business-address.e2e.js +10 -0
  68. package/dist/collection/components/business-form/business-address/test/business-address.e2e.js.map +1 -0
  69. package/dist/collection/components/business-form/business-address/test/business-address.spec.js +72 -0
  70. package/dist/collection/components/business-form/business-address/test/business-address.spec.js.map +1 -0
  71. package/dist/collection/components/business-form/business-form-schema.js +149 -0
  72. package/dist/collection/components/business-form/business-form-schema.js.map +1 -0
  73. package/dist/collection/components/business-form/business-form.css +2532 -0
  74. package/dist/collection/components/business-form/business-form.js +76 -0
  75. package/dist/collection/components/business-form/business-form.js.map +1 -0
  76. package/dist/collection/components/{business-info/business-info.css → business-form/business-generic-info/business-generic-info.css} +745 -530
  77. package/dist/collection/components/business-form/business-generic-info/business-generic-info.js +79 -0
  78. package/dist/collection/components/business-form/business-generic-info/business-generic-info.js.map +1 -0
  79. package/dist/collection/components/business-form/business-owners/business-owners.css +2489 -0
  80. package/dist/collection/components/business-form/business-owners/business-owners.js +120 -0
  81. package/dist/collection/components/business-form/business-owners/business-owners.js.map +1 -0
  82. package/dist/collection/components/business-form/business-representative/business-representative-schema.js +2 -0
  83. package/dist/collection/components/business-form/business-representative/business-representative-schema.js.map +1 -0
  84. package/dist/collection/components/business-form/business-representative/business-representative.css +2489 -0
  85. package/dist/collection/components/business-form/business-representative/business-representative.js +76 -0
  86. package/dist/collection/components/business-form/business-representative/business-representative.js.map +1 -0
  87. package/dist/collection/components/business-form/businessForm.stories.js +115 -0
  88. package/dist/collection/components/business-form/businessForm.stories.js.map +1 -0
  89. package/dist/collection/components/card-form/card-form.js +38 -10
  90. package/dist/collection/components/card-form/card-form.js.map +1 -1
  91. package/dist/collection/components/card-form/card-form.stories.js +5 -2
  92. package/dist/collection/components/card-form/card-form.stories.js.map +1 -1
  93. package/dist/collection/components/card-form/test/card-form.e2e.js +1 -1
  94. package/dist/collection/components/card-form/test/card-form.spec.js +3 -3
  95. package/dist/collection/components/{business-address/business-address.css → form/form-control-select.css} +344 -1212
  96. package/dist/collection/components/form/form-control-select.js +168 -0
  97. package/dist/collection/components/form/form-control-select.js.map +1 -0
  98. package/dist/collection/components/form/form-control-text.css +1794 -0
  99. package/dist/collection/components/form/form-control-text.js +152 -0
  100. package/dist/collection/components/form/form-control-text.js.map +1 -0
  101. package/dist/collection/components/form/form.js +85 -0
  102. package/dist/collection/components/form/form.js.map +1 -0
  103. package/dist/collection/components/payment-form/payment-form.css +220 -45
  104. package/dist/collection/components/payment-form/payment-form.js +47 -7
  105. package/dist/collection/components/payment-form/payment-form.js.map +1 -1
  106. package/dist/collection/components/payment-form/payment-form.stories.js +3 -2
  107. package/dist/collection/components/payment-form/payment-form.stories.js.map +1 -1
  108. package/dist/collection/components/payment-form/payment-method-selector.css +348 -145
  109. package/dist/collection/components/payment-form/payment-method-selector.js +5 -3
  110. package/dist/collection/components/payment-form/payment-method-selector.js.map +1 -1
  111. package/dist/collection/components/payment-form/test/payment-form.e2e.js +1 -1
  112. package/dist/collection/components/payment-form/test/payment-form.spec.js +4 -3
  113. package/dist/collection/components/payment-form/test/payment-form.spec.js.map +1 -1
  114. package/dist/collection/components/payment-method-form/get-computed-theme.js +2 -0
  115. package/dist/collection/components/payment-method-form/get-computed-theme.js.map +1 -1
  116. package/dist/collection/components/payment-method-form/payment-method-form.js +19 -11
  117. package/dist/collection/components/payment-method-form/payment-method-form.js.map +1 -1
  118. package/dist/collection/components/payment-method-form/test/payment-method-form.e2e.js +1 -1
  119. package/dist/collection/components/payment-method-form/test/payment-method-form.spec.js +3 -3
  120. package/dist/collection/components/payment-method-form/theme.js.map +1 -1
  121. package/dist/collection/components/payments-list/example.js +12 -0
  122. package/dist/collection/components/payments-list/payments-list.css +7954 -1
  123. package/dist/collection/components/payments-list/payments-list.js +104 -27
  124. package/dist/collection/components/payments-list/payments-list.js.map +1 -1
  125. package/dist/collection/components/payments-list/payments-list.stories.js +78 -0
  126. package/dist/collection/components/payments-list/payments-list.stories.js.map +1 -0
  127. package/dist/collection/components/payments-list/test/payments-list.spec.js +82 -18
  128. package/dist/collection/components/payments-list/test/payments-list.spec.js.map +1 -1
  129. package/dist/collection/components/payouts-list/payouts-list.css +7983 -0
  130. package/dist/collection/components/payouts-list/payouts-list.js +181 -0
  131. package/dist/collection/components/payouts-list/payouts-list.js.map +1 -0
  132. package/dist/collection/components/payouts-list/payouts-list.stories.js +69 -0
  133. package/dist/collection/components/payouts-list/payouts-list.stories.js.map +1 -0
  134. package/dist/collection/components/select-input/select-input.css +344 -141
  135. package/dist/collection/components/select-input/select-input.js +5 -4
  136. package/dist/collection/components/select-input/select-input.js.map +1 -1
  137. package/dist/collection/components/select-input/test/select-input.spec.js +72 -28
  138. package/dist/collection/components/select-input/test/select-input.spec.js.map +1 -1
  139. package/dist/collection/components/text-input/test/text-input.spec.js +47 -5
  140. package/dist/collection/components/text-input/test/text-input.spec.js.map +1 -1
  141. package/dist/collection/components/text-input/text-input.css +344 -141
  142. package/dist/collection/components/text-input/text-input.js +2 -2
  143. package/dist/collection/components/text-input/text-input.js.map +1 -1
  144. package/dist/collection/utils/utils.js +7 -2
  145. package/dist/collection/utils/utils.js.map +1 -1
  146. package/dist/components/Api.js +2 -1
  147. package/dist/components/Api.js.map +1 -1
  148. package/dist/components/billing-form.js +2 -2
  149. package/dist/components/billing-form.js.map +1 -1
  150. package/dist/components/business-address-form.js +65 -0
  151. package/dist/components/business-address-form.js.map +1 -0
  152. package/dist/components/business-generic-info.js +190 -0
  153. package/dist/components/business-generic-info.js.map +1 -0
  154. package/dist/components/business-owners.js +102 -0
  155. package/dist/components/business-owners.js.map +1 -0
  156. package/dist/components/business-representative.js +75 -0
  157. package/dist/components/business-representative.js.map +1 -0
  158. package/dist/components/{justifi-business-info.d.ts → form-control-select.d.ts} +4 -4
  159. package/dist/components/form-control-select.js +8 -0
  160. package/dist/components/form-control-select.js.map +1 -0
  161. package/dist/components/form-control-select2.js +53 -0
  162. package/dist/components/form-control-select2.js.map +1 -0
  163. package/dist/components/form-control-text.d.ts +11 -0
  164. package/dist/components/form-control-text.js +8 -0
  165. package/dist/components/form-control-text.js.map +1 -0
  166. package/dist/components/form-control-text2.js +51 -0
  167. package/dist/components/form-control-text2.js.map +1 -0
  168. package/dist/components/index.esm.js +298 -14
  169. package/dist/components/index.esm.js.map +1 -1
  170. package/dist/components/justifi-bank-account-form.js +7 -2
  171. package/dist/components/justifi-bank-account-form.js.map +1 -1
  172. package/dist/components/justifi-business-address-form.d.ts +11 -0
  173. package/dist/components/justifi-business-address-form.js +8 -0
  174. package/dist/components/justifi-business-address-form.js.map +1 -0
  175. package/dist/components/justifi-business-form.d.ts +11 -0
  176. package/dist/components/justifi-business-form.js +802 -0
  177. package/dist/components/justifi-business-form.js.map +1 -0
  178. package/dist/components/justifi-business-generic-info.d.ts +11 -0
  179. package/dist/components/justifi-business-generic-info.js +8 -0
  180. package/dist/components/justifi-business-generic-info.js.map +1 -0
  181. package/dist/components/justifi-business-owners.d.ts +11 -0
  182. package/dist/components/justifi-business-owners.js +8 -0
  183. package/dist/components/justifi-business-owners.js.map +1 -0
  184. package/dist/components/justifi-business-representative.d.ts +11 -0
  185. package/dist/components/justifi-business-representative.js +8 -0
  186. package/dist/components/justifi-business-representative.js.map +1 -0
  187. package/dist/components/justifi-card-form.js +7 -2
  188. package/dist/components/justifi-card-form.js.map +1 -1
  189. package/dist/components/justifi-payment-form.js +23 -4
  190. package/dist/components/justifi-payment-form.js.map +1 -1
  191. package/dist/components/justifi-payments-list.js +78 -4038
  192. package/dist/components/justifi-payments-list.js.map +1 -1
  193. package/dist/components/justifi-payouts-list.d.ts +11 -0
  194. package/dist/components/justifi-payouts-list.js +134 -0
  195. package/dist/components/justifi-payouts-list.js.map +1 -0
  196. package/dist/components/payment-method-form.js +21 -16
  197. package/dist/components/payment-method-form.js.map +1 -1
  198. package/dist/components/payment-method-selector.js +1 -1
  199. package/dist/components/payment-method-selector.js.map +1 -1
  200. package/dist/components/select-input2.js +3 -3
  201. package/dist/components/select-input2.js.map +1 -1
  202. package/dist/components/state-options.js.map +1 -1
  203. package/dist/components/text-input2.js +2 -2
  204. package/dist/components/text-input2.js.map +1 -1
  205. package/dist/components/utils.js +3972 -0
  206. package/dist/components/utils.js.map +1 -0
  207. package/dist/esm/{Api-a07f0057.js → Api-436dfa09.js} +3 -2
  208. package/dist/esm/Api-436dfa09.js.map +1 -0
  209. package/dist/esm/business-form-schema-30c48693.js +128 -0
  210. package/dist/esm/business-form-schema-30c48693.js.map +1 -0
  211. package/dist/esm/form-control-select_2.entry.js +56 -0
  212. package/dist/esm/form-control-select_2.entry.js.map +1 -0
  213. package/dist/esm/{index-044f93fc.js → index-c8f391de.js} +136 -20
  214. package/dist/esm/index-c8f391de.js.map +1 -0
  215. package/dist/esm/{index.esm-5624a5ed.js → index.esm-be2cd327.js} +299 -15
  216. package/dist/esm/index.esm-be2cd327.js.map +1 -0
  217. package/dist/esm/justifi-bank-account-form.entry.js +8 -3
  218. package/dist/esm/justifi-bank-account-form.entry.js.map +1 -1
  219. package/dist/esm/justifi-billing-form_2.entry.js +5 -5
  220. package/dist/esm/justifi-billing-form_2.entry.js.map +1 -1
  221. package/dist/esm/justifi-business-address-form.entry.js +33 -0
  222. package/dist/esm/justifi-business-address-form.entry.js.map +1 -0
  223. package/dist/esm/justifi-business-form.entry.js +747 -0
  224. package/dist/esm/justifi-business-form.entry.js.map +1 -0
  225. package/dist/esm/justifi-business-generic-info_3.entry.js +142 -0
  226. package/dist/esm/justifi-business-generic-info_3.entry.js.map +1 -0
  227. package/dist/esm/justifi-card-form.entry.js +8 -3
  228. package/dist/esm/justifi-card-form.entry.js.map +1 -1
  229. package/dist/esm/justifi-payment-form.entry.js +21 -4
  230. package/dist/esm/justifi-payment-form.entry.js.map +1 -1
  231. package/dist/esm/justifi-payment-method-form.entry.js +22 -17
  232. package/dist/esm/justifi-payment-method-form.entry.js.map +1 -1
  233. package/dist/esm/justifi-payments-list.entry.js +75 -4038
  234. package/dist/esm/justifi-payments-list.entry.js.map +1 -1
  235. package/dist/esm/justifi-payouts-list.entry.js +109 -0
  236. package/dist/esm/justifi-payouts-list.entry.js.map +1 -0
  237. package/dist/esm/loader.js +4 -13
  238. package/dist/esm/loader.js.map +1 -1
  239. package/dist/esm/select-input_2.entry.js +6 -6
  240. package/dist/esm/select-input_2.entry.js.map +1 -1
  241. package/dist/esm/{state-options-188acc34.js → state-options-ece00aa2.js} +1 -1
  242. package/dist/esm/state-options-ece00aa2.js.map +1 -0
  243. package/dist/esm/utils-e7782126.js +3972 -0
  244. package/dist/esm/utils-e7782126.js.map +1 -0
  245. package/dist/esm/webcomponents.js +4 -7
  246. package/dist/esm/webcomponents.js.map +1 -1
  247. package/dist/types/api/Payout.d.ts +62 -0
  248. package/dist/types/api/index.d.ts +1 -0
  249. package/dist/types/components/business-form/business-address/business-address-form.d.ts +9 -0
  250. package/dist/types/components/{business-info/business-info-schema.d.ts → business-form/business-form-schema.d.ts} +55 -4
  251. package/dist/types/components/business-form/business-form.d.ts +14 -0
  252. package/dist/types/components/business-form/business-generic-info/business-generic-info.d.ts +16 -0
  253. package/dist/types/components/business-form/business-owners/business-owners.d.ts +32 -0
  254. package/dist/types/components/business-form/business-representative/business-representative-schema.d.ts +15 -0
  255. package/dist/types/components/business-form/business-representative/business-representative.d.ts +12 -0
  256. package/dist/types/components/business-form/businessForm.stories.d.ts +21 -0
  257. package/dist/types/components/form/form-control-select.d.ts +16 -0
  258. package/dist/types/components/form/form-control-text.d.ts +12 -0
  259. package/dist/types/components/form/form.d.ts +21 -0
  260. package/dist/types/components/payment-form/payment-form.d.ts +2 -0
  261. package/dist/types/components/payment-method-form/theme.d.ts +2 -0
  262. package/dist/types/components/payments-list/payments-list.d.ts +38 -5
  263. package/dist/types/components/payments-list/payments-list.stories.d.ts +17 -0
  264. package/dist/types/components/payouts-list/payouts-list.d.ts +45 -0
  265. package/dist/types/components/payouts-list/payouts-list.stories.d.ts +16 -0
  266. package/dist/types/components.d.ts +339 -26
  267. package/dist/types/stencil-public-runtime.d.ts +14 -2
  268. package/dist/types/utils/utils.d.ts +1 -0
  269. package/dist/webcomponents/p-0fd4aae2.js +2 -0
  270. package/dist/webcomponents/p-0fd4aae2.js.map +1 -0
  271. package/dist/webcomponents/p-1953797f.entry.js +2 -0
  272. package/dist/webcomponents/p-1953797f.entry.js.map +1 -0
  273. package/dist/webcomponents/p-1a1f2196.js +2 -0
  274. package/dist/webcomponents/p-1a1f2196.js.map +1 -0
  275. package/dist/webcomponents/p-23e9c7d4.entry.js +2 -0
  276. package/dist/webcomponents/p-23e9c7d4.entry.js.map +1 -0
  277. package/dist/webcomponents/p-309a886f.entry.js +2 -0
  278. package/dist/webcomponents/p-309a886f.entry.js.map +1 -0
  279. package/dist/webcomponents/p-33d69eb5.entry.js +2 -0
  280. package/dist/webcomponents/p-33d69eb5.entry.js.map +1 -0
  281. package/dist/webcomponents/p-3a80a2ec.entry.js +2 -0
  282. package/dist/webcomponents/p-3a80a2ec.entry.js.map +1 -0
  283. package/dist/webcomponents/p-45fea6a8.entry.js +2 -0
  284. package/dist/webcomponents/p-45fea6a8.entry.js.map +1 -0
  285. package/dist/webcomponents/{p-0ea23153.js → p-47bc59b5.js} +1 -1
  286. package/dist/webcomponents/p-47bc59b5.js.map +1 -0
  287. package/dist/webcomponents/p-7041a637.entry.js +2 -0
  288. package/dist/webcomponents/p-7041a637.entry.js.map +1 -0
  289. package/dist/webcomponents/p-79456add.js +2 -0
  290. package/dist/webcomponents/p-79456add.js.map +1 -0
  291. package/dist/webcomponents/{p-1f151d49.js → p-af080b21.js} +2 -2
  292. package/dist/webcomponents/p-af080b21.js.map +1 -0
  293. package/dist/webcomponents/p-bc969904.js +3 -0
  294. package/dist/webcomponents/p-bc969904.js.map +1 -0
  295. package/dist/webcomponents/p-cd097ce9.entry.js +2 -0
  296. package/dist/webcomponents/p-cd097ce9.entry.js.map +1 -0
  297. package/dist/webcomponents/p-d5bc9f22.entry.js +2 -0
  298. package/dist/webcomponents/p-d5bc9f22.entry.js.map +1 -0
  299. package/dist/webcomponents/p-d5cadc78.entry.js +2 -0
  300. package/dist/webcomponents/p-d5cadc78.entry.js.map +1 -0
  301. package/dist/webcomponents/p-dd1ebc0b.entry.js +2 -0
  302. package/dist/webcomponents/p-dd1ebc0b.entry.js.map +1 -0
  303. package/dist/webcomponents/p-e05e0c6b.entry.js +2 -0
  304. package/dist/webcomponents/p-e05e0c6b.entry.js.map +1 -0
  305. package/dist/webcomponents/webcomponents.css +1 -1
  306. package/dist/webcomponents/webcomponents.esm.js +1 -1
  307. package/dist/webcomponents/webcomponents.esm.js.map +1 -1
  308. package/loader/index.d.ts +1 -1
  309. package/package.json +12 -14
  310. package/CHANGELOG.md +0 -196
  311. package/changelog-template.hbs +0 -10
  312. package/dist/cjs/Api-11362403.js.map +0 -1
  313. package/dist/cjs/Payment-ac4dea02.js +0 -73
  314. package/dist/cjs/Payment-ac4dea02.js.map +0 -1
  315. package/dist/cjs/index-34312a38.js.map +0 -1
  316. package/dist/cjs/index.esm-bcf90c56.js.map +0 -1
  317. package/dist/cjs/justifi-business-address.cjs.entry.js +0 -69
  318. package/dist/cjs/justifi-business-address.cjs.entry.js.map +0 -1
  319. package/dist/cjs/justifi-business-info.cjs.entry.js +0 -174
  320. package/dist/cjs/justifi-business-info.cjs.entry.js.map +0 -1
  321. package/dist/cjs/state-options-efeaa587.js.map +0 -1
  322. package/dist/collection/components/business-address/business-address-schema.js.map +0 -1
  323. package/dist/collection/components/business-address/business-address.js +0 -100
  324. package/dist/collection/components/business-address/business-address.js.map +0 -1
  325. package/dist/collection/components/business-address/test/business-address.e2e.js +0 -10
  326. package/dist/collection/components/business-address/test/business-address.e2e.js.map +0 -1
  327. package/dist/collection/components/business-address/test/business-address.spec.js +0 -18
  328. package/dist/collection/components/business-address/test/business-address.spec.js.map +0 -1
  329. package/dist/collection/components/business-info/business-info-schema.js +0 -94
  330. package/dist/collection/components/business-info/business-info-schema.js.map +0 -1
  331. package/dist/collection/components/business-info/business-info.js +0 -168
  332. package/dist/collection/components/business-info/business-info.js.map +0 -1
  333. package/dist/components/Payment.js +0 -71
  334. package/dist/components/Payment.js.map +0 -1
  335. package/dist/components/justifi-business-address.d.ts +0 -11
  336. package/dist/components/justifi-business-address.js +0 -99
  337. package/dist/components/justifi-business-address.js.map +0 -1
  338. package/dist/components/justifi-business-info.js +0 -207
  339. package/dist/components/justifi-business-info.js.map +0 -1
  340. package/dist/esm/Api-a07f0057.js.map +0 -1
  341. package/dist/esm/Payment-c86e1e84.js +0 -71
  342. package/dist/esm/Payment-c86e1e84.js.map +0 -1
  343. package/dist/esm/index-044f93fc.js.map +0 -1
  344. package/dist/esm/index.esm-5624a5ed.js.map +0 -1
  345. package/dist/esm/justifi-business-address.entry.js +0 -65
  346. package/dist/esm/justifi-business-address.entry.js.map +0 -1
  347. package/dist/esm/justifi-business-info.entry.js +0 -170
  348. package/dist/esm/justifi-business-info.entry.js.map +0 -1
  349. package/dist/esm/polyfills/css-shim.js +0 -1
  350. package/dist/types/components/bank-account-form/bank-account-form.d.ts +0 -56
  351. package/dist/types/components/business-address/business-address.d.ts +0 -11
  352. package/dist/types/components/business-info/business-info.d.ts +0 -20
  353. package/dist/types/components/card-form/card-form.d.ts +0 -62
  354. package/dist/webcomponents/p-0969db8f.entry.js +0 -2
  355. package/dist/webcomponents/p-0969db8f.entry.js.map +0 -1
  356. package/dist/webcomponents/p-0ea23153.js.map +0 -1
  357. package/dist/webcomponents/p-1ca0646b.js +0 -2
  358. package/dist/webcomponents/p-1ca0646b.js.map +0 -1
  359. package/dist/webcomponents/p-1f151d49.js.map +0 -1
  360. package/dist/webcomponents/p-255b1284.entry.js +0 -2
  361. package/dist/webcomponents/p-255b1284.entry.js.map +0 -1
  362. package/dist/webcomponents/p-2b8c281e.entry.js +0 -2
  363. package/dist/webcomponents/p-2b8c281e.entry.js.map +0 -1
  364. package/dist/webcomponents/p-3aa91155.js +0 -3
  365. package/dist/webcomponents/p-3aa91155.js.map +0 -1
  366. package/dist/webcomponents/p-90c0d9e1.entry.js +0 -2
  367. package/dist/webcomponents/p-90c0d9e1.entry.js.map +0 -1
  368. package/dist/webcomponents/p-bd5352d6.entry.js +0 -2
  369. package/dist/webcomponents/p-bd5352d6.entry.js.map +0 -1
  370. package/dist/webcomponents/p-c903cc5a.entry.js +0 -2
  371. package/dist/webcomponents/p-c903cc5a.entry.js.map +0 -1
  372. package/dist/webcomponents/p-d87b0711.entry.js +0 -2
  373. package/dist/webcomponents/p-d87b0711.entry.js.map +0 -1
  374. package/dist/webcomponents/p-dbf7100f.entry.js +0 -2
  375. package/dist/webcomponents/p-dbf7100f.entry.js.map +0 -1
  376. package/dist/webcomponents/p-e0054bc3.js +0 -2
  377. package/dist/webcomponents/p-e0054bc3.js.map +0 -1
  378. package/dist/webcomponents/p-f30d1567.entry.js +0 -2
  379. package/dist/webcomponents/p-f30d1567.entry.js.map +0 -1
  380. /package/dist/types/components/{business-address/business-address-schema.d.ts → business-form/business-address/business-address-form-schema.d.ts} +0 -0
@@ -0,0 +1,3979 @@
1
+ 'use strict';
2
+
3
+ var CaptureStrategy;
4
+ (function (CaptureStrategy) {
5
+ CaptureStrategy["automatic"] = "automatic";
6
+ CaptureStrategy["manual"] = "manual";
7
+ })(CaptureStrategy || (CaptureStrategy = {}));
8
+ exports.PaymentMethodTypes = void 0;
9
+ (function (PaymentMethodTypes) {
10
+ PaymentMethodTypes["card"] = "card";
11
+ PaymentMethodTypes["bankAccount"] = "bankAccount";
12
+ })(exports.PaymentMethodTypes || (exports.PaymentMethodTypes = {}));
13
+ var PaymentStatuses;
14
+ (function (PaymentStatuses) {
15
+ PaymentStatuses["pending"] = "pending";
16
+ PaymentStatuses["authorized"] = "authorized";
17
+ PaymentStatuses["succeeded"] = "succeeded";
18
+ PaymentStatuses["failed"] = "failed";
19
+ PaymentStatuses["disputed"] = "disputed";
20
+ PaymentStatuses["fully_refunded"] = "fully_refunded";
21
+ PaymentStatuses["partially_refunded"] = "partially_refunded";
22
+ })(PaymentStatuses || (PaymentStatuses = {}));
23
+ var PaymentDisputedStatuses;
24
+ (function (PaymentDisputedStatuses) {
25
+ // if a dispute is 'won', we don't show a dispute status, just general status
26
+ PaymentDisputedStatuses["lost"] = "lost";
27
+ PaymentDisputedStatuses["open"] = "open";
28
+ })(PaymentDisputedStatuses || (PaymentDisputedStatuses = {}));
29
+ class Payment {
30
+ constructor(payment) {
31
+ this.id = payment.id;
32
+ this.account_id = payment.account_id;
33
+ this.amount = payment.amount;
34
+ this.amount_disputed = payment.amount_disputed;
35
+ this.amount_refundable = payment.amount_refundable;
36
+ this.amount_refunded = payment.amount_refunded;
37
+ this.balance = payment.balance;
38
+ this.captured = payment.captured;
39
+ this.capture_strategy = payment.capture_strategy;
40
+ this.currency = payment.currency;
41
+ this.description = payment.description;
42
+ this.disputed = payment.disputed;
43
+ this.disputes = payment.disputes;
44
+ this.error_code = payment.error_code;
45
+ this.error_description = payment.error_description;
46
+ this.fee_amount = payment.fee_amount;
47
+ this.is_test = payment.is_test;
48
+ this.metadata = payment.metadata;
49
+ this.payment_method = payment.payment_method;
50
+ this.payment_intent_id = payment.payment_intent_id;
51
+ this.refunded = payment.refunded;
52
+ this.status = payment.status;
53
+ this.created_at = payment.created_at;
54
+ this.updated_at = payment.updated_at;
55
+ }
56
+ get disputedStatus() {
57
+ const lost = this.disputes.some(dispute => dispute.status === PaymentDisputedStatuses.lost);
58
+ // if a dispute is 'won', we don't show a dispute status, just general status
59
+ if (!this.disputed) {
60
+ return null;
61
+ }
62
+ else if (lost) {
63
+ return PaymentDisputedStatuses.lost;
64
+ }
65
+ else {
66
+ return PaymentDisputedStatuses.open;
67
+ }
68
+ }
69
+ }
70
+
71
+ exports.PayoutStatuses = void 0;
72
+ (function (PayoutStatuses) {
73
+ PayoutStatuses["paid"] = "paid";
74
+ PayoutStatuses["failed"] = "failed";
75
+ PayoutStatuses["forwarded"] = "forwarded";
76
+ PayoutStatuses["scheduled"] = "scheduled";
77
+ PayoutStatuses["in_transit"] = "in_transit";
78
+ PayoutStatuses["canceled"] = "canceled";
79
+ })(exports.PayoutStatuses || (exports.PayoutStatuses = {}));
80
+ class Payout {
81
+ constructor(payout) {
82
+ this.id = payout.id;
83
+ this.account_id = payout.account_id;
84
+ this.amount = payout.amount;
85
+ this.bank_account = payout.bank_account;
86
+ this.currency = payout.currency;
87
+ this.delivery_method = payout.delivery_method || 'standard';
88
+ this.description = payout.description;
89
+ this.deposits_at = payout.deposits_at;
90
+ this.fees_total = payout.fees_total;
91
+ this.refunds_count = payout.refunds_count;
92
+ this.refunds_total = payout.refunds_total;
93
+ this.payments_count = payout.payments_count;
94
+ this.payments_total = payout.payments_total;
95
+ this.payout_type = payout.payout_type;
96
+ this.other_total = payout.other_total;
97
+ this.status = payout.status;
98
+ this.metadata = payout.metadata;
99
+ this.created_at = payout.created_at;
100
+ this.updated_at = payout.updated_at;
101
+ }
102
+ }
103
+
104
+ function _typeof$1(obj) {
105
+ "@babel/helpers - typeof";
106
+
107
+ return _typeof$1 = "function" == typeof Symbol && "symbol" == typeof Symbol.iterator ? function (obj) {
108
+ return typeof obj;
109
+ } : function (obj) {
110
+ return obj && "function" == typeof Symbol && obj.constructor === Symbol && obj !== Symbol.prototype ? "symbol" : typeof obj;
111
+ }, _typeof$1(obj);
112
+ }
113
+
114
+ function toInteger(dirtyNumber) {
115
+ if (dirtyNumber === null || dirtyNumber === true || dirtyNumber === false) {
116
+ return NaN;
117
+ }
118
+ var number = Number(dirtyNumber);
119
+ if (isNaN(number)) {
120
+ return number;
121
+ }
122
+ return number < 0 ? Math.ceil(number) : Math.floor(number);
123
+ }
124
+
125
+ function requiredArgs(required, args) {
126
+ if (args.length < required) {
127
+ throw new TypeError(required + ' argument' + (required > 1 ? 's' : '') + ' required, but only ' + args.length + ' present');
128
+ }
129
+ }
130
+
131
+ /**
132
+ * @name toDate
133
+ * @category Common Helpers
134
+ * @summary Convert the given argument to an instance of Date.
135
+ *
136
+ * @description
137
+ * Convert the given argument to an instance of Date.
138
+ *
139
+ * If the argument is an instance of Date, the function returns its clone.
140
+ *
141
+ * If the argument is a number, it is treated as a timestamp.
142
+ *
143
+ * If the argument is none of the above, the function returns Invalid Date.
144
+ *
145
+ * **Note**: *all* Date arguments passed to any *date-fns* function is processed by `toDate`.
146
+ *
147
+ * @param {Date|Number} argument - the value to convert
148
+ * @returns {Date} the parsed date in the local time zone
149
+ * @throws {TypeError} 1 argument required
150
+ *
151
+ * @example
152
+ * // Clone the date:
153
+ * const result = toDate(new Date(2014, 1, 11, 11, 30, 30))
154
+ * //=> Tue Feb 11 2014 11:30:30
155
+ *
156
+ * @example
157
+ * // Convert the timestamp to date:
158
+ * const result = toDate(1392098430000)
159
+ * //=> Tue Feb 11 2014 11:30:30
160
+ */
161
+ function toDate(argument) {
162
+ requiredArgs(1, arguments);
163
+ var argStr = Object.prototype.toString.call(argument);
164
+
165
+ // Clone the date
166
+ if (argument instanceof Date || _typeof$1(argument) === 'object' && argStr === '[object Date]') {
167
+ // Prevent the date to lose the milliseconds when passed to new Date() in IE10
168
+ return new Date(argument.getTime());
169
+ } else if (typeof argument === 'number' || argStr === '[object Number]') {
170
+ return new Date(argument);
171
+ } else {
172
+ if ((typeof argument === 'string' || argStr === '[object String]') && typeof console !== 'undefined') {
173
+ // eslint-disable-next-line no-console
174
+ console.warn("Starting with v2.0.0-beta.1 date-fns doesn't accept strings as date arguments. Please use `parseISO` to parse strings. See: https://github.com/date-fns/date-fns/blob/master/docs/upgradeGuide.md#string-arguments");
175
+ // eslint-disable-next-line no-console
176
+ console.warn(new Error().stack);
177
+ }
178
+ return new Date(NaN);
179
+ }
180
+ }
181
+
182
+ /**
183
+ * @name addMilliseconds
184
+ * @category Millisecond Helpers
185
+ * @summary Add the specified number of milliseconds to the given date.
186
+ *
187
+ * @description
188
+ * Add the specified number of milliseconds to the given date.
189
+ *
190
+ * @param {Date|Number} date - the date to be changed
191
+ * @param {Number} amount - the amount of milliseconds to be added. Positive decimals will be rounded using `Math.floor`, decimals less than zero will be rounded using `Math.ceil`.
192
+ * @returns {Date} the new date with the milliseconds added
193
+ * @throws {TypeError} 2 arguments required
194
+ *
195
+ * @example
196
+ * // Add 750 milliseconds to 10 July 2014 12:45:30.000:
197
+ * const result = addMilliseconds(new Date(2014, 6, 10, 12, 45, 30, 0), 750)
198
+ * //=> Thu Jul 10 2014 12:45:30.750
199
+ */
200
+ function addMilliseconds(dirtyDate, dirtyAmount) {
201
+ requiredArgs(2, arguments);
202
+ var timestamp = toDate(dirtyDate).getTime();
203
+ var amount = toInteger(dirtyAmount);
204
+ return new Date(timestamp + amount);
205
+ }
206
+
207
+ var defaultOptions = {};
208
+ function getDefaultOptions() {
209
+ return defaultOptions;
210
+ }
211
+
212
+ /**
213
+ * Google Chrome as of 67.0.3396.87 introduced timezones with offset that includes seconds.
214
+ * They usually appear for dates that denote time before the timezones were introduced
215
+ * (e.g. for 'Europe/Prague' timezone the offset is GMT+00:57:44 before 1 October 1891
216
+ * and GMT+01:00:00 after that date)
217
+ *
218
+ * Date#getTimezoneOffset returns the offset in minutes and would return 57 for the example above,
219
+ * which would lead to incorrect calculations.
220
+ *
221
+ * This function returns the timezone offset in milliseconds that takes seconds in account.
222
+ */
223
+ function getTimezoneOffsetInMilliseconds(date) {
224
+ var utcDate = new Date(Date.UTC(date.getFullYear(), date.getMonth(), date.getDate(), date.getHours(), date.getMinutes(), date.getSeconds(), date.getMilliseconds()));
225
+ utcDate.setUTCFullYear(date.getFullYear());
226
+ return date.getTime() - utcDate.getTime();
227
+ }
228
+
229
+ /**
230
+ * @name isDate
231
+ * @category Common Helpers
232
+ * @summary Is the given value a date?
233
+ *
234
+ * @description
235
+ * Returns true if the given value is an instance of Date. The function works for dates transferred across iframes.
236
+ *
237
+ * @param {*} value - the value to check
238
+ * @returns {boolean} true if the given value is a date
239
+ * @throws {TypeError} 1 arguments required
240
+ *
241
+ * @example
242
+ * // For a valid date:
243
+ * const result = isDate(new Date())
244
+ * //=> true
245
+ *
246
+ * @example
247
+ * // For an invalid date:
248
+ * const result = isDate(new Date(NaN))
249
+ * //=> true
250
+ *
251
+ * @example
252
+ * // For some value:
253
+ * const result = isDate('2014-02-31')
254
+ * //=> false
255
+ *
256
+ * @example
257
+ * // For an object:
258
+ * const result = isDate({})
259
+ * //=> false
260
+ */
261
+ function isDate(value) {
262
+ requiredArgs(1, arguments);
263
+ return value instanceof Date || _typeof$1(value) === 'object' && Object.prototype.toString.call(value) === '[object Date]';
264
+ }
265
+
266
+ /**
267
+ * @name isValid
268
+ * @category Common Helpers
269
+ * @summary Is the given date valid?
270
+ *
271
+ * @description
272
+ * Returns false if argument is Invalid Date and true otherwise.
273
+ * Argument is converted to Date using `toDate`. See [toDate]{@link https://date-fns.org/docs/toDate}
274
+ * Invalid Date is a Date, whose time value is NaN.
275
+ *
276
+ * Time value of Date: http://es5.github.io/#x15.9.1.1
277
+ *
278
+ * @param {*} date - the date to check
279
+ * @returns {Boolean} the date is valid
280
+ * @throws {TypeError} 1 argument required
281
+ *
282
+ * @example
283
+ * // For the valid date:
284
+ * const result = isValid(new Date(2014, 1, 31))
285
+ * //=> true
286
+ *
287
+ * @example
288
+ * // For the value, convertable into a date:
289
+ * const result = isValid(1393804800000)
290
+ * //=> true
291
+ *
292
+ * @example
293
+ * // For the invalid date:
294
+ * const result = isValid(new Date(''))
295
+ * //=> false
296
+ */
297
+ function isValid(dirtyDate) {
298
+ requiredArgs(1, arguments);
299
+ if (!isDate(dirtyDate) && typeof dirtyDate !== 'number') {
300
+ return false;
301
+ }
302
+ var date = toDate(dirtyDate);
303
+ return !isNaN(Number(date));
304
+ }
305
+
306
+ /**
307
+ * @name subMilliseconds
308
+ * @category Millisecond Helpers
309
+ * @summary Subtract the specified number of milliseconds from the given date.
310
+ *
311
+ * @description
312
+ * Subtract the specified number of milliseconds from the given date.
313
+ *
314
+ * @param {Date|Number} date - the date to be changed
315
+ * @param {Number} amount - the amount of milliseconds to be subtracted. Positive decimals will be rounded using `Math.floor`, decimals less than zero will be rounded using `Math.ceil`.
316
+ * @returns {Date} the new date with the milliseconds subtracted
317
+ * @throws {TypeError} 2 arguments required
318
+ *
319
+ * @example
320
+ * // Subtract 750 milliseconds from 10 July 2014 12:45:30.000:
321
+ * const result = subMilliseconds(new Date(2014, 6, 10, 12, 45, 30, 0), 750)
322
+ * //=> Thu Jul 10 2014 12:45:29.250
323
+ */
324
+ function subMilliseconds(dirtyDate, dirtyAmount) {
325
+ requiredArgs(2, arguments);
326
+ var amount = toInteger(dirtyAmount);
327
+ return addMilliseconds(dirtyDate, -amount);
328
+ }
329
+
330
+ var MILLISECONDS_IN_DAY = 86400000;
331
+ function getUTCDayOfYear(dirtyDate) {
332
+ requiredArgs(1, arguments);
333
+ var date = toDate(dirtyDate);
334
+ var timestamp = date.getTime();
335
+ date.setUTCMonth(0, 1);
336
+ date.setUTCHours(0, 0, 0, 0);
337
+ var startOfYearTimestamp = date.getTime();
338
+ var difference = timestamp - startOfYearTimestamp;
339
+ return Math.floor(difference / MILLISECONDS_IN_DAY) + 1;
340
+ }
341
+
342
+ function startOfUTCISOWeek(dirtyDate) {
343
+ requiredArgs(1, arguments);
344
+ var weekStartsOn = 1;
345
+ var date = toDate(dirtyDate);
346
+ var day = date.getUTCDay();
347
+ var diff = (day < weekStartsOn ? 7 : 0) + day - weekStartsOn;
348
+ date.setUTCDate(date.getUTCDate() - diff);
349
+ date.setUTCHours(0, 0, 0, 0);
350
+ return date;
351
+ }
352
+
353
+ function getUTCISOWeekYear(dirtyDate) {
354
+ requiredArgs(1, arguments);
355
+ var date = toDate(dirtyDate);
356
+ var year = date.getUTCFullYear();
357
+ var fourthOfJanuaryOfNextYear = new Date(0);
358
+ fourthOfJanuaryOfNextYear.setUTCFullYear(year + 1, 0, 4);
359
+ fourthOfJanuaryOfNextYear.setUTCHours(0, 0, 0, 0);
360
+ var startOfNextYear = startOfUTCISOWeek(fourthOfJanuaryOfNextYear);
361
+ var fourthOfJanuaryOfThisYear = new Date(0);
362
+ fourthOfJanuaryOfThisYear.setUTCFullYear(year, 0, 4);
363
+ fourthOfJanuaryOfThisYear.setUTCHours(0, 0, 0, 0);
364
+ var startOfThisYear = startOfUTCISOWeek(fourthOfJanuaryOfThisYear);
365
+ if (date.getTime() >= startOfNextYear.getTime()) {
366
+ return year + 1;
367
+ } else if (date.getTime() >= startOfThisYear.getTime()) {
368
+ return year;
369
+ } else {
370
+ return year - 1;
371
+ }
372
+ }
373
+
374
+ function startOfUTCISOWeekYear(dirtyDate) {
375
+ requiredArgs(1, arguments);
376
+ var year = getUTCISOWeekYear(dirtyDate);
377
+ var fourthOfJanuary = new Date(0);
378
+ fourthOfJanuary.setUTCFullYear(year, 0, 4);
379
+ fourthOfJanuary.setUTCHours(0, 0, 0, 0);
380
+ var date = startOfUTCISOWeek(fourthOfJanuary);
381
+ return date;
382
+ }
383
+
384
+ var MILLISECONDS_IN_WEEK$1 = 604800000;
385
+ function getUTCISOWeek(dirtyDate) {
386
+ requiredArgs(1, arguments);
387
+ var date = toDate(dirtyDate);
388
+ var diff = startOfUTCISOWeek(date).getTime() - startOfUTCISOWeekYear(date).getTime();
389
+
390
+ // Round the number of days to the nearest integer
391
+ // because the number of milliseconds in a week is not constant
392
+ // (e.g. it's different in the week of the daylight saving time clock shift)
393
+ return Math.round(diff / MILLISECONDS_IN_WEEK$1) + 1;
394
+ }
395
+
396
+ function startOfUTCWeek(dirtyDate, options) {
397
+ var _ref, _ref2, _ref3, _options$weekStartsOn, _options$locale, _options$locale$optio, _defaultOptions$local, _defaultOptions$local2;
398
+ requiredArgs(1, arguments);
399
+ var defaultOptions = getDefaultOptions();
400
+ var weekStartsOn = toInteger((_ref = (_ref2 = (_ref3 = (_options$weekStartsOn = options === null || options === void 0 ? void 0 : options.weekStartsOn) !== null && _options$weekStartsOn !== void 0 ? _options$weekStartsOn : options === null || options === void 0 ? void 0 : (_options$locale = options.locale) === null || _options$locale === void 0 ? void 0 : (_options$locale$optio = _options$locale.options) === null || _options$locale$optio === void 0 ? void 0 : _options$locale$optio.weekStartsOn) !== null && _ref3 !== void 0 ? _ref3 : defaultOptions.weekStartsOn) !== null && _ref2 !== void 0 ? _ref2 : (_defaultOptions$local = defaultOptions.locale) === null || _defaultOptions$local === void 0 ? void 0 : (_defaultOptions$local2 = _defaultOptions$local.options) === null || _defaultOptions$local2 === void 0 ? void 0 : _defaultOptions$local2.weekStartsOn) !== null && _ref !== void 0 ? _ref : 0);
401
+
402
+ // Test if weekStartsOn is between 0 and 6 _and_ is not NaN
403
+ if (!(weekStartsOn >= 0 && weekStartsOn <= 6)) {
404
+ throw new RangeError('weekStartsOn must be between 0 and 6 inclusively');
405
+ }
406
+ var date = toDate(dirtyDate);
407
+ var day = date.getUTCDay();
408
+ var diff = (day < weekStartsOn ? 7 : 0) + day - weekStartsOn;
409
+ date.setUTCDate(date.getUTCDate() - diff);
410
+ date.setUTCHours(0, 0, 0, 0);
411
+ return date;
412
+ }
413
+
414
+ function getUTCWeekYear(dirtyDate, options) {
415
+ var _ref, _ref2, _ref3, _options$firstWeekCon, _options$locale, _options$locale$optio, _defaultOptions$local, _defaultOptions$local2;
416
+ requiredArgs(1, arguments);
417
+ var date = toDate(dirtyDate);
418
+ var year = date.getUTCFullYear();
419
+ var defaultOptions = getDefaultOptions();
420
+ var firstWeekContainsDate = toInteger((_ref = (_ref2 = (_ref3 = (_options$firstWeekCon = options === null || options === void 0 ? void 0 : options.firstWeekContainsDate) !== null && _options$firstWeekCon !== void 0 ? _options$firstWeekCon : options === null || options === void 0 ? void 0 : (_options$locale = options.locale) === null || _options$locale === void 0 ? void 0 : (_options$locale$optio = _options$locale.options) === null || _options$locale$optio === void 0 ? void 0 : _options$locale$optio.firstWeekContainsDate) !== null && _ref3 !== void 0 ? _ref3 : defaultOptions.firstWeekContainsDate) !== null && _ref2 !== void 0 ? _ref2 : (_defaultOptions$local = defaultOptions.locale) === null || _defaultOptions$local === void 0 ? void 0 : (_defaultOptions$local2 = _defaultOptions$local.options) === null || _defaultOptions$local2 === void 0 ? void 0 : _defaultOptions$local2.firstWeekContainsDate) !== null && _ref !== void 0 ? _ref : 1);
421
+
422
+ // Test if weekStartsOn is between 1 and 7 _and_ is not NaN
423
+ if (!(firstWeekContainsDate >= 1 && firstWeekContainsDate <= 7)) {
424
+ throw new RangeError('firstWeekContainsDate must be between 1 and 7 inclusively');
425
+ }
426
+ var firstWeekOfNextYear = new Date(0);
427
+ firstWeekOfNextYear.setUTCFullYear(year + 1, 0, firstWeekContainsDate);
428
+ firstWeekOfNextYear.setUTCHours(0, 0, 0, 0);
429
+ var startOfNextYear = startOfUTCWeek(firstWeekOfNextYear, options);
430
+ var firstWeekOfThisYear = new Date(0);
431
+ firstWeekOfThisYear.setUTCFullYear(year, 0, firstWeekContainsDate);
432
+ firstWeekOfThisYear.setUTCHours(0, 0, 0, 0);
433
+ var startOfThisYear = startOfUTCWeek(firstWeekOfThisYear, options);
434
+ if (date.getTime() >= startOfNextYear.getTime()) {
435
+ return year + 1;
436
+ } else if (date.getTime() >= startOfThisYear.getTime()) {
437
+ return year;
438
+ } else {
439
+ return year - 1;
440
+ }
441
+ }
442
+
443
+ function startOfUTCWeekYear(dirtyDate, options) {
444
+ var _ref, _ref2, _ref3, _options$firstWeekCon, _options$locale, _options$locale$optio, _defaultOptions$local, _defaultOptions$local2;
445
+ requiredArgs(1, arguments);
446
+ var defaultOptions = getDefaultOptions();
447
+ var firstWeekContainsDate = toInteger((_ref = (_ref2 = (_ref3 = (_options$firstWeekCon = options === null || options === void 0 ? void 0 : options.firstWeekContainsDate) !== null && _options$firstWeekCon !== void 0 ? _options$firstWeekCon : options === null || options === void 0 ? void 0 : (_options$locale = options.locale) === null || _options$locale === void 0 ? void 0 : (_options$locale$optio = _options$locale.options) === null || _options$locale$optio === void 0 ? void 0 : _options$locale$optio.firstWeekContainsDate) !== null && _ref3 !== void 0 ? _ref3 : defaultOptions.firstWeekContainsDate) !== null && _ref2 !== void 0 ? _ref2 : (_defaultOptions$local = defaultOptions.locale) === null || _defaultOptions$local === void 0 ? void 0 : (_defaultOptions$local2 = _defaultOptions$local.options) === null || _defaultOptions$local2 === void 0 ? void 0 : _defaultOptions$local2.firstWeekContainsDate) !== null && _ref !== void 0 ? _ref : 1);
448
+ var year = getUTCWeekYear(dirtyDate, options);
449
+ var firstWeek = new Date(0);
450
+ firstWeek.setUTCFullYear(year, 0, firstWeekContainsDate);
451
+ firstWeek.setUTCHours(0, 0, 0, 0);
452
+ var date = startOfUTCWeek(firstWeek, options);
453
+ return date;
454
+ }
455
+
456
+ var MILLISECONDS_IN_WEEK = 604800000;
457
+ function getUTCWeek(dirtyDate, options) {
458
+ requiredArgs(1, arguments);
459
+ var date = toDate(dirtyDate);
460
+ var diff = startOfUTCWeek(date, options).getTime() - startOfUTCWeekYear(date, options).getTime();
461
+
462
+ // Round the number of days to the nearest integer
463
+ // because the number of milliseconds in a week is not constant
464
+ // (e.g. it's different in the week of the daylight saving time clock shift)
465
+ return Math.round(diff / MILLISECONDS_IN_WEEK) + 1;
466
+ }
467
+
468
+ function addLeadingZeros(number, targetLength) {
469
+ var sign = number < 0 ? '-' : '';
470
+ var output = Math.abs(number).toString();
471
+ while (output.length < targetLength) {
472
+ output = '0' + output;
473
+ }
474
+ return sign + output;
475
+ }
476
+
477
+ /*
478
+ * | | Unit | | Unit |
479
+ * |-----|--------------------------------|-----|--------------------------------|
480
+ * | a | AM, PM | A* | |
481
+ * | d | Day of month | D | |
482
+ * | h | Hour [1-12] | H | Hour [0-23] |
483
+ * | m | Minute | M | Month |
484
+ * | s | Second | S | Fraction of second |
485
+ * | y | Year (abs) | Y | |
486
+ *
487
+ * Letters marked by * are not implemented but reserved by Unicode standard.
488
+ */
489
+ var formatters$1 = {
490
+ // Year
491
+ y: function y(date, token) {
492
+ // From http://www.unicode.org/reports/tr35/tr35-31/tr35-dates.html#Date_Format_tokens
493
+ // | Year | y | yy | yyy | yyyy | yyyyy |
494
+ // |----------|-------|----|-------|-------|-------|
495
+ // | AD 1 | 1 | 01 | 001 | 0001 | 00001 |
496
+ // | AD 12 | 12 | 12 | 012 | 0012 | 00012 |
497
+ // | AD 123 | 123 | 23 | 123 | 0123 | 00123 |
498
+ // | AD 1234 | 1234 | 34 | 1234 | 1234 | 01234 |
499
+ // | AD 12345 | 12345 | 45 | 12345 | 12345 | 12345 |
500
+
501
+ var signedYear = date.getUTCFullYear();
502
+ // Returns 1 for 1 BC (which is year 0 in JavaScript)
503
+ var year = signedYear > 0 ? signedYear : 1 - signedYear;
504
+ return addLeadingZeros(token === 'yy' ? year % 100 : year, token.length);
505
+ },
506
+ // Month
507
+ M: function M(date, token) {
508
+ var month = date.getUTCMonth();
509
+ return token === 'M' ? String(month + 1) : addLeadingZeros(month + 1, 2);
510
+ },
511
+ // Day of the month
512
+ d: function d(date, token) {
513
+ return addLeadingZeros(date.getUTCDate(), token.length);
514
+ },
515
+ // AM or PM
516
+ a: function a(date, token) {
517
+ var dayPeriodEnumValue = date.getUTCHours() / 12 >= 1 ? 'pm' : 'am';
518
+ switch (token) {
519
+ case 'a':
520
+ case 'aa':
521
+ return dayPeriodEnumValue.toUpperCase();
522
+ case 'aaa':
523
+ return dayPeriodEnumValue;
524
+ case 'aaaaa':
525
+ return dayPeriodEnumValue[0];
526
+ case 'aaaa':
527
+ default:
528
+ return dayPeriodEnumValue === 'am' ? 'a.m.' : 'p.m.';
529
+ }
530
+ },
531
+ // Hour [1-12]
532
+ h: function h(date, token) {
533
+ return addLeadingZeros(date.getUTCHours() % 12 || 12, token.length);
534
+ },
535
+ // Hour [0-23]
536
+ H: function H(date, token) {
537
+ return addLeadingZeros(date.getUTCHours(), token.length);
538
+ },
539
+ // Minute
540
+ m: function m(date, token) {
541
+ return addLeadingZeros(date.getUTCMinutes(), token.length);
542
+ },
543
+ // Second
544
+ s: function s(date, token) {
545
+ return addLeadingZeros(date.getUTCSeconds(), token.length);
546
+ },
547
+ // Fraction of second
548
+ S: function S(date, token) {
549
+ var numberOfDigits = token.length;
550
+ var milliseconds = date.getUTCMilliseconds();
551
+ var fractionalSeconds = Math.floor(milliseconds * Math.pow(10, numberOfDigits - 3));
552
+ return addLeadingZeros(fractionalSeconds, token.length);
553
+ }
554
+ };
555
+
556
+ var dayPeriodEnum = {
557
+ am: 'am',
558
+ pm: 'pm',
559
+ midnight: 'midnight',
560
+ noon: 'noon',
561
+ morning: 'morning',
562
+ afternoon: 'afternoon',
563
+ evening: 'evening',
564
+ night: 'night'
565
+ };
566
+ /*
567
+ * | | Unit | | Unit |
568
+ * |-----|--------------------------------|-----|--------------------------------|
569
+ * | a | AM, PM | A* | Milliseconds in day |
570
+ * | b | AM, PM, noon, midnight | B | Flexible day period |
571
+ * | c | Stand-alone local day of week | C* | Localized hour w/ day period |
572
+ * | d | Day of month | D | Day of year |
573
+ * | e | Local day of week | E | Day of week |
574
+ * | f | | F* | Day of week in month |
575
+ * | g* | Modified Julian day | G | Era |
576
+ * | h | Hour [1-12] | H | Hour [0-23] |
577
+ * | i! | ISO day of week | I! | ISO week of year |
578
+ * | j* | Localized hour w/ day period | J* | Localized hour w/o day period |
579
+ * | k | Hour [1-24] | K | Hour [0-11] |
580
+ * | l* | (deprecated) | L | Stand-alone month |
581
+ * | m | Minute | M | Month |
582
+ * | n | | N | |
583
+ * | o! | Ordinal number modifier | O | Timezone (GMT) |
584
+ * | p! | Long localized time | P! | Long localized date |
585
+ * | q | Stand-alone quarter | Q | Quarter |
586
+ * | r* | Related Gregorian year | R! | ISO week-numbering year |
587
+ * | s | Second | S | Fraction of second |
588
+ * | t! | Seconds timestamp | T! | Milliseconds timestamp |
589
+ * | u | Extended year | U* | Cyclic year |
590
+ * | v* | Timezone (generic non-locat.) | V* | Timezone (location) |
591
+ * | w | Local week of year | W* | Week of month |
592
+ * | x | Timezone (ISO-8601 w/o Z) | X | Timezone (ISO-8601) |
593
+ * | y | Year (abs) | Y | Local week-numbering year |
594
+ * | z | Timezone (specific non-locat.) | Z* | Timezone (aliases) |
595
+ *
596
+ * Letters marked by * are not implemented but reserved by Unicode standard.
597
+ *
598
+ * Letters marked by ! are non-standard, but implemented by date-fns:
599
+ * - `o` modifies the previous token to turn it into an ordinal (see `format` docs)
600
+ * - `i` is ISO day of week. For `i` and `ii` is returns numeric ISO week days,
601
+ * i.e. 7 for Sunday, 1 for Monday, etc.
602
+ * - `I` is ISO week of year, as opposed to `w` which is local week of year.
603
+ * - `R` is ISO week-numbering year, as opposed to `Y` which is local week-numbering year.
604
+ * `R` is supposed to be used in conjunction with `I` and `i`
605
+ * for universal ISO week-numbering date, whereas
606
+ * `Y` is supposed to be used in conjunction with `w` and `e`
607
+ * for week-numbering date specific to the locale.
608
+ * - `P` is long localized date format
609
+ * - `p` is long localized time format
610
+ */
611
+
612
+ var formatters = {
613
+ // Era
614
+ G: function G(date, token, localize) {
615
+ var era = date.getUTCFullYear() > 0 ? 1 : 0;
616
+ switch (token) {
617
+ // AD, BC
618
+ case 'G':
619
+ case 'GG':
620
+ case 'GGG':
621
+ return localize.era(era, {
622
+ width: 'abbreviated'
623
+ });
624
+ // A, B
625
+ case 'GGGGG':
626
+ return localize.era(era, {
627
+ width: 'narrow'
628
+ });
629
+ // Anno Domini, Before Christ
630
+ case 'GGGG':
631
+ default:
632
+ return localize.era(era, {
633
+ width: 'wide'
634
+ });
635
+ }
636
+ },
637
+ // Year
638
+ y: function y(date, token, localize) {
639
+ // Ordinal number
640
+ if (token === 'yo') {
641
+ var signedYear = date.getUTCFullYear();
642
+ // Returns 1 for 1 BC (which is year 0 in JavaScript)
643
+ var year = signedYear > 0 ? signedYear : 1 - signedYear;
644
+ return localize.ordinalNumber(year, {
645
+ unit: 'year'
646
+ });
647
+ }
648
+ return formatters$1.y(date, token);
649
+ },
650
+ // Local week-numbering year
651
+ Y: function Y(date, token, localize, options) {
652
+ var signedWeekYear = getUTCWeekYear(date, options);
653
+ // Returns 1 for 1 BC (which is year 0 in JavaScript)
654
+ var weekYear = signedWeekYear > 0 ? signedWeekYear : 1 - signedWeekYear;
655
+
656
+ // Two digit year
657
+ if (token === 'YY') {
658
+ var twoDigitYear = weekYear % 100;
659
+ return addLeadingZeros(twoDigitYear, 2);
660
+ }
661
+
662
+ // Ordinal number
663
+ if (token === 'Yo') {
664
+ return localize.ordinalNumber(weekYear, {
665
+ unit: 'year'
666
+ });
667
+ }
668
+
669
+ // Padding
670
+ return addLeadingZeros(weekYear, token.length);
671
+ },
672
+ // ISO week-numbering year
673
+ R: function R(date, token) {
674
+ var isoWeekYear = getUTCISOWeekYear(date);
675
+
676
+ // Padding
677
+ return addLeadingZeros(isoWeekYear, token.length);
678
+ },
679
+ // Extended year. This is a single number designating the year of this calendar system.
680
+ // The main difference between `y` and `u` localizers are B.C. years:
681
+ // | Year | `y` | `u` |
682
+ // |------|-----|-----|
683
+ // | AC 1 | 1 | 1 |
684
+ // | BC 1 | 1 | 0 |
685
+ // | BC 2 | 2 | -1 |
686
+ // Also `yy` always returns the last two digits of a year,
687
+ // while `uu` pads single digit years to 2 characters and returns other years unchanged.
688
+ u: function u(date, token) {
689
+ var year = date.getUTCFullYear();
690
+ return addLeadingZeros(year, token.length);
691
+ },
692
+ // Quarter
693
+ Q: function Q(date, token, localize) {
694
+ var quarter = Math.ceil((date.getUTCMonth() + 1) / 3);
695
+ switch (token) {
696
+ // 1, 2, 3, 4
697
+ case 'Q':
698
+ return String(quarter);
699
+ // 01, 02, 03, 04
700
+ case 'QQ':
701
+ return addLeadingZeros(quarter, 2);
702
+ // 1st, 2nd, 3rd, 4th
703
+ case 'Qo':
704
+ return localize.ordinalNumber(quarter, {
705
+ unit: 'quarter'
706
+ });
707
+ // Q1, Q2, Q3, Q4
708
+ case 'QQQ':
709
+ return localize.quarter(quarter, {
710
+ width: 'abbreviated',
711
+ context: 'formatting'
712
+ });
713
+ // 1, 2, 3, 4 (narrow quarter; could be not numerical)
714
+ case 'QQQQQ':
715
+ return localize.quarter(quarter, {
716
+ width: 'narrow',
717
+ context: 'formatting'
718
+ });
719
+ // 1st quarter, 2nd quarter, ...
720
+ case 'QQQQ':
721
+ default:
722
+ return localize.quarter(quarter, {
723
+ width: 'wide',
724
+ context: 'formatting'
725
+ });
726
+ }
727
+ },
728
+ // Stand-alone quarter
729
+ q: function q(date, token, localize) {
730
+ var quarter = Math.ceil((date.getUTCMonth() + 1) / 3);
731
+ switch (token) {
732
+ // 1, 2, 3, 4
733
+ case 'q':
734
+ return String(quarter);
735
+ // 01, 02, 03, 04
736
+ case 'qq':
737
+ return addLeadingZeros(quarter, 2);
738
+ // 1st, 2nd, 3rd, 4th
739
+ case 'qo':
740
+ return localize.ordinalNumber(quarter, {
741
+ unit: 'quarter'
742
+ });
743
+ // Q1, Q2, Q3, Q4
744
+ case 'qqq':
745
+ return localize.quarter(quarter, {
746
+ width: 'abbreviated',
747
+ context: 'standalone'
748
+ });
749
+ // 1, 2, 3, 4 (narrow quarter; could be not numerical)
750
+ case 'qqqqq':
751
+ return localize.quarter(quarter, {
752
+ width: 'narrow',
753
+ context: 'standalone'
754
+ });
755
+ // 1st quarter, 2nd quarter, ...
756
+ case 'qqqq':
757
+ default:
758
+ return localize.quarter(quarter, {
759
+ width: 'wide',
760
+ context: 'standalone'
761
+ });
762
+ }
763
+ },
764
+ // Month
765
+ M: function M(date, token, localize) {
766
+ var month = date.getUTCMonth();
767
+ switch (token) {
768
+ case 'M':
769
+ case 'MM':
770
+ return formatters$1.M(date, token);
771
+ // 1st, 2nd, ..., 12th
772
+ case 'Mo':
773
+ return localize.ordinalNumber(month + 1, {
774
+ unit: 'month'
775
+ });
776
+ // Jan, Feb, ..., Dec
777
+ case 'MMM':
778
+ return localize.month(month, {
779
+ width: 'abbreviated',
780
+ context: 'formatting'
781
+ });
782
+ // J, F, ..., D
783
+ case 'MMMMM':
784
+ return localize.month(month, {
785
+ width: 'narrow',
786
+ context: 'formatting'
787
+ });
788
+ // January, February, ..., December
789
+ case 'MMMM':
790
+ default:
791
+ return localize.month(month, {
792
+ width: 'wide',
793
+ context: 'formatting'
794
+ });
795
+ }
796
+ },
797
+ // Stand-alone month
798
+ L: function L(date, token, localize) {
799
+ var month = date.getUTCMonth();
800
+ switch (token) {
801
+ // 1, 2, ..., 12
802
+ case 'L':
803
+ return String(month + 1);
804
+ // 01, 02, ..., 12
805
+ case 'LL':
806
+ return addLeadingZeros(month + 1, 2);
807
+ // 1st, 2nd, ..., 12th
808
+ case 'Lo':
809
+ return localize.ordinalNumber(month + 1, {
810
+ unit: 'month'
811
+ });
812
+ // Jan, Feb, ..., Dec
813
+ case 'LLL':
814
+ return localize.month(month, {
815
+ width: 'abbreviated',
816
+ context: 'standalone'
817
+ });
818
+ // J, F, ..., D
819
+ case 'LLLLL':
820
+ return localize.month(month, {
821
+ width: 'narrow',
822
+ context: 'standalone'
823
+ });
824
+ // January, February, ..., December
825
+ case 'LLLL':
826
+ default:
827
+ return localize.month(month, {
828
+ width: 'wide',
829
+ context: 'standalone'
830
+ });
831
+ }
832
+ },
833
+ // Local week of year
834
+ w: function w(date, token, localize, options) {
835
+ var week = getUTCWeek(date, options);
836
+ if (token === 'wo') {
837
+ return localize.ordinalNumber(week, {
838
+ unit: 'week'
839
+ });
840
+ }
841
+ return addLeadingZeros(week, token.length);
842
+ },
843
+ // ISO week of year
844
+ I: function I(date, token, localize) {
845
+ var isoWeek = getUTCISOWeek(date);
846
+ if (token === 'Io') {
847
+ return localize.ordinalNumber(isoWeek, {
848
+ unit: 'week'
849
+ });
850
+ }
851
+ return addLeadingZeros(isoWeek, token.length);
852
+ },
853
+ // Day of the month
854
+ d: function d(date, token, localize) {
855
+ if (token === 'do') {
856
+ return localize.ordinalNumber(date.getUTCDate(), {
857
+ unit: 'date'
858
+ });
859
+ }
860
+ return formatters$1.d(date, token);
861
+ },
862
+ // Day of year
863
+ D: function D(date, token, localize) {
864
+ var dayOfYear = getUTCDayOfYear(date);
865
+ if (token === 'Do') {
866
+ return localize.ordinalNumber(dayOfYear, {
867
+ unit: 'dayOfYear'
868
+ });
869
+ }
870
+ return addLeadingZeros(dayOfYear, token.length);
871
+ },
872
+ // Day of week
873
+ E: function E(date, token, localize) {
874
+ var dayOfWeek = date.getUTCDay();
875
+ switch (token) {
876
+ // Tue
877
+ case 'E':
878
+ case 'EE':
879
+ case 'EEE':
880
+ return localize.day(dayOfWeek, {
881
+ width: 'abbreviated',
882
+ context: 'formatting'
883
+ });
884
+ // T
885
+ case 'EEEEE':
886
+ return localize.day(dayOfWeek, {
887
+ width: 'narrow',
888
+ context: 'formatting'
889
+ });
890
+ // Tu
891
+ case 'EEEEEE':
892
+ return localize.day(dayOfWeek, {
893
+ width: 'short',
894
+ context: 'formatting'
895
+ });
896
+ // Tuesday
897
+ case 'EEEE':
898
+ default:
899
+ return localize.day(dayOfWeek, {
900
+ width: 'wide',
901
+ context: 'formatting'
902
+ });
903
+ }
904
+ },
905
+ // Local day of week
906
+ e: function e(date, token, localize, options) {
907
+ var dayOfWeek = date.getUTCDay();
908
+ var localDayOfWeek = (dayOfWeek - options.weekStartsOn + 8) % 7 || 7;
909
+ switch (token) {
910
+ // Numerical value (Nth day of week with current locale or weekStartsOn)
911
+ case 'e':
912
+ return String(localDayOfWeek);
913
+ // Padded numerical value
914
+ case 'ee':
915
+ return addLeadingZeros(localDayOfWeek, 2);
916
+ // 1st, 2nd, ..., 7th
917
+ case 'eo':
918
+ return localize.ordinalNumber(localDayOfWeek, {
919
+ unit: 'day'
920
+ });
921
+ case 'eee':
922
+ return localize.day(dayOfWeek, {
923
+ width: 'abbreviated',
924
+ context: 'formatting'
925
+ });
926
+ // T
927
+ case 'eeeee':
928
+ return localize.day(dayOfWeek, {
929
+ width: 'narrow',
930
+ context: 'formatting'
931
+ });
932
+ // Tu
933
+ case 'eeeeee':
934
+ return localize.day(dayOfWeek, {
935
+ width: 'short',
936
+ context: 'formatting'
937
+ });
938
+ // Tuesday
939
+ case 'eeee':
940
+ default:
941
+ return localize.day(dayOfWeek, {
942
+ width: 'wide',
943
+ context: 'formatting'
944
+ });
945
+ }
946
+ },
947
+ // Stand-alone local day of week
948
+ c: function c(date, token, localize, options) {
949
+ var dayOfWeek = date.getUTCDay();
950
+ var localDayOfWeek = (dayOfWeek - options.weekStartsOn + 8) % 7 || 7;
951
+ switch (token) {
952
+ // Numerical value (same as in `e`)
953
+ case 'c':
954
+ return String(localDayOfWeek);
955
+ // Padded numerical value
956
+ case 'cc':
957
+ return addLeadingZeros(localDayOfWeek, token.length);
958
+ // 1st, 2nd, ..., 7th
959
+ case 'co':
960
+ return localize.ordinalNumber(localDayOfWeek, {
961
+ unit: 'day'
962
+ });
963
+ case 'ccc':
964
+ return localize.day(dayOfWeek, {
965
+ width: 'abbreviated',
966
+ context: 'standalone'
967
+ });
968
+ // T
969
+ case 'ccccc':
970
+ return localize.day(dayOfWeek, {
971
+ width: 'narrow',
972
+ context: 'standalone'
973
+ });
974
+ // Tu
975
+ case 'cccccc':
976
+ return localize.day(dayOfWeek, {
977
+ width: 'short',
978
+ context: 'standalone'
979
+ });
980
+ // Tuesday
981
+ case 'cccc':
982
+ default:
983
+ return localize.day(dayOfWeek, {
984
+ width: 'wide',
985
+ context: 'standalone'
986
+ });
987
+ }
988
+ },
989
+ // ISO day of week
990
+ i: function i(date, token, localize) {
991
+ var dayOfWeek = date.getUTCDay();
992
+ var isoDayOfWeek = dayOfWeek === 0 ? 7 : dayOfWeek;
993
+ switch (token) {
994
+ // 2
995
+ case 'i':
996
+ return String(isoDayOfWeek);
997
+ // 02
998
+ case 'ii':
999
+ return addLeadingZeros(isoDayOfWeek, token.length);
1000
+ // 2nd
1001
+ case 'io':
1002
+ return localize.ordinalNumber(isoDayOfWeek, {
1003
+ unit: 'day'
1004
+ });
1005
+ // Tue
1006
+ case 'iii':
1007
+ return localize.day(dayOfWeek, {
1008
+ width: 'abbreviated',
1009
+ context: 'formatting'
1010
+ });
1011
+ // T
1012
+ case 'iiiii':
1013
+ return localize.day(dayOfWeek, {
1014
+ width: 'narrow',
1015
+ context: 'formatting'
1016
+ });
1017
+ // Tu
1018
+ case 'iiiiii':
1019
+ return localize.day(dayOfWeek, {
1020
+ width: 'short',
1021
+ context: 'formatting'
1022
+ });
1023
+ // Tuesday
1024
+ case 'iiii':
1025
+ default:
1026
+ return localize.day(dayOfWeek, {
1027
+ width: 'wide',
1028
+ context: 'formatting'
1029
+ });
1030
+ }
1031
+ },
1032
+ // AM or PM
1033
+ a: function a(date, token, localize) {
1034
+ var hours = date.getUTCHours();
1035
+ var dayPeriodEnumValue = hours / 12 >= 1 ? 'pm' : 'am';
1036
+ switch (token) {
1037
+ case 'a':
1038
+ case 'aa':
1039
+ return localize.dayPeriod(dayPeriodEnumValue, {
1040
+ width: 'abbreviated',
1041
+ context: 'formatting'
1042
+ });
1043
+ case 'aaa':
1044
+ return localize.dayPeriod(dayPeriodEnumValue, {
1045
+ width: 'abbreviated',
1046
+ context: 'formatting'
1047
+ }).toLowerCase();
1048
+ case 'aaaaa':
1049
+ return localize.dayPeriod(dayPeriodEnumValue, {
1050
+ width: 'narrow',
1051
+ context: 'formatting'
1052
+ });
1053
+ case 'aaaa':
1054
+ default:
1055
+ return localize.dayPeriod(dayPeriodEnumValue, {
1056
+ width: 'wide',
1057
+ context: 'formatting'
1058
+ });
1059
+ }
1060
+ },
1061
+ // AM, PM, midnight, noon
1062
+ b: function b(date, token, localize) {
1063
+ var hours = date.getUTCHours();
1064
+ var dayPeriodEnumValue;
1065
+ if (hours === 12) {
1066
+ dayPeriodEnumValue = dayPeriodEnum.noon;
1067
+ } else if (hours === 0) {
1068
+ dayPeriodEnumValue = dayPeriodEnum.midnight;
1069
+ } else {
1070
+ dayPeriodEnumValue = hours / 12 >= 1 ? 'pm' : 'am';
1071
+ }
1072
+ switch (token) {
1073
+ case 'b':
1074
+ case 'bb':
1075
+ return localize.dayPeriod(dayPeriodEnumValue, {
1076
+ width: 'abbreviated',
1077
+ context: 'formatting'
1078
+ });
1079
+ case 'bbb':
1080
+ return localize.dayPeriod(dayPeriodEnumValue, {
1081
+ width: 'abbreviated',
1082
+ context: 'formatting'
1083
+ }).toLowerCase();
1084
+ case 'bbbbb':
1085
+ return localize.dayPeriod(dayPeriodEnumValue, {
1086
+ width: 'narrow',
1087
+ context: 'formatting'
1088
+ });
1089
+ case 'bbbb':
1090
+ default:
1091
+ return localize.dayPeriod(dayPeriodEnumValue, {
1092
+ width: 'wide',
1093
+ context: 'formatting'
1094
+ });
1095
+ }
1096
+ },
1097
+ // in the morning, in the afternoon, in the evening, at night
1098
+ B: function B(date, token, localize) {
1099
+ var hours = date.getUTCHours();
1100
+ var dayPeriodEnumValue;
1101
+ if (hours >= 17) {
1102
+ dayPeriodEnumValue = dayPeriodEnum.evening;
1103
+ } else if (hours >= 12) {
1104
+ dayPeriodEnumValue = dayPeriodEnum.afternoon;
1105
+ } else if (hours >= 4) {
1106
+ dayPeriodEnumValue = dayPeriodEnum.morning;
1107
+ } else {
1108
+ dayPeriodEnumValue = dayPeriodEnum.night;
1109
+ }
1110
+ switch (token) {
1111
+ case 'B':
1112
+ case 'BB':
1113
+ case 'BBB':
1114
+ return localize.dayPeriod(dayPeriodEnumValue, {
1115
+ width: 'abbreviated',
1116
+ context: 'formatting'
1117
+ });
1118
+ case 'BBBBB':
1119
+ return localize.dayPeriod(dayPeriodEnumValue, {
1120
+ width: 'narrow',
1121
+ context: 'formatting'
1122
+ });
1123
+ case 'BBBB':
1124
+ default:
1125
+ return localize.dayPeriod(dayPeriodEnumValue, {
1126
+ width: 'wide',
1127
+ context: 'formatting'
1128
+ });
1129
+ }
1130
+ },
1131
+ // Hour [1-12]
1132
+ h: function h(date, token, localize) {
1133
+ if (token === 'ho') {
1134
+ var hours = date.getUTCHours() % 12;
1135
+ if (hours === 0) hours = 12;
1136
+ return localize.ordinalNumber(hours, {
1137
+ unit: 'hour'
1138
+ });
1139
+ }
1140
+ return formatters$1.h(date, token);
1141
+ },
1142
+ // Hour [0-23]
1143
+ H: function H(date, token, localize) {
1144
+ if (token === 'Ho') {
1145
+ return localize.ordinalNumber(date.getUTCHours(), {
1146
+ unit: 'hour'
1147
+ });
1148
+ }
1149
+ return formatters$1.H(date, token);
1150
+ },
1151
+ // Hour [0-11]
1152
+ K: function K(date, token, localize) {
1153
+ var hours = date.getUTCHours() % 12;
1154
+ if (token === 'Ko') {
1155
+ return localize.ordinalNumber(hours, {
1156
+ unit: 'hour'
1157
+ });
1158
+ }
1159
+ return addLeadingZeros(hours, token.length);
1160
+ },
1161
+ // Hour [1-24]
1162
+ k: function k(date, token, localize) {
1163
+ var hours = date.getUTCHours();
1164
+ if (hours === 0) hours = 24;
1165
+ if (token === 'ko') {
1166
+ return localize.ordinalNumber(hours, {
1167
+ unit: 'hour'
1168
+ });
1169
+ }
1170
+ return addLeadingZeros(hours, token.length);
1171
+ },
1172
+ // Minute
1173
+ m: function m(date, token, localize) {
1174
+ if (token === 'mo') {
1175
+ return localize.ordinalNumber(date.getUTCMinutes(), {
1176
+ unit: 'minute'
1177
+ });
1178
+ }
1179
+ return formatters$1.m(date, token);
1180
+ },
1181
+ // Second
1182
+ s: function s(date, token, localize) {
1183
+ if (token === 'so') {
1184
+ return localize.ordinalNumber(date.getUTCSeconds(), {
1185
+ unit: 'second'
1186
+ });
1187
+ }
1188
+ return formatters$1.s(date, token);
1189
+ },
1190
+ // Fraction of second
1191
+ S: function S(date, token) {
1192
+ return formatters$1.S(date, token);
1193
+ },
1194
+ // Timezone (ISO-8601. If offset is 0, output is always `'Z'`)
1195
+ X: function X(date, token, _localize, options) {
1196
+ var originalDate = options._originalDate || date;
1197
+ var timezoneOffset = originalDate.getTimezoneOffset();
1198
+ if (timezoneOffset === 0) {
1199
+ return 'Z';
1200
+ }
1201
+ switch (token) {
1202
+ // Hours and optional minutes
1203
+ case 'X':
1204
+ return formatTimezoneWithOptionalMinutes(timezoneOffset);
1205
+
1206
+ // Hours, minutes and optional seconds without `:` delimiter
1207
+ // Note: neither ISO-8601 nor JavaScript supports seconds in timezone offsets
1208
+ // so this token always has the same output as `XX`
1209
+ case 'XXXX':
1210
+ case 'XX':
1211
+ // Hours and minutes without `:` delimiter
1212
+ return formatTimezone(timezoneOffset);
1213
+
1214
+ // Hours, minutes and optional seconds with `:` delimiter
1215
+ // Note: neither ISO-8601 nor JavaScript supports seconds in timezone offsets
1216
+ // so this token always has the same output as `XXX`
1217
+ case 'XXXXX':
1218
+ case 'XXX': // Hours and minutes with `:` delimiter
1219
+ default:
1220
+ return formatTimezone(timezoneOffset, ':');
1221
+ }
1222
+ },
1223
+ // Timezone (ISO-8601. If offset is 0, output is `'+00:00'` or equivalent)
1224
+ x: function x(date, token, _localize, options) {
1225
+ var originalDate = options._originalDate || date;
1226
+ var timezoneOffset = originalDate.getTimezoneOffset();
1227
+ switch (token) {
1228
+ // Hours and optional minutes
1229
+ case 'x':
1230
+ return formatTimezoneWithOptionalMinutes(timezoneOffset);
1231
+
1232
+ // Hours, minutes and optional seconds without `:` delimiter
1233
+ // Note: neither ISO-8601 nor JavaScript supports seconds in timezone offsets
1234
+ // so this token always has the same output as `xx`
1235
+ case 'xxxx':
1236
+ case 'xx':
1237
+ // Hours and minutes without `:` delimiter
1238
+ return formatTimezone(timezoneOffset);
1239
+
1240
+ // Hours, minutes and optional seconds with `:` delimiter
1241
+ // Note: neither ISO-8601 nor JavaScript supports seconds in timezone offsets
1242
+ // so this token always has the same output as `xxx`
1243
+ case 'xxxxx':
1244
+ case 'xxx': // Hours and minutes with `:` delimiter
1245
+ default:
1246
+ return formatTimezone(timezoneOffset, ':');
1247
+ }
1248
+ },
1249
+ // Timezone (GMT)
1250
+ O: function O(date, token, _localize, options) {
1251
+ var originalDate = options._originalDate || date;
1252
+ var timezoneOffset = originalDate.getTimezoneOffset();
1253
+ switch (token) {
1254
+ // Short
1255
+ case 'O':
1256
+ case 'OO':
1257
+ case 'OOO':
1258
+ return 'GMT' + formatTimezoneShort(timezoneOffset, ':');
1259
+ // Long
1260
+ case 'OOOO':
1261
+ default:
1262
+ return 'GMT' + formatTimezone(timezoneOffset, ':');
1263
+ }
1264
+ },
1265
+ // Timezone (specific non-location)
1266
+ z: function z(date, token, _localize, options) {
1267
+ var originalDate = options._originalDate || date;
1268
+ var timezoneOffset = originalDate.getTimezoneOffset();
1269
+ switch (token) {
1270
+ // Short
1271
+ case 'z':
1272
+ case 'zz':
1273
+ case 'zzz':
1274
+ return 'GMT' + formatTimezoneShort(timezoneOffset, ':');
1275
+ // Long
1276
+ case 'zzzz':
1277
+ default:
1278
+ return 'GMT' + formatTimezone(timezoneOffset, ':');
1279
+ }
1280
+ },
1281
+ // Seconds timestamp
1282
+ t: function t(date, token, _localize, options) {
1283
+ var originalDate = options._originalDate || date;
1284
+ var timestamp = Math.floor(originalDate.getTime() / 1000);
1285
+ return addLeadingZeros(timestamp, token.length);
1286
+ },
1287
+ // Milliseconds timestamp
1288
+ T: function T(date, token, _localize, options) {
1289
+ var originalDate = options._originalDate || date;
1290
+ var timestamp = originalDate.getTime();
1291
+ return addLeadingZeros(timestamp, token.length);
1292
+ }
1293
+ };
1294
+ function formatTimezoneShort(offset, dirtyDelimiter) {
1295
+ var sign = offset > 0 ? '-' : '+';
1296
+ var absOffset = Math.abs(offset);
1297
+ var hours = Math.floor(absOffset / 60);
1298
+ var minutes = absOffset % 60;
1299
+ if (minutes === 0) {
1300
+ return sign + String(hours);
1301
+ }
1302
+ var delimiter = dirtyDelimiter || '';
1303
+ return sign + String(hours) + delimiter + addLeadingZeros(minutes, 2);
1304
+ }
1305
+ function formatTimezoneWithOptionalMinutes(offset, dirtyDelimiter) {
1306
+ if (offset % 60 === 0) {
1307
+ var sign = offset > 0 ? '-' : '+';
1308
+ return sign + addLeadingZeros(Math.abs(offset) / 60, 2);
1309
+ }
1310
+ return formatTimezone(offset, dirtyDelimiter);
1311
+ }
1312
+ function formatTimezone(offset, dirtyDelimiter) {
1313
+ var delimiter = dirtyDelimiter || '';
1314
+ var sign = offset > 0 ? '-' : '+';
1315
+ var absOffset = Math.abs(offset);
1316
+ var hours = addLeadingZeros(Math.floor(absOffset / 60), 2);
1317
+ var minutes = addLeadingZeros(absOffset % 60, 2);
1318
+ return sign + hours + delimiter + minutes;
1319
+ }
1320
+
1321
+ var dateLongFormatter = function dateLongFormatter(pattern, formatLong) {
1322
+ switch (pattern) {
1323
+ case 'P':
1324
+ return formatLong.date({
1325
+ width: 'short'
1326
+ });
1327
+ case 'PP':
1328
+ return formatLong.date({
1329
+ width: 'medium'
1330
+ });
1331
+ case 'PPP':
1332
+ return formatLong.date({
1333
+ width: 'long'
1334
+ });
1335
+ case 'PPPP':
1336
+ default:
1337
+ return formatLong.date({
1338
+ width: 'full'
1339
+ });
1340
+ }
1341
+ };
1342
+ var timeLongFormatter = function timeLongFormatter(pattern, formatLong) {
1343
+ switch (pattern) {
1344
+ case 'p':
1345
+ return formatLong.time({
1346
+ width: 'short'
1347
+ });
1348
+ case 'pp':
1349
+ return formatLong.time({
1350
+ width: 'medium'
1351
+ });
1352
+ case 'ppp':
1353
+ return formatLong.time({
1354
+ width: 'long'
1355
+ });
1356
+ case 'pppp':
1357
+ default:
1358
+ return formatLong.time({
1359
+ width: 'full'
1360
+ });
1361
+ }
1362
+ };
1363
+ var dateTimeLongFormatter = function dateTimeLongFormatter(pattern, formatLong) {
1364
+ var matchResult = pattern.match(/(P+)(p+)?/) || [];
1365
+ var datePattern = matchResult[1];
1366
+ var timePattern = matchResult[2];
1367
+ if (!timePattern) {
1368
+ return dateLongFormatter(pattern, formatLong);
1369
+ }
1370
+ var dateTimeFormat;
1371
+ switch (datePattern) {
1372
+ case 'P':
1373
+ dateTimeFormat = formatLong.dateTime({
1374
+ width: 'short'
1375
+ });
1376
+ break;
1377
+ case 'PP':
1378
+ dateTimeFormat = formatLong.dateTime({
1379
+ width: 'medium'
1380
+ });
1381
+ break;
1382
+ case 'PPP':
1383
+ dateTimeFormat = formatLong.dateTime({
1384
+ width: 'long'
1385
+ });
1386
+ break;
1387
+ case 'PPPP':
1388
+ default:
1389
+ dateTimeFormat = formatLong.dateTime({
1390
+ width: 'full'
1391
+ });
1392
+ break;
1393
+ }
1394
+ return dateTimeFormat.replace('{{date}}', dateLongFormatter(datePattern, formatLong)).replace('{{time}}', timeLongFormatter(timePattern, formatLong));
1395
+ };
1396
+ var longFormatters = {
1397
+ p: timeLongFormatter,
1398
+ P: dateTimeLongFormatter
1399
+ };
1400
+
1401
+ var protectedDayOfYearTokens = ['D', 'DD'];
1402
+ var protectedWeekYearTokens = ['YY', 'YYYY'];
1403
+ function isProtectedDayOfYearToken(token) {
1404
+ return protectedDayOfYearTokens.indexOf(token) !== -1;
1405
+ }
1406
+ function isProtectedWeekYearToken(token) {
1407
+ return protectedWeekYearTokens.indexOf(token) !== -1;
1408
+ }
1409
+ function throwProtectedError(token, format, input) {
1410
+ if (token === 'YYYY') {
1411
+ throw new RangeError("Use `yyyy` instead of `YYYY` (in `".concat(format, "`) for formatting years to the input `").concat(input, "`; see: https://github.com/date-fns/date-fns/blob/master/docs/unicodeTokens.md"));
1412
+ } else if (token === 'YY') {
1413
+ throw new RangeError("Use `yy` instead of `YY` (in `".concat(format, "`) for formatting years to the input `").concat(input, "`; see: https://github.com/date-fns/date-fns/blob/master/docs/unicodeTokens.md"));
1414
+ } else if (token === 'D') {
1415
+ throw new RangeError("Use `d` instead of `D` (in `".concat(format, "`) for formatting days of the month to the input `").concat(input, "`; see: https://github.com/date-fns/date-fns/blob/master/docs/unicodeTokens.md"));
1416
+ } else if (token === 'DD') {
1417
+ throw new RangeError("Use `dd` instead of `DD` (in `".concat(format, "`) for formatting days of the month to the input `").concat(input, "`; see: https://github.com/date-fns/date-fns/blob/master/docs/unicodeTokens.md"));
1418
+ }
1419
+ }
1420
+
1421
+ var formatDistanceLocale = {
1422
+ lessThanXSeconds: {
1423
+ one: 'less than a second',
1424
+ other: 'less than {{count}} seconds'
1425
+ },
1426
+ xSeconds: {
1427
+ one: '1 second',
1428
+ other: '{{count}} seconds'
1429
+ },
1430
+ halfAMinute: 'half a minute',
1431
+ lessThanXMinutes: {
1432
+ one: 'less than a minute',
1433
+ other: 'less than {{count}} minutes'
1434
+ },
1435
+ xMinutes: {
1436
+ one: '1 minute',
1437
+ other: '{{count}} minutes'
1438
+ },
1439
+ aboutXHours: {
1440
+ one: 'about 1 hour',
1441
+ other: 'about {{count}} hours'
1442
+ },
1443
+ xHours: {
1444
+ one: '1 hour',
1445
+ other: '{{count}} hours'
1446
+ },
1447
+ xDays: {
1448
+ one: '1 day',
1449
+ other: '{{count}} days'
1450
+ },
1451
+ aboutXWeeks: {
1452
+ one: 'about 1 week',
1453
+ other: 'about {{count}} weeks'
1454
+ },
1455
+ xWeeks: {
1456
+ one: '1 week',
1457
+ other: '{{count}} weeks'
1458
+ },
1459
+ aboutXMonths: {
1460
+ one: 'about 1 month',
1461
+ other: 'about {{count}} months'
1462
+ },
1463
+ xMonths: {
1464
+ one: '1 month',
1465
+ other: '{{count}} months'
1466
+ },
1467
+ aboutXYears: {
1468
+ one: 'about 1 year',
1469
+ other: 'about {{count}} years'
1470
+ },
1471
+ xYears: {
1472
+ one: '1 year',
1473
+ other: '{{count}} years'
1474
+ },
1475
+ overXYears: {
1476
+ one: 'over 1 year',
1477
+ other: 'over {{count}} years'
1478
+ },
1479
+ almostXYears: {
1480
+ one: 'almost 1 year',
1481
+ other: 'almost {{count}} years'
1482
+ }
1483
+ };
1484
+ var formatDistance = function formatDistance(token, count, options) {
1485
+ var result;
1486
+ var tokenValue = formatDistanceLocale[token];
1487
+ if (typeof tokenValue === 'string') {
1488
+ result = tokenValue;
1489
+ } else if (count === 1) {
1490
+ result = tokenValue.one;
1491
+ } else {
1492
+ result = tokenValue.other.replace('{{count}}', count.toString());
1493
+ }
1494
+ if (options !== null && options !== void 0 && options.addSuffix) {
1495
+ if (options.comparison && options.comparison > 0) {
1496
+ return 'in ' + result;
1497
+ } else {
1498
+ return result + ' ago';
1499
+ }
1500
+ }
1501
+ return result;
1502
+ };
1503
+
1504
+ function buildFormatLongFn(args) {
1505
+ return function () {
1506
+ var options = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {};
1507
+ // TODO: Remove String()
1508
+ var width = options.width ? String(options.width) : args.defaultWidth;
1509
+ var format = args.formats[width] || args.formats[args.defaultWidth];
1510
+ return format;
1511
+ };
1512
+ }
1513
+
1514
+ var dateFormats = {
1515
+ full: 'EEEE, MMMM do, y',
1516
+ long: 'MMMM do, y',
1517
+ medium: 'MMM d, y',
1518
+ short: 'MM/dd/yyyy'
1519
+ };
1520
+ var timeFormats = {
1521
+ full: 'h:mm:ss a zzzz',
1522
+ long: 'h:mm:ss a z',
1523
+ medium: 'h:mm:ss a',
1524
+ short: 'h:mm a'
1525
+ };
1526
+ var dateTimeFormats = {
1527
+ full: "{{date}} 'at' {{time}}",
1528
+ long: "{{date}} 'at' {{time}}",
1529
+ medium: '{{date}}, {{time}}',
1530
+ short: '{{date}}, {{time}}'
1531
+ };
1532
+ var formatLong = {
1533
+ date: buildFormatLongFn({
1534
+ formats: dateFormats,
1535
+ defaultWidth: 'full'
1536
+ }),
1537
+ time: buildFormatLongFn({
1538
+ formats: timeFormats,
1539
+ defaultWidth: 'full'
1540
+ }),
1541
+ dateTime: buildFormatLongFn({
1542
+ formats: dateTimeFormats,
1543
+ defaultWidth: 'full'
1544
+ })
1545
+ };
1546
+
1547
+ var formatRelativeLocale = {
1548
+ lastWeek: "'last' eeee 'at' p",
1549
+ yesterday: "'yesterday at' p",
1550
+ today: "'today at' p",
1551
+ tomorrow: "'tomorrow at' p",
1552
+ nextWeek: "eeee 'at' p",
1553
+ other: 'P'
1554
+ };
1555
+ var formatRelative = function formatRelative(token, _date, _baseDate, _options) {
1556
+ return formatRelativeLocale[token];
1557
+ };
1558
+
1559
+ function buildLocalizeFn(args) {
1560
+ return function (dirtyIndex, options) {
1561
+ var context = options !== null && options !== void 0 && options.context ? String(options.context) : 'standalone';
1562
+ var valuesArray;
1563
+ if (context === 'formatting' && args.formattingValues) {
1564
+ var defaultWidth = args.defaultFormattingWidth || args.defaultWidth;
1565
+ var width = options !== null && options !== void 0 && options.width ? String(options.width) : defaultWidth;
1566
+ valuesArray = args.formattingValues[width] || args.formattingValues[defaultWidth];
1567
+ } else {
1568
+ var _defaultWidth = args.defaultWidth;
1569
+ var _width = options !== null && options !== void 0 && options.width ? String(options.width) : args.defaultWidth;
1570
+ valuesArray = args.values[_width] || args.values[_defaultWidth];
1571
+ }
1572
+ var index = args.argumentCallback ? args.argumentCallback(dirtyIndex) : dirtyIndex;
1573
+ // @ts-ignore: For some reason TypeScript just don't want to match it, no matter how hard we try. I challenge you to try to remove it!
1574
+ return valuesArray[index];
1575
+ };
1576
+ }
1577
+
1578
+ var eraValues = {
1579
+ narrow: ['B', 'A'],
1580
+ abbreviated: ['BC', 'AD'],
1581
+ wide: ['Before Christ', 'Anno Domini']
1582
+ };
1583
+ var quarterValues = {
1584
+ narrow: ['1', '2', '3', '4'],
1585
+ abbreviated: ['Q1', 'Q2', 'Q3', 'Q4'],
1586
+ wide: ['1st quarter', '2nd quarter', '3rd quarter', '4th quarter']
1587
+ };
1588
+
1589
+ // Note: in English, the names of days of the week and months are capitalized.
1590
+ // If you are making a new locale based on this one, check if the same is true for the language you're working on.
1591
+ // Generally, formatted dates should look like they are in the middle of a sentence,
1592
+ // e.g. in Spanish language the weekdays and months should be in the lowercase.
1593
+ var monthValues = {
1594
+ narrow: ['J', 'F', 'M', 'A', 'M', 'J', 'J', 'A', 'S', 'O', 'N', 'D'],
1595
+ abbreviated: ['Jan', 'Feb', 'Mar', 'Apr', 'May', 'Jun', 'Jul', 'Aug', 'Sep', 'Oct', 'Nov', 'Dec'],
1596
+ wide: ['January', 'February', 'March', 'April', 'May', 'June', 'July', 'August', 'September', 'October', 'November', 'December']
1597
+ };
1598
+ var dayValues = {
1599
+ narrow: ['S', 'M', 'T', 'W', 'T', 'F', 'S'],
1600
+ short: ['Su', 'Mo', 'Tu', 'We', 'Th', 'Fr', 'Sa'],
1601
+ abbreviated: ['Sun', 'Mon', 'Tue', 'Wed', 'Thu', 'Fri', 'Sat'],
1602
+ wide: ['Sunday', 'Monday', 'Tuesday', 'Wednesday', 'Thursday', 'Friday', 'Saturday']
1603
+ };
1604
+ var dayPeriodValues = {
1605
+ narrow: {
1606
+ am: 'a',
1607
+ pm: 'p',
1608
+ midnight: 'mi',
1609
+ noon: 'n',
1610
+ morning: 'morning',
1611
+ afternoon: 'afternoon',
1612
+ evening: 'evening',
1613
+ night: 'night'
1614
+ },
1615
+ abbreviated: {
1616
+ am: 'AM',
1617
+ pm: 'PM',
1618
+ midnight: 'midnight',
1619
+ noon: 'noon',
1620
+ morning: 'morning',
1621
+ afternoon: 'afternoon',
1622
+ evening: 'evening',
1623
+ night: 'night'
1624
+ },
1625
+ wide: {
1626
+ am: 'a.m.',
1627
+ pm: 'p.m.',
1628
+ midnight: 'midnight',
1629
+ noon: 'noon',
1630
+ morning: 'morning',
1631
+ afternoon: 'afternoon',
1632
+ evening: 'evening',
1633
+ night: 'night'
1634
+ }
1635
+ };
1636
+ var formattingDayPeriodValues = {
1637
+ narrow: {
1638
+ am: 'a',
1639
+ pm: 'p',
1640
+ midnight: 'mi',
1641
+ noon: 'n',
1642
+ morning: 'in the morning',
1643
+ afternoon: 'in the afternoon',
1644
+ evening: 'in the evening',
1645
+ night: 'at night'
1646
+ },
1647
+ abbreviated: {
1648
+ am: 'AM',
1649
+ pm: 'PM',
1650
+ midnight: 'midnight',
1651
+ noon: 'noon',
1652
+ morning: 'in the morning',
1653
+ afternoon: 'in the afternoon',
1654
+ evening: 'in the evening',
1655
+ night: 'at night'
1656
+ },
1657
+ wide: {
1658
+ am: 'a.m.',
1659
+ pm: 'p.m.',
1660
+ midnight: 'midnight',
1661
+ noon: 'noon',
1662
+ morning: 'in the morning',
1663
+ afternoon: 'in the afternoon',
1664
+ evening: 'in the evening',
1665
+ night: 'at night'
1666
+ }
1667
+ };
1668
+ var ordinalNumber = function ordinalNumber(dirtyNumber, _options) {
1669
+ var number = Number(dirtyNumber);
1670
+
1671
+ // If ordinal numbers depend on context, for example,
1672
+ // if they are different for different grammatical genders,
1673
+ // use `options.unit`.
1674
+ //
1675
+ // `unit` can be 'year', 'quarter', 'month', 'week', 'date', 'dayOfYear',
1676
+ // 'day', 'hour', 'minute', 'second'.
1677
+
1678
+ var rem100 = number % 100;
1679
+ if (rem100 > 20 || rem100 < 10) {
1680
+ switch (rem100 % 10) {
1681
+ case 1:
1682
+ return number + 'st';
1683
+ case 2:
1684
+ return number + 'nd';
1685
+ case 3:
1686
+ return number + 'rd';
1687
+ }
1688
+ }
1689
+ return number + 'th';
1690
+ };
1691
+ var localize = {
1692
+ ordinalNumber: ordinalNumber,
1693
+ era: buildLocalizeFn({
1694
+ values: eraValues,
1695
+ defaultWidth: 'wide'
1696
+ }),
1697
+ quarter: buildLocalizeFn({
1698
+ values: quarterValues,
1699
+ defaultWidth: 'wide',
1700
+ argumentCallback: function argumentCallback(quarter) {
1701
+ return quarter - 1;
1702
+ }
1703
+ }),
1704
+ month: buildLocalizeFn({
1705
+ values: monthValues,
1706
+ defaultWidth: 'wide'
1707
+ }),
1708
+ day: buildLocalizeFn({
1709
+ values: dayValues,
1710
+ defaultWidth: 'wide'
1711
+ }),
1712
+ dayPeriod: buildLocalizeFn({
1713
+ values: dayPeriodValues,
1714
+ defaultWidth: 'wide',
1715
+ formattingValues: formattingDayPeriodValues,
1716
+ defaultFormattingWidth: 'wide'
1717
+ })
1718
+ };
1719
+
1720
+ function buildMatchFn(args) {
1721
+ return function (string) {
1722
+ var options = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {};
1723
+ var width = options.width;
1724
+ var matchPattern = width && args.matchPatterns[width] || args.matchPatterns[args.defaultMatchWidth];
1725
+ var matchResult = string.match(matchPattern);
1726
+ if (!matchResult) {
1727
+ return null;
1728
+ }
1729
+ var matchedString = matchResult[0];
1730
+ var parsePatterns = width && args.parsePatterns[width] || args.parsePatterns[args.defaultParseWidth];
1731
+ var key = Array.isArray(parsePatterns) ? findIndex(parsePatterns, function (pattern) {
1732
+ return pattern.test(matchedString);
1733
+ }) : findKey(parsePatterns, function (pattern) {
1734
+ return pattern.test(matchedString);
1735
+ });
1736
+ var value;
1737
+ value = args.valueCallback ? args.valueCallback(key) : key;
1738
+ value = options.valueCallback ? options.valueCallback(value) : value;
1739
+ var rest = string.slice(matchedString.length);
1740
+ return {
1741
+ value: value,
1742
+ rest: rest
1743
+ };
1744
+ };
1745
+ }
1746
+ function findKey(object, predicate) {
1747
+ for (var key in object) {
1748
+ if (object.hasOwnProperty(key) && predicate(object[key])) {
1749
+ return key;
1750
+ }
1751
+ }
1752
+ return undefined;
1753
+ }
1754
+ function findIndex(array, predicate) {
1755
+ for (var key = 0; key < array.length; key++) {
1756
+ if (predicate(array[key])) {
1757
+ return key;
1758
+ }
1759
+ }
1760
+ return undefined;
1761
+ }
1762
+
1763
+ function buildMatchPatternFn(args) {
1764
+ return function (string) {
1765
+ var options = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {};
1766
+ var matchResult = string.match(args.matchPattern);
1767
+ if (!matchResult) return null;
1768
+ var matchedString = matchResult[0];
1769
+ var parseResult = string.match(args.parsePattern);
1770
+ if (!parseResult) return null;
1771
+ var value = args.valueCallback ? args.valueCallback(parseResult[0]) : parseResult[0];
1772
+ value = options.valueCallback ? options.valueCallback(value) : value;
1773
+ var rest = string.slice(matchedString.length);
1774
+ return {
1775
+ value: value,
1776
+ rest: rest
1777
+ };
1778
+ };
1779
+ }
1780
+
1781
+ var matchOrdinalNumberPattern = /^(\d+)(th|st|nd|rd)?/i;
1782
+ var parseOrdinalNumberPattern = /\d+/i;
1783
+ var matchEraPatterns = {
1784
+ narrow: /^(b|a)/i,
1785
+ abbreviated: /^(b\.?\s?c\.?|b\.?\s?c\.?\s?e\.?|a\.?\s?d\.?|c\.?\s?e\.?)/i,
1786
+ wide: /^(before christ|before common era|anno domini|common era)/i
1787
+ };
1788
+ var parseEraPatterns = {
1789
+ any: [/^b/i, /^(a|c)/i]
1790
+ };
1791
+ var matchQuarterPatterns = {
1792
+ narrow: /^[1234]/i,
1793
+ abbreviated: /^q[1234]/i,
1794
+ wide: /^[1234](th|st|nd|rd)? quarter/i
1795
+ };
1796
+ var parseQuarterPatterns = {
1797
+ any: [/1/i, /2/i, /3/i, /4/i]
1798
+ };
1799
+ var matchMonthPatterns = {
1800
+ narrow: /^[jfmasond]/i,
1801
+ abbreviated: /^(jan|feb|mar|apr|may|jun|jul|aug|sep|oct|nov|dec)/i,
1802
+ wide: /^(january|february|march|april|may|june|july|august|september|october|november|december)/i
1803
+ };
1804
+ var parseMonthPatterns = {
1805
+ narrow: [/^j/i, /^f/i, /^m/i, /^a/i, /^m/i, /^j/i, /^j/i, /^a/i, /^s/i, /^o/i, /^n/i, /^d/i],
1806
+ any: [/^ja/i, /^f/i, /^mar/i, /^ap/i, /^may/i, /^jun/i, /^jul/i, /^au/i, /^s/i, /^o/i, /^n/i, /^d/i]
1807
+ };
1808
+ var matchDayPatterns = {
1809
+ narrow: /^[smtwf]/i,
1810
+ short: /^(su|mo|tu|we|th|fr|sa)/i,
1811
+ abbreviated: /^(sun|mon|tue|wed|thu|fri|sat)/i,
1812
+ wide: /^(sunday|monday|tuesday|wednesday|thursday|friday|saturday)/i
1813
+ };
1814
+ var parseDayPatterns = {
1815
+ narrow: [/^s/i, /^m/i, /^t/i, /^w/i, /^t/i, /^f/i, /^s/i],
1816
+ any: [/^su/i, /^m/i, /^tu/i, /^w/i, /^th/i, /^f/i, /^sa/i]
1817
+ };
1818
+ var matchDayPeriodPatterns = {
1819
+ narrow: /^(a|p|mi|n|(in the|at) (morning|afternoon|evening|night))/i,
1820
+ any: /^([ap]\.?\s?m\.?|midnight|noon|(in the|at) (morning|afternoon|evening|night))/i
1821
+ };
1822
+ var parseDayPeriodPatterns = {
1823
+ any: {
1824
+ am: /^a/i,
1825
+ pm: /^p/i,
1826
+ midnight: /^mi/i,
1827
+ noon: /^no/i,
1828
+ morning: /morning/i,
1829
+ afternoon: /afternoon/i,
1830
+ evening: /evening/i,
1831
+ night: /night/i
1832
+ }
1833
+ };
1834
+ var match = {
1835
+ ordinalNumber: buildMatchPatternFn({
1836
+ matchPattern: matchOrdinalNumberPattern,
1837
+ parsePattern: parseOrdinalNumberPattern,
1838
+ valueCallback: function valueCallback(value) {
1839
+ return parseInt(value, 10);
1840
+ }
1841
+ }),
1842
+ era: buildMatchFn({
1843
+ matchPatterns: matchEraPatterns,
1844
+ defaultMatchWidth: 'wide',
1845
+ parsePatterns: parseEraPatterns,
1846
+ defaultParseWidth: 'any'
1847
+ }),
1848
+ quarter: buildMatchFn({
1849
+ matchPatterns: matchQuarterPatterns,
1850
+ defaultMatchWidth: 'wide',
1851
+ parsePatterns: parseQuarterPatterns,
1852
+ defaultParseWidth: 'any',
1853
+ valueCallback: function valueCallback(index) {
1854
+ return index + 1;
1855
+ }
1856
+ }),
1857
+ month: buildMatchFn({
1858
+ matchPatterns: matchMonthPatterns,
1859
+ defaultMatchWidth: 'wide',
1860
+ parsePatterns: parseMonthPatterns,
1861
+ defaultParseWidth: 'any'
1862
+ }),
1863
+ day: buildMatchFn({
1864
+ matchPatterns: matchDayPatterns,
1865
+ defaultMatchWidth: 'wide',
1866
+ parsePatterns: parseDayPatterns,
1867
+ defaultParseWidth: 'any'
1868
+ }),
1869
+ dayPeriod: buildMatchFn({
1870
+ matchPatterns: matchDayPeriodPatterns,
1871
+ defaultMatchWidth: 'any',
1872
+ parsePatterns: parseDayPeriodPatterns,
1873
+ defaultParseWidth: 'any'
1874
+ })
1875
+ };
1876
+
1877
+ /**
1878
+ * @type {Locale}
1879
+ * @category Locales
1880
+ * @summary English locale (United States).
1881
+ * @language English
1882
+ * @iso-639-2 eng
1883
+ * @author Sasha Koss [@kossnocorp]{@link https://github.com/kossnocorp}
1884
+ * @author Lesha Koss [@leshakoss]{@link https://github.com/leshakoss}
1885
+ */
1886
+ var locale = {
1887
+ code: 'en-US',
1888
+ formatDistance: formatDistance,
1889
+ formatLong: formatLong,
1890
+ formatRelative: formatRelative,
1891
+ localize: localize,
1892
+ match: match,
1893
+ options: {
1894
+ weekStartsOn: 0 /* Sunday */,
1895
+ firstWeekContainsDate: 1
1896
+ }
1897
+ };
1898
+
1899
+ // - [yYQqMLwIdDecihHKkms]o matches any available ordinal number token
1900
+ // (one of the certain letters followed by `o`)
1901
+ // - (\w)\1* matches any sequences of the same letter
1902
+ // - '' matches two quote characters in a row
1903
+ // - '(''|[^'])+('|$) matches anything surrounded by two quote characters ('),
1904
+ // except a single quote symbol, which ends the sequence.
1905
+ // Two quote characters do not end the sequence.
1906
+ // If there is no matching single quote
1907
+ // then the sequence will continue until the end of the string.
1908
+ // - . matches any single character unmatched by previous parts of the RegExps
1909
+ var formattingTokensRegExp = /[yYQqMLwIdDecihHKkms]o|(\w)\1*|''|'(''|[^'])+('|$)|./g;
1910
+
1911
+ // This RegExp catches symbols escaped by quotes, and also
1912
+ // sequences of symbols P, p, and the combinations like `PPPPPPPppppp`
1913
+ var longFormattingTokensRegExp = /P+p+|P+|p+|''|'(''|[^'])+('|$)|./g;
1914
+ var escapedStringRegExp = /^'([^]*?)'?$/;
1915
+ var doubleQuoteRegExp = /''/g;
1916
+ var unescapedLatinCharacterRegExp = /[a-zA-Z]/;
1917
+
1918
+ /**
1919
+ * @name format
1920
+ * @category Common Helpers
1921
+ * @summary Format the date.
1922
+ *
1923
+ * @description
1924
+ * Return the formatted date string in the given format. The result may vary by locale.
1925
+ *
1926
+ * > ⚠️ Please note that the `format` tokens differ from Moment.js and other libraries.
1927
+ * > See: https://github.com/date-fns/date-fns/blob/master/docs/unicodeTokens.md
1928
+ *
1929
+ * The characters wrapped between two single quotes characters (') are escaped.
1930
+ * Two single quotes in a row, whether inside or outside a quoted sequence, represent a 'real' single quote.
1931
+ * (see the last example)
1932
+ *
1933
+ * Format of the string is based on Unicode Technical Standard #35:
1934
+ * https://www.unicode.org/reports/tr35/tr35-dates.html#Date_Field_Symbol_Table
1935
+ * with a few additions (see note 7 below the table).
1936
+ *
1937
+ * Accepted patterns:
1938
+ * | Unit | Pattern | Result examples | Notes |
1939
+ * |---------------------------------|---------|-----------------------------------|-------|
1940
+ * | Era | G..GGG | AD, BC | |
1941
+ * | | GGGG | Anno Domini, Before Christ | 2 |
1942
+ * | | GGGGG | A, B | |
1943
+ * | Calendar year | y | 44, 1, 1900, 2017 | 5 |
1944
+ * | | yo | 44th, 1st, 0th, 17th | 5,7 |
1945
+ * | | yy | 44, 01, 00, 17 | 5 |
1946
+ * | | yyy | 044, 001, 1900, 2017 | 5 |
1947
+ * | | yyyy | 0044, 0001, 1900, 2017 | 5 |
1948
+ * | | yyyyy | ... | 3,5 |
1949
+ * | Local week-numbering year | Y | 44, 1, 1900, 2017 | 5 |
1950
+ * | | Yo | 44th, 1st, 1900th, 2017th | 5,7 |
1951
+ * | | YY | 44, 01, 00, 17 | 5,8 |
1952
+ * | | YYY | 044, 001, 1900, 2017 | 5 |
1953
+ * | | YYYY | 0044, 0001, 1900, 2017 | 5,8 |
1954
+ * | | YYYYY | ... | 3,5 |
1955
+ * | ISO week-numbering year | R | -43, 0, 1, 1900, 2017 | 5,7 |
1956
+ * | | RR | -43, 00, 01, 1900, 2017 | 5,7 |
1957
+ * | | RRR | -043, 000, 001, 1900, 2017 | 5,7 |
1958
+ * | | RRRR | -0043, 0000, 0001, 1900, 2017 | 5,7 |
1959
+ * | | RRRRR | ... | 3,5,7 |
1960
+ * | Extended year | u | -43, 0, 1, 1900, 2017 | 5 |
1961
+ * | | uu | -43, 01, 1900, 2017 | 5 |
1962
+ * | | uuu | -043, 001, 1900, 2017 | 5 |
1963
+ * | | uuuu | -0043, 0001, 1900, 2017 | 5 |
1964
+ * | | uuuuu | ... | 3,5 |
1965
+ * | Quarter (formatting) | Q | 1, 2, 3, 4 | |
1966
+ * | | Qo | 1st, 2nd, 3rd, 4th | 7 |
1967
+ * | | QQ | 01, 02, 03, 04 | |
1968
+ * | | QQQ | Q1, Q2, Q3, Q4 | |
1969
+ * | | QQQQ | 1st quarter, 2nd quarter, ... | 2 |
1970
+ * | | QQQQQ | 1, 2, 3, 4 | 4 |
1971
+ * | Quarter (stand-alone) | q | 1, 2, 3, 4 | |
1972
+ * | | qo | 1st, 2nd, 3rd, 4th | 7 |
1973
+ * | | qq | 01, 02, 03, 04 | |
1974
+ * | | qqq | Q1, Q2, Q3, Q4 | |
1975
+ * | | qqqq | 1st quarter, 2nd quarter, ... | 2 |
1976
+ * | | qqqqq | 1, 2, 3, 4 | 4 |
1977
+ * | Month (formatting) | M | 1, 2, ..., 12 | |
1978
+ * | | Mo | 1st, 2nd, ..., 12th | 7 |
1979
+ * | | MM | 01, 02, ..., 12 | |
1980
+ * | | MMM | Jan, Feb, ..., Dec | |
1981
+ * | | MMMM | January, February, ..., December | 2 |
1982
+ * | | MMMMM | J, F, ..., D | |
1983
+ * | Month (stand-alone) | L | 1, 2, ..., 12 | |
1984
+ * | | Lo | 1st, 2nd, ..., 12th | 7 |
1985
+ * | | LL | 01, 02, ..., 12 | |
1986
+ * | | LLL | Jan, Feb, ..., Dec | |
1987
+ * | | LLLL | January, February, ..., December | 2 |
1988
+ * | | LLLLL | J, F, ..., D | |
1989
+ * | Local week of year | w | 1, 2, ..., 53 | |
1990
+ * | | wo | 1st, 2nd, ..., 53th | 7 |
1991
+ * | | ww | 01, 02, ..., 53 | |
1992
+ * | ISO week of year | I | 1, 2, ..., 53 | 7 |
1993
+ * | | Io | 1st, 2nd, ..., 53th | 7 |
1994
+ * | | II | 01, 02, ..., 53 | 7 |
1995
+ * | Day of month | d | 1, 2, ..., 31 | |
1996
+ * | | do | 1st, 2nd, ..., 31st | 7 |
1997
+ * | | dd | 01, 02, ..., 31 | |
1998
+ * | Day of year | D | 1, 2, ..., 365, 366 | 9 |
1999
+ * | | Do | 1st, 2nd, ..., 365th, 366th | 7 |
2000
+ * | | DD | 01, 02, ..., 365, 366 | 9 |
2001
+ * | | DDD | 001, 002, ..., 365, 366 | |
2002
+ * | | DDDD | ... | 3 |
2003
+ * | Day of week (formatting) | E..EEE | Mon, Tue, Wed, ..., Sun | |
2004
+ * | | EEEE | Monday, Tuesday, ..., Sunday | 2 |
2005
+ * | | EEEEE | M, T, W, T, F, S, S | |
2006
+ * | | EEEEEE | Mo, Tu, We, Th, Fr, Sa, Su | |
2007
+ * | ISO day of week (formatting) | i | 1, 2, 3, ..., 7 | 7 |
2008
+ * | | io | 1st, 2nd, ..., 7th | 7 |
2009
+ * | | ii | 01, 02, ..., 07 | 7 |
2010
+ * | | iii | Mon, Tue, Wed, ..., Sun | 7 |
2011
+ * | | iiii | Monday, Tuesday, ..., Sunday | 2,7 |
2012
+ * | | iiiii | M, T, W, T, F, S, S | 7 |
2013
+ * | | iiiiii | Mo, Tu, We, Th, Fr, Sa, Su | 7 |
2014
+ * | Local day of week (formatting) | e | 2, 3, 4, ..., 1 | |
2015
+ * | | eo | 2nd, 3rd, ..., 1st | 7 |
2016
+ * | | ee | 02, 03, ..., 01 | |
2017
+ * | | eee | Mon, Tue, Wed, ..., Sun | |
2018
+ * | | eeee | Monday, Tuesday, ..., Sunday | 2 |
2019
+ * | | eeeee | M, T, W, T, F, S, S | |
2020
+ * | | eeeeee | Mo, Tu, We, Th, Fr, Sa, Su | |
2021
+ * | Local day of week (stand-alone) | c | 2, 3, 4, ..., 1 | |
2022
+ * | | co | 2nd, 3rd, ..., 1st | 7 |
2023
+ * | | cc | 02, 03, ..., 01 | |
2024
+ * | | ccc | Mon, Tue, Wed, ..., Sun | |
2025
+ * | | cccc | Monday, Tuesday, ..., Sunday | 2 |
2026
+ * | | ccccc | M, T, W, T, F, S, S | |
2027
+ * | | cccccc | Mo, Tu, We, Th, Fr, Sa, Su | |
2028
+ * | AM, PM | a..aa | AM, PM | |
2029
+ * | | aaa | am, pm | |
2030
+ * | | aaaa | a.m., p.m. | 2 |
2031
+ * | | aaaaa | a, p | |
2032
+ * | AM, PM, noon, midnight | b..bb | AM, PM, noon, midnight | |
2033
+ * | | bbb | am, pm, noon, midnight | |
2034
+ * | | bbbb | a.m., p.m., noon, midnight | 2 |
2035
+ * | | bbbbb | a, p, n, mi | |
2036
+ * | Flexible day period | B..BBB | at night, in the morning, ... | |
2037
+ * | | BBBB | at night, in the morning, ... | 2 |
2038
+ * | | BBBBB | at night, in the morning, ... | |
2039
+ * | Hour [1-12] | h | 1, 2, ..., 11, 12 | |
2040
+ * | | ho | 1st, 2nd, ..., 11th, 12th | 7 |
2041
+ * | | hh | 01, 02, ..., 11, 12 | |
2042
+ * | Hour [0-23] | H | 0, 1, 2, ..., 23 | |
2043
+ * | | Ho | 0th, 1st, 2nd, ..., 23rd | 7 |
2044
+ * | | HH | 00, 01, 02, ..., 23 | |
2045
+ * | Hour [0-11] | K | 1, 2, ..., 11, 0 | |
2046
+ * | | Ko | 1st, 2nd, ..., 11th, 0th | 7 |
2047
+ * | | KK | 01, 02, ..., 11, 00 | |
2048
+ * | Hour [1-24] | k | 24, 1, 2, ..., 23 | |
2049
+ * | | ko | 24th, 1st, 2nd, ..., 23rd | 7 |
2050
+ * | | kk | 24, 01, 02, ..., 23 | |
2051
+ * | Minute | m | 0, 1, ..., 59 | |
2052
+ * | | mo | 0th, 1st, ..., 59th | 7 |
2053
+ * | | mm | 00, 01, ..., 59 | |
2054
+ * | Second | s | 0, 1, ..., 59 | |
2055
+ * | | so | 0th, 1st, ..., 59th | 7 |
2056
+ * | | ss | 00, 01, ..., 59 | |
2057
+ * | Fraction of second | S | 0, 1, ..., 9 | |
2058
+ * | | SS | 00, 01, ..., 99 | |
2059
+ * | | SSS | 000, 001, ..., 999 | |
2060
+ * | | SSSS | ... | 3 |
2061
+ * | Timezone (ISO-8601 w/ Z) | X | -08, +0530, Z | |
2062
+ * | | XX | -0800, +0530, Z | |
2063
+ * | | XXX | -08:00, +05:30, Z | |
2064
+ * | | XXXX | -0800, +0530, Z, +123456 | 2 |
2065
+ * | | XXXXX | -08:00, +05:30, Z, +12:34:56 | |
2066
+ * | Timezone (ISO-8601 w/o Z) | x | -08, +0530, +00 | |
2067
+ * | | xx | -0800, +0530, +0000 | |
2068
+ * | | xxx | -08:00, +05:30, +00:00 | 2 |
2069
+ * | | xxxx | -0800, +0530, +0000, +123456 | |
2070
+ * | | xxxxx | -08:00, +05:30, +00:00, +12:34:56 | |
2071
+ * | Timezone (GMT) | O...OOO | GMT-8, GMT+5:30, GMT+0 | |
2072
+ * | | OOOO | GMT-08:00, GMT+05:30, GMT+00:00 | 2 |
2073
+ * | Timezone (specific non-locat.) | z...zzz | GMT-8, GMT+5:30, GMT+0 | 6 |
2074
+ * | | zzzz | GMT-08:00, GMT+05:30, GMT+00:00 | 2,6 |
2075
+ * | Seconds timestamp | t | 512969520 | 7 |
2076
+ * | | tt | ... | 3,7 |
2077
+ * | Milliseconds timestamp | T | 512969520900 | 7 |
2078
+ * | | TT | ... | 3,7 |
2079
+ * | Long localized date | P | 04/29/1453 | 7 |
2080
+ * | | PP | Apr 29, 1453 | 7 |
2081
+ * | | PPP | April 29th, 1453 | 7 |
2082
+ * | | PPPP | Friday, April 29th, 1453 | 2,7 |
2083
+ * | Long localized time | p | 12:00 AM | 7 |
2084
+ * | | pp | 12:00:00 AM | 7 |
2085
+ * | | ppp | 12:00:00 AM GMT+2 | 7 |
2086
+ * | | pppp | 12:00:00 AM GMT+02:00 | 2,7 |
2087
+ * | Combination of date and time | Pp | 04/29/1453, 12:00 AM | 7 |
2088
+ * | | PPpp | Apr 29, 1453, 12:00:00 AM | 7 |
2089
+ * | | PPPppp | April 29th, 1453 at ... | 7 |
2090
+ * | | PPPPpppp| Friday, April 29th, 1453 at ... | 2,7 |
2091
+ * Notes:
2092
+ * 1. "Formatting" units (e.g. formatting quarter) in the default en-US locale
2093
+ * are the same as "stand-alone" units, but are different in some languages.
2094
+ * "Formatting" units are declined according to the rules of the language
2095
+ * in the context of a date. "Stand-alone" units are always nominative singular:
2096
+ *
2097
+ * `format(new Date(2017, 10, 6), 'do LLLL', {locale: cs}) //=> '6. listopad'`
2098
+ *
2099
+ * `format(new Date(2017, 10, 6), 'do MMMM', {locale: cs}) //=> '6. listopadu'`
2100
+ *
2101
+ * 2. Any sequence of the identical letters is a pattern, unless it is escaped by
2102
+ * the single quote characters (see below).
2103
+ * If the sequence is longer than listed in table (e.g. `EEEEEEEEEEE`)
2104
+ * the output will be the same as default pattern for this unit, usually
2105
+ * the longest one (in case of ISO weekdays, `EEEE`). Default patterns for units
2106
+ * are marked with "2" in the last column of the table.
2107
+ *
2108
+ * `format(new Date(2017, 10, 6), 'MMM') //=> 'Nov'`
2109
+ *
2110
+ * `format(new Date(2017, 10, 6), 'MMMM') //=> 'November'`
2111
+ *
2112
+ * `format(new Date(2017, 10, 6), 'MMMMM') //=> 'N'`
2113
+ *
2114
+ * `format(new Date(2017, 10, 6), 'MMMMMM') //=> 'November'`
2115
+ *
2116
+ * `format(new Date(2017, 10, 6), 'MMMMMMM') //=> 'November'`
2117
+ *
2118
+ * 3. Some patterns could be unlimited length (such as `yyyyyyyy`).
2119
+ * The output will be padded with zeros to match the length of the pattern.
2120
+ *
2121
+ * `format(new Date(2017, 10, 6), 'yyyyyyyy') //=> '00002017'`
2122
+ *
2123
+ * 4. `QQQQQ` and `qqqqq` could be not strictly numerical in some locales.
2124
+ * These tokens represent the shortest form of the quarter.
2125
+ *
2126
+ * 5. The main difference between `y` and `u` patterns are B.C. years:
2127
+ *
2128
+ * | Year | `y` | `u` |
2129
+ * |------|-----|-----|
2130
+ * | AC 1 | 1 | 1 |
2131
+ * | BC 1 | 1 | 0 |
2132
+ * | BC 2 | 2 | -1 |
2133
+ *
2134
+ * Also `yy` always returns the last two digits of a year,
2135
+ * while `uu` pads single digit years to 2 characters and returns other years unchanged:
2136
+ *
2137
+ * | Year | `yy` | `uu` |
2138
+ * |------|------|------|
2139
+ * | 1 | 01 | 01 |
2140
+ * | 14 | 14 | 14 |
2141
+ * | 376 | 76 | 376 |
2142
+ * | 1453 | 53 | 1453 |
2143
+ *
2144
+ * The same difference is true for local and ISO week-numbering years (`Y` and `R`),
2145
+ * except local week-numbering years are dependent on `options.weekStartsOn`
2146
+ * and `options.firstWeekContainsDate` (compare [getISOWeekYear]{@link https://date-fns.org/docs/getISOWeekYear}
2147
+ * and [getWeekYear]{@link https://date-fns.org/docs/getWeekYear}).
2148
+ *
2149
+ * 6. Specific non-location timezones are currently unavailable in `date-fns`,
2150
+ * so right now these tokens fall back to GMT timezones.
2151
+ *
2152
+ * 7. These patterns are not in the Unicode Technical Standard #35:
2153
+ * - `i`: ISO day of week
2154
+ * - `I`: ISO week of year
2155
+ * - `R`: ISO week-numbering year
2156
+ * - `t`: seconds timestamp
2157
+ * - `T`: milliseconds timestamp
2158
+ * - `o`: ordinal number modifier
2159
+ * - `P`: long localized date
2160
+ * - `p`: long localized time
2161
+ *
2162
+ * 8. `YY` and `YYYY` tokens represent week-numbering years but they are often confused with years.
2163
+ * You should enable `options.useAdditionalWeekYearTokens` to use them. See: https://github.com/date-fns/date-fns/blob/master/docs/unicodeTokens.md
2164
+ *
2165
+ * 9. `D` and `DD` tokens represent days of the year but they are often confused with days of the month.
2166
+ * You should enable `options.useAdditionalDayOfYearTokens` to use them. See: https://github.com/date-fns/date-fns/blob/master/docs/unicodeTokens.md
2167
+ *
2168
+ * @param {Date|Number} date - the original date
2169
+ * @param {String} format - the string of tokens
2170
+ * @param {Object} [options] - an object with options.
2171
+ * @param {Locale} [options.locale=defaultLocale] - the locale object. See [Locale]{@link https://date-fns.org/docs/Locale}
2172
+ * @param {0|1|2|3|4|5|6} [options.weekStartsOn=0] - the index of the first day of the week (0 - Sunday)
2173
+ * @param {Number} [options.firstWeekContainsDate=1] - the day of January, which is
2174
+ * @param {Boolean} [options.useAdditionalWeekYearTokens=false] - if true, allows usage of the week-numbering year tokens `YY` and `YYYY`;
2175
+ * see: https://github.com/date-fns/date-fns/blob/master/docs/unicodeTokens.md
2176
+ * @param {Boolean} [options.useAdditionalDayOfYearTokens=false] - if true, allows usage of the day of year tokens `D` and `DD`;
2177
+ * see: https://github.com/date-fns/date-fns/blob/master/docs/unicodeTokens.md
2178
+ * @returns {String} the formatted date string
2179
+ * @throws {TypeError} 2 arguments required
2180
+ * @throws {RangeError} `date` must not be Invalid Date
2181
+ * @throws {RangeError} `options.locale` must contain `localize` property
2182
+ * @throws {RangeError} `options.locale` must contain `formatLong` property
2183
+ * @throws {RangeError} `options.weekStartsOn` must be between 0 and 6
2184
+ * @throws {RangeError} `options.firstWeekContainsDate` must be between 1 and 7
2185
+ * @throws {RangeError} use `yyyy` instead of `YYYY` for formatting years using [format provided] to the input [input provided]; see: https://github.com/date-fns/date-fns/blob/master/docs/unicodeTokens.md
2186
+ * @throws {RangeError} use `yy` instead of `YY` for formatting years using [format provided] to the input [input provided]; see: https://github.com/date-fns/date-fns/blob/master/docs/unicodeTokens.md
2187
+ * @throws {RangeError} use `d` instead of `D` for formatting days of the month using [format provided] to the input [input provided]; see: https://github.com/date-fns/date-fns/blob/master/docs/unicodeTokens.md
2188
+ * @throws {RangeError} use `dd` instead of `DD` for formatting days of the month using [format provided] to the input [input provided]; see: https://github.com/date-fns/date-fns/blob/master/docs/unicodeTokens.md
2189
+ * @throws {RangeError} format string contains an unescaped latin alphabet character
2190
+ *
2191
+ * @example
2192
+ * // Represent 11 February 2014 in middle-endian format:
2193
+ * const result = format(new Date(2014, 1, 11), 'MM/dd/yyyy')
2194
+ * //=> '02/11/2014'
2195
+ *
2196
+ * @example
2197
+ * // Represent 2 July 2014 in Esperanto:
2198
+ * import { eoLocale } from 'date-fns/locale/eo'
2199
+ * const result = format(new Date(2014, 6, 2), "do 'de' MMMM yyyy", {
2200
+ * locale: eoLocale
2201
+ * })
2202
+ * //=> '2-a de julio 2014'
2203
+ *
2204
+ * @example
2205
+ * // Escape string by single quote characters:
2206
+ * const result = format(new Date(2014, 6, 2, 15), "h 'o''clock'")
2207
+ * //=> "3 o'clock"
2208
+ */
2209
+
2210
+ function format(dirtyDate, dirtyFormatStr, options) {
2211
+ var _ref, _options$locale, _ref2, _ref3, _ref4, _options$firstWeekCon, _options$locale2, _options$locale2$opti, _defaultOptions$local, _defaultOptions$local2, _ref5, _ref6, _ref7, _options$weekStartsOn, _options$locale3, _options$locale3$opti, _defaultOptions$local3, _defaultOptions$local4;
2212
+ requiredArgs(2, arguments);
2213
+ var formatStr = String(dirtyFormatStr);
2214
+ var defaultOptions = getDefaultOptions();
2215
+ var locale$1 = (_ref = (_options$locale = options === null || options === void 0 ? void 0 : options.locale) !== null && _options$locale !== void 0 ? _options$locale : defaultOptions.locale) !== null && _ref !== void 0 ? _ref : locale;
2216
+ var firstWeekContainsDate = toInteger((_ref2 = (_ref3 = (_ref4 = (_options$firstWeekCon = options === null || options === void 0 ? void 0 : options.firstWeekContainsDate) !== null && _options$firstWeekCon !== void 0 ? _options$firstWeekCon : options === null || options === void 0 ? void 0 : (_options$locale2 = options.locale) === null || _options$locale2 === void 0 ? void 0 : (_options$locale2$opti = _options$locale2.options) === null || _options$locale2$opti === void 0 ? void 0 : _options$locale2$opti.firstWeekContainsDate) !== null && _ref4 !== void 0 ? _ref4 : defaultOptions.firstWeekContainsDate) !== null && _ref3 !== void 0 ? _ref3 : (_defaultOptions$local = defaultOptions.locale) === null || _defaultOptions$local === void 0 ? void 0 : (_defaultOptions$local2 = _defaultOptions$local.options) === null || _defaultOptions$local2 === void 0 ? void 0 : _defaultOptions$local2.firstWeekContainsDate) !== null && _ref2 !== void 0 ? _ref2 : 1);
2217
+
2218
+ // Test if weekStartsOn is between 1 and 7 _and_ is not NaN
2219
+ if (!(firstWeekContainsDate >= 1 && firstWeekContainsDate <= 7)) {
2220
+ throw new RangeError('firstWeekContainsDate must be between 1 and 7 inclusively');
2221
+ }
2222
+ var weekStartsOn = toInteger((_ref5 = (_ref6 = (_ref7 = (_options$weekStartsOn = options === null || options === void 0 ? void 0 : options.weekStartsOn) !== null && _options$weekStartsOn !== void 0 ? _options$weekStartsOn : options === null || options === void 0 ? void 0 : (_options$locale3 = options.locale) === null || _options$locale3 === void 0 ? void 0 : (_options$locale3$opti = _options$locale3.options) === null || _options$locale3$opti === void 0 ? void 0 : _options$locale3$opti.weekStartsOn) !== null && _ref7 !== void 0 ? _ref7 : defaultOptions.weekStartsOn) !== null && _ref6 !== void 0 ? _ref6 : (_defaultOptions$local3 = defaultOptions.locale) === null || _defaultOptions$local3 === void 0 ? void 0 : (_defaultOptions$local4 = _defaultOptions$local3.options) === null || _defaultOptions$local4 === void 0 ? void 0 : _defaultOptions$local4.weekStartsOn) !== null && _ref5 !== void 0 ? _ref5 : 0);
2223
+
2224
+ // Test if weekStartsOn is between 0 and 6 _and_ is not NaN
2225
+ if (!(weekStartsOn >= 0 && weekStartsOn <= 6)) {
2226
+ throw new RangeError('weekStartsOn must be between 0 and 6 inclusively');
2227
+ }
2228
+ if (!locale$1.localize) {
2229
+ throw new RangeError('locale must contain localize property');
2230
+ }
2231
+ if (!locale$1.formatLong) {
2232
+ throw new RangeError('locale must contain formatLong property');
2233
+ }
2234
+ var originalDate = toDate(dirtyDate);
2235
+ if (!isValid(originalDate)) {
2236
+ throw new RangeError('Invalid time value');
2237
+ }
2238
+
2239
+ // Convert the date in system timezone to the same date in UTC+00:00 timezone.
2240
+ // This ensures that when UTC functions will be implemented, locales will be compatible with them.
2241
+ // See an issue about UTC functions: https://github.com/date-fns/date-fns/issues/376
2242
+ var timezoneOffset = getTimezoneOffsetInMilliseconds(originalDate);
2243
+ var utcDate = subMilliseconds(originalDate, timezoneOffset);
2244
+ var formatterOptions = {
2245
+ firstWeekContainsDate: firstWeekContainsDate,
2246
+ weekStartsOn: weekStartsOn,
2247
+ locale: locale$1,
2248
+ _originalDate: originalDate
2249
+ };
2250
+ var result = formatStr.match(longFormattingTokensRegExp).map(function (substring) {
2251
+ var firstCharacter = substring[0];
2252
+ if (firstCharacter === 'p' || firstCharacter === 'P') {
2253
+ var longFormatter = longFormatters[firstCharacter];
2254
+ return longFormatter(substring, locale$1.formatLong);
2255
+ }
2256
+ return substring;
2257
+ }).join('').match(formattingTokensRegExp).map(function (substring) {
2258
+ // Replace two single quote characters with one single quote character
2259
+ if (substring === "''") {
2260
+ return "'";
2261
+ }
2262
+ var firstCharacter = substring[0];
2263
+ if (firstCharacter === "'") {
2264
+ return cleanEscapedString(substring);
2265
+ }
2266
+ var formatter = formatters[firstCharacter];
2267
+ if (formatter) {
2268
+ if (!(options !== null && options !== void 0 && options.useAdditionalWeekYearTokens) && isProtectedWeekYearToken(substring)) {
2269
+ throwProtectedError(substring, dirtyFormatStr, String(dirtyDate));
2270
+ }
2271
+ if (!(options !== null && options !== void 0 && options.useAdditionalDayOfYearTokens) && isProtectedDayOfYearToken(substring)) {
2272
+ throwProtectedError(substring, dirtyFormatStr, String(dirtyDate));
2273
+ }
2274
+ return formatter(utcDate, substring, locale$1.localize, formatterOptions);
2275
+ }
2276
+ if (firstCharacter.match(unescapedLatinCharacterRegExp)) {
2277
+ throw new RangeError('Format string contains an unescaped latin alphabet character `' + firstCharacter + '`');
2278
+ }
2279
+ return substring;
2280
+ }).join('');
2281
+ return result;
2282
+ }
2283
+ function cleanEscapedString(input) {
2284
+ var matched = input.match(escapedStringRegExp);
2285
+ if (!matched) {
2286
+ return input;
2287
+ }
2288
+ return matched[1].replace(doubleQuoteRegExp, "'");
2289
+ }
2290
+
2291
+ /**
2292
+ * Default values for all Dinero objects.
2293
+ *
2294
+ * You can override default values for all subsequent Dinero objects by changing them directly on the global `Dinero` object.
2295
+ * Existing instances won't be affected.
2296
+ *
2297
+ * @property {Number} defaultAmount - The default amount for new Dinero objects (see {@link module:Dinero Dinero} for format).
2298
+ * @property {String} defaultCurrency - The default currency for new Dinero objects (see {@link module:Dinero Dinero} for format).
2299
+ * @property {Number} defaultPrecision - The default precision for new Dinero objects (see {@link module:Dinero Dinero} for format).
2300
+ *
2301
+ * @example
2302
+ * // Will set currency to 'EUR' for all Dinero objects.
2303
+ * Dinero.defaultCurrency = 'EUR'
2304
+ *
2305
+ * @type {Object}
2306
+ */
2307
+ var Defaults = {
2308
+ defaultAmount: 0,
2309
+ defaultCurrency: 'USD',
2310
+ defaultPrecision: 2
2311
+ };
2312
+ /**
2313
+ * Global settings for all Dinero objects.
2314
+ *
2315
+ * You can override global values for all subsequent Dinero objects by changing them directly on the global `Dinero` object.
2316
+ * Existing instances won't be affected.
2317
+ *
2318
+ * @property {String} globalLocale - The global locale for new Dinero objects (see {@link module:Dinero~setLocale setLocale} for format).
2319
+ * @property {String} globalFormat - The global format for new Dinero objects (see {@link module:Dinero~toFormat toFormat} for format).
2320
+ * @property {String} globalRoundingMode - The global rounding mode for new Dinero objects (see {@link module:Dinero~multiply multiply} or {@link module:Dinero~divide divide} for format).
2321
+ * @property {String} globalFormatRoundingMode - The global rounding mode to format new Dinero objects (see {@link module:Dinero~toFormat toFormat} or {@link module:Dinero~toRoundedUnit toRoundedUnit} for format).
2322
+ * @property {(String|Promise)} globalExchangeRatesApi.endpoint - The global exchange rate API endpoint for new Dinero objects, or the global promise that resolves to the exchanges rates (see {@link module:Dinero~convert convert} for format).
2323
+ * @property {String} globalExchangeRatesApi.propertyPath - The global exchange rate API property path for new Dinero objects (see {@link module:Dinero~convert convert} for format).
2324
+ * @property {Object} globalExchangeRatesApi.headers - The global exchange rate API headers for new Dinero objects (see {@link module:Dinero~convert convert} for format).
2325
+ *
2326
+ * @example
2327
+ * // Will set locale to 'fr-FR' for all Dinero objects.
2328
+ * Dinero.globalLocale = 'fr-FR'
2329
+ * @example
2330
+ * // Will set global exchange rate API parameters for all Dinero objects.
2331
+ * Dinero.globalExchangeRatesApi = {
2332
+ * endpoint: 'https://yourexchangerates.api/latest?base={{from}}',
2333
+ * propertyPath: 'data.rates.{{to}}',
2334
+ * headers: {
2335
+ * 'user-key': 'xxxxxxxxx'
2336
+ * }
2337
+ * }
2338
+ *
2339
+ * @type {Object}
2340
+ */
2341
+
2342
+ var Globals = {
2343
+ globalLocale: 'en-US',
2344
+ globalFormat: '$0,0.00',
2345
+ globalRoundingMode: 'HALF_EVEN',
2346
+ globalFormatRoundingMode: 'HALF_AWAY_FROM_ZERO',
2347
+ globalExchangeRatesApi: {
2348
+ endpoint: undefined,
2349
+ headers: undefined,
2350
+ propertyPath: undefined
2351
+ }
2352
+ };
2353
+
2354
+ function _typeof(obj) {
2355
+ "@babel/helpers - typeof";
2356
+
2357
+ if (typeof Symbol === "function" && typeof Symbol.iterator === "symbol") {
2358
+ _typeof = function (obj) {
2359
+ return typeof obj;
2360
+ };
2361
+ } else {
2362
+ _typeof = function (obj) {
2363
+ return obj && typeof Symbol === "function" && obj.constructor === Symbol && obj !== Symbol.prototype ? "symbol" : typeof obj;
2364
+ };
2365
+ }
2366
+
2367
+ return _typeof(obj);
2368
+ }
2369
+
2370
+ function _toArray(arr) {
2371
+ return _arrayWithHoles(arr) || _iterableToArray(arr) || _unsupportedIterableToArray(arr) || _nonIterableRest();
2372
+ }
2373
+
2374
+ function _arrayWithHoles(arr) {
2375
+ if (Array.isArray(arr)) return arr;
2376
+ }
2377
+
2378
+ function _iterableToArray(iter) {
2379
+ if (typeof Symbol !== "undefined" && Symbol.iterator in Object(iter)) return Array.from(iter);
2380
+ }
2381
+
2382
+ function _unsupportedIterableToArray(o, minLen) {
2383
+ if (!o) return;
2384
+ if (typeof o === "string") return _arrayLikeToArray(o, minLen);
2385
+ var n = Object.prototype.toString.call(o).slice(8, -1);
2386
+ if (n === "Object" && o.constructor) n = o.constructor.name;
2387
+ if (n === "Map" || n === "Set") return Array.from(o);
2388
+ if (n === "Arguments" || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n)) return _arrayLikeToArray(o, minLen);
2389
+ }
2390
+
2391
+ function _arrayLikeToArray(arr, len) {
2392
+ if (len == null || len > arr.length) len = arr.length;
2393
+
2394
+ for (var i = 0, arr2 = new Array(len); i < len; i++) arr2[i] = arr[i];
2395
+
2396
+ return arr2;
2397
+ }
2398
+
2399
+ function _nonIterableRest() {
2400
+ throw new TypeError("Invalid attempt to destructure non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.");
2401
+ }
2402
+
2403
+ /**
2404
+ * Static methods for Dinero.
2405
+ * @ignore
2406
+ *
2407
+ * @type {Object}
2408
+ */
2409
+ var Static = {
2410
+ /**
2411
+ * Returns an array of Dinero objects, normalized to the same precision (the highest).
2412
+ *
2413
+ * @memberof module:Dinero
2414
+ * @method
2415
+ *
2416
+ * @param {Dinero[]} objects - An array of Dinero objects
2417
+ *
2418
+ * @example
2419
+ * // returns an array of Dinero objects
2420
+ * // both with a precision of 3
2421
+ * // and an amount of 1000
2422
+ * Dinero.normalizePrecision([
2423
+ * Dinero({ amount: 100, precision: 2 }),
2424
+ * Dinero({ amount: 1000, precision: 3 })
2425
+ * ])
2426
+ *
2427
+ * @return {Dinero[]}
2428
+ */
2429
+ normalizePrecision: function normalizePrecision(objects) {
2430
+ var highestPrecision = objects.reduce(function (a, b) {
2431
+ return Math.max(a.getPrecision(), b.getPrecision());
2432
+ });
2433
+ return objects.map(function (object) {
2434
+ return object.getPrecision() !== highestPrecision ? object.convertPrecision(highestPrecision) : object;
2435
+ });
2436
+ },
2437
+
2438
+ /**
2439
+ * Returns the smallest Dinero object from an array of Dinero objects
2440
+ *
2441
+ * @memberof module:Dinero
2442
+ * @method
2443
+ *
2444
+ * @param {Dinero[]} objects - An array of Dinero objects
2445
+ *
2446
+ * @example
2447
+ * // returns the smallest Dinero object with amount of 500 from an array of Dinero objects with different precisions
2448
+ * Dinero.minimum([
2449
+ * Dinero({ amount: 500, precision: 3 }),
2450
+ * Dinero({ amount: 100, precision: 2 })
2451
+ * ])
2452
+ * @example
2453
+ * // returns the smallest Dinero object with amount of 50 from an array of Dinero objects
2454
+ * Dinero.minimum([
2455
+ * Dinero({ amount: 50 }),
2456
+ * Dinero({ amount: 100 })
2457
+ * ])
2458
+ *
2459
+ * @return {Dinero[]}
2460
+ */
2461
+ minimum: function minimum(objects) {
2462
+ var _objects = _toArray(objects),
2463
+ firstObject = _objects[0],
2464
+ tailObjects = _objects.slice(1);
2465
+
2466
+ var currentMinimum = firstObject;
2467
+ tailObjects.forEach(function (obj) {
2468
+ currentMinimum = currentMinimum.lessThan(obj) ? currentMinimum : obj;
2469
+ });
2470
+ return currentMinimum;
2471
+ },
2472
+
2473
+ /**
2474
+ * Returns the biggest Dinero object from an array of Dinero objects
2475
+ *
2476
+ * @memberof module:Dinero
2477
+ * @method
2478
+ *
2479
+ * @param {Dinero[]} objects - An array of Dinero objects
2480
+ *
2481
+ * @example
2482
+ * // returns the biggest Dinero object with amount of 20, from an array of Dinero objects with different precisions
2483
+ * Dinero.maximum([
2484
+ * Dinero({ amount: 20, precision: 2 }),
2485
+ * Dinero({ amount: 150, precision: 3 })
2486
+ * ])
2487
+ * @example
2488
+ * // returns the biggest Dinero object with amount of 100, from an array of Dinero objects
2489
+ * Dinero.maximum([
2490
+ * Dinero({ amount: 100 }),
2491
+ * Dinero({ amount: 50 })
2492
+ * ])
2493
+ *
2494
+ * @return {Dinero[]}
2495
+ */
2496
+ maximum: function maximum(objects) {
2497
+ var _objects2 = _toArray(objects),
2498
+ firstObject = _objects2[0],
2499
+ tailObjects = _objects2.slice(1);
2500
+
2501
+ var currentMaximum = firstObject;
2502
+ tailObjects.forEach(function (obj) {
2503
+ currentMaximum = currentMaximum.greaterThan(obj) ? currentMaximum : obj;
2504
+ });
2505
+ return currentMaximum;
2506
+ }
2507
+ };
2508
+
2509
+ /**
2510
+ * Returns whether a value is numeric.
2511
+ * @ignore
2512
+ *
2513
+ * @param {} value - The value to test.
2514
+ *
2515
+ * @return {Boolean}
2516
+ */
2517
+ function isNumeric(value) {
2518
+ return !isNaN(parseInt(value)) && isFinite(value);
2519
+ }
2520
+ /**
2521
+ * Returns whether a value is a percentage.
2522
+ * @ignore
2523
+ *
2524
+ * @param {} percentage - The percentage to test.
2525
+ *
2526
+ * @return {Boolean}
2527
+ */
2528
+
2529
+ function isPercentage(percentage) {
2530
+ return isNumeric(percentage) && percentage <= 100 && percentage >= 0;
2531
+ }
2532
+ /**
2533
+ * Returns whether an array of ratios is valid.
2534
+ * @ignore
2535
+ *
2536
+ * @param {} ratios - The ratios to test.
2537
+ *
2538
+ * @return {Boolean}
2539
+ */
2540
+
2541
+ function areValidRatios(ratios) {
2542
+ return ratios.length > 0 && ratios.every(function (ratio) {
2543
+ return ratio >= 0;
2544
+ }) && ratios.some(function (ratio) {
2545
+ return ratio > 0;
2546
+ });
2547
+ }
2548
+ /**
2549
+ * Returns whether a value is even.
2550
+ * @ignore
2551
+ *
2552
+ * @param {Number} value - The value to test.
2553
+ *
2554
+ * @return {Boolean}
2555
+ */
2556
+
2557
+ function isEven(value) {
2558
+ return value % 2 === 0;
2559
+ }
2560
+ /**
2561
+ * Returns whether a value is a float.
2562
+ * @ignore
2563
+ *
2564
+ * @param {} value - The value to test.
2565
+ *
2566
+ * @return {Boolean}
2567
+ */
2568
+
2569
+ function isFloat(value) {
2570
+ return isNumeric(value) && !Number.isInteger(value);
2571
+ }
2572
+ /**
2573
+ * Returns how many fraction digits a number has.
2574
+ * @ignore
2575
+ *
2576
+ * @param {Number} [number=0] - The number to test.
2577
+ *
2578
+ * @return {Number}
2579
+ */
2580
+
2581
+ function countFractionDigits() {
2582
+ var number = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : 0;
2583
+ var stringRepresentation = number.toString();
2584
+
2585
+ if (stringRepresentation.indexOf('e-') > 0) {
2586
+ // It's too small for a normal string representation, e.g. 1e-7 instead of 0.00000001
2587
+ return parseInt(stringRepresentation.split('e-')[1]);
2588
+ } else {
2589
+ var fractionDigits = stringRepresentation.split('.')[1];
2590
+ return fractionDigits ? fractionDigits.length : 0;
2591
+ }
2592
+ }
2593
+ /**
2594
+ * Returns whether a number is half.
2595
+ * @ignore
2596
+ *
2597
+ * @param {Number} number - The number to test.
2598
+ *
2599
+ * @return {Number}
2600
+ */
2601
+
2602
+ function isHalf(number) {
2603
+ return Math.abs(number) % 1 === 0.5;
2604
+ }
2605
+ /**
2606
+ * Fetches a JSON resource.
2607
+ * @ignore
2608
+ *
2609
+ * @param {String} url - The resource to fetch.
2610
+ * @param {Object} [options.headers] - The headers to pass.
2611
+ *
2612
+ * @throws {Error} If `request.status` is lesser than 200 or greater or equal to 400.
2613
+ * @throws {Error} If network fails.
2614
+ *
2615
+ * @return {JSON}
2616
+ */
2617
+
2618
+ function getJSON(url) {
2619
+ var options = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {};
2620
+ return new Promise(function (resolve, reject) {
2621
+ var request = Object.assign(new XMLHttpRequest(), {
2622
+ onreadystatechange: function onreadystatechange() {
2623
+ if (request.readyState === 4) {
2624
+ if (request.status >= 200 && request.status < 400) resolve(JSON.parse(request.responseText));else reject(new Error(request.statusText));
2625
+ }
2626
+ },
2627
+ onerror: function onerror() {
2628
+ reject(new Error('Network error'));
2629
+ }
2630
+ });
2631
+ request.open('GET', url, true);
2632
+ setXHRHeaders(request, options.headers);
2633
+ request.send();
2634
+ });
2635
+ }
2636
+ /**
2637
+ * Returns an XHR object with attached headers.
2638
+ * @ignore
2639
+ *
2640
+ * @param {XMLHttpRequest} xhr - The XHR request to set headers to.
2641
+ * @param {Object} headers - The headers to set.
2642
+ *
2643
+ * @return {XMLHttpRequest}
2644
+ */
2645
+
2646
+ function setXHRHeaders(xhr) {
2647
+ var headers = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {};
2648
+
2649
+ for (var header in headers) {
2650
+ xhr.setRequestHeader(header, headers[header]);
2651
+ }
2652
+
2653
+ return xhr;
2654
+ }
2655
+ /**
2656
+ * Returns whether a value is undefined.
2657
+ * @ignore
2658
+ *
2659
+ * @param {} value - The value to test.
2660
+ *
2661
+ * @return {Boolean}
2662
+ */
2663
+
2664
+ function isUndefined(value) {
2665
+ return typeof value === 'undefined';
2666
+ }
2667
+ /**
2668
+ * Returns an object flattened to one level deep.
2669
+ * @ignore
2670
+ *
2671
+ * @param {Object} object - The object to flatten.
2672
+ * @param {String} separator - The separator to use between flattened nodes.
2673
+ *
2674
+ * @return {Object}
2675
+ */
2676
+
2677
+ function flattenObject(object) {
2678
+ var separator = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : '.';
2679
+ var finalObject = {};
2680
+ Object.entries(object).forEach(function (item) {
2681
+ if (_typeof(item[1]) === 'object') {
2682
+ var flatObject = flattenObject(item[1]);
2683
+ Object.entries(flatObject).forEach(function (node) {
2684
+ finalObject[item[0] + separator + node[0]] = node[1];
2685
+ });
2686
+ } else {
2687
+ finalObject[item[0]] = item[1];
2688
+ }
2689
+ });
2690
+ return finalObject;
2691
+ }
2692
+ /**
2693
+ * Returns whether a value is thenable.
2694
+ * @ignore
2695
+ *
2696
+ * @param {} value - The value to test.
2697
+ *
2698
+ * @return {Boolean}
2699
+ */
2700
+
2701
+ function isThenable(value) {
2702
+ return Boolean(value) && (_typeof(value) === 'object' || typeof value === 'function') && typeof value.then === 'function';
2703
+ }
2704
+
2705
+ function Calculator() {
2706
+ var floatMultiply = function floatMultiply(a, b) {
2707
+ var getFactor = function getFactor(number) {
2708
+ return Math.pow(10, countFractionDigits(number));
2709
+ };
2710
+
2711
+ var factor = Math.max(getFactor(a), getFactor(b));
2712
+ return Math.round(a * factor) * Math.round(b * factor) / (factor * factor);
2713
+ };
2714
+
2715
+ var roundingModes = {
2716
+ HALF_ODD: function HALF_ODD(number) {
2717
+ var rounded = Math.round(number);
2718
+ return isHalf(number) ? isEven(rounded) ? rounded - 1 : rounded : rounded;
2719
+ },
2720
+ HALF_EVEN: function HALF_EVEN(number) {
2721
+ var rounded = Math.round(number);
2722
+ return isHalf(number) ? isEven(rounded) ? rounded : rounded - 1 : rounded;
2723
+ },
2724
+ HALF_UP: function HALF_UP(number) {
2725
+ return Math.round(number);
2726
+ },
2727
+ HALF_DOWN: function HALF_DOWN(number) {
2728
+ return isHalf(number) ? Math.floor(number) : Math.round(number);
2729
+ },
2730
+ HALF_TOWARDS_ZERO: function HALF_TOWARDS_ZERO(number) {
2731
+ return isHalf(number) ? Math.sign(number) * Math.floor(Math.abs(number)) : Math.round(number);
2732
+ },
2733
+ HALF_AWAY_FROM_ZERO: function HALF_AWAY_FROM_ZERO(number) {
2734
+ return isHalf(number) ? Math.sign(number) * Math.ceil(Math.abs(number)) : Math.round(number);
2735
+ },
2736
+ DOWN: function DOWN(number) {
2737
+ return Math.floor(number);
2738
+ }
2739
+ };
2740
+ return {
2741
+ /**
2742
+ * Returns the sum of two numbers.
2743
+ * @ignore
2744
+ *
2745
+ * @param {Number} a - The first number to add.
2746
+ * @param {Number} b - The second number to add.
2747
+ *
2748
+ * @return {Number}
2749
+ */
2750
+ add: function add(a, b) {
2751
+ return a + b;
2752
+ },
2753
+
2754
+ /**
2755
+ * Returns the difference of two numbers.
2756
+ * @ignore
2757
+ *
2758
+ * @param {Number} a - The first number to subtract.
2759
+ * @param {Number} b - The second number to subtract.
2760
+ *
2761
+ * @return {Number}
2762
+ */
2763
+ subtract: function subtract(a, b) {
2764
+ return a - b;
2765
+ },
2766
+
2767
+ /**
2768
+ * Returns the product of two numbers.
2769
+ * @ignore
2770
+ *
2771
+ * @param {Number} a - The first number to multiply.
2772
+ * @param {Number} b - The second number to multiply.
2773
+ *
2774
+ * @return {Number}
2775
+ */
2776
+ multiply: function multiply(a, b) {
2777
+ return isFloat(a) || isFloat(b) ? floatMultiply(a, b) : a * b;
2778
+ },
2779
+
2780
+ /**
2781
+ * Returns the quotient of two numbers.
2782
+ * @ignore
2783
+ *
2784
+ * @param {Number} a - The first number to divide.
2785
+ * @param {Number} b - The second number to divide.
2786
+ *
2787
+ * @return {Number}
2788
+ */
2789
+ divide: function divide(a, b) {
2790
+ return a / b;
2791
+ },
2792
+
2793
+ /**
2794
+ * Returns the remainder of two numbers.
2795
+ * @ignore
2796
+ *
2797
+ * @param {Number} a - The first number to divide.
2798
+ * @param {Number} b - The second number to divide.
2799
+ *
2800
+ * @return {Number}
2801
+ */
2802
+ modulo: function modulo(a, b) {
2803
+ return a % b;
2804
+ },
2805
+
2806
+ /**
2807
+ * Returns a rounded number based off a specific rounding mode.
2808
+ * @ignore
2809
+ *
2810
+ * @param {Number} number - The number to round.
2811
+ * @param {String} [roundingMode='HALF_EVEN'] - The rounding mode to use.
2812
+ *
2813
+ * @returns {Number}
2814
+ */
2815
+ round: function round(number) {
2816
+ var roundingMode = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : 'HALF_EVEN';
2817
+ return roundingModes[roundingMode](number);
2818
+ }
2819
+ };
2820
+ }
2821
+
2822
+ var calculator = Calculator();
2823
+ function Format(format) {
2824
+ var matches = /^(?:(\$|USD)?0(?:(,)0)?(\.)?(0+)?|0(?:(,)0)?(\.)?(0+)?\s?(dollar)?)$/gm.exec(format);
2825
+ return {
2826
+ /**
2827
+ * Returns the matches.
2828
+ * @ignore
2829
+ *
2830
+ * @return {Array}
2831
+ */
2832
+ getMatches: function getMatches() {
2833
+ return matches !== null ? matches.slice(1).filter(function (match) {
2834
+ return !isUndefined(match);
2835
+ }) : [];
2836
+ },
2837
+
2838
+ /**
2839
+ * Returns the amount of fraction digits to display.
2840
+ * @ignore
2841
+ *
2842
+ * @return {Number}
2843
+ */
2844
+ getMinimumFractionDigits: function getMinimumFractionDigits() {
2845
+ var decimalPosition = function decimalPosition(match) {
2846
+ return match === '.';
2847
+ };
2848
+
2849
+ return !isUndefined(this.getMatches().find(decimalPosition)) ? this.getMatches()[calculator.add(this.getMatches().findIndex(decimalPosition), 1)].split('').length : 0;
2850
+ },
2851
+
2852
+ /**
2853
+ * Returns the currency display mode.
2854
+ * @ignore
2855
+ *
2856
+ * @return {String}
2857
+ */
2858
+ getCurrencyDisplay: function getCurrencyDisplay() {
2859
+ var modes = {
2860
+ USD: 'code',
2861
+ dollar: 'name',
2862
+ $: 'symbol'
2863
+ };
2864
+ return modes[this.getMatches().find(function (match) {
2865
+ return match === 'USD' || match === 'dollar' || match === '$';
2866
+ })];
2867
+ },
2868
+
2869
+ /**
2870
+ * Returns the formatting style.
2871
+ * @ignore
2872
+ *
2873
+ * @return {String}
2874
+ */
2875
+ getStyle: function getStyle() {
2876
+ return !isUndefined(this.getCurrencyDisplay(this.getMatches())) ? 'currency' : 'decimal';
2877
+ },
2878
+
2879
+ /**
2880
+ * Returns whether grouping should be used or not.
2881
+ * @ignore
2882
+ *
2883
+ * @return {Boolean}
2884
+ */
2885
+ getUseGrouping: function getUseGrouping() {
2886
+ return !isUndefined(this.getMatches().find(function (match) {
2887
+ return match === ',';
2888
+ }));
2889
+ }
2890
+ };
2891
+ }
2892
+
2893
+ function CurrencyConverter(options) {
2894
+ /* istanbul ignore next */
2895
+ var mergeTags = function mergeTags() {
2896
+ var string = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : '';
2897
+ var tags = arguments.length > 1 ? arguments[1] : undefined;
2898
+
2899
+ for (var tag in tags) {
2900
+ string = string.replace("{{".concat(tag, "}}"), tags[tag]);
2901
+ }
2902
+
2903
+ return string;
2904
+ };
2905
+ /* istanbul ignore next */
2906
+
2907
+
2908
+ var getRatesFromRestApi = function getRatesFromRestApi(from, to) {
2909
+ return getJSON(mergeTags(options.endpoint, {
2910
+ from: from,
2911
+ to: to
2912
+ }), {
2913
+ headers: options.headers
2914
+ });
2915
+ };
2916
+
2917
+ return {
2918
+ /**
2919
+ * Returns the exchange rate.
2920
+ * @ignore
2921
+ *
2922
+ * @param {String} from - The base currency.
2923
+ * @param {String} to - The destination currency.
2924
+ *
2925
+ * @return {Promise}
2926
+ */
2927
+ getExchangeRate: function getExchangeRate(from, to) {
2928
+ return (isThenable(options.endpoint) ? options.endpoint : getRatesFromRestApi(from, to)).then(function (data) {
2929
+ return flattenObject(data)[mergeTags(options.propertyPath, {
2930
+ from: from,
2931
+ to: to
2932
+ })];
2933
+ });
2934
+ }
2935
+ };
2936
+ }
2937
+
2938
+ /**
2939
+ * Performs an assertion.
2940
+ * @ignore
2941
+ *
2942
+ * @param {Boolean} condition - The expression to assert.
2943
+ * @param {String} errorMessage - The message to throw if the assertion fails
2944
+ * @param {ErrorConstructor} [ErrorType=Error] - The error to throw if the assertion fails.
2945
+ *
2946
+ * @throws {Error} If `condition` returns `false`.
2947
+ */
2948
+
2949
+ function assert(condition, errorMessage) {
2950
+ var ErrorType = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : Error;
2951
+ if (!condition) throw new ErrorType(errorMessage);
2952
+ }
2953
+ /**
2954
+ * Asserts a value is a percentage.
2955
+ * @ignore
2956
+ *
2957
+ * @param {} percentage - The percentage to test.
2958
+ *
2959
+ * @throws {RangeError} If `percentage` is out of range.
2960
+ */
2961
+
2962
+ function assertPercentage(percentage) {
2963
+ assert(isPercentage(percentage), 'You must provide a numeric value between 0 and 100.', RangeError);
2964
+ }
2965
+ /**
2966
+ * Asserts an array of ratios is valid.
2967
+ * @ignore
2968
+ *
2969
+ * @param {} ratios - The ratios to test.
2970
+ *
2971
+ * @throws {TypeError} If `ratios` are invalid.
2972
+ */
2973
+
2974
+ function assertValidRatios(ratios) {
2975
+ assert(areValidRatios(ratios), 'You must provide a non-empty array of numeric values greater than 0.', TypeError);
2976
+ }
2977
+ /**
2978
+ * Asserts a value is an integer.
2979
+ * @ignore
2980
+ *
2981
+ * @param {} number - The value to test.
2982
+ *
2983
+ * @throws {TypeError}
2984
+ */
2985
+
2986
+ function assertInteger(number) {
2987
+ assert(Number.isInteger(number), 'You must provide an integer.', TypeError);
2988
+ }
2989
+
2990
+ var calculator$1 = Calculator();
2991
+ /**
2992
+ * A Dinero object is an immutable data structure representing a specific monetary value.
2993
+ * It comes with methods for creating, parsing, manipulating, testing, transforming and formatting them.
2994
+ *
2995
+ * A Dinero object has:
2996
+ *
2997
+ * * An `amount`, expressed in minor currency units, as an integer.
2998
+ * * A `currency`, expressed as an {@link https://en.wikipedia.org/wiki/ISO_4217#Active_codes ISO 4217 currency code}.
2999
+ * * A `precision`, expressed as an integer, to represent the number of decimal places in the `amount`.
3000
+ * This is helpful when you want to represent fractional minor currency units (e.g.: $10.4545).
3001
+ * You can also use it to represent a currency with a different [exponent](https://en.wikipedia.org/wiki/ISO_4217#Treatment_of_minor_currency_units_.28the_.22exponent.22.29) than `2` (e.g.: Iraqi dinar with 1000 fils in 1 dinar (exponent of `3`), Japanese yen with no sub-units (exponent of `0`)).
3002
+ * * An optional `locale` property that affects how output strings are formatted.
3003
+ *
3004
+ * Here's an overview of the public API:
3005
+ *
3006
+ * * **Access:** {@link module:Dinero~getAmount getAmount}, {@link module:Dinero~getCurrency getCurrency}, {@link module:Dinero~getLocale getLocale} and {@link module:Dinero~getPrecision getPrecision}.
3007
+ * * **Manipulation:** {@link module:Dinero~add add}, {@link module:Dinero~subtract subtract}, {@link module:Dinero~multiply multiply}, {@link module:Dinero~divide divide}, {@link module:Dinero~percentage percentage}, {@link module:Dinero~allocate allocate} and {@link module:Dinero~convert convert}.
3008
+ * * **Testing:** {@link module:Dinero~equalsTo equalsTo}, {@link module:Dinero~lessThan lessThan}, {@link module:Dinero~lessThanOrEqual lessThanOrEqual}, {@link module:Dinero~greaterThan greaterThan}, {@link module:Dinero~greaterThanOrEqual greaterThanOrEqual}, {@link module:Dinero~isZero isZero}, {@link module:Dinero~isPositive isPositive}, {@link module:Dinero~isNegative isNegative}, {@link module:Dinero~hasSubUnits hasSubUnits}, {@link module:Dinero~hasSameCurrency hasSameCurrency} and {@link module:Dinero~hasSameAmount hasSameAmount}.
3009
+ * * **Configuration:** {@link module:Dinero~setLocale setLocale}.
3010
+ * * **Conversion & formatting:** {@link module:Dinero~toFormat toFormat}, {@link module:Dinero~toUnit toUnit}, {@link module:Dinero~toRoundedUnit toRoundedUnit}, {@link module:Dinero~toObject toObject}, {@link module:Dinero~toJSON toJSON}, {@link module:Dinero~convertPrecision convertPrecision} and {@link module:Dinero.normalizePrecision normalizePrecision}.
3011
+ *
3012
+ * Dinero.js uses `number`s under the hood, so it's constrained by the [double-precision floating-point format](https://en.wikipedia.org/wiki/Double-precision_floating-point_format). Using values over [`Number.MAX_SAFE_INTEGER`](https://developer.mozilla.org/fr/docs/Web/JavaScript/Reference/Objets_globaux/Number/MAX_SAFE_INTEGER) or below [`Number.MIN_SAFE_INTEGER`](https://developer.mozilla.org/fr/docs/Web/JavaScript/Reference/Objets_globaux/Number/MIN_SAFE_INTEGER) will yield unpredictable results.
3013
+ * Same goes with performing calculations: once the internal `amount` value exceeds those limits, precision is no longer guaranteed.
3014
+ *
3015
+ * @module Dinero
3016
+ * @param {Number} [options.amount=0] - The amount in minor currency units (as an integer).
3017
+ * @param {String} [options.currency='USD'] - An ISO 4217 currency code.
3018
+ * @param {String} [options.precision=2] - The number of decimal places to represent.
3019
+ *
3020
+ * @throws {TypeError} If `amount` or `precision` is invalid. Integers over [`Number.MAX_SAFE_INTEGER`](https://developer.mozilla.org/fr/docs/Web/JavaScript/Reference/Objets_globaux/Number/MAX_SAFE_INTEGER) or below [`Number.MIN_SAFE_INTEGER`](https://developer.mozilla.org/fr/docs/Web/JavaScript/Reference/Objets_globaux/Number/MIN_SAFE_INTEGER) are considered valid, even though they can lead to imprecise amounts.
3021
+ *
3022
+ * @return {Object}
3023
+ */
3024
+
3025
+ var Dinero = function Dinero(options) {
3026
+ var _Object$assign = Object.assign({}, {
3027
+ amount: Dinero.defaultAmount,
3028
+ currency: Dinero.defaultCurrency,
3029
+ precision: Dinero.defaultPrecision
3030
+ }, options),
3031
+ amount = _Object$assign.amount,
3032
+ currency = _Object$assign.currency,
3033
+ precision = _Object$assign.precision;
3034
+
3035
+ assertInteger(amount);
3036
+ assertInteger(precision);
3037
+ var globalLocale = Dinero.globalLocale,
3038
+ globalFormat = Dinero.globalFormat,
3039
+ globalRoundingMode = Dinero.globalRoundingMode,
3040
+ globalFormatRoundingMode = Dinero.globalFormatRoundingMode;
3041
+ var globalExchangeRatesApi = Object.assign({}, Dinero.globalExchangeRatesApi);
3042
+ /**
3043
+ * Uses ES5 function notation so `this` can be passed through call, apply and bind
3044
+ * @ignore
3045
+ */
3046
+
3047
+ var create = function create(options) {
3048
+ var obj = Object.assign({}, Object.assign({}, {
3049
+ amount: amount,
3050
+ currency: currency,
3051
+ precision: precision
3052
+ }, options), Object.assign({}, {
3053
+ locale: this.locale
3054
+ }, options));
3055
+ return Object.assign(Dinero({
3056
+ amount: obj.amount,
3057
+ currency: obj.currency,
3058
+ precision: obj.precision
3059
+ }), {
3060
+ locale: obj.locale
3061
+ });
3062
+ };
3063
+ /**
3064
+ * Uses ES5 function notation so `this` can be passed through call, apply and bind
3065
+ * @ignore
3066
+ */
3067
+
3068
+
3069
+ var assertSameCurrency = function assertSameCurrency(comparator) {
3070
+ assert(this.hasSameCurrency(comparator), 'You must provide a Dinero instance with the same currency.', TypeError);
3071
+ };
3072
+
3073
+ return {
3074
+ /**
3075
+ * Returns the amount.
3076
+ *
3077
+ * @example
3078
+ * // returns 500
3079
+ * Dinero({ amount: 500 }).getAmount()
3080
+ *
3081
+ * @return {Number}
3082
+ */
3083
+ getAmount: function getAmount() {
3084
+ return amount;
3085
+ },
3086
+
3087
+ /**
3088
+ * Returns the currency.
3089
+ *
3090
+ * @example
3091
+ * // returns 'EUR'
3092
+ * Dinero({ currency: 'EUR' }).getCurrency()
3093
+ *
3094
+ * @return {String}
3095
+ */
3096
+ getCurrency: function getCurrency() {
3097
+ return currency;
3098
+ },
3099
+
3100
+ /**
3101
+ * Returns the locale.
3102
+ *
3103
+ * @example
3104
+ * // returns 'fr-FR'
3105
+ * Dinero().setLocale('fr-FR').getLocale()
3106
+ *
3107
+ * @return {String}
3108
+ */
3109
+ getLocale: function getLocale() {
3110
+ return this.locale || globalLocale;
3111
+ },
3112
+
3113
+ /**
3114
+ * Returns a new Dinero object with an embedded locale.
3115
+ *
3116
+ * @param {String} newLocale - The new locale as an {@link http://tools.ietf.org/html/rfc5646 BCP 47 language tag}.
3117
+ *
3118
+ * @example
3119
+ * // Returns a Dinero object with locale 'ja-JP'
3120
+ * Dinero().setLocale('ja-JP')
3121
+ *
3122
+ * @return {Dinero}
3123
+ */
3124
+ setLocale: function setLocale(newLocale) {
3125
+ return create.call(this, {
3126
+ locale: newLocale
3127
+ });
3128
+ },
3129
+
3130
+ /**
3131
+ * Returns the precision.
3132
+ *
3133
+ * @example
3134
+ * // returns 3
3135
+ * Dinero({ precision: 3 }).getPrecision()
3136
+ *
3137
+ * @return {Number}
3138
+ */
3139
+ getPrecision: function getPrecision() {
3140
+ return precision;
3141
+ },
3142
+
3143
+ /**
3144
+ * Returns a new Dinero object with a new precision and a converted amount.
3145
+ *
3146
+ * By default, fractional minor currency units are rounded using the **half to even** rule ([banker's rounding](http://wiki.c2.com/?BankersRounding)).
3147
+ * This can be necessary when you need to convert objects to a smaller precision.
3148
+ *
3149
+ * Rounding *can* lead to accuracy issues as you chain many times. Consider a minimal amount of subsequent conversions for safer results.
3150
+ * You can also specify a different `roundingMode` to better fit your needs.
3151
+ *
3152
+ * @param {Number} newPrecision - The new precision.
3153
+ * @param {String} [roundingMode='HALF_EVEN'] - The rounding mode to use: `'HALF_ODD'`, `'HALF_EVEN'`, `'HALF_UP'`, `'HALF_DOWN'`, `'HALF_TOWARDS_ZERO'`, `'HALF_AWAY_FROM_ZERO'` or `'DOWN'`.
3154
+ *
3155
+ * @example
3156
+ * // Returns a Dinero object with precision 3 and amount 1000
3157
+ * Dinero({ amount: 100, precision: 2 }).convertPrecision(3)
3158
+ *
3159
+ * @throws {TypeError} If `newPrecision` is invalid.
3160
+ *
3161
+ * @return {Dinero}
3162
+ */
3163
+ convertPrecision: function convertPrecision(newPrecision) {
3164
+ var roundingMode = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : globalFormatRoundingMode;
3165
+ assertInteger(newPrecision);
3166
+ var precision = this.getPrecision();
3167
+ var isNewPrecisionLarger = newPrecision > precision;
3168
+ var operation = isNewPrecisionLarger ? calculator$1.multiply : calculator$1.divide;
3169
+ var terms = isNewPrecisionLarger ? [newPrecision, precision] : [precision, newPrecision];
3170
+ var factor = Math.pow(10, calculator$1.subtract.apply(calculator$1, terms));
3171
+ return create.call(this, {
3172
+ amount: calculator$1.round(operation(this.getAmount(), factor), roundingMode),
3173
+ precision: newPrecision
3174
+ });
3175
+ },
3176
+
3177
+ /**
3178
+ * Returns a new Dinero object that represents the sum of this and an other Dinero object.
3179
+ *
3180
+ * If Dinero objects have a different `precision`, they will be first converted to the highest.
3181
+ *
3182
+ * @param {Dinero} addend - The Dinero object to add.
3183
+ *
3184
+ * @example
3185
+ * // returns a Dinero object with amount 600
3186
+ * Dinero({ amount: 400 }).add(Dinero({ amount: 200 }))
3187
+ * @example
3188
+ * // returns a Dinero object with amount 144545 and precision 4
3189
+ * Dinero({ amount: 400 }).add(Dinero({ amount: 104545, precision: 4 }))
3190
+ *
3191
+ * @throws {TypeError} If `addend` has a different currency.
3192
+ *
3193
+ * @return {Dinero}
3194
+ */
3195
+ add: function add(addend) {
3196
+ assertSameCurrency.call(this, addend);
3197
+ var addends = Dinero.normalizePrecision([this, addend]);
3198
+ return create.call(this, {
3199
+ amount: calculator$1.add(addends[0].getAmount(), addends[1].getAmount()),
3200
+ precision: addends[0].getPrecision()
3201
+ });
3202
+ },
3203
+
3204
+ /**
3205
+ * Returns a new Dinero object that represents the difference of this and an other Dinero object.
3206
+ *
3207
+ * If Dinero objects have a different `precision`, they will be first converted to the highest.
3208
+ *
3209
+ * @param {Dinero} subtrahend - The Dinero object to subtract.
3210
+ *
3211
+ * @example
3212
+ * // returns a Dinero object with amount 200
3213
+ * Dinero({ amount: 400 }).subtract(Dinero({ amount: 200 }))
3214
+ * @example
3215
+ * // returns a Dinero object with amount 64545 and precision 4
3216
+ * Dinero({ amount: 104545, precision: 4 }).subtract(Dinero({ amount: 400 }))
3217
+ *
3218
+ * @throws {TypeError} If `subtrahend` has a different currency.
3219
+ *
3220
+ * @return {Dinero}
3221
+ */
3222
+ subtract: function subtract(subtrahend) {
3223
+ assertSameCurrency.call(this, subtrahend);
3224
+ var subtrahends = Dinero.normalizePrecision([this, subtrahend]);
3225
+ return create.call(this, {
3226
+ amount: calculator$1.subtract(subtrahends[0].getAmount(), subtrahends[1].getAmount()),
3227
+ precision: subtrahends[0].getPrecision()
3228
+ });
3229
+ },
3230
+
3231
+ /**
3232
+ * Returns a new Dinero object that represents the multiplied value by the given factor.
3233
+ *
3234
+ * By default, fractional minor currency units are rounded using the **half to even** rule ([banker's rounding](http://wiki.c2.com/?BankersRounding)).
3235
+ *
3236
+ * Rounding *can* lead to accuracy issues as you chain many times. Consider a minimal amount of subsequent calculations for safer results.
3237
+ * You can also specify a different `roundingMode` to better fit your needs.
3238
+ *
3239
+ * @param {Number} multiplier - The factor to multiply by.
3240
+ * @param {String} [roundingMode='HALF_EVEN'] - The rounding mode to use: `'HALF_ODD'`, `'HALF_EVEN'`, `'HALF_UP'`, `'HALF_DOWN'`, `'HALF_TOWARDS_ZERO'`, `'HALF_AWAY_FROM_ZERO'` or `'DOWN'`.
3241
+ *
3242
+ * @example
3243
+ * // returns a Dinero object with amount 1600
3244
+ * Dinero({ amount: 400 }).multiply(4)
3245
+ * @example
3246
+ * // returns a Dinero object with amount 800
3247
+ * Dinero({ amount: 400 }).multiply(2.001)
3248
+ * @example
3249
+ * // returns a Dinero object with amount 801
3250
+ * Dinero({ amount: 400 }).multiply(2.00125, 'HALF_UP')
3251
+ *
3252
+ * @return {Dinero}
3253
+ */
3254
+ multiply: function multiply(multiplier) {
3255
+ var roundingMode = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : globalRoundingMode;
3256
+ return create.call(this, {
3257
+ amount: calculator$1.round(calculator$1.multiply(this.getAmount(), multiplier), roundingMode)
3258
+ });
3259
+ },
3260
+
3261
+ /**
3262
+ * Returns a new Dinero object that represents the divided value by the given factor.
3263
+ *
3264
+ * By default, fractional minor currency units are rounded using the **half to even** rule ([banker's rounding](http://wiki.c2.com/?BankersRounding)).
3265
+ *
3266
+ * Rounding *can* lead to accuracy issues as you chain many times. Consider a minimal amount of subsequent calculations for safer results.
3267
+ * You can also specify a different `roundingMode` to better fit your needs.
3268
+ *
3269
+ * As rounding is applied, precision may be lost in the process. If you want to accurately split a Dinero object, use {@link module:Dinero~allocate allocate} instead.
3270
+ *
3271
+ * @param {Number} divisor - The factor to divide by.
3272
+ * @param {String} [roundingMode='HALF_EVEN'] - The rounding mode to use: `'HALF_ODD'`, `'HALF_EVEN'`, `'HALF_UP'`, `'HALF_DOWN'`, `'HALF_TOWARDS_ZERO'`, `'HALF_AWAY_FROM_ZERO'` or `'DOWN'`.
3273
+ *
3274
+ * @example
3275
+ * // returns a Dinero object with amount 100
3276
+ * Dinero({ amount: 400 }).divide(4)
3277
+ * @example
3278
+ * // returns a Dinero object with amount 52
3279
+ * Dinero({ amount: 105 }).divide(2)
3280
+ * @example
3281
+ * // returns a Dinero object with amount 53
3282
+ * Dinero({ amount: 105 }).divide(2, 'HALF_UP')
3283
+ *
3284
+ * @return {Dinero}
3285
+ */
3286
+ divide: function divide(divisor) {
3287
+ var roundingMode = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : globalRoundingMode;
3288
+ return create.call(this, {
3289
+ amount: calculator$1.round(calculator$1.divide(this.getAmount(), divisor), roundingMode)
3290
+ });
3291
+ },
3292
+
3293
+ /**
3294
+ * Returns a new Dinero object that represents a percentage of this.
3295
+ *
3296
+ * As rounding is applied, precision may be lost in the process. If you want to accurately split a Dinero object, use {@link module:Dinero~allocate allocate} instead.
3297
+ *
3298
+ * @param {Number} percentage - The percentage to extract (between 0 and 100).
3299
+ * @param {String} [roundingMode='HALF_EVEN'] - The rounding mode to use: `'HALF_ODD'`, `'HALF_EVEN'`, `'HALF_UP'`, `'HALF_DOWN'`, `'HALF_TOWARDS_ZERO'`, `'HALF_AWAY_FROM_ZERO'` or `'DOWN'`.
3300
+ *
3301
+ * @example
3302
+ * // returns a Dinero object with amount 5000
3303
+ * Dinero({ amount: 10000 }).percentage(50)
3304
+ * @example
3305
+ * // returns a Dinero object with amount 29
3306
+ * Dinero({ amount: 57 }).percentage(50, "HALF_ODD")
3307
+ *
3308
+ * @throws {RangeError} If `percentage` is out of range.
3309
+ *
3310
+ * @return {Dinero}
3311
+ */
3312
+ percentage: function percentage(_percentage) {
3313
+ var roundingMode = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : globalRoundingMode;
3314
+ assertPercentage(_percentage);
3315
+ return this.multiply(calculator$1.divide(_percentage, 100), roundingMode);
3316
+ },
3317
+
3318
+ /**
3319
+ * Allocates the amount of a Dinero object according to a list of ratios.
3320
+ *
3321
+ * Sometimes you need to split monetary values but percentages can't cut it without adding or losing pennies.
3322
+ * A good example is invoicing: let's say you need to bill $1,000.03 and you want a 50% downpayment.
3323
+ * If you use {@link module:Dinero~percentage percentage}, you'll get an accurate Dinero object but the amount won't be billable: you can't split a penny.
3324
+ * If you round it, you'll bill a penny extra.
3325
+ * With {@link module:Dinero~allocate allocate}, you can split a monetary amount then distribute the remainder as evenly as possible.
3326
+ *
3327
+ * You can use percentage style or ratio style for `ratios`: `[25, 75]` and `[1, 3]` will do the same thing.
3328
+ *
3329
+ * Since v1.8.0, you can use zero ratios (such as [0, 50, 50]). If there's a remainder to distribute, zero ratios are skipped and return a Dinero object with amount zero.
3330
+ *
3331
+ * @param {Number[]} ratios - The ratios to allocate the money to.
3332
+ *
3333
+ * @example
3334
+ * // returns an array of two Dinero objects
3335
+ * // the first one with an amount of 502
3336
+ * // the second one with an amount of 501
3337
+ * Dinero({ amount: 1003 }).allocate([50, 50])
3338
+ * @example
3339
+ * // returns an array of two Dinero objects
3340
+ * // the first one with an amount of 25
3341
+ * // the second one with an amount of 75
3342
+ * Dinero({ amount: 100 }).allocate([1, 3])
3343
+ * @example
3344
+ * // since version 1.8.0
3345
+ * // returns an array of three Dinero objects
3346
+ * // the first one with an amount of 0
3347
+ * // the second one with an amount of 502
3348
+ * // the third one with an amount of 501
3349
+ * Dinero({ amount: 1003 }).allocate([0, 50, 50])
3350
+ *
3351
+ * @throws {TypeError} If ratios are invalid.
3352
+ *
3353
+ * @return {Dinero[]}
3354
+ */
3355
+ allocate: function allocate(ratios) {
3356
+ var _this = this;
3357
+
3358
+ assertValidRatios(ratios);
3359
+ var total = ratios.reduce(function (a, b) {
3360
+ return calculator$1.add(a, b);
3361
+ });
3362
+ var remainder = this.getAmount();
3363
+ var shares = ratios.map(function (ratio) {
3364
+ var share = Math.floor(calculator$1.divide(calculator$1.multiply(_this.getAmount(), ratio), total));
3365
+ remainder = calculator$1.subtract(remainder, share);
3366
+ return create.call(_this, {
3367
+ amount: share
3368
+ });
3369
+ });
3370
+ var i = 0;
3371
+
3372
+ while (remainder > 0) {
3373
+ if (ratios[i] > 0) {
3374
+ shares[i] = shares[i].add(create.call(this, {
3375
+ amount: 1
3376
+ }));
3377
+ remainder = calculator$1.subtract(remainder, 1);
3378
+ }
3379
+
3380
+ i += 1;
3381
+ }
3382
+
3383
+ return shares;
3384
+ },
3385
+
3386
+ /**
3387
+ * Returns a Promise containing a new Dinero object converted to another currency.
3388
+ *
3389
+ * You have two options to provide the exchange rates:
3390
+ *
3391
+ * 1. **Use an exchange rate REST API, and let Dinero handle the fetching and conversion.**
3392
+ * This is a simple option if you have access to an exchange rate REST API and want Dinero to do the rest.
3393
+ * 2. **Fetch the exchange rates on your own and provide them directly.**
3394
+ * This is useful if you're fetching your rates from somewhere else (a file, a database), use a different protocol or query language than REST (SOAP, GraphQL) or want to fetch rates once and cache them instead of making new requests every time.
3395
+ *
3396
+ * **If you want to use a REST API**, you must provide a third-party endpoint yourself. Dinero doesn't come bundled with an exchange rates endpoint.
3397
+ *
3398
+ * Here are some exchange rate APIs you can use:
3399
+ *
3400
+ * * [Fixer](https://fixer.io)
3401
+ * * [Open Exchange Rates](https://openexchangerates.org)
3402
+ * * [Coinbase](https://api.coinbase.com/v2/exchange-rates)
3403
+ * * More [foreign](https://github.com/toddmotto/public-apis#currency-exchange) and [crypto](https://github.com/toddmotto/public-apis#cryptocurrency) exchange rate APIs.
3404
+ *
3405
+ * **If you want to fetch your own rates and provide them directly**, you need to pass a promise that resolves to the exchanges rates.
3406
+ *
3407
+ * In both cases, you need to specify at least:
3408
+ *
3409
+ * * a **destination currency**: the currency in which you want to convert your Dinero object. You can specify it with `currency`.
3410
+ * * an **endpoint**: the API URL to query exchange rates, with parameters, or a promise that resolves to the exchange rates. You can specify it with `options.endpoint`.
3411
+ * * a **property path**: the path to access the wanted rate in your API's JSON response (or the custom promise's payload). For example, with a response of:
3412
+ * ```json
3413
+ * {
3414
+ * "data": {
3415
+ * "base": "USD",
3416
+ * "destination": "EUR",
3417
+ * "rate": "0.827728919"
3418
+ * }
3419
+ * }
3420
+ * ```
3421
+ * Then the property path is `'data.rate'`. You can specify it with `options.propertyPath`.
3422
+ *
3423
+ * The base currency (the one of your Dinero object) and the destination currency can be used as "merge tags" with the mustache syntax, respectively `{{from}}` and `{{to}}`.
3424
+ * You can use these tags to refer to these values in `options.endpoint` and `options.propertyPath`.
3425
+ *
3426
+ * For example, if you need to specify the base currency as a query parameter, you can do the following:
3427
+ *
3428
+ * ```js
3429
+ * {
3430
+ * endpoint: 'https://yourexchangerates.api/latest?base={{from}}'
3431
+ * }
3432
+ * ```
3433
+ *
3434
+ * @param {String} currency - The destination currency, expressed as an {@link https://en.wikipedia.org/wiki/ISO_4217#Active_codes ISO 4217 currency code}.
3435
+ * @param {(String|Promise)} options.endpoint - The API endpoint to retrieve exchange rates. You can substitute this with a promise that resolves to the exchanges rates if you already have them.
3436
+ * @param {String} [options.propertyPath='rates.{{to}}'] - The property path to the rate.
3437
+ * @param {Object} [options.headers] - The HTTP headers to provide, if needed.
3438
+ * @param {String} [options.roundingMode='HALF_EVEN'] - The rounding mode to use: `'HALF_ODD'`, `'HALF_EVEN'`, `'HALF_UP'`, `'HALF_DOWN'`, `'HALF_TOWARDS_ZERO'`, `'HALF_AWAY_FROM_ZERO'` or `'DOWN'`.
3439
+ *
3440
+ * @example
3441
+ * // your global API parameters
3442
+ * Dinero.globalExchangeRatesApi = { ... }
3443
+ *
3444
+ * // returns a Promise containing a Dinero object with the destination currency
3445
+ * // and the initial amount converted to the new currency.
3446
+ * Dinero({ amount: 500 }).convert('EUR')
3447
+ * @example
3448
+ * // returns a Promise containing a Dinero object,
3449
+ * // with specific API parameters and rounding mode for this specific instance.
3450
+ * Dinero({ amount: 500 })
3451
+ * .convert('XBT', {
3452
+ * endpoint: 'https://yourexchangerates.api/latest?base={{from}}',
3453
+ * propertyPath: 'data.rates.{{to}}',
3454
+ * headers: {
3455
+ * 'user-key': 'xxxxxxxxx'
3456
+ * },
3457
+ * roundingMode: 'HALF_UP'
3458
+ * })
3459
+ * @example
3460
+ * // usage with exchange rates provided as a custom promise
3461
+ * // using the default `propertyPath` format (so it doesn't have to be specified)
3462
+ * const rates = {
3463
+ * rates: {
3464
+ * EUR: 0.81162
3465
+ * }
3466
+ * }
3467
+ *
3468
+ * Dinero({ amount: 500 })
3469
+ * .convert('EUR', {
3470
+ * endpoint: new Promise(resolve => resolve(rates))
3471
+ * })
3472
+ * @example
3473
+ * // usage with Promise.prototype.then and Promise.prototype.catch
3474
+ * Dinero({ amount: 500 })
3475
+ * .convert('EUR')
3476
+ * .then(dinero => {
3477
+ * dinero.getCurrency() // returns 'EUR'
3478
+ * })
3479
+ * .catch(err => {
3480
+ * // handle errors
3481
+ * })
3482
+ * @example
3483
+ * // usage with async/await
3484
+ * (async () => {
3485
+ * const price = await Dinero({ amount: 500 }).convert('EUR')
3486
+ * price.getCurrency() // returns 'EUR'
3487
+ * })()
3488
+ *
3489
+ * @return {Promise}
3490
+ */
3491
+ convert: function convert(currency) {
3492
+ var _this2 = this;
3493
+
3494
+ var _ref = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {},
3495
+ _ref$endpoint = _ref.endpoint,
3496
+ endpoint = _ref$endpoint === void 0 ? globalExchangeRatesApi.endpoint : _ref$endpoint,
3497
+ _ref$propertyPath = _ref.propertyPath,
3498
+ propertyPath = _ref$propertyPath === void 0 ? globalExchangeRatesApi.propertyPath || 'rates.{{to}}' : _ref$propertyPath,
3499
+ _ref$headers = _ref.headers,
3500
+ headers = _ref$headers === void 0 ? globalExchangeRatesApi.headers : _ref$headers,
3501
+ _ref$roundingMode = _ref.roundingMode,
3502
+ roundingMode = _ref$roundingMode === void 0 ? globalRoundingMode : _ref$roundingMode;
3503
+
3504
+ var options = Object.assign({}, {
3505
+ endpoint: endpoint,
3506
+ propertyPath: propertyPath,
3507
+ headers: headers,
3508
+ roundingMode: roundingMode
3509
+ });
3510
+ return CurrencyConverter(options).getExchangeRate(this.getCurrency(), currency).then(function (rate) {
3511
+ assert(!isUndefined(rate), "No rate was found for the destination currency \"".concat(currency, "\"."), TypeError);
3512
+ return create.call(_this2, {
3513
+ amount: calculator$1.round(calculator$1.multiply(_this2.getAmount(), parseFloat(rate)), options.roundingMode),
3514
+ currency: currency
3515
+ });
3516
+ });
3517
+ },
3518
+
3519
+ /**
3520
+ * Checks whether the value represented by this object equals to the other.
3521
+ *
3522
+ * @param {Dinero} comparator - The Dinero object to compare to.
3523
+ *
3524
+ * @example
3525
+ * // returns true
3526
+ * Dinero({ amount: 500, currency: 'EUR' }).equalsTo(Dinero({ amount: 500, currency: 'EUR' }))
3527
+ * @example
3528
+ * // returns false
3529
+ * Dinero({ amount: 500, currency: 'EUR' }).equalsTo(Dinero({ amount: 800, currency: 'EUR' }))
3530
+ * @example
3531
+ * // returns false
3532
+ * Dinero({ amount: 500, currency: 'USD' }).equalsTo(Dinero({ amount: 500, currency: 'EUR' }))
3533
+ * @example
3534
+ * // returns false
3535
+ * Dinero({ amount: 500, currency: 'USD' }).equalsTo(Dinero({ amount: 800, currency: 'EUR' }))
3536
+ * @example
3537
+ * // returns true
3538
+ * Dinero({ amount: 1000, currency: 'EUR', precision: 2 }).equalsTo(Dinero({ amount: 10000, currency: 'EUR', precision: 3 }))
3539
+ * @example
3540
+ * // returns false
3541
+ * Dinero({ amount: 10000, currency: 'EUR', precision: 2 }).equalsTo(Dinero({ amount: 10000, currency: 'EUR', precision: 3 }))
3542
+ *
3543
+ * @return {Boolean}
3544
+ */
3545
+ equalsTo: function equalsTo(comparator) {
3546
+ return this.hasSameAmount(comparator) && this.hasSameCurrency(comparator);
3547
+ },
3548
+
3549
+ /**
3550
+ * Checks whether the value represented by this object is less than the other.
3551
+ *
3552
+ * @param {Dinero} comparator - The Dinero object to compare to.
3553
+ *
3554
+ * @example
3555
+ * // returns true
3556
+ * Dinero({ amount: 500 }).lessThan(Dinero({ amount: 800 }))
3557
+ * @example
3558
+ * // returns false
3559
+ * Dinero({ amount: 800 }).lessThan(Dinero({ amount: 500 }))
3560
+ * @example
3561
+ * // returns true
3562
+ * Dinero({ amount: 5000, precision: 3 }).lessThan(Dinero({ amount: 800 }))
3563
+ * @example
3564
+ * // returns false
3565
+ * Dinero({ amount: 800 }).lessThan(Dinero({ amount: 5000, precision: 3 }))
3566
+ *
3567
+ * @throws {TypeError} If `comparator` has a different currency.
3568
+ *
3569
+ * @return {Boolean}
3570
+ */
3571
+ lessThan: function lessThan(comparator) {
3572
+ assertSameCurrency.call(this, comparator);
3573
+ var comparators = Dinero.normalizePrecision([this, comparator]);
3574
+ return comparators[0].getAmount() < comparators[1].getAmount();
3575
+ },
3576
+
3577
+ /**
3578
+ * Checks whether the value represented by this object is less than or equal to the other.
3579
+ *
3580
+ * @param {Dinero} comparator - The Dinero object to compare to.
3581
+ *
3582
+ * @example
3583
+ * // returns true
3584
+ * Dinero({ amount: 500 }).lessThanOrEqual(Dinero({ amount: 800 }))
3585
+ * @example
3586
+ * // returns true
3587
+ * Dinero({ amount: 500 }).lessThanOrEqual(Dinero({ amount: 500 }))
3588
+ * @example
3589
+ * // returns false
3590
+ * Dinero({ amount: 500 }).lessThanOrEqual(Dinero({ amount: 300 }))
3591
+ * @example
3592
+ * // returns true
3593
+ * Dinero({ amount: 5000, precision: 3 }).lessThanOrEqual(Dinero({ amount: 800 }))
3594
+ * @example
3595
+ * // returns true
3596
+ * Dinero({ amount: 5000, precision: 3 }).lessThanOrEqual(Dinero({ amount: 500 }))
3597
+ * @example
3598
+ * // returns false
3599
+ * Dinero({ amount: 800 }).lessThanOrEqual(Dinero({ amount: 5000, precision: 3 }))
3600
+ *
3601
+ * @throws {TypeError} If `comparator` has a different currency.
3602
+ *
3603
+ * @return {Boolean}
3604
+ */
3605
+ lessThanOrEqual: function lessThanOrEqual(comparator) {
3606
+ assertSameCurrency.call(this, comparator);
3607
+ var comparators = Dinero.normalizePrecision([this, comparator]);
3608
+ return comparators[0].getAmount() <= comparators[1].getAmount();
3609
+ },
3610
+
3611
+ /**
3612
+ * Checks whether the value represented by this object is greater than the other.
3613
+ *
3614
+ * @param {Dinero} comparator - The Dinero object to compare to.
3615
+ *
3616
+ * @example
3617
+ * // returns false
3618
+ * Dinero({ amount: 500 }).greaterThan(Dinero({ amount: 800 }))
3619
+ * @example
3620
+ * // returns true
3621
+ * Dinero({ amount: 800 }).greaterThan(Dinero({ amount: 500 }))
3622
+ * @example
3623
+ * // returns true
3624
+ * Dinero({ amount: 800 }).greaterThan(Dinero({ amount: 5000, precision: 3 }))
3625
+ * @example
3626
+ * // returns false
3627
+ * Dinero({ amount: 5000, precision: 3 }).greaterThan(Dinero({ amount: 800 }))
3628
+ *
3629
+ * @throws {TypeError} If `comparator` has a different currency.
3630
+ *
3631
+ * @return {Boolean}
3632
+ */
3633
+ greaterThan: function greaterThan(comparator) {
3634
+ assertSameCurrency.call(this, comparator);
3635
+ var comparators = Dinero.normalizePrecision([this, comparator]);
3636
+ return comparators[0].getAmount() > comparators[1].getAmount();
3637
+ },
3638
+
3639
+ /**
3640
+ * Checks whether the value represented by this object is greater than or equal to the other.
3641
+ *
3642
+ * @param {Dinero} comparator - The Dinero object to compare to.
3643
+ *
3644
+ * @example
3645
+ * // returns true
3646
+ * Dinero({ amount: 500 }).greaterThanOrEqual(Dinero({ amount: 300 }))
3647
+ * @example
3648
+ * // returns true
3649
+ * Dinero({ amount: 500 }).greaterThanOrEqual(Dinero({ amount: 500 }))
3650
+ * @example
3651
+ * // returns false
3652
+ * Dinero({ amount: 500 }).greaterThanOrEqual(Dinero({ amount: 800 }))
3653
+ * @example
3654
+ * // returns true
3655
+ * Dinero({ amount: 800 }).greaterThanOrEqual(Dinero({ amount: 5000, precision: 3 }))
3656
+ * @example
3657
+ * // returns true
3658
+ * Dinero({ amount: 500 }).greaterThanOrEqual(Dinero({ amount: 5000, precision: 3 }))
3659
+ * @example
3660
+ * // returns false
3661
+ * Dinero({ amount: 5000, precision: 3 }).greaterThanOrEqual(Dinero({ amount: 800 }))
3662
+ *
3663
+ * @throws {TypeError} If `comparator` has a different currency.
3664
+ *
3665
+ * @return {Boolean}
3666
+ */
3667
+ greaterThanOrEqual: function greaterThanOrEqual(comparator) {
3668
+ assertSameCurrency.call(this, comparator);
3669
+ var comparators = Dinero.normalizePrecision([this, comparator]);
3670
+ return comparators[0].getAmount() >= comparators[1].getAmount();
3671
+ },
3672
+
3673
+ /**
3674
+ * Checks if the value represented by this object is zero.
3675
+ *
3676
+ * @example
3677
+ * // returns true
3678
+ * Dinero({ amount: 0 }).isZero()
3679
+ * @example
3680
+ * // returns false
3681
+ * Dinero({ amount: 100 }).isZero()
3682
+ *
3683
+ * @return {Boolean}
3684
+ */
3685
+ isZero: function isZero() {
3686
+ return this.getAmount() === 0;
3687
+ },
3688
+
3689
+ /**
3690
+ * Checks if the value represented by this object is positive.
3691
+ *
3692
+ * @example
3693
+ * // returns false
3694
+ * Dinero({ amount: -10 }).isPositive()
3695
+ * @example
3696
+ * // returns true
3697
+ * Dinero({ amount: 10 }).isPositive()
3698
+ * @example
3699
+ * // returns true
3700
+ * Dinero({ amount: 0 }).isPositive()
3701
+ *
3702
+ * @return {Boolean}
3703
+ */
3704
+ isPositive: function isPositive() {
3705
+ return this.getAmount() >= 0;
3706
+ },
3707
+
3708
+ /**
3709
+ * Checks if the value represented by this object is negative.
3710
+ *
3711
+ * @example
3712
+ * // returns true
3713
+ * Dinero({ amount: -10 }).isNegative()
3714
+ * @example
3715
+ * // returns false
3716
+ * Dinero({ amount: 10 }).isNegative()
3717
+ * @example
3718
+ * // returns false
3719
+ * Dinero({ amount: 0 }).isNegative()
3720
+ *
3721
+ * @return {Boolean}
3722
+ */
3723
+ isNegative: function isNegative() {
3724
+ return this.getAmount() < 0;
3725
+ },
3726
+
3727
+ /**
3728
+ * Checks if this has minor currency units.
3729
+ * Deprecates {@link module:Dinero~hasCents hasCents}.
3730
+ *
3731
+ * @example
3732
+ * // returns false
3733
+ * Dinero({ amount: 1100 }).hasSubUnits()
3734
+ * @example
3735
+ * // returns true
3736
+ * Dinero({ amount: 1150 }).hasSubUnits()
3737
+ *
3738
+ * @return {Boolean}
3739
+ */
3740
+ hasSubUnits: function hasSubUnits() {
3741
+ return calculator$1.modulo(this.getAmount(), Math.pow(10, precision)) !== 0;
3742
+ },
3743
+
3744
+ /**
3745
+ * Checks if this has minor currency units.
3746
+ *
3747
+ * @deprecated since version 1.4.0, will be removed in 2.0.0
3748
+ * Use {@link module:Dinero~hasSubUnits hasSubUnits} instead.
3749
+ *
3750
+ * @example
3751
+ * // returns false
3752
+ * Dinero({ amount: 1100 }).hasCents()
3753
+ * @example
3754
+ * // returns true
3755
+ * Dinero({ amount: 1150 }).hasCents()
3756
+ *
3757
+ * @return {Boolean}
3758
+ */
3759
+ hasCents: function hasCents() {
3760
+ return calculator$1.modulo(this.getAmount(), Math.pow(10, precision)) !== 0;
3761
+ },
3762
+
3763
+ /**
3764
+ * Checks whether the currency represented by this object equals to the other.
3765
+ *
3766
+ * @param {Dinero} comparator - The Dinero object to compare to.
3767
+ *
3768
+ * @example
3769
+ * // returns true
3770
+ * Dinero({ amount: 2000, currency: 'EUR' }).hasSameCurrency(Dinero({ amount: 1000, currency: 'EUR' }))
3771
+ * @example
3772
+ * // returns false
3773
+ * Dinero({ amount: 1000, currency: 'EUR' }).hasSameCurrency(Dinero({ amount: 1000, currency: 'USD' }))
3774
+ *
3775
+ * @return {Boolean}
3776
+ */
3777
+ hasSameCurrency: function hasSameCurrency(comparator) {
3778
+ return this.getCurrency() === comparator.getCurrency();
3779
+ },
3780
+
3781
+ /**
3782
+ * Checks whether the amount represented by this object equals to the other.
3783
+ *
3784
+ * @param {Dinero} comparator - The Dinero object to compare to.
3785
+ *
3786
+ * @example
3787
+ * // returns true
3788
+ * Dinero({ amount: 1000, currency: 'EUR' }).hasSameAmount(Dinero({ amount: 1000 }))
3789
+ * @example
3790
+ * // returns false
3791
+ * Dinero({ amount: 2000, currency: 'EUR' }).hasSameAmount(Dinero({ amount: 1000, currency: 'EUR' }))
3792
+ * @example
3793
+ * // returns true
3794
+ * Dinero({ amount: 1000, currency: 'EUR', precision: 2 }).hasSameAmount(Dinero({ amount: 10000, precision: 3 }))
3795
+ * @example
3796
+ * // returns false
3797
+ * Dinero({ amount: 10000, currency: 'EUR', precision: 2 }).hasSameAmount(Dinero({ amount: 10000, precision: 3 }))
3798
+ *
3799
+ * @return {Boolean}
3800
+ */
3801
+ hasSameAmount: function hasSameAmount(comparator) {
3802
+ var comparators = Dinero.normalizePrecision([this, comparator]);
3803
+ return comparators[0].getAmount() === comparators[1].getAmount();
3804
+ },
3805
+
3806
+ /**
3807
+ * Returns this object formatted as a string.
3808
+ *
3809
+ * The format is a mask which defines how the output string will be formatted.
3810
+ * It defines whether to display a currency, in what format, how many fraction digits to display and whether to use grouping separators.
3811
+ * The output is formatted according to the applying locale.
3812
+ *
3813
+ * Object | Format | String
3814
+ * :--------------------------- | :---------------- | :---
3815
+ * `Dinero({ amount: 500050 })` | `'$0,0.00'` | $5,000.50
3816
+ * `Dinero({ amount: 500050 })` | `'$0,0'` | $5,001
3817
+ * `Dinero({ amount: 500050 })` | `'$0'` | $5001
3818
+ * `Dinero({ amount: 500050 })` | `'$0.0'` | $5000.5
3819
+ * `Dinero({ amount: 500050 })` | `'USD0,0.0'` | USD5,000.5
3820
+ * `Dinero({ amount: 500050 })` | `'0,0.0 dollar'` | 5,000.5 dollars
3821
+ *
3822
+ * Don't try to substitute the `$` sign or the `USD` code with your target currency, nor adapt the format string to the exact format you want.
3823
+ * The format is a mask which defines a pattern and returns a valid, localized currency string.
3824
+ * If you want to display the object in a custom way, either use {@link module:Dinero~getAmount getAmount}, {@link module:Dinero~toUnit toUnit} or {@link module:Dinero~toRoundedUnit toRoundedUnit} and manipulate the output string as you wish.
3825
+ *
3826
+ * {@link module:Dinero~toFormat toFormat} wraps around `Number.prototype.toLocaleString`. For that reason, **format will vary depending on how it's implemented in the end user's environment**.
3827
+ *
3828
+ * You can also use `toLocaleString` directly:
3829
+ * `Dinero().toRoundedUnit(digits, roundingMode).toLocaleString(locale, options)`.
3830
+ *
3831
+ * By default, amounts are rounded using the **half away from zero** rule ([commercial rounding](https://en.wikipedia.org/wiki/Rounding#Round_half_away_from_zero)).
3832
+ * You can also specify a different `roundingMode` to better fit your needs.
3833
+ *
3834
+ * @param {String} [format='$0,0.00'] - The format mask to format to.
3835
+ * @param {String} [roundingMode='HALF_AWAY_FROM_ZERO'] - The rounding mode to use: `'HALF_ODD'`, `'HALF_EVEN'`, `'HALF_UP'`, `'HALF_DOWN'`, `'HALF_TOWARDS_ZERO'`, `'HALF_AWAY_FROM_ZERO'` or `'DOWN'`.
3836
+ *
3837
+ * @example
3838
+ * // returns $2,000
3839
+ * Dinero({ amount: 200000 }).toFormat('$0,0')
3840
+ * @example
3841
+ * // returns €50.5
3842
+ * Dinero({ amount: 5050, currency: 'EUR' }).toFormat('$0,0.0')
3843
+ * @example
3844
+ * // returns 100 euros
3845
+ * Dinero({ amount: 10000, currency: 'EUR' }).setLocale('fr-FR').toFormat('0,0 dollar')
3846
+ * @example
3847
+ * // returns 2000
3848
+ * Dinero({ amount: 200000, currency: 'EUR' }).toFormat()
3849
+ * @example
3850
+ * // returns $10
3851
+ * Dinero({ amount: 1050 }).toFormat('$0', 'HALF_EVEN')
3852
+ *
3853
+ * @return {String}
3854
+ */
3855
+ toFormat: function toFormat() {
3856
+ var format = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : globalFormat;
3857
+ var roundingMode = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : globalFormatRoundingMode;
3858
+ var formatter = Format(format);
3859
+ return this.toRoundedUnit(formatter.getMinimumFractionDigits(), roundingMode).toLocaleString(this.getLocale(), {
3860
+ currencyDisplay: formatter.getCurrencyDisplay(),
3861
+ useGrouping: formatter.getUseGrouping(),
3862
+ minimumFractionDigits: formatter.getMinimumFractionDigits(),
3863
+ style: formatter.getStyle(),
3864
+ currency: this.getCurrency()
3865
+ });
3866
+ },
3867
+
3868
+ /**
3869
+ * Returns the amount represented by this object in units.
3870
+ *
3871
+ * @example
3872
+ * // returns 10.5
3873
+ * Dinero({ amount: 1050 }).toUnit()
3874
+ * @example
3875
+ * // returns 10.545
3876
+ * Dinero({ amount: 10545, precision: 3 }).toUnit()
3877
+ *
3878
+ * @return {Number}
3879
+ */
3880
+ toUnit: function toUnit() {
3881
+ return calculator$1.divide(this.getAmount(), Math.pow(10, precision));
3882
+ },
3883
+
3884
+ /**
3885
+ * Returns the amount represented by this object in rounded units.
3886
+ *
3887
+ * By default, the method uses the **half away from zero** rule ([commercial rounding](https://en.wikipedia.org/wiki/Rounding#Round_half_away_from_zero)).
3888
+ * You can also specify a different `roundingMode` to better fit your needs.
3889
+ *
3890
+ * @example
3891
+ * // returns 10.6
3892
+ * Dinero({ amount: 1055 }).toRoundedUnit(1)
3893
+ * @example
3894
+ * // returns 10
3895
+ * Dinero({ amount: 1050 }).toRoundedUnit(0, 'HALF_EVEN')
3896
+ *
3897
+ * @param {Number} digits - The number of fraction digits to round to.
3898
+ * @param {String} [roundingMode='HALF_AWAY_FROM_ZERO'] - The rounding mode to use: `'HALF_ODD'`, `'HALF_EVEN'`, `'HALF_UP'`, `'HALF_DOWN'`, `'HALF_TOWARDS_ZERO'`, `'HALF_AWAY_FROM_ZERO'` or `'DOWN'`.
3899
+ *
3900
+ * @return {Number}
3901
+ */
3902
+ toRoundedUnit: function toRoundedUnit(digits) {
3903
+ var roundingMode = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : globalFormatRoundingMode;
3904
+ var factor = Math.pow(10, digits);
3905
+ return calculator$1.divide(calculator$1.round(calculator$1.multiply(this.toUnit(), factor), roundingMode), factor);
3906
+ },
3907
+
3908
+ /**
3909
+ * Returns the object's data as an object literal.
3910
+ *
3911
+ * @example
3912
+ * // returns { amount: 500, currency: 'EUR', precision: 2 }
3913
+ * Dinero({ amount: 500, currency: 'EUR', precision: 2 }).toObject()
3914
+ *
3915
+ * @return {Object}
3916
+ */
3917
+ toObject: function toObject() {
3918
+ return {
3919
+ amount: amount,
3920
+ currency: currency,
3921
+ precision: precision
3922
+ };
3923
+ },
3924
+
3925
+ /**
3926
+ * Returns the object's data as an object literal.
3927
+ *
3928
+ * Alias of {@link module:Dinero~toObject toObject}.
3929
+ * It is defined so that calling `JSON.stringify` on a Dinero object will automatically extract the relevant data.
3930
+ *
3931
+ * @example
3932
+ * // returns '{"amount":500,"currency":"EUR","precision":2}'
3933
+ * JSON.stringify(Dinero({ amount: 500, currency: 'EUR', precision: 2 }))
3934
+ *
3935
+ * @return {Object}
3936
+ */
3937
+ toJSON: function toJSON() {
3938
+ return this.toObject();
3939
+ }
3940
+ };
3941
+ };
3942
+
3943
+ var dinero = Object.assign(Dinero, Defaults, Globals, Static);
3944
+
3945
+ function formatCurrency(amount, withSymbol = true) {
3946
+ if (!amount)
3947
+ amount = 0;
3948
+ function format(amount) {
3949
+ const formattedString = withSymbol ? '$0,0.00' : '0,0.00';
3950
+ return dinero({ amount: amount, currency: 'USD' }).toFormat(formattedString);
3951
+ }
3952
+ return amount < 0 ? `(${format(-amount)})` : format(amount);
3953
+ }
3954
+ function formatDate(dateString) {
3955
+ if (!dateString)
3956
+ return '';
3957
+ const date = new Date(dateString);
3958
+ return format(date, 'MMM d, yyyy');
3959
+ }
3960
+ function formatTime(dateString) {
3961
+ if (!dateString)
3962
+ return '';
3963
+ const date = new Date(dateString);
3964
+ return format(date, 'h:mmaaa');
3965
+ }
3966
+ function extractComputedFontsToLoad() {
3967
+ var _a;
3968
+ const computedStyles = getComputedStyle(document.body);
3969
+ return ((_a = computedStyles === null || computedStyles === void 0 ? void 0 : computedStyles.getPropertyValue('--jfi-load-google-font')) === null || _a === void 0 ? void 0 : _a.trim().replace(/'|"/g, '').replace(' ', '+')) || null;
3970
+ }
3971
+
3972
+ exports.Payment = Payment;
3973
+ exports.Payout = Payout;
3974
+ exports.extractComputedFontsToLoad = extractComputedFontsToLoad;
3975
+ exports.formatCurrency = formatCurrency;
3976
+ exports.formatDate = formatDate;
3977
+ exports.formatTime = formatTime;
3978
+
3979
+ //# sourceMappingURL=utils-4ee7e080.js.map