@jhqn/utils-core 0.0.3-beta.7 → 0.0.3
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 +138 -135
- package/dist/index.d.cts +270 -170
- package/dist/index.d.mts +270 -170
- package/dist/index.d.ts +270 -170
- package/dist/index.mjs +125 -131
- package/package.json +2 -2
package/dist/index.mjs
CHANGED
|
@@ -1,12 +1,12 @@
|
|
|
1
1
|
export { detect } from 'detect-browser';
|
|
2
2
|
import dayjs from 'dayjs';
|
|
3
3
|
export { default as dayjs } from 'dayjs';
|
|
4
|
-
import
|
|
5
|
-
import duration from 'dayjs/plugin/duration';
|
|
6
|
-
import relativeTime from 'dayjs/plugin/relativeTime';
|
|
4
|
+
import zhCN from 'dayjs/locale/zh-cn';
|
|
7
5
|
import customParseFormat from 'dayjs/plugin/customParseFormat';
|
|
6
|
+
import duration from 'dayjs/plugin/duration';
|
|
7
|
+
import localeData from 'dayjs/plugin/localeData';
|
|
8
8
|
import objectSupport from 'dayjs/plugin/objectSupport';
|
|
9
|
-
import
|
|
9
|
+
import relativeTime from 'dayjs/plugin/relativeTime';
|
|
10
10
|
|
|
11
11
|
const snake2Kebab = (str) => str.replace(/_([a-z])/g, (_, letter) => `-${letter.toLowerCase()}`);
|
|
12
12
|
const snake2Pascal = (str) => str.replace(/_([a-z])/g, (_, letter) => letter.toUpperCase()).replace(/^[a-z]/, (letter) => letter.toUpperCase());
|
|
@@ -44,8 +44,12 @@ const jDebug = (...args) => console.log.bind(
|
|
|
44
44
|
`%c[${args.length === 1 ? "DEBUG" : "%s"}]`,
|
|
45
45
|
`${sharedStyle} background: linear-gradient(LightSalmon, Tomato); border-radius: 2px; font-weight: bold; border-top: 2px solid Crimson; border-bottom: 2px solid Crimson;`
|
|
46
46
|
)(...args);
|
|
47
|
-
const jWarn = console.
|
|
48
|
-
const jError = console.error.bind(
|
|
47
|
+
const jWarn = (...args) => console.warn.bind(console, `%c[${args.length === 1 ? "WARN" : "%s"}]`, `${sharedStyle} background: tomato;`)(...args);
|
|
48
|
+
const jError = (...args) => console.error.bind(
|
|
49
|
+
console,
|
|
50
|
+
`%c[${args.length === 1 ? "ERROR" : "%s"}]`,
|
|
51
|
+
`${sharedStyle} background: crimson;`
|
|
52
|
+
)(...args);
|
|
49
53
|
const jInfo = (...args) => console.info.bind(
|
|
50
54
|
console,
|
|
51
55
|
`%c[${args.length === 1 ? "INFO" : "%s"}]`,
|
|
@@ -60,18 +64,15 @@ const jClear = console.clear.bind(console);
|
|
|
60
64
|
|
|
61
65
|
let prevValue;
|
|
62
66
|
const jLogDedupe = (...args) => {
|
|
63
|
-
if (args.length === 0)
|
|
64
|
-
|
|
65
|
-
if (args.length > 0 && prevValue && JSON.stringify(args) === JSON.stringify(prevValue))
|
|
66
|
-
return;
|
|
67
|
+
if (args.length === 0) return;
|
|
68
|
+
if (args.length > 0 && prevValue && JSON.stringify(args) === JSON.stringify(prevValue)) return;
|
|
67
69
|
jLog(...args);
|
|
68
70
|
prevValue = args;
|
|
69
71
|
};
|
|
70
72
|
|
|
71
73
|
let logged = false;
|
|
72
74
|
const jLogOnce = (...args) => {
|
|
73
|
-
if (logged)
|
|
74
|
-
return;
|
|
75
|
+
if (logged) return;
|
|
75
76
|
jLog(...args);
|
|
76
77
|
logged = true;
|
|
77
78
|
};
|
|
@@ -109,6 +110,7 @@ const isJSONStr = (str) => {
|
|
|
109
110
|
JSON.parse(str);
|
|
110
111
|
return true;
|
|
111
112
|
} catch (e) {
|
|
113
|
+
jWarn("Failed to parse invalid string", e);
|
|
112
114
|
return false;
|
|
113
115
|
}
|
|
114
116
|
}
|
|
@@ -119,6 +121,7 @@ const isArrStr = (str) => {
|
|
|
119
121
|
try {
|
|
120
122
|
return Array.isArray(JSON.parse(str));
|
|
121
123
|
} catch (e) {
|
|
124
|
+
jWarn("Failed to parse invalid string", e);
|
|
122
125
|
return false;
|
|
123
126
|
}
|
|
124
127
|
}
|
|
@@ -129,39 +132,36 @@ const isEmpty = (val) => {
|
|
|
129
132
|
return !isDef(val) || val === "" || isArray(val) && val.length === 0 || isObject(val) && Object.keys(val).length === 0 || isMap(val) && val.size === 0 || isSet(val) && val.size === 0;
|
|
130
133
|
};
|
|
131
134
|
|
|
132
|
-
const isValidResCode = (res, code = 200) => res.code === code;
|
|
133
|
-
const isValidRes = (res, code) => isValidResCode(res, code) && isDef(res.data);
|
|
134
|
-
const isValidArrRes = (res, code) => isValidResCode(res, code) && Array.isArray(res.data);
|
|
135
|
-
const isValidPageRes = (res, code) => isValidResCode(res, code) && isDef(res.data) && Array.isArray(res.data.list || res.data.records);
|
|
136
|
-
|
|
137
135
|
const cnPhoneRE = /^1[3-9]\d{9}$/;
|
|
138
|
-
const cnTelRE = /^0\d{
|
|
136
|
+
const cnTelRE = /^0\d{2,3}-?\d{7,8}$/;
|
|
137
|
+
const cnTelRE2 = /^\(0\d{2,3}\)\d{7,8}$/;
|
|
138
|
+
const cnUSCIRE = /^[0-9A-HJ-NPQRTUWXY]{2}\d{6}[0-9A-HJ-NPQRTUWXY]{10}$/;
|
|
139
|
+
const cnIdCard15Re = /^[1-9]\d{7}(?:0[1-9]|10|11|12)(?:[0-2][1-9]|10|20|30|31)\d{2}[\dX]$/i;
|
|
140
|
+
const cnIdCard18Re = /^[1-9]\d{5}(?:18|19|20)\d{2}(?:0[1-9]|1[0-2])(?:[0-2][1-9]|10|20|30|31)\d{3}[\dX]$/i;
|
|
141
|
+
const emailRE = /^[a-z\d](?:\w|-)+@[a-z\d]+\.[a-z]{2,5}$/i;
|
|
142
|
+
const isUSCI = (val) => {
|
|
143
|
+
if (!isDef(val)) return false;
|
|
144
|
+
return cnUSCIRE.test(val);
|
|
145
|
+
};
|
|
139
146
|
const isPhone = (val) => {
|
|
140
|
-
if (!isDef(val))
|
|
141
|
-
return false;
|
|
147
|
+
if (!isDef(val)) return false;
|
|
142
148
|
return cnPhoneRE.test(val.toString());
|
|
143
149
|
};
|
|
144
150
|
const isTel = (val) => {
|
|
145
|
-
if (!isDef(val))
|
|
146
|
-
|
|
147
|
-
return cnTelRE.test(
|
|
151
|
+
if (!isDef(val)) return false;
|
|
152
|
+
const valStr = val.toString().replaceAll(" ", "");
|
|
153
|
+
return cnTelRE.test(valStr) || cnTelRE2.test(valStr);
|
|
148
154
|
};
|
|
149
155
|
const isEmail = (val) => {
|
|
150
|
-
if (!isDef(val))
|
|
151
|
-
|
|
152
|
-
const reg = /^[a-z\d](?:\w|-)+@[a-z\d]+\.[a-z]{2,5}$/i;
|
|
153
|
-
return reg.test(val);
|
|
156
|
+
if (!isDef(val)) return false;
|
|
157
|
+
return emailRE.test(val);
|
|
154
158
|
};
|
|
155
159
|
const isIdCard = (val, compatible = true) => {
|
|
156
|
-
if (!isDef(val))
|
|
157
|
-
|
|
158
|
-
const card15 = /^[1-9]\d{7}(?:0[1-9]|10|11|12)(?:[0-2][1-9]|10|20|30|31)\d{2}[\dX]$/i;
|
|
159
|
-
const card18 = /^[1-9]\d{5}(?:18|19|20)\d{2}(?:0[1-9]|1[0-2])(?:[0-2][1-9]|10|20|30|31)\d{3}[\dX]$/i;
|
|
160
|
-
return card18.test(val) || (compatible ? card15.test(val) : false);
|
|
160
|
+
if (!isDef(val)) return false;
|
|
161
|
+
return cnIdCard18Re.test(val) || (compatible ? cnIdCard15Re.test(val) : false);
|
|
161
162
|
};
|
|
162
163
|
const isNumeric = (val) => {
|
|
163
|
-
if (isDef(val))
|
|
164
|
-
return typeof val === "number" || /^\d+(?:\.\d+)?$/.test(val);
|
|
164
|
+
if (isDef(val)) return typeof val === "number" || /^\d+(?:\.\d+)?$/.test(val);
|
|
165
165
|
return false;
|
|
166
166
|
};
|
|
167
167
|
const checkImg = (ext) => {
|
|
@@ -169,8 +169,7 @@ const checkImg = (ext) => {
|
|
|
169
169
|
};
|
|
170
170
|
const nonASCII = (text) => /[^\x20-\x7E]/.test(text);
|
|
171
171
|
const isValidFileType = (file, type) => {
|
|
172
|
-
if (type === "*")
|
|
173
|
-
return true;
|
|
172
|
+
if (type === "*") return true;
|
|
174
173
|
const fileType = file.type;
|
|
175
174
|
const fileName = file.name;
|
|
176
175
|
function validate(item) {
|
|
@@ -192,52 +191,49 @@ const isValidFileType = (file, type) => {
|
|
|
192
191
|
return validate(type);
|
|
193
192
|
};
|
|
194
193
|
|
|
194
|
+
const isValidResCode = (res, code = 200) => res.code === code;
|
|
195
|
+
const isValidRes = (res, code) => isValidResCode(res, code) && isDef(res.data);
|
|
196
|
+
const isValidArrRes = (res, code) => isValidResCode(res, code) && Array.isArray(res.data);
|
|
197
|
+
const isValidPageRes = (res, code) => isValidResCode(res, code) && isDef(res.data) && Array.isArray(res.data.list || res.data.records);
|
|
198
|
+
|
|
195
199
|
const hideMiddle = (str) => {
|
|
196
|
-
if (!isDef(str))
|
|
197
|
-
return "";
|
|
200
|
+
if (!isDef(str)) return "";
|
|
198
201
|
const len = str.length;
|
|
199
|
-
if (len
|
|
200
|
-
return "*";
|
|
201
|
-
if (len === 2)
|
|
202
|
-
return "**";
|
|
202
|
+
if (len <= 2) return "*".repeat(len);
|
|
203
203
|
return str[0] + "*".repeat(len - 2) + str[len - 1];
|
|
204
204
|
};
|
|
205
205
|
const hideThird = (str) => {
|
|
206
|
-
if (!isDef(str))
|
|
207
|
-
return "";
|
|
206
|
+
if (!isDef(str)) return "";
|
|
208
207
|
const len = str.length;
|
|
208
|
+
if (len <= 2) return "*".repeat(len);
|
|
209
209
|
const partLen = Math.round(len / 3);
|
|
210
|
-
if (len === 1)
|
|
211
|
-
return "*";
|
|
212
|
-
if (len === 2)
|
|
213
|
-
return "**";
|
|
214
210
|
return str.slice(0, partLen) + "*".repeat(len - 2 * partLen) + str.slice(len - partLen);
|
|
215
211
|
};
|
|
216
212
|
const hideHead = (str, count) => {
|
|
217
|
-
if (!isDef(str))
|
|
218
|
-
return "";
|
|
213
|
+
if (!isDef(str)) return "";
|
|
219
214
|
const len = str.length;
|
|
215
|
+
if (len <= 1) return "*".repeat(len);
|
|
220
216
|
const cnt = count !== void 0 ? Math.max(Math.min(len, count), 0) : len - 1;
|
|
221
|
-
if (len === 1)
|
|
222
|
-
return "*";
|
|
223
217
|
return "*".repeat(cnt) + str.substring(cnt);
|
|
224
218
|
};
|
|
225
219
|
const hideTail = (str, count) => {
|
|
226
|
-
if (!isDef(str))
|
|
227
|
-
return "";
|
|
220
|
+
if (!isDef(str)) return "";
|
|
228
221
|
const len = str.length;
|
|
222
|
+
if (len <= 1) return "*".repeat(len);
|
|
229
223
|
const cnt = count !== void 0 ? Math.max(Math.min(len, count), 0) : len - 1;
|
|
230
|
-
if (len === 1)
|
|
231
|
-
return "*";
|
|
232
224
|
return str.substring(0, len - cnt) + "*".repeat(cnt);
|
|
233
225
|
};
|
|
234
226
|
const hidePhone = (phone) => {
|
|
235
227
|
if (phone) {
|
|
236
|
-
|
|
237
|
-
|
|
228
|
+
const phoneStr = phone.replaceAll(" ", "");
|
|
229
|
+
if (isPhone(phoneStr)) {
|
|
230
|
+
return phoneStr.replace(/^(\d{3})\d{4}(\d{4})$/, "$1****$2");
|
|
231
|
+
}
|
|
232
|
+
if (cnTelRE.test(phoneStr)) {
|
|
233
|
+
return phoneStr.replace(/^(0\d{2,3})-?\d{3,4}(\d{4})$/, "$1****$2");
|
|
238
234
|
}
|
|
239
|
-
if (
|
|
240
|
-
return
|
|
235
|
+
if (cnTelRE2.test(phoneStr)) {
|
|
236
|
+
return phoneStr.replace(/^\((0\d{2,3})\)\d{3,4}(\d{4})$/, "$1****$2");
|
|
241
237
|
}
|
|
242
238
|
return phone;
|
|
243
239
|
}
|
|
@@ -252,20 +248,6 @@ const hideCardNo = (cardNo, strong = true) => {
|
|
|
252
248
|
}
|
|
253
249
|
return "";
|
|
254
250
|
};
|
|
255
|
-
const hideName = (name) => {
|
|
256
|
-
if (name) {
|
|
257
|
-
let res = "";
|
|
258
|
-
for (let i = 0; i < name.length; i += 1) {
|
|
259
|
-
if (i === 0) {
|
|
260
|
-
res += "*";
|
|
261
|
-
} else {
|
|
262
|
-
res += name[i];
|
|
263
|
-
}
|
|
264
|
-
}
|
|
265
|
-
return res;
|
|
266
|
-
}
|
|
267
|
-
return "";
|
|
268
|
-
};
|
|
269
251
|
const hideSurname = (name) => {
|
|
270
252
|
return hideHead(name, 1);
|
|
271
253
|
};
|
|
@@ -274,13 +256,11 @@ const hideFirstName = (name) => {
|
|
|
274
256
|
};
|
|
275
257
|
const hideEmail = (email) => {
|
|
276
258
|
if (email) {
|
|
277
|
-
if (!email.includes("@"))
|
|
278
|
-
return email;
|
|
259
|
+
if (!email.includes("@")) return email;
|
|
279
260
|
const arr = email.split("@");
|
|
280
261
|
const name = arr[0];
|
|
281
262
|
const domain = arr[1];
|
|
282
|
-
if (!name || !domain)
|
|
283
|
-
return email;
|
|
263
|
+
if (!name || !domain) return email;
|
|
284
264
|
const len = name.length;
|
|
285
265
|
let newName;
|
|
286
266
|
if (len <= 3) {
|
|
@@ -295,33 +275,79 @@ const hideEmail = (email) => {
|
|
|
295
275
|
const hideBankCard = (bankCard) => {
|
|
296
276
|
if (bankCard) {
|
|
297
277
|
const len = bankCard.length;
|
|
298
|
-
if (len <= 10)
|
|
299
|
-
return bankCard;
|
|
278
|
+
if (len <= 10) return bankCard;
|
|
300
279
|
return bankCard.substring(0, 6) + "*".repeat(len - 10) + bankCard.substring(len - 4, len);
|
|
301
280
|
}
|
|
302
281
|
return "";
|
|
303
282
|
};
|
|
304
283
|
|
|
305
|
-
|
|
306
|
-
|
|
307
|
-
|
|
284
|
+
let __BASE_ATTACH_URL__;
|
|
285
|
+
function setBaseAttachUrl(baseUrl) {
|
|
286
|
+
__BASE_ATTACH_URL__ = baseUrl;
|
|
287
|
+
}
|
|
288
|
+
function getBaseAttachUrl() {
|
|
289
|
+
return __BASE_ATTACH_URL__;
|
|
290
|
+
}
|
|
291
|
+
|
|
292
|
+
function parseToJSON(str, reviverFn) {
|
|
293
|
+
return isJSONStr(str) ? JSON.parse(str, reviverFn) : null;
|
|
294
|
+
}
|
|
295
|
+
function parseJSON(str, reviverFn = reviver) {
|
|
296
|
+
return isJSONStr(str) ? JSON.parse(str, reviverFn) : null;
|
|
297
|
+
}
|
|
298
|
+
function stringifyJSON(value, replacerFn = replacer) {
|
|
299
|
+
return JSON.stringify(value, replacerFn);
|
|
300
|
+
}
|
|
301
|
+
function replacer(_key, value) {
|
|
302
|
+
if (isMap(value)) {
|
|
308
303
|
return {
|
|
309
304
|
dataType: "Map",
|
|
310
305
|
value: [...value]
|
|
311
306
|
};
|
|
312
307
|
}
|
|
308
|
+
if (isSet(value)) {
|
|
309
|
+
return {
|
|
310
|
+
dataType: "Set",
|
|
311
|
+
value: [...value]
|
|
312
|
+
};
|
|
313
|
+
}
|
|
314
|
+
if (isDate(value)) {
|
|
315
|
+
return {
|
|
316
|
+
dataType: "Date",
|
|
317
|
+
value: value.toISOString()
|
|
318
|
+
};
|
|
319
|
+
}
|
|
313
320
|
return value;
|
|
314
|
-
}
|
|
315
|
-
|
|
321
|
+
}
|
|
322
|
+
function reviver(_key, value) {
|
|
316
323
|
if (typeof value === "object" && value !== null) {
|
|
317
324
|
if (value.dataType === "Map") {
|
|
318
325
|
return new Map(value.value);
|
|
319
326
|
}
|
|
327
|
+
if (value.dataType === "Set") {
|
|
328
|
+
return new Set(value.value);
|
|
329
|
+
}
|
|
330
|
+
if (value.dataType === "Date") {
|
|
331
|
+
return new Date(value.value);
|
|
332
|
+
}
|
|
320
333
|
}
|
|
321
334
|
return value;
|
|
322
|
-
}
|
|
335
|
+
}
|
|
323
336
|
const filterObj = (obj, keys, reverse = false) => Object.fromEntries(Object.entries(obj).filter(([key]) => reverse ? !keys.includes(key) : keys.includes(key)));
|
|
324
337
|
|
|
338
|
+
const toThousands = (num) => {
|
|
339
|
+
const arr = num.toString().split(".");
|
|
340
|
+
const integer = arr[0]?.replace(/(\d)(?=(?:\d{3})+$)/g, "$1,");
|
|
341
|
+
if (arr.length > 1) return `${integer}.${arr[1]}`;
|
|
342
|
+
return integer;
|
|
343
|
+
};
|
|
344
|
+
const currencyFmt = (currency, maximumFractionDigits = 2) => {
|
|
345
|
+
if (!isDef(currency)) return "";
|
|
346
|
+
const num = Number(currency);
|
|
347
|
+
if (Number.isNaN(num)) return "";
|
|
348
|
+
return new Intl.NumberFormat("zh-CN", { style: "currency", currency: "CNY", maximumFractionDigits }).format(num);
|
|
349
|
+
};
|
|
350
|
+
|
|
325
351
|
dayjs.extend(localeData).locale("zh-cn", zhCN);
|
|
326
352
|
dayjs.extend(duration);
|
|
327
353
|
dayjs.extend(relativeTime);
|
|
@@ -330,19 +356,15 @@ dayjs.extend(objectSupport);
|
|
|
330
356
|
const dateFmt = (date, format = "YYYY-MM-DD HH:mm:ss") => {
|
|
331
357
|
const dd = dayjs(date);
|
|
332
358
|
let fmt = format;
|
|
333
|
-
if (!isDef(date) || !dd.isValid())
|
|
334
|
-
|
|
335
|
-
if (format === "
|
|
336
|
-
fmt = "YYYY-MM-DD";
|
|
337
|
-
if (format === "datetime")
|
|
338
|
-
fmt = "YYYY-MM-DD HH:mm:ss";
|
|
359
|
+
if (!isDef(date) || !dd.isValid()) return "";
|
|
360
|
+
if (format === "date") fmt = "YYYY-MM-DD";
|
|
361
|
+
if (format === "datetime") fmt = "YYYY-MM-DD HH:mm:ss";
|
|
339
362
|
return dd.format(fmt);
|
|
340
363
|
};
|
|
341
364
|
const dateDuration = (start, end) => {
|
|
342
365
|
const startDay = dayjs(start);
|
|
343
366
|
const endDay = dayjs(end);
|
|
344
|
-
if (!isDef(start) || !startDay.isValid() || !isDef(end) || !endDay.isValid())
|
|
345
|
-
return "";
|
|
367
|
+
if (!isDef(start) || !startDay.isValid() || !isDef(end) || !endDay.isValid()) return "";
|
|
346
368
|
const dd = dayjs.duration(endDay.diff(startDay));
|
|
347
369
|
const year = dd.years();
|
|
348
370
|
const month = dd.months();
|
|
@@ -355,34 +377,9 @@ const dateDuration = (start, end) => {
|
|
|
355
377
|
return dd.format(format);
|
|
356
378
|
};
|
|
357
379
|
|
|
358
|
-
let __BASE_ATTACH_URL__;
|
|
359
|
-
function setBaseAttachUrl(baseUrl) {
|
|
360
|
-
__BASE_ATTACH_URL__ = baseUrl;
|
|
361
|
-
}
|
|
362
|
-
function getBaseAttachUrl() {
|
|
363
|
-
return __BASE_ATTACH_URL__;
|
|
364
|
-
}
|
|
365
|
-
|
|
366
|
-
const toThousands = (num) => {
|
|
367
|
-
const arr = num.toString().split(".");
|
|
368
|
-
const integer = arr[0]?.replace(/(\d)(?=(?:\d{3})+$)/g, "$1,");
|
|
369
|
-
if (arr.length > 1)
|
|
370
|
-
return `${integer}.${arr[1]}`;
|
|
371
|
-
return integer;
|
|
372
|
-
};
|
|
373
|
-
const currencyFmt = (currency, maximumFractionDigits = 2) => {
|
|
374
|
-
if (!isDef(currency))
|
|
375
|
-
return "";
|
|
376
|
-
const num = Number(currency);
|
|
377
|
-
if (Number.isNaN(num))
|
|
378
|
-
return "";
|
|
379
|
-
return new Intl.NumberFormat("zh-CN", { style: "currency", currency: "CNY", maximumFractionDigits }).format(num);
|
|
380
|
-
};
|
|
381
|
-
|
|
382
380
|
const resUrl = (url) => {
|
|
383
|
-
if (!isDef(url))
|
|
384
|
-
|
|
385
|
-
if (/^https?:\/\//.test(url) || /^blob:/.test(url) || /^data:/.test(url)) {
|
|
381
|
+
if (!isDef(url)) return void 0;
|
|
382
|
+
if (/^https?:\/\//.test(url) || url.startsWith("blob:") || url.startsWith("data:")) {
|
|
386
383
|
return url;
|
|
387
384
|
}
|
|
388
385
|
const baseUrl = getBaseAttachUrl();
|
|
@@ -412,14 +409,12 @@ const attachFmt = (data) => {
|
|
|
412
409
|
attachList = data.filter(Boolean);
|
|
413
410
|
} else if (typeof data === "string") {
|
|
414
411
|
if (isArrStr(data)) {
|
|
415
|
-
attachList = (
|
|
412
|
+
attachList = (parseJSON(data) || []).filter(Boolean);
|
|
416
413
|
} else {
|
|
417
|
-
const jsonData =
|
|
414
|
+
const jsonData = parseJSON(data);
|
|
418
415
|
const prototypeJson = Object.prototype.toString.call(jsonData);
|
|
419
|
-
if (prototypeJson === "[object Object]")
|
|
420
|
-
|
|
421
|
-
else
|
|
422
|
-
attachList = [{ id: data, name: "name", uri: data, group: "default" }];
|
|
416
|
+
if (prototypeJson === "[object Object]") attachList = [jsonData].filter(Boolean);
|
|
417
|
+
else attachList = [{ id: data, name: "name", uri: data, group: "default" }];
|
|
423
418
|
}
|
|
424
419
|
} else if (prototype === "[object Object]") {
|
|
425
420
|
attachList = [data];
|
|
@@ -430,8 +425,7 @@ const attachFmt = (data) => {
|
|
|
430
425
|
const isNumberArray = (arr) => arr.every((item) => typeof item === "number");
|
|
431
426
|
const isStringArray = (arr) => arr.every((item) => typeof item === "string");
|
|
432
427
|
const naturalSort = (arr) => {
|
|
433
|
-
if (isNumberArray(arr))
|
|
434
|
-
return [...arr].sort((a, b) => a - b);
|
|
428
|
+
if (isNumberArray(arr)) return [...arr].sort((a, b) => a - b);
|
|
435
429
|
if (isStringArray(arr)) {
|
|
436
430
|
return [...arr].sort((a, b) => a.localeCompare(b, "zh-CN")).sort((a, b) => a.length - b.length);
|
|
437
431
|
}
|
|
@@ -483,8 +477,8 @@ const getHostEnv = () => {
|
|
|
483
477
|
};
|
|
484
478
|
const XOR_VAL = 1111;
|
|
485
479
|
const getCodeOfTime = (time) => Math.abs(new Date(time).getTime() ^ XOR_VAL);
|
|
486
|
-
const getCodeOfHour = () => getCodeOfTime(`${dateFmt( new Date(), "YYYY-MM-DD HH")}:00:00`);
|
|
480
|
+
const getCodeOfHour = () => getCodeOfTime(`${dateFmt(/* @__PURE__ */ new Date(), "YYYY-MM-DD HH")}:00:00`);
|
|
487
481
|
const getCodeOfDate = () => getCodeOfTime(dateFmt(/* @__PURE__ */ new Date(), "date"));
|
|
488
482
|
const getCodeOfMonth = () => getCodeOfTime(dateFmt(dayjs().endOf("month"), "date"));
|
|
489
483
|
|
|
490
|
-
export { attachFmt, camel2Kebab, camel2Pascal, camel2Snake, camel2Title, checkImg, currencyFmt, dateDuration, dateFmt, filterObj, fixiOSInputAutoZoomIn, getBaseAttachUrl, getCodeOfDate, getCodeOfHour, getCodeOfMonth, getHostEnv, getVariableType, hideBankCard, hideCardNo, hideEmail, hideFirstName, hideHead, hideMiddle,
|
|
484
|
+
export { attachFmt, camel2Kebab, camel2Pascal, camel2Snake, camel2Title, checkImg, cnIdCard15Re, cnIdCard18Re, cnPhoneRE, cnTelRE, cnTelRE2, cnUSCIRE, currencyFmt, dateDuration, dateFmt, emailRE, filterObj, fixiOSInputAutoZoomIn, getBaseAttachUrl, getCodeOfDate, getCodeOfHour, getCodeOfMonth, getHostEnv, getVariableType, hideBankCard, hideCardNo, hideEmail, hideFirstName, hideHead, hideMiddle, hidePhone, hideSurname, hideTail, hideThird, inBrowser, isArrStr, isArray, isBigInt, isBlob, isBoolean, isDate, isDef, isEmail, isEmpty, isError, isFile, isFunction, isIdCard, isJSONStr, isMap, isNull, isNumber, isNumeric, isObject, isPhone, isPromise, isRegExp, isSet, isString, isSymbol, isTel, isURL, isUSCI, isUndefined, isValidArrRes, isValidFileType, isValidKey, isValidPageRes, isValidRes, isValidResCode, isWeakMap, isWeakSet, jClear, jDebug, jError, jGroup, jGroupC, jGroupE, jInfo, jLog, jLogDedupe, jLogOnce, jTime, jTimeEnd, jWarn, kebab2Camel, kebab2Pascal, kebab2Snake, kebab2Title, naturalSort, naturalSortBy, nonASCII, parseJSON, parseToJSON, pascal2Camel, pascal2Kebab, pascal2Snake, pascal2Title, recoverFile, replacer, resUrl, reviver, setBaseAttachUrl, snake2Camel, snake2Kebab, snake2Pascal, snake2Title, stringifyJSON, title2Camel, title2Kebab, title2Pascal, title2Snake, toThousands, userAgent, waitTime };
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@jhqn/utils-core",
|
|
3
3
|
"type": "module",
|
|
4
|
-
"version": "0.0.3
|
|
4
|
+
"version": "0.0.3",
|
|
5
5
|
"author": "jade-gjz <jiangang.zhang@jaderd.com>",
|
|
6
6
|
"license": "MIT",
|
|
7
7
|
"homepage": "https://github.com/jaderd-jh/utils/tree/main/packages/core#readme",
|
|
@@ -37,7 +37,7 @@
|
|
|
37
37
|
"dist"
|
|
38
38
|
],
|
|
39
39
|
"dependencies": {
|
|
40
|
-
"dayjs": "^1.11.
|
|
40
|
+
"dayjs": "^1.11.13",
|
|
41
41
|
"detect-browser": "^5.3.0"
|
|
42
42
|
},
|
|
43
43
|
"scripts": {
|