react-util-tools 1.0.25 → 1.0.27
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/README.md +38 -0
- package/dist/index.cjs +404 -78
- package/dist/index.d.cts +45 -1
- package/dist/index.d.ts +45 -1
- package/dist/index.js +359 -76
- package/package.json +1 -1
- package/src/format/index.ts +263 -102
- package/src/index.ts +45 -0
- package/src/string/README.md +441 -0
- package/src/string/index.ts +527 -0
package/dist/index.cjs
CHANGED
|
@@ -30,7 +30,7 @@ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: tru
|
|
|
30
30
|
// src/index.ts
|
|
31
31
|
var index_exports = {};
|
|
32
32
|
__export(index_exports, {
|
|
33
|
-
Decimal: () =>
|
|
33
|
+
Decimal: () => import_decimal2.default,
|
|
34
34
|
XLSX: () => XLSX,
|
|
35
35
|
abs: () => abs,
|
|
36
36
|
add: () => add,
|
|
@@ -39,13 +39,19 @@ __export(index_exports, {
|
|
|
39
39
|
addMonthsToDate: () => addMonthsToDate,
|
|
40
40
|
addMonthsUTC: () => addMonthsUTC,
|
|
41
41
|
aoaToSheet: () => aoaToSheet,
|
|
42
|
+
camelCase: () => camelCase,
|
|
43
|
+
capitalize: () => capitalize,
|
|
42
44
|
ceil: () => ceil,
|
|
43
45
|
clearAllCookies: () => clearAllCookies,
|
|
46
|
+
countOccurrences: () => countOccurrences,
|
|
44
47
|
debounce: () => debounceFn,
|
|
45
48
|
divide: () => divide,
|
|
49
|
+
endsWith: () => endsWith,
|
|
46
50
|
equals: () => equals,
|
|
51
|
+
escapeHtml: () => escapeHtml,
|
|
47
52
|
exportExcelFile: () => exportExcelFile,
|
|
48
53
|
exportJSONToExcel: () => exportJSONToExcel,
|
|
54
|
+
extractNumbers: () => extractNumbers,
|
|
49
55
|
floor: () => floor,
|
|
50
56
|
formatDate: () => formatDate,
|
|
51
57
|
formatDateOnly: () => formatDateOnly,
|
|
@@ -58,6 +64,7 @@ __export(index_exports, {
|
|
|
58
64
|
formatUTC: () => formatUTC,
|
|
59
65
|
formatUTCDateOnly: () => formatUTCDateOnly,
|
|
60
66
|
formatUTCTimeOnly: () => formatUTCTimeOnly,
|
|
67
|
+
fromBase64: () => fromBase64,
|
|
61
68
|
fromUTC: () => fromUTC,
|
|
62
69
|
getAllCookies: () => getAllCookies,
|
|
63
70
|
getAllQueryParams: () => getAllQueryParams,
|
|
@@ -112,35 +119,61 @@ __export(index_exports, {
|
|
|
112
119
|
greaterThan: () => greaterThan,
|
|
113
120
|
greaterThanOrEqual: () => greaterThanOrEqual,
|
|
114
121
|
hasCookie: () => hasCookie,
|
|
122
|
+
includes: () => includes,
|
|
115
123
|
isAfterDate: () => isAfterDate,
|
|
116
124
|
isAndroid: () => isAndroid,
|
|
117
125
|
isBeforeDate: () => isBeforeDate,
|
|
118
126
|
isDesktop: () => isDesktop,
|
|
127
|
+
isEmpty: () => isEmpty,
|
|
119
128
|
isIOS: () => isIOS,
|
|
120
129
|
isMobile: () => isMobile,
|
|
130
|
+
isNotEmpty: () => isNotEmpty,
|
|
121
131
|
isSameDayDate: () => isSameDayDate,
|
|
122
132
|
isTablet: () => isTablet,
|
|
123
133
|
isTouchDevice: () => isTouchDevice,
|
|
124
134
|
isValidDate: () => isValidDate,
|
|
135
|
+
isValidEmail: () => isValidEmail,
|
|
136
|
+
isValidIdCard: () => isValidIdCard,
|
|
137
|
+
isValidPhone: () => isValidPhone,
|
|
138
|
+
isValidUrl: () => isValidUrl,
|
|
125
139
|
isWeChat: () => isWeChat,
|
|
126
140
|
jsonToWorkbook: () => jsonToWorkbook,
|
|
141
|
+
kebabCase: () => kebabCase,
|
|
142
|
+
length: () => length,
|
|
127
143
|
lessThan: () => lessThan,
|
|
128
144
|
lessThanOrEqual: () => lessThanOrEqual,
|
|
145
|
+
maskBankCard: () => maskBankCard,
|
|
129
146
|
maskEmail: () => maskEmail,
|
|
147
|
+
maskIdCard: () => maskIdCard,
|
|
148
|
+
maskName: () => maskName,
|
|
149
|
+
maskPhone: () => maskPhone,
|
|
130
150
|
multiply: () => multiply,
|
|
131
151
|
negate: () => negate,
|
|
152
|
+
normalizeSpaces: () => normalizeSpaces,
|
|
153
|
+
padEnd: () => padEnd,
|
|
154
|
+
padStart: () => padStart,
|
|
132
155
|
parseDate: () => parseDate,
|
|
133
156
|
parseMoney: () => parseMoney,
|
|
157
|
+
pascalCase: () => pascalCase,
|
|
158
|
+
randomString: () => randomString,
|
|
134
159
|
read: () => read2,
|
|
135
160
|
readExcelFile: () => readExcelFile,
|
|
136
161
|
readExcelToJSON: () => readExcelToJSON,
|
|
137
162
|
readFile: () => readFile,
|
|
138
163
|
removeCookie: () => removeCookie,
|
|
164
|
+
removeSpaces: () => removeSpaces,
|
|
165
|
+
repeat: () => repeat,
|
|
166
|
+
replaceAll: () => replaceAll,
|
|
167
|
+
reverse: () => reverse,
|
|
139
168
|
round: () => round,
|
|
140
169
|
setCookie: () => setCookie,
|
|
141
170
|
sheetToAOA: () => sheetToAOA,
|
|
142
171
|
sheetToCSV: () => sheetToCSV,
|
|
143
172
|
sheetToHTML: () => sheetToHTML,
|
|
173
|
+
snakeCase: () => snakeCase,
|
|
174
|
+
split: () => split,
|
|
175
|
+
startsWith: () => startsWith,
|
|
176
|
+
stripHtml: () => stripHtml,
|
|
144
177
|
subDaysFromDate: () => subDaysFromDate,
|
|
145
178
|
subDaysUTC: () => subDaysUTC,
|
|
146
179
|
subMonthsFromDate: () => subMonthsFromDate,
|
|
@@ -148,10 +181,20 @@ __export(index_exports, {
|
|
|
148
181
|
subtract: () => subtract,
|
|
149
182
|
tableToSheet: () => tableToSheet,
|
|
150
183
|
throttle: () => throttleFn,
|
|
184
|
+
titleCase: () => titleCase,
|
|
185
|
+
toBase64: () => toBase64,
|
|
151
186
|
toISOString: () => toISOString,
|
|
187
|
+
toLowerCase: () => toLowerCase,
|
|
152
188
|
toUTC: () => toUTC,
|
|
189
|
+
toUpperCase: () => toUpperCase,
|
|
190
|
+
trim: () => trim,
|
|
191
|
+
trimEnd: () => trimEnd,
|
|
192
|
+
trimStart: () => trimStart,
|
|
193
|
+
truncate: () => truncate,
|
|
194
|
+
unescapeHtml: () => unescapeHtml,
|
|
153
195
|
unmaskEmail: () => unmaskEmail,
|
|
154
196
|
utils: () => utils2,
|
|
197
|
+
uuid: () => uuid,
|
|
155
198
|
workbookToJSON: () => workbookToJSON,
|
|
156
199
|
write: () => write,
|
|
157
200
|
writeFile: () => writeFile2,
|
|
@@ -421,6 +464,7 @@ function getDeviceInfo() {
|
|
|
421
464
|
}
|
|
422
465
|
|
|
423
466
|
// src/format/index.ts
|
|
467
|
+
var import_decimal = __toESM(require("decimal.js"), 1);
|
|
424
468
|
function formatMoney(amount, options = {}) {
|
|
425
469
|
const {
|
|
426
470
|
decimals = 2,
|
|
@@ -428,20 +472,19 @@ function formatMoney(amount, options = {}) {
|
|
|
428
472
|
separator = ",",
|
|
429
473
|
decimalPoint = "."
|
|
430
474
|
} = options;
|
|
431
|
-
|
|
432
|
-
|
|
433
|
-
|
|
434
|
-
|
|
435
|
-
|
|
436
|
-
|
|
437
|
-
|
|
438
|
-
|
|
439
|
-
|
|
440
|
-
|
|
441
|
-
|
|
442
|
-
|
|
443
|
-
}
|
|
444
|
-
return isNegative ? `-${result}` : result;
|
|
475
|
+
return tryRun(() => {
|
|
476
|
+
const dec = new import_decimal.default(amount);
|
|
477
|
+
const isNegative = dec.isNegative();
|
|
478
|
+
const absDec = dec.abs();
|
|
479
|
+
const fixed = absDec.toFixed(decimals, import_decimal.default.ROUND_DOWN);
|
|
480
|
+
const [integerPart, decimalPart] = fixed.split(".");
|
|
481
|
+
const formattedInteger = integerPart.replace(/\B(?=(\d{3})+(?!\d))/g, separator);
|
|
482
|
+
let result = symbol + formattedInteger;
|
|
483
|
+
if (decimals > 0 && decimalPart) {
|
|
484
|
+
result += decimalPoint + decimalPart;
|
|
485
|
+
}
|
|
486
|
+
return isNegative ? `-${result}` : result;
|
|
487
|
+
}) ?? `${symbol}0${decimalPoint}${"0".repeat(decimals)}`;
|
|
445
488
|
}
|
|
446
489
|
function parseMoney(formattedAmount) {
|
|
447
490
|
if (!formattedAmount || typeof formattedAmount !== "string") {
|
|
@@ -452,68 +495,70 @@ function parseMoney(formattedAmount) {
|
|
|
452
495
|
return isNaN(num) ? 0 : num;
|
|
453
496
|
}
|
|
454
497
|
function formatNumber(amount, decimals = 2) {
|
|
455
|
-
|
|
456
|
-
|
|
457
|
-
|
|
458
|
-
|
|
459
|
-
|
|
460
|
-
|
|
461
|
-
|
|
462
|
-
return decimals > 0 && decimalPart ? `${formattedInteger}.${decimalPart}` : formattedInteger;
|
|
498
|
+
return tryRun(() => {
|
|
499
|
+
const dec = new import_decimal.default(amount);
|
|
500
|
+
const fixed = dec.toFixed(decimals, import_decimal.default.ROUND_DOWN);
|
|
501
|
+
const [integerPart, decimalPart] = fixed.split(".");
|
|
502
|
+
const formattedInteger = integerPart.replace(/\B(?=(\d{3})+(?!\d))/g, ",");
|
|
503
|
+
return decimals > 0 && decimalPart ? `${formattedInteger}.${decimalPart}` : formattedInteger;
|
|
504
|
+
}) ?? "0." + "0".repeat(decimals);
|
|
463
505
|
}
|
|
464
506
|
function formatMoneyToChinese(amount) {
|
|
465
|
-
|
|
466
|
-
|
|
467
|
-
|
|
468
|
-
|
|
469
|
-
|
|
470
|
-
|
|
471
|
-
|
|
472
|
-
|
|
473
|
-
|
|
474
|
-
|
|
475
|
-
|
|
476
|
-
result = "
|
|
477
|
-
|
|
478
|
-
|
|
479
|
-
|
|
480
|
-
|
|
481
|
-
|
|
482
|
-
|
|
483
|
-
|
|
484
|
-
|
|
485
|
-
|
|
486
|
-
|
|
487
|
-
|
|
488
|
-
|
|
489
|
-
|
|
507
|
+
return tryRun(() => {
|
|
508
|
+
const dec = new import_decimal.default(amount);
|
|
509
|
+
if (dec.isNegative()) {
|
|
510
|
+
return "\u96F6\u5143\u6574";
|
|
511
|
+
}
|
|
512
|
+
const num = dec.toNumber();
|
|
513
|
+
const digits = ["\u96F6", "\u58F9", "\u8D30", "\u53C1", "\u8086", "\u4F0D", "\u9646", "\u67D2", "\u634C", "\u7396"];
|
|
514
|
+
const units = ["", "\u62FE", "\u4F70", "\u4EDF"];
|
|
515
|
+
const bigUnits = ["", "\u4E07", "\u4EBF", "\u5146"];
|
|
516
|
+
const decimalUnits = ["\u89D2", "\u5206"];
|
|
517
|
+
const [integerPart, decimalPart] = num.toFixed(2).split(".");
|
|
518
|
+
let result = "";
|
|
519
|
+
if (integerPart === "0") {
|
|
520
|
+
result = "\u96F6\u5143";
|
|
521
|
+
} else {
|
|
522
|
+
const integerStr = integerPart;
|
|
523
|
+
const len = integerStr.length;
|
|
524
|
+
let zeroCount = 0;
|
|
525
|
+
for (let i = 0; i < len; i++) {
|
|
526
|
+
const digit = parseInt(integerStr[i]);
|
|
527
|
+
const unitIndex = (len - i - 1) % 4;
|
|
528
|
+
const bigUnitIndex = Math.floor((len - i - 1) / 4);
|
|
529
|
+
if (digit === 0) {
|
|
530
|
+
zeroCount++;
|
|
531
|
+
} else {
|
|
532
|
+
if (zeroCount > 0) {
|
|
533
|
+
result += "\u96F6";
|
|
534
|
+
}
|
|
535
|
+
result += digits[digit] + units[unitIndex];
|
|
536
|
+
zeroCount = 0;
|
|
490
537
|
}
|
|
491
|
-
|
|
492
|
-
|
|
493
|
-
|
|
494
|
-
|
|
495
|
-
if (result[result.length - 1] !== bigUnits[bigUnitIndex]) {
|
|
496
|
-
result += bigUnits[bigUnitIndex];
|
|
538
|
+
if (unitIndex === 0 && bigUnitIndex > 0) {
|
|
539
|
+
if (result[result.length - 1] !== bigUnits[bigUnitIndex]) {
|
|
540
|
+
result += bigUnits[bigUnitIndex];
|
|
541
|
+
}
|
|
497
542
|
}
|
|
498
543
|
}
|
|
544
|
+
result += "\u5143";
|
|
499
545
|
}
|
|
500
|
-
|
|
501
|
-
|
|
502
|
-
|
|
503
|
-
|
|
504
|
-
|
|
505
|
-
|
|
506
|
-
|
|
507
|
-
|
|
508
|
-
|
|
509
|
-
|
|
510
|
-
|
|
511
|
-
|
|
546
|
+
if (decimalPart && decimalPart !== "00") {
|
|
547
|
+
const jiao = parseInt(decimalPart[0]);
|
|
548
|
+
const fen = parseInt(decimalPart[1]);
|
|
549
|
+
if (jiao > 0) {
|
|
550
|
+
result += digits[jiao] + decimalUnits[0];
|
|
551
|
+
} else if (fen > 0) {
|
|
552
|
+
result += "\u96F6";
|
|
553
|
+
}
|
|
554
|
+
if (fen > 0) {
|
|
555
|
+
result += digits[fen] + decimalUnits[1];
|
|
556
|
+
}
|
|
557
|
+
} else {
|
|
558
|
+
result += "\u6574";
|
|
512
559
|
}
|
|
513
|
-
|
|
514
|
-
|
|
515
|
-
}
|
|
516
|
-
return result;
|
|
560
|
+
return result;
|
|
561
|
+
}) ?? "\u96F6\u5143\u6574";
|
|
517
562
|
}
|
|
518
563
|
function formatPercent(value, options = {}) {
|
|
519
564
|
const { decimals = 2, multiply: multiply2 = true } = options;
|
|
@@ -556,6 +601,13 @@ function unmaskEmail(maskedEmail, originalEmail) {
|
|
|
556
601
|
}
|
|
557
602
|
return maskedEmail;
|
|
558
603
|
}
|
|
604
|
+
function tryRun(fn) {
|
|
605
|
+
try {
|
|
606
|
+
return fn();
|
|
607
|
+
} catch (error) {
|
|
608
|
+
return null;
|
|
609
|
+
}
|
|
610
|
+
}
|
|
559
611
|
|
|
560
612
|
// src/date/index.ts
|
|
561
613
|
var import_date_fns = require("date-fns");
|
|
@@ -819,22 +871,22 @@ function getUTCWeekNumber(date) {
|
|
|
819
871
|
}
|
|
820
872
|
|
|
821
873
|
// src/decimal/index.ts
|
|
822
|
-
var
|
|
874
|
+
var import_decimal2 = __toESM(require("decimal.js"), 1);
|
|
823
875
|
|
|
824
876
|
// src/decimal/utils/index.ts
|
|
825
|
-
var
|
|
877
|
+
var import_decimal3 = __toESM(require("decimal.js"), 1);
|
|
826
878
|
function safeDecimal(value) {
|
|
827
879
|
try {
|
|
828
|
-
if (value instanceof
|
|
880
|
+
if (value instanceof import_decimal3.default) {
|
|
829
881
|
return value;
|
|
830
882
|
}
|
|
831
|
-
const decimal = new
|
|
883
|
+
const decimal = new import_decimal3.default(value);
|
|
832
884
|
if (decimal.isNaN()) {
|
|
833
|
-
return new
|
|
885
|
+
return new import_decimal3.default(0);
|
|
834
886
|
}
|
|
835
887
|
return decimal;
|
|
836
888
|
} catch {
|
|
837
|
-
return new
|
|
889
|
+
return new import_decimal3.default(0);
|
|
838
890
|
}
|
|
839
891
|
}
|
|
840
892
|
function add(a, b) {
|
|
@@ -932,7 +984,7 @@ function round(value, decimalPlaces = 2) {
|
|
|
932
984
|
function ceil(value, decimalPlaces = 2) {
|
|
933
985
|
try {
|
|
934
986
|
const decimal = safeDecimal(value);
|
|
935
|
-
return decimal.toDecimalPlaces(decimalPlaces,
|
|
987
|
+
return decimal.toDecimalPlaces(decimalPlaces, import_decimal3.default.ROUND_CEIL).toNumber();
|
|
936
988
|
} catch {
|
|
937
989
|
return 0;
|
|
938
990
|
}
|
|
@@ -940,7 +992,7 @@ function ceil(value, decimalPlaces = 2) {
|
|
|
940
992
|
function floor(value, decimalPlaces = 2) {
|
|
941
993
|
try {
|
|
942
994
|
const decimal = safeDecimal(value);
|
|
943
|
-
return decimal.toDecimalPlaces(decimalPlaces,
|
|
995
|
+
return decimal.toDecimalPlaces(decimalPlaces, import_decimal3.default.ROUND_FLOOR).toNumber();
|
|
944
996
|
} catch {
|
|
945
997
|
return 0;
|
|
946
998
|
}
|
|
@@ -1039,6 +1091,237 @@ function aoaToSheet(data, options) {
|
|
|
1039
1091
|
function sheetToAOA(worksheet, options) {
|
|
1040
1092
|
return XLSX.utils.sheet_to_json(worksheet, { ...options, header: 1 });
|
|
1041
1093
|
}
|
|
1094
|
+
|
|
1095
|
+
// src/string/index.ts
|
|
1096
|
+
function capitalize(str) {
|
|
1097
|
+
if (!str) return "";
|
|
1098
|
+
return str.charAt(0).toUpperCase() + str.slice(1).toLowerCase();
|
|
1099
|
+
}
|
|
1100
|
+
function camelCase(str) {
|
|
1101
|
+
if (!str) return "";
|
|
1102
|
+
return str.replace(/[-_\s]+(.)?/g, (_, char) => char ? char.toUpperCase() : "").replace(/^[A-Z]/, (char) => char.toLowerCase());
|
|
1103
|
+
}
|
|
1104
|
+
function pascalCase(str) {
|
|
1105
|
+
if (!str) return "";
|
|
1106
|
+
const camel = camelCase(str);
|
|
1107
|
+
return camel.charAt(0).toUpperCase() + camel.slice(1);
|
|
1108
|
+
}
|
|
1109
|
+
function snakeCase(str) {
|
|
1110
|
+
if (!str) return "";
|
|
1111
|
+
return str.replace(/([A-Z])/g, "_$1").replace(/[-\s]+/g, "_").replace(/^_/, "").toLowerCase();
|
|
1112
|
+
}
|
|
1113
|
+
function kebabCase(str) {
|
|
1114
|
+
if (!str) return "";
|
|
1115
|
+
return str.replace(/([A-Z])/g, "-$1").replace(/[_\s]+/g, "-").replace(/^-/, "").toLowerCase();
|
|
1116
|
+
}
|
|
1117
|
+
function truncate(str, length2, suffix = "...") {
|
|
1118
|
+
if (!str || str.length <= length2) return str;
|
|
1119
|
+
return str.slice(0, length2) + suffix;
|
|
1120
|
+
}
|
|
1121
|
+
function trim(str) {
|
|
1122
|
+
return str ? str.trim() : "";
|
|
1123
|
+
}
|
|
1124
|
+
function trimStart(str) {
|
|
1125
|
+
return str ? str.trimStart() : "";
|
|
1126
|
+
}
|
|
1127
|
+
function trimEnd(str) {
|
|
1128
|
+
return str ? str.trimEnd() : "";
|
|
1129
|
+
}
|
|
1130
|
+
function reverse(str) {
|
|
1131
|
+
if (!str) return "";
|
|
1132
|
+
return str.split("").reverse().join("");
|
|
1133
|
+
}
|
|
1134
|
+
function repeat(str, count) {
|
|
1135
|
+
if (!str || count <= 0) return "";
|
|
1136
|
+
return str.repeat(count);
|
|
1137
|
+
}
|
|
1138
|
+
function padStart(str, length2, padStr = " ") {
|
|
1139
|
+
if (!str) return padStr.repeat(length2);
|
|
1140
|
+
return str.padStart(length2, padStr);
|
|
1141
|
+
}
|
|
1142
|
+
function padEnd(str, length2, padStr = " ") {
|
|
1143
|
+
if (!str) return padStr.repeat(length2);
|
|
1144
|
+
return str.padEnd(length2, padStr);
|
|
1145
|
+
}
|
|
1146
|
+
function startsWith(str, searchString) {
|
|
1147
|
+
if (!str) return false;
|
|
1148
|
+
return str.startsWith(searchString);
|
|
1149
|
+
}
|
|
1150
|
+
function endsWith(str, searchString) {
|
|
1151
|
+
if (!str) return false;
|
|
1152
|
+
return str.endsWith(searchString);
|
|
1153
|
+
}
|
|
1154
|
+
function includes(str, searchString) {
|
|
1155
|
+
if (!str) return false;
|
|
1156
|
+
return str.includes(searchString);
|
|
1157
|
+
}
|
|
1158
|
+
function replaceAll(str, search, replacement) {
|
|
1159
|
+
if (!str) return "";
|
|
1160
|
+
if (typeof search === "string") {
|
|
1161
|
+
return str.split(search).join(replacement);
|
|
1162
|
+
}
|
|
1163
|
+
return str.replace(search, replacement);
|
|
1164
|
+
}
|
|
1165
|
+
function stripHtml(str) {
|
|
1166
|
+
if (!str) return "";
|
|
1167
|
+
return str.replace(/<[^>]*>/g, "");
|
|
1168
|
+
}
|
|
1169
|
+
function escapeHtml(str) {
|
|
1170
|
+
if (!str) return "";
|
|
1171
|
+
const map = {
|
|
1172
|
+
"&": "&",
|
|
1173
|
+
"<": "<",
|
|
1174
|
+
">": ">",
|
|
1175
|
+
'"': """,
|
|
1176
|
+
"'": "'"
|
|
1177
|
+
};
|
|
1178
|
+
return str.replace(/[&<>"']/g, (char) => map[char]);
|
|
1179
|
+
}
|
|
1180
|
+
function unescapeHtml(str) {
|
|
1181
|
+
if (!str) return "";
|
|
1182
|
+
const map = {
|
|
1183
|
+
"&": "&",
|
|
1184
|
+
"<": "<",
|
|
1185
|
+
">": ">",
|
|
1186
|
+
""": '"',
|
|
1187
|
+
"'": "'"
|
|
1188
|
+
};
|
|
1189
|
+
return str.replace(/&(amp|lt|gt|quot|#39);/g, (entity) => map[entity]);
|
|
1190
|
+
}
|
|
1191
|
+
function toLowerCase(str) {
|
|
1192
|
+
return str ? str.toLowerCase() : "";
|
|
1193
|
+
}
|
|
1194
|
+
function toUpperCase(str) {
|
|
1195
|
+
return str ? str.toUpperCase() : "";
|
|
1196
|
+
}
|
|
1197
|
+
function titleCase(str) {
|
|
1198
|
+
if (!str) return "";
|
|
1199
|
+
return str.toLowerCase().split(" ").map((word) => word.charAt(0).toUpperCase() + word.slice(1)).join(" ");
|
|
1200
|
+
}
|
|
1201
|
+
function isEmpty(str) {
|
|
1202
|
+
return !str || str.trim().length === 0;
|
|
1203
|
+
}
|
|
1204
|
+
function isNotEmpty(str) {
|
|
1205
|
+
return !isEmpty(str);
|
|
1206
|
+
}
|
|
1207
|
+
function length(str) {
|
|
1208
|
+
if (!str) return 0;
|
|
1209
|
+
return Array.from(str).length;
|
|
1210
|
+
}
|
|
1211
|
+
function split(str, separator) {
|
|
1212
|
+
if (!str) return [];
|
|
1213
|
+
return str.split(separator);
|
|
1214
|
+
}
|
|
1215
|
+
function extractNumbers(str) {
|
|
1216
|
+
if (!str) return [];
|
|
1217
|
+
const matches = str.match(/\d+(\.\d+)?/g);
|
|
1218
|
+
return matches ? matches.map(Number) : [];
|
|
1219
|
+
}
|
|
1220
|
+
function removeSpaces(str) {
|
|
1221
|
+
if (!str) return "";
|
|
1222
|
+
return str.replace(/\s+/g, "");
|
|
1223
|
+
}
|
|
1224
|
+
function normalizeSpaces(str) {
|
|
1225
|
+
if (!str) return "";
|
|
1226
|
+
return str.replace(/\s+/g, " ").trim();
|
|
1227
|
+
}
|
|
1228
|
+
function countOccurrences(str, searchString) {
|
|
1229
|
+
if (!str || !searchString) return 0;
|
|
1230
|
+
return str.split(searchString).length - 1;
|
|
1231
|
+
}
|
|
1232
|
+
function randomString(length2, chars = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789") {
|
|
1233
|
+
let result = "";
|
|
1234
|
+
for (let i = 0; i < length2; i++) {
|
|
1235
|
+
result += chars.charAt(Math.floor(Math.random() * chars.length));
|
|
1236
|
+
}
|
|
1237
|
+
return result;
|
|
1238
|
+
}
|
|
1239
|
+
function uuid() {
|
|
1240
|
+
return "xxxxxxxx-xxxx-4xxx-yxxx-xxxxxxxxxxxx".replace(/[xy]/g, (c) => {
|
|
1241
|
+
const r = Math.random() * 16 | 0;
|
|
1242
|
+
const v = c === "x" ? r : r & 3 | 8;
|
|
1243
|
+
return v.toString(16);
|
|
1244
|
+
});
|
|
1245
|
+
}
|
|
1246
|
+
function maskPhone(phone) {
|
|
1247
|
+
if (!phone || phone.length < 11) return phone;
|
|
1248
|
+
return phone.replace(/(\d{3})\d{4}(\d{4})/, "$1****$2");
|
|
1249
|
+
}
|
|
1250
|
+
function maskIdCard(idCard) {
|
|
1251
|
+
if (!idCard || idCard.length < 18) return idCard;
|
|
1252
|
+
return idCard.replace(/(\d{6})\d{8}(\d{4})/, "$1********$2");
|
|
1253
|
+
}
|
|
1254
|
+
function maskBankCard(cardNumber) {
|
|
1255
|
+
if (!cardNumber || cardNumber.length < 16) return cardNumber;
|
|
1256
|
+
return cardNumber.replace(/(\d{4})\d+(\d{4})/, "$1 **** **** $2");
|
|
1257
|
+
}
|
|
1258
|
+
function maskName(name) {
|
|
1259
|
+
if (!name) return "";
|
|
1260
|
+
if (name.length === 2) {
|
|
1261
|
+
return name.charAt(0) + "*";
|
|
1262
|
+
}
|
|
1263
|
+
return name.charAt(0) + "*".repeat(name.length - 2) + name.charAt(name.length - 1);
|
|
1264
|
+
}
|
|
1265
|
+
function isValidPhone(phone) {
|
|
1266
|
+
if (!phone) return false;
|
|
1267
|
+
return /^1[3-9]\d{9}$/.test(phone);
|
|
1268
|
+
}
|
|
1269
|
+
function isValidEmail(email) {
|
|
1270
|
+
if (!email) return false;
|
|
1271
|
+
return /^[^\s@]+@[^\s@]+\.[^\s@]+$/.test(email);
|
|
1272
|
+
}
|
|
1273
|
+
function isValidUrl(url) {
|
|
1274
|
+
if (!url) return false;
|
|
1275
|
+
try {
|
|
1276
|
+
new URL(url);
|
|
1277
|
+
return true;
|
|
1278
|
+
} catch {
|
|
1279
|
+
return false;
|
|
1280
|
+
}
|
|
1281
|
+
}
|
|
1282
|
+
function isValidIdCard(idCard) {
|
|
1283
|
+
if (!idCard) return false;
|
|
1284
|
+
return /(^\d{15}$)|(^\d{18}$)|(^\d{17}(\d|X|x)$)/.test(idCard);
|
|
1285
|
+
}
|
|
1286
|
+
function toBase64(str) {
|
|
1287
|
+
if (!str) return "";
|
|
1288
|
+
if (typeof window !== "undefined" && window.btoa) {
|
|
1289
|
+
try {
|
|
1290
|
+
return window.btoa(encodeURIComponent(str).replace(/%([0-9A-F]{2})/g, (_, p1) => {
|
|
1291
|
+
return String.fromCharCode(parseInt(p1, 16));
|
|
1292
|
+
}));
|
|
1293
|
+
} catch {
|
|
1294
|
+
return "";
|
|
1295
|
+
}
|
|
1296
|
+
}
|
|
1297
|
+
try {
|
|
1298
|
+
const BufferClass = globalThis.Buffer;
|
|
1299
|
+
return BufferClass ? BufferClass.from(str, "utf-8").toString("base64") : "";
|
|
1300
|
+
} catch {
|
|
1301
|
+
return "";
|
|
1302
|
+
}
|
|
1303
|
+
}
|
|
1304
|
+
function fromBase64(base64) {
|
|
1305
|
+
if (!base64) return "";
|
|
1306
|
+
if (typeof window !== "undefined" && window.atob) {
|
|
1307
|
+
try {
|
|
1308
|
+
const binary = window.atob(base64);
|
|
1309
|
+
const bytes = new Uint8Array(binary.length);
|
|
1310
|
+
for (let i = 0; i < binary.length; i++) {
|
|
1311
|
+
bytes[i] = binary.charCodeAt(i);
|
|
1312
|
+
}
|
|
1313
|
+
return new TextDecoder().decode(bytes);
|
|
1314
|
+
} catch {
|
|
1315
|
+
return "";
|
|
1316
|
+
}
|
|
1317
|
+
}
|
|
1318
|
+
try {
|
|
1319
|
+
const BufferClass = globalThis.Buffer;
|
|
1320
|
+
return BufferClass ? BufferClass.from(base64, "base64").toString("utf-8") : "";
|
|
1321
|
+
} catch {
|
|
1322
|
+
return "";
|
|
1323
|
+
}
|
|
1324
|
+
}
|
|
1042
1325
|
// Annotate the CommonJS export names for ESM import in node:
|
|
1043
1326
|
0 && (module.exports = {
|
|
1044
1327
|
Decimal,
|
|
@@ -1050,13 +1333,19 @@ function sheetToAOA(worksheet, options) {
|
|
|
1050
1333
|
addMonthsToDate,
|
|
1051
1334
|
addMonthsUTC,
|
|
1052
1335
|
aoaToSheet,
|
|
1336
|
+
camelCase,
|
|
1337
|
+
capitalize,
|
|
1053
1338
|
ceil,
|
|
1054
1339
|
clearAllCookies,
|
|
1340
|
+
countOccurrences,
|
|
1055
1341
|
debounce,
|
|
1056
1342
|
divide,
|
|
1343
|
+
endsWith,
|
|
1057
1344
|
equals,
|
|
1345
|
+
escapeHtml,
|
|
1058
1346
|
exportExcelFile,
|
|
1059
1347
|
exportJSONToExcel,
|
|
1348
|
+
extractNumbers,
|
|
1060
1349
|
floor,
|
|
1061
1350
|
formatDate,
|
|
1062
1351
|
formatDateOnly,
|
|
@@ -1069,6 +1358,7 @@ function sheetToAOA(worksheet, options) {
|
|
|
1069
1358
|
formatUTC,
|
|
1070
1359
|
formatUTCDateOnly,
|
|
1071
1360
|
formatUTCTimeOnly,
|
|
1361
|
+
fromBase64,
|
|
1072
1362
|
fromUTC,
|
|
1073
1363
|
getAllCookies,
|
|
1074
1364
|
getAllQueryParams,
|
|
@@ -1123,35 +1413,61 @@ function sheetToAOA(worksheet, options) {
|
|
|
1123
1413
|
greaterThan,
|
|
1124
1414
|
greaterThanOrEqual,
|
|
1125
1415
|
hasCookie,
|
|
1416
|
+
includes,
|
|
1126
1417
|
isAfterDate,
|
|
1127
1418
|
isAndroid,
|
|
1128
1419
|
isBeforeDate,
|
|
1129
1420
|
isDesktop,
|
|
1421
|
+
isEmpty,
|
|
1130
1422
|
isIOS,
|
|
1131
1423
|
isMobile,
|
|
1424
|
+
isNotEmpty,
|
|
1132
1425
|
isSameDayDate,
|
|
1133
1426
|
isTablet,
|
|
1134
1427
|
isTouchDevice,
|
|
1135
1428
|
isValidDate,
|
|
1429
|
+
isValidEmail,
|
|
1430
|
+
isValidIdCard,
|
|
1431
|
+
isValidPhone,
|
|
1432
|
+
isValidUrl,
|
|
1136
1433
|
isWeChat,
|
|
1137
1434
|
jsonToWorkbook,
|
|
1435
|
+
kebabCase,
|
|
1436
|
+
length,
|
|
1138
1437
|
lessThan,
|
|
1139
1438
|
lessThanOrEqual,
|
|
1439
|
+
maskBankCard,
|
|
1140
1440
|
maskEmail,
|
|
1441
|
+
maskIdCard,
|
|
1442
|
+
maskName,
|
|
1443
|
+
maskPhone,
|
|
1141
1444
|
multiply,
|
|
1142
1445
|
negate,
|
|
1446
|
+
normalizeSpaces,
|
|
1447
|
+
padEnd,
|
|
1448
|
+
padStart,
|
|
1143
1449
|
parseDate,
|
|
1144
1450
|
parseMoney,
|
|
1451
|
+
pascalCase,
|
|
1452
|
+
randomString,
|
|
1145
1453
|
read,
|
|
1146
1454
|
readExcelFile,
|
|
1147
1455
|
readExcelToJSON,
|
|
1148
1456
|
readFile,
|
|
1149
1457
|
removeCookie,
|
|
1458
|
+
removeSpaces,
|
|
1459
|
+
repeat,
|
|
1460
|
+
replaceAll,
|
|
1461
|
+
reverse,
|
|
1150
1462
|
round,
|
|
1151
1463
|
setCookie,
|
|
1152
1464
|
sheetToAOA,
|
|
1153
1465
|
sheetToCSV,
|
|
1154
1466
|
sheetToHTML,
|
|
1467
|
+
snakeCase,
|
|
1468
|
+
split,
|
|
1469
|
+
startsWith,
|
|
1470
|
+
stripHtml,
|
|
1155
1471
|
subDaysFromDate,
|
|
1156
1472
|
subDaysUTC,
|
|
1157
1473
|
subMonthsFromDate,
|
|
@@ -1159,10 +1475,20 @@ function sheetToAOA(worksheet, options) {
|
|
|
1159
1475
|
subtract,
|
|
1160
1476
|
tableToSheet,
|
|
1161
1477
|
throttle,
|
|
1478
|
+
titleCase,
|
|
1479
|
+
toBase64,
|
|
1162
1480
|
toISOString,
|
|
1481
|
+
toLowerCase,
|
|
1163
1482
|
toUTC,
|
|
1483
|
+
toUpperCase,
|
|
1484
|
+
trim,
|
|
1485
|
+
trimEnd,
|
|
1486
|
+
trimStart,
|
|
1487
|
+
truncate,
|
|
1488
|
+
unescapeHtml,
|
|
1164
1489
|
unmaskEmail,
|
|
1165
1490
|
utils,
|
|
1491
|
+
uuid,
|
|
1166
1492
|
workbookToJSON,
|
|
1167
1493
|
write,
|
|
1168
1494
|
writeFile,
|