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

Function jsDelivrResolver

website/app/utils/cdn.ts:3–20  ·  view source on GitHub ↗
(
	fontId: string,
	variable = false,
)

Source from the content-addressed store, hash-verified

1import type { UrlResolver } from '@fontsource-utils/core';
2
3export const jsDelivrResolver = (
4 fontId: string,
5 variable = false,
6): UrlResolver => {
7 const prefix = `${fontId}-`;
8 const packageId = `${fontId}${variable ? ':vf' : ''}@latest`;
9
10 const baseUrl = `https://cdn.jsdelivr.net/fontsource/fonts/${packageId}`;
11
12 return ({ source }) => {
13 // Strip the font id prefix from filename for our CDN endpoints.
14 const filename = source.filename.startsWith(prefix)
15 ? source.filename.slice(prefix.length)
16 : source.filename;
17
18 return `${baseUrl}/${filename}`;
19 };
20};

Callers 3

VariableFunction · 0.90
StaticFunction · 0.90
loaderFunction · 0.90

Calls

no outgoing calls

Tested by

no test coverage detected