koishi-plugin-echo-cave 1.24.1 → 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 +16 -22
  2. package/package.json +1 -1
package/lib/index.cjs CHANGED
@@ -908,36 +908,30 @@ var PREDEFINED_PERIODS = [
908
908
  "all"
909
909
  ];
910
910
  var TIME_UNITS = {
911
- m: 60 * 1e3,
912
- // minutes
913
- h: 60 * 60 * 1e3,
914
- // hours
915
- d: 24 * 60 * 60 * 1e3,
916
- // days
911
+ m: 30 * 24 * 60 * 60 * 1e3,
917
912
  w: 7 * 24 * 60 * 60 * 1e3,
918
- // weeks
919
- M: 30 * 24 * 60 * 60 * 1e3
920
- // months (approximate)
913
+ d: 24 * 60 * 60 * 1e3,
914
+ h: 60 * 60 * 1e3
921
915
  };
922
916
  function parseCustomTime(timeStr) {
923
- const regex = /(\d+)([mhdwM])/g;
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;
920
+ const regex = /(\d+)([mwdh])/g;
924
921
  let match;
925
922
  let totalMs = 0;
926
- let lastUnit = "";
927
- const unitOrder = ["M", "w", "d", "h", "m"];
928
- if (!/^(\d+[mhdwM])+$/.test(timeStr)) {
929
- return null;
930
- }
931
- while ((match = regex.exec(timeStr)) !== null) {
932
- const [, value, unit] = match;
933
- const num = parseInt(value, 10);
923
+ const unitOrder = ["m", "w", "d", "h"];
924
+ let lastIndex = -1;
925
+ while ((match = regex.exec(s)) !== null) {
926
+ const value = parseInt(match[1], 10);
927
+ const unit = match[2].toLowerCase();
934
928
  const currentIndex = unitOrder.indexOf(unit);
935
- const lastIndex = unitOrder.indexOf(lastUnit);
936
- if (lastUnit && currentIndex > lastIndex) {
929
+ if (currentIndex === -1) return null;
930
+ if (lastIndex !== -1 && currentIndex < lastIndex) {
937
931
  return null;
938
932
  }
939
- totalMs += num * TIME_UNITS[unit];
940
- lastUnit = unit;
933
+ totalMs += value * (TIME_UNITS[unit] ?? 0);
934
+ lastIndex = currentIndex;
941
935
  }
942
936
  return totalMs;
943
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.1",
4
+ "version": "1.24.3",
5
5
  "main": "lib/index.cjs",
6
6
  "typings": "lib/index.d.ts",
7
7
  "type": "module",