1.0.1 • Published 6 months ago
@crazyorr/loan v1.0.1
loan.js
A JavaScript library for interest calculation of loans.
Installation
$ npm install @crazyorr/loan
Usage
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();
Contributing
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.json
name propertytest
- starts vitest and runs all teststest:coverage
- starts vitest and run all tests with code coverage reportlint:scripts
- lint.ts
files with eslintlint:styles
- lint.css
and.scss
files with stylelintformat:scripts
- format.ts
,.html
and.json
files with prettierformat:styles
- format.cs
and.scss
files with stylelintformat
- format all with prettier and stylelintprepare
- script for setting up husky pre-commit hookuninstall-husky
- script for removing husky from repository
License
This project is licensed under the ISC License