Skip to content
This repository has been archived by the owner on Feb 10, 2019. It is now read-only.

export as a function (by default) rather than a string #1

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open

export as a function (by default) rather than a string #1

wants to merge 1 commit into from

Conversation

chocolateboy
Copy link

This is a very handy module, but I always end up wrapping it in a function (for convenience/correctness), which gets tedious:

var path  = require('path');
var $root = require('rootrequire');

function root ($path) {
    return path.join($root, $path);
}

var libPath = root('/path/to/lib');

Exporting it as a string value doesn't allow the function to be attached (in ES5). Exporting it as a String object doesn't play well with console.log. Exporting it as a function allows easy access to both e.g.:

var root  = require('rootrequire'); // function
var $root = require('rootrequire').path; // path

The only downside I can see is that this is a breaking change.

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant