Skip to content

Function: relative()

ts
function relative(from, to): string;

根据当前工作目录,计算从 from 到 to 的相对路径。

Parameters

ParameterTypeDescription
fromstring源路径
tostring目标路径

Returns

string

相对路径

Example

ts
relative('/data/orandea/test/aaa', '/data/orandea/impl/bbb')   // => '../../impl/bbb'
relative('/foo/bar/baz', '/foo/bar/baz')                       // => ''
relative('/foo/bar/baz', '/foo/bar/baz/')                      // => ''
relative('/foo/bar/baz', '/foo/bar/baz/file.txt')             // => 'file.txt'

Since

1.0.0

Released under the MIT License.