rate-limit-readable
v1.0.0
Published
Human-friendly explanations for API rate limit headers.
Readme
Rate Limit Header Explainer
Human-friendly explanations for API rate-limit headers.
Install
npm install rate-limit-readableUsage
import { explainRateLimit } from "rate-limit-readable"
const explanation = explainRateLimit(
{
"X-RateLimit-Limit": "100",
"X-RateLimit-Remaining": "3",
"X-RateLimit-Reset": "1707379200"
},
{ audience: "user", style: "verbose" }
)
console.log(explanation.message)API
export interface RateLimitExplanation {
limit?: number
remaining?: number
resetsInSeconds?: number
resetsAt?: Date
isLimited: boolean
message: string
severity: "info" | "warning" | "error"
retryAfterSeconds?: number
}
explainRateLimit(headers: Headers | Record<string, string>, options?)Options:
now: epoch ms override for testsstyle:"short" | "verbose"audience:"user" | "developer"
Development
Build library:
npm run buildRun tests:
npm testDemo (Local)
- Build the library.
- Serve the repo root with a static server (so
demo/can importdist/).
npm run build
python -m http.serverOpen http://localhost:8000/demo/.
Demo Deployment (GitHub Pages)
This repo includes .github/workflows/deploy-demo.yml which publishes the demo to GitHub Pages on pushes to main.
Steps:
- Push to GitHub.
- In the repo settings, set Pages → Source to GitHub Actions.
- Push to
main(or manually run the workflow).
The demo will be served at https://milind-nair.github.io/rate-limit-readable/demo/.
