# resolver-revolver

> Resolves and validates configurations.

Latest version **0.4.10** (published 2015-10-01) · MIT license · 0 weekly downloads

## Install

```sh
npm install resolver-revolver
pnpm add resolver-revolver
yarn add resolver-revolver
bun add resolver-revolver
```

## 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.4.10 |
| Published | 2015-10-01 |
| First published | 2015-09-21 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | none |
| Module format | CommonJS |
| Dependencies | 10 |
| Known vulnerabilities | 0 (+2 in 1 direct dependencies) |
| Install scripts | no |
| GitHub stars | 1 |
| Author | JP Wesselink |
| Maintainers | jpwesselink |

## Links

- npm: https://www.npmjs.com/package/resolver-revolver
- Repository: https://github.com/jslovesyou/resolver-revolver
- Issues: https://github.com/jslovesyou/resolver-revolver/issues
- npm.io page: https://npm.io/package/resolver-revolver

## Dependencies (10)

- [lodash.every](https://npm.io/package/lodash.every.md) ^3.2.3
- [lodash.first](https://npm.io/package/lodash.first.md) ^3.0.0
- [lodash.merge](https://npm.io/package/lodash.merge.md) ^3.3.2
- [lodash.negate](https://npm.io/package/lodash.negate.md) ^3.0.1
- [lodash.isarray](https://npm.io/package/lodash.isarray.md) ^3.0.4
- [lodash.isnumber](https://npm.io/package/lodash.isnumber.md) ^3.0.1
- [lodash.isobject](https://npm.io/package/lodash.isobject.md) ^3.0.2
- [lodash.isstring](https://npm.io/package/lodash.isstring.md) ^3.0.1
- [lodash.isfunction](https://npm.io/package/lodash.isfunction.md) ^3.0.6
- [lodash.isundefined](https://npm.io/package/lodash.isundefined.md) ^3.0.1

## Recent versions

- 0.4.10 (latest) — 2015-10-01
- 0.4.8 — 2015-09-25
- 0.4.7 — 2015-09-25
- 0.4.9 — 2015-09-25
- 0.4.6 — 2015-09-24
- 0.4.5 — 2015-09-24
- 0.4.4 — 2015-09-24
- 0.4.3 — 2015-09-22
- 0.4.2 — 2015-09-22
- 0.3.3 — 2015-09-22
- 0.4.0 — 2015-09-22
- 0.4.1 — 2015-09-22
- 0.3.1 — 2015-09-21
- 0.3.0 — 2015-09-21
- 0.2.1 — 2015-09-21
- … 3 more at https://npm.io/package/resolver-revolver/versions

## README

# resolver-revolver

[![Codeship Status for sytac/gulp-commonjs-tasks](https://codeship.com/projects/fbd845d0-42d7-0133-683e-1e375ee071eb/status?branch=master)](https://codeship.com/projects/103903)

![revolver](https://cloud.githubusercontent.com/assets/1814479/10023500/bad1db20-6152-11e5-8bfd-731c91466b8b.png)

## Description

Resolves values from and validates by trying to find values in given contexts in
a lazy way.

## Installation

```zsh
$ npm install --save resolver-revolver
```

Since that is pretty generic, here's an example which resolves `NODE_ENV` from
either the command line, then from the system environment, and if all else fails
it will set it to a default of `development`.

*If you'd like to try these examples, please run `gulp prepare-examples` first*

```js
// ./examples/easy/index.js

'use strict';

var resolverRevolver = require('resolver-revolver');
var argv = require('yargs').argv;
var isString = require('lodash.isstring');

var resolved = resolverRevolver.parse({
  context: {
    argv: argv,
    env: process.env
  },
  resolvables: {
    'environment': {
      from: ['argv.NODE_ENV', 'env.NODE_ENV'],
      default: 'development'
    }
  }
});

var defaults = {
  environment: resolved.environment()
};

console.log(JSON.stringify(defaults, null, 4));

```

**Default value**

Since `argv.NODE_ENV` and `env.NODE_ENV` can not be resolved round-robin style,
the `default` will be resolved.

```zsh
$ node examples/easy
{
    "environment": "development"
}
```

**Use a cli argument**

Since the first

```zsh
$ node examples/easy --NODE_ENV=production
{
    "environment": "production"
}
```

**Export a system variable**

```zsh
$ export NODE_ENV=coocoo
$ node examples/easy                           
{
    "environment": "coocoo"
}
```

**Provide a cli argument *and* export a system variable**

Since `argv.NODE_ENV` has a higher priority than `env.NODE_ENV`,
it will be resolved.

```zsh
$ export NODE_ENV=coocoo
$ node examples/easy --NODE_ENV=production                          
{
    "environment": "production"
}
```

Savvy? Here's a more elaborate example.

```js
// ./examples/elaborate/index.js

'use strict';

var resolverRevolver = require('resolver-revolver');
var argv = require('yargs').argv;
var negate = require('lodash.negate');
var isUndefined = require('lodash.isundefined');
var isDefined = negate(isUndefined);

var resolved = resolverRevolver.parse({
  // Add a console for logging
  // defaults to undefined
  console: console,

  // Our context
  // defaults to {}
  context: {
    argv: argv,
    env: process.env
  },

  // when set to true it returns the default without validating
  lenientDefaults: false,

  // Resolvables
  resolvables: {
    'environment': {
      // defaults to []
      from: ['argv.NODE_ENV', 'env.NODE_ENV'],
      // defaults to undefined
      default: 'development',

      // And preconditions. If you do not set this array, it will default to
      // [isDefined].
      //
      // A precondition can be a function or an object containing a function and
      // name like so:
      // {
      //  fn: isDefined,
      //  name: 'is defined'
      // }
      //
      // Let's add our own here
      // defaults to []
      preconditions: [{
        fn: isDefined,
        name: 'is defined'
      }, {
        fn: function (value) {
          return ['development', 'production', 'test'].indexOf(value) !== -1;
        },
        name: 'is an enviroment'
      }]
    }
  }
});

var defaults = {
  // call resolved.environment function
  environment: resolved.environment()
};

console.log(JSON.stringify(defaults, null, 4));

```

```zsh
$ unset NODE_ENV
$ node examples/elaborate --NODE_ENV asdasd
Resolving: environment
    ✖ (1 of 3) - argv.NODE_ENV: asdasd
      ✔ (1 of 2) is defined
      ✖ (2 of 2) is an enviroment
    ✖ (2 of 3) - env.NODE_ENV: undefined
      ✖ (1 of 2) is defined
      ✖ (2 of 2) is an enviroment
  ✊✔ (3 of 3) - default value: development
      ✔ (1 of 2) is defined
      ✔ (2 of 2) is an enviroment

Resolved environment from default value to development

{
    "environment": "development"
}

```

## Running tests

```zsh
$ gulp test
```

Test reports are written to `./reports`.

## Contributing

-   Do pull requests.
-   Make sure there's tests and meaningful coverage.
-   Respect `./eslintrc`.
-   Issues should go in issues.

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