relative-filepath-from-module

0.0.1 • Public • Published

#relative-filepath-from-module

Returns a filepath relative to the module you are in.

Usage

// file: /home/username/git/personal/relative-filepath-from-module/test/yet-another-dir/
import modulePathFromFile from 'relative-filepath-from-module'
const modulePath = modulePathFromFile(__dirname)

console.log(modulePath) // relative-filepath-from-module/test/yet-another-dir/
// file: /home/username/git/personal/relative-filepath-from-module/test/yet-another-dir/testFile.js

import modulePathFromFile from 'relative-filepath-from-module'
const modulePath = modulePathFromFile(__dirname)

console.log(modulePath) // relative-filepath-from-module/test/yet-another-dir/testFile.js
// file: /home/username/git/personal/relative-filepath-from-module/test/yet-another-dir

import modulePathFromFile from 'relative-filepath-from-module'
const modulePath = modulePathFromFile(__dirname)

console.log(modulePath) // relative-filepath-from-module/test/yet-another-dir

Should also work on windows, but have not tested. feedback is welcomed.

Package Sidebar

Install

npm i relative-filepath-from-module

Weekly Downloads

1

Version

0.0.1

License

ISC

Last publish

Collaborators

  • sindresvendby