MCPcopy
hub / github.com/unjs/fontaine / readMetrics

Function readMetrics

packages/fontaine/src/metrics.ts:68–97  ·  view source on GitHub ↗
(_source: URL | string)

Source from the content-addressed store, hash-verified

66 * @async
67 */
68export async function readMetrics(_source: URL | string): Promise<FontFaceMetrics | null> {
69 const source = typeof _source !== 'string' && 'href' in _source ? _source.href : _source
70
71 if (source in metricCache)
72 return metricCache[source] ?? null
73
74 const { protocol } = parseURL(source)
75 if (!protocol)
76 return null
77
78 let metrics: Font
79 if (protocol === 'file:') {
80 metrics = await fromFile(fileURLToPath(source))
81 }
82 else {
83 if (urlRequestCache.has(source)) {
84 metrics = await urlRequestCache.get(source)!
85 }
86 else {
87 const requestPromise = fromUrl(source)
88 urlRequestCache.set(source, requestPromise)
89
90 metrics = await requestPromise
91 }
92 }
93
94 const filteredMetrics = filterRequiredMetrics(metrics)
95 metricCache[source] = filteredMetrics
96 return filteredMetrics
97}
98
99// inline `@capsizecss/metrics`
100// https://github.com/seek-oss/capsize/blob/66344699ff7759a661a78d0629375714c6f308b0/packages/metrics/src/index.ts

Callers 4

metrics.spec.tsFile · 0.90
index.spec.tsFile · 0.90
readMetricsFromIdFunction · 0.90
generateFontFallbacksFunction · 0.90

Calls 1

filterRequiredMetricsFunction · 0.85

Tested by

no test coverage detected