eve
Version:
Filesystem-first framework for durable backend AI agents that run anywhere.
1 lines • 1.27 kB
JavaScript
const WINDOWS_DRIVE_ABSOLUTE_PATH_PATTERN=/^\/?[A-Za-z]:[\\/]/,WINDOWS_UNC_ABSOLUTE_PATH_PATTERN=/^\\\\[^\\]/,IMPORT_SPECIFIER_PATTERN=/(\b(?:from|import)\s*(?:\(\s*)?)(["'])([A-Za-z]:[\\/][^"'\n\r]*)\2/g;function isWindowsAbsolutePath(n){return WINDOWS_DRIVE_ABSOLUTE_PATH_PATTERN.test(n)||WINDOWS_UNC_ABSOLUTE_PATH_PATTERN.test(n)}function convertWindowsPathToFileUrl(e){let t=e.replaceAll(`\\`,`/`);return t.startsWith(`//`)?new URL(`file:${t}`).href:(/^\/[A-Za-z]:\//.test(t)&&(t=t.slice(1)),new URL(`file:///${t}`).href)}function splitPathSpecifierSuffix(e){let t=e.indexOf(`?`),n=e.indexOf(`#`),r=t===-1?n:n===-1?t:Math.min(t,n);return r===-1?{path:e,suffix:``}:{path:e.slice(0,r),suffix:e.slice(r)}}function normalizeEsmImportSpecifier(e){if(e.startsWith(`file://`))return e;let{path:t,suffix:n}=splitPathSpecifierSuffix(e);return isWindowsAbsolutePath(t)?`${convertWindowsPathToFileUrl(t)}${n}`:e.replaceAll(`\\`,`/`)}function stringifyEsmImportSpecifier(e){return JSON.stringify(normalizeEsmImportSpecifier(e))}function normalizeGeneratedEsmImportSpecifiers(e){return e.replace(IMPORT_SPECIFIER_PATTERN,(e,t,n,r)=>`${t}${n}${normalizeEsmImportSpecifier(r)}${n}`)}export{normalizeEsmImportSpecifier,normalizeGeneratedEsmImportSpecifiers,stringifyEsmImportSpecifier};