unformat-money-js
Version:
Zero dependency tiny JavaScript library (532 bytes) by CurrencyRate.today, providing simple way removes all formatting/cruft and returns the raw float value.
8 lines (7 loc) • 812 B
JavaScript
;
/*!
* unformat-money-js v1.0.7
* (c) 2025 Yurii Derevych
* Released under the BSD-2-Clause License.
*/exports.UnFormatMoney=class{constructor(e){this.options=e,this.version="1.0.7",this.defaults={decimalPoint:".",accounting:!1},this.escapeRegExp=e=>e.replace(/[.*+?^${}()|[\]\\]/g,"\\$&"),this.un=(e,s)=>{const t=Object.assign(Object.assign({},this.options),s),i=e||0;if("number"==typeof i)return i;let n=i;n=t.accounting?n.replace(/\(\s*([\d,\.]+)\s*\)/,"-$1"):n.replace(/[()]/g,"");const c=this.escapeRegExp(t.decimalPoint),a=new RegExp(`[^0-9\\-${c}]`,"g"),o=parseFloat(n.replace(/\((?=\d+)(.*)\)/,"-$1").replace(a,"").replace(new RegExp(c,"g"),"."));return isNaN(o)?0:o},this.options=Object.assign(Object.assign({},this.defaults),e)}};
//# sourceMappingURL=unformat-money-js.cjs.min.js.map