@jhqn/utils-core 0.0.3-beta.7 → 0.0.3-beta.8
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 +66 -39
- package/dist/index.d.cts +132 -122
- package/dist/index.d.mts +132 -122
- package/dist/index.d.ts +132 -122
- package/dist/index.mjs +62 -36
- package/package.json +2 -2
package/dist/index.cjs
CHANGED
|
@@ -2,22 +2,22 @@
|
|
|
2
2
|
|
|
3
3
|
const detectBrowser = require('detect-browser');
|
|
4
4
|
const dayjs = require('dayjs');
|
|
5
|
-
const
|
|
6
|
-
const duration = require('dayjs/plugin/duration');
|
|
7
|
-
const relativeTime = require('dayjs/plugin/relativeTime');
|
|
5
|
+
const zhCN = require('dayjs/locale/zh-cn');
|
|
8
6
|
const customParseFormat = require('dayjs/plugin/customParseFormat');
|
|
7
|
+
const duration = require('dayjs/plugin/duration');
|
|
8
|
+
const localeData = require('dayjs/plugin/localeData');
|
|
9
9
|
const objectSupport = require('dayjs/plugin/objectSupport');
|
|
10
|
-
const
|
|
10
|
+
const relativeTime = require('dayjs/plugin/relativeTime');
|
|
11
11
|
|
|
12
12
|
function _interopDefaultCompat (e) { return e && typeof e === 'object' && 'default' in e ? e.default : e; }
|
|
13
13
|
|
|
14
14
|
const dayjs__default = /*#__PURE__*/_interopDefaultCompat(dayjs);
|
|
15
|
-
const
|
|
16
|
-
const duration__default = /*#__PURE__*/_interopDefaultCompat(duration);
|
|
17
|
-
const relativeTime__default = /*#__PURE__*/_interopDefaultCompat(relativeTime);
|
|
15
|
+
const zhCN__default = /*#__PURE__*/_interopDefaultCompat(zhCN);
|
|
18
16
|
const customParseFormat__default = /*#__PURE__*/_interopDefaultCompat(customParseFormat);
|
|
17
|
+
const duration__default = /*#__PURE__*/_interopDefaultCompat(duration);
|
|
18
|
+
const localeData__default = /*#__PURE__*/_interopDefaultCompat(localeData);
|
|
19
19
|
const objectSupport__default = /*#__PURE__*/_interopDefaultCompat(objectSupport);
|
|
20
|
-
const
|
|
20
|
+
const relativeTime__default = /*#__PURE__*/_interopDefaultCompat(relativeTime);
|
|
21
21
|
|
|
22
22
|
const snake2Kebab = (str) => str.replace(/_([a-z])/g, (_, letter) => `-${letter.toLowerCase()}`);
|
|
23
23
|
const snake2Pascal = (str) => str.replace(/_([a-z])/g, (_, letter) => letter.toUpperCase()).replace(/^[a-z]/, (letter) => letter.toUpperCase());
|
|
@@ -120,6 +120,7 @@ const isJSONStr = (str) => {
|
|
|
120
120
|
JSON.parse(str);
|
|
121
121
|
return true;
|
|
122
122
|
} catch (e) {
|
|
123
|
+
jError("isJSONStr", e);
|
|
123
124
|
return false;
|
|
124
125
|
}
|
|
125
126
|
}
|
|
@@ -130,6 +131,7 @@ const isArrStr = (str) => {
|
|
|
130
131
|
try {
|
|
131
132
|
return Array.isArray(JSON.parse(str));
|
|
132
133
|
} catch (e) {
|
|
134
|
+
jError("isArrStr", e);
|
|
133
135
|
return false;
|
|
134
136
|
}
|
|
135
137
|
}
|
|
@@ -140,13 +142,14 @@ const isEmpty = (val) => {
|
|
|
140
142
|
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;
|
|
141
143
|
};
|
|
142
144
|
|
|
143
|
-
const isValidResCode = (res, code = 200) => res.code === code;
|
|
144
|
-
const isValidRes = (res, code) => isValidResCode(res, code) && isDef(res.data);
|
|
145
|
-
const isValidArrRes = (res, code) => isValidResCode(res, code) && Array.isArray(res.data);
|
|
146
|
-
const isValidPageRes = (res, code) => isValidResCode(res, code) && isDef(res.data) && Array.isArray(res.data.list || res.data.records);
|
|
147
|
-
|
|
148
145
|
const cnPhoneRE = /^1[3-9]\d{9}$/;
|
|
149
146
|
const cnTelRE = /^0\d{9,11}$/;
|
|
147
|
+
const cnUSCIRE = /^[0-9A-HJ-NPQRTUWXY]{2}\d{6}[0-9A-HJ-NPQRTUWXY]{10}$/;
|
|
148
|
+
const isUSCI = (val) => {
|
|
149
|
+
if (!isDef(val))
|
|
150
|
+
return false;
|
|
151
|
+
return cnUSCIRE.test(val);
|
|
152
|
+
};
|
|
150
153
|
const isPhone = (val) => {
|
|
151
154
|
if (!isDef(val))
|
|
152
155
|
return false;
|
|
@@ -203,6 +206,11 @@ const isValidFileType = (file, type) => {
|
|
|
203
206
|
return validate(type);
|
|
204
207
|
};
|
|
205
208
|
|
|
209
|
+
const isValidResCode = (res, code = 200) => res.code === code;
|
|
210
|
+
const isValidRes = (res, code) => isValidResCode(res, code) && isDef(res.data);
|
|
211
|
+
const isValidArrRes = (res, code) => isValidResCode(res, code) && Array.isArray(res.data);
|
|
212
|
+
const isValidPageRes = (res, code) => isValidResCode(res, code) && isDef(res.data) && Array.isArray(res.data.list || res.data.records);
|
|
213
|
+
|
|
206
214
|
const hideMiddle = (str) => {
|
|
207
215
|
if (!isDef(str))
|
|
208
216
|
return "";
|
|
@@ -313,14 +321,34 @@ const hideBankCard = (bankCard) => {
|
|
|
313
321
|
return "";
|
|
314
322
|
};
|
|
315
323
|
|
|
324
|
+
let __BASE_ATTACH_URL__;
|
|
325
|
+
function setBaseAttachUrl(baseUrl) {
|
|
326
|
+
__BASE_ATTACH_URL__ = baseUrl;
|
|
327
|
+
}
|
|
328
|
+
function getBaseAttachUrl() {
|
|
329
|
+
return __BASE_ATTACH_URL__;
|
|
330
|
+
}
|
|
331
|
+
|
|
316
332
|
const parseToJSON = (str, reviver2) => isJSONStr(str) ? JSON.parse(str, reviver2) : null;
|
|
317
333
|
const replacer = (_, value) => {
|
|
318
|
-
if (value
|
|
334
|
+
if (isMap(value)) {
|
|
319
335
|
return {
|
|
320
336
|
dataType: "Map",
|
|
321
337
|
value: [...value]
|
|
322
338
|
};
|
|
323
339
|
}
|
|
340
|
+
if (isSet(value)) {
|
|
341
|
+
return {
|
|
342
|
+
dataType: "Set",
|
|
343
|
+
value: [...value]
|
|
344
|
+
};
|
|
345
|
+
}
|
|
346
|
+
if (isDate(value)) {
|
|
347
|
+
return {
|
|
348
|
+
dataType: "Date",
|
|
349
|
+
value: value.toISOString()
|
|
350
|
+
};
|
|
351
|
+
}
|
|
324
352
|
return value;
|
|
325
353
|
};
|
|
326
354
|
const reviver = (_, value) => {
|
|
@@ -328,11 +356,33 @@ const reviver = (_, value) => {
|
|
|
328
356
|
if (value.dataType === "Map") {
|
|
329
357
|
return new Map(value.value);
|
|
330
358
|
}
|
|
359
|
+
if (value.dataType === "Set") {
|
|
360
|
+
return new Set(value.value);
|
|
361
|
+
}
|
|
362
|
+
if (value.dataType === "Date") {
|
|
363
|
+
return new Date(value.value);
|
|
364
|
+
}
|
|
331
365
|
}
|
|
332
366
|
return value;
|
|
333
367
|
};
|
|
334
368
|
const filterObj = (obj, keys, reverse = false) => Object.fromEntries(Object.entries(obj).filter(([key]) => reverse ? !keys.includes(key) : keys.includes(key)));
|
|
335
369
|
|
|
370
|
+
const toThousands = (num) => {
|
|
371
|
+
const arr = num.toString().split(".");
|
|
372
|
+
const integer = arr[0]?.replace(/(\d)(?=(?:\d{3})+$)/g, "$1,");
|
|
373
|
+
if (arr.length > 1)
|
|
374
|
+
return `${integer}.${arr[1]}`;
|
|
375
|
+
return integer;
|
|
376
|
+
};
|
|
377
|
+
const currencyFmt = (currency, maximumFractionDigits = 2) => {
|
|
378
|
+
if (!isDef(currency))
|
|
379
|
+
return "";
|
|
380
|
+
const num = Number(currency);
|
|
381
|
+
if (Number.isNaN(num))
|
|
382
|
+
return "";
|
|
383
|
+
return new Intl.NumberFormat("zh-CN", { style: "currency", currency: "CNY", maximumFractionDigits }).format(num);
|
|
384
|
+
};
|
|
385
|
+
|
|
336
386
|
dayjs__default.extend(localeData__default).locale("zh-cn", zhCN__default);
|
|
337
387
|
dayjs__default.extend(duration__default);
|
|
338
388
|
dayjs__default.extend(relativeTime__default);
|
|
@@ -366,34 +416,10 @@ const dateDuration = (start, end) => {
|
|
|
366
416
|
return dd.format(format);
|
|
367
417
|
};
|
|
368
418
|
|
|
369
|
-
let __BASE_ATTACH_URL__;
|
|
370
|
-
function setBaseAttachUrl(baseUrl) {
|
|
371
|
-
__BASE_ATTACH_URL__ = baseUrl;
|
|
372
|
-
}
|
|
373
|
-
function getBaseAttachUrl() {
|
|
374
|
-
return __BASE_ATTACH_URL__;
|
|
375
|
-
}
|
|
376
|
-
|
|
377
|
-
const toThousands = (num) => {
|
|
378
|
-
const arr = num.toString().split(".");
|
|
379
|
-
const integer = arr[0]?.replace(/(\d)(?=(?:\d{3})+$)/g, "$1,");
|
|
380
|
-
if (arr.length > 1)
|
|
381
|
-
return `${integer}.${arr[1]}`;
|
|
382
|
-
return integer;
|
|
383
|
-
};
|
|
384
|
-
const currencyFmt = (currency, maximumFractionDigits = 2) => {
|
|
385
|
-
if (!isDef(currency))
|
|
386
|
-
return "";
|
|
387
|
-
const num = Number(currency);
|
|
388
|
-
if (Number.isNaN(num))
|
|
389
|
-
return "";
|
|
390
|
-
return new Intl.NumberFormat("zh-CN", { style: "currency", currency: "CNY", maximumFractionDigits }).format(num);
|
|
391
|
-
};
|
|
392
|
-
|
|
393
419
|
const resUrl = (url) => {
|
|
394
420
|
if (!isDef(url))
|
|
395
421
|
return void 0;
|
|
396
|
-
if (/^https?:\/\//.test(url) ||
|
|
422
|
+
if (/^https?:\/\//.test(url) || url.startsWith("blob:") || url.startsWith("data:")) {
|
|
397
423
|
return url;
|
|
398
424
|
}
|
|
399
425
|
const baseUrl = getBaseAttachUrl();
|
|
@@ -556,6 +582,7 @@ exports.isString = isString;
|
|
|
556
582
|
exports.isSymbol = isSymbol;
|
|
557
583
|
exports.isTel = isTel;
|
|
558
584
|
exports.isURL = isURL;
|
|
585
|
+
exports.isUSCI = isUSCI;
|
|
559
586
|
exports.isUndefined = isUndefined;
|
|
560
587
|
exports.isValidArrRes = isValidArrRes;
|
|
561
588
|
exports.isValidFileType = isValidFileType;
|
package/dist/index.d.cts
CHANGED
|
@@ -7,6 +7,59 @@ import { ConfigType } from 'dayjs';
|
|
|
7
7
|
export { Dayjs, default as dayjs } from 'dayjs';
|
|
8
8
|
export { detect } from 'detect-browser';
|
|
9
9
|
|
|
10
|
+
/**
|
|
11
|
+
* 数字或字符串
|
|
12
|
+
*/
|
|
13
|
+
type Numeric = number | string;
|
|
14
|
+
/**
|
|
15
|
+
* 可 Null
|
|
16
|
+
*/
|
|
17
|
+
type Nullable<T> = T | null;
|
|
18
|
+
/**
|
|
19
|
+
* 可 Undefined
|
|
20
|
+
*/
|
|
21
|
+
type Undefinable<T> = T | undefined;
|
|
22
|
+
/**
|
|
23
|
+
* 可 Null 或 Undefined
|
|
24
|
+
*/
|
|
25
|
+
type NullOrUndefinable<T> = Nullable<Undefinable<T>>;
|
|
26
|
+
/**
|
|
27
|
+
* alias for NullOrUndefinable
|
|
28
|
+
*/
|
|
29
|
+
type UnDef<T> = NullOrUndefinable<T>;
|
|
30
|
+
/**
|
|
31
|
+
* 请求结果
|
|
32
|
+
*/
|
|
33
|
+
type Res<T = any> = Service.Response<T>;
|
|
34
|
+
/**
|
|
35
|
+
* 分页请求结果数据
|
|
36
|
+
*/
|
|
37
|
+
type PageResData<T = any> = Service.PageResponseData<T>;
|
|
38
|
+
/**
|
|
39
|
+
* 分页请求结果
|
|
40
|
+
*/
|
|
41
|
+
type PageRes<T = any> = Service.PageResponse<T>;
|
|
42
|
+
/**
|
|
43
|
+
* 分页请求参数
|
|
44
|
+
*/
|
|
45
|
+
type PageReq<T extends Record<string, any> = NonNullable<unknown>> = Service.PageRequestParams<T>;
|
|
46
|
+
/**
|
|
47
|
+
* 可能是数组
|
|
48
|
+
*/
|
|
49
|
+
type MaybeArray<T = any> = T | Array<T>;
|
|
50
|
+
/**
|
|
51
|
+
* 枚举键值对
|
|
52
|
+
*/
|
|
53
|
+
type VK<T = string> = Record<string | number, T>;
|
|
54
|
+
/**
|
|
55
|
+
* 字典
|
|
56
|
+
*/
|
|
57
|
+
type Dict<T = string> = Record<string, T>;
|
|
58
|
+
/**
|
|
59
|
+
* 使某键可选
|
|
60
|
+
*/
|
|
61
|
+
type PartialBy<T, K extends keyof T> = Omit<T, K> & Partial<Pick<T, K>>;
|
|
62
|
+
|
|
10
63
|
/**
|
|
11
64
|
* snake2Kebab
|
|
12
65
|
* @param {string} str 字符串
|
|
@@ -217,59 +270,6 @@ declare const jLogDedupe: (...args: any[]) => void;
|
|
|
217
270
|
*/
|
|
218
271
|
declare const jLogOnce: (...args: any[]) => void;
|
|
219
272
|
|
|
220
|
-
/**
|
|
221
|
-
* 数字或字符串
|
|
222
|
-
*/
|
|
223
|
-
type Numeric = number | string;
|
|
224
|
-
/**
|
|
225
|
-
* 可 Null
|
|
226
|
-
*/
|
|
227
|
-
type Nullable<T> = T | null;
|
|
228
|
-
/**
|
|
229
|
-
* 可 Undefined
|
|
230
|
-
*/
|
|
231
|
-
type Undefinable<T> = T | undefined;
|
|
232
|
-
/**
|
|
233
|
-
* 可 Null 或 Undefined
|
|
234
|
-
*/
|
|
235
|
-
type NullOrUndefinable<T> = Nullable<Undefinable<T>>;
|
|
236
|
-
/**
|
|
237
|
-
* alias for NullOrUndefinable
|
|
238
|
-
*/
|
|
239
|
-
type UnDef<T> = NullOrUndefinable<T>;
|
|
240
|
-
/**
|
|
241
|
-
* 请求结果
|
|
242
|
-
*/
|
|
243
|
-
type Res<T = any> = Service.Response<T>;
|
|
244
|
-
/**
|
|
245
|
-
* 分页请求结果数据
|
|
246
|
-
*/
|
|
247
|
-
type PageResData<T = any> = Service.PageResponseData<T>;
|
|
248
|
-
/**
|
|
249
|
-
* 分页请求结果
|
|
250
|
-
*/
|
|
251
|
-
type PageRes<T = any> = Service.PageResponse<T>;
|
|
252
|
-
/**
|
|
253
|
-
* 分页请求参数
|
|
254
|
-
*/
|
|
255
|
-
type PageReq<T extends Record<string, any> = NonNullable<unknown>> = Service.PageRequestParams<T>;
|
|
256
|
-
/**
|
|
257
|
-
* 可能是数组
|
|
258
|
-
*/
|
|
259
|
-
type MaybeArray<T = any> = T | Array<T>;
|
|
260
|
-
/**
|
|
261
|
-
* 枚举键值对
|
|
262
|
-
*/
|
|
263
|
-
type VK<T = string> = Record<string | number, T>;
|
|
264
|
-
/**
|
|
265
|
-
* 字典
|
|
266
|
-
*/
|
|
267
|
-
type Dict<T = string> = Record<string, T>;
|
|
268
|
-
/**
|
|
269
|
-
* 使某键可选
|
|
270
|
-
*/
|
|
271
|
-
type PartialBy<T, K extends keyof T> = Omit<T, K> & Partial<Pick<T, K>>;
|
|
272
|
-
|
|
273
273
|
/**
|
|
274
274
|
* 隐藏中间部分
|
|
275
275
|
* @param {string} str 需要隐藏的字符串
|
|
@@ -408,6 +408,16 @@ declare const getCodeOfDate: () => number;
|
|
|
408
408
|
*/
|
|
409
409
|
declare const getCodeOfMonth: () => number;
|
|
410
410
|
|
|
411
|
+
/**
|
|
412
|
+
* 设置文件基本路径
|
|
413
|
+
* @param baseUrl
|
|
414
|
+
*/
|
|
415
|
+
declare function setBaseAttachUrl(baseUrl: string): void;
|
|
416
|
+
/**
|
|
417
|
+
* 获取文件基本路径
|
|
418
|
+
*/
|
|
419
|
+
declare function getBaseAttachUrl(): string;
|
|
420
|
+
|
|
411
421
|
/**
|
|
412
422
|
* Json字符串转对象
|
|
413
423
|
* @param str
|
|
@@ -436,13 +446,25 @@ declare const filterObj: (obj: Record<string, any>, keys: string[], reverse?: bo
|
|
|
436
446
|
[k: string]: any;
|
|
437
447
|
};
|
|
438
448
|
|
|
449
|
+
/**
|
|
450
|
+
* 千位分隔符
|
|
451
|
+
* @param num
|
|
452
|
+
*/
|
|
453
|
+
declare const toThousands: (num: number) => string | undefined;
|
|
454
|
+
/**
|
|
455
|
+
* 货币格式化
|
|
456
|
+
* @param {number | string | bigint} currency - 金额
|
|
457
|
+
* @param {number} [maximumFractionDigits] - 小数位数
|
|
458
|
+
*/
|
|
459
|
+
declare const currencyFmt: (currency: UnDef<Numeric | bigint>, maximumFractionDigits?: number) => string;
|
|
460
|
+
|
|
439
461
|
/**
|
|
440
462
|
* 格式化时间
|
|
441
463
|
* @param {import('dayjs').ConfigType} date 时间
|
|
442
464
|
* @param {string} format 格式
|
|
443
465
|
* @returns {string} 格式化后的时间
|
|
444
466
|
*/
|
|
445
|
-
declare const dateFmt: (date: ConfigType, format?: string |
|
|
467
|
+
declare const dateFmt: (date: ConfigType, format?: string | "date" | "datetime") => string;
|
|
446
468
|
/**
|
|
447
469
|
* 格式化时间间隔
|
|
448
470
|
* @param {import('dayjs').ConfigType} start 开始时间
|
|
@@ -450,28 +472,6 @@ declare const dateFmt: (date: ConfigType, format?: string | 'date' | 'datetime')
|
|
|
450
472
|
*/
|
|
451
473
|
declare const dateDuration: (start: ConfigType, end: ConfigType) => string;
|
|
452
474
|
|
|
453
|
-
/**
|
|
454
|
-
* 设置文件基本路径
|
|
455
|
-
* @param baseUrl
|
|
456
|
-
*/
|
|
457
|
-
declare function setBaseAttachUrl(baseUrl: string): void;
|
|
458
|
-
/**
|
|
459
|
-
* 获取文件基本路径
|
|
460
|
-
*/
|
|
461
|
-
declare function getBaseAttachUrl(): string;
|
|
462
|
-
|
|
463
|
-
/**
|
|
464
|
-
* 千位分隔符
|
|
465
|
-
* @param num
|
|
466
|
-
*/
|
|
467
|
-
declare const toThousands: (num: number) => string | undefined;
|
|
468
|
-
/**
|
|
469
|
-
* 货币格式化
|
|
470
|
-
* @param {number | string | bigint} currency - 金额
|
|
471
|
-
* @param {number} [maximumFractionDigits] - 小数位数
|
|
472
|
-
*/
|
|
473
|
-
declare const currencyFmt: (currency: UnDef<Numeric | bigint>, maximumFractionDigits?: number) => string;
|
|
474
|
-
|
|
475
475
|
type VantUploadFileStatus = '' | 'uploading' | 'done' | 'failed'
|
|
476
476
|
type AntdUploadFileStatus = 'removed' | 'uploading' | 'done' | 'error'
|
|
477
477
|
type ElementPlusUploadFileStatus = 'ready' | 'uploading' | 'success' | 'fail'
|
|
@@ -520,16 +520,16 @@ declare const recoverFile: (resource: Resource) => {
|
|
|
520
520
|
group: string;
|
|
521
521
|
id: string;
|
|
522
522
|
name: string;
|
|
523
|
-
size?: number
|
|
524
|
-
uid?: string
|
|
525
|
-
objectUrl?: string
|
|
526
|
-
isImage?: boolean
|
|
527
|
-
message?: string
|
|
528
|
-
deletable?: boolean
|
|
529
|
-
reupload?: boolean
|
|
530
|
-
fileName?: string
|
|
531
|
-
thumbUrl?: string
|
|
532
|
-
percentage?: number
|
|
523
|
+
size?: number;
|
|
524
|
+
uid?: string;
|
|
525
|
+
objectUrl?: string;
|
|
526
|
+
isImage?: boolean;
|
|
527
|
+
message?: string;
|
|
528
|
+
deletable?: boolean;
|
|
529
|
+
reupload?: boolean;
|
|
530
|
+
fileName?: string;
|
|
531
|
+
thumbUrl?: string;
|
|
532
|
+
percentage?: number;
|
|
533
533
|
};
|
|
534
534
|
/**
|
|
535
535
|
* 附件格式
|
|
@@ -544,16 +544,16 @@ declare const attachFmt: (data: UnDef<MaybeArray<Resource>> | string) => {
|
|
|
544
544
|
group: string;
|
|
545
545
|
id: string;
|
|
546
546
|
name: string;
|
|
547
|
-
size?: number
|
|
548
|
-
uid?: string
|
|
549
|
-
objectUrl?: string
|
|
550
|
-
isImage?: boolean
|
|
551
|
-
message?: string
|
|
552
|
-
deletable?: boolean
|
|
553
|
-
reupload?: boolean
|
|
554
|
-
fileName?: string
|
|
555
|
-
thumbUrl?: string
|
|
556
|
-
percentage?: number
|
|
547
|
+
size?: number;
|
|
548
|
+
uid?: string;
|
|
549
|
+
objectUrl?: string;
|
|
550
|
+
isImage?: boolean;
|
|
551
|
+
message?: string;
|
|
552
|
+
deletable?: boolean;
|
|
553
|
+
reupload?: boolean;
|
|
554
|
+
fileName?: string;
|
|
555
|
+
thumbUrl?: string;
|
|
556
|
+
percentage?: number;
|
|
557
557
|
}[];
|
|
558
558
|
|
|
559
559
|
/**
|
|
@@ -619,7 +619,7 @@ declare const isObject: (val: any) => val is Record<any, any>;
|
|
|
619
619
|
* 是否是数组
|
|
620
620
|
* @param {any} val 检测的目标
|
|
621
621
|
*/
|
|
622
|
-
declare const isArray: (val: any) => val is any
|
|
622
|
+
declare const isArray: (val: any) => val is Array<any>;
|
|
623
623
|
/**
|
|
624
624
|
* 是否是函数,但也有可能是Class
|
|
625
625
|
* @param {any} val 检测的目标
|
|
@@ -707,7 +707,7 @@ declare const isArrStr: (str: UnDef<string>) => boolean;
|
|
|
707
707
|
* ```
|
|
708
708
|
* @returns {boolean} boolean
|
|
709
709
|
*/
|
|
710
|
-
declare const isValidKey: (key: string | number | symbol, object: object) => key is
|
|
710
|
+
declare const isValidKey: (key: string | number | symbol, object: object) => key is keyof typeof object;
|
|
711
711
|
/**
|
|
712
712
|
* 是否是空值/空数组/空对象 null undefined '' [] {} Set Map
|
|
713
713
|
* @param val
|
|
@@ -715,30 +715,15 @@ declare const isValidKey: (key: string | number | symbol, object: object) => key
|
|
|
715
715
|
declare const isEmpty: (val: UnDef<Numeric | boolean | Record<any, any> | Array<any> | Set<any> | Map<any, any>>) => boolean;
|
|
716
716
|
|
|
717
717
|
/**
|
|
718
|
-
*
|
|
719
|
-
* @
|
|
720
|
-
*
|
|
721
|
-
|
|
722
|
-
|
|
723
|
-
|
|
724
|
-
*
|
|
725
|
-
* @param res
|
|
726
|
-
* @param code
|
|
727
|
-
*/
|
|
728
|
-
declare const isValidRes: (res: Res, code?: number) => boolean;
|
|
729
|
-
/**
|
|
730
|
-
* 校验接口数组返回内容
|
|
731
|
-
* @param res
|
|
732
|
-
* @param code
|
|
733
|
-
*/
|
|
734
|
-
declare const isValidArrRes: (res: Res<any[]>, code?: number) => boolean;
|
|
735
|
-
/**
|
|
736
|
-
* 校验接口分页返回内容
|
|
737
|
-
* @param res
|
|
738
|
-
* @param code
|
|
718
|
+
* 是否是[统一社会信用代码](https://zh.wikipedia.org/zh-cn/%E7%BB%9F%E4%B8%80%E7%A4%BE%E4%BC%9A%E4%BF%A1%E7%94%A8%E4%BB%A3%E7%A0%81)
|
|
719
|
+
* @example
|
|
720
|
+
* ```ts
|
|
721
|
+
* isUSCI('91350100M000100Y43') // true
|
|
722
|
+
* ```
|
|
723
|
+
* @param {UnDef<string>} val - 待校验的值
|
|
724
|
+
* @returns {boolean} 是否是统一社会信用代码
|
|
739
725
|
*/
|
|
740
|
-
declare const
|
|
741
|
-
|
|
726
|
+
declare const isUSCI: (val: UnDef<string>) => boolean;
|
|
742
727
|
/**
|
|
743
728
|
* 是否是中国手机号
|
|
744
729
|
* @param val
|
|
@@ -783,4 +768,29 @@ declare const nonASCII: (text: string) => boolean;
|
|
|
783
768
|
*/
|
|
784
769
|
declare const isValidFileType: (file: File, type: string) => boolean;
|
|
785
770
|
|
|
786
|
-
|
|
771
|
+
/**
|
|
772
|
+
* 校验接口返回code
|
|
773
|
+
* @param res
|
|
774
|
+
* @param code
|
|
775
|
+
*/
|
|
776
|
+
declare const isValidResCode: (res: Res, code?: number) => boolean;
|
|
777
|
+
/**
|
|
778
|
+
* 校验接口返回内容
|
|
779
|
+
* @param res
|
|
780
|
+
* @param code
|
|
781
|
+
*/
|
|
782
|
+
declare const isValidRes: (res: Res, code?: number) => boolean;
|
|
783
|
+
/**
|
|
784
|
+
* 校验接口数组返回内容
|
|
785
|
+
* @param res
|
|
786
|
+
* @param code
|
|
787
|
+
*/
|
|
788
|
+
declare const isValidArrRes: (res: Res<any[]>, code?: number) => boolean;
|
|
789
|
+
/**
|
|
790
|
+
* 校验接口分页返回内容
|
|
791
|
+
* @param res
|
|
792
|
+
* @param code
|
|
793
|
+
*/
|
|
794
|
+
declare const isValidPageRes: (res: PageRes, code?: number) => boolean;
|
|
795
|
+
|
|
796
|
+
export { type Dict, type MaybeArray, type NullOrUndefinable, type Nullable, type Numeric, type PageReq, type PageRes, type PageResData, type PartialBy, type Res, type UnDef, type Undefinable, type VK, attachFmt, camel2Kebab, camel2Pascal, camel2Snake, camel2Title, checkImg, currencyFmt, dateDuration, dateFmt, filterObj, fixiOSInputAutoZoomIn, getBaseAttachUrl, getCodeOfDate, getCodeOfHour, getCodeOfMonth, getHostEnv, getVariableType, hideBankCard, hideCardNo, hideEmail, hideFirstName, hideHead, hideMiddle, hideName, 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, parseToJSON, pascal2Camel, pascal2Kebab, pascal2Snake, pascal2Title, recoverFile, replacer, resUrl, reviver, setBaseAttachUrl, snake2Camel, snake2Kebab, snake2Pascal, snake2Title, title2Camel, title2Kebab, title2Pascal, title2Snake, toThousands, userAgent, waitTime };
|
package/dist/index.d.mts
CHANGED
|
@@ -7,6 +7,59 @@ import { ConfigType } from 'dayjs';
|
|
|
7
7
|
export { Dayjs, default as dayjs } from 'dayjs';
|
|
8
8
|
export { detect } from 'detect-browser';
|
|
9
9
|
|
|
10
|
+
/**
|
|
11
|
+
* 数字或字符串
|
|
12
|
+
*/
|
|
13
|
+
type Numeric = number | string;
|
|
14
|
+
/**
|
|
15
|
+
* 可 Null
|
|
16
|
+
*/
|
|
17
|
+
type Nullable<T> = T | null;
|
|
18
|
+
/**
|
|
19
|
+
* 可 Undefined
|
|
20
|
+
*/
|
|
21
|
+
type Undefinable<T> = T | undefined;
|
|
22
|
+
/**
|
|
23
|
+
* 可 Null 或 Undefined
|
|
24
|
+
*/
|
|
25
|
+
type NullOrUndefinable<T> = Nullable<Undefinable<T>>;
|
|
26
|
+
/**
|
|
27
|
+
* alias for NullOrUndefinable
|
|
28
|
+
*/
|
|
29
|
+
type UnDef<T> = NullOrUndefinable<T>;
|
|
30
|
+
/**
|
|
31
|
+
* 请求结果
|
|
32
|
+
*/
|
|
33
|
+
type Res<T = any> = Service.Response<T>;
|
|
34
|
+
/**
|
|
35
|
+
* 分页请求结果数据
|
|
36
|
+
*/
|
|
37
|
+
type PageResData<T = any> = Service.PageResponseData<T>;
|
|
38
|
+
/**
|
|
39
|
+
* 分页请求结果
|
|
40
|
+
*/
|
|
41
|
+
type PageRes<T = any> = Service.PageResponse<T>;
|
|
42
|
+
/**
|
|
43
|
+
* 分页请求参数
|
|
44
|
+
*/
|
|
45
|
+
type PageReq<T extends Record<string, any> = NonNullable<unknown>> = Service.PageRequestParams<T>;
|
|
46
|
+
/**
|
|
47
|
+
* 可能是数组
|
|
48
|
+
*/
|
|
49
|
+
type MaybeArray<T = any> = T | Array<T>;
|
|
50
|
+
/**
|
|
51
|
+
* 枚举键值对
|
|
52
|
+
*/
|
|
53
|
+
type VK<T = string> = Record<string | number, T>;
|
|
54
|
+
/**
|
|
55
|
+
* 字典
|
|
56
|
+
*/
|
|
57
|
+
type Dict<T = string> = Record<string, T>;
|
|
58
|
+
/**
|
|
59
|
+
* 使某键可选
|
|
60
|
+
*/
|
|
61
|
+
type PartialBy<T, K extends keyof T> = Omit<T, K> & Partial<Pick<T, K>>;
|
|
62
|
+
|
|
10
63
|
/**
|
|
11
64
|
* snake2Kebab
|
|
12
65
|
* @param {string} str 字符串
|
|
@@ -217,59 +270,6 @@ declare const jLogDedupe: (...args: any[]) => void;
|
|
|
217
270
|
*/
|
|
218
271
|
declare const jLogOnce: (...args: any[]) => void;
|
|
219
272
|
|
|
220
|
-
/**
|
|
221
|
-
* 数字或字符串
|
|
222
|
-
*/
|
|
223
|
-
type Numeric = number | string;
|
|
224
|
-
/**
|
|
225
|
-
* 可 Null
|
|
226
|
-
*/
|
|
227
|
-
type Nullable<T> = T | null;
|
|
228
|
-
/**
|
|
229
|
-
* 可 Undefined
|
|
230
|
-
*/
|
|
231
|
-
type Undefinable<T> = T | undefined;
|
|
232
|
-
/**
|
|
233
|
-
* 可 Null 或 Undefined
|
|
234
|
-
*/
|
|
235
|
-
type NullOrUndefinable<T> = Nullable<Undefinable<T>>;
|
|
236
|
-
/**
|
|
237
|
-
* alias for NullOrUndefinable
|
|
238
|
-
*/
|
|
239
|
-
type UnDef<T> = NullOrUndefinable<T>;
|
|
240
|
-
/**
|
|
241
|
-
* 请求结果
|
|
242
|
-
*/
|
|
243
|
-
type Res<T = any> = Service.Response<T>;
|
|
244
|
-
/**
|
|
245
|
-
* 分页请求结果数据
|
|
246
|
-
*/
|
|
247
|
-
type PageResData<T = any> = Service.PageResponseData<T>;
|
|
248
|
-
/**
|
|
249
|
-
* 分页请求结果
|
|
250
|
-
*/
|
|
251
|
-
type PageRes<T = any> = Service.PageResponse<T>;
|
|
252
|
-
/**
|
|
253
|
-
* 分页请求参数
|
|
254
|
-
*/
|
|
255
|
-
type PageReq<T extends Record<string, any> = NonNullable<unknown>> = Service.PageRequestParams<T>;
|
|
256
|
-
/**
|
|
257
|
-
* 可能是数组
|
|
258
|
-
*/
|
|
259
|
-
type MaybeArray<T = any> = T | Array<T>;
|
|
260
|
-
/**
|
|
261
|
-
* 枚举键值对
|
|
262
|
-
*/
|
|
263
|
-
type VK<T = string> = Record<string | number, T>;
|
|
264
|
-
/**
|
|
265
|
-
* 字典
|
|
266
|
-
*/
|
|
267
|
-
type Dict<T = string> = Record<string, T>;
|
|
268
|
-
/**
|
|
269
|
-
* 使某键可选
|
|
270
|
-
*/
|
|
271
|
-
type PartialBy<T, K extends keyof T> = Omit<T, K> & Partial<Pick<T, K>>;
|
|
272
|
-
|
|
273
273
|
/**
|
|
274
274
|
* 隐藏中间部分
|
|
275
275
|
* @param {string} str 需要隐藏的字符串
|
|
@@ -408,6 +408,16 @@ declare const getCodeOfDate: () => number;
|
|
|
408
408
|
*/
|
|
409
409
|
declare const getCodeOfMonth: () => number;
|
|
410
410
|
|
|
411
|
+
/**
|
|
412
|
+
* 设置文件基本路径
|
|
413
|
+
* @param baseUrl
|
|
414
|
+
*/
|
|
415
|
+
declare function setBaseAttachUrl(baseUrl: string): void;
|
|
416
|
+
/**
|
|
417
|
+
* 获取文件基本路径
|
|
418
|
+
*/
|
|
419
|
+
declare function getBaseAttachUrl(): string;
|
|
420
|
+
|
|
411
421
|
/**
|
|
412
422
|
* Json字符串转对象
|
|
413
423
|
* @param str
|
|
@@ -436,13 +446,25 @@ declare const filterObj: (obj: Record<string, any>, keys: string[], reverse?: bo
|
|
|
436
446
|
[k: string]: any;
|
|
437
447
|
};
|
|
438
448
|
|
|
449
|
+
/**
|
|
450
|
+
* 千位分隔符
|
|
451
|
+
* @param num
|
|
452
|
+
*/
|
|
453
|
+
declare const toThousands: (num: number) => string | undefined;
|
|
454
|
+
/**
|
|
455
|
+
* 货币格式化
|
|
456
|
+
* @param {number | string | bigint} currency - 金额
|
|
457
|
+
* @param {number} [maximumFractionDigits] - 小数位数
|
|
458
|
+
*/
|
|
459
|
+
declare const currencyFmt: (currency: UnDef<Numeric | bigint>, maximumFractionDigits?: number) => string;
|
|
460
|
+
|
|
439
461
|
/**
|
|
440
462
|
* 格式化时间
|
|
441
463
|
* @param {import('dayjs').ConfigType} date 时间
|
|
442
464
|
* @param {string} format 格式
|
|
443
465
|
* @returns {string} 格式化后的时间
|
|
444
466
|
*/
|
|
445
|
-
declare const dateFmt: (date: ConfigType, format?: string |
|
|
467
|
+
declare const dateFmt: (date: ConfigType, format?: string | "date" | "datetime") => string;
|
|
446
468
|
/**
|
|
447
469
|
* 格式化时间间隔
|
|
448
470
|
* @param {import('dayjs').ConfigType} start 开始时间
|
|
@@ -450,28 +472,6 @@ declare const dateFmt: (date: ConfigType, format?: string | 'date' | 'datetime')
|
|
|
450
472
|
*/
|
|
451
473
|
declare const dateDuration: (start: ConfigType, end: ConfigType) => string;
|
|
452
474
|
|
|
453
|
-
/**
|
|
454
|
-
* 设置文件基本路径
|
|
455
|
-
* @param baseUrl
|
|
456
|
-
*/
|
|
457
|
-
declare function setBaseAttachUrl(baseUrl: string): void;
|
|
458
|
-
/**
|
|
459
|
-
* 获取文件基本路径
|
|
460
|
-
*/
|
|
461
|
-
declare function getBaseAttachUrl(): string;
|
|
462
|
-
|
|
463
|
-
/**
|
|
464
|
-
* 千位分隔符
|
|
465
|
-
* @param num
|
|
466
|
-
*/
|
|
467
|
-
declare const toThousands: (num: number) => string | undefined;
|
|
468
|
-
/**
|
|
469
|
-
* 货币格式化
|
|
470
|
-
* @param {number | string | bigint} currency - 金额
|
|
471
|
-
* @param {number} [maximumFractionDigits] - 小数位数
|
|
472
|
-
*/
|
|
473
|
-
declare const currencyFmt: (currency: UnDef<Numeric | bigint>, maximumFractionDigits?: number) => string;
|
|
474
|
-
|
|
475
475
|
type VantUploadFileStatus = '' | 'uploading' | 'done' | 'failed'
|
|
476
476
|
type AntdUploadFileStatus = 'removed' | 'uploading' | 'done' | 'error'
|
|
477
477
|
type ElementPlusUploadFileStatus = 'ready' | 'uploading' | 'success' | 'fail'
|
|
@@ -520,16 +520,16 @@ declare const recoverFile: (resource: Resource) => {
|
|
|
520
520
|
group: string;
|
|
521
521
|
id: string;
|
|
522
522
|
name: string;
|
|
523
|
-
size?: number
|
|
524
|
-
uid?: string
|
|
525
|
-
objectUrl?: string
|
|
526
|
-
isImage?: boolean
|
|
527
|
-
message?: string
|
|
528
|
-
deletable?: boolean
|
|
529
|
-
reupload?: boolean
|
|
530
|
-
fileName?: string
|
|
531
|
-
thumbUrl?: string
|
|
532
|
-
percentage?: number
|
|
523
|
+
size?: number;
|
|
524
|
+
uid?: string;
|
|
525
|
+
objectUrl?: string;
|
|
526
|
+
isImage?: boolean;
|
|
527
|
+
message?: string;
|
|
528
|
+
deletable?: boolean;
|
|
529
|
+
reupload?: boolean;
|
|
530
|
+
fileName?: string;
|
|
531
|
+
thumbUrl?: string;
|
|
532
|
+
percentage?: number;
|
|
533
533
|
};
|
|
534
534
|
/**
|
|
535
535
|
* 附件格式
|
|
@@ -544,16 +544,16 @@ declare const attachFmt: (data: UnDef<MaybeArray<Resource>> | string) => {
|
|
|
544
544
|
group: string;
|
|
545
545
|
id: string;
|
|
546
546
|
name: string;
|
|
547
|
-
size?: number
|
|
548
|
-
uid?: string
|
|
549
|
-
objectUrl?: string
|
|
550
|
-
isImage?: boolean
|
|
551
|
-
message?: string
|
|
552
|
-
deletable?: boolean
|
|
553
|
-
reupload?: boolean
|
|
554
|
-
fileName?: string
|
|
555
|
-
thumbUrl?: string
|
|
556
|
-
percentage?: number
|
|
547
|
+
size?: number;
|
|
548
|
+
uid?: string;
|
|
549
|
+
objectUrl?: string;
|
|
550
|
+
isImage?: boolean;
|
|
551
|
+
message?: string;
|
|
552
|
+
deletable?: boolean;
|
|
553
|
+
reupload?: boolean;
|
|
554
|
+
fileName?: string;
|
|
555
|
+
thumbUrl?: string;
|
|
556
|
+
percentage?: number;
|
|
557
557
|
}[];
|
|
558
558
|
|
|
559
559
|
/**
|
|
@@ -619,7 +619,7 @@ declare const isObject: (val: any) => val is Record<any, any>;
|
|
|
619
619
|
* 是否是数组
|
|
620
620
|
* @param {any} val 检测的目标
|
|
621
621
|
*/
|
|
622
|
-
declare const isArray: (val: any) => val is any
|
|
622
|
+
declare const isArray: (val: any) => val is Array<any>;
|
|
623
623
|
/**
|
|
624
624
|
* 是否是函数,但也有可能是Class
|
|
625
625
|
* @param {any} val 检测的目标
|
|
@@ -707,7 +707,7 @@ declare const isArrStr: (str: UnDef<string>) => boolean;
|
|
|
707
707
|
* ```
|
|
708
708
|
* @returns {boolean} boolean
|
|
709
709
|
*/
|
|
710
|
-
declare const isValidKey: (key: string | number | symbol, object: object) => key is
|
|
710
|
+
declare const isValidKey: (key: string | number | symbol, object: object) => key is keyof typeof object;
|
|
711
711
|
/**
|
|
712
712
|
* 是否是空值/空数组/空对象 null undefined '' [] {} Set Map
|
|
713
713
|
* @param val
|
|
@@ -715,30 +715,15 @@ declare const isValidKey: (key: string | number | symbol, object: object) => key
|
|
|
715
715
|
declare const isEmpty: (val: UnDef<Numeric | boolean | Record<any, any> | Array<any> | Set<any> | Map<any, any>>) => boolean;
|
|
716
716
|
|
|
717
717
|
/**
|
|
718
|
-
*
|
|
719
|
-
* @
|
|
720
|
-
*
|
|
721
|
-
|
|
722
|
-
|
|
723
|
-
|
|
724
|
-
*
|
|
725
|
-
* @param res
|
|
726
|
-
* @param code
|
|
727
|
-
*/
|
|
728
|
-
declare const isValidRes: (res: Res, code?: number) => boolean;
|
|
729
|
-
/**
|
|
730
|
-
* 校验接口数组返回内容
|
|
731
|
-
* @param res
|
|
732
|
-
* @param code
|
|
733
|
-
*/
|
|
734
|
-
declare const isValidArrRes: (res: Res<any[]>, code?: number) => boolean;
|
|
735
|
-
/**
|
|
736
|
-
* 校验接口分页返回内容
|
|
737
|
-
* @param res
|
|
738
|
-
* @param code
|
|
718
|
+
* 是否是[统一社会信用代码](https://zh.wikipedia.org/zh-cn/%E7%BB%9F%E4%B8%80%E7%A4%BE%E4%BC%9A%E4%BF%A1%E7%94%A8%E4%BB%A3%E7%A0%81)
|
|
719
|
+
* @example
|
|
720
|
+
* ```ts
|
|
721
|
+
* isUSCI('91350100M000100Y43') // true
|
|
722
|
+
* ```
|
|
723
|
+
* @param {UnDef<string>} val - 待校验的值
|
|
724
|
+
* @returns {boolean} 是否是统一社会信用代码
|
|
739
725
|
*/
|
|
740
|
-
declare const
|
|
741
|
-
|
|
726
|
+
declare const isUSCI: (val: UnDef<string>) => boolean;
|
|
742
727
|
/**
|
|
743
728
|
* 是否是中国手机号
|
|
744
729
|
* @param val
|
|
@@ -783,4 +768,29 @@ declare const nonASCII: (text: string) => boolean;
|
|
|
783
768
|
*/
|
|
784
769
|
declare const isValidFileType: (file: File, type: string) => boolean;
|
|
785
770
|
|
|
786
|
-
|
|
771
|
+
/**
|
|
772
|
+
* 校验接口返回code
|
|
773
|
+
* @param res
|
|
774
|
+
* @param code
|
|
775
|
+
*/
|
|
776
|
+
declare const isValidResCode: (res: Res, code?: number) => boolean;
|
|
777
|
+
/**
|
|
778
|
+
* 校验接口返回内容
|
|
779
|
+
* @param res
|
|
780
|
+
* @param code
|
|
781
|
+
*/
|
|
782
|
+
declare const isValidRes: (res: Res, code?: number) => boolean;
|
|
783
|
+
/**
|
|
784
|
+
* 校验接口数组返回内容
|
|
785
|
+
* @param res
|
|
786
|
+
* @param code
|
|
787
|
+
*/
|
|
788
|
+
declare const isValidArrRes: (res: Res<any[]>, code?: number) => boolean;
|
|
789
|
+
/**
|
|
790
|
+
* 校验接口分页返回内容
|
|
791
|
+
* @param res
|
|
792
|
+
* @param code
|
|
793
|
+
*/
|
|
794
|
+
declare const isValidPageRes: (res: PageRes, code?: number) => boolean;
|
|
795
|
+
|
|
796
|
+
export { type Dict, type MaybeArray, type NullOrUndefinable, type Nullable, type Numeric, type PageReq, type PageRes, type PageResData, type PartialBy, type Res, type UnDef, type Undefinable, type VK, attachFmt, camel2Kebab, camel2Pascal, camel2Snake, camel2Title, checkImg, currencyFmt, dateDuration, dateFmt, filterObj, fixiOSInputAutoZoomIn, getBaseAttachUrl, getCodeOfDate, getCodeOfHour, getCodeOfMonth, getHostEnv, getVariableType, hideBankCard, hideCardNo, hideEmail, hideFirstName, hideHead, hideMiddle, hideName, 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, parseToJSON, pascal2Camel, pascal2Kebab, pascal2Snake, pascal2Title, recoverFile, replacer, resUrl, reviver, setBaseAttachUrl, snake2Camel, snake2Kebab, snake2Pascal, snake2Title, title2Camel, title2Kebab, title2Pascal, title2Snake, toThousands, userAgent, waitTime };
|
package/dist/index.d.ts
CHANGED
|
@@ -7,6 +7,59 @@ import { ConfigType } from 'dayjs';
|
|
|
7
7
|
export { Dayjs, default as dayjs } from 'dayjs';
|
|
8
8
|
export { detect } from 'detect-browser';
|
|
9
9
|
|
|
10
|
+
/**
|
|
11
|
+
* 数字或字符串
|
|
12
|
+
*/
|
|
13
|
+
type Numeric = number | string;
|
|
14
|
+
/**
|
|
15
|
+
* 可 Null
|
|
16
|
+
*/
|
|
17
|
+
type Nullable<T> = T | null;
|
|
18
|
+
/**
|
|
19
|
+
* 可 Undefined
|
|
20
|
+
*/
|
|
21
|
+
type Undefinable<T> = T | undefined;
|
|
22
|
+
/**
|
|
23
|
+
* 可 Null 或 Undefined
|
|
24
|
+
*/
|
|
25
|
+
type NullOrUndefinable<T> = Nullable<Undefinable<T>>;
|
|
26
|
+
/**
|
|
27
|
+
* alias for NullOrUndefinable
|
|
28
|
+
*/
|
|
29
|
+
type UnDef<T> = NullOrUndefinable<T>;
|
|
30
|
+
/**
|
|
31
|
+
* 请求结果
|
|
32
|
+
*/
|
|
33
|
+
type Res<T = any> = Service.Response<T>;
|
|
34
|
+
/**
|
|
35
|
+
* 分页请求结果数据
|
|
36
|
+
*/
|
|
37
|
+
type PageResData<T = any> = Service.PageResponseData<T>;
|
|
38
|
+
/**
|
|
39
|
+
* 分页请求结果
|
|
40
|
+
*/
|
|
41
|
+
type PageRes<T = any> = Service.PageResponse<T>;
|
|
42
|
+
/**
|
|
43
|
+
* 分页请求参数
|
|
44
|
+
*/
|
|
45
|
+
type PageReq<T extends Record<string, any> = NonNullable<unknown>> = Service.PageRequestParams<T>;
|
|
46
|
+
/**
|
|
47
|
+
* 可能是数组
|
|
48
|
+
*/
|
|
49
|
+
type MaybeArray<T = any> = T | Array<T>;
|
|
50
|
+
/**
|
|
51
|
+
* 枚举键值对
|
|
52
|
+
*/
|
|
53
|
+
type VK<T = string> = Record<string | number, T>;
|
|
54
|
+
/**
|
|
55
|
+
* 字典
|
|
56
|
+
*/
|
|
57
|
+
type Dict<T = string> = Record<string, T>;
|
|
58
|
+
/**
|
|
59
|
+
* 使某键可选
|
|
60
|
+
*/
|
|
61
|
+
type PartialBy<T, K extends keyof T> = Omit<T, K> & Partial<Pick<T, K>>;
|
|
62
|
+
|
|
10
63
|
/**
|
|
11
64
|
* snake2Kebab
|
|
12
65
|
* @param {string} str 字符串
|
|
@@ -217,59 +270,6 @@ declare const jLogDedupe: (...args: any[]) => void;
|
|
|
217
270
|
*/
|
|
218
271
|
declare const jLogOnce: (...args: any[]) => void;
|
|
219
272
|
|
|
220
|
-
/**
|
|
221
|
-
* 数字或字符串
|
|
222
|
-
*/
|
|
223
|
-
type Numeric = number | string;
|
|
224
|
-
/**
|
|
225
|
-
* 可 Null
|
|
226
|
-
*/
|
|
227
|
-
type Nullable<T> = T | null;
|
|
228
|
-
/**
|
|
229
|
-
* 可 Undefined
|
|
230
|
-
*/
|
|
231
|
-
type Undefinable<T> = T | undefined;
|
|
232
|
-
/**
|
|
233
|
-
* 可 Null 或 Undefined
|
|
234
|
-
*/
|
|
235
|
-
type NullOrUndefinable<T> = Nullable<Undefinable<T>>;
|
|
236
|
-
/**
|
|
237
|
-
* alias for NullOrUndefinable
|
|
238
|
-
*/
|
|
239
|
-
type UnDef<T> = NullOrUndefinable<T>;
|
|
240
|
-
/**
|
|
241
|
-
* 请求结果
|
|
242
|
-
*/
|
|
243
|
-
type Res<T = any> = Service.Response<T>;
|
|
244
|
-
/**
|
|
245
|
-
* 分页请求结果数据
|
|
246
|
-
*/
|
|
247
|
-
type PageResData<T = any> = Service.PageResponseData<T>;
|
|
248
|
-
/**
|
|
249
|
-
* 分页请求结果
|
|
250
|
-
*/
|
|
251
|
-
type PageRes<T = any> = Service.PageResponse<T>;
|
|
252
|
-
/**
|
|
253
|
-
* 分页请求参数
|
|
254
|
-
*/
|
|
255
|
-
type PageReq<T extends Record<string, any> = NonNullable<unknown>> = Service.PageRequestParams<T>;
|
|
256
|
-
/**
|
|
257
|
-
* 可能是数组
|
|
258
|
-
*/
|
|
259
|
-
type MaybeArray<T = any> = T | Array<T>;
|
|
260
|
-
/**
|
|
261
|
-
* 枚举键值对
|
|
262
|
-
*/
|
|
263
|
-
type VK<T = string> = Record<string | number, T>;
|
|
264
|
-
/**
|
|
265
|
-
* 字典
|
|
266
|
-
*/
|
|
267
|
-
type Dict<T = string> = Record<string, T>;
|
|
268
|
-
/**
|
|
269
|
-
* 使某键可选
|
|
270
|
-
*/
|
|
271
|
-
type PartialBy<T, K extends keyof T> = Omit<T, K> & Partial<Pick<T, K>>;
|
|
272
|
-
|
|
273
273
|
/**
|
|
274
274
|
* 隐藏中间部分
|
|
275
275
|
* @param {string} str 需要隐藏的字符串
|
|
@@ -408,6 +408,16 @@ declare const getCodeOfDate: () => number;
|
|
|
408
408
|
*/
|
|
409
409
|
declare const getCodeOfMonth: () => number;
|
|
410
410
|
|
|
411
|
+
/**
|
|
412
|
+
* 设置文件基本路径
|
|
413
|
+
* @param baseUrl
|
|
414
|
+
*/
|
|
415
|
+
declare function setBaseAttachUrl(baseUrl: string): void;
|
|
416
|
+
/**
|
|
417
|
+
* 获取文件基本路径
|
|
418
|
+
*/
|
|
419
|
+
declare function getBaseAttachUrl(): string;
|
|
420
|
+
|
|
411
421
|
/**
|
|
412
422
|
* Json字符串转对象
|
|
413
423
|
* @param str
|
|
@@ -436,13 +446,25 @@ declare const filterObj: (obj: Record<string, any>, keys: string[], reverse?: bo
|
|
|
436
446
|
[k: string]: any;
|
|
437
447
|
};
|
|
438
448
|
|
|
449
|
+
/**
|
|
450
|
+
* 千位分隔符
|
|
451
|
+
* @param num
|
|
452
|
+
*/
|
|
453
|
+
declare const toThousands: (num: number) => string | undefined;
|
|
454
|
+
/**
|
|
455
|
+
* 货币格式化
|
|
456
|
+
* @param {number | string | bigint} currency - 金额
|
|
457
|
+
* @param {number} [maximumFractionDigits] - 小数位数
|
|
458
|
+
*/
|
|
459
|
+
declare const currencyFmt: (currency: UnDef<Numeric | bigint>, maximumFractionDigits?: number) => string;
|
|
460
|
+
|
|
439
461
|
/**
|
|
440
462
|
* 格式化时间
|
|
441
463
|
* @param {import('dayjs').ConfigType} date 时间
|
|
442
464
|
* @param {string} format 格式
|
|
443
465
|
* @returns {string} 格式化后的时间
|
|
444
466
|
*/
|
|
445
|
-
declare const dateFmt: (date: ConfigType, format?: string |
|
|
467
|
+
declare const dateFmt: (date: ConfigType, format?: string | "date" | "datetime") => string;
|
|
446
468
|
/**
|
|
447
469
|
* 格式化时间间隔
|
|
448
470
|
* @param {import('dayjs').ConfigType} start 开始时间
|
|
@@ -450,28 +472,6 @@ declare const dateFmt: (date: ConfigType, format?: string | 'date' | 'datetime')
|
|
|
450
472
|
*/
|
|
451
473
|
declare const dateDuration: (start: ConfigType, end: ConfigType) => string;
|
|
452
474
|
|
|
453
|
-
/**
|
|
454
|
-
* 设置文件基本路径
|
|
455
|
-
* @param baseUrl
|
|
456
|
-
*/
|
|
457
|
-
declare function setBaseAttachUrl(baseUrl: string): void;
|
|
458
|
-
/**
|
|
459
|
-
* 获取文件基本路径
|
|
460
|
-
*/
|
|
461
|
-
declare function getBaseAttachUrl(): string;
|
|
462
|
-
|
|
463
|
-
/**
|
|
464
|
-
* 千位分隔符
|
|
465
|
-
* @param num
|
|
466
|
-
*/
|
|
467
|
-
declare const toThousands: (num: number) => string | undefined;
|
|
468
|
-
/**
|
|
469
|
-
* 货币格式化
|
|
470
|
-
* @param {number | string | bigint} currency - 金额
|
|
471
|
-
* @param {number} [maximumFractionDigits] - 小数位数
|
|
472
|
-
*/
|
|
473
|
-
declare const currencyFmt: (currency: UnDef<Numeric | bigint>, maximumFractionDigits?: number) => string;
|
|
474
|
-
|
|
475
475
|
type VantUploadFileStatus = '' | 'uploading' | 'done' | 'failed'
|
|
476
476
|
type AntdUploadFileStatus = 'removed' | 'uploading' | 'done' | 'error'
|
|
477
477
|
type ElementPlusUploadFileStatus = 'ready' | 'uploading' | 'success' | 'fail'
|
|
@@ -520,16 +520,16 @@ declare const recoverFile: (resource: Resource) => {
|
|
|
520
520
|
group: string;
|
|
521
521
|
id: string;
|
|
522
522
|
name: string;
|
|
523
|
-
size?: number
|
|
524
|
-
uid?: string
|
|
525
|
-
objectUrl?: string
|
|
526
|
-
isImage?: boolean
|
|
527
|
-
message?: string
|
|
528
|
-
deletable?: boolean
|
|
529
|
-
reupload?: boolean
|
|
530
|
-
fileName?: string
|
|
531
|
-
thumbUrl?: string
|
|
532
|
-
percentage?: number
|
|
523
|
+
size?: number;
|
|
524
|
+
uid?: string;
|
|
525
|
+
objectUrl?: string;
|
|
526
|
+
isImage?: boolean;
|
|
527
|
+
message?: string;
|
|
528
|
+
deletable?: boolean;
|
|
529
|
+
reupload?: boolean;
|
|
530
|
+
fileName?: string;
|
|
531
|
+
thumbUrl?: string;
|
|
532
|
+
percentage?: number;
|
|
533
533
|
};
|
|
534
534
|
/**
|
|
535
535
|
* 附件格式
|
|
@@ -544,16 +544,16 @@ declare const attachFmt: (data: UnDef<MaybeArray<Resource>> | string) => {
|
|
|
544
544
|
group: string;
|
|
545
545
|
id: string;
|
|
546
546
|
name: string;
|
|
547
|
-
size?: number
|
|
548
|
-
uid?: string
|
|
549
|
-
objectUrl?: string
|
|
550
|
-
isImage?: boolean
|
|
551
|
-
message?: string
|
|
552
|
-
deletable?: boolean
|
|
553
|
-
reupload?: boolean
|
|
554
|
-
fileName?: string
|
|
555
|
-
thumbUrl?: string
|
|
556
|
-
percentage?: number
|
|
547
|
+
size?: number;
|
|
548
|
+
uid?: string;
|
|
549
|
+
objectUrl?: string;
|
|
550
|
+
isImage?: boolean;
|
|
551
|
+
message?: string;
|
|
552
|
+
deletable?: boolean;
|
|
553
|
+
reupload?: boolean;
|
|
554
|
+
fileName?: string;
|
|
555
|
+
thumbUrl?: string;
|
|
556
|
+
percentage?: number;
|
|
557
557
|
}[];
|
|
558
558
|
|
|
559
559
|
/**
|
|
@@ -619,7 +619,7 @@ declare const isObject: (val: any) => val is Record<any, any>;
|
|
|
619
619
|
* 是否是数组
|
|
620
620
|
* @param {any} val 检测的目标
|
|
621
621
|
*/
|
|
622
|
-
declare const isArray: (val: any) => val is any
|
|
622
|
+
declare const isArray: (val: any) => val is Array<any>;
|
|
623
623
|
/**
|
|
624
624
|
* 是否是函数,但也有可能是Class
|
|
625
625
|
* @param {any} val 检测的目标
|
|
@@ -707,7 +707,7 @@ declare const isArrStr: (str: UnDef<string>) => boolean;
|
|
|
707
707
|
* ```
|
|
708
708
|
* @returns {boolean} boolean
|
|
709
709
|
*/
|
|
710
|
-
declare const isValidKey: (key: string | number | symbol, object: object) => key is
|
|
710
|
+
declare const isValidKey: (key: string | number | symbol, object: object) => key is keyof typeof object;
|
|
711
711
|
/**
|
|
712
712
|
* 是否是空值/空数组/空对象 null undefined '' [] {} Set Map
|
|
713
713
|
* @param val
|
|
@@ -715,30 +715,15 @@ declare const isValidKey: (key: string | number | symbol, object: object) => key
|
|
|
715
715
|
declare const isEmpty: (val: UnDef<Numeric | boolean | Record<any, any> | Array<any> | Set<any> | Map<any, any>>) => boolean;
|
|
716
716
|
|
|
717
717
|
/**
|
|
718
|
-
*
|
|
719
|
-
* @
|
|
720
|
-
*
|
|
721
|
-
|
|
722
|
-
|
|
723
|
-
|
|
724
|
-
*
|
|
725
|
-
* @param res
|
|
726
|
-
* @param code
|
|
727
|
-
*/
|
|
728
|
-
declare const isValidRes: (res: Res, code?: number) => boolean;
|
|
729
|
-
/**
|
|
730
|
-
* 校验接口数组返回内容
|
|
731
|
-
* @param res
|
|
732
|
-
* @param code
|
|
733
|
-
*/
|
|
734
|
-
declare const isValidArrRes: (res: Res<any[]>, code?: number) => boolean;
|
|
735
|
-
/**
|
|
736
|
-
* 校验接口分页返回内容
|
|
737
|
-
* @param res
|
|
738
|
-
* @param code
|
|
718
|
+
* 是否是[统一社会信用代码](https://zh.wikipedia.org/zh-cn/%E7%BB%9F%E4%B8%80%E7%A4%BE%E4%BC%9A%E4%BF%A1%E7%94%A8%E4%BB%A3%E7%A0%81)
|
|
719
|
+
* @example
|
|
720
|
+
* ```ts
|
|
721
|
+
* isUSCI('91350100M000100Y43') // true
|
|
722
|
+
* ```
|
|
723
|
+
* @param {UnDef<string>} val - 待校验的值
|
|
724
|
+
* @returns {boolean} 是否是统一社会信用代码
|
|
739
725
|
*/
|
|
740
|
-
declare const
|
|
741
|
-
|
|
726
|
+
declare const isUSCI: (val: UnDef<string>) => boolean;
|
|
742
727
|
/**
|
|
743
728
|
* 是否是中国手机号
|
|
744
729
|
* @param val
|
|
@@ -783,4 +768,29 @@ declare const nonASCII: (text: string) => boolean;
|
|
|
783
768
|
*/
|
|
784
769
|
declare const isValidFileType: (file: File, type: string) => boolean;
|
|
785
770
|
|
|
786
|
-
|
|
771
|
+
/**
|
|
772
|
+
* 校验接口返回code
|
|
773
|
+
* @param res
|
|
774
|
+
* @param code
|
|
775
|
+
*/
|
|
776
|
+
declare const isValidResCode: (res: Res, code?: number) => boolean;
|
|
777
|
+
/**
|
|
778
|
+
* 校验接口返回内容
|
|
779
|
+
* @param res
|
|
780
|
+
* @param code
|
|
781
|
+
*/
|
|
782
|
+
declare const isValidRes: (res: Res, code?: number) => boolean;
|
|
783
|
+
/**
|
|
784
|
+
* 校验接口数组返回内容
|
|
785
|
+
* @param res
|
|
786
|
+
* @param code
|
|
787
|
+
*/
|
|
788
|
+
declare const isValidArrRes: (res: Res<any[]>, code?: number) => boolean;
|
|
789
|
+
/**
|
|
790
|
+
* 校验接口分页返回内容
|
|
791
|
+
* @param res
|
|
792
|
+
* @param code
|
|
793
|
+
*/
|
|
794
|
+
declare const isValidPageRes: (res: PageRes, code?: number) => boolean;
|
|
795
|
+
|
|
796
|
+
export { type Dict, type MaybeArray, type NullOrUndefinable, type Nullable, type Numeric, type PageReq, type PageRes, type PageResData, type PartialBy, type Res, type UnDef, type Undefinable, type VK, attachFmt, camel2Kebab, camel2Pascal, camel2Snake, camel2Title, checkImg, currencyFmt, dateDuration, dateFmt, filterObj, fixiOSInputAutoZoomIn, getBaseAttachUrl, getCodeOfDate, getCodeOfHour, getCodeOfMonth, getHostEnv, getVariableType, hideBankCard, hideCardNo, hideEmail, hideFirstName, hideHead, hideMiddle, hideName, 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, parseToJSON, pascal2Camel, pascal2Kebab, pascal2Snake, pascal2Title, recoverFile, replacer, resUrl, reviver, setBaseAttachUrl, snake2Camel, snake2Kebab, snake2Pascal, snake2Title, title2Camel, title2Kebab, title2Pascal, title2Snake, toThousands, userAgent, waitTime };
|
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());
|
|
@@ -109,6 +109,7 @@ const isJSONStr = (str) => {
|
|
|
109
109
|
JSON.parse(str);
|
|
110
110
|
return true;
|
|
111
111
|
} catch (e) {
|
|
112
|
+
jError("isJSONStr", e);
|
|
112
113
|
return false;
|
|
113
114
|
}
|
|
114
115
|
}
|
|
@@ -119,6 +120,7 @@ const isArrStr = (str) => {
|
|
|
119
120
|
try {
|
|
120
121
|
return Array.isArray(JSON.parse(str));
|
|
121
122
|
} catch (e) {
|
|
123
|
+
jError("isArrStr", e);
|
|
122
124
|
return false;
|
|
123
125
|
}
|
|
124
126
|
}
|
|
@@ -129,13 +131,14 @@ const isEmpty = (val) => {
|
|
|
129
131
|
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
132
|
};
|
|
131
133
|
|
|
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
134
|
const cnPhoneRE = /^1[3-9]\d{9}$/;
|
|
138
135
|
const cnTelRE = /^0\d{9,11}$/;
|
|
136
|
+
const cnUSCIRE = /^[0-9A-HJ-NPQRTUWXY]{2}\d{6}[0-9A-HJ-NPQRTUWXY]{10}$/;
|
|
137
|
+
const isUSCI = (val) => {
|
|
138
|
+
if (!isDef(val))
|
|
139
|
+
return false;
|
|
140
|
+
return cnUSCIRE.test(val);
|
|
141
|
+
};
|
|
139
142
|
const isPhone = (val) => {
|
|
140
143
|
if (!isDef(val))
|
|
141
144
|
return false;
|
|
@@ -192,6 +195,11 @@ const isValidFileType = (file, type) => {
|
|
|
192
195
|
return validate(type);
|
|
193
196
|
};
|
|
194
197
|
|
|
198
|
+
const isValidResCode = (res, code = 200) => res.code === code;
|
|
199
|
+
const isValidRes = (res, code) => isValidResCode(res, code) && isDef(res.data);
|
|
200
|
+
const isValidArrRes = (res, code) => isValidResCode(res, code) && Array.isArray(res.data);
|
|
201
|
+
const isValidPageRes = (res, code) => isValidResCode(res, code) && isDef(res.data) && Array.isArray(res.data.list || res.data.records);
|
|
202
|
+
|
|
195
203
|
const hideMiddle = (str) => {
|
|
196
204
|
if (!isDef(str))
|
|
197
205
|
return "";
|
|
@@ -302,14 +310,34 @@ const hideBankCard = (bankCard) => {
|
|
|
302
310
|
return "";
|
|
303
311
|
};
|
|
304
312
|
|
|
313
|
+
let __BASE_ATTACH_URL__;
|
|
314
|
+
function setBaseAttachUrl(baseUrl) {
|
|
315
|
+
__BASE_ATTACH_URL__ = baseUrl;
|
|
316
|
+
}
|
|
317
|
+
function getBaseAttachUrl() {
|
|
318
|
+
return __BASE_ATTACH_URL__;
|
|
319
|
+
}
|
|
320
|
+
|
|
305
321
|
const parseToJSON = (str, reviver2) => isJSONStr(str) ? JSON.parse(str, reviver2) : null;
|
|
306
322
|
const replacer = (_, value) => {
|
|
307
|
-
if (value
|
|
323
|
+
if (isMap(value)) {
|
|
308
324
|
return {
|
|
309
325
|
dataType: "Map",
|
|
310
326
|
value: [...value]
|
|
311
327
|
};
|
|
312
328
|
}
|
|
329
|
+
if (isSet(value)) {
|
|
330
|
+
return {
|
|
331
|
+
dataType: "Set",
|
|
332
|
+
value: [...value]
|
|
333
|
+
};
|
|
334
|
+
}
|
|
335
|
+
if (isDate(value)) {
|
|
336
|
+
return {
|
|
337
|
+
dataType: "Date",
|
|
338
|
+
value: value.toISOString()
|
|
339
|
+
};
|
|
340
|
+
}
|
|
313
341
|
return value;
|
|
314
342
|
};
|
|
315
343
|
const reviver = (_, value) => {
|
|
@@ -317,11 +345,33 @@ const reviver = (_, value) => {
|
|
|
317
345
|
if (value.dataType === "Map") {
|
|
318
346
|
return new Map(value.value);
|
|
319
347
|
}
|
|
348
|
+
if (value.dataType === "Set") {
|
|
349
|
+
return new Set(value.value);
|
|
350
|
+
}
|
|
351
|
+
if (value.dataType === "Date") {
|
|
352
|
+
return new Date(value.value);
|
|
353
|
+
}
|
|
320
354
|
}
|
|
321
355
|
return value;
|
|
322
356
|
};
|
|
323
357
|
const filterObj = (obj, keys, reverse = false) => Object.fromEntries(Object.entries(obj).filter(([key]) => reverse ? !keys.includes(key) : keys.includes(key)));
|
|
324
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, maximumFractionDigits = 2) => {
|
|
367
|
+
if (!isDef(currency))
|
|
368
|
+
return "";
|
|
369
|
+
const num = Number(currency);
|
|
370
|
+
if (Number.isNaN(num))
|
|
371
|
+
return "";
|
|
372
|
+
return new Intl.NumberFormat("zh-CN", { style: "currency", currency: "CNY", maximumFractionDigits }).format(num);
|
|
373
|
+
};
|
|
374
|
+
|
|
325
375
|
dayjs.extend(localeData).locale("zh-cn", zhCN);
|
|
326
376
|
dayjs.extend(duration);
|
|
327
377
|
dayjs.extend(relativeTime);
|
|
@@ -355,34 +405,10 @@ const dateDuration = (start, end) => {
|
|
|
355
405
|
return dd.format(format);
|
|
356
406
|
};
|
|
357
407
|
|
|
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
408
|
const resUrl = (url) => {
|
|
383
409
|
if (!isDef(url))
|
|
384
410
|
return void 0;
|
|
385
|
-
if (/^https?:\/\//.test(url) ||
|
|
411
|
+
if (/^https?:\/\//.test(url) || url.startsWith("blob:") || url.startsWith("data:")) {
|
|
386
412
|
return url;
|
|
387
413
|
}
|
|
388
414
|
const baseUrl = getBaseAttachUrl();
|
|
@@ -487,4 +513,4 @@ const getCodeOfHour = () => getCodeOfTime(`${dateFmt( new Date(), "YYYY-MM-DD HH
|
|
|
487
513
|
const getCodeOfDate = () => getCodeOfTime(dateFmt(/* @__PURE__ */ new Date(), "date"));
|
|
488
514
|
const getCodeOfMonth = () => getCodeOfTime(dateFmt(dayjs().endOf("month"), "date"));
|
|
489
515
|
|
|
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, hideName, 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, 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, parseToJSON, pascal2Camel, pascal2Kebab, pascal2Snake, pascal2Title, recoverFile, replacer, resUrl, reviver, setBaseAttachUrl, snake2Camel, snake2Kebab, snake2Pascal, snake2Title, title2Camel, title2Kebab, title2Pascal, title2Snake, toThousands, userAgent, waitTime };
|
|
516
|
+
export { attachFmt, camel2Kebab, camel2Pascal, camel2Snake, camel2Title, checkImg, currencyFmt, dateDuration, dateFmt, filterObj, fixiOSInputAutoZoomIn, getBaseAttachUrl, getCodeOfDate, getCodeOfHour, getCodeOfMonth, getHostEnv, getVariableType, hideBankCard, hideCardNo, hideEmail, hideFirstName, hideHead, hideMiddle, hideName, 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, parseToJSON, pascal2Camel, pascal2Kebab, pascal2Snake, pascal2Title, recoverFile, replacer, resUrl, reviver, setBaseAttachUrl, snake2Camel, snake2Kebab, snake2Pascal, snake2Title, 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-beta.
|
|
4
|
+
"version": "0.0.3-beta.8",
|
|
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": {
|