A JavaScript library for interest calculation of loans.
$ npm install @crazyorr/loan
import {
EvenPrincipalLoan,
EvenTotalLoan,
Frequency,
InterestOnlyOnInstallmentLoan,
LumpSumLoan,
TermUnit,
} from "@crazyorr/loan";or
const {
LumpSumLoan,
EvenTotalLoan,
EvenPrincipalLoan,
InterestOnlyOnInstallmentLoan,
Frequency,
TermUnit,
} = require("@crazyorr/loan");then
let loan;
// 到期还本付息贷款
loan = new LumpSumLoan(
10000, // 本金
0.1, // 利率
Frequency.YEARLY, // 利率类型(日/月/年)
12, // 期限
TermUnit.MONTH // 期限单位(日/月/年)
);
// 等额本息贷款
loan = new EvenTotalLoan(
10000, // 本金
0.1, // 利率
Frequency.YEARLY, // 利率类型(日/月/年)
12, // 期限
TermUnit.MONTH, // 期限单位(日/月/年)
Frequency.MONTHLY // 还款频率(日/月/年)
);
// 等额本金贷款
loan = new EvenPrincipalLoan(
10000, // 本金
0.1, // 利率
Frequency.YEARLY, // 利率类型(日/月/年)
12, // 期限
TermUnit.MONTH, // 期限单位(日/月/年)
Frequency.MONTHLY // 还款频率(日/月/年)
);
// 先息后本(按期付息)贷款
loan = new InterestOnlyOnInstallmentLoan(
10000, // 本金
0.1, // 利率
Frequency.YEARLY, // 利率类型(日/月/年)
12, // 期限
TermUnit.MONTH, // 期限单位(日/月/年)
Frequency.MONTHLY // 还款频率(日/月/年)
);
// 计算利息
const repayment = loan.calculateInterest();The starter contains the following scripts:
dev- starts dev serverbuild- generates the following bundles: CommonJS (.js) ESM (.mjs) and IIFE (.iife.js). The name of bundle is automatically taken frompackage.jsonname propertytest- starts vitest and runs all teststest:coverage- starts vitest and run all tests with code coverage reportlint:scripts- lint.tsfiles with eslintlint:styles- lint.cssand.scssfiles with stylelintformat:scripts- format.ts,.htmland.jsonfiles with prettierformat:styles- format.csand.scssfiles with stylelintformat- format all with prettier and stylelintspelling- check spellings with cspellprepare- script for setting up husky pre-commit hookuninstall-husky- script for removing husky from repository
This project is licensed under the ISC License