@jhqn/utils-core 0.0.2-beta.1 → 0.0.2-beta.3
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/index.cjs +39 -17
- package/dist/index.d.cts +53 -39
- package/dist/index.d.mts +53 -39
- package/dist/index.d.ts +53 -39
- package/dist/index.mjs +38 -18
- package/package.json +1 -1
package/dist/index.cjs
CHANGED
|
@@ -69,8 +69,24 @@ const jTime = (str) => console.time(`[${str}]`);
|
|
|
69
69
|
const jTimeEnd = (str) => console.timeEnd(`[${str}]`);
|
|
70
70
|
const jClear = console.clear.bind(console);
|
|
71
71
|
|
|
72
|
-
|
|
73
|
-
const
|
|
72
|
+
let prevValue;
|
|
73
|
+
const jLogDedupe = (...args) => {
|
|
74
|
+
if (args.length === 0)
|
|
75
|
+
return;
|
|
76
|
+
if (args.length > 0 && prevValue && JSON.stringify(args) === JSON.stringify(prevValue))
|
|
77
|
+
return;
|
|
78
|
+
jLog(...args);
|
|
79
|
+
prevValue = args;
|
|
80
|
+
};
|
|
81
|
+
|
|
82
|
+
let logged = false;
|
|
83
|
+
const jLogOnce = (...args) => {
|
|
84
|
+
if (logged)
|
|
85
|
+
return;
|
|
86
|
+
jLog(...args);
|
|
87
|
+
logged = true;
|
|
88
|
+
};
|
|
89
|
+
|
|
74
90
|
const getVariableType = (val) => {
|
|
75
91
|
const value = Object.prototype.toString.call(val);
|
|
76
92
|
const result = value.match(/\[object (\S*)\]/)?.[1];
|
|
@@ -97,17 +113,6 @@ const isBlob = (val) => getVariableType(val) === "blob";
|
|
|
97
113
|
const isURL = (val) => getVariableType(val) === "url";
|
|
98
114
|
const isError = (val) => getVariableType(val) === "error";
|
|
99
115
|
const isDef = (val) => !isNull(val) && !isUndefined(val);
|
|
100
|
-
const isNumeric = (val) => {
|
|
101
|
-
if (isDef(val))
|
|
102
|
-
return typeof val === "number" || /^\d+(?:\.\d+)?$/.test(val);
|
|
103
|
-
return false;
|
|
104
|
-
};
|
|
105
|
-
const checkImg = (ext) => {
|
|
106
|
-
return /\.(?:jpg|jpeg|png|gif)$/.test((ext || "").toLowerCase());
|
|
107
|
-
};
|
|
108
|
-
const isEmpty = (val) => {
|
|
109
|
-
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;
|
|
110
|
-
};
|
|
111
116
|
const isJSONStr = (str) => {
|
|
112
117
|
if (isDef(str))
|
|
113
118
|
try {
|
|
@@ -128,6 +133,17 @@ const isArrStr = (str) => {
|
|
|
128
133
|
return false;
|
|
129
134
|
};
|
|
130
135
|
const isValidKey = (key, object) => key in object;
|
|
136
|
+
const isEmpty = (val) => {
|
|
137
|
+
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;
|
|
138
|
+
};
|
|
139
|
+
|
|
140
|
+
const isValidResCode = (res, code = 200) => res.code === code;
|
|
141
|
+
const isValidRes = (res, code) => isValidResCode(res, code) && isDef(res.data);
|
|
142
|
+
const isValidArrRes = (res, code) => isValidResCode(res, code) && Array.isArray(res.data);
|
|
143
|
+
const isValidPageRes = (res, code) => isValidResCode(res, code) && isDef(res.data) && Array.isArray(res.data.list || res.data.records);
|
|
144
|
+
|
|
145
|
+
const cnPhoneRE = /^1[3-9]\d{9}$/;
|
|
146
|
+
const cnTelRE = /^0\d{9,11}$/;
|
|
131
147
|
const isPhone = (val) => {
|
|
132
148
|
if (!isDef(val))
|
|
133
149
|
return false;
|
|
@@ -151,11 +167,15 @@ const isIdCard = (val, compatible = true) => {
|
|
|
151
167
|
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]$/;
|
|
152
168
|
return card18.test(val) || (compatible ? card15.test(val) : false);
|
|
153
169
|
};
|
|
170
|
+
const isNumeric = (val) => {
|
|
171
|
+
if (isDef(val))
|
|
172
|
+
return typeof val === "number" || /^\d+(?:\.\d+)?$/.test(val);
|
|
173
|
+
return false;
|
|
174
|
+
};
|
|
175
|
+
const checkImg = (ext) => {
|
|
176
|
+
return /\.(?:jpg|jpeg|png|gif)$/.test((ext || "").toLowerCase());
|
|
177
|
+
};
|
|
154
178
|
const nonASCII = (text) => /[^\x20-\x7E]/.test(text);
|
|
155
|
-
const isValidResCode = (res, code = 200) => res.code === code;
|
|
156
|
-
const isValidRes = (res, code) => isValidResCode(res, code) && isDef(res.data);
|
|
157
|
-
const isValidArrRes = (res, code) => isValidResCode(res, code) && Array.isArray(res.data);
|
|
158
|
-
const isValidPageRes = (res, code) => isValidResCode(res, code) && isDef(res.data) && Array.isArray(res.data.list || res.data.records);
|
|
159
179
|
const isValidFileType = (file, type) => {
|
|
160
180
|
if (type === "*")
|
|
161
181
|
return true;
|
|
@@ -542,6 +562,8 @@ exports.jGroupC = jGroupC;
|
|
|
542
562
|
exports.jGroupE = jGroupE;
|
|
543
563
|
exports.jInfo = jInfo;
|
|
544
564
|
exports.jLog = jLog;
|
|
565
|
+
exports.jLogDedupe = jLogDedupe;
|
|
566
|
+
exports.jLogOnce = jLogOnce;
|
|
545
567
|
exports.jTime = jTime;
|
|
546
568
|
exports.jTimeEnd = jTimeEnd;
|
|
547
569
|
exports.jWarn = jWarn;
|
package/dist/index.d.cts
CHANGED
|
@@ -205,6 +205,18 @@ declare const jClear: {
|
|
|
205
205
|
(): void;
|
|
206
206
|
};
|
|
207
207
|
|
|
208
|
+
/**
|
|
209
|
+
* 不连续打印相同的值
|
|
210
|
+
* @param args
|
|
211
|
+
*/
|
|
212
|
+
declare const jLogDedupe: (...args: any[]) => void;
|
|
213
|
+
|
|
214
|
+
/**
|
|
215
|
+
* 只打印一次
|
|
216
|
+
* @param args
|
|
217
|
+
*/
|
|
218
|
+
declare const jLogOnce: (...args: any[]) => void;
|
|
219
|
+
|
|
208
220
|
/**
|
|
209
221
|
* 数字或字符串
|
|
210
222
|
*/
|
|
@@ -763,21 +775,6 @@ declare const isError: (val: any) => val is Error;
|
|
|
763
775
|
* @param {any} val 检测的目标
|
|
764
776
|
*/
|
|
765
777
|
declare const isDef: <T>(val: T) => val is NonNullable<T>;
|
|
766
|
-
/**
|
|
767
|
-
* 是否是数字或字符
|
|
768
|
-
* @param val
|
|
769
|
-
*/
|
|
770
|
-
declare const isNumeric: (val: UnDef<Numeric>) => val is string;
|
|
771
|
-
/**
|
|
772
|
-
* 是否是需要的图片格式
|
|
773
|
-
* @param ext
|
|
774
|
-
*/
|
|
775
|
-
declare const checkImg: (ext?: string) => boolean;
|
|
776
|
-
/**
|
|
777
|
-
* 是否是空值/空数组/空对象 null undefined '' [] {} Set Map
|
|
778
|
-
* @param val
|
|
779
|
-
*/
|
|
780
|
-
declare const isEmpty: (val: UnDef<Numeric | boolean | Record<any, any> | Array<any> | Set<any> | Map<any, any>>) => boolean;
|
|
781
778
|
/**
|
|
782
779
|
* 判断是否合法JSON字符串
|
|
783
780
|
* @param str
|
|
@@ -802,31 +799,11 @@ declare const isArrStr: (str: UnDef<string>) => boolean;
|
|
|
802
799
|
*/
|
|
803
800
|
declare const isValidKey: (key: string | number | symbol, object: object) => key is never;
|
|
804
801
|
/**
|
|
805
|
-
*
|
|
806
|
-
* @param val
|
|
807
|
-
*/
|
|
808
|
-
declare const isPhone: (val: UnDef<Numeric>) => boolean;
|
|
809
|
-
/**
|
|
810
|
-
* 是否是中国座机号
|
|
811
|
-
* @param val
|
|
812
|
-
*/
|
|
813
|
-
declare const isTel: (val: UnDef<Numeric>) => boolean;
|
|
814
|
-
/**
|
|
815
|
-
* 是否是邮箱
|
|
802
|
+
* 是否是空值/空数组/空对象 null undefined '' [] {} Set Map
|
|
816
803
|
* @param val
|
|
817
804
|
*/
|
|
818
|
-
declare const
|
|
819
|
-
|
|
820
|
-
* 是否是身份证
|
|
821
|
-
* @param {string|null|undefined} val 身份证号
|
|
822
|
-
* @param {boolean} compatible 兼容15位
|
|
823
|
-
*/
|
|
824
|
-
declare const isIdCard: (val: UnDef<string>, compatible?: boolean) => boolean;
|
|
825
|
-
/**
|
|
826
|
-
* 包含非ASCII字符
|
|
827
|
-
* @param text
|
|
828
|
-
*/
|
|
829
|
-
declare const nonASCII: (text: string) => boolean;
|
|
805
|
+
declare const isEmpty: (val: UnDef<Numeric | boolean | Record<any, any> | Array<any> | Set<any> | Map<any, any>>) => boolean;
|
|
806
|
+
|
|
830
807
|
/**
|
|
831
808
|
* 校验接口返回code
|
|
832
809
|
* @param res
|
|
@@ -851,6 +828,43 @@ declare const isValidArrRes: (res: Res<any[]>, code?: number) => boolean;
|
|
|
851
828
|
* @param code
|
|
852
829
|
*/
|
|
853
830
|
declare const isValidPageRes: (res: PageRes, code?: number) => boolean;
|
|
831
|
+
|
|
832
|
+
/**
|
|
833
|
+
* 是否是中国手机号
|
|
834
|
+
* @param val
|
|
835
|
+
*/
|
|
836
|
+
declare const isPhone: (val: UnDef<Numeric>) => boolean;
|
|
837
|
+
/**
|
|
838
|
+
* 是否是中国座机号
|
|
839
|
+
* @param val
|
|
840
|
+
*/
|
|
841
|
+
declare const isTel: (val: UnDef<Numeric>) => boolean;
|
|
842
|
+
/**
|
|
843
|
+
* 是否是邮箱
|
|
844
|
+
* @param val
|
|
845
|
+
*/
|
|
846
|
+
declare const isEmail: (val: UnDef<string>) => boolean;
|
|
847
|
+
/**
|
|
848
|
+
* 是否是身份证
|
|
849
|
+
* @param {string|null|undefined} val 身份证号
|
|
850
|
+
* @param {boolean} compatible 兼容15位
|
|
851
|
+
*/
|
|
852
|
+
declare const isIdCard: (val: UnDef<string>, compatible?: boolean) => boolean;
|
|
853
|
+
/**
|
|
854
|
+
* 是否是数字或字符
|
|
855
|
+
* @param val
|
|
856
|
+
*/
|
|
857
|
+
declare const isNumeric: (val: UnDef<Numeric>) => val is string;
|
|
858
|
+
/**
|
|
859
|
+
* 是否是需要的图片格式
|
|
860
|
+
* @param ext
|
|
861
|
+
*/
|
|
862
|
+
declare const checkImg: (ext?: string) => boolean;
|
|
863
|
+
/**
|
|
864
|
+
* 包含非ASCII字符
|
|
865
|
+
* @param text
|
|
866
|
+
*/
|
|
867
|
+
declare const nonASCII: (text: string) => boolean;
|
|
854
868
|
/**
|
|
855
869
|
* 校验文件类型
|
|
856
870
|
* 1. XXX/YYY 2. .xxx 3. XXX/* 4.*
|
|
@@ -859,4 +873,4 @@ declare const isValidPageRes: (res: PageRes, code?: number) => boolean;
|
|
|
859
873
|
*/
|
|
860
874
|
declare const isValidFileType: (file: File, type: string) => boolean;
|
|
861
875
|
|
|
862
|
-
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, getVariableType, hideBankCard, hideCardNo, hideEmail, hideFirstName, hideHead, hideMiddle, hideName, hidePhone, hideSurname, hideTail, hideThird, inBrowser, isArrStr, isArray, 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, 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 };
|
|
876
|
+
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, getVariableType, hideBankCard, hideCardNo, hideEmail, hideFirstName, hideHead, hideMiddle, hideName, hidePhone, hideSurname, hideTail, hideThird, inBrowser, isArrStr, isArray, 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, 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
|
@@ -205,6 +205,18 @@ declare const jClear: {
|
|
|
205
205
|
(): void;
|
|
206
206
|
};
|
|
207
207
|
|
|
208
|
+
/**
|
|
209
|
+
* 不连续打印相同的值
|
|
210
|
+
* @param args
|
|
211
|
+
*/
|
|
212
|
+
declare const jLogDedupe: (...args: any[]) => void;
|
|
213
|
+
|
|
214
|
+
/**
|
|
215
|
+
* 只打印一次
|
|
216
|
+
* @param args
|
|
217
|
+
*/
|
|
218
|
+
declare const jLogOnce: (...args: any[]) => void;
|
|
219
|
+
|
|
208
220
|
/**
|
|
209
221
|
* 数字或字符串
|
|
210
222
|
*/
|
|
@@ -763,21 +775,6 @@ declare const isError: (val: any) => val is Error;
|
|
|
763
775
|
* @param {any} val 检测的目标
|
|
764
776
|
*/
|
|
765
777
|
declare const isDef: <T>(val: T) => val is NonNullable<T>;
|
|
766
|
-
/**
|
|
767
|
-
* 是否是数字或字符
|
|
768
|
-
* @param val
|
|
769
|
-
*/
|
|
770
|
-
declare const isNumeric: (val: UnDef<Numeric>) => val is string;
|
|
771
|
-
/**
|
|
772
|
-
* 是否是需要的图片格式
|
|
773
|
-
* @param ext
|
|
774
|
-
*/
|
|
775
|
-
declare const checkImg: (ext?: string) => boolean;
|
|
776
|
-
/**
|
|
777
|
-
* 是否是空值/空数组/空对象 null undefined '' [] {} Set Map
|
|
778
|
-
* @param val
|
|
779
|
-
*/
|
|
780
|
-
declare const isEmpty: (val: UnDef<Numeric | boolean | Record<any, any> | Array<any> | Set<any> | Map<any, any>>) => boolean;
|
|
781
778
|
/**
|
|
782
779
|
* 判断是否合法JSON字符串
|
|
783
780
|
* @param str
|
|
@@ -802,31 +799,11 @@ declare const isArrStr: (str: UnDef<string>) => boolean;
|
|
|
802
799
|
*/
|
|
803
800
|
declare const isValidKey: (key: string | number | symbol, object: object) => key is never;
|
|
804
801
|
/**
|
|
805
|
-
*
|
|
806
|
-
* @param val
|
|
807
|
-
*/
|
|
808
|
-
declare const isPhone: (val: UnDef<Numeric>) => boolean;
|
|
809
|
-
/**
|
|
810
|
-
* 是否是中国座机号
|
|
811
|
-
* @param val
|
|
812
|
-
*/
|
|
813
|
-
declare const isTel: (val: UnDef<Numeric>) => boolean;
|
|
814
|
-
/**
|
|
815
|
-
* 是否是邮箱
|
|
802
|
+
* 是否是空值/空数组/空对象 null undefined '' [] {} Set Map
|
|
816
803
|
* @param val
|
|
817
804
|
*/
|
|
818
|
-
declare const
|
|
819
|
-
|
|
820
|
-
* 是否是身份证
|
|
821
|
-
* @param {string|null|undefined} val 身份证号
|
|
822
|
-
* @param {boolean} compatible 兼容15位
|
|
823
|
-
*/
|
|
824
|
-
declare const isIdCard: (val: UnDef<string>, compatible?: boolean) => boolean;
|
|
825
|
-
/**
|
|
826
|
-
* 包含非ASCII字符
|
|
827
|
-
* @param text
|
|
828
|
-
*/
|
|
829
|
-
declare const nonASCII: (text: string) => boolean;
|
|
805
|
+
declare const isEmpty: (val: UnDef<Numeric | boolean | Record<any, any> | Array<any> | Set<any> | Map<any, any>>) => boolean;
|
|
806
|
+
|
|
830
807
|
/**
|
|
831
808
|
* 校验接口返回code
|
|
832
809
|
* @param res
|
|
@@ -851,6 +828,43 @@ declare const isValidArrRes: (res: Res<any[]>, code?: number) => boolean;
|
|
|
851
828
|
* @param code
|
|
852
829
|
*/
|
|
853
830
|
declare const isValidPageRes: (res: PageRes, code?: number) => boolean;
|
|
831
|
+
|
|
832
|
+
/**
|
|
833
|
+
* 是否是中国手机号
|
|
834
|
+
* @param val
|
|
835
|
+
*/
|
|
836
|
+
declare const isPhone: (val: UnDef<Numeric>) => boolean;
|
|
837
|
+
/**
|
|
838
|
+
* 是否是中国座机号
|
|
839
|
+
* @param val
|
|
840
|
+
*/
|
|
841
|
+
declare const isTel: (val: UnDef<Numeric>) => boolean;
|
|
842
|
+
/**
|
|
843
|
+
* 是否是邮箱
|
|
844
|
+
* @param val
|
|
845
|
+
*/
|
|
846
|
+
declare const isEmail: (val: UnDef<string>) => boolean;
|
|
847
|
+
/**
|
|
848
|
+
* 是否是身份证
|
|
849
|
+
* @param {string|null|undefined} val 身份证号
|
|
850
|
+
* @param {boolean} compatible 兼容15位
|
|
851
|
+
*/
|
|
852
|
+
declare const isIdCard: (val: UnDef<string>, compatible?: boolean) => boolean;
|
|
853
|
+
/**
|
|
854
|
+
* 是否是数字或字符
|
|
855
|
+
* @param val
|
|
856
|
+
*/
|
|
857
|
+
declare const isNumeric: (val: UnDef<Numeric>) => val is string;
|
|
858
|
+
/**
|
|
859
|
+
* 是否是需要的图片格式
|
|
860
|
+
* @param ext
|
|
861
|
+
*/
|
|
862
|
+
declare const checkImg: (ext?: string) => boolean;
|
|
863
|
+
/**
|
|
864
|
+
* 包含非ASCII字符
|
|
865
|
+
* @param text
|
|
866
|
+
*/
|
|
867
|
+
declare const nonASCII: (text: string) => boolean;
|
|
854
868
|
/**
|
|
855
869
|
* 校验文件类型
|
|
856
870
|
* 1. XXX/YYY 2. .xxx 3. XXX/* 4.*
|
|
@@ -859,4 +873,4 @@ declare const isValidPageRes: (res: PageRes, code?: number) => boolean;
|
|
|
859
873
|
*/
|
|
860
874
|
declare const isValidFileType: (file: File, type: string) => boolean;
|
|
861
875
|
|
|
862
|
-
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, getVariableType, hideBankCard, hideCardNo, hideEmail, hideFirstName, hideHead, hideMiddle, hideName, hidePhone, hideSurname, hideTail, hideThird, inBrowser, isArrStr, isArray, 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, 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 };
|
|
876
|
+
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, getVariableType, hideBankCard, hideCardNo, hideEmail, hideFirstName, hideHead, hideMiddle, hideName, hidePhone, hideSurname, hideTail, hideThird, inBrowser, isArrStr, isArray, 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, 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
|
@@ -205,6 +205,18 @@ declare const jClear: {
|
|
|
205
205
|
(): void;
|
|
206
206
|
};
|
|
207
207
|
|
|
208
|
+
/**
|
|
209
|
+
* 不连续打印相同的值
|
|
210
|
+
* @param args
|
|
211
|
+
*/
|
|
212
|
+
declare const jLogDedupe: (...args: any[]) => void;
|
|
213
|
+
|
|
214
|
+
/**
|
|
215
|
+
* 只打印一次
|
|
216
|
+
* @param args
|
|
217
|
+
*/
|
|
218
|
+
declare const jLogOnce: (...args: any[]) => void;
|
|
219
|
+
|
|
208
220
|
/**
|
|
209
221
|
* 数字或字符串
|
|
210
222
|
*/
|
|
@@ -763,21 +775,6 @@ declare const isError: (val: any) => val is Error;
|
|
|
763
775
|
* @param {any} val 检测的目标
|
|
764
776
|
*/
|
|
765
777
|
declare const isDef: <T>(val: T) => val is NonNullable<T>;
|
|
766
|
-
/**
|
|
767
|
-
* 是否是数字或字符
|
|
768
|
-
* @param val
|
|
769
|
-
*/
|
|
770
|
-
declare const isNumeric: (val: UnDef<Numeric>) => val is string;
|
|
771
|
-
/**
|
|
772
|
-
* 是否是需要的图片格式
|
|
773
|
-
* @param ext
|
|
774
|
-
*/
|
|
775
|
-
declare const checkImg: (ext?: string) => boolean;
|
|
776
|
-
/**
|
|
777
|
-
* 是否是空值/空数组/空对象 null undefined '' [] {} Set Map
|
|
778
|
-
* @param val
|
|
779
|
-
*/
|
|
780
|
-
declare const isEmpty: (val: UnDef<Numeric | boolean | Record<any, any> | Array<any> | Set<any> | Map<any, any>>) => boolean;
|
|
781
778
|
/**
|
|
782
779
|
* 判断是否合法JSON字符串
|
|
783
780
|
* @param str
|
|
@@ -802,31 +799,11 @@ declare const isArrStr: (str: UnDef<string>) => boolean;
|
|
|
802
799
|
*/
|
|
803
800
|
declare const isValidKey: (key: string | number | symbol, object: object) => key is never;
|
|
804
801
|
/**
|
|
805
|
-
*
|
|
806
|
-
* @param val
|
|
807
|
-
*/
|
|
808
|
-
declare const isPhone: (val: UnDef<Numeric>) => boolean;
|
|
809
|
-
/**
|
|
810
|
-
* 是否是中国座机号
|
|
811
|
-
* @param val
|
|
812
|
-
*/
|
|
813
|
-
declare const isTel: (val: UnDef<Numeric>) => boolean;
|
|
814
|
-
/**
|
|
815
|
-
* 是否是邮箱
|
|
802
|
+
* 是否是空值/空数组/空对象 null undefined '' [] {} Set Map
|
|
816
803
|
* @param val
|
|
817
804
|
*/
|
|
818
|
-
declare const
|
|
819
|
-
|
|
820
|
-
* 是否是身份证
|
|
821
|
-
* @param {string|null|undefined} val 身份证号
|
|
822
|
-
* @param {boolean} compatible 兼容15位
|
|
823
|
-
*/
|
|
824
|
-
declare const isIdCard: (val: UnDef<string>, compatible?: boolean) => boolean;
|
|
825
|
-
/**
|
|
826
|
-
* 包含非ASCII字符
|
|
827
|
-
* @param text
|
|
828
|
-
*/
|
|
829
|
-
declare const nonASCII: (text: string) => boolean;
|
|
805
|
+
declare const isEmpty: (val: UnDef<Numeric | boolean | Record<any, any> | Array<any> | Set<any> | Map<any, any>>) => boolean;
|
|
806
|
+
|
|
830
807
|
/**
|
|
831
808
|
* 校验接口返回code
|
|
832
809
|
* @param res
|
|
@@ -851,6 +828,43 @@ declare const isValidArrRes: (res: Res<any[]>, code?: number) => boolean;
|
|
|
851
828
|
* @param code
|
|
852
829
|
*/
|
|
853
830
|
declare const isValidPageRes: (res: PageRes, code?: number) => boolean;
|
|
831
|
+
|
|
832
|
+
/**
|
|
833
|
+
* 是否是中国手机号
|
|
834
|
+
* @param val
|
|
835
|
+
*/
|
|
836
|
+
declare const isPhone: (val: UnDef<Numeric>) => boolean;
|
|
837
|
+
/**
|
|
838
|
+
* 是否是中国座机号
|
|
839
|
+
* @param val
|
|
840
|
+
*/
|
|
841
|
+
declare const isTel: (val: UnDef<Numeric>) => boolean;
|
|
842
|
+
/**
|
|
843
|
+
* 是否是邮箱
|
|
844
|
+
* @param val
|
|
845
|
+
*/
|
|
846
|
+
declare const isEmail: (val: UnDef<string>) => boolean;
|
|
847
|
+
/**
|
|
848
|
+
* 是否是身份证
|
|
849
|
+
* @param {string|null|undefined} val 身份证号
|
|
850
|
+
* @param {boolean} compatible 兼容15位
|
|
851
|
+
*/
|
|
852
|
+
declare const isIdCard: (val: UnDef<string>, compatible?: boolean) => boolean;
|
|
853
|
+
/**
|
|
854
|
+
* 是否是数字或字符
|
|
855
|
+
* @param val
|
|
856
|
+
*/
|
|
857
|
+
declare const isNumeric: (val: UnDef<Numeric>) => val is string;
|
|
858
|
+
/**
|
|
859
|
+
* 是否是需要的图片格式
|
|
860
|
+
* @param ext
|
|
861
|
+
*/
|
|
862
|
+
declare const checkImg: (ext?: string) => boolean;
|
|
863
|
+
/**
|
|
864
|
+
* 包含非ASCII字符
|
|
865
|
+
* @param text
|
|
866
|
+
*/
|
|
867
|
+
declare const nonASCII: (text: string) => boolean;
|
|
854
868
|
/**
|
|
855
869
|
* 校验文件类型
|
|
856
870
|
* 1. XXX/YYY 2. .xxx 3. XXX/* 4.*
|
|
@@ -859,4 +873,4 @@ declare const isValidPageRes: (res: PageRes, code?: number) => boolean;
|
|
|
859
873
|
*/
|
|
860
874
|
declare const isValidFileType: (file: File, type: string) => boolean;
|
|
861
875
|
|
|
862
|
-
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, getVariableType, hideBankCard, hideCardNo, hideEmail, hideFirstName, hideHead, hideMiddle, hideName, hidePhone, hideSurname, hideTail, hideThird, inBrowser, isArrStr, isArray, 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, 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 };
|
|
876
|
+
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, getVariableType, hideBankCard, hideCardNo, hideEmail, hideFirstName, hideHead, hideMiddle, hideName, hidePhone, hideSurname, hideTail, hideThird, inBrowser, isArrStr, isArray, 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, 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
|
@@ -58,8 +58,24 @@ const jTime = (str) => console.time(`[${str}]`);
|
|
|
58
58
|
const jTimeEnd = (str) => console.timeEnd(`[${str}]`);
|
|
59
59
|
const jClear = console.clear.bind(console);
|
|
60
60
|
|
|
61
|
-
|
|
62
|
-
const
|
|
61
|
+
let prevValue;
|
|
62
|
+
const jLogDedupe = (...args) => {
|
|
63
|
+
if (args.length === 0)
|
|
64
|
+
return;
|
|
65
|
+
if (args.length > 0 && prevValue && JSON.stringify(args) === JSON.stringify(prevValue))
|
|
66
|
+
return;
|
|
67
|
+
jLog(...args);
|
|
68
|
+
prevValue = args;
|
|
69
|
+
};
|
|
70
|
+
|
|
71
|
+
let logged = false;
|
|
72
|
+
const jLogOnce = (...args) => {
|
|
73
|
+
if (logged)
|
|
74
|
+
return;
|
|
75
|
+
jLog(...args);
|
|
76
|
+
logged = true;
|
|
77
|
+
};
|
|
78
|
+
|
|
63
79
|
const getVariableType = (val) => {
|
|
64
80
|
const value = Object.prototype.toString.call(val);
|
|
65
81
|
const result = value.match(/\[object (\S*)\]/)?.[1];
|
|
@@ -86,17 +102,6 @@ const isBlob = (val) => getVariableType(val) === "blob";
|
|
|
86
102
|
const isURL = (val) => getVariableType(val) === "url";
|
|
87
103
|
const isError = (val) => getVariableType(val) === "error";
|
|
88
104
|
const isDef = (val) => !isNull(val) && !isUndefined(val);
|
|
89
|
-
const isNumeric = (val) => {
|
|
90
|
-
if (isDef(val))
|
|
91
|
-
return typeof val === "number" || /^\d+(?:\.\d+)?$/.test(val);
|
|
92
|
-
return false;
|
|
93
|
-
};
|
|
94
|
-
const checkImg = (ext) => {
|
|
95
|
-
return /\.(?:jpg|jpeg|png|gif)$/.test((ext || "").toLowerCase());
|
|
96
|
-
};
|
|
97
|
-
const isEmpty = (val) => {
|
|
98
|
-
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;
|
|
99
|
-
};
|
|
100
105
|
const isJSONStr = (str) => {
|
|
101
106
|
if (isDef(str))
|
|
102
107
|
try {
|
|
@@ -117,6 +122,17 @@ const isArrStr = (str) => {
|
|
|
117
122
|
return false;
|
|
118
123
|
};
|
|
119
124
|
const isValidKey = (key, object) => key in object;
|
|
125
|
+
const isEmpty = (val) => {
|
|
126
|
+
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;
|
|
127
|
+
};
|
|
128
|
+
|
|
129
|
+
const isValidResCode = (res, code = 200) => res.code === code;
|
|
130
|
+
const isValidRes = (res, code) => isValidResCode(res, code) && isDef(res.data);
|
|
131
|
+
const isValidArrRes = (res, code) => isValidResCode(res, code) && Array.isArray(res.data);
|
|
132
|
+
const isValidPageRes = (res, code) => isValidResCode(res, code) && isDef(res.data) && Array.isArray(res.data.list || res.data.records);
|
|
133
|
+
|
|
134
|
+
const cnPhoneRE = /^1[3-9]\d{9}$/;
|
|
135
|
+
const cnTelRE = /^0\d{9,11}$/;
|
|
120
136
|
const isPhone = (val) => {
|
|
121
137
|
if (!isDef(val))
|
|
122
138
|
return false;
|
|
@@ -140,11 +156,15 @@ const isIdCard = (val, compatible = true) => {
|
|
|
140
156
|
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]$/;
|
|
141
157
|
return card18.test(val) || (compatible ? card15.test(val) : false);
|
|
142
158
|
};
|
|
159
|
+
const isNumeric = (val) => {
|
|
160
|
+
if (isDef(val))
|
|
161
|
+
return typeof val === "number" || /^\d+(?:\.\d+)?$/.test(val);
|
|
162
|
+
return false;
|
|
163
|
+
};
|
|
164
|
+
const checkImg = (ext) => {
|
|
165
|
+
return /\.(?:jpg|jpeg|png|gif)$/.test((ext || "").toLowerCase());
|
|
166
|
+
};
|
|
143
167
|
const nonASCII = (text) => /[^\x20-\x7E]/.test(text);
|
|
144
|
-
const isValidResCode = (res, code = 200) => res.code === code;
|
|
145
|
-
const isValidRes = (res, code) => isValidResCode(res, code) && isDef(res.data);
|
|
146
|
-
const isValidArrRes = (res, code) => isValidResCode(res, code) && Array.isArray(res.data);
|
|
147
|
-
const isValidPageRes = (res, code) => isValidResCode(res, code) && isDef(res.data) && Array.isArray(res.data.list || res.data.records);
|
|
148
168
|
const isValidFileType = (file, type) => {
|
|
149
169
|
if (type === "*")
|
|
150
170
|
return true;
|
|
@@ -461,4 +481,4 @@ const attachFmt = (data) => {
|
|
|
461
481
|
return attachList.map(recoverFile);
|
|
462
482
|
};
|
|
463
483
|
|
|
464
|
-
export { attachFmt, camel2Kebab, camel2Pascal, camel2Snake, camel2Title, checkImg, currencyFmt, dateDuration, dateFmt, filterObj, fixiOSInputAutoZoomIn, getBaseAttachUrl, getHostEnv, getVariableType, hideBankCard, hideCardNo, hideEmail, hideFirstName, hideHead, hideMiddle, hideName, hidePhone, hideSurname, hideTail, hideThird, inBrowser, isArrStr, isArray, 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, 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 };
|
|
484
|
+
export { attachFmt, camel2Kebab, camel2Pascal, camel2Snake, camel2Title, checkImg, currencyFmt, dateDuration, dateFmt, filterObj, fixiOSInputAutoZoomIn, getBaseAttachUrl, getHostEnv, getVariableType, hideBankCard, hideCardNo, hideEmail, hideFirstName, hideHead, hideMiddle, hideName, hidePhone, hideSurname, hideTail, hideThird, inBrowser, isArrStr, isArray, 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, 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