@jhqn/utils-core 0.4.1 → 0.4.2

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.
Files changed (2) hide show
  1. package/dist/index.js +16 -10
  2. package/package.json +1 -1
package/dist/index.js CHANGED
@@ -354,12 +354,18 @@ const isDef = (val) => !isNull(val) && !isUndefined(val);
354
354
  * @param str
355
355
  */
356
356
  const isJSONStr = (str) => {
357
- if (isDef(str)) try {
358
- JSON.parse(str);
359
- return true;
360
- } catch (e) {
361
- jWarn("Failed to parse invalid string", e);
362
- return false;
357
+ if (isDef(str)) {
358
+ const normalized = str.trim();
359
+ if (normalized === "") return false;
360
+ const firstChar = normalized[0];
361
+ if (!"{[\"tfn-0123456789".includes(firstChar)) return false;
362
+ try {
363
+ JSON.parse(normalized);
364
+ return true;
365
+ } catch (e) {
366
+ jWarn("Failed to parse invalid string", e);
367
+ return false;
368
+ }
363
369
  }
364
370
  return false;
365
371
  };
@@ -369,7 +375,7 @@ const isJSONStr = (str) => {
369
375
  */
370
376
  const isArrStr = (str) => {
371
377
  if (isDef(str)) try {
372
- return Array.isArray(JSON.parse(str));
378
+ return isArray(JSON.parse(str));
373
379
  } catch (e) {
374
380
  jWarn("Failed to parse invalid string", e);
375
381
  return false;
@@ -517,13 +523,13 @@ const isValidRes = (res, code) => isValidResCode(res, code) && isDef(res.data);
517
523
  * @param res
518
524
  * @param code
519
525
  */
520
- const isValidArrRes = (res, code) => isValidResCode(res, code) && Array.isArray(res.data);
526
+ const isValidArrRes = (res, code) => isValidResCode(res, code) && isArray(res.data);
521
527
  /**
522
528
  * 校验接口分页返回内容
523
529
  * @param res
524
530
  * @param code
525
531
  */
526
- const isValidPageRes = (res, code) => isValidResCode(res, code) && isDef(res.data) && Array.isArray(res.data.list || res.data.records);
532
+ const isValidPageRes = (res, code) => isValidResCode(res, code) && isDef(res.data) && isArray(res.data.list || res.data.records);
527
533
 
528
534
  //#endregion
529
535
  //#region src/desensitize.ts
@@ -914,7 +920,7 @@ const attachFmt = (data) => {
914
920
  let attachList = [];
915
921
  const prototype = Object.prototype.toString.call(data);
916
922
  if (!data) attachList = [];
917
- else if (Array.isArray(data)) attachList = data.filter(Boolean);
923
+ else if (isArray(data)) attachList = data.filter(Boolean);
918
924
  else if (typeof data === "string") if (isArrStr(data)) attachList = (parseJSON(data) || []).filter(Boolean);
919
925
  else {
920
926
  const jsonData = parseJSON(data);
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@jhqn/utils-core",
3
- "version": "0.4.1",
3
+ "version": "0.4.2",
4
4
  "keywords": [
5
5
  "jade",
6
6
  "utils"