@jjlmoya/utils-finance 1.43.0 → 1.44.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.
- package/package.json +1 -1
- package/src/category/index.ts +2 -1
- package/src/entries.ts +4 -1
- package/src/tests/locale_completeness.test.ts +2 -2
- package/src/tests/tool_validation.test.ts +2 -2
- package/src/tool/insuranceDeductibleBreakEvenCalculator/bibliography.astro +10 -0
- package/src/tool/insuranceDeductibleBreakEvenCalculator/bibliography.ts +6 -0
- package/src/tool/insuranceDeductibleBreakEvenCalculator/component.astro +172 -0
- package/src/tool/insuranceDeductibleBreakEvenCalculator/currency.test.ts +13 -0
- package/src/tool/insuranceDeductibleBreakEvenCalculator/currency.ts +26 -0
- package/src/tool/insuranceDeductibleBreakEvenCalculator/entry.ts +28 -0
- package/src/tool/insuranceDeductibleBreakEvenCalculator/i18n/content-factory.ts +147 -0
- package/src/tool/insuranceDeductibleBreakEvenCalculator/i18n/de.ts +2 -0
- package/src/tool/insuranceDeductibleBreakEvenCalculator/i18n/en.ts +100 -0
- package/src/tool/insuranceDeductibleBreakEvenCalculator/i18n/es.ts +2 -0
- package/src/tool/insuranceDeductibleBreakEvenCalculator/i18n/fr.ts +2 -0
- package/src/tool/insuranceDeductibleBreakEvenCalculator/i18n/id.ts +2 -0
- package/src/tool/insuranceDeductibleBreakEvenCalculator/i18n/it.ts +2 -0
- package/src/tool/insuranceDeductibleBreakEvenCalculator/i18n/ja.ts +2 -0
- package/src/tool/insuranceDeductibleBreakEvenCalculator/i18n/ko.ts +2 -0
- package/src/tool/insuranceDeductibleBreakEvenCalculator/i18n/nl.ts +2 -0
- package/src/tool/insuranceDeductibleBreakEvenCalculator/i18n/pl.ts +2 -0
- package/src/tool/insuranceDeductibleBreakEvenCalculator/i18n/pt.ts +2 -0
- package/src/tool/insuranceDeductibleBreakEvenCalculator/i18n/ru.ts +2 -0
- package/src/tool/insuranceDeductibleBreakEvenCalculator/i18n/sv.ts +2 -0
- package/src/tool/insuranceDeductibleBreakEvenCalculator/i18n/tr.ts +2 -0
- package/src/tool/insuranceDeductibleBreakEvenCalculator/i18n/zh.ts +2 -0
- package/src/tool/insuranceDeductibleBreakEvenCalculator/index.ts +11 -0
- package/src/tool/insuranceDeductibleBreakEvenCalculator/insurance-deductible-break-even-calculator.css +424 -0
- package/src/tool/insuranceDeductibleBreakEvenCalculator/logic.test.ts +40 -0
- package/src/tool/insuranceDeductibleBreakEvenCalculator/logic.ts +72 -0
- package/src/tool/insuranceDeductibleBreakEvenCalculator/seo.astro +11 -0
- package/src/tool/insuranceDeductibleBreakEvenCalculator/ui.ts +33 -0
- package/src/tools.ts +2 -1
|
@@ -0,0 +1,72 @@
|
|
|
1
|
+
import { isInsuranceCurrencyCode, type InsuranceCurrencyCode } from './currency';
|
|
2
|
+
|
|
3
|
+
export interface InsuranceDeductibleInput {
|
|
4
|
+
currency: string;
|
|
5
|
+
damageCost: number;
|
|
6
|
+
deductible: number;
|
|
7
|
+
annualPremium: number;
|
|
8
|
+
premiumIncreasePercent: number;
|
|
9
|
+
surchargeYears: number;
|
|
10
|
+
}
|
|
11
|
+
|
|
12
|
+
export type InsuranceRecommendation = 'claim' | 'payYourself' | 'breakEven';
|
|
13
|
+
|
|
14
|
+
export interface InsuranceValidationErrors {
|
|
15
|
+
currency?: string;
|
|
16
|
+
damageCost?: string;
|
|
17
|
+
deductible?: string;
|
|
18
|
+
annualPremium?: string;
|
|
19
|
+
premiumIncreasePercent?: string;
|
|
20
|
+
surchargeYears?: string;
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
export interface InsuranceDeductibleResult {
|
|
24
|
+
currency: InsuranceCurrencyCode;
|
|
25
|
+
damageCost: number;
|
|
26
|
+
deductible: number;
|
|
27
|
+
annualPremium: number;
|
|
28
|
+
premiumIncreasePercent: number;
|
|
29
|
+
surchargeYears: number;
|
|
30
|
+
premiumSurcharge: number;
|
|
31
|
+
insurerShare: number;
|
|
32
|
+
claimCost: number;
|
|
33
|
+
payYourselfCost: number;
|
|
34
|
+
difference: number;
|
|
35
|
+
breakEvenDamage: number;
|
|
36
|
+
recommendation: InsuranceRecommendation;
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
const roundMoney = (value: number): number => Number(value.toFixed(2));
|
|
40
|
+
const isMoney = (value: number): boolean => Number.isFinite(value) && value >= 0 && value <= 1_000_000_000_000;
|
|
41
|
+
|
|
42
|
+
export function validateInsuranceInput(input: InsuranceDeductibleInput): InsuranceValidationErrors {
|
|
43
|
+
const errors: InsuranceValidationErrors = {};
|
|
44
|
+
const currency = input.currency.trim().toUpperCase();
|
|
45
|
+
const addError = (key: keyof InsuranceValidationErrors, invalid: boolean): void => { if (invalid) errors[key] = key; };
|
|
46
|
+
addError('currency', !isInsuranceCurrencyCode(currency));
|
|
47
|
+
addError('damageCost', !Number.isFinite(input.damageCost) || input.damageCost <= 0 || input.damageCost > 1_000_000_000_000);
|
|
48
|
+
addError('deductible', !isMoney(input.deductible));
|
|
49
|
+
addError('annualPremium', !isMoney(input.annualPremium));
|
|
50
|
+
addError('premiumIncreasePercent', !Number.isFinite(input.premiumIncreasePercent) || input.premiumIncreasePercent < 0 || input.premiumIncreasePercent > 100);
|
|
51
|
+
addError('surchargeYears', !Number.isFinite(input.surchargeYears) || input.surchargeYears <= 0 || input.surchargeYears > 20);
|
|
52
|
+
return errors;
|
|
53
|
+
}
|
|
54
|
+
|
|
55
|
+
const recommendationFor = (difference: number): InsuranceRecommendation => {
|
|
56
|
+
if (difference > 0.005) return 'claim';
|
|
57
|
+
if (difference < -0.005) return 'payYourself';
|
|
58
|
+
return 'breakEven';
|
|
59
|
+
};
|
|
60
|
+
|
|
61
|
+
export function calculateInsuranceDeductibleBreakEven(input: InsuranceDeductibleInput): InsuranceDeductibleResult | null {
|
|
62
|
+
const errors = validateInsuranceInput(input);
|
|
63
|
+
if (Object.keys(errors).length > 0) return null;
|
|
64
|
+
const currency = input.currency.trim().toUpperCase() as InsuranceCurrencyCode;
|
|
65
|
+
const premiumSurcharge = roundMoney(input.annualPremium * input.premiumIncreasePercent / 100 * input.surchargeYears);
|
|
66
|
+
const insurerShare = roundMoney(Math.max(0, input.damageCost - input.deductible));
|
|
67
|
+
const claimCost = roundMoney(Math.min(input.damageCost, input.deductible) + premiumSurcharge);
|
|
68
|
+
const payYourselfCost = roundMoney(input.damageCost);
|
|
69
|
+
const difference = roundMoney(payYourselfCost - claimCost);
|
|
70
|
+
const breakEvenDamage = roundMoney(input.deductible + premiumSurcharge);
|
|
71
|
+
return { currency, damageCost: payYourselfCost, deductible: roundMoney(input.deductible), annualPremium: roundMoney(input.annualPremium), premiumIncreasePercent: input.premiumIncreasePercent, surchargeYears: input.surchargeYears, premiumSurcharge, insurerShare, claimCost, payYourselfCost, difference, breakEvenDamage, recommendation: recommendationFor(difference) };
|
|
72
|
+
}
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
---
|
|
2
|
+
import { SEORenderer } from '@jjlmoya/utils-shared';
|
|
3
|
+
import { insuranceDeductibleBreakEvenCalculator } from './entry';
|
|
4
|
+
import type { KnownLocale } from '../../types';
|
|
5
|
+
|
|
6
|
+
interface Props { locale?: KnownLocale; }
|
|
7
|
+
const { locale = 'en' } = Astro.props;
|
|
8
|
+
const content = await insuranceDeductibleBreakEvenCalculator.i18n[locale]?.() ?? await insuranceDeductibleBreakEvenCalculator.i18n.en?.();
|
|
9
|
+
---
|
|
10
|
+
|
|
11
|
+
{content?.seo && <SEORenderer content={{ locale, sections: content.seo }} />}
|
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
export interface InsuranceDeductibleBreakEvenCalculatorUI extends Record<string, string> {
|
|
2
|
+
labelDamageCost: string;
|
|
3
|
+
labelDeductible: string;
|
|
4
|
+
labelAnnualPremium: string;
|
|
5
|
+
labelPremiumIncrease: string;
|
|
6
|
+
labelSurchargeYears: string;
|
|
7
|
+
labelCurrency: string;
|
|
8
|
+
labelClaimRoute: string;
|
|
9
|
+
labelPayYourselfRoute: string;
|
|
10
|
+
labelClaimCost: string;
|
|
11
|
+
labelPayYourselfCost: string;
|
|
12
|
+
labelPremiumSurcharge: string;
|
|
13
|
+
labelInsurerShare: string;
|
|
14
|
+
labelBreakEvenDamage: string;
|
|
15
|
+
labelDifference: string;
|
|
16
|
+
labelRecommendation: string;
|
|
17
|
+
labelClaimRecommended: string;
|
|
18
|
+
labelPayYourselfRecommended: string;
|
|
19
|
+
labelBreakEvenRecommendation: string;
|
|
20
|
+
labelVisual: string;
|
|
21
|
+
labelReset: string;
|
|
22
|
+
labelCopy: string;
|
|
23
|
+
labelCopied: string;
|
|
24
|
+
labelCopyFailed: string;
|
|
25
|
+
labelInvalidInput: string;
|
|
26
|
+
labelMethodTitle: string;
|
|
27
|
+
labelMethodText: string;
|
|
28
|
+
labelPrivacyNote: string;
|
|
29
|
+
labelAmountPlaceholder: string;
|
|
30
|
+
labelPercentPlaceholder: string;
|
|
31
|
+
labelYearsPlaceholder: string;
|
|
32
|
+
labelApproximateRates: string;
|
|
33
|
+
}
|
package/src/tools.ts
CHANGED
|
@@ -25,5 +25,6 @@ import { SUBSCRIPTION_COST_ANNUALIZER_TOOL } from './tool/subscriptionCostAnnual
|
|
|
25
25
|
import { LOAN_TO_INCOME_RATIO_TOOL } from './tool/loanToIncomeRatio';
|
|
26
26
|
import { RENTAL_DEPOSIT_RETURN_TOOL } from './tool/rentalDepositReturn';
|
|
27
27
|
import { CAPITAL_GAINS_TAX_SCENARIO_CALCULATOR_TOOL } from './tool/capitalGainsTaxScenarioCalculator';
|
|
28
|
+
import { INSURANCE_DEDUCTIBLE_BREAK_EVEN_CALCULATOR_TOOL } from './tool/insuranceDeductibleBreakEvenCalculator';
|
|
28
29
|
|
|
29
|
-
export const ALL_TOOLS: ToolDefinition[] = [COMPOUND_INTEREST_TOOL, FINANCIAL_FREEDOM_TOOL, SAVINGS_RATE_TOOL, PROFITABILITY_TOOL, MORTGAGE_TOOL, INFLATION_TOOL, PERCENTAGE_CALCULATOR_TOOL, LATE_INTEREST_TOOL, IBAN_BIC_SWIFT_TOOL, RENT_INCREASE_TOOL, LOTTERY_OPTIMIZER_TOOL, COURT_FEE_CALCULATOR_TOOL, LEGAL_INTEREST_RATE_TOOL, FIRE_CALCULATOR_TOOL, DEBT_SNOWBALL_TOOL, REVOLVING_CARD_CALCULATOR_TOOL, PESETA_VALUE_TOOL, SALARY_EMPLOYER_COST_TOOL, DIVIDEND_YIELD_TOOL, MORTGAGE_EXTRA_PAYMENT_PLANNER_TOOL, INFLATION_PURCHASING_POWER_TOOL, SUBSCRIPTION_COST_ANNUALIZER_TOOL, LOAN_TO_INCOME_RATIO_TOOL, RENTAL_DEPOSIT_RETURN_TOOL, CAPITAL_GAINS_TAX_SCENARIO_CALCULATOR_TOOL];
|
|
30
|
+
export const ALL_TOOLS: ToolDefinition[] = [COMPOUND_INTEREST_TOOL, FINANCIAL_FREEDOM_TOOL, SAVINGS_RATE_TOOL, PROFITABILITY_TOOL, MORTGAGE_TOOL, INFLATION_TOOL, PERCENTAGE_CALCULATOR_TOOL, LATE_INTEREST_TOOL, IBAN_BIC_SWIFT_TOOL, RENT_INCREASE_TOOL, LOTTERY_OPTIMIZER_TOOL, COURT_FEE_CALCULATOR_TOOL, LEGAL_INTEREST_RATE_TOOL, FIRE_CALCULATOR_TOOL, DEBT_SNOWBALL_TOOL, REVOLVING_CARD_CALCULATOR_TOOL, PESETA_VALUE_TOOL, SALARY_EMPLOYER_COST_TOOL, DIVIDEND_YIELD_TOOL, MORTGAGE_EXTRA_PAYMENT_PLANNER_TOOL, INFLATION_PURCHASING_POWER_TOOL, SUBSCRIPTION_COST_ANNUALIZER_TOOL, LOAN_TO_INCOME_RATIO_TOOL, RENTAL_DEPOSIT_RETURN_TOOL, CAPITAL_GAINS_TAX_SCENARIO_CALCULATOR_TOOL, INSURANCE_DEDUCTIBLE_BREAK_EVEN_CALCULATOR_TOOL];
|