# base-env

> Base plugin, creates a normalized environment object from a function, filepath or instance of base.

Latest version **0.3.1** (published 2018-07-19) · MIT license · 0 weekly downloads

## Install

```sh
npm install base-env
pnpm add base-env
yarn add base-env
bun add base-env
```

## Health

**Score 15/100 (F)** — status: abandoned.

Positive: no vulnerabilities.

Warnings: low downloads; no types; no esm support; pre 1.0.

Negative: abandoned; low maintenance score.

## Facts

| | |
|---|---|
| Version | 0.3.1 |
| Published | 2018-07-19 |
| First published | 2016-03-13 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | none |
| Module format | CommonJS |
| Node | >=0.10.0 |
| Dependencies | 12 |
| Unpacked size | 28.7 KB |
| Known vulnerabilities | 0 |
| Install scripts | no |
| GitHub stars | 12 |
| Author | Jon Schlinkert |
| Maintainers | doowb, jonschlinkert |
| Keywords | base, env |

## Links

- npm: https://www.npmjs.com/package/base-env
- Repository: https://github.com/base/base-env
- Issues: https://github.com/base/base-env/issues
- npm.io page: https://npm.io/package/base-env

## Dependencies (12)

- [debug](https://npm.io/package/debug.md) ^2.2.0
- [kind-of](https://npm.io/package/kind-of.md) ^3.0.3
- [os-homedir](https://npm.io/package/os-homedir.md) ^1.0.1
- [is-absolute](https://npm.io/package/is-absolute.md) ^0.2.5
- [is-valid-app](https://npm.io/package/is-valid-app.md) ^0.1.0
- [resolve-file](https://npm.io/package/resolve-file.md) ^0.3.0
- [contains-path](https://npm.io/package/contains-path.md) ^0.1.0
- [base-namespace](https://npm.io/package/base-namespace.md) ^0.2.0
- [extend-shallow](https://npm.io/package/extend-shallow.md) ^2.0.1
- [fs-exists-sync](https://npm.io/package/fs-exists-sync.md) ^0.1.0
- [global-modules](https://npm.io/package/global-modules.md) ^0.2.2
- [is-valid-instance](https://npm.io/package/is-valid-instance.md) ^0.1.0

## Alternatives

- [replicas-cli](https://npm.io/package/replicas-cli.md) — 3.0K weekly downloads
- [env-contract](https://npm.io/package/env-contract.md) — 133 weekly downloads
- [@openveo/api](https://npm.io/package/@openveo/api.md) — 61 weekly downloads
- [@ryniaubenpm2/cumque-error-reiciendis](https://npm.io/package/@ryniaubenpm2/cumque-error-reiciendis.md) — 54 weekly downloads
- [ts-global-type-extra](https://npm.io/package/ts-global-type-extra.md) — 11 weekly downloads

## Recent versions

- 0.3.1 (latest) — 2018-07-19
- 0.2.1 — 2016-07-12
- 0.3.0 — 2016-06-07
- 0.2.0 — 2016-05-17
- 0.1.7 — 2016-05-05
- 0.1.6 — 2016-04-21
- 0.1.5 — 2016-04-21
- 0.1.3 — 2016-04-05
- 0.1.2 — 2016-04-05
- 0.1.1 — 2016-04-02
- 0.1.0 — 2016-03-13

## README

# base-env [![NPM version](https://img.shields.io/npm/v/base-env.svg?style=flat)](https://www.npmjs.com/package/base-env) [![NPM monthly downloads](https://img.shields.io/npm/dm/base-env.svg?style=flat)](https://npmjs.org/package/base-env) [![NPM total downloads](https://img.shields.io/npm/dt/base-env.svg?style=flat)](https://npmjs.org/package/base-env) [![Linux Build Status](https://img.shields.io/travis/base/base-env.svg?style=flat&label=Travis)](https://travis-ci.org/base/base-env)

> Base plugin, creates a normalized environment object from a function, filepath or instance of base.

## Install

Install with [npm](https://www.npmjs.com/):

```sh
$ npm install --save base-env
```

## Usage

```js
var Base = require('base');
var env = require('base-env');
var base = new Base();
base.use(env());
```

## API

### [createEnv](index.js#L42)

Create an `env` object with the given `name`, function, filepath or app instance, and options. See the [Env](#Env) API docs below.

**Params**

* `name` **{String}**
* `val` **{Object|Function|String}**
* `options` **{Object}**
* `returns` **{Object}**

**Example**

```js
var base = require('base');
var env = require('base-env');
var app = new Base();
app.use(env());

var env = app.createEnv('foo', function() {});
```

### [Env](lib/env.js#L33)

Create an instance of `Env` with the given `name`, `fn`, `app` instance, and options. The `Env` class is used by [base-generators][] to handle some of the heavy lifting for resolving generators.

**Params**

* `name` **{String}**
* `fn` **{Function|Object|String}**: Function to be lazily invoked, instance, or filepath that resolves to one of the other types when required.
* `app` **{Object}**: Base instance to use for invocation context.
* `options` **{Object}**

**Example**

```js
var env = new Env('foo', function(app) {
  // do stuff to app
});
```

### [.isMatch](lib/env.js#L67)

Returns true if the given `str` matches any of the following properties, in order:

* `env.key`
* `env.name`
* `env.alias`
* `env.dirname`
* `env.path`
* `env.basename`

**Params**

* `str` **{String}**: The string to match
* `returns` **{Boolean}**: Retuns true if a match is made.

**Example**

```js
var env = new Env('foo', fucntion(){});
console.log(env.isMatch('bar')) //=> false
console.log(env.isMatch('foo')) //=> true
```

### [.invoke](lib/env.js#L97)

Invoke `env.fn` with the given `context` and `options`.

**Params**

* `context` **{Object}**: The application instance to use for invoking `env.fn`
* `opptions` **{Object}**
* `returns` **{Object}**

**Example**

```js
var app = new Base();
env.fn(app, {doStuff: true});
```

### [.isDefault](lib/env.js#L165)

Getter that is set to `true` when the env being loaded is in the user's working directory.

* `returns` **{Boolean}**

**Example**

```js
var env = new Env('generator.js', generatorFn, {cwd: process.cwd()});
console.log(env.isDefault);
//=> true
```

### [.namespace](lib/env.js#L185)

Getter for resolving the `namespace` of an `env`. A namespace is created by joining the `namespace` from a parent instance (if exists) to `env.alias` (e.g. `parent.namespace + '.' + env.alias`).

```js
var env = new Env('foo', function() {});

* `returns` **{String}**  

## About
### Related projects
- [base-generators](https://www.npmjs.com/package/base-generators): Adds project-generator support to your `base` application. | [homepage](https://github.com/node-base/base-generators "Adds project-generator support to your `base` application.")
- [base-runner](https://www.npmjs.com/package/base-runner): Orchestrate multiple instances of base at once. | [homepage](https://github.com/node-base/base-runner "Orchestrate multiple instances of base at once.")
- [base](https://www.npmjs.com/package/base): Framework for rapidly creating high quality, server-side node.js applications, using plugins like building blocks | [homepage](https://github.com/node-base/base "Framework for rapidly creating high quality, server-side node.js applications, using plugins like building blocks")

### Contributing
Pull requests and stars are always welcome. For bugs and feature requests, [please create an issue](../../issues/new).

### Contributors
| **Commits** | **Contributor** |  
| --- | --- |  
| 37 | [jonschlinkert](https://github.com/jonschlinkert) |  
| 6  | [doowb](https://github.com/doowb) |  

### Release history

### Building docs
_(This project's readme.md is generated by [verb](https://github.com/verbose/verb-generate-readme), please don't edit the readme directly. Any changes to the readme must be made in the [.verb.md](.verb.md) readme template.)_

To generate the readme, run the following command:

```sh
$ npm install -g verbose/verb#dev verb-generate-readme && verb
```

### Running tests

Running and reviewing unit tests is a great way to get familiarized with a library and its API. You can install dependencies and run tests with the following command:

```sh
$ npm install && npm test

```
### Author

**Jon Schlinkert**

+ [github/jonschlinkert](https://github.com/jonschlinkert)
+ [twitter/jonschlinkert](https://twitter.com/jonschlinkert)

### License

Copyright © 2018, [Jon Schlinkert](https://github.com/jonschlinkert).
Released under the [MIT License](LICENSE).

***

_This file was generated by [verb-generate-readme](https://github.com/verbose/verb-generate-readme), v0.7.0, on July 19, 2018._

[verb]: https://github.com/verbose/verb

[base-generators]: https://github.com/node-base/base-generators
```

---
_Source: https://npm.io/package/base-env · Machine-readable twin of the npm.io package page. Health data is recomputed on every publish._
