Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -89,3 +89,7 @@ By default, the object returned by configuer is frozen. Since it is also flat,
the object is completely immutable. The `mutable` option makes configeur return
an unfrozen object. This is not recommended in general, but may be useful for
testing purposes.

### `env`

If you prefer to pass an environment object in manually, use this field.
1 change: 1 addition & 0 deletions index.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ type Parser = [string, (string) => any];
interface Options {
parsers?: Parser[],
mutable?: Boolean
env?: Object
}

export default function configeur(environment: Environment, options?: Options): Object;
2 changes: 1 addition & 1 deletion index.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ const processConfig = require('./lib/processConfig');
const makeParsers = require('./lib/makeParsers');

module.exports = function configeur(schema, options = {}) {
return processConfig(schema, process.env, makeParsers(options.parsers), options.mutable);
return processConfig(schema, options.env || process.env, makeParsers(options.parsers), options.mutable);
};

module.exports.default = module.exports;
21 changes: 19 additions & 2 deletions test/index.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -48,8 +48,25 @@ describe('configeur', () => {
});

it('passes the schema, the environment, and the parsers to processConfig', () => {
configeur('fakeSchema', { parsers: 'fake-custom-parsers', mutable: 'is-mutable' });
configeur('fakeSchema', {
parsers: 'fake-custom-parsers',
mutable: 'is-mutable'
});

assert.deepEqual(processConfigStub.args, [
['fakeSchema', { AN_ARG: 'argValue' }, 'fakeParsers', 'is-mutable']
]);
});

it('uses the optional env field to override process.env', () => {
configeur('fakeSchema', {
parsers: 'fake-custom-parsers',
mutable: 'is-mutable',
env: { A_DIFFERENT_ARG: 'differentValue' }
});

assert.deepEqual(processConfigStub.args, [['fakeSchema', { AN_ARG: 'argValue' }, 'fakeParsers', 'is-mutable']]);
assert.deepEqual(processConfigStub.args, [
['fakeSchema', { A_DIFFERENT_ARG: 'differentValue' }, 'fakeParsers', 'is-mutable']
]);
});
});