MCPcopy
hub / github.com/QwikDev/qwik / relative

Function relative

packages/qwik/src/optimizer/src/path.ts:223–320  ·  view source on GitHub ↗
(from: string, to: string)

Source from the content-addressed store, hash-verified

221 };
222
223 const relative = function relative(from: string, to: string) {
224 assertPath(from);
225 assertPath(to);
226
227 if (from === to) {
228 return '';
229 }
230
231 from = resolve(from);
232 to = resolve(to);
233
234 if (from === to) {
235 return '';
236 }
237
238 // Trim any leading backslashes
239 let fromStart = 1;
240 for (; fromStart < from.length; ++fromStart) {
241 if (from.charCodeAt(fromStart) !== 47 /*/*/) {
242 break;
243 }
244 }
245 const fromEnd = from.length;
246 const fromLen = fromEnd - fromStart;
247
248 // Trim any leading backslashes
249 let toStart = 1;
250 for (; toStart < to.length; ++toStart) {
251 if (to.charCodeAt(toStart) !== 47 /*/*/) {
252 break;
253 }
254 }
255 const toEnd = to.length;
256 const toLen = toEnd - toStart;
257
258 // Compare paths to find the longest common path from root
259 const length = fromLen < toLen ? fromLen : toLen;
260 let lastCommonSep = -1;
261 let i = 0;
262 for (; i <= length; ++i) {
263 if (i === length) {
264 if (toLen > length) {
265 if (to.charCodeAt(toStart + i) === 47 /*/*/) {
266 // We get here if `from` is the exact base path for `to`.
267 // For example: from='/foo/bar'; to='/foo/bar/baz'
268 return to.slice(toStart + i + 1);
269 } else if (i === 0) {
270 // We get here if `from` is the root
271 // For example: from='/'; to='/foo'
272 return to.slice(toStart + i);
273 }
274 } else if (fromLen > length) {
275 if (from.charCodeAt(fromStart + i) === 47 /*/*/) {
276 // We get here if `to` is the exact base path for `from`.
277 // For example: from='/foo/bar/baz'; to='/foo/bar'
278 lastCommonSep = i;
279 } else if (i === 0) {
280 // We get here if `to` is the root.

Callers 10

visitNotIgnoredFilesFunction · 0.90
logUpdateAppResultFunction · 0.85
getPathnameFromDirPathFunction · 0.85
getMenuPathnameFunction · 0.85
renderFunction · 0.85
generateFunction · 0.85
runCreateInteractiveCliFunction · 0.85
logAppCreatedFunction · 0.85
handleAppFunction · 0.85

Calls 2

assertPathFunction · 0.85
resolveFunction · 0.70

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…