buy-vs-rent
Advanced tools
Comparing version 1.2.4 to 1.2.5
module.exports = { | ||
'root': true, | ||
'parserOptions': { | ||
'parser': 'babel-eslint' | ||
}, | ||
'env': { | ||
'browser': true, | ||
'node': true | ||
}, | ||
'globals': { | ||
// 'xla': false | ||
}, | ||
'extends': [ | ||
'standard' | ||
// 'plugin:vue/recommended' // .vue | ||
], | ||
'plugins': [ // 二选一 | ||
'html' // eslint-plugin-html | ||
// 'vue' // eslint-plugin-vue | ||
], | ||
'rules': { // 0 === 'off'; 1 === 'warn'; 2 === 'error' | ||
/* 重载standard */ | ||
'eqeqeq': 1, // 强制使用`===/!==`代替`==/!=` | ||
'no-new': 0, // 允许单独使用`new 构造函数()`,而不赋值 | ||
'no-multi-spaces': [2, { ignoreEOLComments: true }], // 忽略行尾注释前的多个空格 | ||
'no-trailing-spaces': [2, { skipBlankLines: true }], // 允许在空行使用空白符 | ||
'no-console': 0, // 允许console | ||
'no-debugger': process.env.NODE_ENV === 'production' ? 2 : 0, // 是否禁止debugger | ||
'max-len': [1, { 'code': 150 }], // 设置最大长度 | ||
/* 重载vue */ | ||
'vue/max-attributes-per-line': 0, // 标签每行最多的属性 | ||
'vue/attributes-order': 0, // 标签的属性顺序 | ||
'vue/order-in-components': 0 // Vue实例属性顺序 | ||
/* 不在vue预设内 */ | ||
// (eslint-plugin-vue v5.0.0+)强制template内组件使用的命名方式(默认:都可以;'PascalCase';'kebab-case') | ||
// 'vue/component-name-in-template-casing': [1, 'PascalCase'] | ||
/* 团队选择 */ | ||
// 'semi': [2, 'always'], // 分号 | ||
// 'indent': [2, 4], // 缩进长度 | ||
// 'vue/html-indent': [2, 4] // 模板缩进长度 | ||
root: true, | ||
extends: ["standard", "plugin:prettier/recommended"], | ||
plugins: ["prettier"], | ||
rules: { | ||
"prettier/prettier": [ | ||
"error", | ||
{ | ||
// 传入prettier的配置 | ||
trailingComma: "none" | ||
} | ||
] | ||
} | ||
} | ||
}; |
@@ -1,19 +0,16 @@ | ||
const path = require('path') | ||
const path = require("path"); | ||
module.exports = { | ||
context: path.resolve(__dirname, '..'), // 基础目录 | ||
context: path.resolve(__dirname, ".."), // 基础目录 | ||
module: { // 加载器 | ||
module: { | ||
// 加载器 | ||
rules: [ | ||
{ | ||
test: /(\.jsx|\.js)$/, | ||
include: [ | ||
path.resolve(__dirname, '../source') | ||
], | ||
include: [path.resolve(__dirname, "../source")], | ||
use: { | ||
loader: 'babel-loader', | ||
loader: "babel-loader", | ||
options: { | ||
presets: [ | ||
'@babel/preset-env' | ||
] | ||
presets: ["@babel/preset-env"] | ||
} | ||
@@ -24,2 +21,2 @@ } | ||
} | ||
} | ||
}; |
@@ -1,29 +0,32 @@ | ||
const path = require('path') | ||
const merge = require('webpack-merge') // 合并配置 | ||
const base = require('./webpack.base') | ||
const HtmlWebpackPlugin = require('html-webpack-plugin') // html模板 | ||
const path = require("path"); | ||
const merge = require("webpack-merge"); // 合并配置 | ||
const base = require("./webpack.base"); | ||
const HtmlWebpackPlugin = require("html-webpack-plugin"); // html模板 | ||
module.exports = merge(base, { | ||
entry: { // 入口文件 | ||
demo: path.resolve(__dirname, '../source/demo/index.js') | ||
entry: { | ||
// 入口文件 | ||
demo: path.resolve(__dirname, "../source/demo/index.js") | ||
}, | ||
plugins: [ // 插件 | ||
plugins: [ | ||
// 插件 | ||
new HtmlWebpackPlugin({ | ||
template: path.resolve(__dirname, '../source/demo/index.html'), | ||
filename: 'index.html' | ||
template: path.resolve(__dirname, "../source/demo/index.html"), | ||
filename: "index.html" | ||
}) | ||
], | ||
devtool: 'eval-source-map', // 生成sourcemap | ||
devtool: "eval-source-map", // 生成sourcemap | ||
devServer: { // 本地服务器 | ||
contentBase: path.resolve(__dirname, '../demo'), // 加载页面所在目录 | ||
port: '2018', // 监听端口号 | ||
publicPath: '/', // 加载文件路径 | ||
devServer: { | ||
// 本地服务器 | ||
contentBase: path.resolve(__dirname, "../demo"), // 加载页面所在目录 | ||
port: "2018", // 监听端口号 | ||
publicPath: "/", // 加载文件路径 | ||
historyApiFallback: true, // true:找不到路径时指向index.html | ||
stats: 'minimal' // 控制台显示信息 | ||
stats: "minimal" // 控制台显示信息 | ||
}, | ||
mode: 'development' // 模式 | ||
}) | ||
mode: "development" // 模式 | ||
}); |
@@ -1,25 +0,25 @@ | ||
const path = require('path') | ||
const merge = require('webpack-merge') // 合并配置 | ||
const base = require('./webpack.base') | ||
const { CleanWebpackPlugin } = require('clean-webpack-plugin') // 清理文件(夹) | ||
const path = require("path"); | ||
const merge = require("webpack-merge"); // 合并配置 | ||
const base = require("./webpack.base"); | ||
const { CleanWebpackPlugin } = require("clean-webpack-plugin"); // 清理文件(夹) | ||
module.exports = merge(base, { | ||
entry: { // 入口文件 | ||
'buy-vs-rent': path.resolve(__dirname, '../source/buy-vs-rent.js') | ||
entry: { | ||
// 入口文件 | ||
"buy-vs-rent": path.resolve(__dirname, "../source/buy-vs-rent.js") | ||
}, | ||
output: { // 出口文件 | ||
path: path.resolve(__dirname, '../dist'), | ||
filename: '[name].js', | ||
library: 'buyvsrent', // 暴露library的变量名 | ||
libraryTarget: 'umd' // 暴露library的方式 | ||
output: { | ||
// 出口文件 | ||
path: path.resolve(__dirname, "../dist"), | ||
filename: "[name].js", | ||
library: "buyvsrent", // 暴露library的变量名 | ||
libraryTarget: "umd" // 暴露library的方式 | ||
}, | ||
plugins: [ | ||
new CleanWebpackPlugin() | ||
], | ||
plugins: [new CleanWebpackPlugin()], | ||
devtool: 'source-map', // 生成sourcemap | ||
devtool: "source-map", // 生成sourcemap | ||
mode: 'production' // 模式 | ||
}) | ||
mode: "production" // 模式 | ||
}); |
@@ -25,4 +25,13 @@ { | ||
"build": "cross-env NODE_ENV=production webpack --config build/webpack.prod.js", | ||
"dev": "cross-env NODE_ENV=development webpack-dev-server --config build/webpack.dev.js" | ||
"dev": "cross-env NODE_ENV=development webpack-dev-server --config build/webpack.dev.js", | ||
"lint:js": "eslint --fix --ext .js ." | ||
}, | ||
"husky": { | ||
"hooks": { | ||
"pre-commit": "lint-staged" | ||
} | ||
}, | ||
"lint-staged": { | ||
"*.js": "eslint --cache --fix" | ||
}, | ||
"dependencies": {}, | ||
@@ -35,3 +44,13 @@ "devDependencies": { | ||
"cross-env": "7", | ||
"html-webpack-plugin": "3", | ||
"eslint": "7", | ||
"eslint-config-prettier": "7", | ||
"eslint-config-standard": "16", | ||
"eslint-plugin-import": "2", | ||
"eslint-plugin-node": "11", | ||
"eslint-plugin-prettier": "3", | ||
"eslint-plugin-promise": "4", | ||
"html-webpack-plugin": "4", | ||
"husky": "4", | ||
"lint-staged": "10", | ||
"prettier": "2", | ||
"webpack": "4", | ||
@@ -42,3 +61,3 @@ "webpack-cli": "3", | ||
}, | ||
"version": "1.2.4" | ||
"version": "1.2.5" | ||
} |
@@ -9,5 +9,8 @@ const tools = { | ||
*/ | ||
funcA ({ loan, loanRate, months }) { | ||
funcA({ loan, loanRate, months }) { | ||
// 月还款额 = 本金 * 月利率 * Math.pow(1 + 月利率, 还款总月数) / (Math.pow(1 + 月利率, 还款总月数) - 1) | ||
return loan * loanRate * Math.pow(1 + loanRate, months) / (Math.pow(1 + loanRate, months) - 1) | ||
return ( | ||
(loan * loanRate * Math.pow(1 + loanRate, months)) / | ||
(Math.pow(1 + loanRate, months) - 1) | ||
); | ||
}, | ||
@@ -22,16 +25,15 @@ | ||
*/ | ||
funcB ({ loan, loanRate, months }) { | ||
const returnArr = [] | ||
const capital = loan / months // 每月还的本金 | ||
funcB({ loan, loanRate, months }) { | ||
const returnArr = []; | ||
const capital = loan / months; // 每月还的本金 | ||
for (let month = 0; month < months; month += 1) { | ||
// 月还款额 = 本金 / 还款总月数 + 剩余本金 * 月利率 | ||
returnArr.push(capital + (loan - capital * month) * loanRate) | ||
returnArr.push(capital + (loan - capital * month) * loanRate); | ||
} | ||
return returnArr | ||
return returnArr; | ||
} | ||
}; | ||
} | ||
/** | ||
@@ -59,17 +61,18 @@ * 方法描述(月) | ||
// 买房的价格 | ||
const housePrice = cash + loan | ||
const housePrice = cash + loan; | ||
// 租房的现金 | ||
loanRate = loanRate / 12 // 贷款月利率 | ||
cashRate = cashRate / 12 // 现金月投资回报率 | ||
rentRate = rentRate / 12 // 租房租金月涨幅率 | ||
const loanPay = tools.funcA({ loan, loanRate, months }) // 等额本息,每月还款数额 | ||
for (let month = 0; month < months; month += 1) { // 未买房获得的现金收益 | ||
cash = (cash + loanPay - rent * (1 + rentRate)) * (1 + cashRate) | ||
loanRate = loanRate / 12; // 贷款月利率 | ||
cashRate = cashRate / 12; // 现金月投资回报率 | ||
rentRate = rentRate / 12; // 租房租金月涨幅率 | ||
const loanPay = tools.funcA({ loan, loanRate, months }); // 等额本息,每月还款数额 | ||
for (let month = 0; month < months; month += 1) { | ||
// 未买房获得的现金收益 | ||
cash = (cash + loanPay - rent * (1 + rentRate)) * (1 + cashRate); | ||
} | ||
cash = cash.toFixed(2) | ||
cash = cash.toFixed(2); | ||
// 通货膨胀和购买力 | ||
const inflation = Math.pow(1 + inflationRate, months / 12).toFixed(2) // 还完款之后的通货膨胀倍数 | ||
const power = (cash / inflation).toFixed(2) // 购买力 | ||
const inflation = Math.pow(1 + inflationRate, months / 12).toFixed(2); // 还完款之后的通货膨胀倍数 | ||
const power = (cash / inflation).toFixed(2); // 购买力 | ||
@@ -81,4 +84,10 @@ return { | ||
power, | ||
msg: `${(months / 12).toFixed()}年后:<br>买房者获得当年总价"${housePrice}万"的一套房子;租房者获得"${cash}万"现金(购买力相当于当年的"${power}万");<br>当年买的房子需要涨至"${(cash / housePrice).toFixed(2)}倍"持平租房者现金流;<br>由于通货膨胀,物价已经是原来的"${inflation}倍"。` | ||
} | ||
} | ||
msg: `${( | ||
months / 12 | ||
).toFixed()}年后:<br>买房者获得当年总价"${housePrice}万"的一套房子;租房者获得"${cash}万"现金(购买力相当于当年的"${power}万");<br>当年买的房子需要涨至"${( | ||
cash / housePrice | ||
).toFixed( | ||
2 | ||
)}倍"持平租房者现金流;<br>由于通货膨胀,物价已经是原来的"${inflation}倍"。` | ||
}; | ||
}; |
@@ -8,20 +8,20 @@ /** | ||
const getSearchValue = (checkKey, search) => { | ||
checkKey = checkKey.toString() | ||
search = search || window.location.search | ||
checkKey = checkKey.toString(); | ||
search = search || window.location.search; | ||
if (search.slice(0, 1) === '?') { | ||
search = search.slice(1) | ||
if (search.slice(0, 1) === "?") { | ||
search = search.slice(1); | ||
} | ||
const searchArr = search.split('&') | ||
let tempArr, key, value | ||
const searchArr = search.split("&"); | ||
let tempArr, key, value; | ||
for (let i = 0, len = searchArr.length; i < len; i++) { | ||
if (searchArr[i] !== '') { | ||
tempArr = searchArr[i].split('=') | ||
key = tempArr.shift() | ||
value = tempArr.join('=') | ||
if (searchArr[i] !== "") { | ||
tempArr = searchArr[i].split("="); | ||
key = tempArr.shift(); | ||
value = tempArr.join("="); | ||
if (key === checkKey) { | ||
return value | ||
return value; | ||
} | ||
@@ -31,25 +31,25 @@ } | ||
return false | ||
} | ||
return false; | ||
}; | ||
// 获取填入内容并打印 | ||
const loan = document.getElementById('loan') | ||
const loanRate = document.getElementById('loanRate') | ||
const months = document.getElementById('months') | ||
const cash = document.getElementById('cash') | ||
const cashRate = document.getElementById('cashRate') | ||
const rent = document.getElementById('rent') | ||
const rentRate = document.getElementById('rentRate') | ||
const inflationRate = document.getElementById('inflationRate') | ||
const loan = document.getElementById("loan"); | ||
const loanRate = document.getElementById("loanRate"); | ||
const months = document.getElementById("months"); | ||
const cash = document.getElementById("cash"); | ||
const cashRate = document.getElementById("cashRate"); | ||
const rent = document.getElementById("rent"); | ||
const rentRate = document.getElementById("rentRate"); | ||
const inflationRate = document.getElementById("inflationRate"); | ||
loan.value = getSearchValue('loan') || '300' | ||
loanRate.value = getSearchValue('loanRate') || '0.049' | ||
months.value = getSearchValue('months') || '360' | ||
cash.value = getSearchValue('cash') || '100' | ||
cashRate.value = getSearchValue('cashRate') || '0.04' | ||
rent.value = getSearchValue('rent') || '0.4' | ||
rentRate.value = getSearchValue('rentRate') || '0.1' | ||
inflationRate.value = getSearchValue('inflationRate') || '0.05' | ||
loan.value = getSearchValue("loan") || "300"; | ||
loanRate.value = getSearchValue("loanRate") || "0.049"; | ||
months.value = getSearchValue("months") || "360"; | ||
cash.value = getSearchValue("cash") || "100"; | ||
cashRate.value = getSearchValue("cashRate") || "0.04"; | ||
rent.value = getSearchValue("rent") || "0.4"; | ||
rentRate.value = getSearchValue("rentRate") || "0.1"; | ||
inflationRate.value = getSearchValue("inflationRate") || "0.05"; | ||
const buyvsrent = require('../buy-vs-rent.js') | ||
const buyvsrent = require("../buy-vs-rent.js"); | ||
const text = buyvsrent({ | ||
@@ -64,4 +64,4 @@ loan: parseFloat(loan.value, 10), | ||
inflationRate: parseFloat(inflationRate.value, 10) | ||
}).msg | ||
document.getElementById('p').innerHTML = text | ||
console.log(text) | ||
}).msg; | ||
document.getElementById("p").innerHTML = text; | ||
console.log(text); |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
Major refactor
Supply chain riskPackage has recently undergone a major refactor. It may be unstable or indicate significant internal changes. Use caution when updating to versions that include significant changes.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
41573
21
20
218
1