From 73fed1eb45b4226d96f5b33755d427b8056256cb Mon Sep 17 00:00:00 2001 From: Mat Carey Date: Fri, 3 Apr 2015 14:21:56 +0100 Subject: [PATCH] Preparing for release 1.0.2 --- README.md | 23 +++++++++++++++++++++++ bower.json | 2 +- package.json | 2 +- spec/usageExamplesSpec.js | 31 +++++++++++++++++++++++++++++++ 4 files changed, 56 insertions(+), 2 deletions(-) diff --git a/README.md b/README.md index 9cde3ea..80eacbf 100644 --- a/README.md +++ b/README.md @@ -34,8 +34,31 @@ expect(myConfig.get('collection.nothing.this.would.usually.cause.problems')).toB To use this with Node.JS or IO.JS you can do things like: +(using environment variables MY_OWN_PASSWORD=secret ONE_OPTIONAL_VALUE=abc) + ```javascript +var myConfig = new JsConfig({ + someKey: 'someValue', + optionalValueTwo: 'defghi', + collection: { + item: 'a', + thePassword: 'default password' + } +}); + +expect(myConfig.get('collection.thePassword')).toEqual('default password'); + +myConfig.readFromObject(process.env, { + collection: { + thePassword: 'MY_OWN_PASSWORD' + }, + optionalValueOne: 'ONE_OPTIONAL_VALUE', + optionalValueTwo: 'ANOTHER_OPTIONAL_VALUE' +}); +expect(myConfig.get('collection.thePassword')).toEqual('secret'); +expect(myConfig.get('optionalValueOne')).toEqual('abc'); +expect(myConfig.get('optionalValueTwo')).toEqual('defghi'); ``` This will give you an object which includes the environment variable values for MUST_BE_PRESENT, AN_ENV_VAR and NO_DEFAULT but blows up if one of them doesn't exist. diff --git a/bower.json b/bower.json index b598a7b..f21e631 100644 --- a/bower.json +++ b/bower.json @@ -1,6 +1,6 @@ { "name": "js-config", - "version": "1.0.1", + "version": "1.0.2", "homepage": "https://github.com/dorightdigital/js-config", "authors": [ "Mat Carey " diff --git a/package.json b/package.json index 750add6..b4f3800 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "js-config", - "version": "1.0.1", + "version": "1.0.2", "description": "A helper for config management in JS - for any browser, node.js and io.js", "main": "src/JsConfig.js", "directories": { diff --git a/spec/usageExamplesSpec.js b/spec/usageExamplesSpec.js index 3f2f565..562bd7c 100755 --- a/spec/usageExamplesSpec.js +++ b/spec/usageExamplesSpec.js @@ -34,6 +34,37 @@ describe('Usage Examples', function () { expect(myConfig.get('collection.nothing')).toBe(undefined); expect(myConfig.get('collection.nothing.this.would.usually.cause.problems')).toBe(undefined); }); + + it('should give a node/io example', function () { + var process = { + env: { + MY_OWN_PASSWORD: 'secret', + ONE_OPTIONAL_VALUE: 'abc' + } + }, + myConfig = new JsConfig({ + someKey: 'someValue', + optionalValueTwo: 'defghi', + collection: { + item: 'a', + thePassword: 'default password' + } + }); + + expect(myConfig.get('collection.thePassword')).toEqual('default password'); + + myConfig.readFromObject(process.env, { + collection: { + thePassword: 'MY_OWN_PASSWORD' + }, + optionalValueOne: 'ONE_OPTIONAL_VALUE', + optionalValueTwo: 'ANOTHER_OPTIONAL_VALUE' + }); + + expect(myConfig.get('collection.thePassword')).toEqual('secret'); + expect(myConfig.get('optionalValueOne')).toEqual('abc'); + expect(myConfig.get('optionalValueTwo')).toEqual('defghi'); + }); }); describe('Basic Usage', function () {