import type { Loader } from 'esbuild' ; export const isAbsolute = ( path ) => { return path . length > 0 && path . charAt ( 0 ) === '/' ; } ; export const extname = ( path ) => { const m = /(\.[a-zA-Z0-9]+)$/ . exec ( path ) ; return m ? m [ 1 ] : "" ; } ; export const RESOLVE_EXTENSIONS = [ ".tsx" , ".ts" , ".jsx" , ".js" , ".css" , ".json" ] ; export const inferLoader = ( url ) : Loader => { const ext = extname ( url ) ; if ( RESOLVE_EXTENSIONS . includes ( ext ) ) return ext . slice ( 1 ) as Loader ; if ( ext === ".mjs" || ext === ".cjs" ) return "js" ; if ( ext === ".mts" || ext === ".cts" ) return "ts" ; if ( ext == ".scss" ) return "css" ; if ( ext == ".png" || ext == ".jpeg" || ext == ".ttf" ) return "dataurl" ; if ( ext == ".svg" || ext == ".html" || ext == ".txt" ) return "text" ; if ( ext == ".wasm" ) return "file" ; return ext . length ? "text" : "ts" ; } ; export const isBareImport = ( url ) => { return /^(?!\.).*/ . test ( url ) && ! isAbsolute ( url ) ; } ; export const HOST = 'https://cdn.skypack.dev/' ; export const getCDNHost = ( url ) => { let argPath = url . replace ( /^(skypack|esm|esm\.sh|unpkg|jsdelivr|esm\.run)\:/ , "" ) ; let host = HOST ; if ( /^skypack\:/ . test ( url ) ) { host = `https://cdn.skypack.dev/` ; } else if ( /^(esm\.sh|esm)\:/ . test ( url ) ) { host = `https://cdn.esm.sh/` ; } else if ( /^unpkg\:/ . test ( url ) ) { host = `https://unpkg.com/` ; } else if ( /^(jsdelivr|esm\.run)\:/ . test ( url ) ) { host = `https://cdn.jsdelivr.net/npm/` ; } else if ( /^typescript/ . test ( url ) ) { host = `https://unpkg.com/` ; } return { argPath , host } ; } ;