Skip to content

Open source personal finance application

chore(formatAmount): move to file

ilkome10eb2b993cbb
diff --git a/components/amount/Amount.vue b/components/amount/Amount.vue
index 31687314..d5e9b0c9 100644
--- a/components/amount/Amount.vue
+++ b/components/amount/Amount.vue
@@ -1,5 +1,6 @@
<script setup lang="ts">
import useAmount from '~/components/amount/useAmount'
+import { formatAmount, getCurrencySymbol } from '~/components/amount/formatAmount'
const props = withDefaults(defineProps<{
amount: number
@@ -14,7 +15,7 @@ const props = withDefaults(defineProps<{
isShowSign: true,
})
-const { baseCurrencyCode, formatAmount, getCurrencySymbol, getAmountInBaseRate } = useAmount()
+const { baseCurrencyCode, getAmountInBaseRate } = useAmount()
const sign = props.type === 0 ? '-' : '+'
const alignClasses = computed(() => ({
diff --git a/components/amount/formatAmount.ts b/components/amount/formatAmount.ts
new file mode 100644
index 00000000..b2808d81
--- /dev/null
+++ b/components/amount/formatAmount.ts
@@ -0,0 +1,26 @@
+import currencyjs from 'currency.js'
+import { currencies } from '~/components/currencies/currencies'
+import type { CurrencyCode } from '~/components/currencies/types'
+
+export function formatAmount(amount: number, currencyCode?: CurrencyCode) {
+ let currencySettings = null
+
+ if (currencyCode && currencies.find(c => c.code === currencyCode))
+ currencySettings = currencies.find(c => c.code === currencyCode)
+
+ return currencyjs(amount, {
+ symbol: '',
+ precision: currencySettings?.precision ?? 2,
+ pattern: currencySettings?.pattern ?? '#',
+ separator: currencySettings?.separator ?? ' ',
+ }).format()
+}
+
+export function getCurrencySymbol(currencyCode?: CurrencyCode) {
+ const currencySettings = currencies.find(c => c.code === currencyCode)
+
+ if (currencySettings?.symbol)
+ return currencySettings.symbol
+
+ return currencyCode
+}
diff --git a/components/amount/useAmount.ts b/components/amount/useAmount.ts
index ec0ec8c2..4852bb24 100644
--- a/components/amount/useAmount.ts
+++ b/components/amount/useAmount.ts
@@ -1,30 +1,5 @@
-import currencyjs from 'currency.js'
-import { currencies } from '~/components/currencies/currencies'
-import type { CurrencyCode } from '~/components/currencies/types'
import { getAmountInRate } from '~/components/trns/getTotal'
-
-function getCurrencySymbol(currencyCode?: CurrencyCode) {
- const currencySettings = currencies.find(c => c.code === currencyCode)
-
- if (currencySettings?.symbol)
- return currencySettings.symbol
-
- return currencyCode
-}
-
-function formatAmount(amount: number, currencyCode?: CurrencyCode) {
- let currencySettings = null
-
- if (currencyCode && currencies.find(c => c.code === currencyCode))
- currencySettings = currencies.find(c => c.code === currencyCode)
-
- return currencyjs(amount, {
- symbol: '',
- precision: currencySettings?.precision ?? 2,
- pattern: currencySettings?.pattern ?? '#',
- separator: currencySettings?.separator ?? ' ',
- }).format()
-}
+import { formatAmount } from '~/components/amount/formatAmount'
export default function useAmount() {
const { $store } = useNuxtApp()
@@ -54,9 +29,7 @@ export default function useAmount() {
return {
baseCurrencyCode,
-
formatAmount,
- getCurrencySymbol,
getAmountInBaseRate,
}
}
diff --git a/pages/wallets/total.vue b/pages/wallets/total.vue
index a314ad1b..c1cc950f 100644
--- a/pages/wallets/total.vue
+++ b/pages/wallets/total.vue
@@ -11,10 +11,11 @@ import { averageLine, baseSeriesItemStyle, options } from '~/components/chart/ch
import { getTransferCategoriesIds } from '~/components/categories/getCategories'
import { getTotal } from '~/components/trns/getTotal'
import { getTrnsIds } from '~/components/trns/getTrns'
+import { formatAmount, getCurrencySymbol } from '~/components/amount/formatAmount'
type DateValueOf = number
-const { baseCurrencyCode, formatAmount, getCurrencySymbol } = useAmount()
+const { baseCurrencyCode } = useAmount()
const { $store } = useNuxtApp()
/**