MCPcopy Index your code
hub / github.com/microsoft/typescript-go / GetPathComponentsRelativeTo

Function GetPathComponentsRelativeTo

internal/tspath/path.go:729–771  ·  view source on GitHub ↗

Relative Paths

(from string, to string, options ComparePathsOptions)

Source from the content-addressed store, hash-verified

727//// Relative Paths
728
729func GetPathComponentsRelativeTo(from string, to string, options ComparePathsOptions) []string {
730 fromComponents := reducePathComponents(GetPathComponents(from, options.CurrentDirectory))
731 toComponents := reducePathComponents(GetPathComponents(to, options.CurrentDirectory))
732
733 start := 0
734 maxCommonComponents := min(len(fromComponents), len(toComponents))
735 stringEqualer := options.getEqualityComparer()
736 for ; start < maxCommonComponents; start++ {
737 fromComponent := fromComponents[start]
738 toComponent := toComponents[start]
739 if start == 0 {
740 if !stringutil.EquateStringCaseInsensitive(fromComponent, toComponent) {
741 break
742 }
743 } else {
744 if !stringEqualer(fromComponent, toComponent) {
745 break
746 }
747 }
748 }
749
750 if start == 0 {
751 return toComponents
752 }
753
754 numDotDotSlashes := len(fromComponents) - start
755 result := make([]string, 1+numDotDotSlashes+len(toComponents)-start)
756
757 result[0] = ""
758 i := 1
759 // Add all the relative components until we hit a common directory.
760 for range numDotDotSlashes {
761 result[i] = ".."
762 i++
763 }
764 // Now add all the remaining components of the "to" path.
765 for _, component := range toComponents[start:] {
766 result[i] = component
767 i++
768 }
769
770 return result
771}
772
773func GetRelativePathFromDirectory(fromDirectory string, to string, options ComparePathsOptions) string {
774 if (GetRootLength(fromDirectory) > 0) != (GetRootLength(to) > 0) {

Callers 6

verifySourceMapOutputMethod · 0.92
verifySourceMapRecordMethod · 0.92
verifyTypesAndSymbolsMethod · 0.92

Calls 7

reducePathComponentsFunction · 0.85
GetPathComponentsFunction · 0.85
minFunction · 0.85
lenFunction · 0.85
getEqualityComparerMethod · 0.80
makeFunction · 0.50

Tested by

no test coverage detected