Skip to content

Instantly share code, notes, and snippets.

@cazetto
Created August 29, 2017 03:07
Show Gist options
  • Save cazetto/1b5ee92bd031d4666f0d9247dbe5ffef to your computer and use it in GitHub Desktop.
Save cazetto/1b5ee92bd031d4666f0d9247dbe5ffef to your computer and use it in GitHub Desktop.
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