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

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,9 @@ const isTel = (val) => {
85
85
  return false;
86
86
  return cnTelRE.test(val.toString());
87
87
  };
88
+ const isValidRes = (res) => res.code === 200 && res.data;
89
+ const isValidArrRes = (res) => res.code === 200 && Array.isArray(res.data);
90
+ const isValidPageRes = (res) => res.code === 200 && res.data && Array.isArray(res.data.list || res.data.records);
88
91
 
89
92
  const hidePhone = (str) => {
90
93
  if (str) {
@@ -233,7 +236,10 @@ exports.isJSONStr = isJSONStr;
233
236
  exports.isNumeric = isNumeric;
234
237
  exports.isPhone = isPhone;
235
238
  exports.isTel = isTel;
239
+ exports.isValidArrRes = isValidArrRes;
236
240
  exports.isValidKey = isValidKey;
241
+ exports.isValidPageRes = isValidPageRes;
242
+ exports.isValidRes = isValidRes;
237
243
  exports.jClear = jClear;
238
244
  exports.jDebug = jDebug;
239
245
  exports.jError = jError;
package/dist/index.d.ts CHANGED
@@ -214,6 +214,14 @@ 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 PageRes<T = any> = Service.PageResponse<T>;
217
225
 
218
226
  /**
219
227
  * 隐藏手机号
@@ -494,5 +502,20 @@ declare const isPhone: (val: NullOrUndefinable<Numeric>) => boolean;
494
502
  * @param val
495
503
  */
496
504
  declare const isTel: (val: NullOrUndefinable<Numeric>) => boolean;
505
+ /**
506
+ * 校验接口返回内容
507
+ * @param res
508
+ */
509
+ declare const isValidRes: (res: Res) => any;
510
+ /**
511
+ * 校验接口数组返回内容
512
+ * @param res
513
+ */
514
+ declare const isValidArrRes: (res: Res<any[]>) => boolean;
515
+ /**
516
+ * 校验接口分页返回内容
517
+ * @param res
518
+ */
519
+ declare const isValidPageRes: (res: PageRes) => boolean;
497
520
 
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 };
521
+ export { NullOrUndefinable, Nullable, Numeric, Undefinable, camel2Kebab, camel2Pascal, camel2Snake, camel2Title, checkImg, filterObj, fixiOSInputAutoZoomIn, getHostEnv, hideCardNo, hideMiddle, hideName, hidePhone, hideThird, isArrStr, isDef, isJSONStr, isNumeric, isPhone, isTel, isValidArrRes, isValidKey, isValidPageRes, isValidRes, 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 };
package/dist/index.mjs CHANGED
@@ -83,6 +83,9 @@ const isTel = (val) => {
83
83
  return false;
84
84
  return cnTelRE.test(val.toString());
85
85
  };
86
+ const isValidRes = (res) => res.code === 200 && res.data;
87
+ const isValidArrRes = (res) => res.code === 200 && Array.isArray(res.data);
88
+ const isValidPageRes = (res) => res.code === 200 && res.data && Array.isArray(res.data.list || res.data.records);
86
89
 
87
90
  const hidePhone = (str) => {
88
91
  if (str) {
@@ -212,4 +215,4 @@ const reviver = (_, value) => {
212
215
  };
213
216
  const filterObj = (obj, keys, reverse = false) => Object.fromEntries(Object.entries(obj).filter(([key]) => reverse ? !keys.includes(key) : keys.includes(key)));
214
217
 
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 };
218
+ export { camel2Kebab, camel2Pascal, camel2Snake, camel2Title, checkImg, filterObj, fixiOSInputAutoZoomIn, getHostEnv, hideCardNo, hideMiddle, hideName, hidePhone, hideThird, isArrStr, isDef, isJSONStr, isNumeric, isPhone, isTel, isValidArrRes, isValidKey, isValidPageRes, isValidRes, 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 };
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.12",
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",