@crup/react-timer-hook 0.0.2 → 0.0.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.
package/README.md CHANGED
@@ -257,6 +257,7 @@ The default import stays small. Add the other pieces only when that screen needs
257
257
  | 📡 Schedules | `@crup/react-timer-hook/schedules` | Polling, cadence callbacks, overdue timing context | 8.62 kB | 3.02 kB | 2.78 kB |
258
258
  | 🧩 Duration | `@crup/react-timer-hook/duration` | `days`, `hours`, `minutes`, `seconds`, `milliseconds` | 318 B | 224 B | 192 B |
259
259
  | 🔎 Diagnostics | `@crup/react-timer-hook/diagnostics` | Optional lifecycle and schedule event logging | 105 B | 115 B | 90 B |
260
+ | 🤖 MCP docs server | `react-timer-hook-mcp` | Optional local docs context for MCP clients and coding agents | 3.80 kB | 1.63 kB | 1.40 kB |
260
261
 
261
262
  CI writes a size summary to the GitHub Actions UI and posts bundle-size reports on pull requests.
262
263
 
@@ -269,17 +270,34 @@ Agents and docs-aware IDEs can use:
269
270
 
270
271
  Optional local MCP docs server:
271
272
 
273
+ Use `npx` if the package is not installed in the current project:
274
+
275
+ ```json
276
+ {
277
+ "mcpServers": {
278
+ "react-timer-hook-docs": {
279
+ "command": "npx",
280
+ "args": ["-y", "@crup/react-timer-hook@latest"]
281
+ }
282
+ }
283
+ }
284
+ ```
285
+
286
+ If the package is installed locally, npm also creates a bin shim in `node_modules/.bin`:
287
+
272
288
  ```json
273
289
  {
274
290
  "mcpServers": {
275
291
  "react-timer-hook-docs": {
276
- "command": "node",
277
- "args": ["/absolute/path/to/react-timer-hook/mcp/server.mjs"]
292
+ "command": "./node_modules/.bin/react-timer-hook-mcp",
293
+ "args": []
278
294
  }
279
295
  }
280
296
  }
281
297
  ```
282
298
 
299
+ The same bundled and minified server is available at `node_modules/@crup/react-timer-hook/dist/mcp/server.js`.
300
+
283
301
  It exposes:
284
302
 
