MCPcopy Index your code
hub / github.com/npmx-dev/npmx.dev / getTypesUrl

Function getTypesUrl

server/utils/docs/client.ts:163–177  ·  view source on GitHub ↗

* Get the TypeScript types URL from esm.sh's x-typescript-types header. * * esm.sh serves types URL in the `x-typescript-types` header, not at the main URL. * Example: curl -sI 'https://esm.sh/ufo@1.5.0' returns header: * x-typescript-types: https://esm.sh/ufo@1.5.0/dist/index.d.ts

(packageName: string, version: string)

Source from the content-addressed store, hash-verified

161 * x-typescript-types: https://esm.sh/ufo@1.5.0/dist/index.d.ts
162 */
163async function getTypesUrl(packageName: string, version: string): Promise<string | null> {
164 const url = `https://esm.sh/${packageName}@${version}`
165
166 try {
167 const response = await $fetch.raw(url, {
168 method: 'HEAD',
169 timeout: FETCH_TIMEOUT_MS,
170 })
171 return response.headers.get('x-typescript-types')
172 } catch (e) {
173 // eslint-disable-next-line no-console
174 console.error(e)
175 return null
176 }
177}

Callers 1

getDocNodesFunction · 0.85

Calls 1

getMethod · 0.65

Tested by

no test coverage detected