@jhqn/utils-core 0.0.1-beta.23 → 0.0.1-beta.24
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 +96 -10
- package/dist/index.d.cts +738 -0
- package/dist/index.d.mts +738 -0
- package/dist/index.d.ts +139 -14
- package/dist/index.mjs +89 -12
- package/package.json +9 -5
package/dist/index.cjs
CHANGED
|
@@ -1,13 +1,13 @@
|
|
|
1
1
|
'use strict';
|
|
2
2
|
|
|
3
3
|
const detectBrowser = require('detect-browser');
|
|
4
|
-
const dayjs = require('dayjs
|
|
5
|
-
const localeData = require('dayjs/
|
|
6
|
-
const duration = require('dayjs/
|
|
7
|
-
const relativeTime = require('dayjs/
|
|
8
|
-
const customParseFormat = require('dayjs/
|
|
9
|
-
const objectSupport = require('dayjs/
|
|
10
|
-
const zhCN = require('dayjs/
|
|
4
|
+
const dayjs = require('dayjs');
|
|
5
|
+
const localeData = require('dayjs/plugin/localeData');
|
|
6
|
+
const duration = require('dayjs/plugin/duration');
|
|
7
|
+
const relativeTime = require('dayjs/plugin/relativeTime');
|
|
8
|
+
const customParseFormat = require('dayjs/plugin/customParseFormat');
|
|
9
|
+
const objectSupport = require('dayjs/plugin/objectSupport');
|
|
10
|
+
const zhCN = require('dayjs/locale/zh-cn');
|
|
11
11
|
|
|
12
12
|
function _interopDefaultCompat (e) { return e && typeof e === 'object' && 'default' in e ? e.default : e; }
|
|
13
13
|
|
|
@@ -76,6 +76,9 @@ const isNumeric = (val) => typeof val === "number" || /^\d+(?:\.\d+)?$/.test(val
|
|
|
76
76
|
const checkImg = (ext) => {
|
|
77
77
|
return /\.(?:jpg|jpeg|png|gif)$/.test((ext || "").toLowerCase());
|
|
78
78
|
};
|
|
79
|
+
const isEmpty = (val) => {
|
|
80
|
+
return !isDef(val) || val === "" || Array.isArray(val) && val.length === 0 || Object.prototype.toString.call(val) === "[object Object]" && Object.keys(val).length === 0 || val instanceof Map && val.size === 0 || val instanceof Set && val.size === 0;
|
|
81
|
+
};
|
|
79
82
|
const isJSONStr = (str) => {
|
|
80
83
|
try {
|
|
81
84
|
JSON.parse(str);
|
|
@@ -116,9 +119,10 @@ const isIdCard = (val) => {
|
|
|
116
119
|
return card15.test(val) || card18.test(val);
|
|
117
120
|
};
|
|
118
121
|
const nonASCII = (text) => /[^\x20-\x7E]/.test(text);
|
|
119
|
-
const
|
|
120
|
-
const
|
|
121
|
-
const
|
|
122
|
+
const isValidResCode = (res, code = 200) => res.code === code;
|
|
123
|
+
const isValidRes = (res, code) => isValidResCode(res, code) && isDef(res.data);
|
|
124
|
+
const isValidArrRes = (res, code) => isValidResCode(res, code) && Array.isArray(res.data);
|
|
125
|
+
const isValidPageRes = (res, code) => isValidResCode(res, code) && isDef(res.data) && Array.isArray(res.data.list || res.data.records);
|
|
122
126
|
const isValidFileType = (file, type) => {
|
|
123
127
|
if (type === "*")
|
|
124
128
|
return true;
|
|
@@ -341,16 +345,92 @@ const dateDuration = (start, end) => {
|
|
|
341
345
|
return dd.format(format);
|
|
342
346
|
};
|
|
343
347
|
|
|
348
|
+
let BASE_ATTACH_URL;
|
|
349
|
+
function setBaseAttachUrl(baseUrl) {
|
|
350
|
+
BASE_ATTACH_URL = baseUrl;
|
|
351
|
+
}
|
|
352
|
+
function getBaseAttachUrl() {
|
|
353
|
+
return BASE_ATTACH_URL;
|
|
354
|
+
}
|
|
355
|
+
if (undefined?.VITE_BASE_ATTACH_URL) {
|
|
356
|
+
setBaseAttachUrl(undefined.VITE_BASE_ATTACH_URL);
|
|
357
|
+
}
|
|
358
|
+
|
|
359
|
+
const toThousands = (num) => {
|
|
360
|
+
const arr = num.toString().split(".");
|
|
361
|
+
const integer = arr[0]?.replace(/(\d)(?=(?:\d{3})+$)/g, "$1,");
|
|
362
|
+
if (arr.length > 1)
|
|
363
|
+
return `${integer}.${arr[1]}`;
|
|
364
|
+
return integer;
|
|
365
|
+
};
|
|
366
|
+
const currencyFmt = (currency, fraction = 0) => {
|
|
367
|
+
if (!isDef(currency))
|
|
368
|
+
return "";
|
|
369
|
+
return new Intl.NumberFormat("zh-CN", { style: "currency", currency: "CNY", maximumFractionDigits: fraction }).format(
|
|
370
|
+
currency
|
|
371
|
+
);
|
|
372
|
+
};
|
|
373
|
+
|
|
374
|
+
const resUrl = (url) => {
|
|
375
|
+
if (!isDef(url))
|
|
376
|
+
return void 0;
|
|
377
|
+
if (/^https?:\/\//.test(url) || /^blob:/.test(url) || /^data:/.test(url)) {
|
|
378
|
+
return url;
|
|
379
|
+
}
|
|
380
|
+
const baseUrl = getBaseAttachUrl();
|
|
381
|
+
if (!isDef(baseUrl)) {
|
|
382
|
+
throw new Error("\u8BF7\u5148\u8BBE\u7F6E import.meta\u200B.env.VITE_BASE_ATTACH_URL");
|
|
383
|
+
}
|
|
384
|
+
return `${baseUrl}/${url}`.replace(/([^:]\/)\/+/g, "$1");
|
|
385
|
+
};
|
|
386
|
+
const recoverFile = (resource) => {
|
|
387
|
+
const { uri, url, ...item } = resource;
|
|
388
|
+
const validUrl = uri || url;
|
|
389
|
+
return {
|
|
390
|
+
...item,
|
|
391
|
+
url: resUrl(validUrl),
|
|
392
|
+
content: resUrl(validUrl),
|
|
393
|
+
uri: validUrl || "",
|
|
394
|
+
status: "done",
|
|
395
|
+
percent: 100
|
|
396
|
+
};
|
|
397
|
+
};
|
|
398
|
+
const attachFmt = (data) => {
|
|
399
|
+
let attachList = [];
|
|
400
|
+
const prototype = Object.prototype.toString.call(data);
|
|
401
|
+
if (!data)
|
|
402
|
+
attachList = [];
|
|
403
|
+
else if (Array.isArray(data))
|
|
404
|
+
attachList = data.filter(Boolean);
|
|
405
|
+
else if (typeof data === "string") {
|
|
406
|
+
if (isArrStr(data)) {
|
|
407
|
+
attachList = (parseToJSON(data) || []).filter(Boolean);
|
|
408
|
+
} else {
|
|
409
|
+
const jsonData = parseToJSON(data);
|
|
410
|
+
const prototypeJson = Object.prototype.toString.call(jsonData);
|
|
411
|
+
if (prototypeJson === "[object Object]")
|
|
412
|
+
attachList = [jsonData].filter(Boolean);
|
|
413
|
+
else
|
|
414
|
+
attachList = [{ id: data, name: "name", uri: data, group: "default" }];
|
|
415
|
+
}
|
|
416
|
+
} else if (prototype === "[object Object]")
|
|
417
|
+
attachList = [data];
|
|
418
|
+
return attachList.map(recoverFile);
|
|
419
|
+
};
|
|
420
|
+
|
|
344
421
|
exports.dayjs = dayjs__default;
|
|
422
|
+
exports.attachFmt = attachFmt;
|
|
345
423
|
exports.camel2Kebab = camel2Kebab;
|
|
346
424
|
exports.camel2Pascal = camel2Pascal;
|
|
347
425
|
exports.camel2Snake = camel2Snake;
|
|
348
426
|
exports.camel2Title = camel2Title;
|
|
349
427
|
exports.checkImg = checkImg;
|
|
428
|
+
exports.currencyFmt = currencyFmt;
|
|
350
429
|
exports.dateDuration = dateDuration;
|
|
351
430
|
exports.dateFmt = dateFmt;
|
|
352
431
|
exports.filterObj = filterObj;
|
|
353
432
|
exports.fixiOSInputAutoZoomIn = fixiOSInputAutoZoomIn;
|
|
433
|
+
exports.getBaseAttachUrl = getBaseAttachUrl;
|
|
354
434
|
exports.getHostEnv = getHostEnv;
|
|
355
435
|
exports.hideCardNo = hideCardNo;
|
|
356
436
|
exports.hideEmail = hideEmail;
|
|
@@ -366,6 +446,7 @@ exports.inBrowser = inBrowser;
|
|
|
366
446
|
exports.isArrStr = isArrStr;
|
|
367
447
|
exports.isDef = isDef;
|
|
368
448
|
exports.isEmail = isEmail;
|
|
449
|
+
exports.isEmpty = isEmpty;
|
|
369
450
|
exports.isIdCard = isIdCard;
|
|
370
451
|
exports.isJSONStr = isJSONStr;
|
|
371
452
|
exports.isNumeric = isNumeric;
|
|
@@ -376,6 +457,7 @@ exports.isValidFileType = isValidFileType;
|
|
|
376
457
|
exports.isValidKey = isValidKey;
|
|
377
458
|
exports.isValidPageRes = isValidPageRes;
|
|
378
459
|
exports.isValidRes = isValidRes;
|
|
460
|
+
exports.isValidResCode = isValidResCode;
|
|
379
461
|
exports.jClear = jClear;
|
|
380
462
|
exports.jDebug = jDebug;
|
|
381
463
|
exports.jError = jError;
|
|
@@ -397,8 +479,11 @@ exports.pascal2Camel = pascal2Camel;
|
|
|
397
479
|
exports.pascal2Kebab = pascal2Kebab;
|
|
398
480
|
exports.pascal2Snake = pascal2Snake;
|
|
399
481
|
exports.pascal2Title = pascal2Title;
|
|
482
|
+
exports.recoverFile = recoverFile;
|
|
400
483
|
exports.replacer = replacer;
|
|
484
|
+
exports.resUrl = resUrl;
|
|
401
485
|
exports.reviver = reviver;
|
|
486
|
+
exports.setBaseAttachUrl = setBaseAttachUrl;
|
|
402
487
|
exports.snake2Camel = snake2Camel;
|
|
403
488
|
exports.snake2Kebab = snake2Kebab;
|
|
404
489
|
exports.snake2Pascal = snake2Pascal;
|
|
@@ -407,5 +492,6 @@ exports.title2Camel = title2Camel;
|
|
|
407
492
|
exports.title2Kebab = title2Kebab;
|
|
408
493
|
exports.title2Pascal = title2Pascal;
|
|
409
494
|
exports.title2Snake = title2Snake;
|
|
495
|
+
exports.toThousands = toThousands;
|
|
410
496
|
exports.userAgent = userAgent;
|
|
411
497
|
exports.waitTime = waitTime;
|