Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/capturr/price-extract
Performant way to extract price amount and metadatas (currency, decimal & thousands separator) from any string.
https://github.com/capturr/price-extract
amount crawler crawling currencies currency extract extractor javascript nodejs parser parsing price scraper scraping spider typescript
Last synced: 5 days ago
JSON representation
Performant way to extract price amount and metadatas (currency, decimal & thousands separator) from any string.
- Host: GitHub
- URL: https://github.com/capturr/price-extract
- Owner: capturr
- Created: 2021-08-31T14:12:24.000Z (about 3 years ago)
- Default Branch: main
- Last Pushed: 2021-09-21T07:37:03.000Z (about 3 years ago)
- Last Synced: 2024-11-06T08:05:58.962Z (9 days ago)
- Topics: amount, crawler, crawling, currencies, currency, extract, extractor, javascript, nodejs, parser, parsing, price, scraper, scraping, spider, typescript
- Language: TypeScript
- Homepage:
- Size: 12.7 KB
- Stars: 3
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: readme.md
Awesome Lists containing this project
README
# Extract Price from String
Performant way to extract price amount and metadatas (currency, decimal & thousands separator) from any string.
[![npm](https://img.shields.io/npm/v/price-extract)](https://www.npmjs.com/package/price-extract)
## Installation
```bash
npm install --save price-extract
```## API
```typescript
extractPrice(
input: string,
details?: boolean = false,
debug?: boolean = false
): TPrice | number | null;type TAmount = {
number: number,
decsep?: string,
grpsep?: string
}type TCurrency = {
symbol: string,
iso: string,
match: string,
index: number
}type TPrice = TAmount & { currency: TCurrency }
```## Return Value
* **null**: When the price could not be parsed
* **number**: The extracted price value
* **object**: The extract price informations (when details = true)## Example
```typescript
import extractPrice from 'price-extract';console.log(
extractPrice('starting from 1 185,36 € (including taxes)'),
/* 1185.36 */extractPrice('$ 85,4556.34'),
/* 556.34 */extractPrice('There is no price here hahaha $$'),
/* null */
extractPrice('12,456.24 USD', true),
/* {
number: 12456.24,
decsep: '.',
grpsep: ',',
currency: {
symbol: '$',
iso: 'USD',
match: 'USD',
index: 10
}
} */
);
```