Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/mac-/configurine-picker
Logic for picking config values based on a given app name, app version, and environment name
https://github.com/mac-/configurine-picker
Last synced: 23 days ago
JSON representation
Logic for picking config values based on a given app name, app version, and environment name
- Host: GitHub
- URL: https://github.com/mac-/configurine-picker
- Owner: mac-
- License: mit
- Created: 2014-01-21T18:06:56.000Z (almost 11 years ago)
- Default Branch: master
- Last Pushed: 2014-03-10T19:53:24.000Z (almost 11 years ago)
- Last Synced: 2024-11-07T15:56:23.501Z (about 2 months ago)
- Language: JavaScript
- Size: 164 KB
- Stars: 0
- Watchers: 2
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
configurine-picker
==================Logic for picking config values based on a given app name, app version, and environment name from Configurine
[![Build Status](https://secure.travis-ci.org/mac-/configurine-picker.png)](http://travis-ci.org/mac-/configurine-picker)
[![Coverage Status](https://coveralls.io/repos/mac-/configurine-picker/badge.png)](https://coveralls.io/r/mac-/configurine-picker)
[![NPM version](https://badge.fury.io/js/configurine-picker.png)](http://badge.fury.io/js/configurine-picker)
[![Dependency Status](https://david-dm.org/mac-/configurine-picker.png)](https://david-dm.org/mac-/configurine-picker)[![NPM](https://nodei.co/npm/configurine-picker.png?downloads=true&stars=true)](https://nodei.co/npm/configurine-picker/)
## Installation
You may depend on the module by putting an entry in the dependencies section of your package.json file with the appropriate version:
"configurine-picker": "0.x.x"
You may also use npm to install the module and have it saved to your package.json using:
npm install configurine-picker --save
## Usage
This module takes a set of config entries and filters them down to one of each name by picking the one whose associations best match the given application and environment using the following priority:
* has both the matching app and env association
* has one of a matching app or env association (app or env may have a higher priority based on app settings (associationPriority))
* has no matching app or env associationsThe function exported by this module takes one `options` paramter and returns an object that contains the names provided and the corresponding values that were picked. The expected properties on the `options` object are:
* `appName` - the name of the application to match on (required)
* `appVersion` - the version of the application to match on (required)
* `environmentName` - the name of the environment to match on (required)
* `names` - an array of strings that represent the names of the config entries pick for
* `associationPriority` - tells the picker which association to give priority to: 'app' or 'env'. Defaults to 'app'
* `entries` - the collection of config entries from configurine to pick from (required)Example:
```javascript
var picker = require('configurine-picker');// example set of config entries from configurine for demo purposes
var entries = [
{
name: 'foo',
value: 'bar',
associations: {
applications: [{
name: 'my-app',
versions: ['1.0.0']
}],
environments: []
},
isActive: true,
isSensitive: false,
owner: 'me'
},
{
name: 'foo',
value: 'baz',
associations: {
applications: [],
environments: ['production']
},
isActive: true,
isSensitive: false,
owner: 'me'
}
];var config = picker({
names: ['foo'],
appName: 'my-app',
appVersion: '1.0.0',
environmentName: 'production',
associationPriority: 'app',
entries: entries
});console.log(config.foo); // 'bar'
config = picker({
names: ['foo', 'other'],
appName: 'my-app',
appVersion: '1.0.0',
environmentName: 'production',
associationPriority: 'env',
entries: entries
});console.log(config.foo); // 'baz'
console.log(config.other); // undefined
```[![Bitdeli Badge](https://d2weczhvl823v0.cloudfront.net/mac-/configurine-picker/trend.png)](https://bitdeli.com/free "Bitdeli Badge")