第4项:对页面、表单及两版共享规则启用严格类型检查
This commit is contained in:
1 parent
389952f31c
commit
f570929cfe
77 files changed
+7629
-2981
No files matched your search
@@ -1,15 +1,19 @@
|
||||
'use strict';
|
||||
// 手续费预览使用整数分;真实费用由服务端按每笔客户付款生成。
|
||||
(function (root) {
|
||||
/** @param {string} account */
|
||||
const isAccount = account => ['助理信用卡', '助理1信用卡', '麦麦信用卡', '助理2信用卡'].includes(account);
|
||||
const ratePermille = 6;
|
||||
function rate(value = ratePermille) {
|
||||
if (!Number.isSafeInteger(value) || value < 0 || value > 1000) throw new Error('信用卡手续费率须为0~1000的整数‰');
|
||||
return value;
|
||||
}
|
||||
/** @param {string} account */
|
||||
const normalizeAccount = account => (isAccount(account) ? '麦麦信用卡' : account);
|
||||
const note = (value = ratePermille) => `信用卡手续费(${rate(value)}‰)`;
|
||||
/** @param {{system?: string; key?: string} | null | undefined} item */
|
||||
const isFee = item => item?.system === 'credit_card' || String(item?.key || '').startsWith('card_fee:');
|
||||
/** @param {number} cents @param {number} [value] */
|
||||
function amount(cents, value = ratePermille) {
|
||||
if (!Number.isSafeInteger(cents) || cents < 0 || cents > 100000000000) throw new Error('客户付款金额无效');
|
||||
return Number((BigInt(cents) * BigInt(rate(value)) + 500n) / 1000n);
|
||||
@@ -17,4 +21,4 @@
|
||||
const api = { isAccount, isFee, amount, rate, ratePermille, normalizeAccount, note };
|
||||
if (typeof module === 'object' && module.exports) module.exports = api;
|
||||
else root.CreditCardFees = api;
|
||||
})(typeof globalThis === 'object' ? globalThis : this);
|
||||
})(typeof globalThis === 'object' ? globalThis : /** @type {typeof globalThis} */ (/** @type {unknown} */ (this)));
|
||||
Reference in new issue
Block a user