UNPKG

make-currency

Version:

[![npm](https://img.shields.io/npm/v/make-currency)](https://www.npmjs.com/package/make-currency) [![NPM](https://img.shields.io/npm/l/make-currency)](https://www.npmjs.com/package/make-currency)

2 lines (1 loc) 2.26 kB
!function(e,n){"object"==typeof exports&&"undefined"!=typeof module?n(exports):"function"==typeof define&&define.amd?define(["exports"],n):n((e="undefined"!=typeof globalThis?globalThis:e||self).Make={})}(this,function(e){"use strict";var n={lang:"en-US",currency:"USD",removePrefix:function(e){return e.slice(1)}},r=Object.freeze({__proto__:null,BRL:{lang:"pt-BR",currency:"BRL",removePrefix:function(e){return e.slice(3)}},EUR:{lang:"pt-PT",currency:"EUR",removePrefix:function(e){return e.slice(0,-2)}},GBP:{lang:"en-GB",currency:"GBP",removePrefix:function(e){return e.slice(1)}},JPY:{lang:"en-US",currency:"USD",removePrefix:function(e){return e.slice(1)},replaceSymbol:function(e){return e.replace("$","¥")}},MXN:{lang:"es-MX",currency:"MXN",removePrefix:function(e){return e.slice(1)}},RUB:{lang:"ru-RU",currency:"RUB",removePrefix:function(e){return e.slice(0,-2)}},USD:n}),o=new(function(){function e(){this.CURRENT=n}return e.prototype.setMoney=function(e){this.CURRENT=e},e}());var t=function(e,n){var r,t,l,u,c,i,a;"INPUT"===n?(c=!1,i=!0,a=o.CURRENT):(c=null===(r=null==n?void 0:n.symbol)||void 0===r||r,i=null!==(t=null==n?void 0:n.isEmpty)&&void 0!==t&&t,a=null!==(l=null==n?void 0:n.money)&&void 0!==l?l:o.CURRENT);var f,s,y=null!==(u=null==a?void 0:a.replaceSymbol)&&void 0!==u?u:function(e){return e},d=(f=e.toString().split("."),s=f[0],f[1]?s+="."+f[1].substring(0,2):s+=".00",parseFloat(s)),p=y(new Intl.NumberFormat(a.lang,{style:"currency",currency:a.currency,useGrouping:!0}).format(d).replace(/[\u00A0]/g," ")),v=a.removePrefix(p),m=c?p:v;return e?m:i?"":m},l=function(e,n){var r,o,l=e.padStart(3,"0"),u=(l=(l=(l=l.replace(/\D/g,"")).replace(/(\d)(\d{2})$/,"$1,$2")).replace(/(?=(\d{3})+(\D))\B/g,".")).padStart(3,"0").replace(/(\d)(\d{2})$/,"$1,$2").split(","),c=u[0],i=u[1],a=c.replace(/\D/g,""),f="".concat(a,".").concat(i),s=parseFloat(f),y={symbol:null!==(r=null==n?void 0:n.symbol)&&void 0!==r&&r,isEmpty:null===(o=null==n?void 0:n.isEmpty)||void 0===o||o,money:null==n?void 0:n.money};return{floatValue:s,stringValue:t(s,y)}},u=function(e){var n=e.money;o.setMoney(n)},c={currency:t,currencyFn:l,TYPES:r,CONFIGURE:u};e.CONFIGURE=u,e.TYPES=r,e.currency=t,e.currencyFn=l,e.default=c,Object.defineProperty(e,"__esModule",{value:!0})});