(_source: URL | string)
| 66 | * @async |
| 67 | */ |
| 68 | export 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 |
no test coverage detected