MCPcopy Index your code
hub / github.com/getsentry/sentry-javascript / relative

Function relative

packages/core/src/utils/path.ts:120–146  ·  view source on GitHub ↗
(from: string, to: string)

Source from the content-addressed store, hash-verified

118// posix version
119/** JSDoc */
120export function relative(from: string, to: string): string {
121 /* eslint-disable no-param-reassign */
122 from = resolve(from).slice(1);
123 to = resolve(to).slice(1);
124 /* eslint-enable no-param-reassign */
125
126 const fromParts = trim(from.split('/'));
127 const toParts = trim(to.split('/'));
128
129 const length = Math.min(fromParts.length, toParts.length);
130 let samePartsLength = length;
131 for (let i = 0; i < length; i++) {
132 if (fromParts[i] !== toParts[i]) {
133 samePartsLength = i;
134 break;
135 }
136 }
137
138 let outputParts = [];
139 for (let i = samePartsLength; i < fromParts.length; i++) {
140 outputParts.push('..');
141 }
142
143 outputParts = outputParts.concat(toParts.slice(samePartsLength));
144
145 return outputParts.join('/');
146}
147
148// path.normalize(path)
149// posix version

Callers 2

generateIterateeFunction · 0.90
assertFixtureViteVersionFunction · 0.85

Calls 4

trimFunction · 0.85
sliceMethod · 0.80
pushMethod · 0.80
resolveFunction · 0.70

Tested by 1

assertFixtureViteVersionFunction · 0.68