Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

relative

Package Overview
Dependencies
Maintainers
1
Versions
15
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

relative

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.

  • 1.0.0
  • Source
  • npm
  • Socket score

Version published
Weekly downloads
320K
decreased by-7.51%
Maintainers
1
Weekly downloads
 
Created
Source

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

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('test/fixtures/foo.txt', 'docs/new/file.txt');
//=> '../../docs/new/file.txt'

toBase

Get the path relative to the given base path.

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

Example:

relative.toBase('test/fixtures', 'test/fixtures/docs/new/file.txt');
//=> 'docs/new/file.txt'

Author

Jon Schlinkert

License

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


This file was generated by verb on November 17, 2014.

Keywords

FAQs

Package last updated on 17 Nov 2014

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc