money-helpers
v0.2.1
Published
some helpers for working with money
Downloads
2
Maintainers
Readme
Money Helpers
Use these patterns and formatters to help you manage money in your code.
Installation
$ npm install --save money-helpers
# or
$ yarn add money-helpers
Usage
Pattern example
- Use patterns in your inputs
const input = 'a1f2as5123f6fh...515..5.1,5.25';
const patterned = pattern(input);
// => "1,251,236.25"
- Options for patterns
const inputOptions = 'a1f2as51..23f6fh,,,515,,5,15,25';
const patternedWithOptions = pattern(inputOptions, {
lenght: 7,
separator: '.',
});
// => "1.251.236,25"
Formatter example
- Use formatters for show your money in your views
const money = 1234567.89;
const formatted = format(money);
// => "$1,234,567.89"
- Options for formatters
const formattedWithOptions = format(money, 'PEN');
// => "S/ 1,234,567.89"
Parser example
- Use parsers for parse your money into float number
const parsed = parse('1,251,236.25');
// => 1251236.25
- Options for parsers
const parsedWithOptions = parse('1.251.236,25', '.');
// => 1251236.25