react-util-tools 1.0.24 → 1.0.26
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 +128 -3
- package/dist/index.cjs +437 -2
- package/dist/index.d.cts +68 -1
- package/dist/index.d.ts +68 -1
- package/dist/index.js +373 -1
- package/package.json +8 -3
- package/src/excel/README.md +388 -0
- package/src/excel/example.md +425 -0
- package/src/excel/index.ts +245 -0
- package/src/index.ts +78 -0
- package/src/string/README.md +441 -0
- package/src/string/index.ts +527 -0
package/dist/index.cjs
CHANGED
|
@@ -31,17 +31,27 @@ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: tru
|
|
|
31
31
|
var index_exports = {};
|
|
32
32
|
__export(index_exports, {
|
|
33
33
|
Decimal: () => import_decimal.default,
|
|
34
|
+
XLSX: () => XLSX,
|
|
34
35
|
abs: () => abs,
|
|
35
36
|
add: () => add,
|
|
36
37
|
addDaysToDate: () => addDaysToDate,
|
|
37
38
|
addDaysUTC: () => addDaysUTC,
|
|
38
39
|
addMonthsToDate: () => addMonthsToDate,
|
|
39
40
|
addMonthsUTC: () => addMonthsUTC,
|
|
41
|
+
aoaToSheet: () => aoaToSheet,
|
|
42
|
+
camelCase: () => camelCase,
|
|
43
|
+
capitalize: () => capitalize,
|
|
40
44
|
ceil: () => ceil,
|
|
41
45
|
clearAllCookies: () => clearAllCookies,
|
|
46
|
+
countOccurrences: () => countOccurrences,
|
|
42
47
|
debounce: () => debounceFn,
|
|
43
48
|
divide: () => divide,
|
|
49
|
+
endsWith: () => endsWith,
|
|
44
50
|
equals: () => equals,
|
|
51
|
+
escapeHtml: () => escapeHtml,
|
|
52
|
+
exportExcelFile: () => exportExcelFile,
|
|
53
|
+
exportJSONToExcel: () => exportJSONToExcel,
|
|
54
|
+
extractNumbers: () => extractNumbers,
|
|
45
55
|
floor: () => floor,
|
|
46
56
|
formatDate: () => formatDate,
|
|
47
57
|
formatDateOnly: () => formatDateOnly,
|
|
@@ -54,6 +64,7 @@ __export(index_exports, {
|
|
|
54
64
|
formatUTC: () => formatUTC,
|
|
55
65
|
formatUTCDateOnly: () => formatUTCDateOnly,
|
|
56
66
|
formatUTCTimeOnly: () => formatUTCTimeOnly,
|
|
67
|
+
fromBase64: () => fromBase64,
|
|
57
68
|
fromUTC: () => fromUTC,
|
|
58
69
|
getAllCookies: () => getAllCookies,
|
|
59
70
|
getAllQueryParams: () => getAllQueryParams,
|
|
@@ -75,6 +86,8 @@ __export(index_exports, {
|
|
|
75
86
|
getQueryParam: () => getQueryParam,
|
|
76
87
|
getQueryParamAll: () => getQueryParamAll,
|
|
77
88
|
getScreenResolution: () => getScreenResolution,
|
|
89
|
+
getSheet: () => getSheet,
|
|
90
|
+
getSheetNames: () => getSheetNames,
|
|
78
91
|
getStartOfDay: () => getStartOfDay,
|
|
79
92
|
getStartOfMonth: () => getStartOfMonth,
|
|
80
93
|
getStartOfWeek: () => getStartOfWeek,
|
|
@@ -106,36 +119,86 @@ __export(index_exports, {
|
|
|
106
119
|
greaterThan: () => greaterThan,
|
|
107
120
|
greaterThanOrEqual: () => greaterThanOrEqual,
|
|
108
121
|
hasCookie: () => hasCookie,
|
|
122
|
+
includes: () => includes,
|
|
109
123
|
isAfterDate: () => isAfterDate,
|
|
110
124
|
isAndroid: () => isAndroid,
|
|
111
125
|
isBeforeDate: () => isBeforeDate,
|
|
112
126
|
isDesktop: () => isDesktop,
|
|
127
|
+
isEmpty: () => isEmpty,
|
|
113
128
|
isIOS: () => isIOS,
|
|
114
129
|
isMobile: () => isMobile,
|
|
130
|
+
isNotEmpty: () => isNotEmpty,
|
|
115
131
|
isSameDayDate: () => isSameDayDate,
|
|
116
132
|
isTablet: () => isTablet,
|
|
117
133
|
isTouchDevice: () => isTouchDevice,
|
|
118
134
|
isValidDate: () => isValidDate,
|
|
135
|
+
isValidEmail: () => isValidEmail,
|
|
136
|
+
isValidIdCard: () => isValidIdCard,
|
|
137
|
+
isValidPhone: () => isValidPhone,
|
|
138
|
+
isValidUrl: () => isValidUrl,
|
|
119
139
|
isWeChat: () => isWeChat,
|
|
140
|
+
jsonToWorkbook: () => jsonToWorkbook,
|
|
141
|
+
kebabCase: () => kebabCase,
|
|
142
|
+
length: () => length,
|
|
120
143
|
lessThan: () => lessThan,
|
|
121
144
|
lessThanOrEqual: () => lessThanOrEqual,
|
|
145
|
+
maskBankCard: () => maskBankCard,
|
|
122
146
|
maskEmail: () => maskEmail,
|
|
147
|
+
maskIdCard: () => maskIdCard,
|
|
148
|
+
maskName: () => maskName,
|
|
149
|
+
maskPhone: () => maskPhone,
|
|
123
150
|
multiply: () => multiply,
|
|
124
151
|
negate: () => negate,
|
|
152
|
+
normalizeSpaces: () => normalizeSpaces,
|
|
153
|
+
padEnd: () => padEnd,
|
|
154
|
+
padStart: () => padStart,
|
|
125
155
|
parseDate: () => parseDate,
|
|
126
156
|
parseMoney: () => parseMoney,
|
|
157
|
+
pascalCase: () => pascalCase,
|
|
158
|
+
randomString: () => randomString,
|
|
159
|
+
read: () => read2,
|
|
160
|
+
readExcelFile: () => readExcelFile,
|
|
161
|
+
readExcelToJSON: () => readExcelToJSON,
|
|
162
|
+
readFile: () => readFile,
|
|
127
163
|
removeCookie: () => removeCookie,
|
|
164
|
+
removeSpaces: () => removeSpaces,
|
|
165
|
+
repeat: () => repeat,
|
|
166
|
+
replaceAll: () => replaceAll,
|
|
167
|
+
reverse: () => reverse,
|
|
128
168
|
round: () => round,
|
|
129
169
|
setCookie: () => setCookie,
|
|
170
|
+
sheetToAOA: () => sheetToAOA,
|
|
171
|
+
sheetToCSV: () => sheetToCSV,
|
|
172
|
+
sheetToHTML: () => sheetToHTML,
|
|
173
|
+
snakeCase: () => snakeCase,
|
|
174
|
+
split: () => split,
|
|
175
|
+
startsWith: () => startsWith,
|
|
176
|
+
stripHtml: () => stripHtml,
|
|
130
177
|
subDaysFromDate: () => subDaysFromDate,
|
|
131
178
|
subDaysUTC: () => subDaysUTC,
|
|
132
179
|
subMonthsFromDate: () => subMonthsFromDate,
|
|
133
180
|
subMonthsUTC: () => subMonthsUTC,
|
|
134
181
|
subtract: () => subtract,
|
|
182
|
+
tableToSheet: () => tableToSheet,
|
|
135
183
|
throttle: () => throttleFn,
|
|
184
|
+
titleCase: () => titleCase,
|
|
185
|
+
toBase64: () => toBase64,
|
|
136
186
|
toISOString: () => toISOString,
|
|
187
|
+
toLowerCase: () => toLowerCase,
|
|
137
188
|
toUTC: () => toUTC,
|
|
138
|
-
|
|
189
|
+
toUpperCase: () => toUpperCase,
|
|
190
|
+
trim: () => trim,
|
|
191
|
+
trimEnd: () => trimEnd,
|
|
192
|
+
trimStart: () => trimStart,
|
|
193
|
+
truncate: () => truncate,
|
|
194
|
+
unescapeHtml: () => unescapeHtml,
|
|
195
|
+
unmaskEmail: () => unmaskEmail,
|
|
196
|
+
utils: () => utils2,
|
|
197
|
+
uuid: () => uuid,
|
|
198
|
+
workbookToJSON: () => workbookToJSON,
|
|
199
|
+
write: () => write,
|
|
200
|
+
writeFile: () => writeFile2,
|
|
201
|
+
writeFileXLSX: () => writeFileXLSX
|
|
139
202
|
});
|
|
140
203
|
module.exports = __toCommonJS(index_exports);
|
|
141
204
|
|
|
@@ -941,20 +1004,339 @@ function negate(value) {
|
|
|
941
1004
|
return 0;
|
|
942
1005
|
}
|
|
943
1006
|
}
|
|
1007
|
+
|
|
1008
|
+
// src/excel/index.ts
|
|
1009
|
+
var XLSX = __toESM(require("xlsx"), 1);
|
|
1010
|
+
var {
|
|
1011
|
+
read: read2,
|
|
1012
|
+
readFile,
|
|
1013
|
+
write,
|
|
1014
|
+
writeFile: writeFile2,
|
|
1015
|
+
writeFileXLSX,
|
|
1016
|
+
utils: utils2
|
|
1017
|
+
} = XLSX;
|
|
1018
|
+
function readExcelFile(file, options) {
|
|
1019
|
+
return new Promise((resolve, reject) => {
|
|
1020
|
+
const reader = new FileReader();
|
|
1021
|
+
reader.onload = (e) => {
|
|
1022
|
+
try {
|
|
1023
|
+
const data = e.target?.result;
|
|
1024
|
+
const workbook = XLSX.read(data, options);
|
|
1025
|
+
resolve(workbook);
|
|
1026
|
+
} catch (error) {
|
|
1027
|
+
reject(error);
|
|
1028
|
+
}
|
|
1029
|
+
};
|
|
1030
|
+
reader.onerror = () => {
|
|
1031
|
+
reject(new Error("Failed to read file"));
|
|
1032
|
+
};
|
|
1033
|
+
reader.readAsArrayBuffer(file);
|
|
1034
|
+
});
|
|
1035
|
+
}
|
|
1036
|
+
function workbookToJSON(workbook, sheetName, options) {
|
|
1037
|
+
const sheet = sheetName ? workbook.Sheets[sheetName] : workbook.Sheets[workbook.SheetNames[0]];
|
|
1038
|
+
if (!sheet) {
|
|
1039
|
+
throw new Error(`Sheet "${sheetName}" not found`);
|
|
1040
|
+
}
|
|
1041
|
+
return XLSX.utils.sheet_to_json(sheet, options);
|
|
1042
|
+
}
|
|
1043
|
+
function jsonToWorkbook(data, sheetName = "Sheet1", options) {
|
|
1044
|
+
const worksheet = XLSX.utils.json_to_sheet(data, options);
|
|
1045
|
+
const workbook = XLSX.utils.book_new();
|
|
1046
|
+
XLSX.utils.book_append_sheet(workbook, worksheet, sheetName);
|
|
1047
|
+
return workbook;
|
|
1048
|
+
}
|
|
1049
|
+
function exportExcelFile(workbook, filename = "export.xlsx", options) {
|
|
1050
|
+
XLSX.writeFile(workbook, filename, options);
|
|
1051
|
+
}
|
|
1052
|
+
function exportJSONToExcel(data, filename = "export.xlsx", sheetName = "Sheet1", options) {
|
|
1053
|
+
const workbook = jsonToWorkbook(data, sheetName);
|
|
1054
|
+
exportExcelFile(workbook, filename, options);
|
|
1055
|
+
}
|
|
1056
|
+
async function readExcelToJSON(file, sheetName, parseOptions, jsonOptions) {
|
|
1057
|
+
const workbook = await readExcelFile(file, parseOptions);
|
|
1058
|
+
return workbookToJSON(workbook, sheetName, jsonOptions);
|
|
1059
|
+
}
|
|
1060
|
+
function getSheetNames(workbook) {
|
|
1061
|
+
return workbook.SheetNames;
|
|
1062
|
+
}
|
|
1063
|
+
function getSheet(workbook, sheetName) {
|
|
1064
|
+
const sheet = workbook.Sheets[sheetName];
|
|
1065
|
+
if (!sheet) {
|
|
1066
|
+
throw new Error(`Sheet "${sheetName}" not found`);
|
|
1067
|
+
}
|
|
1068
|
+
return sheet;
|
|
1069
|
+
}
|
|
1070
|
+
function sheetToCSV(worksheet, options) {
|
|
1071
|
+
return XLSX.utils.sheet_to_csv(worksheet, options);
|
|
1072
|
+
}
|
|
1073
|
+
function sheetToHTML(worksheet, options) {
|
|
1074
|
+
return XLSX.utils.sheet_to_html(worksheet, options);
|
|
1075
|
+
}
|
|
1076
|
+
function tableToSheet(table, options) {
|
|
1077
|
+
return XLSX.utils.table_to_sheet(table, options);
|
|
1078
|
+
}
|
|
1079
|
+
function aoaToSheet(data, options) {
|
|
1080
|
+
return XLSX.utils.aoa_to_sheet(data, options);
|
|
1081
|
+
}
|
|
1082
|
+
function sheetToAOA(worksheet, options) {
|
|
1083
|
+
return XLSX.utils.sheet_to_json(worksheet, { ...options, header: 1 });
|
|
1084
|
+
}
|
|
1085
|
+
|
|
1086
|
+
// src/string/index.ts
|
|
1087
|
+
function capitalize(str) {
|
|
1088
|
+
if (!str) return "";
|
|
1089
|
+
return str.charAt(0).toUpperCase() + str.slice(1).toLowerCase();
|
|
1090
|
+
}
|
|
1091
|
+
function camelCase(str) {
|
|
1092
|
+
if (!str) return "";
|
|
1093
|
+
return str.replace(/[-_\s]+(.)?/g, (_, char) => char ? char.toUpperCase() : "").replace(/^[A-Z]/, (char) => char.toLowerCase());
|
|
1094
|
+
}
|
|
1095
|
+
function pascalCase(str) {
|
|
1096
|
+
if (!str) return "";
|
|
1097
|
+
const camel = camelCase(str);
|
|
1098
|
+
return camel.charAt(0).toUpperCase() + camel.slice(1);
|
|
1099
|
+
}
|
|
1100
|
+
function snakeCase(str) {
|
|
1101
|
+
if (!str) return "";
|
|
1102
|
+
return str.replace(/([A-Z])/g, "_$1").replace(/[-\s]+/g, "_").replace(/^_/, "").toLowerCase();
|
|
1103
|
+
}
|
|
1104
|
+
function kebabCase(str) {
|
|
1105
|
+
if (!str) return "";
|
|
1106
|
+
return str.replace(/([A-Z])/g, "-$1").replace(/[_\s]+/g, "-").replace(/^-/, "").toLowerCase();
|
|
1107
|
+
}
|
|
1108
|
+
function truncate(str, length2, suffix = "...") {
|
|
1109
|
+
if (!str || str.length <= length2) return str;
|
|
1110
|
+
return str.slice(0, length2) + suffix;
|
|
1111
|
+
}
|
|
1112
|
+
function trim(str) {
|
|
1113
|
+
return str ? str.trim() : "";
|
|
1114
|
+
}
|
|
1115
|
+
function trimStart(str) {
|
|
1116
|
+
return str ? str.trimStart() : "";
|
|
1117
|
+
}
|
|
1118
|
+
function trimEnd(str) {
|
|
1119
|
+
return str ? str.trimEnd() : "";
|
|
1120
|
+
}
|
|
1121
|
+
function reverse(str) {
|
|
1122
|
+
if (!str) return "";
|
|
1123
|
+
return str.split("").reverse().join("");
|
|
1124
|
+
}
|
|
1125
|
+
function repeat(str, count) {
|
|
1126
|
+
if (!str || count <= 0) return "";
|
|
1127
|
+
return str.repeat(count);
|
|
1128
|
+
}
|
|
1129
|
+
function padStart(str, length2, padStr = " ") {
|
|
1130
|
+
if (!str) return padStr.repeat(length2);
|
|
1131
|
+
return str.padStart(length2, padStr);
|
|
1132
|
+
}
|
|
1133
|
+
function padEnd(str, length2, padStr = " ") {
|
|
1134
|
+
if (!str) return padStr.repeat(length2);
|
|
1135
|
+
return str.padEnd(length2, padStr);
|
|
1136
|
+
}
|
|
1137
|
+
function startsWith(str, searchString) {
|
|
1138
|
+
if (!str) return false;
|
|
1139
|
+
return str.startsWith(searchString);
|
|
1140
|
+
}
|
|
1141
|
+
function endsWith(str, searchString) {
|
|
1142
|
+
if (!str) return false;
|
|
1143
|
+
return str.endsWith(searchString);
|
|
1144
|
+
}
|
|
1145
|
+
function includes(str, searchString) {
|
|
1146
|
+
if (!str) return false;
|
|
1147
|
+
return str.includes(searchString);
|
|
1148
|
+
}
|
|
1149
|
+
function replaceAll(str, search, replacement) {
|
|
1150
|
+
if (!str) return "";
|
|
1151
|
+
if (typeof search === "string") {
|
|
1152
|
+
return str.split(search).join(replacement);
|
|
1153
|
+
}
|
|
1154
|
+
return str.replace(search, replacement);
|
|
1155
|
+
}
|
|
1156
|
+
function stripHtml(str) {
|
|
1157
|
+
if (!str) return "";
|
|
1158
|
+
return str.replace(/<[^>]*>/g, "");
|
|
1159
|
+
}
|
|
1160
|
+
function escapeHtml(str) {
|
|
1161
|
+
if (!str) return "";
|
|
1162
|
+
const map = {
|
|
1163
|
+
"&": "&",
|
|
1164
|
+
"<": "<",
|
|
1165
|
+
">": ">",
|
|
1166
|
+
'"': """,
|
|
1167
|
+
"'": "'"
|
|
1168
|
+
};
|
|
1169
|
+
return str.replace(/[&<>"']/g, (char) => map[char]);
|
|
1170
|
+
}
|
|
1171
|
+
function unescapeHtml(str) {
|
|
1172
|
+
if (!str) return "";
|
|
1173
|
+
const map = {
|
|
1174
|
+
"&": "&",
|
|
1175
|
+
"<": "<",
|
|
1176
|
+
">": ">",
|
|
1177
|
+
""": '"',
|
|
1178
|
+
"'": "'"
|
|
1179
|
+
};
|
|
1180
|
+
return str.replace(/&(amp|lt|gt|quot|#39);/g, (entity) => map[entity]);
|
|
1181
|
+
}
|
|
1182
|
+
function toLowerCase(str) {
|
|
1183
|
+
return str ? str.toLowerCase() : "";
|
|
1184
|
+
}
|
|
1185
|
+
function toUpperCase(str) {
|
|
1186
|
+
return str ? str.toUpperCase() : "";
|
|
1187
|
+
}
|
|
1188
|
+
function titleCase(str) {
|
|
1189
|
+
if (!str) return "";
|
|
1190
|
+
return str.toLowerCase().split(" ").map((word) => word.charAt(0).toUpperCase() + word.slice(1)).join(" ");
|
|
1191
|
+
}
|
|
1192
|
+
function isEmpty(str) {
|
|
1193
|
+
return !str || str.trim().length === 0;
|
|
1194
|
+
}
|
|
1195
|
+
function isNotEmpty(str) {
|
|
1196
|
+
return !isEmpty(str);
|
|
1197
|
+
}
|
|
1198
|
+
function length(str) {
|
|
1199
|
+
if (!str) return 0;
|
|
1200
|
+
return Array.from(str).length;
|
|
1201
|
+
}
|
|
1202
|
+
function split(str, separator) {
|
|
1203
|
+
if (!str) return [];
|
|
1204
|
+
return str.split(separator);
|
|
1205
|
+
}
|
|
1206
|
+
function extractNumbers(str) {
|
|
1207
|
+
if (!str) return [];
|
|
1208
|
+
const matches = str.match(/\d+(\.\d+)?/g);
|
|
1209
|
+
return matches ? matches.map(Number) : [];
|
|
1210
|
+
}
|
|
1211
|
+
function removeSpaces(str) {
|
|
1212
|
+
if (!str) return "";
|
|
1213
|
+
return str.replace(/\s+/g, "");
|
|
1214
|
+
}
|
|
1215
|
+
function normalizeSpaces(str) {
|
|
1216
|
+
if (!str) return "";
|
|
1217
|
+
return str.replace(/\s+/g, " ").trim();
|
|
1218
|
+
}
|
|
1219
|
+
function countOccurrences(str, searchString) {
|
|
1220
|
+
if (!str || !searchString) return 0;
|
|
1221
|
+
return str.split(searchString).length - 1;
|
|
1222
|
+
}
|
|
1223
|
+
function randomString(length2, chars = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789") {
|
|
1224
|
+
let result = "";
|
|
1225
|
+
for (let i = 0; i < length2; i++) {
|
|
1226
|
+
result += chars.charAt(Math.floor(Math.random() * chars.length));
|
|
1227
|
+
}
|
|
1228
|
+
return result;
|
|
1229
|
+
}
|
|
1230
|
+
function uuid() {
|
|
1231
|
+
return "xxxxxxxx-xxxx-4xxx-yxxx-xxxxxxxxxxxx".replace(/[xy]/g, (c) => {
|
|
1232
|
+
const r = Math.random() * 16 | 0;
|
|
1233
|
+
const v = c === "x" ? r : r & 3 | 8;
|
|
1234
|
+
return v.toString(16);
|
|
1235
|
+
});
|
|
1236
|
+
}
|
|
1237
|
+
function maskPhone(phone) {
|
|
1238
|
+
if (!phone || phone.length < 11) return phone;
|
|
1239
|
+
return phone.replace(/(\d{3})\d{4}(\d{4})/, "$1****$2");
|
|
1240
|
+
}
|
|
1241
|
+
function maskIdCard(idCard) {
|
|
1242
|
+
if (!idCard || idCard.length < 18) return idCard;
|
|
1243
|
+
return idCard.replace(/(\d{6})\d{8}(\d{4})/, "$1********$2");
|
|
1244
|
+
}
|
|
1245
|
+
function maskBankCard(cardNumber) {
|
|
1246
|
+
if (!cardNumber || cardNumber.length < 16) return cardNumber;
|
|
1247
|
+
return cardNumber.replace(/(\d{4})\d+(\d{4})/, "$1 **** **** $2");
|
|
1248
|
+
}
|
|
1249
|
+
function maskName(name) {
|
|
1250
|
+
if (!name) return "";
|
|
1251
|
+
if (name.length === 2) {
|
|
1252
|
+
return name.charAt(0) + "*";
|
|
1253
|
+
}
|
|
1254
|
+
return name.charAt(0) + "*".repeat(name.length - 2) + name.charAt(name.length - 1);
|
|
1255
|
+
}
|
|
1256
|
+
function isValidPhone(phone) {
|
|
1257
|
+
if (!phone) return false;
|
|
1258
|
+
return /^1[3-9]\d{9}$/.test(phone);
|
|
1259
|
+
}
|
|
1260
|
+
function isValidEmail(email) {
|
|
1261
|
+
if (!email) return false;
|
|
1262
|
+
return /^[^\s@]+@[^\s@]+\.[^\s@]+$/.test(email);
|
|
1263
|
+
}
|
|
1264
|
+
function isValidUrl(url) {
|
|
1265
|
+
if (!url) return false;
|
|
1266
|
+
try {
|
|
1267
|
+
new URL(url);
|
|
1268
|
+
return true;
|
|
1269
|
+
} catch {
|
|
1270
|
+
return false;
|
|
1271
|
+
}
|
|
1272
|
+
}
|
|
1273
|
+
function isValidIdCard(idCard) {
|
|
1274
|
+
if (!idCard) return false;
|
|
1275
|
+
return /(^\d{15}$)|(^\d{18}$)|(^\d{17}(\d|X|x)$)/.test(idCard);
|
|
1276
|
+
}
|
|
1277
|
+
function toBase64(str) {
|
|
1278
|
+
if (!str) return "";
|
|
1279
|
+
if (typeof window !== "undefined" && window.btoa) {
|
|
1280
|
+
try {
|
|
1281
|
+
return window.btoa(encodeURIComponent(str).replace(/%([0-9A-F]{2})/g, (_, p1) => {
|
|
1282
|
+
return String.fromCharCode(parseInt(p1, 16));
|
|
1283
|
+
}));
|
|
1284
|
+
} catch {
|
|
1285
|
+
return "";
|
|
1286
|
+
}
|
|
1287
|
+
}
|
|
1288
|
+
try {
|
|
1289
|
+
const BufferClass = globalThis.Buffer;
|
|
1290
|
+
return BufferClass ? BufferClass.from(str, "utf-8").toString("base64") : "";
|
|
1291
|
+
} catch {
|
|
1292
|
+
return "";
|
|
1293
|
+
}
|
|
1294
|
+
}
|
|
1295
|
+
function fromBase64(base64) {
|
|
1296
|
+
if (!base64) return "";
|
|
1297
|
+
if (typeof window !== "undefined" && window.atob) {
|
|
1298
|
+
try {
|
|
1299
|
+
const binary = window.atob(base64);
|
|
1300
|
+
const bytes = new Uint8Array(binary.length);
|
|
1301
|
+
for (let i = 0; i < binary.length; i++) {
|
|
1302
|
+
bytes[i] = binary.charCodeAt(i);
|
|
1303
|
+
}
|
|
1304
|
+
return new TextDecoder().decode(bytes);
|
|
1305
|
+
} catch {
|
|
1306
|
+
return "";
|
|
1307
|
+
}
|
|
1308
|
+
}
|
|
1309
|
+
try {
|
|
1310
|
+
const BufferClass = globalThis.Buffer;
|
|
1311
|
+
return BufferClass ? BufferClass.from(base64, "base64").toString("utf-8") : "";
|
|
1312
|
+
} catch {
|
|
1313
|
+
return "";
|
|
1314
|
+
}
|
|
1315
|
+
}
|
|
944
1316
|
// Annotate the CommonJS export names for ESM import in node:
|
|
945
1317
|
0 && (module.exports = {
|
|
946
1318
|
Decimal,
|
|
1319
|
+
XLSX,
|
|
947
1320
|
abs,
|
|
948
1321
|
add,
|
|
949
1322
|
addDaysToDate,
|
|
950
1323
|
addDaysUTC,
|
|
951
1324
|
addMonthsToDate,
|
|
952
1325
|
addMonthsUTC,
|
|
1326
|
+
aoaToSheet,
|
|
1327
|
+
camelCase,
|
|
1328
|
+
capitalize,
|
|
953
1329
|
ceil,
|
|
954
1330
|
clearAllCookies,
|
|
1331
|
+
countOccurrences,
|
|
955
1332
|
debounce,
|
|
956
1333
|
divide,
|
|
1334
|
+
endsWith,
|
|
957
1335
|
equals,
|
|
1336
|
+
escapeHtml,
|
|
1337
|
+
exportExcelFile,
|
|
1338
|
+
exportJSONToExcel,
|
|
1339
|
+
extractNumbers,
|
|
958
1340
|
floor,
|
|
959
1341
|
formatDate,
|
|
960
1342
|
formatDateOnly,
|
|
@@ -967,6 +1349,7 @@ function negate(value) {
|
|
|
967
1349
|
formatUTC,
|
|
968
1350
|
formatUTCDateOnly,
|
|
969
1351
|
formatUTCTimeOnly,
|
|
1352
|
+
fromBase64,
|
|
970
1353
|
fromUTC,
|
|
971
1354
|
getAllCookies,
|
|
972
1355
|
getAllQueryParams,
|
|
@@ -988,6 +1371,8 @@ function negate(value) {
|
|
|
988
1371
|
getQueryParam,
|
|
989
1372
|
getQueryParamAll,
|
|
990
1373
|
getScreenResolution,
|
|
1374
|
+
getSheet,
|
|
1375
|
+
getSheetNames,
|
|
991
1376
|
getStartOfDay,
|
|
992
1377
|
getStartOfMonth,
|
|
993
1378
|
getStartOfWeek,
|
|
@@ -1019,34 +1404,84 @@ function negate(value) {
|
|
|
1019
1404
|
greaterThan,
|
|
1020
1405
|
greaterThanOrEqual,
|
|
1021
1406
|
hasCookie,
|
|
1407
|
+
includes,
|
|
1022
1408
|
isAfterDate,
|
|
1023
1409
|
isAndroid,
|
|
1024
1410
|
isBeforeDate,
|
|
1025
1411
|
isDesktop,
|
|
1412
|
+
isEmpty,
|
|
1026
1413
|
isIOS,
|
|
1027
1414
|
isMobile,
|
|
1415
|
+
isNotEmpty,
|
|
1028
1416
|
isSameDayDate,
|
|
1029
1417
|
isTablet,
|
|
1030
1418
|
isTouchDevice,
|
|
1031
1419
|
isValidDate,
|
|
1420
|
+
isValidEmail,
|
|
1421
|
+
isValidIdCard,
|
|
1422
|
+
isValidPhone,
|
|
1423
|
+
isValidUrl,
|
|
1032
1424
|
isWeChat,
|
|
1425
|
+
jsonToWorkbook,
|
|
1426
|
+
kebabCase,
|
|
1427
|
+
length,
|
|
1033
1428
|
lessThan,
|
|
1034
1429
|
lessThanOrEqual,
|
|
1430
|
+
maskBankCard,
|
|
1035
1431
|
maskEmail,
|
|
1432
|
+
maskIdCard,
|
|
1433
|
+
maskName,
|
|
1434
|
+
maskPhone,
|
|
1036
1435
|
multiply,
|
|
1037
1436
|
negate,
|
|
1437
|
+
normalizeSpaces,
|
|
1438
|
+
padEnd,
|
|
1439
|
+
padStart,
|
|
1038
1440
|
parseDate,
|
|
1039
1441
|
parseMoney,
|
|
1442
|
+
pascalCase,
|
|
1443
|
+
randomString,
|
|
1444
|
+
read,
|
|
1445
|
+
readExcelFile,
|
|
1446
|
+
readExcelToJSON,
|
|
1447
|
+
readFile,
|
|
1040
1448
|
removeCookie,
|
|
1449
|
+
removeSpaces,
|
|
1450
|
+
repeat,
|
|
1451
|
+
replaceAll,
|
|
1452
|
+
reverse,
|
|
1041
1453
|
round,
|
|
1042
1454
|
setCookie,
|
|
1455
|
+
sheetToAOA,
|
|
1456
|
+
sheetToCSV,
|
|
1457
|
+
sheetToHTML,
|
|
1458
|
+
snakeCase,
|
|
1459
|
+
split,
|
|
1460
|
+
startsWith,
|
|
1461
|
+
stripHtml,
|
|
1043
1462
|
subDaysFromDate,
|
|
1044
1463
|
subDaysUTC,
|
|
1045
1464
|
subMonthsFromDate,
|
|
1046
1465
|
subMonthsUTC,
|
|
1047
1466
|
subtract,
|
|
1467
|
+
tableToSheet,
|
|
1048
1468
|
throttle,
|
|
1469
|
+
titleCase,
|
|
1470
|
+
toBase64,
|
|
1049
1471
|
toISOString,
|
|
1472
|
+
toLowerCase,
|
|
1050
1473
|
toUTC,
|
|
1051
|
-
|
|
1474
|
+
toUpperCase,
|
|
1475
|
+
trim,
|
|
1476
|
+
trimEnd,
|
|
1477
|
+
trimStart,
|
|
1478
|
+
truncate,
|
|
1479
|
+
unescapeHtml,
|
|
1480
|
+
unmaskEmail,
|
|
1481
|
+
utils,
|
|
1482
|
+
uuid,
|
|
1483
|
+
workbookToJSON,
|
|
1484
|
+
write,
|
|
1485
|
+
writeFile,
|
|
1486
|
+
writeFileXLSX
|
|
1052
1487
|
});
|
package/dist/index.d.cts
CHANGED
|
@@ -1,5 +1,8 @@
|
|
|
1
1
|
import Decimal from 'decimal.js';
|
|
2
2
|
export { default as Decimal, Decimal as DecimalType } from 'decimal.js';
|
|
3
|
+
import * as XLSX from 'xlsx';
|
|
4
|
+
export { XLSX };
|
|
5
|
+
export { BookType, CellObject, JSON2SheetOpts, ParsingOptions, Range, Sheet2JSONOpts, WorkBook, WorkSheet, WritingOptions } from 'xlsx';
|
|
3
6
|
|
|
4
7
|
declare function throttleFn<T extends (...args: any[]) => any>(fn: T, wait?: number, options?: {
|
|
5
8
|
leading?: boolean;
|
|
@@ -167,4 +170,68 @@ declare function floor(value: number | string | Decimal, decimalPlaces?: number)
|
|
|
167
170
|
declare function abs(value: number | string | Decimal): number;
|
|
168
171
|
declare function negate(value: number | string | Decimal): number;
|
|
169
172
|
|
|
170
|
-
|
|
173
|
+
declare const read: typeof XLSX.read;
|
|
174
|
+
declare const readFile: typeof XLSX.readFile;
|
|
175
|
+
declare const write: typeof XLSX.write;
|
|
176
|
+
declare const writeFile: typeof XLSX.writeFile;
|
|
177
|
+
declare const writeFileXLSX: typeof XLSX.writeFileXLSX;
|
|
178
|
+
declare const utils: XLSX.XLSX$Utils;
|
|
179
|
+
declare function readExcelFile(file: File, options?: XLSX.ParsingOptions): Promise<XLSX.WorkBook>;
|
|
180
|
+
declare function workbookToJSON<T = any>(workbook: XLSX.WorkBook, sheetName?: string, options?: XLSX.Sheet2JSONOpts): T[];
|
|
181
|
+
declare function jsonToWorkbook<T = any>(data: T[], sheetName?: string, options?: XLSX.JSON2SheetOpts): XLSX.WorkBook;
|
|
182
|
+
declare function exportExcelFile(workbook: XLSX.WorkBook, filename?: string, options?: XLSX.WritingOptions): void;
|
|
183
|
+
declare function exportJSONToExcel<T = any>(data: T[], filename?: string, sheetName?: string, options?: XLSX.WritingOptions): void;
|
|
184
|
+
declare function readExcelToJSON<T = any>(file: File, sheetName?: string, parseOptions?: XLSX.ParsingOptions, jsonOptions?: XLSX.Sheet2JSONOpts): Promise<T[]>;
|
|
185
|
+
declare function getSheetNames(workbook: XLSX.WorkBook): string[];
|
|
186
|
+
declare function getSheet(workbook: XLSX.WorkBook, sheetName: string): XLSX.WorkSheet;
|
|
187
|
+
declare function sheetToCSV(worksheet: XLSX.WorkSheet, options?: XLSX.Sheet2CSVOpts): string;
|
|
188
|
+
declare function sheetToHTML(worksheet: XLSX.WorkSheet, options?: XLSX.Sheet2HTMLOpts): string;
|
|
189
|
+
declare function tableToSheet(table: HTMLElement | string, options?: XLSX.Table2SheetOpts): XLSX.WorkSheet;
|
|
190
|
+
declare function aoaToSheet(data: any[][], options?: XLSX.AOA2SheetOpts): XLSX.WorkSheet;
|
|
191
|
+
declare function sheetToAOA(worksheet: XLSX.WorkSheet, options?: XLSX.Sheet2JSONOpts): any[][];
|
|
192
|
+
|
|
193
|
+
declare function capitalize(str: string): string;
|
|
194
|
+
declare function camelCase(str: string): string;
|
|
195
|
+
declare function pascalCase(str: string): string;
|
|
196
|
+
declare function snakeCase(str: string): string;
|
|
197
|
+
declare function kebabCase(str: string): string;
|
|
198
|
+
declare function truncate(str: string, length: number, suffix?: string): string;
|
|
199
|
+
declare function trim(str: string): string;
|
|
200
|
+
declare function trimStart(str: string): string;
|
|
201
|
+
declare function trimEnd(str: string): string;
|
|
202
|
+
declare function reverse(str: string): string;
|
|
203
|
+
declare function repeat(str: string, count: number): string;
|
|
204
|
+
declare function padStart(str: string, length: number, padStr?: string): string;
|
|
205
|
+
declare function padEnd(str: string, length: number, padStr?: string): string;
|
|
206
|
+
declare function startsWith(str: string, searchString: string): boolean;
|
|
207
|
+
declare function endsWith(str: string, searchString: string): boolean;
|
|
208
|
+
declare function includes(str: string, searchString: string): boolean;
|
|
209
|
+
declare function replaceAll(str: string, search: string | RegExp, replacement: string): string;
|
|
210
|
+
declare function stripHtml(str: string): string;
|
|
211
|
+
declare function escapeHtml(str: string): string;
|
|
212
|
+
declare function unescapeHtml(str: string): string;
|
|
213
|
+
declare function toLowerCase(str: string): string;
|
|
214
|
+
declare function toUpperCase(str: string): string;
|
|
215
|
+
declare function titleCase(str: string): string;
|
|
216
|
+
declare function isEmpty(str: string): boolean;
|
|
217
|
+
declare function isNotEmpty(str: string): boolean;
|
|
218
|
+
declare function length(str: string): number;
|
|
219
|
+
declare function split(str: string, separator: string | RegExp): string[];
|
|
220
|
+
declare function extractNumbers(str: string): number[];
|
|
221
|
+
declare function removeSpaces(str: string): string;
|
|
222
|
+
declare function normalizeSpaces(str: string): string;
|
|
223
|
+
declare function countOccurrences(str: string, searchString: string): number;
|
|
224
|
+
declare function randomString(length: number, chars?: string): string;
|
|
225
|
+
declare function uuid(): string;
|
|
226
|
+
declare function maskPhone(phone: string): string;
|
|
227
|
+
declare function maskIdCard(idCard: string): string;
|
|
228
|
+
declare function maskBankCard(cardNumber: string): string;
|
|
229
|
+
declare function maskName(name: string): string;
|
|
230
|
+
declare function isValidPhone(phone: string): boolean;
|
|
231
|
+
declare function isValidEmail(email: string): boolean;
|
|
232
|
+
declare function isValidUrl(url: string): boolean;
|
|
233
|
+
declare function isValidIdCard(idCard: string): boolean;
|
|
234
|
+
declare function toBase64(str: string): string;
|
|
235
|
+
declare function fromBase64(base64: string): string;
|
|
236
|
+
|
|
237
|
+
export { 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, 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, 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, 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, toLowerCase, toUTC, toUpperCase, trim, trimEnd, trimStart, truncate, unescapeHtml, unmaskEmail, utils, uuid, workbookToJSON, write, writeFile, writeFileXLSX };
|