MCPcopy Create free account
hub / github.com/microsoft/typescript-go / PathIsRelative

Function PathIsRelative

internal/tspath/path.go:904–920  ·  view source on GitHub ↗
(path string)

Source from the content-addressed store, hash-verified

902}
903
904func PathIsRelative(path string) bool {
905 // True if path is ".", "..", or starts with "./", "../", ".\\", or "..\\".
906
907 if path == "." || path == ".." {
908 return true
909 }
910
911 if len(path) >= 2 && path[0] == '.' && (path[1] == '/' || path[1] == '\\') {
912 return true
913 }
914
915 if len(path) >= 3 && path[0] == '.' && path[1] == '.' && (path[2] == '/' || path[2] == '\\') {
916 return true
917 }
918
919 return false
920}
921
922// EnsurePathIsNonModuleName ensures a path is either absolute (prefixed with `/` or `c:`) or dot-relative (prefixed
923// with `./` or `../`) so as not to be confused with an unprefixed module name.

Callers 15

GetResolvedModuleMethod · 0.92
computeModuleSpecifiersFunction · 0.92
getLocalModuleSpecifierFunction · 0.92
PathIsBareSpecifierFunction · 0.92
usesExtensionsOnImportsFunction · 0.92
inferPreferenceFunction · 0.92
verifyCompilerOptionsMethod · 0.92
sortByBestNameMethod · 0.92
resolveExternalModuleMethod · 0.92

Calls 1

lenFunction · 0.85

Tested by 2

TestPathIsRelativeFunction · 0.68
BenchmarkPathIsRelativeFunction · 0.68