MCPcopy Index your code
hub / github.com/tinyplex/tinybase / getMappedImportUrl

Function getMappedImportUrl

site/demo.ts:54–72  ·  view source on GitHub ↗
(
  specifier: string,
  importMap: {[specifier: string]: string},
  baseUrl: string,
)

Source from the content-addressed store, hash-verified

52 /^https?:\/\//.test(url) ? url : new URL(url, baseUrl).href;
53
54const getMappedImportUrl = (
55 specifier: string,
56 importMap: {[specifier: string]: string},
57 baseUrl: string,
58): string | undefined => {
59 const exact = importMap[specifier];
60 if (exact != null) {
61 return absolutizeImportUrl(exact, baseUrl);
62 }
63 const prefix = Object.keys(importMap)
64 .filter((key) => specifier.startsWith(key + '/'))
65 .sort((a, b) => b.length - a.length)[0];
66 return prefix == null
67 ? undefined
68 : absolutizeImportUrl(
69 importMap[prefix]! + specifier.slice(prefix.length),
70 baseUrl,
71 );
72};
73
74export const getPublishedImportUrl = (
75 specifier: string,

Callers 1

getBundleFunction · 0.85

Calls 1

absolutizeImportUrlFunction · 0.85

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…