Created
September 28, 2018 15:31
-
-
Save mcavaliere/e417c982fd1cd55c2e8307b5fe6a68d5 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Final config.js | |
export default class { | |
init() { | |
this.config = // ... load the object ... | |
// For posterity, but we don't need to return it at the moment. | |
return this.config; | |
}, | |
settingExists( key ) { | |
let found = Object.keys( this.config ).indexOf( key ) | |
return found; | |
} | |
static printFormatInstructions() { | |
console.log('Your config file must be in json format, and contain the following keys: foo, bar, baz.'); | |
} | |
} | |
// Final usage | |
import Config from 'config.js'; | |
Config.init(); | |
// Later | |
if ( ! Config.settingExists( 'foo' ) ) { | |
Config.printFormatInstructions(); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment