MCPcopy Index your code
hub / github.com/angular/angular-cli / relative

Function relative

packages/angular_devkit/core/src/virtual-fs/path.ts:129–161  ·  view source on GitHub ↗
(from: Path, to: Path)

Source from the content-addressed store, hash-verified

127 * Both paths must be absolute, otherwise it does not make much sense.
128 */
129export function relative(from: Path, to: Path): Path {
130 if (!isAbsolute(from)) {
131 throw new PathMustBeAbsoluteException(from);
132 }
133 if (!isAbsolute(to)) {
134 throw new PathMustBeAbsoluteException(to);
135 }
136
137 let p: string;
138
139 if (from == to) {
140 p = '';
141 } else {
142 const splitFrom = split(from);
143 const splitTo = split(to);
144
145 while (splitFrom.length > 0 && splitTo.length > 0 && splitFrom[0] == splitTo[0]) {
146 splitFrom.shift();
147 splitTo.shift();
148 }
149
150 if (splitFrom.length == 0) {
151 p = splitTo.join(NormalizedSep);
152 } else {
153 p = splitFrom
154 .map(() => '..')
155 .concat(splitTo)
156 .join(NormalizedSep);
157 }
158 }
159
160 return normalize(p);
161}
162
163/**
164 * Returns a Path that is the resolution of p2, from p1. If p2 is absolute, it will return p2,

Callers 15

buildRelativePathFunction · 0.90
initializeMethod · 0.90
pathMethod · 0.90
pathMethod · 0.90
visitMethod · 0.90
actionsMethod · 0.90
path_spec.tsFile · 0.90
allow-js_spec.tsFile · 0.90
fullDescribeFunction · 0.50
isWithinAllowedRootFunction · 0.50

Calls 3

isAbsoluteFunction · 0.85
splitFunction · 0.85
normalizeFunction · 0.85

Tested by

no test coverage detected