https://github.com/gajus/extract-price
Extracts prices from an arbitrary text input.
https://github.com/gajus/extract-price
currency extract price
Last synced: 6 months ago
JSON representation
Extracts prices from an arbitrary text input.
- Host: GitHub
- URL: https://github.com/gajus/extract-price
- Owner: gajus
- License: other
- Created: 2019-01-05T13:03:52.000Z (almost 7 years ago)
- Default Branch: master
- Last Pushed: 2019-01-05T16:35:45.000Z (almost 7 years ago)
- Last Synced: 2025-03-28T13:17:30.056Z (6 months ago)
- Topics: currency, extract, price
- Language: JavaScript
- Size: 17.6 KB
- Stars: 16
- Watchers: 2
- Forks: 0
- Open Issues: 2
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
[](https://travis-ci.org/gajus/extract-price)
[](https://coveralls.io/github/gajus/extract-price)
[](https://www.npmjs.org/package/extract-price)
[](https://github.com/gajus/canonical)
[](https://twitter.com/kuizinas)Extracts price from an arbitrary text input.
* [extract-price 🤑](#extract-price)
* [Usage](#extract-price-usage)
* [FAQ](#extract-price-faq)
* [What is the reason the price amount is returned in cents?](#extract-price-faq-what-is-the-reason-the-price-amount-is-returned-in-cents)
* [Related projects](#extract-price-related-projects)```js
import extractPrice from 'extract-price';extractPrice('extracts price from anywhere within the input 1.222.333,50');
// [{amount: 122233350}]extractPrice('understands ,. notation 1,222,333.50');
// [{amount: 122233350}]extractPrice('and ., notation 1.222.333,50');
// [{amount: 122233350}]extractPrice('and space followed by "," notation 1 222 333,50');
// [{amount: 122233350}]extractPrice('and space followed by "." notation 1 222 333.50');
// [{amount: 122233350}]extractPrice('extracts multiple prices listed anywhere within the string using different formats: 1,22, 222, 3,22, 4.20, 5.666');
// [{amount: 12200}, {amount: 22200}, {amount: 322}, {amount: 422}, {amount: 566600}]extractPrice('extracts currency codes EUR 1.00, 2.00 USD');
// [{amount: 100, currencyCode: 'EUR'}, {amount: 200, currencyCode: 'USD'}]extractPrice('extracts currency symbols €1.00, 2.00$');
// [{amount: 100, currencySymbol: '€'}, {amount: 200, currencySymbol: '$'}]extractPrice('does not100 100.20extract ambig0u0s numbers as price');
// []```
### What is the reason the price amount is returned in cents?Because:
```
> 1.03 - 0.42
< 0.6100000000000001```
See: https://stackoverflow.com/q/3730019/368691
* [`extract-date`](https://github.com/gajus/extract-date) – Extracts date from an arbitrary text input.
* [`extract-time`](https://github.com/gajus/extract-time) – Extracts time from an arbitrary text input.