require-path-relative

1.0.1 • Public • Published

require-path-relative

stable

Like path.relative(from, to), but normalizes it to look good in a Node require() statement. Also allows for an optional file entry-point.

For example:

var relative = require('require-path-relative')
 
relative('/modules/utils', '/modules')
=> '../'
 
relative('/modules/utils', '/modules', './index.js')
=> '../test.js'
 
relative('/modules', '/modules/utils', 'test.js')
=> './utils/test.js'
 
relative('/modules', '/modules')
=> './'

Usage

NPM

filepath = relative(from, to, [entry])

Resolves the from and to directories, and optionally appends the entry file to the end of the path.

This is handy for generating pretty-looking Node source.

License

MIT, see LICENSE.md for details.

Package Sidebar

Install

npm i require-path-relative

Weekly Downloads

24

Version

1.0.1

License

MIT

Last publish

Collaborators

  • mattdesl