react-util-tools 1.0.23 → 1.0.25

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 CHANGED
@@ -60,6 +60,16 @@ const total = new Decimal('0.1').plus('0.2') // Decimal(0.3)
60
60
 
61
61
  [查看文档](./src/address/README.md)
62
62
 
63
+ ### 🍪 Cookie - Cookie 操作
64
+ - `setCookie()` - 设置 Cookie
65
+ - `getCookie()` - 获取 Cookie
66
+ - `removeCookie()` - 删除 Cookie
67
+ - `hasCookie()` - 检查 Cookie 是否存在
68
+ - `getAllCookies()` - 获取所有 Cookie
69
+ - `clearAllCookies()` - 清除所有 Cookie
70
+
71
+ [查看文档](./src/cookie/README.md)
72
+
63
73
  ### 📱 Device - 设备检测
64
74
  - `getOS()` - 获取操作系统
65
75
  - `getBrowser()` - 获取浏览器类型
@@ -76,6 +86,8 @@ const total = new Decimal('0.1').plus('0.2') // Decimal(0.3)
76
86
  - `formatNumber()` - 数字格式化
77
87
  - `formatMoneyToChinese()` - 金额转中文大写
78
88
  - `formatPercent()` - 百分比格式化
89
+ - `maskEmail()` - 邮箱脱敏
90
+ - `unmaskEmail()` - 邮箱解脱敏
79
91
 
80
92
  [查看文档](./src/format/README.md)
81
93
 
@@ -108,6 +120,31 @@ const total = new Decimal('0.1').plus('0.2') // Decimal(0.3)
108
120
 
109
121
  [查看文档](./src/decimal/README.md)
110
122
 
123
+ #### Decimal Utils - 高精度计算工具函数
124
+ - `add()` - 加法运算
125
+ - `subtract()` - 减法运算
126
+ - `multiply()` - 乘法运算
127
+ - `divide()` - 除法运算
128
+ - `equals()` - 判断相等
129
+ - `greaterThan()` / `lessThan()` - 大小比较
130
+ - `round()` / `ceil()` / `floor()` - 取整
131
+ - `abs()` / `negate()` - 绝对值/取反
132
+
133
+ [查看文档](./src/decimal/utils/README.md)
134
+
135
+ ### 📊 Excel - Excel 文件处理
136
+ 基于 SheetJS (xlsx) 的 Excel 文件处理工具:
137
+ - `XLSX` - 完整的 SheetJS 对象
138
+ - `readExcelFile()` - 读取 Excel 文件
139
+ - `exportJSONToExcel()` - 导出 JSON 为 Excel
140
+ - `workbookToJSON()` - WorkBook 转 JSON
141
+ - `jsonToWorkbook()` - JSON 转 WorkBook
142
+ - `readExcelToJSON()` - 直接读取为 JSON
143
+ - 支持多种格式(.xlsx, .xls, .csv 等)
144
+ - 完整保留 SheetJS 所有功能
145
+
146
+ [查看文档](./src/excel/README.md)
147
+
111
148
  ## 使用示例
112
149
 
113
150
  ### 节流防抖
@@ -136,6 +173,26 @@ const id = getQueryParam('id') // "123"
136
173
  const params = getAllQueryParams() // { id: "123", name: "test" }
137
174
  ```
138
175
 
176
+ ### Cookie 操作
177
+
178
+ ```typescript
179
+ import { setCookie, getCookie, removeCookie } from '@dj49846917/react-tools'
180
+
181
+ // 设置 Cookie
182
+ setCookie('token', 'abc123', {
183
+ expires: 7 * 24 * 60 * 60, // 7天(秒)
184
+ path: '/',
185
+ secure: true,
186
+ sameSite: 'Strict'
187
+ })
188
+
189
+ // 获取 Cookie
190
+ const token = getCookie('token') // "abc123"
191
+
192
+ // 删除 Cookie
193
+ removeCookie('token')
194
+ ```
195
+
139
196
  ### 设备检测
140
197
 
141
198
  ```typescript
