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) • 805 B
JavaScript
/*!
* unformat-money-js v1.0.7
* (c) 2025 Yurii Derevych
* Released under the BSD-2-Clause License.
*/
class e{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 c=i;c=t.accounting?c.replace(/\(\s*([\d,\.]+)\s*\)/,"-$1"):c.replace(/[()]/g,"");const n=this.escapeRegExp(t.decimalPoint),a=new RegExp(`[^0-9\\-${n}]`,"g"),o=parseFloat(c.replace(/\((?=\d+)(.*)\)/,"-$1").replace(a,"").replace(new RegExp(n,"g"),"."));return isNaN(o)?0:o},this.options=Object.assign(Object.assign({},this.defaults),e)}}export{e as UnFormatMoney};
//# sourceMappingURL=unformat-money-js.esm.min.js.map