Methods
(static) formatBankCard(str, optionsopt) → {String}
- Source:
- Since:
- 1.1.0
格式化银行卡号
Example
// 19位银行卡
formatBankCard('6228480402564890018');
// => 6228 4804 0256 4890 018
// 16位银行卡
formatBankCard('6228480402564890');
// => 6228 4804 0256 4890
// 16位银行卡,"-"间隔
formatBankCard('6228480402564890', {char: '-'});
// => 6228-4804-0256-4890
Parameters:
Name | Type | Attributes | Description | |||||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
str |
String | 要处理的字符串 | ||||||||||||||||
options |
Object |
<optional> |
配置项
Properties
|
Returns:
格式化的银行卡号
- Type
- String
(static) formatMoney(num, optionsopt) → {String}
- Source:
- Since:
- 1.1.0
格式化金额
Example
// 整数
formatMoney('1000');
// => 1,000.00
// 小数(默认保留2位小数)
formatMoney('3000.03');
// => 3,000.03
// 保留4位小数
formatMoney('3000.0300', { precision: 4 });
// => 3,000.0300
// 保留10位小数
formatMoney('1500.2', { precision: 10 });
// => 1,500.2000000000
// 自定义单位符号
formatMoney(1000.00, { symbol: '$' });
// => $1,000.00
// 自定义千位分割符(默认',')
formatMoney(1000.00, { thousand: '|' });
// => 1|000.00
// 自定义小数位分割符(默认'.')
formatMoney(1000.00, { thousand: '&' });
// => 1,000&00
Parameters:
Name | Type | Attributes | Description | |||||||||||||||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
num |
String | Number | 需转换金额 (最大:9007199254740991 最小: -9007199254740991) | ||||||||||||||||||||||||||
options |
Object |
<optional> |
金额格式化配置
Properties
|
Returns:
格式化的金额
- Type
- String
(static) numberToChinese(num, optionsopt) → {String}
- Source:
- Since:
- 1.2.0
数字转中文数字
不在安全数字 -9007199254740991~9007199254740991 内,处理会有异常
Example
numberToChinese(100);
// => 一百
numberToChinese(100.3);
// => 一百点三
// 繁体
numberToChinese(100, {big5: true});
// => 壹佰
numberToChinese(100.3, {big5: true});
// => 壹佰点叁
numberToChinese(1234567890, {big5: true});
// => 壹拾贰亿叁仟肆佰伍拾陆万柒仟捌佰玖拾
// 不带计数单位
numberToChinese(1990, {unit: false});
// => 一九九零
// 不带计数单位,修改0
numberToChinese(1990, {unit: false, zero:'〇'});
// => 一九九〇
Parameters:
Name | Type | Attributes | Description | ||||||||||||||||||||||||||||||||||||||||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
num |
Number | 数字 | |||||||||||||||||||||||||||||||||||||||||||||||||||
options |
Object |
<optional> |
配置项
Properties
|
Returns:
中文数字
- Type
- String
(static) replaceChar(str, optionsopt) → {String}
- Source:
- Since:
- 1.1.0
替换字符,应用场景如:脱敏
Example
// 手机号
replaceChar('13000000000');
// => 130****0000
// 身份证
replaceChar('130701199310302288');
// => 130***********2288
// 邮箱
const email = '12345@qq.com'
replaceChar(email, {start: 2, end: email.indexOf('@'), repeat: 4});
// => 12****@qq.com
// 银行卡号
replaceChar('6228480402564890018', {start: 0, end: -4, repeat: 4});
// => ****0018
// 带格式的银行卡号
replaceChar('6228 4804 0256 4890 018', {start: 4, end: -4, exclude: ' '});
// => 6228 **** **** **** 018
// 用户名
replaceChar('林某某', {start: 1, end: -1, repeat: 1});
// => 林*某
Parameters:
Name | Type | Attributes | Description | ||||||||||||||||||||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
str |
String | 要处理的字符串 | |||||||||||||||||||||||||||||||
options |
Object |
<optional> |
配置项
Properties
|
Returns:
处理后的字符
- Type
- String