1.0.12 • Published 4 years ago

parse-money v1.0.12

Weekly downloads
180
License
MIT
Repository
github
Last release
4 years ago

parse-money

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

1.0.12

4 years ago

1.0.10

4 years ago

1.0.9

4 years ago

1.0.8

4 years ago

1.0.7

4 years ago

1.0.6

4 years ago

1.0.4

4 years ago

1.0.2

4 years ago

1.0.1

4 years ago

1.0.0

4 years ago