react-util-tools 1.0.28 → 1.0.29
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/index.cjs +11 -0
- package/dist/index.d.cts +2 -1
- package/dist/index.d.ts +2 -1
- package/dist/index.js +10 -0
- package/package.json +1 -1
- package/src/index.ts +1 -0
- package/src/string/README.md +18 -0
- package/src/string/index.ts +25 -0
package/dist/index.cjs
CHANGED
|
@@ -151,6 +151,7 @@ __export(index_exports, {
|
|
|
151
151
|
maskIdCard: () => maskIdCard,
|
|
152
152
|
maskName: () => maskName,
|
|
153
153
|
maskPhone: () => maskPhone,
|
|
154
|
+
maskString: () => maskString,
|
|
154
155
|
multiply: () => multiply,
|
|
155
156
|
negate: () => negate,
|
|
156
157
|
normalizeSpaces: () => normalizeSpaces,
|
|
@@ -1374,6 +1375,15 @@ function maskName(name) {
|
|
|
1374
1375
|
}
|
|
1375
1376
|
return name.charAt(0) + "*".repeat(name.length - 2) + name.charAt(name.length - 1);
|
|
1376
1377
|
}
|
|
1378
|
+
function maskString(str, visibleChars = 3, mask = "...") {
|
|
1379
|
+
if (!str) return "";
|
|
1380
|
+
if (str.length <= visibleChars * 2) {
|
|
1381
|
+
return str;
|
|
1382
|
+
}
|
|
1383
|
+
const start = str.slice(0, visibleChars);
|
|
1384
|
+
const end = str.slice(-visibleChars);
|
|
1385
|
+
return `${start}${mask}${end}`;
|
|
1386
|
+
}
|
|
1377
1387
|
function isValidPhone(phone) {
|
|
1378
1388
|
if (!phone) return false;
|
|
1379
1389
|
return /^1[3-9]\d{9}$/.test(phone);
|
|
@@ -1557,6 +1567,7 @@ function fromBase64(base64) {
|
|
|
1557
1567
|
maskIdCard,
|
|
1558
1568
|
maskName,
|
|
1559
1569
|
maskPhone,
|
|
1570
|
+
maskString,
|
|
1560
1571
|
multiply,
|
|
1561
1572
|
negate,
|
|
1562
1573
|
normalizeSpaces,
|
package/dist/index.d.cts
CHANGED
|
@@ -240,6 +240,7 @@ declare function maskPhone(phone: string): string;
|
|
|
240
240
|
declare function maskIdCard(idCard: string): string;
|
|
241
241
|
declare function maskBankCard(cardNumber: string): string;
|
|
242
242
|
declare function maskName(name: string): string;
|
|
243
|
+
declare function maskString(str: string, visibleChars?: number, mask?: string): string;
|
|
243
244
|
declare function isValidPhone(phone: string): boolean;
|
|
244
245
|
declare function isValidEmail(email: string): boolean;
|
|
245
246
|
declare function isValidUrl(url: string): boolean;
|
|
@@ -247,4 +248,4 @@ declare function isValidIdCard(idCard: string): boolean;
|
|
|
247
248
|
declare function toBase64(str: string): string;
|
|
248
249
|
declare function fromBase64(base64: string): string;
|
|
249
250
|
|
|
250
|
-
export { type AmountNum, type CookieOptions, abs, add, addDaysToDate, addDaysUTC, addMonthsToDate, addMonthsUTC, aoaToSheet, camelCase, capitalize, ceil, clearAllCookies, countOccurrences, debounceFn as debounce, divide, endsWith, equals, escapeHtml, exportExcelFile, exportJSONToExcel, extractNumbers, floor, formatDate, formatDateOnly, formatMoney, formatMoneyToChinese, formatNumber, formatPercent, formatRelativeTime, formatTimeOnly, formatUTC, formatUTCDateOnly, formatUTCTimeOnly, formateAmount, formateFaitAmount, formatePrecision, fromBase64, fromUTC, getAllCookies, getAllQueryParams, getBrowser, getBrowserEngine, getBrowserVersion, getCookie, getDaysDiff, getDeviceInfo, getDevicePixelRatio, getDeviceType, getEndOfDay, getEndOfMonth, getEndOfWeek, getEndOfYear, getHoursDiff, getMinutesDiff, getOS, getQueryParam, getQueryParamAll, getScreenResolution, getSheet, getSheetNames, getStartOfDay, getStartOfMonth, getStartOfWeek, getStartOfYear, getTimestamp, getTimestampInSeconds, getTimezoneOffset, getTimezoneOffsetHours, getUTCAllWeeksInYear, getUTCDaysDiff, getUTCEndOfDay, getUTCEndOfMonth, getUTCHoursDiff, getUTCMinutesDiff, getUTCNow, getUTCStartOfDay, getUTCStartOfMonth, getUTCTimestamp, getUTCTimestampInSeconds, getUTCWeekEnd, getUTCWeekNumber, getUTCWeekStart, getUTCWeeksInYear, getUTCYearEnd, getUTCYearEndTimestamp, getUTCYearStart, getUTCYearStartTimestamp, getViewportSize, greaterThan, greaterThanOrEqual, hasCookie, includes, integerTokenArr, isAfterDate, isAndroid, isBeforeDate, isDesktop, isEmpty, isIOS, isMobile, isNotEmpty, isSameDayDate, isTablet, isTouchDevice, isValidDate, isValidEmail, isValidIdCard, isValidPhone, isValidUrl, isWeChat, jsonToWorkbook, kebabCase, length, lessThan, lessThanOrEqual, maskBankCard, maskEmail, maskIdCard, maskName, maskPhone, multiply, negate, normalizeSpaces, padEnd, padStart, parseDate, parseMoney, pascalCase, randomString, read, readExcelFile, readExcelToJSON, readFile, removeCookie, removeInvalidZero, removeSpaces, repeat, replaceAll, reverse, round, setCookie, sheetToAOA, sheetToCSV, sheetToHTML, snakeCase, split, startsWith, stripHtml, subDaysFromDate, subDaysUTC, subMonthsFromDate, subMonthsUTC, subtract, tableToSheet, throttleFn as throttle, titleCase, toBase64, toISOString, toLocalString, toLowerCase, toUTC, toUpperCase, trim, trimEnd, trimStart, truncate, tryRun, unescapeHtml, unmaskEmail, utils, uuid, workbookToJSON, write, writeFile, writeFileXLSX };
|
|
251
|
+
export { type AmountNum, type CookieOptions, abs, add, addDaysToDate, addDaysUTC, addMonthsToDate, addMonthsUTC, aoaToSheet, camelCase, capitalize, ceil, clearAllCookies, countOccurrences, debounceFn as debounce, divide, endsWith, equals, escapeHtml, exportExcelFile, exportJSONToExcel, extractNumbers, floor, formatDate, formatDateOnly, formatMoney, formatMoneyToChinese, formatNumber, formatPercent, formatRelativeTime, formatTimeOnly, formatUTC, formatUTCDateOnly, formatUTCTimeOnly, formateAmount, formateFaitAmount, formatePrecision, fromBase64, fromUTC, getAllCookies, getAllQueryParams, getBrowser, getBrowserEngine, getBrowserVersion, getCookie, getDaysDiff, getDeviceInfo, getDevicePixelRatio, getDeviceType, getEndOfDay, getEndOfMonth, getEndOfWeek, getEndOfYear, getHoursDiff, getMinutesDiff, getOS, getQueryParam, getQueryParamAll, getScreenResolution, getSheet, getSheetNames, getStartOfDay, getStartOfMonth, getStartOfWeek, getStartOfYear, getTimestamp, getTimestampInSeconds, getTimezoneOffset, getTimezoneOffsetHours, getUTCAllWeeksInYear, getUTCDaysDiff, getUTCEndOfDay, getUTCEndOfMonth, getUTCHoursDiff, getUTCMinutesDiff, getUTCNow, getUTCStartOfDay, getUTCStartOfMonth, getUTCTimestamp, getUTCTimestampInSeconds, getUTCWeekEnd, getUTCWeekNumber, getUTCWeekStart, getUTCWeeksInYear, getUTCYearEnd, getUTCYearEndTimestamp, getUTCYearStart, getUTCYearStartTimestamp, getViewportSize, greaterThan, greaterThanOrEqual, hasCookie, includes, integerTokenArr, isAfterDate, isAndroid, isBeforeDate, isDesktop, isEmpty, isIOS, isMobile, isNotEmpty, isSameDayDate, isTablet, isTouchDevice, isValidDate, isValidEmail, isValidIdCard, isValidPhone, isValidUrl, isWeChat, jsonToWorkbook, kebabCase, length, lessThan, lessThanOrEqual, maskBankCard, maskEmail, maskIdCard, maskName, maskPhone, maskString, multiply, negate, normalizeSpaces, padEnd, padStart, parseDate, parseMoney, pascalCase, randomString, read, readExcelFile, readExcelToJSON, readFile, removeCookie, removeInvalidZero, removeSpaces, repeat, replaceAll, reverse, round, setCookie, sheetToAOA, sheetToCSV, sheetToHTML, snakeCase, split, startsWith, stripHtml, subDaysFromDate, subDaysUTC, subMonthsFromDate, subMonthsUTC, subtract, tableToSheet, throttleFn as throttle, titleCase, toBase64, toISOString, toLocalString, toLowerCase, toUTC, toUpperCase, trim, trimEnd, trimStart, truncate, tryRun, unescapeHtml, unmaskEmail, utils, uuid, workbookToJSON, write, writeFile, writeFileXLSX };
|
package/dist/index.d.ts
CHANGED
|
@@ -240,6 +240,7 @@ declare function maskPhone(phone: string): string;
|
|
|
240
240
|
declare function maskIdCard(idCard: string): string;
|
|
241
241
|
declare function maskBankCard(cardNumber: string): string;
|
|
242
242
|
declare function maskName(name: string): string;
|
|
243
|
+
declare function maskString(str: string, visibleChars?: number, mask?: string): string;
|
|
243
244
|
declare function isValidPhone(phone: string): boolean;
|
|
244
245
|
declare function isValidEmail(email: string): boolean;
|
|
245
246
|
declare function isValidUrl(url: string): boolean;
|
|
@@ -247,4 +248,4 @@ declare function isValidIdCard(idCard: string): boolean;
|
|
|
247
248
|
declare function toBase64(str: string): string;
|
|
248
249
|
declare function fromBase64(base64: string): string;
|
|
249
250
|
|
|
250
|
-
export { type AmountNum, type CookieOptions, abs, add, addDaysToDate, addDaysUTC, addMonthsToDate, addMonthsUTC, aoaToSheet, camelCase, capitalize, ceil, clearAllCookies, countOccurrences, debounceFn as debounce, divide, endsWith, equals, escapeHtml, exportExcelFile, exportJSONToExcel, extractNumbers, floor, formatDate, formatDateOnly, formatMoney, formatMoneyToChinese, formatNumber, formatPercent, formatRelativeTime, formatTimeOnly, formatUTC, formatUTCDateOnly, formatUTCTimeOnly, formateAmount, formateFaitAmount, formatePrecision, fromBase64, fromUTC, getAllCookies, getAllQueryParams, getBrowser, getBrowserEngine, getBrowserVersion, getCookie, getDaysDiff, getDeviceInfo, getDevicePixelRatio, getDeviceType, getEndOfDay, getEndOfMonth, getEndOfWeek, getEndOfYear, getHoursDiff, getMinutesDiff, getOS, getQueryParam, getQueryParamAll, getScreenResolution, getSheet, getSheetNames, getStartOfDay, getStartOfMonth, getStartOfWeek, getStartOfYear, getTimestamp, getTimestampInSeconds, getTimezoneOffset, getTimezoneOffsetHours, getUTCAllWeeksInYear, getUTCDaysDiff, getUTCEndOfDay, getUTCEndOfMonth, getUTCHoursDiff, getUTCMinutesDiff, getUTCNow, getUTCStartOfDay, getUTCStartOfMonth, getUTCTimestamp, getUTCTimestampInSeconds, getUTCWeekEnd, getUTCWeekNumber, getUTCWeekStart, getUTCWeeksInYear, getUTCYearEnd, getUTCYearEndTimestamp, getUTCYearStart, getUTCYearStartTimestamp, getViewportSize, greaterThan, greaterThanOrEqual, hasCookie, includes, integerTokenArr, isAfterDate, isAndroid, isBeforeDate, isDesktop, isEmpty, isIOS, isMobile, isNotEmpty, isSameDayDate, isTablet, isTouchDevice, isValidDate, isValidEmail, isValidIdCard, isValidPhone, isValidUrl, isWeChat, jsonToWorkbook, kebabCase, length, lessThan, lessThanOrEqual, maskBankCard, maskEmail, maskIdCard, maskName, maskPhone, multiply, negate, normalizeSpaces, padEnd, padStart, parseDate, parseMoney, pascalCase, randomString, read, readExcelFile, readExcelToJSON, readFile, removeCookie, removeInvalidZero, removeSpaces, repeat, replaceAll, reverse, round, setCookie, sheetToAOA, sheetToCSV, sheetToHTML, snakeCase, split, startsWith, stripHtml, subDaysFromDate, subDaysUTC, subMonthsFromDate, subMonthsUTC, subtract, tableToSheet, throttleFn as throttle, titleCase, toBase64, toISOString, toLocalString, toLowerCase, toUTC, toUpperCase, trim, trimEnd, trimStart, truncate, tryRun, unescapeHtml, unmaskEmail, utils, uuid, workbookToJSON, write, writeFile, writeFileXLSX };
|
|
251
|
+
export { type AmountNum, type CookieOptions, abs, add, addDaysToDate, addDaysUTC, addMonthsToDate, addMonthsUTC, aoaToSheet, camelCase, capitalize, ceil, clearAllCookies, countOccurrences, debounceFn as debounce, divide, endsWith, equals, escapeHtml, exportExcelFile, exportJSONToExcel, extractNumbers, floor, formatDate, formatDateOnly, formatMoney, formatMoneyToChinese, formatNumber, formatPercent, formatRelativeTime, formatTimeOnly, formatUTC, formatUTCDateOnly, formatUTCTimeOnly, formateAmount, formateFaitAmount, formatePrecision, fromBase64, fromUTC, getAllCookies, getAllQueryParams, getBrowser, getBrowserEngine, getBrowserVersion, getCookie, getDaysDiff, getDeviceInfo, getDevicePixelRatio, getDeviceType, getEndOfDay, getEndOfMonth, getEndOfWeek, getEndOfYear, getHoursDiff, getMinutesDiff, getOS, getQueryParam, getQueryParamAll, getScreenResolution, getSheet, getSheetNames, getStartOfDay, getStartOfMonth, getStartOfWeek, getStartOfYear, getTimestamp, getTimestampInSeconds, getTimezoneOffset, getTimezoneOffsetHours, getUTCAllWeeksInYear, getUTCDaysDiff, getUTCEndOfDay, getUTCEndOfMonth, getUTCHoursDiff, getUTCMinutesDiff, getUTCNow, getUTCStartOfDay, getUTCStartOfMonth, getUTCTimestamp, getUTCTimestampInSeconds, getUTCWeekEnd, getUTCWeekNumber, getUTCWeekStart, getUTCWeeksInYear, getUTCYearEnd, getUTCYearEndTimestamp, getUTCYearStart, getUTCYearStartTimestamp, getViewportSize, greaterThan, greaterThanOrEqual, hasCookie, includes, integerTokenArr, isAfterDate, isAndroid, isBeforeDate, isDesktop, isEmpty, isIOS, isMobile, isNotEmpty, isSameDayDate, isTablet, isTouchDevice, isValidDate, isValidEmail, isValidIdCard, isValidPhone, isValidUrl, isWeChat, jsonToWorkbook, kebabCase, length, lessThan, lessThanOrEqual, maskBankCard, maskEmail, maskIdCard, maskName, maskPhone, maskString, multiply, negate, normalizeSpaces, padEnd, padStart, parseDate, parseMoney, pascalCase, randomString, read, readExcelFile, readExcelToJSON, readFile, removeCookie, removeInvalidZero, removeSpaces, repeat, replaceAll, reverse, round, setCookie, sheetToAOA, sheetToCSV, sheetToHTML, snakeCase, split, startsWith, stripHtml, subDaysFromDate, subDaysUTC, subMonthsFromDate, subMonthsUTC, subtract, tableToSheet, throttleFn as throttle, titleCase, toBase64, toISOString, toLocalString, toLowerCase, toUTC, toUpperCase, trim, trimEnd, trimStart, truncate, tryRun, unescapeHtml, unmaskEmail, utils, uuid, workbookToJSON, write, writeFile, writeFileXLSX };
|
package/dist/index.js
CHANGED
|
@@ -1206,6 +1206,15 @@ function maskName(name) {
|
|
|
1206
1206
|
}
|
|
1207
1207
|
return name.charAt(0) + "*".repeat(name.length - 2) + name.charAt(name.length - 1);
|
|
1208
1208
|
}
|
|
1209
|
+
function maskString(str, visibleChars = 3, mask = "...") {
|
|
1210
|
+
if (!str) return "";
|
|
1211
|
+
if (str.length <= visibleChars * 2) {
|
|
1212
|
+
return str;
|
|
1213
|
+
}
|
|
1214
|
+
const start = str.slice(0, visibleChars);
|
|
1215
|
+
const end = str.slice(-visibleChars);
|
|
1216
|
+
return `${start}${mask}${end}`;
|
|
1217
|
+
}
|
|
1209
1218
|
function isValidPhone(phone) {
|
|
1210
1219
|
if (!phone) return false;
|
|
1211
1220
|
return /^1[3-9]\d{9}$/.test(phone);
|
|
@@ -1388,6 +1397,7 @@ export {
|
|
|
1388
1397
|
maskIdCard,
|
|
1389
1398
|
maskName,
|
|
1390
1399
|
maskPhone,
|
|
1400
|
+
maskString,
|
|
1391
1401
|
multiply,
|
|
1392
1402
|
negate,
|
|
1393
1403
|
normalizeSpaces,
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "react-util-tools",
|
|
3
|
-
"version": "1.0.
|
|
3
|
+
"version": "1.0.29",
|
|
4
4
|
"description": "A collection of useful utilities: throttle, debounce, date formatting, device detection, money formatting, decimal calculations, Excel processing and more",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"main": "dist/index.cjs",
|
package/src/index.ts
CHANGED
package/src/string/README.md
CHANGED
|
@@ -90,6 +90,7 @@ import {
|
|
|
90
90
|
maskIdCard,
|
|
91
91
|
maskBankCard,
|
|
92
92
|
maskName,
|
|
93
|
+
maskString,
|
|
93
94
|
maskEmail
|
|
94
95
|
} from 'react-util-tools'
|
|
95
96
|
|
|
@@ -106,6 +107,22 @@ maskBankCard('6222021234567890') // '6222 **** **** 7890'
|
|
|
106
107
|
maskName('张三') // '张*'
|
|
107
108
|
maskName('李四光') // '李*光'
|
|
108
109
|
|
|
110
|
+
// 通用字符串脱敏
|
|
111
|
+
maskString('123wedwdwddwed567', 3) // '123...567'
|
|
112
|
+
maskString('abcdefghijk', 2) // 'ab...jk'
|
|
113
|
+
maskString('hello', 2, '***') // 'he***lo'
|
|
114
|
+
|
|
115
|
+
// 邮箱脱敏(在 format 模块)
|
|
116
|
+
maskEmail('test@example.com') // 'tes***@example.com'
|
|
117
|
+
```
|
|
118
|
+
|
|
119
|
+
// 银行卡号脱敏
|
|
120
|
+
maskBankCard('6222021234567890') // '6222 **** **** 7890'
|
|
121
|
+
|
|
122
|
+
// 姓名脱敏
|
|
123
|
+
maskName('张三') // '张*'
|
|
124
|
+
maskName('李四光') // '李*光'
|
|
125
|
+
|
|
109
126
|
// 邮箱脱敏(在 format 模块)
|
|
110
127
|
maskEmail('test@example.com') // 'tes***@example.com'
|
|
111
128
|
```
|
|
@@ -318,6 +335,7 @@ extractNumbers('abc123def456') // [123, 456]
|
|
|
318
335
|
- `maskIdCard(idCard)` - 身份证号脱敏
|
|
319
336
|
- `maskBankCard(cardNumber)` - 银行卡号脱敏
|
|
320
337
|
- `maskName(name)` - 姓名脱敏
|
|
338
|
+
- `maskString(str, visibleChars?, mask?)` - 通用字符串脱敏
|
|
321
339
|
|
|
322
340
|
### 格式验证
|
|
323
341
|
|
package/src/string/index.ts
CHANGED
|
@@ -428,6 +428,31 @@ export function maskName(name: string): string {
|
|
|
428
428
|
return name.charAt(0) + '*'.repeat(name.length - 2) + name.charAt(name.length - 1)
|
|
429
429
|
}
|
|
430
430
|
|
|
431
|
+
/**
|
|
432
|
+
* 通用字符串脱敏:保留前后指定位数,中间用省略号替换
|
|
433
|
+
* @param str 字符串
|
|
434
|
+
* @param visibleChars 前后各保留的字符数,默认 3
|
|
435
|
+
* @param mask 脱敏符号,默认 '...'
|
|
436
|
+
* @returns 脱敏后的字符串
|
|
437
|
+
* @example
|
|
438
|
+
* maskString('123wedwdwddwed567', 3) // '123...567'
|
|
439
|
+
* maskString('abcdefghijk', 2) // 'ab...jk'
|
|
440
|
+
* maskString('hello', 2, '***') // 'he***lo'
|
|
441
|
+
*/
|
|
442
|
+
export function maskString(str: string, visibleChars = 3, mask = '...'): string {
|
|
443
|
+
if (!str) return ''
|
|
444
|
+
|
|
445
|
+
// 如果字符串长度小于等于需要显示的字符数,直接返回原字符串
|
|
446
|
+
if (str.length <= visibleChars * 2) {
|
|
447
|
+
return str
|
|
448
|
+
}
|
|
449
|
+
|
|
450
|
+
const start = str.slice(0, visibleChars)
|
|
451
|
+
const end = str.slice(-visibleChars)
|
|
452
|
+
|
|
453
|
+
return `${start}${mask}${end}`
|
|
454
|
+
}
|
|
455
|
+
|
|
431
456
|
/**
|
|
432
457
|
* 判断是否为有效的手机号(中国大陆)
|
|
433
458
|
* @param phone 手机号
|