koishi-plugin-echo-cave 1.24.2 → 1.24.3

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/lib/index.cjs +11 -16
  2. package/package.json +1 -1
package/lib/index.cjs CHANGED
@@ -909,34 +909,29 @@ var PREDEFINED_PERIODS = [
909
909
  ];
910
910
  var TIME_UNITS = {
911
911
  m: 30 * 24 * 60 * 60 * 1e3,
912
- // 月(按约 30 天算)
913
912
  w: 7 * 24 * 60 * 60 * 1e3,
914
- // 周
915
913
  d: 24 * 60 * 60 * 1e3,
916
- // 天
917
914
  h: 60 * 60 * 1e3
918
- // 小时
919
915
  };
920
916
  function parseCustomTime(timeStr) {
917
+ if (!timeStr || typeof timeStr !== "string") return null;
918
+ const s = timeStr.toLowerCase();
919
+ if (!/^(\d+(m|w|d|h))+$/i.test(s)) return null;
921
920
  const regex = /(\d+)([mwdh])/g;
922
921
  let match;
923
922
  let totalMs = 0;
924
- let lastUnit = "";
925
923
  const unitOrder = ["m", "w", "d", "h"];
926
- if (!/^(\d+[mwdh])+$/i.test(timeStr)) {
927
- return null;
928
- }
929
- while ((match = regex.exec(timeStr)) !== null) {
930
- const [, value, unit] = match;
931
- const num = parseInt(value, 10);
924
+ let lastIndex = -1;
925
+ while ((match = regex.exec(s)) !== null) {
926
+ const value = parseInt(match[1], 10);
927
+ const unit = match[2].toLowerCase();
932
928
  const currentIndex = unitOrder.indexOf(unit);
933
- const lastIndex = unitOrder.indexOf(lastUnit);
934
- if (lastUnit && currentIndex < 0) return null;
935
- if (lastUnit && currentIndex > lastIndex) {
929
+ if (currentIndex === -1) return null;
930
+ if (lastIndex !== -1 && currentIndex < lastIndex) {
936
931
  return null;
937
932
  }
938
- totalMs += num * TIME_UNITS[unit];
939
- lastUnit = unit;
933
+ totalMs += value * (TIME_UNITS[unit] ?? 0);
934
+ lastIndex = currentIndex;
940
935
  }
941
936
  return totalMs;
942
937
  }
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "koishi-plugin-echo-cave",
3
3
  "description": "Group echo cave",
4
- "version": "1.24.2",
4
+ "version": "1.24.3",
5
5
  "main": "lib/index.cjs",
6
6
  "typings": "lib/index.d.ts",
7
7
  "type": "module",