Package Exports
- erlc-api
- erlc-api/dist/browser/erlc.min.js
- erlc-api/dist/cjs/index.js
- erlc-api/dist/esm/index.js
This package does not declare an exports field, so the exports above have been automatically detected and optimized by JSPM instead. If any package subpath is missing, it is recommended to post an issue to the original package (erlc-api) to support the "exports" field. If that is not possible, create a JSPM override to customize the exports field for this package.
Readme
ERLC API
A modern TypeScript/JavaScript API wrapper for ER:LC (Emergency Response: Liberty County) with full browser support.
Features
- 🚀 Full TypeScript support
- 🌐 Browser compatible
- ⚡ Promise-based API
- 🛡️ Comprehensive error handling
- 📘 Type definitions included
- 🔄 CommonJS and ES Module support
Installation
npm install erlc-apiUsage
TypeScript/ES Modules
import { Client } from 'erlc-api';
const client = new Client({
globalToken: 'your-global-token',
});
// Get server information
const serverInfo = await client.getServer('server-token');
console.log(serverInfo);
// Get players
const players = await client.getPlayers('server-token');
console.log(players);
//Run Command
const Command = await client.runCommand('server-token', ':h Hello');
console.log(Command);CommonJS
const { Client } = require('erlc-api');
const client = new Client({
globalToken: 'your-global-token',
});
// Using async/await
async function getServerInfo() {
try {
const server = await client.getServer('server-token');
console.log(server);
} catch (error) {
console.error('Error:', error.message);
}
}Browser
<script src="node_modules/erlc-api/dist/browser/erlc.min.js"></script>
<script>
const client = new ERLC.Client({
globalToken: 'your-global-token',
});
client
.getServer('server-token')
.then((server) => console.log(server))
.catch((error) => console.error(error));
</script>API Methods
getServer(serverToken)- Get server informationgetPlayers(serverToken)- Get list of playersgetJoinLogs(serverToken)- Get join/leave logsgetKillLogs(serverToken)- Get kill logsgetCommandLogs(serverToken)- Get command logsgetModcallLogs(serverToken)- Get modcall logsgetBans(serverToken)- Get server bansgetVehicles(serverToken)- Get vehicle informationgetQueue(serverToken)- Get queue informationrunCommand(serverToken, command)- Run a server command
Error Handling
The library includes custom error classes for better error handling:
import { AuthenticationError, ValidationError, NetworkError } from 'erlc-api';
try {
await client.getServer('server-token');
} catch (error) {
if (error instanceof AuthenticationError) {
console.error('Authentication failed');
} else if (error instanceof ValidationError) {
console.error('Invalid input');
} else if (error instanceof NetworkError) {
console.error('Network error occurred');
}
}Development
# Install dependencies
npm install
# Run tests
npm test
# Build
npm run build
# Lint
npm run lint
# Format code
npm run formatLicense
MIT License - see LICENSE file for details.