| | |
| | | return addStarForString(str, 2, end); |
| | | } |
| | | |
| | | export function addStarForPhone(str: string) { |
| | | return `*${str.substring(str.length - 4)}`; |
| | | } |
| | | |
| | | export function formatTimeAgo(date: string, format = 'YYYY-MM-DD HH:mm') { |
| | | const diff = dayjs().diff(date, 'seconds'); // 计算时间差,单位为秒 |
| | | |
| | |
| | | } |
| | | return LifeRechargeConstants.LifePayOrderFrontStatusEnum.支付成功; |
| | | } |
| | | |
| | | export class StringUtils { |
| | | static insertSpaces(str: string, space = 4) { |
| | | if (!str) return ''; |
| | | const regex = new RegExp(`(.{${space}})`, 'g'); |
| | | return str.replace(regex, '$1 '); |
| | | } |
| | | |
| | | static societyCreditCodeInsertSpaces(str: string) { |
| | | if (!str) return ''; |
| | | return str.replace(/(.{4})(.{4})(.{4})(.{6})/g, '$1 $2 $3 $4'); |
| | | } |
| | | |
| | | static idNumberInsertSpaces(str: string) { |
| | | if (!str) return ''; |
| | | return str.replace(/(.{3})(.{3})(.{4})(.{4})(.{4})/g, '$1 $2 $3 $4 $5'); |
| | | } |
| | | |
| | | static phoneNumberAddSpace(realPhoneNumber: string) { |
| | | if (!realPhoneNumber) return ''; |
| | | return realPhoneNumber.replace(/^(\d{3})(\d*)(\d{4})$/, '$1 $2 $3'); |
| | | } |
| | | |
| | | static formatterNumber(str: string) { |
| | | const cleanedValue = str.replace(/[^\d.]/g, ''); |
| | | const singleDotValue = cleanedValue.replace(/(\..*)\./g, '$1'); |
| | | const numberValue = parseFloat(singleDotValue); |
| | | return isNaN(numberValue) ? '' : singleDotValue; |
| | | } |
| | | } |