@jhqn/utils-core 0.0.1-beta.11 → 0.0.1-beta.13

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 CHANGED
@@ -85,6 +85,23 @@ const isTel = (val) => {
85
85
  return false;
86
86
  return cnTelRE.test(val.toString());
87
87
  };
88
+ const isEmail = (val) => {
89
+ if (!isDef(val))
90
+ return false;
91
+ const reg = /^[a-zA-Z\d](?:\w|-)+@[a-zA-Z\d]+\.[a-zA-Z]{2,5}$/;
92
+ return reg.test(val);
93
+ };
94
+ const isIdCard = (val) => {
95
+ if (!isDef(val))
96
+ return false;
97
+ const card15 = /^[1-9]\d{7}(?:0[1-9]|10|11|12)(?:[0-2][1-9]|10|20|30|31)\d{2}[\dXx]$/;
98
+ 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]$/;
99
+ return card15.test(val) || card18.test(val);
100
+ };
101
+ const nonASCII = (text) => /[^\x20-\x7E]/.test(text);
102
+ const isValidRes = (res) => res.code === 200 && res.data;
103
+ const isValidArrRes = (res) => res.code === 200 && Array.isArray(res.data);
104
+ const isValidPageRes = (res) => res.code === 200 && res.data && Array.isArray(res.data.list || res.data.records);
88
105
 
