rpr

0.1.4 • Public • Published

RPR (Resolve Project Root)

Resolves '~/...' to a project root

This little utility modifies the built-in path.resolve(...) function so that you can resolve paths relative to a project root. Because require(...) uses path.resolve(...), this also modifies the behvaior of require(...).

Example

./utils.js

module.exports.square = (x) => {
  return x * x;
}

./index.js

require('rpr')(__dirname);

const custom = require('~/path/file.js');

custom();

./path/file.js

const { square } = require('~/utils.js');

module.exports = () => {
  console.log( square(2) );  
}

API

  • directory {String} a path to set as the project directory (Default: process.cwd())

/rpr/

    Package Sidebar

    Install

    npm i rpr

    Weekly Downloads

    0

    Version

    0.1.4

    License

    MIT

    Last publish

    Collaborators

    • trevorhreed