@takentrade/takentrade-libs
Version:
TakeNTrade shared libraries
41 lines (40 loc) • 1.58 kB
JavaScript
;
Object.defineProperty(exports, "__esModule", { value: true });
exports.getPenaltyTiers = exports.calculatePenaltyAmount = exports.calculatePenalty = void 0;
const PENALTY_TIERS = [
{ maxDays: 7, rate: 0.025 }, // 2.5% for first week
{ maxDays: 14, rate: 0.05 }, // 5% for second week
{ maxDays: 21, rate: 0.075 }, // 7.5% for third week
{ maxDays: Infinity, rate: 0.1 }, // 10% for anything beyond
];
/**
* Calculates the penalty rate based on the number of days a loan repayment is delayed.
* Uses predefined penalty tiers to determine the rate.
*
* @param delayInDays - The number of days the loan repayment is delayed.
* @returns The penalty rate as a decimal (e.g., 0.025 for 2.5%).
*/
const calculatePenalty = (delayInDays) => {
const tier = PENALTY_TIERS.find((tier) => delayInDays <= tier.maxDays);
return tier ? tier.rate : PENALTY_TIERS[PENALTY_TIERS.length - 1].rate;
};
exports.calculatePenalty = calculatePenalty;
/**
* Calculates the penalty amount based on the principal and the number of days delayed.
*
* @param principal - The principal amount of the loan.
* @param delayInDays - The number of days the loan repayment is delayed.
* @returns The penalty amount.
*/
const calculatePenaltyAmount = (principal, delayInDays) => {
const rate = (0, exports.calculatePenalty)(delayInDays);
return principal * rate;
};
exports.calculatePenaltyAmount = calculatePenaltyAmount;
/**
* Get all penalty tiers
*/
const getPenaltyTiers = () => {
return [...PENALTY_TIERS];
};
exports.getPenaltyTiers = getPenaltyTiers;