price-parser

Parse { value: number, currencyCode: string } from string

Usage no npm install needed!

<script type="module">
  import priceParser from 'https://cdn.skypack.dev/price-parser';
</script>

README

const priceParser = require('price-parser');

priceParser.parseFirst('31 june: only £ 54 each — 1 time offer!');
// { value: 5400, floatValue: 54, symbol: '£', currencyCode: 'gbp' }
// Note: values are in smallest currency unit

priceParser.parseAll('Was £5.99, now £2.99',);
// [
//   { value: 599, floatValue: 5.99, symbol: '£', currencyCode: 'gbp' },
//   { value: 299, floatValue: 2.99, symbol: '£', currencyCode: 'gbp' },
// ]