get-relative-path
TypeScript icon, indicating that this package has built-in type declarations

1.0.2 • Public • Published

get-relative-path

Work out what the relative path to get from from to to is. i.e. Starting at from, what path would lead us to to.

Similar to Node.js's path.relative() but works outside the context of a filesystem, and assumes all paths are POSIX-style. So this also works for URL pathnames.

npm install get-relative-path
const getRelativePath = require('get-relative-path');
 
console.log(getRelativePath('/data/orandea/test/aaa/', '/data/orandea/impl/bbb'));
// ../../impl/bbb
 
console.log(getRelativePath('data/orandea/test/aaa/', 'data/orandea/impl/bbb'));
// ../../impl/bbb
 
console.log(getRelativePath(
  new URL('https://localhost/data/orandea/test/aaa/').pathname,
  new URL('https://localhost/data/orandea/impl/bbb').pathname
))
// ../../impl/bbb
 

/get-relative-path/

    Package Sidebar

    Install

    npm i get-relative-path

    Weekly Downloads

    10,781

    Version

    1.0.2

    License

    MIT

    Unpacked Size

    2.72 kB

    Total Files

    5

    Last publish

    Collaborators

    • s0