@thalorlabs/jokeapi
v1.1.1
Published
Provider adapter for v2.jokeapi.dev — returns TLJoke
Readme
@thalorlabs/jokeapi
Provider adapter for v2.jokeapi.dev. Returns normalised TLJoke from @thalorlabs/types. Supports both single and twopart jokes with category filtering and safe mode.
Installation
npm install @thalorlabs/jokeapiUsage
import { JokeApiClient, JOKE_API_CONFIG } from '@thalorlabs/jokeapi';
import { EJokeCategory, EJokeType } from '@thalorlabs/types';
const client = new JokeApiClient();
// Random joke
const joke = await client.getJoke();
// Filtered by category and type
const progJoke = await client.getJoke({
category: EJokeCategory.PROGRAMMING,
type: EJokeType.TWOPART,
safe: true,
});
// → TLJoke { id, type: 'TWOPART', setup: '...', delivery: '...', category: 'PROGRAMMING', safe: true, provider: 'jokeapi' }Configuration
| Option | Default | Description |
|--------|---------|-------------|
| baseURL | https://v2.jokeapi.dev | API base URL |
| timeout | 10000 | Request timeout (ms) |
Query Parameters
| Param | Type | Description |
|-------|------|-------------|
| category | EJokeCategory | Filter by category (PROGRAMMING, DARK, PUN, SPOOKY, CHRISTMAS, GENERAL) |
| type | EJokeType | Filter by type (SINGLE, TWOPART) |
| safe | boolean | Only return safe jokes |
Exported Config
JOKE_API_CONFIG = {
cacheTtlMs: 3600000, // 1h
isBillable: false,
}Scripts
npm run build # tsc → dist/
npm test # vitest
npm run lint # eslint
npm run format:check # prettier