- Extract extractListId to src/lib/extract-list-id.ts with proper tests - Add json-full/includeRaw test for list timeline - Add 404 retry tests for getOwnedLists and getListMemberships - Add tests for skipping invalid list entries and missing owner handling - Use shared TwitterClientPrivate type from fixtures 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude Opus 4.5 <[email protected]>
21 lines
523 B
TypeScript
21 lines
523 B
TypeScript
// ABOUTME: Extract list ID from an X/Twitter list URL.
|
|
// ABOUTME: Returns list ID or null if input is invalid.
|
|
|
|
const LIST_URL_REGEX = /(?:twitter\.com|x\.com)\/i\/lists\/(\d+)/i;
|
|
const LIST_ID_REGEX = /^\d{5,}$/;
|
|
|
|
export function extractListId(input: string): string | null {
|
|
const trimmed = input.trim();
|
|
if (!trimmed) {
|
|
return null;
|
|
}
|
|
const urlMatch = LIST_URL_REGEX.exec(trimmed);
|
|
if (urlMatch) {
|
|
return urlMatch[1];
|
|
}
|
|
if (LIST_ID_REGEX.test(trimmed)) {
|
|
return trimmed;
|
|
}
|
|
return null;
|
|
}
|