home / skills / a5c-ai / babysitter / encoding-handler
This skill helps you manage text encoding across platforms, detecting BOMs, converting between encodings, and ensuring clean, interoperable text.
npx playbooks add skill a5c-ai/babysitter --skill encoding-handlerReview the files below or copy the command above to add this skill to your agents.
---
name: encoding-handler
description: Handle text encoding across platforms including UTF-8, Windows codepages, and BOM handling.
allowed-tools: Read, Write, Edit, Bash, Glob, Grep
---
# Encoding Handler
Handle text encoding across platforms.
## Capabilities
- Detect file encoding
- Convert between encodings
- Handle BOM markers
- Configure Windows codepage support
- Normalize text encoding
- Handle encoding errors
## Generated Patterns
```typescript
import { Buffer } from 'buffer';
import iconv from 'iconv-lite';
export function detectBOM(buffer: Buffer): string | null {
if (buffer[0] === 0xEF && buffer[1] === 0xBB && buffer[2] === 0xBF) return 'utf-8';
if (buffer[0] === 0xFF && buffer[1] === 0xFE) return 'utf-16le';
if (buffer[0] === 0xFE && buffer[1] === 0xFF) return 'utf-16be';
return null;
}
export function stripBOM(content: string): string {
return content.charCodeAt(0) === 0xFEFF ? content.slice(1) : content;
}
export function decodeBuffer(buffer: Buffer, encoding = 'utf-8'): string {
const bom = detectBOM(buffer);
if (bom) {
return stripBOM(iconv.decode(buffer, bom));
}
return iconv.decode(buffer, encoding);
}
export function encodeString(content: string, encoding = 'utf-8', addBOM = false): Buffer {
const encoded = iconv.encode(content, encoding);
if (addBOM && encoding.toLowerCase() === 'utf-8') {
return Buffer.concat([Buffer.from([0xEF, 0xBB, 0xBF]), encoded]);
}
return encoded;
}
```
## Target Processes
- cross-platform-cli-compatibility
- cli-output-formatting
- configuration-management-system
This skill handles text encoding across platforms, focusing on UTF-8, Windows code pages, and BOM handling. It provides deterministic detection, conversion, and normalization utilities to ensure consistent text I/O across CLIs, editors, and automation pipelines.
The implementation inspects raw buffers for BOM markers, decodes bytes with a chosen encoding (falling back to detected BOM when present), and optionally strips or injects BOMs. It uses a buffer-first approach and leverages iconv-style conversions to support legacy Windows code pages and avoid silent corruption. Encoding errors are surfaced so calling processes can decide whether to repair, replace, or fail.
How do you decide which encoding to use when no BOM is present?
The skill defaults to a configured encoding (commonly UTF-8) but first attempts detection heuristics or explicit overrides; callers can pass the desired encoding to force a conversion.
Will conversion lose data for characters outside the target code page?
Conversions to limited code pages can be lossy. The skill surfaces decoding/encoding errors so the caller can choose to replace, escape, or abort instead of silently losing characters.