@wpgenius/financial-calculators 1.0.0 → 1.0.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
/*! financial-calculators 1.0.
|
|
1
|
+
/*! financial-calculators 1.0.1 | GPL-3.0-or-later | https://wpgenius.github.io/financial-calculators-js/ */
|
|
2
2
|
|
|
3
3
|
// src/utils.js
|
|
4
4
|
function readNumber(name, value, min = 0) {
|
|
@@ -421,7 +421,7 @@ function amountInWords(value, { system = "indian" } = {}) {
|
|
|
421
421
|
}
|
|
422
422
|
|
|
423
423
|
// src/index.js
|
|
424
|
-
var VERSION = true ? "1.0.
|
|
424
|
+
var VERSION = true ? "1.0.1" : "development";
|
|
425
425
|
export {
|
|
426
426
|
VERSION,
|
|
427
427
|
amountInWords,
|
|
@@ -1,4 +1,5 @@
|
|
|
1
|
-
/*! financial-calculators 1.0.
|
|
1
|
+
/*! financial-calculators 1.0.1 | GPL-3.0-or-later | https://wpgenius.github.io/financial-calculators-js/ */
|
|
2
|
+
"use strict";
|
|
2
3
|
var FinancialCalculators = (() => {
|
|
3
4
|
var __defProp = Object.defineProperty;
|
|
4
5
|
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
@@ -458,6 +459,6 @@ var FinancialCalculators = (() => {
|
|
|
458
459
|
}
|
|
459
460
|
|
|
460
461
|
// src/index.js
|
|
461
|
-
var VERSION = true ? "1.0.
|
|
462
|
+
var VERSION = true ? "1.0.1" : "development";
|
|
462
463
|
return __toCommonJS(index_exports);
|
|
463
464
|
})();
|
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
/*! financial-calculators 1.0.
|
|
2
|
-
var FinancialCalculators=(()=>{var P=Object.defineProperty;var Z=Object.getOwnPropertyDescriptor;var q=Object.getOwnPropertyNames;var J=Object.prototype.hasOwnProperty;var X=(t,n)=>{for(var r in n)P(t,r,{get:n[r],enumerable:!0})},tt=(t,n,r,e)=>{if(n&&typeof n=="object"||typeof n=="function")for(let o of q(n))!J.call(t,o)&&o!==r&&P(t,o,{get:()=>n[o],enumerable:!(e=Z(n,o))||e.enumerable});return t};var nt=t=>tt(P({},"__esModule",{value:!0}),t);var at={};X(at,{VERSION:()=>st,amountInWords:()=>Y,calculate:()=>L,emi:()=>I,formatCompact:()=>Q,formatCurrency:()=>K,formatNumber:()=>x,goal:()=>T,groupDigits:()=>B,lumpsum:()=>M,register:()=>U,sip:()=>S,swp:()=>E,types:()=>A});function f(t,n,r=0){let e=typeof n=="string"&&n.trim()!==""?Number(n):n;if(typeof e!="number"||!Number.isFinite(e))throw new TypeError(`${t} must be a finite number, got ${String(n)}.`);if(e<r)throw new RangeError(`${t} must be at least ${r}, got ${e}.`);return e}function d(t){let n=Math.round(f("years",t)*12);if(n<1)throw new RangeError(`years must be at least one month (1/12), got ${t}.`);return n}function g(t,n){let r=[];for(let e=0;e<t;e+=12)r.push({year:e/12,month:e,...n(e)});return r.push({year:t/12,month:t,...n(t)}),r}function y(t,n,r){return n===0?t*r:t*((Math.pow(1+n,r)-1)/n)*(1+n)}function S({monthlyAmount:t,annualRate:n,years:r}){let e=f("monthlyAmount",t),o=f("annualRate",n)/100/12,i=d(r),c=y(e,o,i),u=e*i;return{invested:u,returns:c-u,total:c,months:i,series:g(i,l=>({invested:e*l,total:y(e,o,l)}))}}function M({amount:t,annualRate:n,years:r,compoundingPerYear:e=1}){let o=f("amount",t),i=f("annualRate",n)/100,c=d(r),u=f("compoundingPerYear",e,1),l=a=>o*Math.pow(1+i/u,u*a/12),m=l(c);return{invested:o,returns:m-o,total:m,months:c,series:g(c,a=>({invested:o,total:l(a)}))}}function E({investment:t,monthlyWithdrawal:n,annualRate:r,years:e}){let o=f("investment",t),i=f("monthlyWithdrawal",n),c=f("annualRate",r)/100/12,u=d(e),l=[o],m=[0],a=o,h=0,b=null;for(let s=1;s<=u;s++){let p=Math.min(i,a);a-=p,h+=p,a<=0?(a=0,b===null&&i>0&&(b=s)):a+=a*c,l.push(a),m.push(h)}return{investment:o,totalWithdrawn:h,finalBalance:a,returns:a+h-o,depletedMonth:b,months:u,series:g(u,s=>({balance:l[s],withdrawn:m[s]}))}}function T({presentCost:t,currentSavings:n=0,inflationRate:r,annualRate:e,years:o}){let i=f("presentCost",t),c=f("currentSavings",n),u=f("inflationRate",r)/100,l=f("annualRate",e)/100,m=d(o),a=l/12,h=w=>i*Math.pow(1+u,w/12),b=w=>c*Math.pow(1+l,w/12),s=h(m),p=b(m),N=Math.max(0,s-p),O=N/y(1,a,m);return{presentCost:i,futureCost:s,savingsFutureValue:p,shortfall:N,monthlyInvestment:O,totalInvested:O*m,months:m,series:g(m,w=>{let W=y(O,a,w);return{goalCost:h(w),savings:b(w),investments:W,total:b(w)+W}})}}function I({principal:t,annualRate:n,years:r}){let e=f("principal",t),o=f("annualRate",n)/100/12,i=d(r),c=o===0?e/i:e*o*Math.pow(1+o,i)/(Math.pow(1+o,i)-1),u=[e],l=[0],m=[0],a=e;for(let s=1;s<=i;s++){let p=a*o,N=s===i?a:c-p;a=Math.max(0,a-N),u.push(a),l.push(l[s-1]+N),m.push(m[s-1]+p)}let h=[];for(let s=0;s<i;s+=12){let p=Math.min(s+12,i);h.push({year:h.length+1,principalPaid:l[p]-l[s],interestPaid:m[p]-m[s],balance:u[p]})}let b=c*i;return{emi:c,principal:e,totalInterest:b-e,totalPayment:b,months:i,schedule:h,series:g(i,s=>({balance:u[s],principalPaid:l[s],interestPaid:m[s]}))}}var F={sip:S,lumpsum:M,swp:E,goal:T,emi:I};function A(){return Object.keys(F)}function L(t,n){if(!Object.prototype.hasOwnProperty.call(F,t))throw new Error(`Unknown calculator "${t}". Available: ${A().join(", ")}.`);return F[t](n)}function U(t,n){if(typeof t!="string"||t===""||typeof n!="function")throw new TypeError("register( type, fn ) needs a type name and a function.");F[t]=n}var v={indian:"en-IN",international:"en-US"},H=!1,D=!1;function et(){if(!H){H=!0;try{D=new Intl.NumberFormat("en-IN").format(1234567)==="12,34,567"&&new Intl.NumberFormat("en-US").format(1234567)==="1,234,567"}catch{D=!1}}return D}function _(t){if(!Object.prototype.hasOwnProperty.call(v,t))throw new RangeError(`system must be "indian" or "international", got "${t}".`);return t}function z(t){if(!Number.isInteger(t)||t<0||t>20)throw new RangeError(`decimals must be a whole number from 0 to 20, got ${t}.`);return t}function B(t,n="indian"){if(t.length<=3)return t;let r=t.slice(-3),e=t.slice(0,-3),o=_(n)==="indian"?2:3,i=new RegExp(`\\B(?=(\\d{${o}})+(?!\\d))`,"g");return e.replace(i,",")+","+r}function rt(t,n,r){let e=Math.abs(t).toFixed(n),[o,i]=e.split(".");return(t<0&&Number(e)!==0?"-":"")+B(o,r)+(i?"."+i:"")}function x(t,{system:n="indian",decimals:r=0}={}){if(_(n),z(r),typeof t!="number"||!Number.isFinite(t))throw new TypeError(`value must be a finite number, got ${String(t)}.`);let o=Number(t.toFixed(r))===0?0:t;return et()?new Intl.NumberFormat(v[n],{minimumFractionDigits:r,maximumFractionDigits:r,useGrouping:!0}).format(o):rt(o,r,n)}function K(t,{symbol:n="\u20B9",position:r="before",system:e="indian",decimals:o=0}={}){let i=x(t,{system:e,decimals:o}),c=i.startsWith("-"),u=c?i.slice(1):i,l=c?"-":"";return r==="after"?`${l}${u} ${n}`:`${l}${n}${u}`}var ot={indian:[[1e7,"Cr"],[1e5,"L"],[1e3,"K"]],international:[[1e12,"T"],[1e9,"B"],[1e6,"M"],[1e3,"K"]]};function Q(t,{system:n="indian",decimals:r=1}={}){if(_(n),z(r),typeof t!="number"||!Number.isFinite(t))throw new TypeError(`value must be a finite number, got ${String(t)}.`);let e=Math.abs(t),o=t<0?"-":"";for(let[i,c]of ot[n])if(e>=i){let u=Number((e/i).toFixed(r));return`${o}${x(u,{system:n,decimals:u%1===0?0:r})}${c}`}return x(t,{system:n,decimals:0})}var k=["","One","Two","Three","Four","Five","Six","Seven","Eight","Nine","Ten","Eleven","Twelve","Thirteen","Fourteen","Fifteen","Sixteen","Seventeen","Eighteen","Nineteen"],it=["","","Twenty","Thirty","Forty","Fifty","Sixty","Seventy","Eighty","Ninety"],R=["","Thousand","Million","Billion","Trillion","Quadrillion","Quintillion","Sextillion","Septillion","Octillion","Nonillion","Decillion"];function C(t){return t<20?k[t]:[it[Math.floor(t/10)],k[t%10]].filter(Boolean).join(" ")}function G(t){let n=Math.floor(t/100),r=t%100;return n?`${k[n]} Hundred`+(r?` and ${C(r)}`:""):C(r)}function $(t){return t.filter(Boolean).join(" ")}function j(t){if(t=t.replace(/^0+/,""),t==="")return"";if(t.length>7){let i=j(t.slice(0,-7));return $([i&&`${i} Crore`,j(t.slice(-7))])}let n=Number(t),r=Math.floor(n/1e5),e=Math.floor(n%1e5/1e3),o=n%1e3;return $([r&&`${C(r)} Lakh`,e&&`${C(e)} Thousand`,G(o)])}function V(t){if(t=t.replace(/^0+/,""),t==="")return"";let n=R.length*3;if(t.length>n){let e=V(t.slice(0,-(n-3))),o=R[R.length-1];return $([e&&`${e} ${o}`,V(t.slice(-(n-3)))])}let r=[];for(let e=t.length,o=0;e>0;e-=3,o++){let i=Number(t.slice(Math.max(0,e-3),e));i&&r.unshift($([G(i),R[o]]))}return $(r)}function Y(t,{system:n="indian"}={}){if(n!=="indian"&&n!=="international")throw new RangeError(`system must be "indian" or "international", got "${n}".`);let r,e=!1;if(typeof t=="number"){if(!Number.isFinite(t))throw new TypeError(`value must be a finite number, got ${t}.`);let i=Math.round(Math.abs(t));e=t<0&&i!==0,r=BigInt(i).toString()}else if(typeof t=="bigint")e=t<0n,r=(e?-t:t).toString();else if(typeof t=="string"&&/^-?\d+$/.test(t.trim())){let i=t.trim();e=i.startsWith("-")&&/[1-9]/.test(i),r=i.replace("-","")}else throw new TypeError(`value must be a number, a BigInt or a string of digits, got ${String(t)}.`);let o=n==="indian"?j(r):V(r);return o===""?"Zero":e?`Minus ${o}`:o}var st="1.0.
|
|
1
|
+
/*! financial-calculators 1.0.1 | GPL-3.0-or-later | https://wpgenius.github.io/financial-calculators-js/ */
|
|
2
|
+
"use strict";var FinancialCalculators=(()=>{var P=Object.defineProperty;var Z=Object.getOwnPropertyDescriptor;var q=Object.getOwnPropertyNames;var J=Object.prototype.hasOwnProperty;var X=(t,n)=>{for(var r in n)P(t,r,{get:n[r],enumerable:!0})},tt=(t,n,r,e)=>{if(n&&typeof n=="object"||typeof n=="function")for(let o of q(n))!J.call(t,o)&&o!==r&&P(t,o,{get:()=>n[o],enumerable:!(e=Z(n,o))||e.enumerable});return t};var nt=t=>tt(P({},"__esModule",{value:!0}),t);var at={};X(at,{VERSION:()=>st,amountInWords:()=>Y,calculate:()=>L,emi:()=>I,formatCompact:()=>Q,formatCurrency:()=>K,formatNumber:()=>x,goal:()=>T,groupDigits:()=>B,lumpsum:()=>M,register:()=>U,sip:()=>S,swp:()=>E,types:()=>A});function f(t,n,r=0){let e=typeof n=="string"&&n.trim()!==""?Number(n):n;if(typeof e!="number"||!Number.isFinite(e))throw new TypeError(`${t} must be a finite number, got ${String(n)}.`);if(e<r)throw new RangeError(`${t} must be at least ${r}, got ${e}.`);return e}function d(t){let n=Math.round(f("years",t)*12);if(n<1)throw new RangeError(`years must be at least one month (1/12), got ${t}.`);return n}function g(t,n){let r=[];for(let e=0;e<t;e+=12)r.push({year:e/12,month:e,...n(e)});return r.push({year:t/12,month:t,...n(t)}),r}function y(t,n,r){return n===0?t*r:t*((Math.pow(1+n,r)-1)/n)*(1+n)}function S({monthlyAmount:t,annualRate:n,years:r}){let e=f("monthlyAmount",t),o=f("annualRate",n)/100/12,i=d(r),c=y(e,o,i),u=e*i;return{invested:u,returns:c-u,total:c,months:i,series:g(i,l=>({invested:e*l,total:y(e,o,l)}))}}function M({amount:t,annualRate:n,years:r,compoundingPerYear:e=1}){let o=f("amount",t),i=f("annualRate",n)/100,c=d(r),u=f("compoundingPerYear",e,1),l=a=>o*Math.pow(1+i/u,u*a/12),m=l(c);return{invested:o,returns:m-o,total:m,months:c,series:g(c,a=>({invested:o,total:l(a)}))}}function E({investment:t,monthlyWithdrawal:n,annualRate:r,years:e}){let o=f("investment",t),i=f("monthlyWithdrawal",n),c=f("annualRate",r)/100/12,u=d(e),l=[o],m=[0],a=o,h=0,b=null;for(let s=1;s<=u;s++){let p=Math.min(i,a);a-=p,h+=p,a<=0?(a=0,b===null&&i>0&&(b=s)):a+=a*c,l.push(a),m.push(h)}return{investment:o,totalWithdrawn:h,finalBalance:a,returns:a+h-o,depletedMonth:b,months:u,series:g(u,s=>({balance:l[s],withdrawn:m[s]}))}}function T({presentCost:t,currentSavings:n=0,inflationRate:r,annualRate:e,years:o}){let i=f("presentCost",t),c=f("currentSavings",n),u=f("inflationRate",r)/100,l=f("annualRate",e)/100,m=d(o),a=l/12,h=w=>i*Math.pow(1+u,w/12),b=w=>c*Math.pow(1+l,w/12),s=h(m),p=b(m),N=Math.max(0,s-p),O=N/y(1,a,m);return{presentCost:i,futureCost:s,savingsFutureValue:p,shortfall:N,monthlyInvestment:O,totalInvested:O*m,months:m,series:g(m,w=>{let W=y(O,a,w);return{goalCost:h(w),savings:b(w),investments:W,total:b(w)+W}})}}function I({principal:t,annualRate:n,years:r}){let e=f("principal",t),o=f("annualRate",n)/100/12,i=d(r),c=o===0?e/i:e*o*Math.pow(1+o,i)/(Math.pow(1+o,i)-1),u=[e],l=[0],m=[0],a=e;for(let s=1;s<=i;s++){let p=a*o,N=s===i?a:c-p;a=Math.max(0,a-N),u.push(a),l.push(l[s-1]+N),m.push(m[s-1]+p)}let h=[];for(let s=0;s<i;s+=12){let p=Math.min(s+12,i);h.push({year:h.length+1,principalPaid:l[p]-l[s],interestPaid:m[p]-m[s],balance:u[p]})}let b=c*i;return{emi:c,principal:e,totalInterest:b-e,totalPayment:b,months:i,schedule:h,series:g(i,s=>({balance:u[s],principalPaid:l[s],interestPaid:m[s]}))}}var F={sip:S,lumpsum:M,swp:E,goal:T,emi:I};function A(){return Object.keys(F)}function L(t,n){if(!Object.prototype.hasOwnProperty.call(F,t))throw new Error(`Unknown calculator "${t}". Available: ${A().join(", ")}.`);return F[t](n)}function U(t,n){if(typeof t!="string"||t===""||typeof n!="function")throw new TypeError("register( type, fn ) needs a type name and a function.");F[t]=n}var v={indian:"en-IN",international:"en-US"},H=!1,D=!1;function et(){if(!H){H=!0;try{D=new Intl.NumberFormat("en-IN").format(1234567)==="12,34,567"&&new Intl.NumberFormat("en-US").format(1234567)==="1,234,567"}catch{D=!1}}return D}function _(t){if(!Object.prototype.hasOwnProperty.call(v,t))throw new RangeError(`system must be "indian" or "international", got "${t}".`);return t}function z(t){if(!Number.isInteger(t)||t<0||t>20)throw new RangeError(`decimals must be a whole number from 0 to 20, got ${t}.`);return t}function B(t,n="indian"){if(t.length<=3)return t;let r=t.slice(-3),e=t.slice(0,-3),o=_(n)==="indian"?2:3,i=new RegExp(`\\B(?=(\\d{${o}})+(?!\\d))`,"g");return e.replace(i,",")+","+r}function rt(t,n,r){let e=Math.abs(t).toFixed(n),[o,i]=e.split(".");return(t<0&&Number(e)!==0?"-":"")+B(o,r)+(i?"."+i:"")}function x(t,{system:n="indian",decimals:r=0}={}){if(_(n),z(r),typeof t!="number"||!Number.isFinite(t))throw new TypeError(`value must be a finite number, got ${String(t)}.`);let o=Number(t.toFixed(r))===0?0:t;return et()?new Intl.NumberFormat(v[n],{minimumFractionDigits:r,maximumFractionDigits:r,useGrouping:!0}).format(o):rt(o,r,n)}function K(t,{symbol:n="\u20B9",position:r="before",system:e="indian",decimals:o=0}={}){let i=x(t,{system:e,decimals:o}),c=i.startsWith("-"),u=c?i.slice(1):i,l=c?"-":"";return r==="after"?`${l}${u} ${n}`:`${l}${n}${u}`}var ot={indian:[[1e7,"Cr"],[1e5,"L"],[1e3,"K"]],international:[[1e12,"T"],[1e9,"B"],[1e6,"M"],[1e3,"K"]]};function Q(t,{system:n="indian",decimals:r=1}={}){if(_(n),z(r),typeof t!="number"||!Number.isFinite(t))throw new TypeError(`value must be a finite number, got ${String(t)}.`);let e=Math.abs(t),o=t<0?"-":"";for(let[i,c]of ot[n])if(e>=i){let u=Number((e/i).toFixed(r));return`${o}${x(u,{system:n,decimals:u%1===0?0:r})}${c}`}return x(t,{system:n,decimals:0})}var k=["","One","Two","Three","Four","Five","Six","Seven","Eight","Nine","Ten","Eleven","Twelve","Thirteen","Fourteen","Fifteen","Sixteen","Seventeen","Eighteen","Nineteen"],it=["","","Twenty","Thirty","Forty","Fifty","Sixty","Seventy","Eighty","Ninety"],R=["","Thousand","Million","Billion","Trillion","Quadrillion","Quintillion","Sextillion","Septillion","Octillion","Nonillion","Decillion"];function C(t){return t<20?k[t]:[it[Math.floor(t/10)],k[t%10]].filter(Boolean).join(" ")}function G(t){let n=Math.floor(t/100),r=t%100;return n?`${k[n]} Hundred`+(r?` and ${C(r)}`:""):C(r)}function $(t){return t.filter(Boolean).join(" ")}function j(t){if(t=t.replace(/^0+/,""),t==="")return"";if(t.length>7){let i=j(t.slice(0,-7));return $([i&&`${i} Crore`,j(t.slice(-7))])}let n=Number(t),r=Math.floor(n/1e5),e=Math.floor(n%1e5/1e3),o=n%1e3;return $([r&&`${C(r)} Lakh`,e&&`${C(e)} Thousand`,G(o)])}function V(t){if(t=t.replace(/^0+/,""),t==="")return"";let n=R.length*3;if(t.length>n){let e=V(t.slice(0,-(n-3))),o=R[R.length-1];return $([e&&`${e} ${o}`,V(t.slice(-(n-3)))])}let r=[];for(let e=t.length,o=0;e>0;e-=3,o++){let i=Number(t.slice(Math.max(0,e-3),e));i&&r.unshift($([G(i),R[o]]))}return $(r)}function Y(t,{system:n="indian"}={}){if(n!=="indian"&&n!=="international")throw new RangeError(`system must be "indian" or "international", got "${n}".`);let r,e=!1;if(typeof t=="number"){if(!Number.isFinite(t))throw new TypeError(`value must be a finite number, got ${t}.`);let i=Math.round(Math.abs(t));e=t<0&&i!==0,r=BigInt(i).toString()}else if(typeof t=="bigint")e=t<0n,r=(e?-t:t).toString();else if(typeof t=="string"&&/^-?\d+$/.test(t.trim())){let i=t.trim();e=i.startsWith("-")&&/[1-9]/.test(i),r=i.replace("-","")}else throw new TypeError(`value must be a number, a BigInt or a string of digits, got ${String(t)}.`);let o=n==="indian"?j(r):V(r);return o===""?"Zero":e?`Minus ${o}`:o}var st="1.0.1";return nt(at);})();
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@wpgenius/financial-calculators",
|
|
3
|
-
"version": "1.0.
|
|
3
|
+
"version": "1.0.1",
|
|
4
4
|
"description": "Financial calculators in plain JavaScript with no dependencies: SIP, lump sum, SWP, goal and EMI, Indian and international number formatting, and amounts in words.",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"finance",
|