feat(utils): add generic buildQueryString utility

- Add type-safe buildQueryString function to /utils
- Support primitives, arrays, and optional values
- Proper URL encoding for special characters
- Add comprehensive tests (25 test cases, all passing)
- Update Google Fonts API client to use shared utility
- Update Fontshare API client to use shared utility
- Export utility from /utils/index.ts

Benefits:
- DRY - Single source of truth for query string logic
- Type-safe - Proper TypeScript support with QueryParams type
- Tested - Comprehensive test coverage
- Maintainable - One place to fix bugs
This commit is contained in:
Ilia Mashkov
2026-01-06 15:00:31 +03:00
parent 29d1cc0cdc
commit 9abec4210c
9 changed files with 303 additions and 84 deletions

View File

@@ -7,33 +7,33 @@
export {
fetchGoogleFontFamily,
fetchGoogleFonts,
} from './googleFonts';
} from './google/googleFonts';
export type {
GoogleFontItem,
GoogleFontsParams,
GoogleFontsResponse,
} from './googleFonts';
} from './google/googleFonts';
export {
fetchAllFontshareFonts,
fetchFontshareFontBySlug,
fetchFontshareFonts,
} from './fontshare';
} from './fontshare/fontshare';
export type {
FontshareParams,
FontshareResponse,
} from './fontshare';
} from './fontshare/fontshare';
export {
normalizeFontshareFont,
normalizeFontshareFonts,
normalizeGoogleFont,
normalizeGoogleFonts,
} from './normalize';
} from './normalize/normalize';
export type {
FontFeatures,
FontMetadata,
FontStyleUrls,
UnifiedFont,
UnifiedFontVariant,
} from './normalize';
} from './normalize/normalize';