tickr-js
v0.1.2
Published
JavaScript client for Tickr.cc
Readme
Tickr.cc JavaScript Client
A JavaScript/TypeScript client library for interacting with the Tickr.cc API (counters service).
Features
- Fetch all your counters (requires authentication)
- Create a new counter (requires authentication)
- Fetch a public counter by slug
- Increment a counter (public or private, depending on API config)
- Update a counter (requires authentication and ownership)
- Delete a counter (requires authentication and ownership)
- Supports API key authentication (recommended; JWT is deprecated)
- Supports
is_privateandis_readonlycounter properties - Fully typed with TypeScript definitions
Installation
npm install tickr-js
# or
yarn add tickr-jsUsage
import { TickrClient } from 'tickr-js';
// Create a client instance (API key is recommended for authenticated endpoints)
// You can get your API key from the Tickr API docs page: https://tickr.cc/api-docs
// Note: Pass the base URL first (default: https://tickr.cc), then the API Key.
const client = new TickrClient("YOUR_API_KEY");
// For public-only access, you can instantiate without arguments:
// const publicClient = new TickrClient();
async function main() {
// Fetch all counters (authenticated)
const counters = await client.getCounters();
console.log(counters);
// Create a new counter (authenticated, with privacy/read-only options)
const newCounter = await client.createCounter({
name: "My Counter",
initial_value: 10,
is_private: true,
is_readonly: false
});
console.log("Created:", newCounter);
// Fetch a public counter by slug
const publicCounter = await client.getCounter("abc123xyz");
console.log("Fetched:", publicCounter);
// Increment a counter (public or private)
const updatedCounter = await client.incrementCounter("abc123xyz", 2);
console.log("Incremented:", updatedCounter);
// Update a counter (authenticated, owner only)
const updated = await client.updateCounter("abc123xyz", {
name: "Renamed",
current_value: 42,
is_private: false
});
console.log("Updated:", updated);
// Delete a counter (authenticated, owner only)
await client.deleteCounter("abc123xyz");
console.log("Deleted");
}
main();Authentication
For authenticated endpoints, obtain an API key from your Tickr.cc dashboard and pass it to the client constructor. Public endpoints do not require authentication.
Note: JWT authentication is deprecated. Use API keys for all new integrations.
Counter Properties
is_private: Iftrue, only authorized users can increment the counter.is_readonly: Iftrue, the counter cannot be incremented by anyone on the website, but can be incremented via the API.
These properties are always included in returned counter objects.
License
MIT
