MCPcopy Create free account
hub / github.com/fontsource/fontsource / getAvailableVersions

Function getAvailableVersions

api/metadata/src/stats/util.ts:32–63  ·  view source on GitHub ↗
(
	id: string,
	isVariable?: boolean,
)

Source from the content-addressed store, hash-verified

30};
31
32export const getAvailableVersions = async (
33 id: string,
34 isVariable?: boolean,
35): Promise<string[]> => {
36 const url = isVariable
37 ? `https://data.jsdelivr.com/v1/packages/npm/@fontsource-variable/${id}`
38 : `https://data.jsdelivr.com/v1/packages/npm/@fontsource/${id}`;
39
40 const resp = await fetch(url);
41
42 if (!resp.ok) {
43 if (resp.status === 404) {
44 throw new StatusError(404, `Not Found. ${id} does not exist.`);
45 }
46
47 // Log error with logpush
48 console.log(await resp.text());
49 throw new StatusError(
50 500,
51 'Internal Server Error. Unable to fetch versions.',
52 );
53 }
54
55 const list = (await resp.json()) as JSDelivrAPIVersion;
56 if (!list?.versions || list.versions.length === 0) {
57 throw new StatusError(404, `Not Found. No versions found for ${id}.`);
58 }
59
60 const versions = list.versions.map((version) => version.version);
61
62 return sortSemverList(versions);
63};

Callers 1

updateVersionFunction · 0.90

Calls 5

sortSemverListFunction · 0.85
logMethod · 0.80
jsonMethod · 0.80
textMethod · 0.65
fetchFunction · 0.50

Tested by

no test coverage detected