refactor(api): make param handling more terse

This commit is contained in:
Kent C. Dodds 2025-04-12 10:21:05 +02:00 committed by GitHub
parent 30ab52ae79
commit a83042c6bc
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194

View File

@ -46,20 +46,10 @@ export async function fetchLibraryDocumentation(
basePath = path; basePath = path;
folders = foldersParam; folders = foldersParam;
} }
let contextURL = `${CONTEXT7_BASE_URL}/${basePath}/llms.txt`; const contextURL = new URL(`${CONTEXT7_BASE_URL}/${basePath}/llms.txt`);
const params = []; if (folders) contextURL.set('folders', folders)
if (folders) { if (tokens) contextURL.set('tokens', tokens)
params.push(`folders=${encodeURIComponent(folders)}`); if (topic) contextURL.set('topic', topic)
}
if (tokens) {
params.push(`tokens=${tokens}`);
}
if (topic) {
params.push(`topic=${encodeURIComponent(topic)}`);
}
if (params.length > 0) {
contextURL += `?${params.join("&")}`;
}
const response = await fetch(contextURL); const response = await fetch(contextURL);
if (!response.ok) { if (!response.ok) {