JSPM

  • ESM via JSPM
  • ES Module Entrypoint
  • Export Map
  • Keywords
  • License
  • Repository URL
  • TypeScript Types
  • README
  • Created
  • Published
  • Downloads 454640
  • Score
    100M100P100Q173753F
  • License

Get the relative filepath from path A to path B. Calculates from file-to-directory, file-to-file, directory-to-file, and directory-to-directory.

Package Exports

  • relative

This package does not declare an exports field, so the exports above have been automatically detected and optimized by JSPM instead. If any package subpath is missing, it is recommended to post an issue to the original package (relative) to support the "exports" field. If that is not possible, create a JSPM override to customize the exports field for this package.

Readme

relative NPM version

Get the relative filepath from path A to path B. Calculates from file-to-directory, file-to-file, directory-to-file, and directory-to-directory.

Calculates correctly from:

  • File to directory
  • File to file
  • Directory to file
  • Directory to directory

Install with npm

npm i relative --save

Usage

var relative = require('relative');
relative(from, to);

// Example
relative('test/fixtures/foo.txt', 'docs');
// => '../../docs'

API

relative

Return the relative path from a to b.

  • from {String}
  • to {String}
  • returns: {String}

Example:

var relative = require('relative');
relative('a/b/foo.txt', 'c/d/file.txt');
//=> '../../c/d/file.txt'

.toBase

Get the path relative to the given base path.

  • base {String}: The base directory
  • fp {String}: The full filepath
  • returns {String}: The relative path

Example:

relative.toBase('a/b', 'a/b/c/d/file.txt');
//=> 'c/d/file.txt'

Author

Jon Schlinkert

License

Copyright (c) 2014 Jon Schlinkert
Released under the MIT license


This file was generated by verb on December 25, 2014.