@resk/core
Version:
An innovative TypeScript framework that empowers developers to build applications with a fully decorator-based architecture for efficient resource management. By combining the power of decorators with a resource-oriented design, DecorRes enhances code cla
4 lines • 4.29 kB
JavaScript
;var d=require('../utils/defaultStr'),D=require('../utils/isNonNullString'),l=require('./session'),P=require('./currencies'),utils=require('./utils');function _interopDefault(e){return e&&e.__esModule?e:{default:e}}var d__default=/*#__PURE__*/_interopDefault(d);var D__default=/*#__PURE__*/_interopDefault(D);var l__default=/*#__PURE__*/_interopDefault(l);var P__default=/*#__PURE__*/_interopDefault(P);var w=Object.defineProperty,$=Object.defineProperties;var j=Object.getOwnPropertyDescriptors;var I=Object.getOwnPropertySymbols;var k=Object.prototype.hasOwnProperty,z=Object.prototype.propertyIsEnumerable;var N=(r,e,t)=>e in r?w(r,e,{enumerable:true,configurable:true,writable:true,value:t}):r[e]=t,S=(r,e)=>{for(var t in e||(e={}))k.call(e,t)&&N(r,t,e[t]);if(I)for(var t of I(e))z.call(e,t)&&N(r,t,e[t]);return r},F=(r,e)=>$(r,j(e));const V=r=>r&&typeof r=="object";function b(r){const e=Object.assign({},l__default.default.getCurrency());if(r&&V(r))for(let t in r)r.hasOwnProperty(t)&&r[t]!==void 0&&(e[t]=r[t]);if(D__default.default(e.format)){const t=R(e.format);t.format&&(e.format=t.format),typeof t.decimalDigits=="number"&&(e.decimalDigits=t.decimalDigits);}return e}function h(r,e){return r=typeof r=="number"?r:0,e=typeof e=="number"?e:0,r=Math.round(Math.abs(r)),isNaN(r)?e:r}function A(r){const e=l__default.default.getCurrency(),t=(e==null?void 0:e.format).toLowerCase();return typeof r=="string"&&(r=r.toLowerCase()),(typeof r!="string"||!r.match("%v"))&&(r=t),{pos:r,neg:r.replace("-","").replace("%v","-%v"),zero:r}}const p=(r,e)=>{const t=l__default.default.getCurrency();if(r=r||0,typeof r=="number")return r;e=e||t.decimalSeparator;const s=new RegExp("[^0-9-"+e+"]","g"),n=parseFloat((""+r).replace(/\((?=\d+)(.*)\)/,"-$1").replace(s,"").replace(e,"."));return isNaN(n)?0:n},C=(r,e)=>{const t=l__default.default.getCurrency();e=h(e,t.decimalDigits);const n=String(r).replace(/[^\d.-]/g,"");if(n.length>15&&!n.includes("."))return n+"."+"0".repeat(e);try{const i=Number(n);if(isNaN(i))return "NaN";const o=+(i+"e"+e);return (+(Math.round(o)+"e-"+e)).toFixed(e)}catch(i){return "NaN"}},x=(r,e,t,s)=>{var m;r=p(r);const n=utils.isValidCurrency(e)?e:{};typeof e=="number"&&(n.decimalDigits=e),typeof n.decimalDigits!="number"&&(n.decimalDigits=(m=String(r).split(".")[1])==null?void 0:m.length),t!==void 0&&(n.thousandSeparator=t),s!==void 0&&(n.decimalSeparator=s);const i=b(n),o=h(i.decimalDigits),a=r<0?"-":"",c=parseInt(C(Math.abs(r||0),o),10)+"",g=c.length>3?c.length%3:0;let u="";if(o){const f=String(parseFloat(C(Math.abs(r),o))||0);f.includes(".")&&(u=d__default.default(f.split(".")[1]).trim());}return a+(g?c.substring(0,g)+i.thousandSeparator:"")+c.substring(g).replace(/(\d{3})(?=\d)/g,"$1"+i.thousandSeparator)+(o&&u?i.decimalSeparator+u:"")},M=(r,e,t,s,n,i)=>{r=p(r);const o=utils.isValidCurrency(e)?e:{};e!==void 0&&typeof e=="string"&&(o.symbol=e),t!==void 0&&(o.decimalDigits=t),s!==void 0&&(o.thousandSeparator=s),n!==void 0&&(o.decimalSeparator=n),i!==void 0&&(o.format=i);const a=b(o),c=A(a.format),g=d__default.default(r>0?c.pos:r<0?c.neg:c.zero),u=d__default.default(a.symbol),m=g.replace(u&&"%s",u),f=x(Math.abs(r),h(a.decimalDigits),a.thousandSeparator,a.decimalSeparator),v=m.replace("%v",f);return F(S({},a),{formattedValue:m,formattedNumber:f,symbol:a.symbol,usedFormat:g,result:v})},O=(r,e,t,s,n,i)=>M(r,e,t,s,n,i).result,R=r=>{r=d__default.default(r).trim();const e={};if(r){const t=/(\.)(\#{0,9}\s*$)/,s=r.match(t);Array.isArray(s)&&s.length===3&&(e.decimalDigits=d__default.default(s[2]).trim().length),r=r.replace(t,"");}return e.format=r,e},L=`Display format for numerical values: a character string consisting of the letters %v and %s, where %v represents the value of the amount and %s represents the currency: example %s%v => $10 and %v %s => $10.
To define decimals, use the [.][#{0,n}] pattern, e.g. .### for display with 3 decimals and . to exclude decimals from the display.
for example, the format %v %s .## returns: 12.35 $ for the value 12.357777 converted into dollard.
`;var Q={parse:p,session:l__default.default,formatMoney:O,currencies:P__default.default,isValidCurrency:utils.isValidCurrency,formatNumber:x,formatMoneyAsObject:M,unformat:p,toFixed:C,formatDescription:L,prepareOptions:b};module.exports=Q;