@xiaoxionga/buzz 2.0.1 → 2.1.0

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 (3) hide show
  1. package/README.md +18 -13
  2. package/bin/buzz.js +38 -14
  3. package/package.json +1 -1
package/README.md CHANGED
@@ -14,14 +14,28 @@ npm install -g @xiaoxionga/buzz
14
14
 
15
15
  ```bash
16
16
  buzz # Keep awake indefinitely (Ctrl+C to stop)
17
- buzz 20 # Keep awake for 20 minutes
18
- buzz 2 # Keep awake for 2 hours
19
- buzz 1.5 # Keep awake for 1.5 hours (90 min)
17
+ buzz 20 # 20 minutes (default unit)
18
+ buzz 2h # 2 hours
19
+ buzz 30s # 30 seconds
20
+ buzz 1.5h # 90 minutes
20
21
  buzz stop # Stop any running buzz
21
22
  buzz status # Check if buzz is running
22
23
  buzz help # Show help
23
24
  ```
24
25
 
26
+ ## Duration Format
27
+
28
+ Default unit is **minutes**. Add a suffix to override:
29
+
30
+ | Input | Meaning |
31
+ |-------|---------|
32
+ | `buzz 30` | 30 **minutes** |
33
+ | `buzz 5min` | 5 **minutes** |
34
+ | `buzz 2h` | 2 **hours** |
35
+ | `buzz 1.5h` | 1.5 hours = 90 minutes |
36
+ | `buzz 30s` | 30 **seconds** |
37
+ | `buzz` | ∞ (until Ctrl+C) |
38
+
25
39
  ## How It Works
26
40
 
27
41
  | Platform | Method | Install needed? | Admin needed? |
@@ -34,15 +48,6 @@ buzz help # Show help
34
48
  - **Windows**: Presses F15 every 30 seconds via PowerShell. No app binds to F15, so it's completely harmless.
35
49
  - **Linux**: Moves mouse 1px via `xdotool`.
36
50
 
37
- ## Duration Format
38
-
39
- | Input | Meaning |
40
- |-------|---------|
41
- | `buzz 30` | 30 **minutes** (numbers ≥ 10 = minutes) |
42
- | `buzz 5` | 5 **hours** (numbers < 10 = hours) |
43
- | `buzz 0.5` | 0.5 hours = 30 minutes |
44
- | `buzz 1.5` | 1.5 hours = 90 minutes |
45
-
46
51
  ## Why buzz?
47
52
 
48
53
  - **Zero dependencies** — `package.json` has no `dependencies` field. Nothing to break.
@@ -54,7 +59,7 @@ buzz help # Show help
54
59
 
55
60
  ```bash
56
61
  # Weekend crunch time
57
- buzz 3 # 3 hours of uninterrupted focus
62
+ buzz 3h # 3 hours of uninterrupted focus
58
63
 
59
64
  # Quick meeting
60
65
  buzz 30 # 30 minutes
package/bin/buzz.js CHANGED
@@ -27,8 +27,10 @@ Keep your screen awake by simulating input.
27
27
 
28
28
  USAGE:
29
29
  buzz Keep awake indefinitely (Ctrl+C to stop)
30
- buzz 20 Keep awake for 20 minutes
31
- buzz 1.5 Keep awake for 1.5 hours (90 min)
30
+ buzz 20 Keep awake for 20 minutes (default unit)
31
+ buzz 2h Keep awake for 2 hours
32
+ buzz 30s Keep awake for 30 seconds
33
+ buzz 1.5h Keep awake for 1.5 hours (90 min)
32
34
  buzz stop Stop any running buzz
33
35
  buzz status Check if buzz is running
34
36
  buzz help Show this help
@@ -39,13 +41,14 @@ PLATFORMS:
39
41
  Linux Uses xdotool (if available)
40
42
 
41
43
  EXAMPLES:
42
- buzz 30 # Stay awake for 30 min
43
- buzz 2 # Stay awake for 2 hours
44
- buzz # Stay awake until you Ctrl+C
44
+ buzz 30 # 30 minutes
45
+ buzz 2h # 2 hours
46
+ buzz 90 # 90 minutes
47
+ buzz # until Ctrl+C
45
48
 
46
49
  TIPS:
47
- - Numbers >= 10 are treated as minutes
48
- - Numbers < 10 are treated as hours
50
+ - Default unit is minutes: buzz 5 = 5 minutes
51
+ - Suffixes: s (seconds), min (minutes), h (hours)
49
52
  - No npm dependencies required!
50
53
  `;
51
54
 
@@ -80,12 +83,34 @@ function formatDuration(ms) {
80
83
  }
81
84
 
82
85
  function parseDuration(arg) {
83
- const num = parseFloat(arg);
86
+ // Formats: "20" = 20min, "2h" = 2h, "30s" = 30s, "5min" = 5min, "1.5h" = 90min
87
+ const match = arg.match(/^(\d+(?:\.\d+)?)\s*(h|hour|hours|m|min|mins|minute|minutes|s|sec|secs|second|seconds)?$/i);
88
+ if (!match) return null;
89
+
90
+ const num = parseFloat(match[1]);
84
91
  if (isNaN(num) || num <= 0) return null;
85
- // >= 10 → minutes, < 10 → hours
86
- return num >= 10
87
- ? num * 60 * 1000
88
- : num * 60 * 60 * 1000;
92
+
93
+ const unit = (match[2] || 'min').toLowerCase();
94
+
95
+ if (unit.startsWith('h')) return num * 60 * 60 * 1000; // hours
96
+ if (unit.startsWith('s')) return num * 1000; // seconds
97
+ return num * 60 * 1000; // minutes (default)
98
+ }
99
+
100
+ function humanDuration(ms) {
101
+ if (ms < 60000) {
102
+ const s = Math.round(ms / 1000);
103
+ return `${s} second${s > 1 ? 's' : ''}`;
104
+ }
105
+ if (ms < 3600000) {
106
+ const m = Math.round(ms / 60000);
107
+ return `${m} minute${m > 1 ? 's' : ''}`;
108
+ }
109
+ const h = ms / 3600000;
110
+ if (h === Math.floor(h)) return `${h} hour${h > 1 ? 's' : ''}`;
111
+ // e.g. 90 min → show as "90 minutes" not "1.5 hours"
112
+ const m = Math.round(ms / 60000);
113
+ return `${m} minute${m > 1 ? 's' : ''}`;
89
114
  }
90
115
 
91
116
  // ─── Platform-specific jiggler ───
@@ -213,8 +238,7 @@ function cmdRun(durationMs) {
213
238
  : 'Linux xdotool';
214
239
 
215
240
  if (durationMs) {
216
- const mins = Math.round(durationMs / 60000);
217
- console.log(`🐝 buzz started! Keeping awake for ${mins} minutes.`);
241
+ console.log(`🐝 buzz started! Keeping awake for ${humanDuration(durationMs)}.`);
218
242
  } else {
219
243
  console.log(`🐝 buzz started! Keeping awake indefinitely.`);
220
244
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@xiaoxionga/buzz",
3
- "version": "2.0.1",
3
+ "version": "2.1.0",
4
4
  "description": "🐝 Keep your screen awake — zero dependencies, no admin required",
5
5
  "main": "bin/buzz.js",
6
6
  "bin": {