@sybz-components/utils 1.0.22 → 1.0.23

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.
@@ -148,6 +148,7 @@ function formatTime(time = /* @__PURE__ */ new Date(), cFormat = "{y}-{m}-{d} {h
148
148
  });
149
149
  }
150
150
  function formatDurationTime(timestamp, cFormat = "{d}\u5929{h}\u65F6{i}\u5206{s}\u79D2") {
151
+ var _a, _b, _c, _d, _e, _f;
151
152
  const secondsPerMinute = 60;
152
153
  const minutesPerHour = 60;
153
154
  const hoursPerDay = 24;
@@ -169,11 +170,11 @@ function formatDurationTime(timestamp, cFormat = "{d}\u5929{h}\u65F6{i}\u5206{s}
169
170
  };
170
171
  let parseFormat = cFormat;
171
172
  if (days === 0) {
172
- parseFormat = cFormat.match(/{h}.*/g)?.[0] ?? "";
173
+ parseFormat = (_b = (_a = cFormat.match(/{h}.*/g)) == null ? void 0 : _a[0]) != null ? _b : "";
173
174
  if (hours === 0) {
174
- parseFormat = cFormat.match(/{i}.*/g)?.[0] ?? "";
175
+ parseFormat = (_d = (_c = cFormat.match(/{i}.*/g)) == null ? void 0 : _c[0]) != null ? _d : "";
175
176
  if (minutes === 0) {
176
- parseFormat = cFormat.match(/{s}.*/g)?.[0] ?? "";
177
+ parseFormat = (_f = (_e = cFormat.match(/{s}.*/g)) == null ? void 0 : _e[0]) != null ? _f : "";
177
178
  }
178
179
  }
179
180
  }
@@ -225,13 +226,16 @@ function formatTextToHtml(str) {
225
226
  return withBreaks.replace(/\t/g, "    ");
226
227
  }
227
228
 
229
+ var __defProp = Object.defineProperty;
230
+ var __defNormalProp = (obj, key, value) => key in obj ? __defProp(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
231
+ var __publicField = (obj, key, value) => __defNormalProp(obj, typeof key !== "symbol" ? key + "" : key, value);
228
232
  class HttpError extends Error {
229
- status;
230
- code;
231
- data;
232
- cause;
233
233
  constructor(message, options = {}) {
234
234
  super(message);
235
+ __publicField(this, "status");
236
+ __publicField(this, "code");
237
+ __publicField(this, "data");
238
+ __publicField(this, "cause");
235
239
  this.name = "HttpError";
236
240
  Object.assign(this, options);
237
241
  }
@@ -264,10 +268,10 @@ function createHttp(options = {}) {
264
268
  return new HttpError(error instanceof Error ? error.message : "\u8BF7\u6C42\u5931\u8D25", { cause: error });
265
269
  const response = error.response;
266
270
  const message = error.code === axios.AxiosError.ECONNABORTED || error.code === "ETIMEDOUT" ? "\u8BF7\u6C42\u8D85\u65F6\uFF0C\u8BF7\u91CD\u8BD5" : error.code === axios.AxiosError.ERR_CANCELED ? "\u8BF7\u6C42\u5DF2\u53D6\u6D88" : response ? `\u8BF7\u6C42\u5931\u8D25\uFF08${response.status}\uFF09` : "\u7F51\u7EDC\u8FDE\u63A5\u5931\u8D25\uFF0C\u8BF7\u68C0\u67E5\u7F51\u7EDC\u540E\u91CD\u8BD5";
267
- return new HttpError(getBusinessMessage(response?.data, message), {
268
- status: response?.status,
271
+ return new HttpError(getBusinessMessage(response == null ? void 0 : response.data, message), {
272
+ status: response == null ? void 0 : response.status,
269
273
  code: error.code,
270
- data: response?.data,
274
+ data: response == null ? void 0 : response.data,
271
275
  cause: error
272
276
  });
273
277
  };
@@ -275,11 +279,11 @@ function createHttp(options = {}) {
275
279
  const requestConfig = config;
276
280
  requestConfig.headers = axios.AxiosHeaders.from(requestConfig.headers);
277
281
  if (!requestConfig.skipAuth) {
278
- const token = getToken?.();
282
+ const token = getToken == null ? void 0 : getToken();
279
283
  if (token && !requestConfig.headers.has("Authorization"))
280
284
  requestConfig.headers.set("Authorization", `Bearer ${token}`);
281
285
  }
282
- return onRequest?.(requestConfig) || requestConfig;
286
+ return (onRequest == null ? void 0 : onRequest(requestConfig)) || requestConfig;
283
287
  });
284
288
  instance.interceptors.response.use(
285
289
  (response) => {
@@ -294,17 +298,18 @@ function createHttp(options = {}) {
294
298
  response.data,
295
299
  response
296
300
  );
297
- onResponse?.(response);
301
+ onResponse == null ? void 0 : onResponse(response);
298
302
  return response;
299
303
  },
300
304
  async (error) => {
305
+ var _a;
301
306
  const normalized = normalizeError ? normalizeError(error) : normalize(error);
302
307
  const response = axios__default.isAxiosError(error) ? error.response : void 0;
303
- const requestConfig = response?.config;
304
- const customMessage = requestConfig?.message;
308
+ const requestConfig = response == null ? void 0 : response.config;
309
+ const customMessage = requestConfig == null ? void 0 : requestConfig.message;
305
310
  const message = typeof customMessage === "function" ? customMessage(normalized) : customMessage || normalized.message;
306
- if (requestConfig?.showErrorToast ?? showErrorToast) toast?.(message);
307
- await onError?.(normalized, response);
311
+ if ((_a = requestConfig == null ? void 0 : requestConfig.showErrorToast) != null ? _a : showErrorToast) toast == null ? void 0 : toast(message);
312
+ await (onError == null ? void 0 : onError(normalized, response));
308
313
  throw normalized;
309
314
  }
310
315
  );
@@ -361,7 +366,7 @@ function _getBrowserStorage(isSession = false) {
361
366
  }
362
367
  try {
363
368
  return isSession ? window.sessionStorage : window.localStorage;
364
- } catch {
369
+ } catch (e) {
365
370
  return null;
366
371
  }
367
372
  }
@@ -374,7 +379,7 @@ function _parseStorageValue(value) {
374
379
  if (typeof parsed !== "number") {
375
380
  return parsed;
376
381
  }
377
- } catch {
382
+ } catch (e) {
378
383
  }
379
384
  return value;
380
385
  }
@@ -382,16 +387,17 @@ function renderToastComponents(message, components, handlers) {
382
387
  const template = document.createElement("template");
383
388
  template.innerHTML = message;
384
389
  const renderNode = (node) => {
385
- if (node.nodeType === Node.TEXT_NODE) return node.textContent ?? "";
390
+ var _a, _b;
391
+ if (node.nodeType === Node.TEXT_NODE) return (_a = node.textContent) != null ? _a : "";
386
392
  if (node.nodeType !== Node.ELEMENT_NODE) return null;
387
393
  const element = node;
388
394
  const tag = element.tagName.toLowerCase();
389
395
  const pascalTag = tag.replace(/(^|-)([a-z])/g, (_, _separator, letter) => letter.toUpperCase());
390
- const component = components[tag] ?? components[pascalTag];
396
+ const component = (_b = components[tag]) != null ? _b : components[pascalTag];
391
397
  const attrs = {};
392
398
  for (const { name, value } of Array.from(element.attributes)) {
393
399
  if (name.startsWith("@")) {
394
- const handler = handlers?.[value];
400
+ const handler = handlers == null ? void 0 : handlers[value];
395
401
  if (handler) {
396
402
  const eventName = name.slice(1).replace(/(^|-)([a-z])/g, (_, _separator, letter) => letter.toUpperCase());
397
403
  attrs[`on${eventName}`] = handler;
@@ -423,6 +429,7 @@ function $toast(message, type = "success", otherParams = {}) {
423
429
  return typeof obj === "object" && obj !== null && !vue.isVNode(obj);
424
430
  }
425
431
  function showToast(options) {
432
+ var _a, _b;
426
433
  const {
427
434
  theme = utilsConfig.theme,
428
435
  customClass,
@@ -433,9 +440,9 @@ function $toast(message, type = "success", otherParams = {}) {
433
440
  } = options;
434
441
  let htmlStringEnabled = dangerouslyUseHTMLString;
435
442
  const appContext = _resolveAppContext(null);
436
- const appComponents = appContext?.components;
443
+ const appComponents = appContext == null ? void 0 : appContext.components;
437
444
  if (typeof messageOptions.icon === "string") {
438
- const icon = appComponents?.SIcon ?? appComponents?.["s-icon"];
445
+ const icon = (_a = appComponents == null ? void 0 : appComponents.SIcon) != null ? _a : appComponents == null ? void 0 : appComponents["s-icon"];
439
446
  if (icon) {
440
447
  const iconName = messageOptions.icon;
441
448
  messageOptions.icon = () => vue.h(icon, { cursor: "default", ...iconAttrs, icon: iconName });
@@ -445,7 +452,7 @@ function $toast(message, type = "success", otherParams = {}) {
445
452
  messageOptions.icon = () => vue.h(icon, iconAttrs);
446
453
  }
447
454
  if (typeof messageOptions.message === "string" && htmlStringEnabled) {
448
- const registeredComponents = appComponents ?? {};
455
+ const registeredComponents = appComponents != null ? appComponents : {};
449
456
  if (Object.keys(registeredComponents).length > 0) {
450
457
  messageOptions.message = renderToastComponents(messageOptions.message, registeredComponents, handlers);
451
458
  htmlStringEnabled = false;
@@ -463,7 +470,7 @@ function $toast(message, type = "success", otherParams = {}) {
463
470
  const resolvedMessageOptions = {
464
471
  ...messageOptions,
465
472
  dangerouslyUseHTMLString: htmlStringEnabled,
466
- showClose: options.showClose ?? true,
473
+ showClose: (_b = options.showClose) != null ? _b : true,
467
474
  customClass: resolvedCustomClass
468
475
  };
469
476
  if (appContext) elementPlus.ElMessage(resolvedMessageOptions, appContext);
@@ -519,14 +526,14 @@ function clearStorage(str = "") {
519
526
  return;
520
527
  }
521
528
  if (isEmpty(str)) {
522
- sessionStorageRef?.clear();
523
- localStorageRef?.clear();
529
+ sessionStorageRef == null ? void 0 : sessionStorageRef.clear();
530
+ localStorageRef == null ? void 0 : localStorageRef.clear();
524
531
  }
525
532
  if (typeof str === "string" || Array.isArray(str)) {
526
533
  const strArr = Array.isArray(str) ? str : [str];
527
534
  for (let i = 0; i < strArr.length; i++) {
528
- sessionStorageRef?.removeItem(strArr[i]);
529
- localStorageRef?.removeItem(strArr[i]);
535
+ sessionStorageRef == null ? void 0 : sessionStorageRef.removeItem(strArr[i]);
536
+ localStorageRef == null ? void 0 : localStorageRef.removeItem(strArr[i]);
530
537
  }
531
538
  }
532
539
  if (_isObjectWithExclude(str)) {
@@ -546,8 +553,8 @@ function clearStorage(str = "") {
546
553
  }
547
554
  }
548
555
  }
549
- sessionStorageRef?.clear();
550
- localStorageRef?.clear();
556
+ sessionStorageRef == null ? void 0 : sessionStorageRef.clear();
557
+ localStorageRef == null ? void 0 : localStorageRef.clear();
551
558
  for (const key in sessionStorageObj) {
552
559
  setStorage(key, sessionStorageObj[key], true);
553
560
  }
@@ -563,23 +570,24 @@ function _isObjectWithExclude(obj) {
563
570
  function validateForm(ref, { message, detail = false, showMessage = true } = {}) {
564
571
  return new Promise((resolve, reject) => {
565
572
  vue.unref(ref).validate((valid, status) => {
573
+ var _a;
566
574
  if (valid) {
567
575
  resolve(status);
568
576
  } else {
569
577
  if (showMessage) {
570
- const fieldNames = Object.keys(status ?? {});
578
+ const fieldNames = Object.keys(status != null ? status : {});
571
579
  const errors = fieldNames.flatMap((field) => {
572
580
  const fieldErrors = status[field];
573
581
  return Array.isArray(fieldErrors) ? fieldErrors : [fieldErrors];
574
582
  });
575
- const errorMessages = errors.map((error) => error?.message).filter((errorMessage) => typeof errorMessage === "string" && !!errorMessage.trim());
576
- const nonRequiredMessage = errors.find((error) => {
577
- const errorMessage = error?.message;
583
+ const errorMessages = errors.map((error) => error == null ? void 0 : error.message).filter((errorMessage) => typeof errorMessage === "string" && !!errorMessage.trim());
584
+ const nonRequiredMessage = (_a = errors.find((error) => {
585
+ const errorMessage = error == null ? void 0 : error.message;
578
586
  if (typeof errorMessage !== "string" || !errorMessage.trim()) return false;
579
587
  if ("fieldValue" in Object(error) && !isEmpty(error.fieldValue)) return true;
580
588
  return !/^(请输入|请选择|请填写|请上传|请勾选|不能为空)/.test(errorMessage) || /^请输入(?:正确|非负|正|整数|数字|\d|至少|最多|不超过)/.test(errorMessage);
581
- })?.message;
582
- const defaultMessage = nonRequiredMessage ?? (errorMessages.length ? "\u5B58\u5728\u5FC5\u586B\u9879\u672A\u586B\u5199\uFF0C\u8BF7\u8865\u5145\u5B8C\u6574" : "\u8868\u5355\u6821\u9A8C\u672A\u901A\u8FC7\uFF0C\u8BF7\u68C0\u67E5\u8F93\u5165");
589
+ })) == null ? void 0 : _a.message;
590
+ const defaultMessage = nonRequiredMessage != null ? nonRequiredMessage : errorMessages.length ? "\u5B58\u5728\u5FC5\u586B\u9879\u672A\u586B\u5199\uFF0C\u8BF7\u8865\u5145\u5B8C\u6574" : "\u8868\u5355\u6821\u9A8C\u672A\u901A\u8FC7\uFF0C\u8BF7\u68C0\u67E5\u8F93\u5165";
583
591
  const toastMessage = message === void 0 ? defaultMessage : message;
584
592
  if (toastMessage) $toast(detail ? toastMessage + fieldNames.join(",") : toastMessage, "e");
585
593
  }
@@ -665,7 +673,7 @@ function mockValue(type = "", length = 4, options = {}) {
665
673
  type = unref2(type);
666
674
  if (Array.isArray(type)) {
667
675
  if (type.length === 0) return "";
668
- const randIndex = optionsIndex ?? random2(0, type.length - 1);
676
+ const randIndex = optionsIndex != null ? optionsIndex : random2(0, type.length - 1);
669
677
  const selectedItem = type[randIndex];
670
678
  if (typeof selectedItem === "object" && selectedItem !== null && "value" in selectedItem) {
671
679
  return selectedItem.value;
@@ -720,12 +728,13 @@ function getType(type) {
720
728
  function delay(delay2 = 0, fn) {
721
729
  return new Promise(
722
730
  (resolve) => setTimeout(() => {
723
- fn?.();
731
+ fn == null ? void 0 : fn();
724
732
  resolve();
725
733
  }, delay2)
726
734
  );
727
735
  }
728
736
  function validateOnSubmit(type = "required", rules = {}, pureValid = false) {
737
+ var _a;
729
738
  const normalized = normalizeValidateParams(type, rules, pureValid);
730
739
  if (normalized.pureValid) {
731
740
  return validate(normalized.type, normalized.rawRules, true);
@@ -734,7 +743,7 @@ function validateOnSubmit(type = "required", rules = {}, pureValid = false) {
734
743
  normalized.type,
735
744
  {
736
745
  ...normalized.rulesObject,
737
- trigger: normalized.rulesObject.trigger ?? []
746
+ trigger: (_a = normalized.rulesObject.trigger) != null ? _a : []
738
747
  },
739
748
  normalized.pureValid
740
749
  );
@@ -759,14 +768,15 @@ var ValidateType = /* @__PURE__ */ ((ValidateType2) => {
759
768
  return ValidateType2;
760
769
  })(ValidateType || {});
761
770
  function validate(type = "required", rules = {}, pureValid = false) {
771
+ var _a, _b, _c, _d, _e, _f;
762
772
  const normalized = normalizeValidateParams(type, rules, pureValid);
763
773
  const rulesObject = normalized.rulesObject;
764
774
  const rawRules = normalized.rawRules;
765
775
  const validType = normalized.type;
766
776
  const isPureValid = normalized.pureValid;
767
- const trigger = rulesObject.trigger ?? ["blur", "change"];
777
+ const trigger = (_a = rulesObject.trigger) != null ? _a : ["blur", "change"];
768
778
  const typeMaps = Object.values(ValidateType);
769
- const parseRequired = rulesObject.required ?? true;
779
+ const parseRequired = (_b = rulesObject.required) != null ? _b : true;
770
780
  const defaultRequiredMessage = validType === "change" /* CHANGE */ ? "\u8BF7\u9009\u62E9" : "\u8BF7\u8F93\u5165";
771
781
  const getPureValue = () => Object.prototype.hasOwnProperty.call(rulesObject, "value") ? rulesObject.value : rawRules;
772
782
  if (!typeMaps.includes(validType)) {
@@ -779,7 +789,7 @@ function validate(type = "required", rules = {}, pureValid = false) {
779
789
  if (validType === "required" /* REQUIRED */ || validType === "change" /* CHANGE */) {
780
790
  return {
781
791
  required: parseRequired,
782
- message: rulesObject.message ?? defaultRequiredMessage,
792
+ message: (_c = rulesObject.message) != null ? _c : defaultRequiredMessage,
783
793
  trigger
784
794
  };
785
795
  }
@@ -837,8 +847,8 @@ function validate(type = "required", rules = {}, pureValid = false) {
837
847
  );
838
848
  }
839
849
  if (validType === "between" /* BETWEEN */) {
840
- let minValue = rulesObject.min ?? "";
841
- let maxValue = rulesObject.max ?? "";
850
+ let minValue = (_d = rulesObject.min) != null ? _d : "";
851
+ let maxValue = (_e = rulesObject.max) != null ? _e : "";
842
852
  const validateBetween = (rule, value, callback) => {
843
853
  let validFlag = /^-?[0-9]+$/.test(value);
844
854
  if (!validFlag) {
@@ -862,7 +872,7 @@ function validate(type = "required", rules = {}, pureValid = false) {
862
872
  return {
863
873
  min: rulesObject.min,
864
874
  max: rulesObject.max,
865
- message: rulesObject.message ?? `\u8BF7\u8F93\u5165${rulesObject.min}\u5230${rulesObject.max}\u4E2A\u5B57\u7B26`,
875
+ message: (_f = rulesObject.message) != null ? _f : `\u8BF7\u8F93\u5165${rulesObject.min}\u5230${rulesObject.max}\u4E2A\u5B57\u7B26`,
866
876
  trigger,
867
877
  required: parseRequired
868
878
  };
@@ -890,20 +900,22 @@ function validate(type = "required", rules = {}, pureValid = false) {
890
900
  return _validValue(getPureValue(), rulesObject.message, isPureValid, rulesObject.reg);
891
901
  }
892
902
  function _validValue(value, msg, pureValid2, reg) {
903
+ var _a2;
893
904
  if (pureValid2) {
894
905
  return reg.test(value);
895
906
  }
896
907
  const validatePhone = (rule, value2, callback) => {
908
+ var _a3;
897
909
  let validFlag = reg.test(value2);
898
910
  if (!validFlag) {
899
- callback(new Error(rulesObject.message ?? msg));
911
+ callback(new Error((_a3 = rulesObject.message) != null ? _a3 : msg));
900
912
  } else {
901
913
  callback();
902
914
  }
903
915
  };
904
916
  return {
905
917
  validator: validatePhone,
906
- required: rulesObject.required ?? true,
918
+ required: (_a2 = rulesObject.required) != null ? _a2 : true,
907
919
  trigger
908
920
  };
909
921
  }
@@ -942,7 +954,8 @@ const copy = (text, toastParams = {}) => {
942
954
  return true;
943
955
  };
944
956
  function log(variableStr, variable, otherInfo = "") {
945
- const stack = new Error().stack?.split("\n")[2]?.trim() ?? "";
957
+ var _a, _b, _c;
958
+ const stack = (_c = (_b = (_a = new Error().stack) == null ? void 0 : _a.split("\n")[2]) == null ? void 0 : _b.trim()) != null ? _c : "";
946
959
  const matchResult = stack.match(/\((.*):(\d+):(\d+)\)/);
947
960
  let fileInfo = "";
948
961
  try {
@@ -950,7 +963,7 @@ function log(variableStr, variable, otherInfo = "") {
950
963
  const lineNumber = matchResult[2];
951
964
  fileInfo = `vscode://file${JSON.parse(otherInfo)}:${lineNumber}`;
952
965
  }
953
- } catch {
966
+ } catch (e) {
954
967
  fileInfo = otherInfo;
955
968
  }
956
969
  if (vue.isRef(variable)) {
@@ -1043,7 +1056,7 @@ function throttle(fn, delay2 = 1e3, options = {}, resultCallback) {
1043
1056
  lastThis = void 0;
1044
1057
  const nextResult = fn.apply(context, args);
1045
1058
  result = nextResult;
1046
- resultCallback?.(nextResult);
1059
+ resultCallback == null ? void 0 : resultCallback(nextResult);
1047
1060
  return result;
1048
1061
  };
1049
1062
  const flush = () => {
@@ -1142,9 +1155,10 @@ function debounce(func, delay2 = 500, immediate, resultCallback) {
1142
1155
  return _debounce;
1143
1156
  }
1144
1157
  function confirm(messageOrOptions, optionsOrAppContext = null, appContext = null) {
1158
+ var _a;
1145
1159
  const isOptionsCall = typeof messageOrOptions === "object" && messageOrOptions !== null && !vue.isVNode(messageOrOptions);
1146
- const options = isOptionsCall ? messageOrOptions : optionsOrAppContext ?? {};
1147
- const message = isOptionsCall ? options.message ?? "" : messageOrOptions;
1160
+ const options = isOptionsCall ? messageOrOptions : optionsOrAppContext != null ? optionsOrAppContext : {};
1161
+ const message = isOptionsCall ? (_a = options.message) != null ? _a : "" : messageOrOptions;
1148
1162
  const argumentAppContext = isOptionsCall ? optionsOrAppContext : appContext;
1149
1163
  const {
1150
1164
  message: _message,
@@ -1242,7 +1256,7 @@ function _resolveAppendTarget(appendTo) {
1242
1256
  try {
1243
1257
  const selector = rawSelector.startsWith("#") || rawSelector.startsWith(".") || rawSelector.startsWith("[") ? rawSelector : `#${rawSelector}`;
1244
1258
  return document.querySelector(selector) || appendTo;
1245
- } catch {
1259
+ } catch (e) {
1246
1260
  return appendTo;
1247
1261
  }
1248
1262
  }
@@ -1263,17 +1277,18 @@ function _resolveAppContext(appContext) {
1263
1277
  }
1264
1278
  const installWithContext = elementPlus.ElMessageBox.install;
1265
1279
  const messageBoxWithContext = elementPlus.ElMessageBox;
1266
- const elementPlusContext = installWithContext?.context || messageBoxWithContext._context || null;
1280
+ const elementPlusContext = (installWithContext == null ? void 0 : installWithContext.context) || messageBoxWithContext._context || null;
1267
1281
  if (typeof document === "undefined") {
1268
1282
  return elementPlusContext;
1269
1283
  }
1270
1284
  return elementPlusContext || _mountedAppContext();
1271
1285
  }
1272
1286
  function _mountedAppContext() {
1287
+ var _a, _b, _c;
1273
1288
  const roots = [document.querySelector("#app"), document.querySelector("[data-v-app]")];
1274
1289
  for (const root of roots) {
1275
1290
  const element = root;
1276
- const context = element?.__vue_app__?._context ?? element?._vue_app?._context;
1291
+ const context = (_c = (_a = element == null ? void 0 : element.__vue_app__) == null ? void 0 : _a._context) != null ? _c : (_b = element == null ? void 0 : element._vue_app) == null ? void 0 : _b._context;
1277
1292
  if (context) {
1278
1293
  return context;
1279
1294
  }
@@ -1290,7 +1305,7 @@ function getVariable(propertyName, fallback = "") {
1290
1305
  const DEFAULT_BUILD_TIME_FALLBACK = "\u672A\u6CE8\u5165";
1291
1306
  function getUtilsBuildTime(fallback = DEFAULT_BUILD_TIME_FALLBACK) {
1292
1307
  {
1293
- return "2026-11-23 13:45:27";
1308
+ return "2026-11-24 15:42:10";
1294
1309
  }
1295
1310
  }
1296
1311
  function test() {
@@ -67,11 +67,12 @@ const writeConfigFile = (relativePath, content, force) => {
67
67
  console.log(`\u8986\u76D6 ${relativePath}\uFF08\u539F\u6587\u4EF6\u5DF2\u5907\u4EFD\u4E3A ${backupPath}\uFF09`);
68
68
  };
69
69
  const configurePackageJson = (force) => {
70
+ var _a;
70
71
  const packageJsonPath = node_path.resolve(cwd, "package.json");
71
72
  if (!node_fs.existsSync(packageJsonPath)) throw new Error(`\u5F53\u524D\u76EE\u5F55\u4E0D\u5B58\u5728 package.json\uFF1A${cwd}`);
72
73
  const packageJsonContent = node_fs.readFileSync(packageJsonPath, "utf8");
73
74
  const packageJson = JSON.parse(packageJsonContent);
74
- packageJson.scripts ??= {};
75
+ (_a = packageJson.scripts) != null ? _a : packageJson.scripts = {};
75
76
  let shouldBackup = false;
76
77
  for (const [name, command2] of Object.entries(scripts)) {
77
78
  const current = packageJson.scripts[name];
@@ -93,7 +94,7 @@ const configurePackageJson = (force) => {
93
94
  const gitRoot = () => {
94
95
  try {
95
96
  return node_child_process.execFileSync("git", ["rev-parse", "--show-toplevel"], { cwd, encoding: "utf8" }).trim();
96
- } catch {
97
+ } catch (e) {
97
98
  throw new Error(`\u5F53\u524D\u76EE\u5F55\u4E0D\u5728 Git \u4ED3\u5E93\u4E2D\uFF0C\u65E0\u6CD5\u5B89\u88C5 Husky\uFF1A${cwd}`);
98
99
  }
99
100
  };
@@ -136,7 +137,7 @@ const configurePreCommit = () => {
136
137
  node_fs.unlinkSync(obsoleteHook);
137
138
  try {
138
139
  node_fs.rmdirSync(obsoleteDir);
139
- } catch {
140
+ } catch (e) {
140
141
  }
141
142
  }
142
143
  }
@@ -60,11 +60,12 @@ const writeConfigFile = (relativePath, content, force) => {
60
60
  console.log(`\u8986\u76D6 ${relativePath}\uFF08\u539F\u6587\u4EF6\u5DF2\u5907\u4EFD\u4E3A ${backupPath}\uFF09`);
61
61
  };
62
62
  const configurePackageJson = (force) => {
63
+ var _a;
63
64
  const packageJsonPath = resolve(cwd, "package.json");
64
65
  if (!existsSync(packageJsonPath)) throw new Error(`\u5F53\u524D\u76EE\u5F55\u4E0D\u5B58\u5728 package.json\uFF1A${cwd}`);
65
66
  const packageJsonContent = readFileSync(packageJsonPath, "utf8");
66
67
  const packageJson = JSON.parse(packageJsonContent);
67
- packageJson.scripts ??= {};
68
+ (_a = packageJson.scripts) != null ? _a : packageJson.scripts = {};
68
69
  let shouldBackup = false;
69
70
  for (const [name, command2] of Object.entries(scripts)) {
70
71
  const current = packageJson.scripts[name];
@@ -86,7 +87,7 @@ const configurePackageJson = (force) => {
86
87
  const gitRoot = () => {
87
88
  try {
88
89
  return execFileSync("git", ["rev-parse", "--show-toplevel"], { cwd, encoding: "utf8" }).trim();
89
- } catch {
90
+ } catch (e) {
90
91
  throw new Error(`\u5F53\u524D\u76EE\u5F55\u4E0D\u5728 Git \u4ED3\u5E93\u4E2D\uFF0C\u65E0\u6CD5\u5B89\u88C5 Husky\uFF1A${cwd}`);
91
92
  }
92
93
  };
@@ -129,7 +130,7 @@ const configurePreCommit = () => {
129
130
  unlinkSync(obsoleteHook);
130
131
  try {
131
132
  rmdirSync(obsoleteDir);
132
- } catch {
133
+ } catch (e) {
133
134
  }
134
135
  }
135
136
  }