@jhqn/utils-core 0.0.3-beta.10 → 0.0.3-beta.11
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 +24 -11
- package/dist/index.d.cts +42 -34
- package/dist/index.d.mts +42 -34
- package/dist/index.d.ts +42 -34
- package/dist/index.mjs +18 -12
- package/package.json +1 -1
package/dist/index.cjs
CHANGED
|
@@ -143,8 +143,12 @@ const isEmpty = (val) => {
|
|
|
143
143
|
};
|
|
144
144
|
|
|
145
145
|
const cnPhoneRE = /^1[3-9]\d{9}$/;
|
|
146
|
-
const cnTelRE = /^0\d{
|
|
146
|
+
const cnTelRE = /^0\d{2,3}-?\d{7,8}$/;
|
|
147
|
+
const cnTelRE2 = /^\(0\d{2,3}\)\d{7,8}$/;
|
|
147
148
|
const cnUSCIRE = /^[0-9A-HJ-NPQRTUWXY]{2}\d{6}[0-9A-HJ-NPQRTUWXY]{10}$/;
|
|
149
|
+
const cnIdCard15Re = /^[1-9]\d{7}(?:0[1-9]|10|11|12)(?:[0-2][1-9]|10|20|30|31)\d{2}[\dX]$/i;
|
|
150
|
+
const cnIdCard18Re = /^[1-9]\d{5}(?:18|19|20)\d{2}(?:0[1-9]|1[0-2])(?:[0-2][1-9]|10|20|30|31)\d{3}[\dX]$/i;
|
|
151
|
+
const emailRE = /^[a-z\d](?:\w|-)+@[a-z\d]+\.[a-z]{2,5}$/i;
|
|
148
152
|
const isUSCI = (val) => {
|
|
149
153
|
if (!isDef(val))
|
|
150
154
|
return false;
|
|
@@ -158,20 +162,18 @@ const isPhone = (val) => {
|
|
|
158
162
|
const isTel = (val) => {
|
|
159
163
|
if (!isDef(val))
|
|
160
164
|
return false;
|
|
161
|
-
|
|
165
|
+
const valStr = val.toString().replaceAll(" ", "");
|
|
166
|
+
return cnTelRE.test(valStr) || cnTelRE2.test(valStr);
|
|
162
167
|
};
|
|
163
168
|
const isEmail = (val) => {
|
|
164
169
|
if (!isDef(val))
|
|
165
170
|
return false;
|
|
166
|
-
|
|
167
|
-
return reg.test(val);
|
|
171
|
+
return emailRE.test(val);
|
|
168
172
|
};
|
|
169
173
|
const isIdCard = (val, compatible = true) => {
|
|
170
174
|
if (!isDef(val))
|
|
171
175
|
return false;
|
|
172
|
-
|
|
173
|
-
const card18 = /^[1-9]\d{5}(?:18|19|20)\d{2}(?:0[1-9]|1[0-2])(?:[0-2][1-9]|10|20|30|31)\d{3}[\dX]$/i;
|
|
174
|
-
return card18.test(val) || (compatible ? card15.test(val) : false);
|
|
176
|
+
return cnIdCard18Re.test(val) || (compatible ? cnIdCard15Re.test(val) : false);
|
|
175
177
|
};
|
|
176
178
|
const isNumeric = (val) => {
|
|
177
179
|
if (isDef(val))
|
|
@@ -258,11 +260,15 @@ const hideTail = (str, count) => {
|
|
|
258
260
|
};
|
|
259
261
|
const hidePhone = (phone) => {
|
|
260
262
|
if (phone) {
|
|
261
|
-
|
|
262
|
-
|
|
263
|
+
const phoneStr = phone.replaceAll(" ", "");
|
|
264
|
+
if (isPhone(phoneStr)) {
|
|
265
|
+
return phoneStr.replace(/^(\d{3})\d{4}(\d{4})$/, "$1****$2");
|
|
263
266
|
}
|
|
264
|
-
if (
|
|
265
|
-
return
|
|
267
|
+
if (cnTelRE.test(phoneStr)) {
|
|
268
|
+
return phoneStr.replace(/^(0\d{2,3})-?\d{3,4}(\d{4})$/, "$1****$2");
|
|
269
|
+
}
|
|
270
|
+
if (cnTelRE2.test(phoneStr)) {
|
|
271
|
+
return phoneStr.replace(/^\((0\d{2,3})\)\d{3,4}(\d{4})$/, "$1****$2");
|
|
266
272
|
}
|
|
267
273
|
return phone;
|
|
268
274
|
}
|
|
@@ -538,9 +544,16 @@ exports.camel2Pascal = camel2Pascal;
|
|
|
538
544
|
exports.camel2Snake = camel2Snake;
|
|
539
545
|
exports.camel2Title = camel2Title;
|
|
540
546
|
exports.checkImg = checkImg;
|
|
547
|
+
exports.cnIdCard15Re = cnIdCard15Re;
|
|
548
|
+
exports.cnIdCard18Re = cnIdCard18Re;
|
|
549
|
+
exports.cnPhoneRE = cnPhoneRE;
|
|
550
|
+
exports.cnTelRE = cnTelRE;
|
|
551
|
+
exports.cnTelRE2 = cnTelRE2;
|
|
552
|
+
exports.cnUSCIRE = cnUSCIRE;
|
|
541
553
|
exports.currencyFmt = currencyFmt;
|
|
542
554
|
exports.dateDuration = dateDuration;
|
|
543
555
|
exports.dateFmt = dateFmt;
|
|
556
|
+
exports.emailRE = emailRE;
|
|
544
557
|
exports.filterObj = filterObj;
|
|
545
558
|
exports.fixiOSInputAutoZoomIn = fixiOSInputAutoZoomIn;
|
|
546
559
|
exports.getBaseAttachUrl = getBaseAttachUrl;
|
package/dist/index.d.cts
CHANGED
|
@@ -60,6 +60,37 @@ type Dict<T = string> = Record<string, T>;
|
|
|
60
60
|
*/
|
|
61
61
|
type PartialBy<T, K extends keyof T> = Omit<T, K> & Partial<Pick<T, K>>;
|
|
62
62
|
|
|
63
|
+
interface HostEnv {
|
|
64
|
+
/**
|
|
65
|
+
* 是否是浙里办
|
|
66
|
+
*/
|
|
67
|
+
readonly zlb: boolean
|
|
68
|
+
/**
|
|
69
|
+
* 是否是专有钉
|
|
70
|
+
*/
|
|
71
|
+
readonly zyd: boolean
|
|
72
|
+
/**
|
|
73
|
+
* 是否是浙政钉
|
|
74
|
+
*/
|
|
75
|
+
readonly zzd: boolean
|
|
76
|
+
/**
|
|
77
|
+
* 是否是钉钉/专有钉/浙政钉
|
|
78
|
+
*/
|
|
79
|
+
readonly dd: boolean
|
|
80
|
+
/**
|
|
81
|
+
* 是否是微信
|
|
82
|
+
*/
|
|
83
|
+
readonly wx: boolean
|
|
84
|
+
/**
|
|
85
|
+
* 是否是支付宝
|
|
86
|
+
*/
|
|
87
|
+
readonly zfb: boolean
|
|
88
|
+
/**
|
|
89
|
+
* 是否是小程序
|
|
90
|
+
*/
|
|
91
|
+
readonly mini: boolean
|
|
92
|
+
}
|
|
93
|
+
|
|
63
94
|
/**
|
|
64
95
|
* snake2Kebab
|
|
65
96
|
* @param {string} str 字符串
|
|
@@ -293,8 +324,9 @@ declare const hideHead: (str: UnDef<string>, count?: number) => string;
|
|
|
293
324
|
*/
|
|
294
325
|
declare const hideTail: (str: UnDef<string>, count?: number) => string;
|
|
295
326
|
/**
|
|
296
|
-
*
|
|
297
|
-
* @param {string} phone
|
|
327
|
+
* 隐藏手机号/座机号
|
|
328
|
+
* @param {string} phone 手机号/座机号
|
|
329
|
+
* @returns {string} 隐藏后的手机号/座机号
|
|
298
330
|
*/
|
|
299
331
|
declare const hidePhone: (phone: UnDef<string>) => string;
|
|
300
332
|
/**
|
|
@@ -330,37 +362,6 @@ declare const hideEmail: (email: UnDef<string>) => string;
|
|
|
330
362
|
*/
|
|
331
363
|
declare const hideBankCard: (bankCard: UnDef<string>) => string;
|
|
332
364
|
|
|
333
|
-
interface HostEnv {
|
|
334
|
-
/**
|
|
335
|
-
* 是否是浙里办
|
|
336
|
-
*/
|
|
337
|
-
readonly zlb: boolean
|
|
338
|
-
/**
|
|
339
|
-
* 是否是专有钉
|
|
340
|
-
*/
|
|
341
|
-
readonly zyd: boolean
|
|
342
|
-
/**
|
|
343
|
-
* 是否是浙政钉
|
|
344
|
-
*/
|
|
345
|
-
readonly zzd: boolean
|
|
346
|
-
/**
|
|
347
|
-
* 是否是钉钉/专有钉/浙政钉
|
|
348
|
-
*/
|
|
349
|
-
readonly dd: boolean
|
|
350
|
-
/**
|
|
351
|
-
* 是否是微信
|
|
352
|
-
*/
|
|
353
|
-
readonly wx: boolean
|
|
354
|
-
/**
|
|
355
|
-
* 是否是支付宝
|
|
356
|
-
*/
|
|
357
|
-
readonly zfb: boolean
|
|
358
|
-
/**
|
|
359
|
-
* 是否是小程序
|
|
360
|
-
*/
|
|
361
|
-
readonly mini: boolean
|
|
362
|
-
}
|
|
363
|
-
|
|
364
365
|
/**
|
|
365
366
|
* 判断是否是浏览器环境
|
|
366
367
|
*/
|
|
@@ -714,6 +715,13 @@ declare const isValidKey: (key: string | number | symbol, object: object) => key
|
|
|
714
715
|
*/
|
|
715
716
|
declare const isEmpty: (val: UnDef<Numeric | boolean | Record<any, any> | Array<any> | Set<any> | Map<any, any>>) => boolean;
|
|
716
717
|
|
|
718
|
+
declare const cnPhoneRE: RegExp;
|
|
719
|
+
declare const cnTelRE: RegExp;
|
|
720
|
+
declare const cnTelRE2: RegExp;
|
|
721
|
+
declare const cnUSCIRE: RegExp;
|
|
722
|
+
declare const cnIdCard15Re: RegExp;
|
|
723
|
+
declare const cnIdCard18Re: RegExp;
|
|
724
|
+
declare const emailRE: RegExp;
|
|
717
725
|
/**
|
|
718
726
|
* 是否是[统一社会信用代码](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
727
|
* @example
|
|
@@ -793,4 +801,4 @@ declare const isValidArrRes: (res: Res<any[]>, code?: number) => boolean;
|
|
|
793
801
|
*/
|
|
794
802
|
declare const isValidPageRes: (res: PageRes, code?: number) => boolean;
|
|
795
803
|
|
|
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 };
|
|
804
|
+
export { type Dict, type HostEnv, 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, cnIdCard15Re, cnIdCard18Re, cnPhoneRE, cnTelRE, cnTelRE2, cnUSCIRE, currencyFmt, dateDuration, dateFmt, emailRE, 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
|
@@ -60,6 +60,37 @@ type Dict<T = string> = Record<string, T>;
|
|
|
60
60
|
*/
|
|
61
61
|
type PartialBy<T, K extends keyof T> = Omit<T, K> & Partial<Pick<T, K>>;
|
|
62
62
|
|
|
63
|
+
interface HostEnv {
|
|
64
|
+
/**
|
|
65
|
+
* 是否是浙里办
|
|
66
|
+
*/
|
|
67
|
+
readonly zlb: boolean
|
|
68
|
+
/**
|
|
69
|
+
* 是否是专有钉
|
|
70
|
+
*/
|
|
71
|
+
readonly zyd: boolean
|
|
72
|
+
/**
|
|
73
|
+
* 是否是浙政钉
|
|
74
|
+
*/
|
|
75
|
+
readonly zzd: boolean
|
|
76
|
+
/**
|
|
77
|
+
* 是否是钉钉/专有钉/浙政钉
|
|
78
|
+
*/
|
|
79
|
+
readonly dd: boolean
|
|
80
|
+
/**
|
|
81
|
+
* 是否是微信
|
|
82
|
+
*/
|
|
83
|
+
readonly wx: boolean
|
|
84
|
+
/**
|
|
85
|
+
* 是否是支付宝
|
|
86
|
+
*/
|
|
87
|
+
readonly zfb: boolean
|
|
88
|
+
/**
|
|
89
|
+
* 是否是小程序
|
|
90
|
+
*/
|
|
91
|
+
readonly mini: boolean
|
|
92
|
+
}
|
|
93
|
+
|
|
63
94
|
/**
|
|
64
95
|
* snake2Kebab
|
|
65
96
|
* @param {string} str 字符串
|
|
@@ -293,8 +324,9 @@ declare const hideHead: (str: UnDef<string>, count?: number) => string;
|
|
|
293
324
|
*/
|
|
294
325
|
declare const hideTail: (str: UnDef<string>, count?: number) => string;
|
|
295
326
|
/**
|
|
296
|
-
*
|
|
297
|
-
* @param {string} phone
|
|
327
|
+
* 隐藏手机号/座机号
|
|
328
|
+
* @param {string} phone 手机号/座机号
|
|
329
|
+
* @returns {string} 隐藏后的手机号/座机号
|
|
298
330
|
*/
|
|
299
331
|
declare const hidePhone: (phone: UnDef<string>) => string;
|
|
300
332
|
/**
|
|
@@ -330,37 +362,6 @@ declare const hideEmail: (email: UnDef<string>) => string;
|
|
|
330
362
|
*/
|
|
331
363
|
declare const hideBankCard: (bankCard: UnDef<string>) => string;
|
|
332
364
|
|
|
333
|
-
interface HostEnv {
|
|
334
|
-
/**
|
|
335
|
-
* 是否是浙里办
|
|
336
|
-
*/
|
|
337
|
-
readonly zlb: boolean
|
|
338
|
-
/**
|
|
339
|
-
* 是否是专有钉
|
|
340
|
-
*/
|
|
341
|
-
readonly zyd: boolean
|
|
342
|
-
/**
|
|
343
|
-
* 是否是浙政钉
|
|
344
|
-
*/
|
|
345
|
-
readonly zzd: boolean
|
|
346
|
-
/**
|
|
347
|
-
* 是否是钉钉/专有钉/浙政钉
|
|
348
|
-
*/
|
|
349
|
-
readonly dd: boolean
|
|
350
|
-
/**
|
|
351
|
-
* 是否是微信
|
|
352
|
-
*/
|
|
353
|
-
readonly wx: boolean
|
|
354
|
-
/**
|
|
355
|
-
* 是否是支付宝
|
|
356
|
-
*/
|
|
357
|
-
readonly zfb: boolean
|
|
358
|
-
/**
|
|
359
|
-
* 是否是小程序
|
|
360
|
-
*/
|
|
361
|
-
readonly mini: boolean
|
|
362
|
-
}
|
|
363
|
-
|
|
364
365
|
/**
|
|
365
366
|
* 判断是否是浏览器环境
|
|
366
367
|
*/
|
|
@@ -714,6 +715,13 @@ declare const isValidKey: (key: string | number | symbol, object: object) => key
|
|
|
714
715
|
*/
|
|
715
716
|
declare const isEmpty: (val: UnDef<Numeric | boolean | Record<any, any> | Array<any> | Set<any> | Map<any, any>>) => boolean;
|
|
716
717
|
|
|
718
|
+
declare const cnPhoneRE: RegExp;
|
|
719
|
+
declare const cnTelRE: RegExp;
|
|
720
|
+
declare const cnTelRE2: RegExp;
|
|
721
|
+
declare const cnUSCIRE: RegExp;
|
|
722
|
+
declare const cnIdCard15Re: RegExp;
|
|
723
|
+
declare const cnIdCard18Re: RegExp;
|
|
724
|
+
declare const emailRE: RegExp;
|
|
717
725
|
/**
|
|
718
726
|
* 是否是[统一社会信用代码](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
727
|
* @example
|
|
@@ -793,4 +801,4 @@ declare const isValidArrRes: (res: Res<any[]>, code?: number) => boolean;
|
|
|
793
801
|
*/
|
|
794
802
|
declare const isValidPageRes: (res: PageRes, code?: number) => boolean;
|
|
795
803
|
|
|
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 };
|
|
804
|
+
export { type Dict, type HostEnv, 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, cnIdCard15Re, cnIdCard18Re, cnPhoneRE, cnTelRE, cnTelRE2, cnUSCIRE, currencyFmt, dateDuration, dateFmt, emailRE, 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
|
@@ -60,6 +60,37 @@ type Dict<T = string> = Record<string, T>;
|
|
|
60
60
|
*/
|
|
61
61
|
type PartialBy<T, K extends keyof T> = Omit<T, K> & Partial<Pick<T, K>>;
|
|
62
62
|
|
|
63
|
+
interface HostEnv {
|
|
64
|
+
/**
|
|
65
|
+
* 是否是浙里办
|
|
66
|
+
*/
|
|
67
|
+
readonly zlb: boolean
|
|
68
|
+
/**
|
|
69
|
+
* 是否是专有钉
|
|
70
|
+
*/
|
|
71
|
+
readonly zyd: boolean
|
|
72
|
+
/**
|
|
73
|
+
* 是否是浙政钉
|
|
74
|
+
*/
|
|
75
|
+
readonly zzd: boolean
|
|
76
|
+
/**
|
|
77
|
+
* 是否是钉钉/专有钉/浙政钉
|
|
78
|
+
*/
|
|
79
|
+
readonly dd: boolean
|
|
80
|
+
/**
|
|
81
|
+
* 是否是微信
|
|
82
|
+
*/
|
|
83
|
+
readonly wx: boolean
|
|
84
|
+
/**
|
|
85
|
+
* 是否是支付宝
|
|
86
|
+
*/
|
|
87
|
+
readonly zfb: boolean
|
|
88
|
+
/**
|
|
89
|
+
* 是否是小程序
|
|
90
|
+
*/
|
|
91
|
+
readonly mini: boolean
|
|
92
|
+
}
|
|
93
|
+
|
|
63
94
|
/**
|
|
64
95
|
* snake2Kebab
|
|
65
96
|
* @param {string} str 字符串
|
|
@@ -293,8 +324,9 @@ declare const hideHead: (str: UnDef<string>, count?: number) => string;
|
|
|
293
324
|
*/
|
|
294
325
|
declare const hideTail: (str: UnDef<string>, count?: number) => string;
|
|
295
326
|
/**
|
|
296
|
-
*
|
|
297
|
-
* @param {string} phone
|
|
327
|
+
* 隐藏手机号/座机号
|
|
328
|
+
* @param {string} phone 手机号/座机号
|
|
329
|
+
* @returns {string} 隐藏后的手机号/座机号
|
|
298
330
|
*/
|
|
299
331
|
declare const hidePhone: (phone: UnDef<string>) => string;
|
|
300
332
|
/**
|
|
@@ -330,37 +362,6 @@ declare const hideEmail: (email: UnDef<string>) => string;
|
|
|
330
362
|
*/
|
|
331
363
|
declare const hideBankCard: (bankCard: UnDef<string>) => string;
|
|
332
364
|
|
|
333
|
-
interface HostEnv {
|
|
334
|
-
/**
|
|
335
|
-
* 是否是浙里办
|
|
336
|
-
*/
|
|
337
|
-
readonly zlb: boolean
|
|
338
|
-
/**
|
|
339
|
-
* 是否是专有钉
|
|
340
|
-
*/
|
|
341
|
-
readonly zyd: boolean
|
|
342
|
-
/**
|
|
343
|
-
* 是否是浙政钉
|
|
344
|
-
*/
|
|
345
|
-
readonly zzd: boolean
|
|
346
|
-
/**
|
|
347
|
-
* 是否是钉钉/专有钉/浙政钉
|
|
348
|
-
*/
|
|
349
|
-
readonly dd: boolean
|
|
350
|
-
/**
|
|
351
|
-
* 是否是微信
|
|
352
|
-
*/
|
|
353
|
-
readonly wx: boolean
|
|
354
|
-
/**
|
|
355
|
-
* 是否是支付宝
|
|
356
|
-
*/
|
|
357
|
-
readonly zfb: boolean
|
|
358
|
-
/**
|
|
359
|
-
* 是否是小程序
|
|
360
|
-
*/
|
|
361
|
-
readonly mini: boolean
|
|
362
|
-
}
|
|
363
|
-
|
|
364
365
|
/**
|
|
365
366
|
* 判断是否是浏览器环境
|
|
366
367
|
*/
|
|
@@ -714,6 +715,13 @@ declare const isValidKey: (key: string | number | symbol, object: object) => key
|
|
|
714
715
|
*/
|
|
715
716
|
declare const isEmpty: (val: UnDef<Numeric | boolean | Record<any, any> | Array<any> | Set<any> | Map<any, any>>) => boolean;
|
|
716
717
|
|
|
718
|
+
declare const cnPhoneRE: RegExp;
|
|
719
|
+
declare const cnTelRE: RegExp;
|
|
720
|
+
declare const cnTelRE2: RegExp;
|
|
721
|
+
declare const cnUSCIRE: RegExp;
|
|
722
|
+
declare const cnIdCard15Re: RegExp;
|
|
723
|
+
declare const cnIdCard18Re: RegExp;
|
|
724
|
+
declare const emailRE: RegExp;
|
|
717
725
|
/**
|
|
718
726
|
* 是否是[统一社会信用代码](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
727
|
* @example
|
|
@@ -793,4 +801,4 @@ declare const isValidArrRes: (res: Res<any[]>, code?: number) => boolean;
|
|
|
793
801
|
*/
|
|
794
802
|
declare const isValidPageRes: (res: PageRes, code?: number) => boolean;
|
|
795
803
|
|
|
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 };
|
|
804
|
+
export { type Dict, type HostEnv, 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, cnIdCard15Re, cnIdCard18Re, cnPhoneRE, cnTelRE, cnTelRE2, cnUSCIRE, currencyFmt, dateDuration, dateFmt, emailRE, 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
|
@@ -132,8 +132,12 @@ const isEmpty = (val) => {
|
|
|
132
132
|
};
|
|
133
133
|
|
|
134
134
|
const cnPhoneRE = /^1[3-9]\d{9}$/;
|
|
135
|
-
const cnTelRE = /^0\d{
|
|
135
|
+
const cnTelRE = /^0\d{2,3}-?\d{7,8}$/;
|
|
136
|
+
const cnTelRE2 = /^\(0\d{2,3}\)\d{7,8}$/;
|
|
136
137
|
const cnUSCIRE = /^[0-9A-HJ-NPQRTUWXY]{2}\d{6}[0-9A-HJ-NPQRTUWXY]{10}$/;
|
|
138
|
+
const cnIdCard15Re = /^[1-9]\d{7}(?:0[1-9]|10|11|12)(?:[0-2][1-9]|10|20|30|31)\d{2}[\dX]$/i;
|
|
139
|
+
const cnIdCard18Re = /^[1-9]\d{5}(?:18|19|20)\d{2}(?:0[1-9]|1[0-2])(?:[0-2][1-9]|10|20|30|31)\d{3}[\dX]$/i;
|
|
140
|
+
const emailRE = /^[a-z\d](?:\w|-)+@[a-z\d]+\.[a-z]{2,5}$/i;
|
|
137
141
|
const isUSCI = (val) => {
|
|
138
142
|
if (!isDef(val))
|
|
139
143
|
return false;
|
|
@@ -147,20 +151,18 @@ const isPhone = (val) => {
|
|
|
147
151
|
const isTel = (val) => {
|
|
148
152
|
if (!isDef(val))
|
|
149
153
|
return false;
|
|
150
|
-
|
|
154
|
+
const valStr = val.toString().replaceAll(" ", "");
|
|
155
|
+
return cnTelRE.test(valStr) || cnTelRE2.test(valStr);
|
|
151
156
|
};
|
|
152
157
|
const isEmail = (val) => {
|
|
153
158
|
if (!isDef(val))
|
|
154
159
|
return false;
|
|
155
|
-
|
|
156
|
-
return reg.test(val);
|
|
160
|
+
return emailRE.test(val);
|
|
157
161
|
};
|
|
158
162
|
const isIdCard = (val, compatible = true) => {
|
|
159
163
|
if (!isDef(val))
|
|
160
164
|
return false;
|
|
161
|
-
|
|
162
|
-
const card18 = /^[1-9]\d{5}(?:18|19|20)\d{2}(?:0[1-9]|1[0-2])(?:[0-2][1-9]|10|20|30|31)\d{3}[\dX]$/i;
|
|
163
|
-
return card18.test(val) || (compatible ? card15.test(val) : false);
|
|
165
|
+
return cnIdCard18Re.test(val) || (compatible ? cnIdCard15Re.test(val) : false);
|
|
164
166
|
};
|
|
165
167
|
const isNumeric = (val) => {
|
|
166
168
|
if (isDef(val))
|
|
@@ -247,11 +249,15 @@ const hideTail = (str, count) => {
|
|
|
247
249
|
};
|
|
248
250
|
const hidePhone = (phone) => {
|
|
249
251
|
if (phone) {
|
|
250
|
-
|
|
251
|
-
|
|
252
|
+
const phoneStr = phone.replaceAll(" ", "");
|
|
253
|
+
if (isPhone(phoneStr)) {
|
|
254
|
+
return phoneStr.replace(/^(\d{3})\d{4}(\d{4})$/, "$1****$2");
|
|
252
255
|
}
|
|
253
|
-
if (
|
|
254
|
-
return
|
|
256
|
+
if (cnTelRE.test(phoneStr)) {
|
|
257
|
+
return phoneStr.replace(/^(0\d{2,3})-?\d{3,4}(\d{4})$/, "$1****$2");
|
|
258
|
+
}
|
|
259
|
+
if (cnTelRE2.test(phoneStr)) {
|
|
260
|
+
return phoneStr.replace(/^\((0\d{2,3})\)\d{3,4}(\d{4})$/, "$1****$2");
|
|
255
261
|
}
|
|
256
262
|
return phone;
|
|
257
263
|
}
|
|
@@ -519,4 +525,4 @@ const getCodeOfHour = () => getCodeOfTime(`${dateFmt( new Date(), "YYYY-MM-DD HH
|
|
|
519
525
|
const getCodeOfDate = () => getCodeOfTime(dateFmt(/* @__PURE__ */ new Date(), "date"));
|
|
520
526
|
const getCodeOfMonth = () => getCodeOfTime(dateFmt(dayjs().endOf("month"), "date"));
|
|
521
527
|
|
|
522
|
-
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 };
|
|
528
|
+
export { attachFmt, camel2Kebab, camel2Pascal, camel2Snake, camel2Title, checkImg, cnIdCard15Re, cnIdCard18Re, cnPhoneRE, cnTelRE, cnTelRE2, cnUSCIRE, currencyFmt, dateDuration, dateFmt, emailRE, filterObj, fixiOSInputAutoZoomIn, getBaseAttachUrl, getCodeOfDate, getCodeOfHour, getCodeOfMonth, getHostEnv, getVariableType, hideBankCard, hideCardNo, hideEmail, hideFirstName, hideHead, hideMiddle, 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.11",
|
|
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",
|