Returns a Number
from a localized price string.
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
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
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