parse-price
Version:
returns a Number from a localized price string
9 lines • 1.02 kB
JavaScript
/**
* parse-price - returns a Number from a localized price string
*
* @version 1.1.8
* @link https://github.com/caiogondim/parse-price.js#readme
* @author Caio Gondim
* @license MIT
*/
!function(e,r){"object"==typeof exports&&"object"==typeof module?module.exports=r():"function"==typeof define&&define.amd?define([],r):"object"==typeof exports?exports.parsePrice=r():e.parsePrice=r()}(this,function(){return function(e){function r(n){if(t[n])return t[n].exports;var o=t[n]={exports:{},id:n,loaded:!1};return e[n].call(o.exports,o,o.exports,r),o.loaded=!0,o.exports}var t={};return r.m=e,r.c=t,r.p="",r(0)}([function(e,r){function t(e){return e.replace(/[^\d]/g,"")}function n(e){return e.replace(/[^\d.,]/g,"").replace(/[.,]$/,"")}function o(e){for(var r=n(e),t="0"===r[r.length-1],o=r.length;o>0;o--){if(r.length-o+1>3&&t)return;var i=r[o-1];if(-1!==[",","."].indexOf(i))return i}}function i(e){var r=String(e),n="00",i=o(r);i&&(n=r.split(i)[1]);var f=r.split(i)[0];return Number(t(f)+"."+t(n))}e.exports=i}])});