@jhqn/utils-core 0.0.1-beta.24 → 0.0.1-beta.26
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/index.cjs +58 -26
- package/dist/index.d.cts +43 -24
- package/dist/index.d.mts +43 -24
- package/dist/index.d.ts +43 -24
- package/dist/index.mjs +58 -27
- package/package.json +1 -1
package/dist/index.cjs
CHANGED
|
@@ -72,7 +72,11 @@ const jClear = console.clear.bind(console);
|
|
|
72
72
|
const cnPhoneRE = /^1[3-9]\d{9}$/;
|
|
73
73
|
const cnTelRE = /^0\d{9,11}$/;
|
|
74
74
|
const isDef = (val) => val !== void 0 && val !== null;
|
|
75
|
-
const isNumeric = (val) =>
|
|
75
|
+
const isNumeric = (val) => {
|
|
76
|
+
if (isDef(val))
|
|
77
|
+
return typeof val === "number" || /^\d+(?:\.\d+)?$/.test(val);
|
|
78
|
+
return false;
|
|
79
|
+
};
|
|
76
80
|
const checkImg = (ext) => {
|
|
77
81
|
return /\.(?:jpg|jpeg|png|gif)$/.test((ext || "").toLowerCase());
|
|
78
82
|
};
|
|
@@ -80,19 +84,23 @@ const isEmpty = (val) => {
|
|
|
80
84
|
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
85
|
};
|
|
82
86
|
const isJSONStr = (str) => {
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
87
|
+
if (isDef(str))
|
|
88
|
+
try {
|
|
89
|
+
JSON.parse(str);
|
|
90
|
+
return true;
|
|
91
|
+
} catch (e) {
|
|
92
|
+
return false;
|
|
93
|
+
}
|
|
94
|
+
return false;
|
|
89
95
|
};
|
|
90
96
|
const isArrStr = (str) => {
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
97
|
+
if (isDef(str))
|
|
98
|
+
try {
|
|
99
|
+
return Array.isArray(JSON.parse(str));
|
|
100
|
+
} catch (e) {
|
|
101
|
+
return false;
|
|
102
|
+
}
|
|
103
|
+
return false;
|
|
96
104
|
};
|
|
97
105
|
const isValidKey = (key, object) => key in object;
|
|
98
106
|
const isPhone = (val) => {
|
|
@@ -111,12 +119,12 @@ const isEmail = (val) => {
|
|
|
111
119
|
const reg = /^[a-zA-Z\d](?:\w|-)+@[a-zA-Z\d]+\.[a-zA-Z]{2,5}$/;
|
|
112
120
|
return reg.test(val);
|
|
113
121
|
};
|
|
114
|
-
const isIdCard = (val) => {
|
|
122
|
+
const isIdCard = (val, compatible = true) => {
|
|
115
123
|
if (!isDef(val))
|
|
116
124
|
return false;
|
|
117
125
|
const card15 = /^[1-9]\d{7}(?:0[1-9]|10|11|12)(?:[0-2][1-9]|10|20|30|31)\d{2}[\dXx]$/;
|
|
118
126
|
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}[\dXx]$/;
|
|
119
|
-
return
|
|
127
|
+
return card18.test(val) || (compatible ? card15.test(val) : false);
|
|
120
128
|
};
|
|
121
129
|
const nonASCII = (text) => /[^\x20-\x7E]/.test(text);
|
|
122
130
|
const isValidResCode = (res, code = 200) => res.code === code;
|
|
@@ -168,21 +176,23 @@ const hideThird = (str) => {
|
|
|
168
176
|
return "**";
|
|
169
177
|
return str.slice(0, partLen) + "*".repeat(len - 2 * partLen) + str.slice(len - partLen);
|
|
170
178
|
};
|
|
171
|
-
const hideHead = (str) => {
|
|
179
|
+
const hideHead = (str, count) => {
|
|
172
180
|
if (!isDef(str))
|
|
173
181
|
return "";
|
|
174
182
|
const len = str.length;
|
|
183
|
+
const cnt = count !== void 0 ? Math.max(Math.min(len, count), 0) : len - 1;
|
|
175
184
|
if (len === 1)
|
|
176
185
|
return "*";
|
|
177
|
-
return "*".repeat(
|
|
186
|
+
return "*".repeat(cnt) + str.substring(cnt);
|
|
178
187
|
};
|
|
179
|
-
const hideTail = (str) => {
|
|
188
|
+
const hideTail = (str, count) => {
|
|
180
189
|
if (!isDef(str))
|
|
181
190
|
return "";
|
|
182
191
|
const len = str.length;
|
|
192
|
+
const cnt = count !== void 0 ? Math.max(Math.min(len, count), 0) : len - 1;
|
|
183
193
|
if (len === 1)
|
|
184
194
|
return "*";
|
|
185
|
-
return str
|
|
195
|
+
return str.substring(0, len - cnt) + "*".repeat(cnt);
|
|
186
196
|
};
|
|
187
197
|
const hidePhone = (phone) => {
|
|
188
198
|
if (phone) {
|
|
@@ -196,9 +206,12 @@ const hidePhone = (phone) => {
|
|
|
196
206
|
}
|
|
197
207
|
return "";
|
|
198
208
|
};
|
|
199
|
-
const hideCardNo = (cardNo) => {
|
|
209
|
+
const hideCardNo = (cardNo, strong = true) => {
|
|
200
210
|
if (cardNo) {
|
|
201
|
-
|
|
211
|
+
if (isIdCard(cardNo, false)) {
|
|
212
|
+
return strong ? hideMiddle(cardNo) : cardNo.replace(/^(.)\d{3}(.{8})\d{5}(.)$/, "$1***$2*****$3");
|
|
213
|
+
}
|
|
214
|
+
return cardNo;
|
|
202
215
|
}
|
|
203
216
|
return "";
|
|
204
217
|
};
|
|
@@ -217,7 +230,7 @@ const hideName = (name) => {
|
|
|
217
230
|
return "";
|
|
218
231
|
};
|
|
219
232
|
const hideSurname = (name) => {
|
|
220
|
-
return hideHead(name);
|
|
233
|
+
return hideHead(name, 1);
|
|
221
234
|
};
|
|
222
235
|
const hideFirstName = (name) => {
|
|
223
236
|
return hideTail(name);
|
|
@@ -225,14 +238,29 @@ const hideFirstName = (name) => {
|
|
|
225
238
|
const hideEmail = (email) => {
|
|
226
239
|
if (email) {
|
|
227
240
|
if (!email.includes("@"))
|
|
228
|
-
return
|
|
241
|
+
return email;
|
|
229
242
|
const arr = email.split("@");
|
|
230
243
|
const name = arr[0];
|
|
231
244
|
const domain = arr[1];
|
|
232
|
-
|
|
233
|
-
if (!len)
|
|
245
|
+
if (!name || !domain)
|
|
234
246
|
return email;
|
|
235
|
-
|
|
247
|
+
const len = name.length;
|
|
248
|
+
let newName;
|
|
249
|
+
if (len <= 3) {
|
|
250
|
+
newName = `${name}***`;
|
|
251
|
+
} else {
|
|
252
|
+
newName = hideTail(name, 3);
|
|
253
|
+
}
|
|
254
|
+
return `${newName}@${domain}`;
|
|
255
|
+
}
|
|
256
|
+
return "";
|
|
257
|
+
};
|
|
258
|
+
const hideBankCard = (bankCard) => {
|
|
259
|
+
if (bankCard) {
|
|
260
|
+
const len = bankCard.length;
|
|
261
|
+
if (len <= 10)
|
|
262
|
+
return bankCard;
|
|
263
|
+
return bankCard.substring(0, 6) + "*".repeat(len - 10) + bankCard.substring(len - 4, len);
|
|
236
264
|
}
|
|
237
265
|
return "";
|
|
238
266
|
};
|
|
@@ -366,8 +394,11 @@ const toThousands = (num) => {
|
|
|
366
394
|
const currencyFmt = (currency, fraction = 0) => {
|
|
367
395
|
if (!isDef(currency))
|
|
368
396
|
return "";
|
|
397
|
+
const num = Number(currency);
|
|
398
|
+
if (Number.isNaN(num))
|
|
399
|
+
return "";
|
|
369
400
|
return new Intl.NumberFormat("zh-CN", { style: "currency", currency: "CNY", maximumFractionDigits: fraction }).format(
|
|
370
|
-
|
|
401
|
+
num
|
|
371
402
|
);
|
|
372
403
|
};
|
|
373
404
|
|
|
@@ -432,6 +463,7 @@ exports.filterObj = filterObj;
|
|
|
432
463
|
exports.fixiOSInputAutoZoomIn = fixiOSInputAutoZoomIn;
|
|
433
464
|
exports.getBaseAttachUrl = getBaseAttachUrl;
|
|
434
465
|
exports.getHostEnv = getHostEnv;
|
|
466
|
+
exports.hideBankCard = hideBankCard;
|
|
435
467
|
exports.hideCardNo = hideCardNo;
|
|
436
468
|
exports.hideEmail = hideEmail;
|
|
437
469
|
exports.hideFirstName = hideFirstName;
|
package/dist/index.d.cts
CHANGED
|
@@ -221,6 +221,10 @@ declare type Undefinable<T> = T | undefined;
|
|
|
221
221
|
* 可 Null 或 Undefined
|
|
222
222
|
*/
|
|
223
223
|
declare type NullOrUndefinable<T> = Nullable<Undefinable<T>>;
|
|
224
|
+
/**
|
|
225
|
+
* alias for NullOrUndefinable
|
|
226
|
+
*/
|
|
227
|
+
declare type UnDef<T> = NullOrUndefinable<T>;
|
|
224
228
|
/**
|
|
225
229
|
* 请求结果
|
|
226
230
|
*/
|
|
@@ -242,53 +246,61 @@ declare type MaybeArray<T = any> = T | Array<T>;
|
|
|
242
246
|
* 隐藏中间部分
|
|
243
247
|
* @param {string} str 需要隐藏的字符串
|
|
244
248
|
*/
|
|
245
|
-
declare const hideMiddle: (str:
|
|
249
|
+
declare const hideMiddle: (str: UnDef<string>) => string;
|
|
246
250
|
/**
|
|
247
251
|
* 隐藏首尾仅保留中间3分之1
|
|
248
252
|
* @param {string} str 需要隐藏的字符串
|
|
249
253
|
*/
|
|
250
|
-
declare const hideThird: (str:
|
|
254
|
+
declare const hideThird: (str: UnDef<string>) => string;
|
|
251
255
|
/**
|
|
252
256
|
* 隐藏首部
|
|
253
257
|
* @param {string} str 需要隐藏的字符串
|
|
258
|
+
* @param {number} count 隐藏的字符数
|
|
254
259
|
*/
|
|
255
|
-
declare const hideHead: (str:
|
|
260
|
+
declare const hideHead: (str: UnDef<string>, count?: number) => string;
|
|
256
261
|
/**
|
|
257
262
|
* 隐藏尾部
|
|
258
263
|
* @param {string} str 需要隐藏的字符串
|
|
264
|
+
* @param {number} count 隐藏的字符数
|
|
259
265
|
*/
|
|
260
|
-
declare const hideTail: (str:
|
|
266
|
+
declare const hideTail: (str: UnDef<string>, count?: number) => string;
|
|
261
267
|
/**
|
|
262
268
|
* 隐藏手机号
|
|
263
269
|
* @param {string} phone 手机号
|
|
264
270
|
*/
|
|
265
|
-
declare const hidePhone: (phone:
|
|
271
|
+
declare const hidePhone: (phone: UnDef<string>) => string;
|
|
266
272
|
/**
|
|
267
273
|
* 隐藏身份证号
|
|
268
274
|
* @param {string} cardNo 身份证号
|
|
275
|
+
* @param {boolean} strong 是否强化隐藏
|
|
269
276
|
*/
|
|
270
|
-
declare const hideCardNo: (cardNo:
|
|
277
|
+
declare const hideCardNo: (cardNo: UnDef<string>, strong?: boolean) => string;
|
|
271
278
|
/**
|
|
272
279
|
* 隐藏姓名第一个字
|
|
273
280
|
* @param {string} name 姓名
|
|
274
281
|
* @deprecated 请使用 hideSurname
|
|
275
282
|
*/
|
|
276
|
-
declare const hideName: (name:
|
|
283
|
+
declare const hideName: (name: UnDef<string>) => string;
|
|
277
284
|
/**
|
|
278
285
|
* 隐藏姓氏
|
|
279
286
|
* @param {string} name 姓名
|
|
280
287
|
*/
|
|
281
|
-
declare const hideSurname: (name:
|
|
288
|
+
declare const hideSurname: (name: UnDef<string>) => string;
|
|
282
289
|
/**
|
|
283
290
|
* 隐藏名字
|
|
284
291
|
* @param {string} name 姓名
|
|
285
292
|
*/
|
|
286
|
-
declare const hideFirstName: (name:
|
|
293
|
+
declare const hideFirstName: (name: UnDef<string>) => string;
|
|
287
294
|
/**
|
|
288
295
|
* 隐藏邮箱
|
|
289
296
|
* @param {string} email 邮箱
|
|
290
297
|
*/
|
|
291
|
-
declare const hideEmail: (email:
|
|
298
|
+
declare const hideEmail: (email: UnDef<string>) => string;
|
|
299
|
+
/**
|
|
300
|
+
* 隐藏银行卡号
|
|
301
|
+
* @param {string} bankCard 银行卡号
|
|
302
|
+
*/
|
|
303
|
+
declare const hideBankCard: (bankCard: UnDef<string>) => string;
|
|
292
304
|
|
|
293
305
|
/**
|
|
294
306
|
* 判断是否是浏览器环境
|
|
@@ -549,7 +561,7 @@ declare const toThousands: (num: number) => string | undefined;
|
|
|
549
561
|
* @param currency
|
|
550
562
|
* @param fraction
|
|
551
563
|
*/
|
|
552
|
-
declare const currencyFmt: (currency:
|
|
564
|
+
declare const currencyFmt: (currency: UnDef<Numeric | bigint>, fraction?: number) => string;
|
|
553
565
|
|
|
554
566
|
type VantUploadFileStatus = '' | 'uploading' | 'done' | 'failed'
|
|
555
567
|
type AntdUploadFileStatus = 'removed' | 'uploading' | 'done' | 'error'
|
|
@@ -607,14 +619,17 @@ declare const recoverFile: (resource: Resource) => {
|
|
|
607
619
|
deletable?: boolean | undefined;
|
|
608
620
|
reupload?: boolean | undefined;
|
|
609
621
|
fileName?: string | undefined;
|
|
610
|
-
thumbUrl?: string | undefined;
|
|
622
|
+
thumbUrl?: string | undefined; /**
|
|
623
|
+
* 统一文件字段内容
|
|
624
|
+
* @param resource
|
|
625
|
+
*/
|
|
611
626
|
percentage?: number | undefined;
|
|
612
627
|
};
|
|
613
628
|
/**
|
|
614
629
|
* 附件格式
|
|
615
630
|
* @param data
|
|
616
631
|
*/
|
|
617
|
-
declare const attachFmt: (data:
|
|
632
|
+
declare const attachFmt: (data: UnDef<MaybeArray<Resource>> | string) => {
|
|
618
633
|
url: string | undefined;
|
|
619
634
|
content: string | undefined;
|
|
620
635
|
uri: string;
|
|
@@ -631,7 +646,10 @@ declare const attachFmt: (data: NullOrUndefinable<MaybeArray<Resource>> | string
|
|
|
631
646
|
deletable?: boolean | undefined;
|
|
632
647
|
reupload?: boolean | undefined;
|
|
633
648
|
fileName?: string | undefined;
|
|
634
|
-
thumbUrl?: string | undefined;
|
|
649
|
+
thumbUrl?: string | undefined; /**
|
|
650
|
+
* 统一文件字段内容
|
|
651
|
+
* @param resource
|
|
652
|
+
*/
|
|
635
653
|
percentage?: number | undefined;
|
|
636
654
|
}[];
|
|
637
655
|
|
|
@@ -644,7 +662,7 @@ declare const isDef: <T>(val: T) => val is NonNullable<T>;
|
|
|
644
662
|
* 是否是数字或字符
|
|
645
663
|
* @param val
|
|
646
664
|
*/
|
|
647
|
-
declare const isNumeric: (val: Numeric) => val is string;
|
|
665
|
+
declare const isNumeric: (val: UnDef<Numeric>) => val is string;
|
|
648
666
|
/**
|
|
649
667
|
* 是否是需要的图片格式
|
|
650
668
|
* @param ext
|
|
@@ -654,17 +672,17 @@ declare const checkImg: (ext?: string) => boolean;
|
|
|
654
672
|
* 是否是空值/空数组/空对象 null undefined '' [] {} Set Map
|
|
655
673
|
* @param val
|
|
656
674
|
*/
|
|
657
|
-
declare const isEmpty: (val:
|
|
675
|
+
declare const isEmpty: (val: UnDef<Numeric | boolean | Record<any, any> | Array<any> | Set<any> | Map<any, any>>) => boolean;
|
|
658
676
|
/**
|
|
659
677
|
* 判断是否合法JSON字符串
|
|
660
678
|
* @param str
|
|
661
679
|
*/
|
|
662
|
-
declare const isJSONStr: (str: string) => boolean;
|
|
680
|
+
declare const isJSONStr: (str: UnDef<string>) => boolean;
|
|
663
681
|
/**
|
|
664
682
|
* 判断是否合法JSON数组字符串
|
|
665
683
|
* @param str
|
|
666
684
|
*/
|
|
667
|
-
declare const isArrStr: (str: string) => boolean;
|
|
685
|
+
declare const isArrStr: (str: UnDef<string>) => boolean;
|
|
668
686
|
/**
|
|
669
687
|
* 判断是否有效的key
|
|
670
688
|
* @param {string | number | symbol} key 键名
|
|
@@ -682,22 +700,23 @@ declare const isValidKey: (key: string | number | symbol, object: object) => key
|
|
|
682
700
|
* 是否是中国手机号
|
|
683
701
|
* @param val
|
|
684
702
|
*/
|
|
685
|
-
declare const isPhone: (val:
|
|
703
|
+
declare const isPhone: (val: UnDef<Numeric>) => boolean;
|
|
686
704
|
/**
|
|
687
705
|
* 是否是中国座机号
|
|
688
706
|
* @param val
|
|
689
707
|
*/
|
|
690
|
-
declare const isTel: (val:
|
|
708
|
+
declare const isTel: (val: UnDef<Numeric>) => boolean;
|
|
691
709
|
/**
|
|
692
710
|
* 是否是邮箱
|
|
693
711
|
* @param val
|
|
694
712
|
*/
|
|
695
|
-
declare const isEmail: (val:
|
|
713
|
+
declare const isEmail: (val: UnDef<string>) => boolean;
|
|
696
714
|
/**
|
|
697
715
|
* 是否是身份证
|
|
698
|
-
* @param val 身份证号
|
|
716
|
+
* @param {string|null|undefined} val 身份证号
|
|
717
|
+
* @param {boolean} compatible 兼容15位
|
|
699
718
|
*/
|
|
700
|
-
declare const isIdCard: (val:
|
|
719
|
+
declare const isIdCard: (val: UnDef<string>, compatible?: boolean) => boolean;
|
|
701
720
|
/**
|
|
702
721
|
* 包含非ASCII字符
|
|
703
722
|
* @param text
|
|
@@ -735,4 +754,4 @@ declare const isValidPageRes: (res: PageRes, code?: number) => boolean;
|
|
|
735
754
|
*/
|
|
736
755
|
declare const isValidFileType: (file: File, type: string) => boolean;
|
|
737
756
|
|
|
738
|
-
export { type NullOrUndefinable, type Nullable, type Numeric, type PageRes, type PageResData, type Res, type Undefinable, attachFmt, camel2Kebab, camel2Pascal, camel2Snake, camel2Title, checkImg, currencyFmt, dateDuration, dateFmt, filterObj, fixiOSInputAutoZoomIn, getBaseAttachUrl, getHostEnv, hideCardNo, hideEmail, hideFirstName, hideHead, hideMiddle, hideName, hidePhone, hideSurname, hideTail, hideThird, inBrowser, isArrStr, isDef, isEmail, isEmpty, isIdCard, isJSONStr, isNumeric, isPhone, isTel, isValidArrRes, isValidFileType, isValidKey, isValidPageRes, isValidRes, isValidResCode, jClear, jDebug, jError, jGroup, jGroupC, jGroupE, jInfo, jLog, jTime, jTimeEnd, jWarn, kebab2Camel, kebab2Pascal, kebab2Snake, kebab2Title, nonASCII, parseToJSON, pascal2Camel, pascal2Kebab, pascal2Snake, pascal2Title, recoverFile, replacer, resUrl, reviver, setBaseAttachUrl, snake2Camel, snake2Kebab, snake2Pascal, snake2Title, title2Camel, title2Kebab, title2Pascal, title2Snake, toThousands, userAgent, waitTime };
|
|
757
|
+
export { type MaybeArray, type NullOrUndefinable, type Nullable, type Numeric, type PageRes, type PageResData, type Res, type UnDef, type Undefinable, attachFmt, camel2Kebab, camel2Pascal, camel2Snake, camel2Title, checkImg, currencyFmt, dateDuration, dateFmt, filterObj, fixiOSInputAutoZoomIn, getBaseAttachUrl, getHostEnv, hideBankCard, hideCardNo, hideEmail, hideFirstName, hideHead, hideMiddle, hideName, hidePhone, hideSurname, hideTail, hideThird, inBrowser, isArrStr, isDef, isEmail, isEmpty, isIdCard, isJSONStr, isNumeric, isPhone, isTel, isValidArrRes, isValidFileType, isValidKey, isValidPageRes, isValidRes, isValidResCode, jClear, jDebug, jError, jGroup, jGroupC, jGroupE, jInfo, jLog, jTime, jTimeEnd, jWarn, kebab2Camel, kebab2Pascal, kebab2Snake, kebab2Title, 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
|
@@ -221,6 +221,10 @@ declare type Undefinable<T> = T | undefined;
|
|
|
221
221
|
* 可 Null 或 Undefined
|
|
222
222
|
*/
|
|
223
223
|
declare type NullOrUndefinable<T> = Nullable<Undefinable<T>>;
|
|
224
|
+
/**
|
|
225
|
+
* alias for NullOrUndefinable
|
|
226
|
+
*/
|
|
227
|
+
declare type UnDef<T> = NullOrUndefinable<T>;
|
|
224
228
|
/**
|
|
225
229
|
* 请求结果
|
|
226
230
|
*/
|
|
@@ -242,53 +246,61 @@ declare type MaybeArray<T = any> = T | Array<T>;
|
|
|
242
246
|
* 隐藏中间部分
|
|
243
247
|
* @param {string} str 需要隐藏的字符串
|
|
244
248
|
*/
|
|
245
|
-
declare const hideMiddle: (str:
|
|
249
|
+
declare const hideMiddle: (str: UnDef<string>) => string;
|
|
246
250
|
/**
|
|
247
251
|
* 隐藏首尾仅保留中间3分之1
|
|
248
252
|
* @param {string} str 需要隐藏的字符串
|
|
249
253
|
*/
|
|
250
|
-
declare const hideThird: (str:
|
|
254
|
+
declare const hideThird: (str: UnDef<string>) => string;
|
|
251
255
|
/**
|
|
252
256
|
* 隐藏首部
|
|
253
257
|
* @param {string} str 需要隐藏的字符串
|
|
258
|
+
* @param {number} count 隐藏的字符数
|
|
254
259
|
*/
|
|
255
|
-
declare const hideHead: (str:
|
|
260
|
+
declare const hideHead: (str: UnDef<string>, count?: number) => string;
|
|
256
261
|
/**
|
|
257
262
|
* 隐藏尾部
|
|
258
263
|
* @param {string} str 需要隐藏的字符串
|
|
264
|
+
* @param {number} count 隐藏的字符数
|
|
259
265
|
*/
|
|
260
|
-
declare const hideTail: (str:
|
|
266
|
+
declare const hideTail: (str: UnDef<string>, count?: number) => string;
|
|
261
267
|
/**
|
|
262
268
|
* 隐藏手机号
|
|
263
269
|
* @param {string} phone 手机号
|
|
264
270
|
*/
|
|
265
|
-
declare const hidePhone: (phone:
|
|
271
|
+
declare const hidePhone: (phone: UnDef<string>) => string;
|
|
266
272
|
/**
|
|
267
273
|
* 隐藏身份证号
|
|
268
274
|
* @param {string} cardNo 身份证号
|
|
275
|
+
* @param {boolean} strong 是否强化隐藏
|
|
269
276
|
*/
|
|
270
|
-
declare const hideCardNo: (cardNo:
|
|
277
|
+
declare const hideCardNo: (cardNo: UnDef<string>, strong?: boolean) => string;
|
|
271
278
|
/**
|
|
272
279
|
* 隐藏姓名第一个字
|
|
273
280
|
* @param {string} name 姓名
|
|
274
281
|
* @deprecated 请使用 hideSurname
|
|
275
282
|
*/
|
|
276
|
-
declare const hideName: (name:
|
|
283
|
+
declare const hideName: (name: UnDef<string>) => string;
|
|
277
284
|
/**
|
|
278
285
|
* 隐藏姓氏
|
|
279
286
|
* @param {string} name 姓名
|
|
280
287
|
*/
|
|
281
|
-
declare const hideSurname: (name:
|
|
288
|
+
declare const hideSurname: (name: UnDef<string>) => string;
|
|
282
289
|
/**
|
|
283
290
|
* 隐藏名字
|
|
284
291
|
* @param {string} name 姓名
|
|
285
292
|
*/
|
|
286
|
-
declare const hideFirstName: (name:
|
|
293
|
+
declare const hideFirstName: (name: UnDef<string>) => string;
|
|
287
294
|
/**
|
|
288
295
|
* 隐藏邮箱
|
|
289
296
|
* @param {string} email 邮箱
|
|
290
297
|
*/
|
|
291
|
-
declare const hideEmail: (email:
|
|
298
|
+
declare const hideEmail: (email: UnDef<string>) => string;
|
|
299
|
+
/**
|
|
300
|
+
* 隐藏银行卡号
|
|
301
|
+
* @param {string} bankCard 银行卡号
|
|
302
|
+
*/
|
|
303
|
+
declare const hideBankCard: (bankCard: UnDef<string>) => string;
|
|
292
304
|
|
|
293
305
|
/**
|
|
294
306
|
* 判断是否是浏览器环境
|
|
@@ -549,7 +561,7 @@ declare const toThousands: (num: number) => string | undefined;
|
|
|
549
561
|
* @param currency
|
|
550
562
|
* @param fraction
|
|
551
563
|
*/
|
|
552
|
-
declare const currencyFmt: (currency:
|
|
564
|
+
declare const currencyFmt: (currency: UnDef<Numeric | bigint>, fraction?: number) => string;
|
|
553
565
|
|
|
554
566
|
type VantUploadFileStatus = '' | 'uploading' | 'done' | 'failed'
|
|
555
567
|
type AntdUploadFileStatus = 'removed' | 'uploading' | 'done' | 'error'
|
|
@@ -607,14 +619,17 @@ declare const recoverFile: (resource: Resource) => {
|
|
|
607
619
|
deletable?: boolean | undefined;
|
|
608
620
|
reupload?: boolean | undefined;
|
|
609
621
|
fileName?: string | undefined;
|
|
610
|
-
thumbUrl?: string | undefined;
|
|
622
|
+
thumbUrl?: string | undefined; /**
|
|
623
|
+
* 统一文件字段内容
|
|
624
|
+
* @param resource
|
|
625
|
+
*/
|
|
611
626
|
percentage?: number | undefined;
|
|
612
627
|
};
|
|
613
628
|
/**
|
|
614
629
|
* 附件格式
|
|
615
630
|
* @param data
|
|
616
631
|
*/
|
|
617
|
-
declare const attachFmt: (data:
|
|
632
|
+
declare const attachFmt: (data: UnDef<MaybeArray<Resource>> | string) => {
|
|
618
633
|
url: string | undefined;
|
|
619
634
|
content: string | undefined;
|
|
620
635
|
uri: string;
|
|
@@ -631,7 +646,10 @@ declare const attachFmt: (data: NullOrUndefinable<MaybeArray<Resource>> | string
|
|
|
631
646
|
deletable?: boolean | undefined;
|
|
632
647
|
reupload?: boolean | undefined;
|
|
633
648
|
fileName?: string | undefined;
|
|
634
|
-
thumbUrl?: string | undefined;
|
|
649
|
+
thumbUrl?: string | undefined; /**
|
|
650
|
+
* 统一文件字段内容
|
|
651
|
+
* @param resource
|
|
652
|
+
*/
|
|
635
653
|
percentage?: number | undefined;
|
|
636
654
|
}[];
|
|
637
655
|
|
|
@@ -644,7 +662,7 @@ declare const isDef: <T>(val: T) => val is NonNullable<T>;
|
|
|
644
662
|
* 是否是数字或字符
|
|
645
663
|
* @param val
|
|
646
664
|
*/
|
|
647
|
-
declare const isNumeric: (val: Numeric) => val is string;
|
|
665
|
+
declare const isNumeric: (val: UnDef<Numeric>) => val is string;
|
|
648
666
|
/**
|
|
649
667
|
* 是否是需要的图片格式
|
|
650
668
|
* @param ext
|
|
@@ -654,17 +672,17 @@ declare const checkImg: (ext?: string) => boolean;
|
|
|
654
672
|
* 是否是空值/空数组/空对象 null undefined '' [] {} Set Map
|
|
655
673
|
* @param val
|
|
656
674
|
*/
|
|
657
|
-
declare const isEmpty: (val:
|
|
675
|
+
declare const isEmpty: (val: UnDef<Numeric | boolean | Record<any, any> | Array<any> | Set<any> | Map<any, any>>) => boolean;
|
|
658
676
|
/**
|
|
659
677
|
* 判断是否合法JSON字符串
|
|
660
678
|
* @param str
|
|
661
679
|
*/
|
|
662
|
-
declare const isJSONStr: (str: string) => boolean;
|
|
680
|
+
declare const isJSONStr: (str: UnDef<string>) => boolean;
|
|
663
681
|
/**
|
|
664
682
|
* 判断是否合法JSON数组字符串
|
|
665
683
|
* @param str
|
|
666
684
|
*/
|
|
667
|
-
declare const isArrStr: (str: string) => boolean;
|
|
685
|
+
declare const isArrStr: (str: UnDef<string>) => boolean;
|
|
668
686
|
/**
|
|
669
687
|
* 判断是否有效的key
|
|
670
688
|
* @param {string | number | symbol} key 键名
|
|
@@ -682,22 +700,23 @@ declare const isValidKey: (key: string | number | symbol, object: object) => key
|
|
|
682
700
|
* 是否是中国手机号
|
|
683
701
|
* @param val
|
|
684
702
|
*/
|
|
685
|
-
declare const isPhone: (val:
|
|
703
|
+
declare const isPhone: (val: UnDef<Numeric>) => boolean;
|
|
686
704
|
/**
|
|
687
705
|
* 是否是中国座机号
|
|
688
706
|
* @param val
|
|
689
707
|
*/
|
|
690
|
-
declare const isTel: (val:
|
|
708
|
+
declare const isTel: (val: UnDef<Numeric>) => boolean;
|
|
691
709
|
/**
|
|
692
710
|
* 是否是邮箱
|
|
693
711
|
* @param val
|
|
694
712
|
*/
|
|
695
|
-
declare const isEmail: (val:
|
|
713
|
+
declare const isEmail: (val: UnDef<string>) => boolean;
|
|
696
714
|
/**
|
|
697
715
|
* 是否是身份证
|
|
698
|
-
* @param val 身份证号
|
|
716
|
+
* @param {string|null|undefined} val 身份证号
|
|
717
|
+
* @param {boolean} compatible 兼容15位
|
|
699
718
|
*/
|
|
700
|
-
declare const isIdCard: (val:
|
|
719
|
+
declare const isIdCard: (val: UnDef<string>, compatible?: boolean) => boolean;
|
|
701
720
|
/**
|
|
702
721
|
* 包含非ASCII字符
|
|
703
722
|
* @param text
|
|
@@ -735,4 +754,4 @@ declare const isValidPageRes: (res: PageRes, code?: number) => boolean;
|
|
|
735
754
|
*/
|
|
736
755
|
declare const isValidFileType: (file: File, type: string) => boolean;
|
|
737
756
|
|
|
738
|
-
export { type NullOrUndefinable, type Nullable, type Numeric, type PageRes, type PageResData, type Res, type Undefinable, attachFmt, camel2Kebab, camel2Pascal, camel2Snake, camel2Title, checkImg, currencyFmt, dateDuration, dateFmt, filterObj, fixiOSInputAutoZoomIn, getBaseAttachUrl, getHostEnv, hideCardNo, hideEmail, hideFirstName, hideHead, hideMiddle, hideName, hidePhone, hideSurname, hideTail, hideThird, inBrowser, isArrStr, isDef, isEmail, isEmpty, isIdCard, isJSONStr, isNumeric, isPhone, isTel, isValidArrRes, isValidFileType, isValidKey, isValidPageRes, isValidRes, isValidResCode, jClear, jDebug, jError, jGroup, jGroupC, jGroupE, jInfo, jLog, jTime, jTimeEnd, jWarn, kebab2Camel, kebab2Pascal, kebab2Snake, kebab2Title, nonASCII, parseToJSON, pascal2Camel, pascal2Kebab, pascal2Snake, pascal2Title, recoverFile, replacer, resUrl, reviver, setBaseAttachUrl, snake2Camel, snake2Kebab, snake2Pascal, snake2Title, title2Camel, title2Kebab, title2Pascal, title2Snake, toThousands, userAgent, waitTime };
|
|
757
|
+
export { type MaybeArray, type NullOrUndefinable, type Nullable, type Numeric, type PageRes, type PageResData, type Res, type UnDef, type Undefinable, attachFmt, camel2Kebab, camel2Pascal, camel2Snake, camel2Title, checkImg, currencyFmt, dateDuration, dateFmt, filterObj, fixiOSInputAutoZoomIn, getBaseAttachUrl, getHostEnv, hideBankCard, hideCardNo, hideEmail, hideFirstName, hideHead, hideMiddle, hideName, hidePhone, hideSurname, hideTail, hideThird, inBrowser, isArrStr, isDef, isEmail, isEmpty, isIdCard, isJSONStr, isNumeric, isPhone, isTel, isValidArrRes, isValidFileType, isValidKey, isValidPageRes, isValidRes, isValidResCode, jClear, jDebug, jError, jGroup, jGroupC, jGroupE, jInfo, jLog, jTime, jTimeEnd, jWarn, kebab2Camel, kebab2Pascal, kebab2Snake, kebab2Title, 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
|
@@ -221,6 +221,10 @@ declare type Undefinable<T> = T | undefined;
|
|
|
221
221
|
* 可 Null 或 Undefined
|
|
222
222
|
*/
|
|
223
223
|
declare type NullOrUndefinable<T> = Nullable<Undefinable<T>>;
|
|
224
|
+
/**
|
|
225
|
+
* alias for NullOrUndefinable
|
|
226
|
+
*/
|
|
227
|
+
declare type UnDef<T> = NullOrUndefinable<T>;
|
|
224
228
|
/**
|
|
225
229
|
* 请求结果
|
|
226
230
|
*/
|
|
@@ -242,53 +246,61 @@ declare type MaybeArray<T = any> = T | Array<T>;
|
|
|
242
246
|
* 隐藏中间部分
|
|
243
247
|
* @param {string} str 需要隐藏的字符串
|
|
244
248
|
*/
|
|
245
|
-
declare const hideMiddle: (str:
|
|
249
|
+
declare const hideMiddle: (str: UnDef<string>) => string;
|
|
246
250
|
/**
|
|
247
251
|
* 隐藏首尾仅保留中间3分之1
|
|
248
252
|
* @param {string} str 需要隐藏的字符串
|
|
249
253
|
*/
|
|
250
|
-
declare const hideThird: (str:
|
|
254
|
+
declare const hideThird: (str: UnDef<string>) => string;
|
|
251
255
|
/**
|
|
252
256
|
* 隐藏首部
|
|
253
257
|
* @param {string} str 需要隐藏的字符串
|
|
258
|
+
* @param {number} count 隐藏的字符数
|
|
254
259
|
*/
|
|
255
|
-
declare const hideHead: (str:
|
|
260
|
+
declare const hideHead: (str: UnDef<string>, count?: number) => string;
|
|
256
261
|
/**
|
|
257
262
|
* 隐藏尾部
|
|
258
263
|
* @param {string} str 需要隐藏的字符串
|
|
264
|
+
* @param {number} count 隐藏的字符数
|
|
259
265
|
*/
|
|
260
|
-
declare const hideTail: (str:
|
|
266
|
+
declare const hideTail: (str: UnDef<string>, count?: number) => string;
|
|
261
267
|
/**
|
|
262
268
|
* 隐藏手机号
|
|
263
269
|
* @param {string} phone 手机号
|
|
264
270
|
*/
|
|
265
|
-
declare const hidePhone: (phone:
|
|
271
|
+
declare const hidePhone: (phone: UnDef<string>) => string;
|
|
266
272
|
/**
|
|
267
273
|
* 隐藏身份证号
|
|
268
274
|
* @param {string} cardNo 身份证号
|
|
275
|
+
* @param {boolean} strong 是否强化隐藏
|
|
269
276
|
*/
|
|
270
|
-
declare const hideCardNo: (cardNo:
|
|
277
|
+
declare const hideCardNo: (cardNo: UnDef<string>, strong?: boolean) => string;
|
|
271
278
|
/**
|
|
272
279
|
* 隐藏姓名第一个字
|
|
273
280
|
* @param {string} name 姓名
|
|
274
281
|
* @deprecated 请使用 hideSurname
|
|
275
282
|
*/
|
|
276
|
-
declare const hideName: (name:
|
|
283
|
+
declare const hideName: (name: UnDef<string>) => string;
|
|
277
284
|
/**
|
|
278
285
|
* 隐藏姓氏
|
|
279
286
|
* @param {string} name 姓名
|
|
280
287
|
*/
|
|
281
|
-
declare const hideSurname: (name:
|
|
288
|
+
declare const hideSurname: (name: UnDef<string>) => string;
|
|
282
289
|
/**
|
|
283
290
|
* 隐藏名字
|
|
284
291
|
* @param {string} name 姓名
|
|
285
292
|
*/
|
|
286
|
-
declare const hideFirstName: (name:
|
|
293
|
+
declare const hideFirstName: (name: UnDef<string>) => string;
|
|
287
294
|
/**
|
|
288
295
|
* 隐藏邮箱
|
|
289
296
|
* @param {string} email 邮箱
|
|
290
297
|
*/
|
|
291
|
-
declare const hideEmail: (email:
|
|
298
|
+
declare const hideEmail: (email: UnDef<string>) => string;
|
|
299
|
+
/**
|
|
300
|
+
* 隐藏银行卡号
|
|
301
|
+
* @param {string} bankCard 银行卡号
|
|
302
|
+
*/
|
|
303
|
+
declare const hideBankCard: (bankCard: UnDef<string>) => string;
|
|
292
304
|
|
|
293
305
|
/**
|
|
294
306
|
* 判断是否是浏览器环境
|
|
@@ -549,7 +561,7 @@ declare const toThousands: (num: number) => string | undefined;
|
|
|
549
561
|
* @param currency
|
|
550
562
|
* @param fraction
|
|
551
563
|
*/
|
|
552
|
-
declare const currencyFmt: (currency:
|
|
564
|
+
declare const currencyFmt: (currency: UnDef<Numeric | bigint>, fraction?: number) => string;
|
|
553
565
|
|
|
554
566
|
type VantUploadFileStatus = '' | 'uploading' | 'done' | 'failed'
|
|
555
567
|
type AntdUploadFileStatus = 'removed' | 'uploading' | 'done' | 'error'
|
|
@@ -607,14 +619,17 @@ declare const recoverFile: (resource: Resource) => {
|
|
|
607
619
|
deletable?: boolean | undefined;
|
|
608
620
|
reupload?: boolean | undefined;
|
|
609
621
|
fileName?: string | undefined;
|
|
610
|
-
thumbUrl?: string | undefined;
|
|
622
|
+
thumbUrl?: string | undefined; /**
|
|
623
|
+
* 统一文件字段内容
|
|
624
|
+
* @param resource
|
|
625
|
+
*/
|
|
611
626
|
percentage?: number | undefined;
|
|
612
627
|
};
|
|
613
628
|
/**
|
|
614
629
|
* 附件格式
|
|
615
630
|
* @param data
|
|
616
631
|
*/
|
|
617
|
-
declare const attachFmt: (data:
|
|
632
|
+
declare const attachFmt: (data: UnDef<MaybeArray<Resource>> | string) => {
|
|
618
633
|
url: string | undefined;
|
|
619
634
|
content: string | undefined;
|
|
620
635
|
uri: string;
|
|
@@ -631,7 +646,10 @@ declare const attachFmt: (data: NullOrUndefinable<MaybeArray<Resource>> | string
|
|
|
631
646
|
deletable?: boolean | undefined;
|
|
632
647
|
reupload?: boolean | undefined;
|
|
633
648
|
fileName?: string | undefined;
|
|
634
|
-
thumbUrl?: string | undefined;
|
|
649
|
+
thumbUrl?: string | undefined; /**
|
|
650
|
+
* 统一文件字段内容
|
|
651
|
+
* @param resource
|
|
652
|
+
*/
|
|
635
653
|
percentage?: number | undefined;
|
|
636
654
|
}[];
|
|
637
655
|
|
|
@@ -644,7 +662,7 @@ declare const isDef: <T>(val: T) => val is NonNullable<T>;
|
|
|
644
662
|
* 是否是数字或字符
|
|
645
663
|
* @param val
|
|
646
664
|
*/
|
|
647
|
-
declare const isNumeric: (val: Numeric) => val is string;
|
|
665
|
+
declare const isNumeric: (val: UnDef<Numeric>) => val is string;
|
|
648
666
|
/**
|
|
649
667
|
* 是否是需要的图片格式
|
|
650
668
|
* @param ext
|
|
@@ -654,17 +672,17 @@ declare const checkImg: (ext?: string) => boolean;
|
|
|
654
672
|
* 是否是空值/空数组/空对象 null undefined '' [] {} Set Map
|
|
655
673
|
* @param val
|
|
656
674
|
*/
|
|
657
|
-
declare const isEmpty: (val:
|
|
675
|
+
declare const isEmpty: (val: UnDef<Numeric | boolean | Record<any, any> | Array<any> | Set<any> | Map<any, any>>) => boolean;
|
|
658
676
|
/**
|
|
659
677
|
* 判断是否合法JSON字符串
|
|
660
678
|
* @param str
|
|
661
679
|
*/
|
|
662
|
-
declare const isJSONStr: (str: string) => boolean;
|
|
680
|
+
declare const isJSONStr: (str: UnDef<string>) => boolean;
|
|
663
681
|
/**
|
|
664
682
|
* 判断是否合法JSON数组字符串
|
|
665
683
|
* @param str
|
|
666
684
|
*/
|
|
667
|
-
declare const isArrStr: (str: string) => boolean;
|
|
685
|
+
declare const isArrStr: (str: UnDef<string>) => boolean;
|
|
668
686
|
/**
|
|
669
687
|
* 判断是否有效的key
|
|
670
688
|
* @param {string | number | symbol} key 键名
|
|
@@ -682,22 +700,23 @@ declare const isValidKey: (key: string | number | symbol, object: object) => key
|
|
|
682
700
|
* 是否是中国手机号
|
|
683
701
|
* @param val
|
|
684
702
|
*/
|
|
685
|
-
declare const isPhone: (val:
|
|
703
|
+
declare const isPhone: (val: UnDef<Numeric>) => boolean;
|
|
686
704
|
/**
|
|
687
705
|
* 是否是中国座机号
|
|
688
706
|
* @param val
|
|
689
707
|
*/
|
|
690
|
-
declare const isTel: (val:
|
|
708
|
+
declare const isTel: (val: UnDef<Numeric>) => boolean;
|
|
691
709
|
/**
|
|
692
710
|
* 是否是邮箱
|
|
693
711
|
* @param val
|
|
694
712
|
*/
|
|
695
|
-
declare const isEmail: (val:
|
|
713
|
+
declare const isEmail: (val: UnDef<string>) => boolean;
|
|
696
714
|
/**
|
|
697
715
|
* 是否是身份证
|
|
698
|
-
* @param val 身份证号
|
|
716
|
+
* @param {string|null|undefined} val 身份证号
|
|
717
|
+
* @param {boolean} compatible 兼容15位
|
|
699
718
|
*/
|
|
700
|
-
declare const isIdCard: (val:
|
|
719
|
+
declare const isIdCard: (val: UnDef<string>, compatible?: boolean) => boolean;
|
|
701
720
|
/**
|
|
702
721
|
* 包含非ASCII字符
|
|
703
722
|
* @param text
|
|
@@ -735,4 +754,4 @@ declare const isValidPageRes: (res: PageRes, code?: number) => boolean;
|
|
|
735
754
|
*/
|
|
736
755
|
declare const isValidFileType: (file: File, type: string) => boolean;
|
|
737
756
|
|
|
738
|
-
export { type NullOrUndefinable, type Nullable, type Numeric, type PageRes, type PageResData, type Res, type Undefinable, attachFmt, camel2Kebab, camel2Pascal, camel2Snake, camel2Title, checkImg, currencyFmt, dateDuration, dateFmt, filterObj, fixiOSInputAutoZoomIn, getBaseAttachUrl, getHostEnv, hideCardNo, hideEmail, hideFirstName, hideHead, hideMiddle, hideName, hidePhone, hideSurname, hideTail, hideThird, inBrowser, isArrStr, isDef, isEmail, isEmpty, isIdCard, isJSONStr, isNumeric, isPhone, isTel, isValidArrRes, isValidFileType, isValidKey, isValidPageRes, isValidRes, isValidResCode, jClear, jDebug, jError, jGroup, jGroupC, jGroupE, jInfo, jLog, jTime, jTimeEnd, jWarn, kebab2Camel, kebab2Pascal, kebab2Snake, kebab2Title, nonASCII, parseToJSON, pascal2Camel, pascal2Kebab, pascal2Snake, pascal2Title, recoverFile, replacer, resUrl, reviver, setBaseAttachUrl, snake2Camel, snake2Kebab, snake2Pascal, snake2Title, title2Camel, title2Kebab, title2Pascal, title2Snake, toThousands, userAgent, waitTime };
|
|
757
|
+
export { type MaybeArray, type NullOrUndefinable, type Nullable, type Numeric, type PageRes, type PageResData, type Res, type UnDef, type Undefinable, attachFmt, camel2Kebab, camel2Pascal, camel2Snake, camel2Title, checkImg, currencyFmt, dateDuration, dateFmt, filterObj, fixiOSInputAutoZoomIn, getBaseAttachUrl, getHostEnv, hideBankCard, hideCardNo, hideEmail, hideFirstName, hideHead, hideMiddle, hideName, hidePhone, hideSurname, hideTail, hideThird, inBrowser, isArrStr, isDef, isEmail, isEmpty, isIdCard, isJSONStr, isNumeric, isPhone, isTel, isValidArrRes, isValidFileType, isValidKey, isValidPageRes, isValidRes, isValidResCode, jClear, jDebug, jError, jGroup, jGroupC, jGroupE, jInfo, jLog, jTime, jTimeEnd, jWarn, kebab2Camel, kebab2Pascal, kebab2Snake, kebab2Title, 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
|
@@ -61,7 +61,11 @@ const jClear = console.clear.bind(console);
|
|
|
61
61
|
const cnPhoneRE = /^1[3-9]\d{9}$/;
|
|
62
62
|
const cnTelRE = /^0\d{9,11}$/;
|
|
63
63
|
const isDef = (val) => val !== void 0 && val !== null;
|
|
64
|
-
const isNumeric = (val) =>
|
|
64
|
+
const isNumeric = (val) => {
|
|
65
|
+
if (isDef(val))
|
|
66
|
+
return typeof val === "number" || /^\d+(?:\.\d+)?$/.test(val);
|
|
67
|
+
return false;
|
|
68
|
+
};
|
|
65
69
|
const checkImg = (ext) => {
|
|
66
70
|
return /\.(?:jpg|jpeg|png|gif)$/.test((ext || "").toLowerCase());
|
|
67
71
|
};
|
|
@@ -69,19 +73,23 @@ const isEmpty = (val) => {
|
|
|
69
73
|
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;
|
|
70
74
|
};
|
|
71
75
|
const isJSONStr = (str) => {
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
76
|
+
if (isDef(str))
|
|
77
|
+
try {
|
|
78
|
+
JSON.parse(str);
|
|
79
|
+
return true;
|
|
80
|
+
} catch (e) {
|
|
81
|
+
return false;
|
|
82
|
+
}
|
|
83
|
+
return false;
|
|
78
84
|
};
|
|
79
85
|
const isArrStr = (str) => {
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
86
|
+
if (isDef(str))
|
|
87
|
+
try {
|
|
88
|
+
return Array.isArray(JSON.parse(str));
|
|
89
|
+
} catch (e) {
|
|
90
|
+
return false;
|
|
91
|
+
}
|
|
92
|
+
return false;
|
|
85
93
|
};
|
|
86
94
|
const isValidKey = (key, object) => key in object;
|
|
87
95
|
const isPhone = (val) => {
|
|
@@ -100,12 +108,12 @@ const isEmail = (val) => {
|
|
|
100
108
|
const reg = /^[a-zA-Z\d](?:\w|-)+@[a-zA-Z\d]+\.[a-zA-Z]{2,5}$/;
|
|
101
109
|
return reg.test(val);
|
|
102
110
|
};
|
|
103
|
-
const isIdCard = (val) => {
|
|
111
|
+
const isIdCard = (val, compatible = true) => {
|
|
104
112
|
if (!isDef(val))
|
|
105
113
|
return false;
|
|
106
114
|
const card15 = /^[1-9]\d{7}(?:0[1-9]|10|11|12)(?:[0-2][1-9]|10|20|30|31)\d{2}[\dXx]$/;
|
|
107
115
|
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}[\dXx]$/;
|
|
108
|
-
return
|
|
116
|
+
return card18.test(val) || (compatible ? card15.test(val) : false);
|
|
109
117
|
};
|
|
110
118
|
const nonASCII = (text) => /[^\x20-\x7E]/.test(text);
|
|
111
119
|
const isValidResCode = (res, code = 200) => res.code === code;
|
|
@@ -157,21 +165,23 @@ const hideThird = (str) => {
|
|
|
157
165
|
return "**";
|
|
158
166
|
return str.slice(0, partLen) + "*".repeat(len - 2 * partLen) + str.slice(len - partLen);
|
|
159
167
|
};
|
|
160
|
-
const hideHead = (str) => {
|
|
168
|
+
const hideHead = (str, count) => {
|
|
161
169
|
if (!isDef(str))
|
|
162
170
|
return "";
|
|
163
171
|
const len = str.length;
|
|
172
|
+
const cnt = count !== void 0 ? Math.max(Math.min(len, count), 0) : len - 1;
|
|
164
173
|
if (len === 1)
|
|
165
174
|
return "*";
|
|
166
|
-
return "*".repeat(
|
|
175
|
+
return "*".repeat(cnt) + str.substring(cnt);
|
|
167
176
|
};
|
|
168
|
-
const hideTail = (str) => {
|
|
177
|
+
const hideTail = (str, count) => {
|
|
169
178
|
if (!isDef(str))
|
|
170
179
|
return "";
|
|
171
180
|
const len = str.length;
|
|
181
|
+
const cnt = count !== void 0 ? Math.max(Math.min(len, count), 0) : len - 1;
|
|
172
182
|
if (len === 1)
|
|
173
183
|
return "*";
|
|
174
|
-
return str
|
|
184
|
+
return str.substring(0, len - cnt) + "*".repeat(cnt);
|
|
175
185
|
};
|
|
176
186
|
const hidePhone = (phone) => {
|
|
177
187
|
if (phone) {
|
|
@@ -185,9 +195,12 @@ const hidePhone = (phone) => {
|
|
|
185
195
|
}
|
|
186
196
|
return "";
|
|
187
197
|
};
|
|
188
|
-
const hideCardNo = (cardNo) => {
|
|
198
|
+
const hideCardNo = (cardNo, strong = true) => {
|
|
189
199
|
if (cardNo) {
|
|
190
|
-
|
|
200
|
+
if (isIdCard(cardNo, false)) {
|
|
201
|
+
return strong ? hideMiddle(cardNo) : cardNo.replace(/^(.)\d{3}(.{8})\d{5}(.)$/, "$1***$2*****$3");
|
|
202
|
+
}
|
|
203
|
+
return cardNo;
|
|
191
204
|
}
|
|
192
205
|
return "";
|
|
193
206
|
};
|
|
@@ -206,7 +219,7 @@ const hideName = (name) => {
|
|
|
206
219
|
return "";
|
|
207
220
|
};
|
|
208
221
|
const hideSurname = (name) => {
|
|
209
|
-
return hideHead(name);
|
|
222
|
+
return hideHead(name, 1);
|
|
210
223
|
};
|
|
211
224
|
const hideFirstName = (name) => {
|
|
212
225
|
return hideTail(name);
|
|
@@ -214,14 +227,29 @@ const hideFirstName = (name) => {
|
|
|
214
227
|
const hideEmail = (email) => {
|
|
215
228
|
if (email) {
|
|
216
229
|
if (!email.includes("@"))
|
|
217
|
-
return
|
|
230
|
+
return email;
|
|
218
231
|
const arr = email.split("@");
|
|
219
232
|
const name = arr[0];
|
|
220
233
|
const domain = arr[1];
|
|
221
|
-
|
|
222
|
-
if (!len)
|
|
234
|
+
if (!name || !domain)
|
|
223
235
|
return email;
|
|
224
|
-
|
|
236
|
+
const len = name.length;
|
|
237
|
+
let newName;
|
|
238
|
+
if (len <= 3) {
|
|
239
|
+
newName = `${name}***`;
|
|
240
|
+
} else {
|
|
241
|
+
newName = hideTail(name, 3);
|
|
242
|
+
}
|
|
243
|
+
return `${newName}@${domain}`;
|
|
244
|
+
}
|
|
245
|
+
return "";
|
|
246
|
+
};
|
|
247
|
+
const hideBankCard = (bankCard) => {
|
|
248
|
+
if (bankCard) {
|
|
249
|
+
const len = bankCard.length;
|
|
250
|
+
if (len <= 10)
|
|
251
|
+
return bankCard;
|
|
252
|
+
return bankCard.substring(0, 6) + "*".repeat(len - 10) + bankCard.substring(len - 4, len);
|
|
225
253
|
}
|
|
226
254
|
return "";
|
|
227
255
|
};
|
|
@@ -355,8 +383,11 @@ const toThousands = (num) => {
|
|
|
355
383
|
const currencyFmt = (currency, fraction = 0) => {
|
|
356
384
|
if (!isDef(currency))
|
|
357
385
|
return "";
|
|
386
|
+
const num = Number(currency);
|
|
387
|
+
if (Number.isNaN(num))
|
|
388
|
+
return "";
|
|
358
389
|
return new Intl.NumberFormat("zh-CN", { style: "currency", currency: "CNY", maximumFractionDigits: fraction }).format(
|
|
359
|
-
|
|
390
|
+
num
|
|
360
391
|
);
|
|
361
392
|
};
|
|
362
393
|
|
|
@@ -407,4 +438,4 @@ const attachFmt = (data) => {
|
|
|
407
438
|
return attachList.map(recoverFile);
|
|
408
439
|
};
|
|
409
440
|
|
|
410
|
-
export { attachFmt, camel2Kebab, camel2Pascal, camel2Snake, camel2Title, checkImg, currencyFmt, dateDuration, dateFmt, filterObj, fixiOSInputAutoZoomIn, getBaseAttachUrl, getHostEnv, hideCardNo, hideEmail, hideFirstName, hideHead, hideMiddle, hideName, hidePhone, hideSurname, hideTail, hideThird, inBrowser, isArrStr, isDef, isEmail, isEmpty, isIdCard, isJSONStr, isNumeric, isPhone, isTel, isValidArrRes, isValidFileType, isValidKey, isValidPageRes, isValidRes, isValidResCode, jClear, jDebug, jError, jGroup, jGroupC, jGroupE, jInfo, jLog, jTime, jTimeEnd, jWarn, kebab2Camel, kebab2Pascal, kebab2Snake, kebab2Title, nonASCII, parseToJSON, pascal2Camel, pascal2Kebab, pascal2Snake, pascal2Title, recoverFile, replacer, resUrl, reviver, setBaseAttachUrl, snake2Camel, snake2Kebab, snake2Pascal, snake2Title, title2Camel, title2Kebab, title2Pascal, title2Snake, toThousands, userAgent, waitTime };
|
|
441
|
+
export { attachFmt, camel2Kebab, camel2Pascal, camel2Snake, camel2Title, checkImg, currencyFmt, dateDuration, dateFmt, filterObj, fixiOSInputAutoZoomIn, getBaseAttachUrl, getHostEnv, hideBankCard, hideCardNo, hideEmail, hideFirstName, hideHead, hideMiddle, hideName, hidePhone, hideSurname, hideTail, hideThird, inBrowser, isArrStr, isDef, isEmail, isEmpty, isIdCard, isJSONStr, isNumeric, isPhone, isTel, isValidArrRes, isValidFileType, isValidKey, isValidPageRes, isValidRes, isValidResCode, jClear, jDebug, jError, jGroup, jGroupC, jGroupE, jInfo, jLog, jTime, jTimeEnd, jWarn, kebab2Camel, kebab2Pascal, kebab2Snake, kebab2Title, 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.1-beta.
|
|
4
|
+
"version": "0.0.1-beta.26",
|
|
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",
|