UNPKG

@lifaon/path

Version:

Useful tool to manage paths like the URL object

24 lines 969 B
import { pushSegmentIntoMutablePathSegments, } from '../mutate/push-segment-into-mutable-path-segments.js'; import { getCommonBaseOfManyPathSegments } from './get-common-base-of-many-path-segments.js'; /** * Returns the relative `IPathSegments` between `from` and `to`: * - if no common base path => `[]` * - else `['..' | '.', ...]` */ export function getRelativePathSegments(from, to, options) { const commonBase = getCommonBaseOfManyPathSegments([from, to]); if (commonBase === null) { return null; } else { const relativePath = ['.']; for (let i = commonBase.length; i < from.length; i++) { pushSegmentIntoMutablePathSegments(relativePath, '..', options); } for (let i = commonBase.length; i < to.length; i++) { pushSegmentIntoMutablePathSegments(relativePath, to[i], options); } return relativePath; } } //# sourceMappingURL=get-relative-path-segments.js.map