@jhqn/utils-core 0.4.3 → 0.4.5

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 -22
  2. package/package.json +2 -2
package/dist/index.js CHANGED
@@ -5,7 +5,6 @@ import duration from "dayjs/plugin/duration.js";
5
5
  import localeData from "dayjs/plugin/localeData.js";
6
6
  import objectSupport from "dayjs/plugin/objectSupport.js";
7
7
  import relativeTime from "dayjs/plugin/relativeTime.js";
8
-
9
8
  //#region src/case.ts
10
9
  /**
11
10
  * snake2Kebab
@@ -150,7 +149,6 @@ const title2Pascal = (str) => str.replace(/ /g, "");
150
149
  * @example title2Camel('Hello World') // Hello World => helloWorld
151
150
  */
152
151
  const title2Camel = (str) => str.replace(/ /g, "").replace(/^[A-Z]/, (match) => match.toLowerCase());
153
-
154
152
  //#endregion
155
153
  //#region src/console/log-common.ts
156
154
  const sharedStyle = "color: white; padding: 1px 2px;";
@@ -185,7 +183,7 @@ const jGroup = console.group.bind(console, "%c[%s]", `${sharedStyle} background:
185
183
  /**
186
184
  * jade console.groupCollapsed
187
185
  */
188
- const jGroupC = console.groupCollapsed.bind(console, "%c[%s]", `${sharedStyle} background: slateblue;`);
186
+ const jGroupC = console?.groupCollapsed?.bind(console, "%c[%s]", `${sharedStyle} background: slateblue;`);
189
187
  /**
190
188
  * jade console.groupEnd
191
189
  */
@@ -194,17 +192,16 @@ const jGroupE = console.groupEnd.bind(console);
194
192
  * jade console.time
195
193
  * @param str
196
194
  */
197
- const jTime = (str) => console.time(`[${str}]`);
195
+ const jTime = (str) => console?.time(`[${str}]`);
198
196
  /**
199
197
  * jade console.timeEnd
200
198
  * @param str
201
199
  */
202
- const jTimeEnd = (str) => console.timeEnd(`[${str}]`);
200
+ const jTimeEnd = (str) => console?.timeEnd(`[${str}]`);
203
201
  /**
204
202
  * jade console.clear
205
203
  */
206
- const jClear = console.clear.bind(console);
207
-
204
+ const jClear = console?.clear?.bind(console);
208
205
  //#endregion
209
206
  //#region src/console/log-dedupe.ts
210
207
  let prevValue;
@@ -218,7 +215,6 @@ const jLogDedupe = (...args) => {
218
215
  jLog(...args);
219
216
  prevValue = args;
220
217
  };
221
-
222
218
  //#endregion
223
219
  //#region src/console/log-once.ts
224
220
  let logged = false;
@@ -231,7 +227,6 @@ const jLogOnce = (...args) => {
231
227
  jLog(...args);
232
228
  logged = true;
233
229
  };
234
-
235
230
  //#endregion
236
231
  //#region src/validate/core.ts
237
232
  /**
@@ -350,12 +345,23 @@ const isError = (val) => getVariableType(val) === "error";
350
345
  */
351
346
  const isDef = (val) => !isNull(val) && !isUndefined(val);
352
347
  const INVALID_JSON = Symbol("invalid_json");
348
+ const JSON_LITERAL_PREFIXES = {
349
+ t: "true",
350
+ f: "false",
351
+ n: "null"
352
+ };
353
353
  const parseJSONLikeStr = (str) => {
354
354
  if (!isDef(str)) return INVALID_JSON;
355
355
  const normalized = str.trim();
356
356
  if (normalized === "") return INVALID_JSON;
357
357
  const firstChar = normalized[0];
358
358
  if (!"{[\"tfn-0123456789".includes(firstChar)) return INVALID_JSON;
359
+ if (firstChar in JSON_LITERAL_PREFIXES) {
360
+ const literal = JSON_LITERAL_PREFIXES[firstChar];
361
+ if (!normalized.startsWith(literal)) return INVALID_JSON;
362
+ const nextChar = normalized[literal.length];
363
+ if (isDef(nextChar) && !",]} \r\n".includes(nextChar)) return INVALID_JSON;
364
+ }
359
365
  try {
360
366
  return JSON.parse(normalized);
361
367
  } catch (e) {
@@ -396,7 +402,6 @@ const isValidKey = (key, object) => key in object;
396
402
  const isEmpty = (val) => {
397
403
  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;
398
404
  };
399
-
400
405
  //#endregion
401
406
  //#region src/validate/form.ts
402
407
  const cnPhoneRE = /^1[3-9]\d{9}$/;
@@ -497,7 +502,6 @@ const isValidFileType = (file, type) => {
497
502
  if (typeArrStr.length > 1) return typeArrStr.some(validate);
498
503
  return validate(type);
499
504
  };
500
-
501
505
  //#endregion
502
506
  //#region src/validate/request.ts
503
507
  /**
@@ -524,7 +528,6 @@ const isValidArrRes = (res, code) => isValidResCode(res, code) && isArray(res.da
524
528
  * @param code
525
529
  */
526
530
  const isValidPageRes = (res, code) => isValidResCode(res, code) && isDef(res.data) && isArray(res.data.list || res.data.records);
527
-
528
531
  //#endregion
529
532
  //#region src/desensitize.ts
530
533
  /**
@@ -712,7 +715,6 @@ const hideBankCard = (bankCard) => {
712
715
  }
713
716
  return "";
714
717
  };
715
-
716
718
  //#endregion
717
719
  //#region src/format/baseAttachUrl.ts
718
720
  /**
@@ -732,7 +734,6 @@ function setBaseAttachUrl(baseUrl) {
732
734
  function getBaseAttachUrl() {
733
735
  return __BASE_ATTACH_URL__;
734
736
  }
735
-
736
737
  //#endregion
737
738
  //#region src/format/core.ts
738
739
  /**
@@ -806,7 +807,6 @@ function reviver(_key, value) {
806
807
  * @param {boolean} reverse 为true时过滤取反
807
808
  */
808
809
  const filterObj = (obj, keys, reverse = false) => Object.fromEntries(Object.entries(obj).filter(([key]) => reverse ? !keys.includes(key) : keys.includes(key)));
809
-
810
810
  //#endregion
811
811
  //#region src/format/currency.ts
812
812
  /**
@@ -834,7 +834,6 @@ const currencyFmt = (currency, maximumFractionDigits = 2) => {
834
834
  maximumFractionDigits
835
835
  }).format(num);
836
836
  };
837
-
838
837
  //#endregion
839
838
  //#region src/format/dayjs.ts
840
839
  dayjs.extend(localeData).locale("zh-cn", zhCN);
@@ -876,7 +875,6 @@ const dateDuration = (start, end) => {
876
875
  ].join("");
877
876
  return dd.format(format);
878
877
  };
879
-
880
878
  //#endregion
881
879
  //#region src/format/resource.ts
882
880
  /**
@@ -929,7 +927,6 @@ const attachFmt = (data) => {
929
927
  else if (prototype === "[object Object]") attachList = [data];
930
928
  return attachList.map(recoverFile);
931
929
  };
932
-
933
930
  //#endregion
934
931
  //#region src/format/sort.ts
935
932
  /**
@@ -966,7 +963,6 @@ const naturalSort = (arr) => {
966
963
  const naturalSortBy = (arr, key) => {
967
964
  return [...arr].sort((a, b) => naturalSort([a[key], b[key]])[0] === a[key] ? -1 : 1);
968
965
  };
969
-
970
966
  //#endregion
971
967
  //#region src/dom.ts
972
968
  /**
@@ -1045,7 +1041,6 @@ const getCodeOfDate = () => getCodeOfTime(dateFmt(/* @__PURE__ */ new Date(), "d
1045
1041
  * 获取当月的时间戳的异或值的绝对值, 当月内获取的值是唯一的
1046
1042
  */
1047
1043
  const getCodeOfMonth = () => getCodeOfTime(dateFmt(dayjs().endOf("month"), "date"));
1048
-
1049
1044
  //#endregion
1050
1045
  //#region src/mock.ts
1051
1046
  const getMockData = (data, code = 200, message = "success") => {
@@ -1067,6 +1062,5 @@ const getMockDataList = (data, total, code = 200, message = "success", options =
1067
1062
  message
1068
1063
  };
1069
1064
  };
1070
-
1071
1065
  //#endregion
1072
- export { attachFmt, camel2Kebab, camel2Pascal, camel2Snake, camel2Title, checkImg, cnIdCard15Re, cnIdCard18Re, cnPhoneRE, cnTelRE, cnTelRE2, cnUSCIRE, currencyFmt, dateDuration, dateFmt, dayjs, emailRE, filterObj, fixiOSInputAutoZoomIn, getBaseAttachUrl, getCodeOfDate, getCodeOfHour, getCodeOfMonth, getHostEnv, getMockData, getMockDataList, getVariableType, hideBankCard, hideCardNo, hideEmail, hideFirstName, hideHead, hideMiddle, 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, parseJSON, parseToJSON, pascal2Camel, pascal2Kebab, pascal2Snake, pascal2Title, recoverFile, replacer, resUrl, reviver, setBaseAttachUrl, snake2Camel, snake2Kebab, snake2Pascal, snake2Title, stringifyJSON, title2Camel, title2Kebab, title2Pascal, title2Snake, toThousands, userAgent, waitTime };
1066
+ export { attachFmt, camel2Kebab, camel2Pascal, camel2Snake, camel2Title, checkImg, cnIdCard15Re, cnIdCard18Re, cnPhoneRE, cnTelRE, cnTelRE2, cnUSCIRE, currencyFmt, dateDuration, dateFmt, dayjs, emailRE, filterObj, fixiOSInputAutoZoomIn, getBaseAttachUrl, getCodeOfDate, getCodeOfHour, getCodeOfMonth, getHostEnv, getMockData, getMockDataList, getVariableType, hideBankCard, hideCardNo, hideEmail, hideFirstName, hideHead, hideMiddle, 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, parseJSON, parseToJSON, pascal2Camel, pascal2Kebab, pascal2Snake, pascal2Title, recoverFile, replacer, resUrl, reviver, setBaseAttachUrl, snake2Camel, snake2Kebab, snake2Pascal, snake2Title, stringifyJSON, title2Camel, title2Kebab, title2Pascal, title2Snake, toThousands, userAgent, waitTime };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@jhqn/utils-core",
3
- "version": "0.4.3",
3
+ "version": "0.4.5",
4
4
  "keywords": [
5
5
  "jade",
6
6
  "utils"
@@ -33,7 +33,7 @@
33
33
  }
34
34
  },
35
35
  "dependencies": {
36
- "dayjs": "^1.11.19",
36
+ "dayjs": "^1.11.20",
37
37
  "detect-browser-es": "0.1.1"
38
38
  },
39
39
  "scripts": {