Created
August 29, 2017 03:07
-
-
Save cazetto/1b5ee92bd031d4666f0d9247dbe5ffef to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import numeral from 'numeral'; | |
export default currency = (function() { | |
const CURRENCIES = { BRL: 'R$' }; | |
numeral.register('locale', 'pt-br', { | |
delimiters: { | |
thousands: '.', | |
decimal: ',' | |
}, | |
abbreviations: { | |
thousand: 'k', | |
million: 'm', | |
billion: 'b', | |
trillion: 't' | |
}, | |
ordinal : function (number) { | |
return number === 1 ? 'st' : 'th'; | |
}, | |
currency: { | |
symbol: 'R$' | |
} | |
}); | |
numeral.locale('pt-br'); | |
return { | |
format: function(value, curr) { | |
return `${curr ? CURRENCIES[curr] : ''} ${numeral(String(value).replace(/\./g,',')).format('0,0.00')}`; | |
}, | |
} | |
}()); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment