Skip to content

relative

Returns the relative path from one path to another.

path-browserify’s own relative cannot be used directly: it resolves a relative argument against process.cwd(), which on Windows is F:\... rather than a POSIX absolute path, and its slicing then assumes a leading / - so relative('src', '../x') came back as '../..x'. Both arguments are resolved through resolve here instead, and rooted at / before the POSIX comparison.

Import:

import { relative } from '@mnaoumov/typescript-lib/path';

Signature:

function relative(from: string, to: string): string

Parameters:

Parameter Type Description
from string The starting path.
to string The destination path.

Returns: string — The relative path from from to to.