1.0.1 • Published 9 years ago

require-path-relative v1.0.1

Weekly downloads
9
License
MIT
Repository
github
Last release
9 years ago

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.