@crup/react-timer-hook 0.0.1 → 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
@@ -2,7 +2,7 @@
2
2
 
3
3
  > A lightweight React hooks library for building timers, stopwatches, and real-time clocks with minimal boilerplate.
4
4
 
5
- [![npm alpha](https://img.shields.io/npm/v/%40crup%2Freact-timer-hook/alpha?label=npm%20alpha&color=00b894)](https://www.npmjs.com/package/@crup/react-timer-hook?activeTab=versions)
5
+ [![npm](https://img.shields.io/npm/v/%40crup%2Freact-timer-hook?label=npm&color=00b894)](https://www.npmjs.com/package/@crup/react-timer-hook)
6
6
  [![npm downloads](https://img.shields.io/npm/dm/%40crup%2Freact-timer-hook?color=0f766e)](https://www.npmjs.com/package/@crup/react-timer-hook)
7
7
  [![CI](https://github.com/crup/react-timer-hook/actions/workflows/ci.yml/badge.svg)](https://github.com/crup/react-timer-hook/actions/workflows/ci.yml)
8
8
  [![Docs](https://github.com/crup/react-timer-hook/actions/workflows/docs.yml/badge.svg)](https://github.com/crup/react-timer-hook/actions/workflows/docs.yml)
@@ -29,11 +29,9 @@ Timers get messy when a product needs pause and resume, countdowns tied to serve
29
29
 
30
30
  ## Install
31
31
 
32
- The project is currently in alpha while the API receives feedback.
33
-
34
32
  ```sh
35
- npm install @crup/react-timer-hook@alpha
36
- pnpm add @crup/react-timer-hook@alpha
33
+ npm install @crup/react-timer-hook@latest
34
+ pnpm add @crup/react-timer-hook@latest
37
35
  ```
38
36
 
39
37
  Runtime requirements: Node 18+ and React 18+.
@@ -259,6 +257,7 @@ The default import stays small. Add the other pieces only when that screen needs
259
257
  | 📡 Schedules | `@crup/react-timer-hook/schedules` | Polling, cadence callbacks, overdue timing context | 8.62 kB | 3.02 kB | 2.78 kB |
260
258
  | 🧩 Duration | `@crup/react-timer-hook/duration` | `days`, `hours`, `minutes`, `seconds`, `milliseconds` | 318 B | 224 B | 192 B |
261
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 |
262
261
 
263
262
  CI writes a size summary to the GitHub Actions UI and posts bundle-size reports on pull requests.
264
263
 
@@ -271,17 +270,34 @@ Agents and docs-aware IDEs can use:
271
270
 
272
271
  Optional local MCP docs server:
273
272
 
273
+ Use `npx` if the package is not installed in the current project:
274
+
274
275
  ```json
275
276
  {
276
277
  "mcpServers": {
277
278
  "react-timer-hook-docs": {
278
- "command": "node",
279
- "args": ["/absolute/path/to/react-timer-hook/mcp/server.mjs"]
279
+ "command": "npx",
280
+ "args": ["-y", "@crup/react-timer-hook@latest"]
280
281
  }
281
282
  }
282
283
  }
283
284
  ```
284
285
 
286
+ If the package is installed locally, npm also creates a bin shim in `node_modules/.bin`:
287
+
288
+ ```json
289
+ {
290
+ "mcpServers": {
291
+ "react-timer-hook-docs": {
292
+ "command": "./node_modules/.bin/react-timer-hook-mcp",
293
+ "args": []
294
+ }
295
+ }
296
+ }
297
+ ```
298
+
299
+ The same bundled and minified server is available at `node_modules/@crup/react-timer-hook/dist/mcp/server.js`.
300
+
285
301
  It exposes:
286
302
 
287
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.1",
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",