npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2025 – Pkg Stats / Ryan Hefner

erlc.ts

v1.0.7

Published

Clean and typesafe PRC API client for TypeScript

Readme

erlc.ts — PRC API Client CodeFactor

A minimal, type-safe TypeScript client for the Police Roleplay Community (PRC) API. No dependencies. No bullshit.


Installation

npm install erlc.ts

Quick Start

import { PRCClient } from 'erlc.ts';

const client = new PRCClient({ serverKey: 'your-server-key' });

const { data: status } = await client.getServerStatus();
console.log(status);

await client.executeCommand(':h Check out Melonly!');

Table of Contents


Features

  • 100% TypeScript support
  • Built-in caching (in-memory or Redis)
  • Automatic rate limit handling
  • Fully typed API responses
  • 100% API coverage
  • Extremely low memory footprint
  • Minimal, predictable API

Usage

Basic Example

import { PRCClient } from 'erlc.ts';

const client = new PRCClient({ serverKey: 'your-server-key' });

const { data: players } = await client.getPlayers();
players.forEach(p => console.log(p.Player, p.Team));

Error Handling

All API calls may throw a PRCAPIError. You can inspect the error type for more detail:

import { PRCClient, PRCAPIError } from 'erlc.ts';

try {
  const { data } = await client.getPlayers();
} catch (err) {
  if (err instanceof PRCAPIError) {
    if (err.isRateLimit) console.error('Rate limited!');
    else if (err.isAuthError) console.error('Bad server key!');
    else console.error('API error:', err.message);
  }
}

Cache Control

The client caches GET requests by default. Supports both in-memory and Redis caching.

  • Default: 30s
  • Disable: cache: false
  • Custom: cacheMaxAge (ms)
  • Per-method: cacheMaxAge in method options
  • Per-method cache control: cache: true/false in method options
  • Redis: redisUrl (e.g., redis://localhost:6379)
  • Clear manually: client.clearCache()
  • Inspect: client.getCacheSize()
// Global cache settings
const client = new PRCClient({
  serverKey: 'your-server-key',
  cacheMaxAge: 120_000, // 2 mins
});

// Per-method cache control
const { data: status } = await client.getServerStatus({ cacheMaxAge: 60_000 }); // 1 min
const { data: players } = await client.getPlayers({ cacheMaxAge: 30_000 }); // 30s

// Enable caching for logs (normally not cached)
const { data: logs } = await client.getJoinLogs({ 
  cache: true, 
  cacheMaxAge: 300_000 
}); // 5 minutes

// Disable caching for a specific call
const { data: freshPlayers } = await client.getPlayers({ cache: false });

Rate Limit Handling


Rate Limit Handling

Handled automatically:

  • Detects retry_after from the API
  • Retries up to 3 times
  • Throws PRCAPIError with isRateLimit = true if still exceeded
try {
  await client.getPlayers();
} catch (err) {
  if (err instanceof PRCAPIError && err.isRateLimit) {
    console.error('Slow down!');
  }
}

Advanced Usage & Type Safety

import { PRCHelpers, Player } from 'erlc.ts';

const helpers = new PRCHelpers(client);

const cops: Player[] = await helpers.getPlayersByTeam('Police');
for (const cop of cops) {
  await helpers.sendPM(cop.Player, 'get ur ass to hq rookie');
}

const stats = await helpers.getServerStats(12);
console.log(`Current players: ${stats.current.players}/${stats.current.maxPlayers}`);

Method Options

All GET methods accept an optional options parameter for per-method configuration:

// Custom cache age for this specific call
const { data: players } = await client.getPlayers({ cacheMaxAge: 60_000 }); // 1 minute

// Enable caching for logs (normally not cached)
const { data: logs } = await client.getJoinLogs({ 
  cache: true, 
  cacheMaxAge: 300_000 
}); // 5 minutes

// Disable caching for a specific call
const { data: freshPlayers } = await client.getPlayers({ cache: false });

API Reference

PRCClient Methods

| Method | Description | Returns | | ------------------------------- | ------------------------- | ------------------------------------ | | getServerStatus(options?) | Get current server status | Promise<APIResponse<ServerStatus>> | | getPlayers(options?) | Get all players | Promise<APIResponse<Player[]>> | | getQueue(options?) | Get server queue | Promise<APIResponse<number[]>> | | getVehicles(options?) | Get all vehicles | Promise<APIResponse<Vehicle[]>> | | getBans(options?) | Get all bans | Promise<APIResponse<ServerBans>> | | getStaff(options?) | Get staff info | Promise<APIResponse<ServerStaff>> | | getJoinLogs(options?) | Get join/leave logs | Promise<APIResponse<JoinLog[]>> | | getKillLogs(options?) | Get kill logs | Promise<APIResponse<KillLog[]>> | | getCommandLogs(options?) | Get command logs | Promise<APIResponse<CommandLog[]>> | | getModCalls(options?) | Get mod calls | Promise<APIResponse<ModCall[]>> | | executeCommand(cmd) | Run a server command | Promise<APIResponse<null>> | | clearCache() | Clear cache | void | | getCacheSize() | Cache size | number |


PRCHelpers Methods

| Method | Description | | -------------------------------------------------- | ------------------------- | | findPlayer(nameOrId)Player \| null | Find player by name or ID | | getPlayersByTeam(team)Player[] | Players on a team | | getStaff()Player[] | All staff players | | getOnlineCount()number | Current online count | | isServerFull()boolean | Is server full? | | sendMessage(msg)void | Send global message | | sendPM(player, msg)void | Send private message | | kickPlayer(player, reason?)void | Kick a player | | banPlayer(player, reason?)void | Ban a player | | teleportPlayer(player, target)void | Teleport player | | setTeam(player, team)void | Set team | | getRecentJoins(mins?)JoinLog[] | Recent joins | | getRecentLeaves(mins?)JoinLog[] | Recent leaves | | getPlayerKills(player, hrs?)KillLog[] | Player kills | | getPlayerDeaths(player, hrs?)KillLog[] | Player deaths | | getPlayerCommands(player, hrs?)CommandLog[] | Player commands | | getUnansweredModCalls(hrs?)ModCall[] | Unanswered mod calls | | waitForPlayer(nameOrId, timeout?)Player | Wait for player | | waitForPlayerCount(count, timeout?)void | Wait for count | | kickAllFromTeam(team, reason?)string[] | Kick all team players | | messageAllStaff(msg)void | Message all staff | | getServerStats(hrs?){ current, recent } | Server stats summary |


License

MIT