vue-currency-symbol
Version:
A simple VueJs library that returns different currency badges.
47 lines (37 loc) • 1.42 kB
JavaScript
import Vue from 'vue'
import countries from './countries.json'
const countrySymbol = {
install(Vue) {
Vue.mixin({
data() {
return {
currencies: '',
}
},
methods: {
allSymbols() {
let currencies = []
countries.map( country => {
currencies.push(country.symbol)
})
return this.currencies = currencies
},
currencySymbol(name) {
name = name.toLowerCase().trim()
let currencyBadge
countries.map( country => {
let countryArray = country.currency.split(' ')
let currencyName = countryArray.pop().toLowerCase().trim()
let currencyAbbr = country.abbreviation.toLowerCase()
let countryName = countryArray.join(' ').toLowerCase().trim()
if (name === currencyName || name === countryName || name === currencyAbbr){
currencyBadge = country.symbol
}
})
return currencyBadge
}
}
})
}
}
export default countrySymbol