calcfy-calculators 1.0.0

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.
Files changed (3) hide show
  1. package/README.md +96 -0
  2. package/index.js +188 -0
  3. package/package.json +31 -0
package/README.md ADDED
@@ -0,0 +1,96 @@
1
+ # CalcFy Calculators
2
+
3
+ A lightweight, zero-dependency JavaScript library for financial, health, and trading calculations.
4
+
5
+ 🌐 **Full Calculator Suite:** [https://calcfy.cc](https://calcfy.cc)
6
+
7
+ ---
8
+
9
+ ## Installation
10
+
11
+ ```bash
12
+ npm install calcfy-calculators
13
+ ```
14
+
15
+ ---
16
+
17
+ ## Usage
18
+
19
+ ```javascript
20
+ const calcfy = require('calcfy-calculators');
21
+
22
+ // EMI Calculator
23
+ const emi = calcfy.calculateEMI(500000, 8.5, 240);
24
+ console.log(emi);
25
+ // { emi: 4340.08, totalAmount: 1041619.2, totalInterest: 541619.2 }
26
+
27
+ // SIP Calculator
28
+ const sip = calcfy.calculateSIP(5000, 12, 10);
29
+ console.log(sip);
30
+ // { maturityValue: 1164908.38, investedAmount: 600000, estimatedReturns: 564908.38 }
31
+
32
+ // GST Calculator
33
+ const gst = calcfy.calculateGST(10000, 18, 'exclusive');
34
+ console.log(gst);
35
+ // { gstAmount: 1800, preGST: 10000, postGST: 11800 }
36
+
37
+ // Lot Size Calculator (Forex)
38
+ const lot = calcfy.calculateLotSize(10000, 1, 20, 10);
39
+ console.log(lot);
40
+ // { lotSize: 0.5, riskAmount: 100, units: 50000 }
41
+
42
+ // BMI Calculator
43
+ const bmi = calcfy.calculateBMI(70, 175);
44
+ console.log(bmi);
45
+ // { bmi: 22.9, category: 'Normal' }
46
+ ```
47
+
48
+ ---
49
+
50
+ ## Available Calculators
51
+
52
+ ### 💰 Finance
53
+ | Function | Description |
54
+ |---|---|
55
+ | `calculateEMI(principal, rate, months)` | Loan EMI calculator |
56
+ | `calculateSIP(amount, return, years)` | SIP maturity value |
57
+ | `calculateGST(amount, rate, type)` | GST inclusive/exclusive |
58
+ | `calculateCompoundInterest(p, rate, years, n)` | Compound interest |
59
+ | `calculateROI(initial, final)` | Return on investment |
60
+ | `calculateFD(principal, rate, years)` | Fixed deposit maturity |
61
+
62
+ ### ❤️ Health
63
+ | Function | Description |
64
+ |---|---|
65
+ | `calculateBMI(weight, height)` | Body Mass Index |
66
+ | `calculateBMR(weight, height, age, gender)` | Basal Metabolic Rate |
67
+
68
+ ### 📊 Trading
69
+ | Function | Description |
70
+ |---|---|
71
+ | `calculateLotSize(balance, risk%, pips, pipValue)` | Forex lot size |
72
+
73
+ ---
74
+
75
+ ## Why CalcFy?
76
+
77
+ - ✅ Zero dependencies
78
+ - ✅ Works in Node.js and browser
79
+ - ✅ Simple, clean API
80
+ - ✅ Accurate formulas
81
+
82
+ For a full visual calculator experience with 47+ tools, visit **[https://calcfy.cc](https://calcfy.cc)**
83
+
84
+ ---
85
+
86
+ ## Links
87
+
88
+ - 🌐 Website: [https://calcfy.cc](https://calcfy.cc)
89
+ - 📧 Support: [calcfycc@gmail.com](mailto:calcfycc@gmail.com)
90
+ - 🐛 Issues: [https://calcfy.cc/contact](https://calcfy.cc/contact)
91
+
92
+ ---
93
+
94
+ ## License
95
+
96
+ MIT © [CalcFy](https://calcfy.cc)
package/index.js ADDED
@@ -0,0 +1,188 @@
1
+ /**
2
+ * CalcFy Calculators
3
+ * A lightweight JavaScript library for financial, health, and trading calculations.
4
+ * Full calculator suite available at https://calcfy.cc
5
+ */
6
+
7
+ // ─── FINANCE ────────────────────────────────────────
8
+
9
+ /**
10
+ * EMI Calculator
11
+ * @param {number} principal - Loan amount
12
+ * @param {number} annualRate - Annual interest rate (%)
13
+ * @param {number} tenureMonths - Loan tenure in months
14
+ * @returns {object} { emi, totalAmount, totalInterest }
15
+ */
16
+ function calculateEMI(principal, annualRate, tenureMonths) {
17
+ const r = annualRate / 100 / 12;
18
+ const emi = principal * r * Math.pow(1 + r, tenureMonths) / (Math.pow(1 + r, tenureMonths) - 1);
19
+ const totalAmount = emi * tenureMonths;
20
+ return {
21
+ emi: parseFloat(emi.toFixed(2)),
22
+ totalAmount: parseFloat(totalAmount.toFixed(2)),
23
+ totalInterest: parseFloat((totalAmount - principal).toFixed(2))
24
+ };
25
+ }
26
+
27
+ /**
28
+ * SIP Calculator
29
+ * @param {number} monthlyAmount - Monthly SIP amount
30
+ * @param {number} annualReturn - Expected annual return (%)
31
+ * @param {number} years - Investment period in years
32
+ * @returns {object} { maturityValue, investedAmount, estimatedReturns }
33
+ */
34
+ function calculateSIP(monthlyAmount, annualReturn, years) {
35
+ const r = annualReturn / 100 / 12;
36
+ const n = years * 12;
37
+ const maturity = monthlyAmount * ((Math.pow(1 + r, n) - 1) / r) * (1 + r);
38
+ const invested = monthlyAmount * n;
39
+ return {
40
+ maturityValue: parseFloat(maturity.toFixed(2)),
41
+ investedAmount: parseFloat(invested.toFixed(2)),
42
+ estimatedReturns: parseFloat((maturity - invested).toFixed(2))
43
+ };
44
+ }
45
+
46
+ /**
47
+ * GST Calculator
48
+ * @param {number} amount - Base amount
49
+ * @param {number} gstRate - GST rate (%)
50
+ * @param {string} type - 'exclusive' or 'inclusive'
51
+ * @returns {object} { gstAmount, preGST, postGST }
52
+ */
53
+ function calculateGST(amount, gstRate, type = 'exclusive') {
54
+ const rate = gstRate / 100;
55
+ let pre, gst, post;
56
+ if (type === 'exclusive') {
57
+ pre = amount; gst = amount * rate; post = amount + gst;
58
+ } else {
59
+ post = amount; pre = amount / (1 + rate); gst = post - pre;
60
+ }
61
+ return {
62
+ gstAmount: parseFloat(gst.toFixed(2)),
63
+ preGST: parseFloat(pre.toFixed(2)),
64
+ postGST: parseFloat(post.toFixed(2))
65
+ };
66
+ }
67
+
68
+ /**
69
+ * Compound Interest Calculator
70
+ * @param {number} principal - Initial amount
71
+ * @param {number} annualRate - Annual interest rate (%)
72
+ * @param {number} years - Time period in years
73
+ * @param {number} n - Compounding frequency per year (1=yearly, 12=monthly, 4=quarterly)
74
+ * @returns {object} { finalAmount, principal, interest }
75
+ */
76
+ function calculateCompoundInterest(principal, annualRate, years, n = 12) {
77
+ const amount = principal * Math.pow(1 + annualRate / 100 / n, n * years);
78
+ return {
79
+ finalAmount: parseFloat(amount.toFixed(2)),
80
+ principal: parseFloat(principal.toFixed(2)),
81
+ interest: parseFloat((amount - principal).toFixed(2))
82
+ };
83
+ }
84
+
85
+ /**
86
+ * ROI Calculator
87
+ * @param {number} initialInvestment
88
+ * @param {number} finalValue
89
+ * @returns {object} { roiPercent, netProfit, totalReturn }
90
+ */
91
+ function calculateROI(initialInvestment, finalValue) {
92
+ const roi = ((finalValue - initialInvestment) / initialInvestment) * 100;
93
+ return {
94
+ roiPercent: parseFloat(roi.toFixed(2)),
95
+ netProfit: parseFloat((finalValue - initialInvestment).toFixed(2)),
96
+ totalReturn: parseFloat(finalValue.toFixed(2))
97
+ };
98
+ }
99
+
100
+ /**
101
+ * FD Calculator
102
+ * @param {number} principal
103
+ * @param {number} annualRate - Annual interest rate (%)
104
+ * @param {number} years
105
+ * @returns {object} { maturityAmount, principal, interest }
106
+ */
107
+ function calculateFD(principal, annualRate, years) {
108
+ const n = 4; // quarterly compounding
109
+ const amount = principal * Math.pow(1 + annualRate / 100 / n, n * years);
110
+ return {
111
+ maturityAmount: parseFloat(amount.toFixed(2)),
112
+ principal: parseFloat(principal.toFixed(2)),
113
+ interest: parseFloat((amount - principal).toFixed(2))
114
+ };
115
+ }
116
+
117
+ // ─── HEALTH ─────────────────────────────────────────
118
+
119
+ /**
120
+ * BMI Calculator
121
+ * @param {number} weightKg
122
+ * @param {number} heightCm
123
+ * @returns {object} { bmi, category }
124
+ */
125
+ function calculateBMI(weightKg, heightCm) {
126
+ const h = heightCm / 100;
127
+ const bmi = weightKg / (h * h);
128
+ let category;
129
+ if (bmi < 18.5) category = 'Underweight';
130
+ else if (bmi < 25) category = 'Normal';
131
+ else if (bmi < 30) category = 'Overweight';
132
+ else category = 'Obese';
133
+ return { bmi: parseFloat(bmi.toFixed(1)), category };
134
+ }
135
+
136
+ /**
137
+ * BMR Calculator (Mifflin-St Jeor)
138
+ * @param {number} weightKg
139
+ * @param {number} heightCm
140
+ * @param {number} age
141
+ * @param {string} gender - 'male' or 'female'
142
+ * @returns {object} { bmr, sedentary, moderate, active }
143
+ */
144
+ function calculateBMR(weightKg, heightCm, age, gender) {
145
+ const bmr = gender === 'male'
146
+ ? 10 * weightKg + 6.25 * heightCm - 5 * age + 5
147
+ : 10 * weightKg + 6.25 * heightCm - 5 * age - 161;
148
+ return {
149
+ bmr: Math.round(bmr),
150
+ sedentary: Math.round(bmr * 1.2),
151
+ moderate: Math.round(bmr * 1.55),
152
+ active: Math.round(bmr * 1.725)
153
+ };
154
+ }
155
+
156
+ // ─── TRADING ────────────────────────────────────────
157
+
158
+ /**
159
+ * Lot Size Calculator
160
+ * @param {number} accountBalance
161
+ * @param {number} riskPercent - Risk percentage (e.g. 1 for 1%)
162
+ * @param {number} stopLossPips
163
+ * @param {number} pipValue - Value per pip per lot (default 10 for forex majors)
164
+ * @returns {object} { lotSize, riskAmount, units }
165
+ */
166
+ function calculateLotSize(accountBalance, riskPercent, stopLossPips, pipValue = 10) {
167
+ const riskAmount = accountBalance * riskPercent / 100;
168
+ const lotSize = riskAmount / (stopLossPips * pipValue);
169
+ return {
170
+ lotSize: parseFloat(lotSize.toFixed(2)),
171
+ riskAmount: parseFloat(riskAmount.toFixed(2)),
172
+ units: Math.round(lotSize * 100000)
173
+ };
174
+ }
175
+
176
+ // ─── EXPORTS ────────────────────────────────────────
177
+
178
+ module.exports = {
179
+ calculateEMI,
180
+ calculateSIP,
181
+ calculateGST,
182
+ calculateCompoundInterest,
183
+ calculateROI,
184
+ calculateFD,
185
+ calculateBMI,
186
+ calculateBMR,
187
+ calculateLotSize
188
+ };
package/package.json ADDED
@@ -0,0 +1,31 @@
1
+ {
2
+ "name": "calcfy-calculators",
3
+ "version": "1.0.0",
4
+ "description": "Lightweight JavaScript library for EMI, SIP, GST, BMI, Lot Size and more financial & health calculators. Full suite at calcfy.cc",
5
+ "main": "index.js",
6
+ "homepage": "https://calcfy.cc",
7
+ "repository": {
8
+ "type": "git",
9
+ "url": "https://github.com/calcfy/calcfy-calculators"
10
+ },
11
+ "keywords": [
12
+ "calculator",
13
+ "emi",
14
+ "sip",
15
+ "gst",
16
+ "bmi",
17
+ "lot-size",
18
+ "forex",
19
+ "finance",
20
+ "compound-interest",
21
+ "roi",
22
+ "fd",
23
+ "bmr",
24
+ "calcfy"
25
+ ],
26
+ "author": "CalcFy <calcfycc@gmail.com> (https://calcfy.cc)",
27
+ "license": "MIT",
28
+ "bugs": {
29
+ "url": "https://calcfy.cc/contact"
30
+ }
31
+ }