Skip to content

mindtricksdev/parse-money

Repository files navigation

parse-money

Travis CI

Extract money from text (number and currency detection)

Returns the amount as Number and the currency as string from a text that contains money.

Installation

npm install --save parse-money
yarn add parse-money

Usage

Pass a string to extract money from.

import parseMoney from 'parse-money';

parseMoney('€1.234,56') // => { amount: 1234.56, currency: 'EUR' }
parseMoney('US$ 1.234,56') // => { amount: 1234.56, currency: 'USD' }
parseMoney('$1.234,56') // => { amount: 1234.56, currency: 'USD' }
parseMoney('1.234,56 US dollars') // => { amount: 1234.56, currency: 'USD' }
parseMoney('£1,234.56') // => { amount: 1234.56, currency: 'GBP' }
parseMoney('R$1.234,56') // => { amount: 1234.56, currency: 'BRL' }
parseMoney('1 234,56 руб') // => { amount: 1234.56, currency: 'RUB' }
parseMoney('1,234.56 ₪') // => { amount: 1234.56, currency: 'ILS' }
parseMoney('123,456.78 lei') // => { amount: 123456.78, currency: 'RON' }
parseMoney('123,45 lei') // => { amount: 123.45, currency: 'RON' }
parseMoney('some text before 123,45 lei and some text after') // => { amount: 123.45, currency: 'RON' }

Typings

type Money = {
  currency: Currency;
  amount: number;
}

type Currency = 'USD' | 'GBP' | 'EUR' | 'BRL' | 'RUB' | 'ILS' | 'RON';

GitHub @mindtricksdev  ·  Twitter @mindtricksdev

About

Localized string to money (number + currency extraction)

Resources

License

Stars

Watchers

Forks

Packages

No packages published