Code Monkey home page Code Monkey logo

extract-price's Introduction

extract-price 🤑

Travis build status Coveralls NPM version Canonical Code Style Twitter Follow

Extracts price from an arbitrary text input.

Usage

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');
// []

FAQ

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

Related projects

  • extract-date – Extracts date from an arbitrary text input.
  • extract-time – Extracts time from an arbitrary text input.

extract-price's People

Contributors

gajus avatar

Stargazers

David Wells avatar Pavel 'Strajk' Dolecek avatar Wildan Zulfikar avatar  avatar Youjun Yu(余佑駿) avatar Michel Ace avatar Mateusz avatar Toon van Ramshorst avatar akshay kadam (a2k) avatar  avatar Anatoli Nicolae avatar JJ. Ramirez avatar  avatar Seb Insua avatar Alberto Leal avatar Dmitriev Sergey avatar  avatar

Watchers

 avatar  avatar

extract-price's Issues

parse result empty for 1 222 333,50

do you have test these ?

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}]

why i got [], with 1 222 333,50

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.