89
106
  const hidePhone = (str) => {
90
107
  if (str) {
@@ -229,11 +246,16 @@ exports.hidePhone = hidePhone;
229
246
  exports.hideThird = hideThird;
230
247
  exports.isArrStr = isArrStr;
231
248
  exports.isDef = isDef;
249
+ exports.isEmail = isEmail;
250
+ exports.isIdCard = isIdCard;
232
251
  exports.isJSONStr = isJSONStr;
233
252
  exports.isNumeric = isNumeric;
234
253
  exports.isPhone = isPhone;
235
254
  exports.isTel = isTel;
255
+ exports.isValidArrRes = isValidArrRes;
236
256
  exports.isValidKey = isValidKey;
257
+ exports.isValidPageRes = isValidPageRes;
258
+ exports.isValidRes = isValidRes;
237
259
  exports.jClear = jClear;
238
260
  exports.jDebug = jDebug;
239
261
  exports.jError = jError;
@@ -249,6 +271,7 @@ exports.kebab2Camel = kebab2Camel;
249
271
  exports.kebab2Pascal = kebab2Pascal;
250
272
  exports.kebab2Snake = kebab2Snake;
251
273
  exports.kebab2Title = kebab2Title;
274
+ exports.nonASCII = nonASCII;
252
275
  exports.parseToJSON = parseToJSON;
253
276
  exports.pascal2Camel = pascal2Camel;
254
277
  exports.pascal2Kebab = pascal2Kebab;
package/dist/index.d.ts CHANGED
@@ -214,6 +214,18 @@ declare type Undefinable<T> = T | undefined;
214
214
  * 可 Null 或 Undefined
215
215
  */
216
216
  declare type NullOrUndefinable<T> = Nullable<Undefinable<T>>;
217
+ /**
218
+ * 请求结果
219
+ */
220
+ declare type Res<T = any> = Service.Response<T>;
221
+ /**
222
+ * 分页请求结果数据
223
+ */
224
+ declare type PageResData<T = any> = Service.PageResponseData<T>;
225
+ /**
226
+ * 分页请求结果
227
+ */
228
+ declare type PageRes<T = any> = Service.PageResponse<T>;
217
229
 
218
230
  /**
219
231
  * 隐藏手机号
@@ -494,5 +506,35 @@ declare const isPhone: (val: NullOrUndefinable<Numeric>) => boolean;
494
506
  * @param val
495
507
  */
496
508
  declare const isTel: (val: NullOrUndefinable<Numeric>) => boolean;
509
+ /**
510
+ * 是否是邮箱
511
+ * @param val
512
+ */
513
+ declare const isEmail: (val: NullOrUndefinable<string>) => boolean;
514
+ /**
515
+ * 是否是身份证
516
+ * @param val 身份证号
517
+ */
518
+ declare const isIdCard: (val: NullOrUndefinable<string>) => boolean;
519
+ /**
520
+ * 包含非ASCII字符
521
+ * @param text
522
+ */
523
+ declare const nonASCII: (text: string) => boolean;
524
+ /**
525
+ * 校验接口返回内容
526
+ * @param res
527
+ */
528
+ declare const isValidRes: (res: Res) => any;
529
+ /**
530
+ * 校验接口数组返回内容
531
+ * @param res
532
+ */
533
+ declare const isValidArrRes: (res: Res<any[]>) => boolean;
534
+ /**
535
+ * 校验接口分页返回内容
536
+ * @param res
537
+ */
538
+ declare const isValidPageRes: (res: PageRes) => boolean;
497
539
 
498
- export { NullOrUndefinable, Nullable, Numeric, Undefinable, camel2Kebab, camel2Pascal, camel2Snake, camel2Title, checkImg, filterObj, fixiOSInputAutoZoomIn, getHostEnv, hideCardNo, hideMiddle, hideName, hidePhone, hideThird, isArrStr, isDef, isJSONStr, isNumeric, isPhone, isTel, isValidKey, jClear, jDebug, jError, jGroup, jGroupC, jGroupE, jInfo, jLog, jTime, jTimeEnd, jWarn, kebab2Camel, kebab2Pascal, kebab2Snake, kebab2Title, parseToJSON, pascal2Camel, pascal2Kebab, pascal2Snake, pascal2Title, replacer, reviver, snake2Camel, snake2Kebab, snake2Pascal, snake2Title, title2Camel, title2Kebab, title2Pascal, title2Snake, userAgent, waitTime };
540
+ export { NullOrUndefinable, Nullable, Numeric, PageRes, PageResData, Res, Undefinable, camel2Kebab, camel2Pascal, camel2Snake, camel2Title, checkImg, filterObj, fixiOSInputAutoZoomIn, getHostEnv, hideCardNo, hideMiddle, hideName, hidePhone, hideThird, isArrStr, isDef, isEmail, isIdCard, isJSONStr, isNumeric, isPhone, isTel, isValidArrRes, isValidKey, isValidPageRes, isValidRes, jClear, jDebug, jError, jGroup, jGroupC, jGroupE, jInfo, jLog, jTime, jTimeEnd, jWarn, kebab2Camel, kebab2Pascal, kebab2Snake, kebab2Title, nonASCII, parseToJSON, pascal2Camel, pascal2Kebab, pascal2Snake, pascal2Title, replacer, reviver, snake2Camel, snake2Kebab, snake2Pascal, snake2Title, title2Camel, title2Kebab, title2Pascal, title2Snake, userAgent, waitTime };
package/dist/index.mjs CHANGED
@@ -83,6 +83,23 @@ const isTel = (val) => {
83
83
  return false;
84
84
  return cnTelRE.test(val.toString());
85
85
  };
86
+ const isEmail = (val) => {
87
+ if (!isDef(val))
88
+ return false;
89
+ const reg = /^[a-zA-Z\d](?:\w|-)+@[a-zA-Z\d]+\.[a-zA-Z]{2,5}$/;
90
+ return reg.test(val);
91
+ };
92
+ const isIdCard = (val) => {
93
+ if (!isDef(val))
94
+ return false;
95
+ const card15 = /^[1-9]\d{7}(?:0[1-9]|10|11|12)(?:[0-2][1-9]|10|20|30|31)\d{2}[\dXx]$/;
96
+ 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]$/;
97
+ return card15.test(val) || card18.test(val);
98
+ };
99
+ const nonASCII = (text) => /[^\x20-\x7E]/.test(text);
100
+ const isValidRes = (res) => res.code === 200 && res.data;
101
+ const isValidArrRes = (res) => res.code === 200 && Array.isArray(res.data);
102
+ const isValidPageRes = (res) => res.code === 200 && res.data && Array.isArray(res.data.list || res.data.records);
86
103
 
87
104
  const hidePhone = (str) => {
88
105
  if (str) {
@@ -212,4 +229,4 @@ const reviver = (_, value) => {
212
229
  };
213
230
  const filterObj = (obj, keys, reverse = false) => Object.fromEntries(Object.entries(obj).filter(([key]) => reverse ? !keys.includes(key) : keys.includes(key)));
214
231
 
215
- export { camel2Kebab, camel2Pascal, camel2Snake, camel2Title, checkImg, filterObj, fixiOSInputAutoZoomIn, getHostEnv, hideCardNo, hideMiddle, hideName, hidePhone, hideThird, isArrStr, isDef, isJSONStr, isNumeric, isPhone, isTel, isValidKey, jClear, jDebug, jError, jGroup, jGroupC, jGroupE, jInfo, jLog, jTime, jTimeEnd, jWarn, kebab2Camel, kebab2Pascal, kebab2Snake, kebab2Title, parseToJSON, pascal2Camel, pascal2Kebab, pascal2Snake, pascal2Title, replacer, reviver, snake2Camel, snake2Kebab, snake2Pascal, snake2Title, title2Camel, title2Kebab, title2Pascal, title2Snake, userAgent, waitTime };
232
+ export { camel2Kebab, camel2Pascal, camel2Snake, camel2Title, checkImg, filterObj, fixiOSInputAutoZoomIn, getHostEnv, hideCardNo, hideMiddle, hideName, hidePhone, hideThird, isArrStr, isDef, isEmail, isIdCard, isJSONStr, isNumeric, isPhone, isTel, isValidArrRes, isValidKey, isValidPageRes, isValidRes, jClear, jDebug, jError, jGroup, jGroupC, jGroupE, jInfo, jLog, jTime, jTimeEnd, jWarn, kebab2Camel, kebab2Pascal, kebab2Snake, kebab2Title, nonASCII, parseToJSON, pascal2Camel, pascal2Kebab, pascal2Snake, pascal2Title, replacer, reviver, snake2Camel, snake2Kebab, snake2Pascal, snake2Title, title2Camel, title2Kebab, title2Pascal, title2Snake, 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.11",
4
+ "version": "0.0.1-beta.13",
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",