Skip to content

florisvink/parse-price.js

 
 

Repository files navigation

parse-price.js

Travis CI codecov dependencies status lib size

Returns a Number from a localized price string.

Usage

Receives a string (price) as input and returns a Number (or NaN) as output.

var parsePrice = require('parse-price')

parsePrice('€1.234,56') // => 1234.56
parsePrice('US$ 1.234,56') // => 1234.56
parsePrice('£1,234.56') // => 1234.56
parsePrice('R$1.234,56') // => 1234.56
parsePrice('1 234,56 руб') // => 1234.56
parsePrice('1,234.56 ₪') // => 1234.56

Installation

Bundler

To use the library, install it through npm

npm install --save parse-price

To port it to Browser or any other (non CJS) environment, use your favorite CJS bundler. No favorite yet? Try: Browserify, Webmake or Webpack

Drop-in

If using a bunlder is not your thing, there are two files with UMD (Universal Module Definition) under dist/ folder, one of them already minified. Just reference it on your browser (drop it) and use it.

<script src="dist/parse-price.min.js"></script>
<script>
  var price = window.parsePrice('€1.1234,56')
</script>

caiogondim.com  ·  GitHub @caiogondim  ·  Twitter @caio_gondim

About

💵 Returns a Number from a localized price string.

Resources

License

Stars

Watchers

Forks

Packages

No packages published

Languages

  • JavaScript 100.0%