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