base-env
Base plugin, creates a normalized environment object from a function, filepath or instance of base.
Install
Install with npm:
$ npm install base-env --save
Usage
var Base = require('base');
var env = require('base-env');
Prototype plugin
Register as a prototype plugin if you want the .createEnv
method to be added to all instances of base
:
Base.use(env());
Instance plugin
Register as an instance plugin if you only want the .createEnv
method to be added to a specific instance:
var base = new Base();
base.use(env());
API
Create an env
object with the given name
, function, filepath
or app instance, and options.
Params
name
{String}val
{Object|Function|String}options
{Object}returns
{Object}
Returns true if the given str
matches env.key
, env.name
or env.alias
. When env is created from a filepath, the following properties are also checked:
env.dirname
env.path
env.basename
Params
str
{String}: The string to matchreturns
{Boolean}: Retuns true if a match is made.
Example
var env = app.createEnv('foo', function() {});
env.isMatch('bar');
When env
is created from an existing application instance, the instance is cached on env.app
and env.invoke
is a noop function that simply returns env.app
.
returns
{Object}: Returns the invoked instance.
Example
var foo = new Base();
var bar = new Base();
var env = foo.createEnv('bar', function() {});
env.invoke(bar);
Contributing
Pull requests and stars are always welcome. For bugs and feature requests, please create an issue.
Building docs
Generate readme and API documentation with verb:
$ npm install verb && npm run docs
Or, if verb is installed globally:
$ verb
Running tests
Install dev dependencies:
$ npm install -d && npm test
Author
Jon Schlinkert
License
Copyright © 2016 Jon Schlinkert
Released under the MIT license.
This file was generated by verb, v0.9.0, on March 13, 2016.