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) • 1.06 kB
JavaScript
!function(e,t){"object"==typeof exports&&"undefined"!=typeof module?t(exports):"function"==typeof define&&define.amd?define(["exports"],t):t((e="undefined"!=typeof globalThis?globalThis:e||self).UnformatMoneyJS={})}(this,(function(e){"use strict";
/*!
* unformat-money-js v1.0.7
* (c) 2025 Yurii Derevych
* Released under the BSD-2-Clause License.
*/e.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,t)=>{const s=Object.assign(Object.assign({},this.options),t),n=e||0;if("number"==typeof n)return n;let i=n;i=s.accounting?i.replace(/\(\s*([\d,\.]+)\s*\)/,"-$1"):i.replace(/[()]/g,"");const o=this.escapeRegExp(s.decimalPoint),c=new RegExp(`[^0-9\\-${o}]`,"g"),a=parseFloat(i.replace(/\((?=\d+)(.*)\)/,"-$1").replace(c,"").replace(new RegExp(o,"g"),"."));return isNaN(a)?0:a},this.options=Object.assign(Object.assign({},this.defaults),e)}}}));
//# sourceMappingURL=unformat-money-js.umd.min.js.map