@@ -152,7 +209,7 @@ if (isMobile()) {
152
209
  ### 金额格式化
153
210
 
154
211
  ```typescript
155
- import { formatMoney, parseMoney, formatMoneyToChinese } from 'react-tools'
212
+ import { formatMoney, parseMoney, formatMoneyToChinese, maskEmail } from 'react-tools'
156
213
 
157
214
  formatMoney(1234.56) // "¥1,234.56"
158
215
  formatMoney(1234.56, { symbol: '$' }) // "$1,234.56"
@@ -160,6 +217,9 @@ formatMoney(1234.56, { symbol: '$' }) // "$1,234.56"
160
217
  parseMoney('¥1,234.56') // 1234.56
161
218
 
162
219
  formatMoneyToChinese(1234.56) // "壹仟贰佰叁拾肆元伍角陆分"
220
+
221
+ // 邮箱脱敏
222
+ maskEmail('dj49846917@proton.me') // "dj4***@proton.me"
163
223
  ```
164
224
 
165
225
  ### 日期处理
@@ -203,9 +263,9 @@ getUTCWeekStart(2024, 10) // Date 对象
203
263
  ### 高精度计算
204
264
 
205
265
  ```typescript
206
- import { Decimal } from 'react-tools'
266
+ import { Decimal, add, multiply, divide } from 'react-tools'
207
267
 
208
- // 解决浮点数精度问题
268
+ // 使用 Decimal 类
209
269
  const result = new Decimal('0.1').plus('0.2')
210
270
  console.log(result.toString()) // "0.3"
211
271
 
@@ -214,6 +274,32 @@ const price = new Decimal('19.99')
214
274
  const quantity = new Decimal('3')
215
275
  const total = price.times(quantity)
216
276
  console.log(total.toFixed(2)) // "59.97"
277
+
278
+ // 使用工具函数(返回 number 类型)
279
+ add(0.1, 0.2) // 0.3
280
+ multiply(19.99, 3) // 59.97
281
+ divide(100, 3) // 33.333...
282
+ ```
283
+
284
+ ### Excel 文件处理
285
+
286
+ ```typescript
287
+ import { readExcelToJSON, exportJSONToExcel } from 'react-tools'
288
+
289
+ // 读取 Excel 文件
290
+ async function handleFileUpload(file: File) {
291
+ const data = await readExcelToJSON(file)
292
+ console.log(data) // [{ name: '张三', age: 25 }, ...]
293
+ }
294
+
295
+ // 导出 JSON 为 Excel
296
+ function exportData() {
297
+ const data = [
298
+ { name: '张三', age: 25, city: '北京' },
299
+ { name: '李四', age: 30, city: '上海' }
300
+ ]
301
+ exportJSONToExcel(data, 'users.xlsx', 'UserList')
302
+ }
217
303
  ```
218
304
 
219
305
  ## TypeScript 支持
@@ -244,6 +330,7 @@ import { formatMoney, Decimal } from 'react-tools'
244
330
  - `date-fns` - 日期处理
245
331
  - `date-fns-tz` - 时区处理
246
332
  - `decimal.js` - 高精度计算
333
+ - `xlsx` - Excel 文件处理
247
334
 
248
335
  ## 许可证
249
336
 
package/dist/index.cjs CHANGED
@@ -31,16 +31,21 @@ 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,
40
42
  ceil: () => ceil,
43
+ clearAllCookies: () => clearAllCookies,
41
44
  debounce: () => debounceFn,
42
45
  divide: () => divide,
43
46
  equals: () => equals,
47
+ exportExcelFile: () => exportExcelFile,
48
+ exportJSONToExcel: () => exportJSONToExcel,
44
49
  floor: () => floor,
45
50
  formatDate: () => formatDate,
46
51
  formatDateOnly: () => formatDateOnly,
@@ -54,10 +59,12 @@ __export(index_exports, {
54
59
  formatUTCDateOnly: () => formatUTCDateOnly,
55
60
  formatUTCTimeOnly: () => formatUTCTimeOnly,
56
61
  fromUTC: () => fromUTC,
62
+ getAllCookies: () => getAllCookies,
57
63
  getAllQueryParams: () => getAllQueryParams,
58
64
  getBrowser: () => getBrowser,
59
65
  getBrowserEngine: () => getBrowserEngine,
60
66
  getBrowserVersion: () => getBrowserVersion,
67
+ getCookie: () => getCookie,
61
68
  getDaysDiff: () => getDaysDiff,
62
69
  getDeviceInfo: () => getDeviceInfo,
63
70
  getDevicePixelRatio: () => getDevicePixelRatio,
@@ -72,6 +79,8 @@ __export(index_exports, {
72
79
  getQueryParam: () => getQueryParam,
73
80
  getQueryParamAll: () => getQueryParamAll,
74
81
  getScreenResolution: () => getScreenResolution,
82
+ getSheet: () => getSheet,
83
+ getSheetNames: () => getSheetNames,
75
84
  getStartOfDay: () => getStartOfDay,
76
85
  getStartOfMonth: () => getStartOfMonth,
77
86
  getStartOfWeek: () => getStartOfWeek,
@@ -102,6 +111,7 @@ __export(index_exports, {
102
111
  getViewportSize: () => getViewportSize,
103
112
  greaterThan: () => greaterThan,
104
113
  greaterThanOrEqual: () => greaterThanOrEqual,
114
+ hasCookie: () => hasCookie,
105
115
  isAfterDate: () => isAfterDate,
106
116
  isAndroid: () => isAndroid,
107
117
  isBeforeDate: () => isBeforeDate,
@@ -113,21 +123,39 @@ __export(index_exports, {
113
123
  isTouchDevice: () => isTouchDevice,
114
124
  isValidDate: () => isValidDate,
115
125
  isWeChat: () => isWeChat,
126
+ jsonToWorkbook: () => jsonToWorkbook,
116
127
  lessThan: () => lessThan,
117
128
  lessThanOrEqual: () => lessThanOrEqual,
129
+ maskEmail: () => maskEmail,
118
130
  multiply: () => multiply,
119
131
  negate: () => negate,
120
132
  parseDate: () => parseDate,
121
133
  parseMoney: () => parseMoney,
134
+ read: () => read2,
135
+ readExcelFile: () => readExcelFile,
136
+ readExcelToJSON: () => readExcelToJSON,
137
+ readFile: () => readFile,
138
+ removeCookie: () => removeCookie,
122
139
  round: () => round,
140
+ setCookie: () => setCookie,
141
+ sheetToAOA: () => sheetToAOA,
142
+ sheetToCSV: () => sheetToCSV,
143
+ sheetToHTML: () => sheetToHTML,
123
144
  subDaysFromDate: () => subDaysFromDate,
124
145
  subDaysUTC: () => subDaysUTC,
125
146
  subMonthsFromDate: () => subMonthsFromDate,
126
147
  subMonthsUTC: () => subMonthsUTC,
127
148
  subtract: () => subtract,
149
+ tableToSheet: () => tableToSheet,
128
150
  throttle: () => throttleFn,
129
151
  toISOString: () => toISOString,
130
- toUTC: () => toUTC
152
+ toUTC: () => toUTC,
153
+ unmaskEmail: () => unmaskEmail,
154
+ utils: () => utils2,
155
+ workbookToJSON: () => workbookToJSON,
156
+ write: () => write,
157
+ writeFile: () => writeFile2,
158
+ writeFileXLSX: () => writeFileXLSX
131
159
  });
132
160
  module.exports = __toCommonJS(index_exports);
133
161
 
@@ -208,6 +236,66 @@ function getQueryParamAll(key, url) {
208
236
  return searchParams.getAll(key);
209
237
  }
210
238
 
239
+ // src/cookie/index.ts
240
+ function setCookie(name, value, options = {}) {
241
+ let cookieString = `${encodeURIComponent(name)}=${encodeURIComponent(value)}`;
242
+ if (options.expires) {
243
+ const expires = options.expires instanceof Date ? options.expires : new Date(Date.now() + options.expires * 1e3);
244
+ cookieString += `; expires=${expires.toUTCString()}`;
245
+ }
246
+ if (options.path) {
247
+ cookieString += `; path=${options.path}`;
248
+ }
249
+ if (options.domain) {
250
+ cookieString += `; domain=${options.domain}`;
251
+ }
252
+ if (options.secure) {
253
+ cookieString += "; secure";
254
+ }
255
+ if (options.sameSite) {
256
+ cookieString += `; SameSite=${options.sameSite}`;
257
+ }
258
+ document.cookie = cookieString;
259
+ }
260
+ function getCookie(name) {
261
+ const nameEQ = encodeURIComponent(name) + "=";
262
+ const cookies = document.cookie.split(";");
263
+ for (let cookie of cookies) {
264
+ cookie = cookie.trim();
265
+ if (cookie.indexOf(nameEQ) === 0) {
266
+ return decodeURIComponent(cookie.substring(nameEQ.length));
267
+ }
268
+ }
269
+ return null;
270
+ }
271
+ function removeCookie(name, options = {}) {
272
+ setCookie(name, "", {
273
+ ...options,
274
+ expires: /* @__PURE__ */ new Date(0)
275
+ });
276
+ }
277
+ function hasCookie(name) {
278
+ return getCookie(name) !== null;
279
+ }
280
+ function getAllCookies() {
281
+ const cookies = {};
282
+ const cookieArray = document.cookie.split(";");
283
+ for (let cookie of cookieArray) {
284
+ cookie = cookie.trim();
285
+ const [name, ...valueParts] = cookie.split("=");
286
+ if (name) {
287
+ cookies[decodeURIComponent(name)] = decodeURIComponent(valueParts.join("="));
288
+ }
289
+ }
290
+ return cookies;
291
+ }
292
+ function clearAllCookies(options = {}) {
293
+ const cookies = getAllCookies();
294
+ for (const name in cookies) {
295
+ removeCookie(name, options);
296
+ }
297
+ }
298
+
211
299
  // src/device/index.ts
212
300
  function getUserAgent() {
213
301
  return navigator.userAgent.toLowerCase();
@@ -435,6 +523,39 @@ function formatPercent(value, options = {}) {
435
523
  const num = multiply2 ? value * 100 : value;
436
524
  return num.toFixed(decimals) + "%";
437
525
  }
526
+ function maskEmail(email) {
527
+ if (!email || typeof email !== "string") {
528
+ return "";
529
+ }
530
+ const atIndex = email.indexOf("@");
531
+ if (atIndex <= 0) {
532
+ return email;
533
+ }
534
+ const localPart = email.substring(0, atIndex);
535
+ const domainPart = email.substring(atIndex);
536
+ const visiblePart = localPart.substring(0, 3);
537
+ return `${visiblePart}***${domainPart}`;
538
+ }
539
+ function unmaskEmail(maskedEmail, originalEmail) {
540
+ if (!maskedEmail || !originalEmail) {
541
+ return "";
542
+ }
543
+ if (!maskedEmail.includes("***@")) {
544
+ return maskedEmail;
545
+ }
546
+ const maskedParts = maskedEmail.split("***@");
547
+ const atIndex = originalEmail.indexOf("@");
548
+ if (atIndex <= 0) {
549
+ return maskedEmail;
550
+ }
551
+ const originalPrefix = originalEmail.substring(0, 3);
552
+ const originalDomain = originalEmail.substring(atIndex + 1);
553
+ const maskedDomain = maskedParts[1];
554
+ if (maskedParts[0] === originalPrefix && maskedDomain === originalDomain) {
555
+ return originalEmail;
556
+ }
557
+ return maskedEmail;
558
+ }
438
559
 
439
560
  // src/date/index.ts
440
561
  var import_date_fns = require("date-fns");
@@ -840,19 +961,102 @@ function negate(value) {
840
961
  return 0;
841
962
  }
842
963
  }
964
+
965
+ // src/excel/index.ts
966
+ var XLSX = __toESM(require("xlsx"), 1);
967
+ var {
968
+ read: read2,
969
+ readFile,
970
+ write,
971
+ writeFile: writeFile2,
972
+ writeFileXLSX,
973
+ utils: utils2
974
+ } = XLSX;
975
+ function readExcelFile(file, options) {
976
+ return new Promise((resolve, reject) => {
977
+ const reader = new FileReader();
978
+ reader.onload = (e) => {
979
+ try {
980
+ const data = e.target?.result;
981
+ const workbook = XLSX.read(data, options);
982
+ resolve(workbook);
983
+ } catch (error) {
984
+ reject(error);
985
+ }
986
+ };
987
+ reader.onerror = () => {
988
+ reject(new Error("Failed to read file"));
989
+ };
990
+ reader.readAsArrayBuffer(file);
991
+ });
992
+ }
993
+ function workbookToJSON(workbook, sheetName, options) {
994
+ const sheet = sheetName ? workbook.Sheets[sheetName] : workbook.Sheets[workbook.SheetNames[0]];
995
+ if (!sheet) {
996
+ throw new Error(`Sheet "${sheetName}" not found`);
997
+ }
998
+ return XLSX.utils.sheet_to_json(sheet, options);
999
+ }
1000
+ function jsonToWorkbook(data, sheetName = "Sheet1", options) {
1001
+ const worksheet = XLSX.utils.json_to_sheet(data, options);
1002
+ const workbook = XLSX.utils.book_new();
1003
+ XLSX.utils.book_append_sheet(workbook, worksheet, sheetName);
1004
+ return workbook;
1005
+ }
1006
+ function exportExcelFile(workbook, filename = "export.xlsx", options) {
1007
+ XLSX.writeFile(workbook, filename, options);
1008
+ }
1009
+ function exportJSONToExcel(data, filename = "export.xlsx", sheetName = "Sheet1", options) {
1010
+ const workbook = jsonToWorkbook(data, sheetName);
1011
+ exportExcelFile(workbook, filename, options);
1012
+ }
1013
+ async function readExcelToJSON(file, sheetName, parseOptions, jsonOptions) {
1014
+ const workbook = await readExcelFile(file, parseOptions);
1015
+ return workbookToJSON(workbook, sheetName, jsonOptions);
1016
+ }
1017
+ function getSheetNames(workbook) {
1018
+ return workbook.SheetNames;
1019
+ }
1020
+ function getSheet(workbook, sheetName) {
1021
+ const sheet = workbook.Sheets[sheetName];
1022
+ if (!sheet) {
1023
+ throw new Error(`Sheet "${sheetName}" not found`);
1024
+ }
1025
+ return sheet;
1026
+ }
1027
+ function sheetToCSV(worksheet, options) {
1028
+ return XLSX.utils.sheet_to_csv(worksheet, options);
1029
+ }
1030
+ function sheetToHTML(worksheet, options) {
1031
+ return XLSX.utils.sheet_to_html(worksheet, options);
1032
+ }
1033
+ function tableToSheet(table, options) {
1034
+ return XLSX.utils.table_to_sheet(table, options);
1035
+ }
1036
+ function aoaToSheet(data, options) {
1037
+ return XLSX.utils.aoa_to_sheet(data, options);
1038
+ }
1039
+ function sheetToAOA(worksheet, options) {
1040
+ return XLSX.utils.sheet_to_json(worksheet, { ...options, header: 1 });
1041
+ }
843
1042
  // Annotate the CommonJS export names for ESM import in node:
844
1043
  0 && (module.exports = {
845
1044
  Decimal,
1045
+ XLSX,
846
1046
  abs,
847
1047
  add,
848
1048
  addDaysToDate,
849
1049
  addDaysUTC,
850
1050
  addMonthsToDate,
851
1051
  addMonthsUTC,
1052
+ aoaToSheet,
852
1053
  ceil,
1054
+ clearAllCookies,
853
1055
  debounce,
854
1056
  divide,
855
1057
  equals,
1058
+ exportExcelFile,
1059
+ exportJSONToExcel,
856
1060
  floor,
857
1061
  formatDate,
858
1062
  formatDateOnly,
@@ -866,10 +1070,12 @@ function negate(value) {
866
1070
  formatUTCDateOnly,
867
1071
  formatUTCTimeOnly,
868
1072
  fromUTC,
1073
+ getAllCookies,
869
1074
  getAllQueryParams,
870
1075
  getBrowser,
871
1076
  getBrowserEngine,
872
1077
  getBrowserVersion,
1078
+ getCookie,
873
1079
  getDaysDiff,
874
1080
  getDeviceInfo,
875
1081
  getDevicePixelRatio,
@@ -884,6 +1090,8 @@ function negate(value) {
884
1090
  getQueryParam,
885
1091
  getQueryParamAll,
886
1092
  getScreenResolution,
1093
+ getSheet,
1094
+ getSheetNames,
887
1095
  getStartOfDay,
888
1096
  getStartOfMonth,
889
1097
  getStartOfWeek,
@@ -914,6 +1122,7 @@ function negate(value) {
914
1122
  getViewportSize,
915
1123
  greaterThan,
916
1124
  greaterThanOrEqual,
1125
+ hasCookie,
917
1126
  isAfterDate,
918
1127
  isAndroid,
919
1128
  isBeforeDate,
@@ -925,19 +1134,37 @@ function negate(value) {
925
1134
  isTouchDevice,
926
1135
  isValidDate,
927
1136
  isWeChat,
1137
+ jsonToWorkbook,
928
1138
  lessThan,
929
1139
  lessThanOrEqual,
1140
+ maskEmail,
930
1141
  multiply,
931
1142
  negate,
932
1143
  parseDate,
933
1144
  parseMoney,
1145
+ read,
1146
+ readExcelFile,
1147
+ readExcelToJSON,
1148
+ readFile,
1149
+ removeCookie,
934
1150
  round,
1151
+ setCookie,
1152
+ sheetToAOA,
1153
+ sheetToCSV,
1154
+ sheetToHTML,
935
1155
  subDaysFromDate,
936
1156
  subDaysUTC,
937
1157
  subMonthsFromDate,
938
1158
  subMonthsUTC,
939
1159
  subtract,
1160
+ tableToSheet,
940
1161
  throttle,
941
1162
  toISOString,
942
- toUTC
1163
+ toUTC,
1164
+ unmaskEmail,
1165
+ utils,
1166
+ workbookToJSON,
1167
+ write,
1168
+ writeFile,
1169
+ writeFileXLSX
943
1170
  });
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;
@@ -11,6 +14,20 @@ declare function getQueryParam(key: string, url?: string): string | null;
11
14
  declare function getAllQueryParams(url?: string): Record<string, string>;
12
15
  declare function getQueryParamAll(key: string, url?: string): string[];
13
16
 
17
+ interface CookieOptions {
18
+ expires?: number | Date;
19
+ path?: string;
20
+ domain?: string;
21
+ secure?: boolean;
22
+ sameSite?: 'Strict' | 'Lax' | 'None';
23
+ }
24
+ declare function setCookie(name: string, value: string, options?: CookieOptions): void;
25
+ declare function getCookie(name: string): string | null;
26
+ declare function removeCookie(name: string, options?: Pick<CookieOptions, 'path' | 'domain'>): void;
27
+ declare function hasCookie(name: string): boolean;
28
+ declare function getAllCookies(): Record<string, string>;
29
+ declare function clearAllCookies(options?: Pick<CookieOptions, 'path' | 'domain'>): void;
30
+
14
31
  declare function getOS(): string;
15
32
  declare function getBrowser(): string;
16
33
  declare function getBrowserEngine(): string;
@@ -70,6 +87,8 @@ declare function formatPercent(value: number, options?: {
70
87
  decimals?: number;
71
88
  multiply?: boolean;
72
89
  }): string;
90
+ declare function maskEmail(email: string): string;
91
+ declare function unmaskEmail(maskedEmail: string, originalEmail: string): string;
73
92
 
74
93
  declare function formatDate(date: Date | number | string, formatStr?: string): string;
75
94
  declare function formatDateOnly(date: Date | number | string): string;
@@ -151,4 +170,24 @@ declare function floor(value: number | string | Decimal, decimalPlaces?: number)
151
170
  declare function abs(value: number | string | Decimal): number;
152
171
  declare function negate(value: number | string | Decimal): number;
153
172
 
154
- export { abs, add, addDaysToDate, addDaysUTC, addMonthsToDate, addMonthsUTC, ceil, debounceFn as debounce, divide, equals, floor, formatDate, formatDateOnly, formatMoney, formatMoneyToChinese, formatNumber, formatPercent, formatRelativeTime, formatTimeOnly, formatUTC, formatUTCDateOnly, formatUTCTimeOnly, fromUTC, getAllQueryParams, getBrowser, getBrowserEngine, getBrowserVersion, getDaysDiff, getDeviceInfo, getDevicePixelRatio, getDeviceType, getEndOfDay, getEndOfMonth, getEndOfWeek, getEndOfYear, getHoursDiff, getMinutesDiff, getOS, getQueryParam, getQueryParamAll, getScreenResolution, 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, isAfterDate, isAndroid, isBeforeDate, isDesktop, isIOS, isMobile, isSameDayDate, isTablet, isTouchDevice, isValidDate, isWeChat, lessThan, lessThanOrEqual, multiply, negate, parseDate, parseMoney, round, subDaysFromDate, subDaysUTC, subMonthsFromDate, subMonthsUTC, subtract, throttleFn as throttle, toISOString, toUTC };
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
+ export { type CookieOptions, abs, add, addDaysToDate, addDaysUTC, addMonthsToDate, addMonthsUTC, aoaToSheet, ceil, clearAllCookies, debounceFn as debounce, divide, equals, exportExcelFile, exportJSONToExcel, floor, formatDate, formatDateOnly, formatMoney, formatMoneyToChinese, formatNumber, formatPercent, formatRelativeTime, formatTimeOnly, formatUTC, formatUTCDateOnly, formatUTCTimeOnly, 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, isAfterDate, isAndroid, isBeforeDate, isDesktop, isIOS, isMobile, isSameDayDate, isTablet, isTouchDevice, isValidDate, isWeChat, jsonToWorkbook, lessThan, lessThanOrEqual, maskEmail, multiply, negate, parseDate, parseMoney, read, readExcelFile, readExcelToJSON, readFile, removeCookie, round, setCookie, sheetToAOA, sheetToCSV, sheetToHTML, subDaysFromDate, subDaysUTC, subMonthsFromDate, subMonthsUTC, subtract, tableToSheet, throttleFn as throttle, toISOString, toUTC, unmaskEmail, utils, workbookToJSON, write, writeFile, writeFileXLSX };
package/dist/index.d.ts 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;
@@ -11,6 +14,20 @@ declare function getQueryParam(key: string, url?: string): string | null;
11
14
  declare function getAllQueryParams(url?: string): Record<string, string>;
12
15
  declare function getQueryParamAll(key: string, url?: string): string[];
13
16
 
17
+ interface CookieOptions {
18
+ expires?: number | Date;
19
+ path?: string;
20
+ domain?: string;
21
+ secure?: boolean;
22
+ sameSite?: 'Strict' | 'Lax' | 'None';
23
+ }
24
+ declare function setCookie(name: string, value: string, options?: CookieOptions): void;
25
+ declare function getCookie(name: string): string | null;
26
+ declare function removeCookie(name: string, options?: Pick<CookieOptions, 'path' | 'domain'>): void;
27
+ declare function hasCookie(name: string): boolean;
28
+ declare function getAllCookies(): Record<string, string>;
29
+ declare function clearAllCookies(options?: Pick<CookieOptions, 'path' | 'domain'>): void;
30
+
14
31
  declare function getOS(): string;
15
32
  declare function getBrowser(): string;
16
33
  declare function getBrowserEngine(): string;
@@ -70,6 +87,8 @@ declare function formatPercent(value: number, options?: {
70
87
  decimals?: number;
71
88
  multiply?: boolean;
72
89
  }): string;
90
+ declare function maskEmail(email: string): string;
91
+ declare function unmaskEmail(maskedEmail: string, originalEmail: string): string;
73
92
 
74
93
  declare function formatDate(date: Date | number | string, formatStr?: string): string;
75
94
  declare function formatDateOnly(date: Date | number | string): string;
@@ -151,4 +170,24 @@ declare function floor(value: number | string | Decimal, decimalPlaces?: number)
151
170
  declare function abs(value: number | string | Decimal): number;
152
171
  declare function negate(value: number | string | Decimal): number;
153
172
 
154
- export { abs, add, addDaysToDate, addDaysUTC, addMonthsToDate, addMonthsUTC, ceil, debounceFn as debounce, divide, equals, floor, formatDate, formatDateOnly, formatMoney, formatMoneyToChinese, formatNumber, formatPercent, formatRelativeTime, formatTimeOnly, formatUTC, formatUTCDateOnly, formatUTCTimeOnly, fromUTC, getAllQueryParams, getBrowser, getBrowserEngine, getBrowserVersion, getDaysDiff, getDeviceInfo, getDevicePixelRatio, getDeviceType, getEndOfDay, getEndOfMonth, getEndOfWeek, getEndOfYear, getHoursDiff, getMinutesDiff, getOS, getQueryParam, getQueryParamAll, getScreenResolution, 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, isAfterDate, isAndroid, isBeforeDate, isDesktop, isIOS, isMobile, isSameDayDate, isTablet, isTouchDevice, isValidDate, isWeChat, lessThan, lessThanOrEqual, multiply, negate, parseDate, parseMoney, round, subDaysFromDate, subDaysUTC, subMonthsFromDate, subMonthsUTC, subtract, throttleFn as throttle, toISOString, toUTC };
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
+ export { type CookieOptions, abs, add, addDaysToDate, addDaysUTC, addMonthsToDate, addMonthsUTC, aoaToSheet, ceil, clearAllCookies, debounceFn as debounce, divide, equals, exportExcelFile, exportJSONToExcel, floor, formatDate, formatDateOnly, formatMoney, formatMoneyToChinese, formatNumber, formatPercent, formatRelativeTime, formatTimeOnly, formatUTC, formatUTCDateOnly, formatUTCTimeOnly, 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, isAfterDate, isAndroid, isBeforeDate, isDesktop, isIOS, isMobile, isSameDayDate, isTablet, isTouchDevice, isValidDate, isWeChat, jsonToWorkbook, lessThan, lessThanOrEqual, maskEmail, multiply, negate, parseDate, parseMoney, read, readExcelFile, readExcelToJSON, readFile, removeCookie, round, setCookie, sheetToAOA, sheetToCSV, sheetToHTML, subDaysFromDate, subDaysUTC, subMonthsFromDate, subMonthsUTC, subtract, tableToSheet, throttleFn as throttle, toISOString, toUTC, unmaskEmail, utils, workbookToJSON, write, writeFile, writeFileXLSX };