Skip to content

Commit

Permalink
Adding formatMoney helper and making it vue-i18n aware
Browse files Browse the repository at this point in the history
  • Loading branch information
weotch committed May 31, 2022
1 parent 69ecde4 commit f0ec0aa
Showing 1 changed file with 11 additions and 0 deletions.
11 changes: 11 additions & 0 deletions helpers/formatting.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,3 +17,14 @@ export function getShopifyId(id) {
const matches = id.match(/\/([^\/?]+)(?:\?.+)?$/)
if (matches) return matches[1]
}

// Format a string or number like money, using vue-i18n if it's installed
// or falling back to USD
export function formatMoney(val) {
if (this && this.$n) return this.$n(val, 'currency')
return parseFloat(val)
.toLocaleString(process.env.LOCALE_CODE || 'en-US', {
style: 'currency',
currency: process.env.CURRENCY_CODE || 'USD'
})
}

0 comments on commit f0ec0aa

Please sign in to comment.