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

Easily calculate the relative path from file A to file B in Node.js project. Will calculate correctly from a file to a directory, file to file, directory to file, and directory to directory.

  • 0.1.2
  • Source
  • npm
  • Socket score

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

relative NPM version

Easily calculate the relative path from file A to file B in Node.js project.

Calculates correctly from:

  • File to directory
  • File to file
  • Directory to file
  • Directory to directory
npm i relative --save

Usage

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

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

relative.toBase

Get the relative path from the given base path.

relative.toBase(basepath, filepath)

Example:

relative.toBase('one/two', 'one/two/three/four.json')
//=> three/four.json

Author

Jon Schlinkert

License

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

Keywords

FAQs

Package last updated on 08 Feb 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