285
303
  ```txt
@@ -0,0 +1,44 @@
1
+ #!/usr/bin/env node
2
+ import{createInterface as m}from"readline";import{readFileSync as p}from"fs";var n=f(),d=`# @crup/react-timer-hook
3
+
4
+ A lightweight React hooks library for building timers, stopwatches, and real-time clocks with minimal boilerplate.
5
+
6
+ Docs: https://crup.github.io/react-timer-hook/
7
+ Package: @crup/react-timer-hook
8
+ Install: npm install @crup/react-timer-hook@latest
9
+ Runtime: Node 18+ and React 18+
10
+ Repository: https://github.com/crup/react-timer-hook
11
+
12
+ Public exports:
13
+ - @crup/react-timer-hook: useTimer(options) for one timer lifecycle.
14
+ - @crup/react-timer-hook/group: useTimerGroup(options) for many keyed independent lifecycles with one shared scheduler.
15
+ - @crup/react-timer-hook/schedules: useScheduledTimer(options) for schedule-enabled timers with timing context.
16
+ - @crup/react-timer-hook/duration: durationParts(milliseconds) for duration display helper values.
17
+ - @crup/react-timer-hook/diagnostics: consoleTimerDiagnostics(options) for optional event logging.
18
+
19
+ Core rules:
20
+ - Use timer.now for wall-clock deadlines and clocks.
21
+ - Use timer.elapsedMilliseconds for active elapsed duration.
22
+ - Use endWhen(snapshot) to end a lifecycle.
23
+ - Use onError(error, snapshot, controls) when onEnd can throw or reject.
24
+ - Use cancel(reason) for terminal early stops.
25
+ - Keep formatting, timezone, retries, and business rules in userland.
26
+
27
+ Schedules:
28
+ - Use useScheduledTimer() from @crup/react-timer-hook/schedules.
29
+ - Schedules are opt-in and default to overlap: "skip".
30
+ - Schedule callbacks receive context with scheduledAt, firedAt, nextRunAt, overdueCount, and effectiveEveryMs.
31
+ - Schedule callbacks can define onError(error, snapshot, controls, context); otherwise timer or item onError is used.
32
+
33
+ Recipes:
34
+ - Wall clock: new Date(timer.now).
35
+ - Stopwatch: render timer.elapsedMilliseconds.
36
+ - Absolute countdown: Math.max(0, expiresAt - timer.now).
37
+ - Pausable countdown: durationMs - timer.elapsedMilliseconds.
38
+ - OTP resend: disable the resend button until elapsedMilliseconds reaches the cooldown.
39
+ - Polling: use schedules with overlap: "skip".
40
+ - Many independent timers: use useTimerGroup().
41
+ `,l={"react-timer-hook://package":{name:"Package",mimeType:"application/json",text:JSON.stringify({name:n.name,version:n.version,docs:"https://crup.github.io/react-timer-hook/",install:`npm install ${n.name}@latest`},null,2)},"react-timer-hook://api":{name:"API",mimeType:"text/markdown",text:d},"react-timer-hook://recipes":{name:"Recipes",mimeType:"text/markdown",text:["# Recipes","","- Countdown: derive remaining time with Math.max(0, expiresAt - timer.now).","- Stopwatch: render timer.elapsedMilliseconds.","- Clock: render new Date(timer.now) with user-owned formatting.","- Polling: import useScheduledTimer from @crup/react-timer-hook/schedules.","- Many timers: import useTimerGroup from @crup/react-timer-hook/group."].join(`
42
+ `)}},h=m({input:process.stdin,output:process.stdout,terminal:!1});h.on("line",e=>{if(!e.trim())return;let t;try{t=JSON.parse(e)}catch{return}let{id:r,method:i,params:s}=t;if(i==="initialize"){c(r,{protocolVersion:"2024-11-05",serverInfo:{name:"react-timer-hook-docs",version:n.version},capabilities:{resources:{}}});return}if(i==="resources/list"){c(r,{resources:Object.entries(l).map(([o,a])=>({uri:o,name:a.name,mimeType:a.mimeType}))});return}if(i==="resources/read"){let o=l[s?.uri];if(!o){u(r,-32004,`Unknown resource: ${s?.uri??"missing uri"}`);return}c(r,{contents:[{uri:s.uri,mimeType:o.mimeType,text:o.text}]});return}u(r,-32601,`Method not found: ${i}`)});function c(e,t){process.stdout.write(`${JSON.stringify({jsonrpc:"2.0",id:e,result:t})}
43
+ `)}function u(e,t,r){process.stdout.write(`${JSON.stringify({jsonrpc:"2.0",id:e,error:{code:t,message:r}})}
44
+ `)}function f(){for(let e of["../../package.json","../package.json"])try{return JSON.parse(p(new URL(e,import.meta.url),"utf8"))}catch{}return{name:"@crup/react-timer-hook",version:"0.0.0"}}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@crup/react-timer-hook",
3
- "version": "0.0.2",
3
+ "version": "0.0.3",
4
4
  "description": "A lightweight React hooks library for building timers, stopwatches, and real-time clocks with minimal boilerplate.",
5
5
  "homepage": "https://crup.github.io/react-timer-hook/",
6
6
  "repository": {
@@ -13,6 +13,9 @@
13
13
  "main": "./dist/index.cjs",
14
14
  "module": "./dist/index.js",
15
15
  "types": "./dist/index.d.ts",
16
+ "bin": {
17
+ "react-timer-hook-mcp": "./dist/mcp/server.js"
18
+ },
16
19
  "exports": {
17
20
  ".": {
18
21
  "types": "./dist/index.d.ts",
@@ -38,6 +41,9 @@
38
41
  "types": "./dist/diagnostics.d.ts",
39
42
  "import": "./dist/diagnostics.js",
40
43
  "require": "./dist/diagnostics.cjs"
44
+ },
45
+ "./mcp/server": {
46
+ "import": "./dist/mcp/server.js"
41
47
  }
42
48
  },
43
49
  "files": [
@@ -112,6 +118,7 @@
112
118
  "docs:dev": "NO_UPDATE_NOTIFIER=1 docusaurus start docs-site",
113
119
  "docs:preview": "NO_UPDATE_NOTIFIER=1 docusaurus serve docs-site/build",
114
120
  "mcp:docs": "node mcp/server.mjs",
121
+ "mcp:check": "node scripts/check-mcp-server.mjs",
115
122
  "readme:check": "node scripts/check-readme.mjs",
116
123
  "release": "changeset publish",
117
124
  "size": "node scripts/size-report.mjs",