Configuration
let HaveApiKey = stampit({
conf: {
apiKey: process.env.API_KEY
}
})
HaveApiKey.compose.configuration.apiKey === process.env.API_KEYHaveApiKey = HaveApiKey.statics({
setApiKey(key) {
return this.conf({ apiKey: key }) // create new stamp by composing parent stamp with some configuration
}
})
HaveApiKey = HaveApiKey.setApiKey('abcd1234')
HaveApiKey.compose.configuration.apiKey === 'abcd1234'const ApiKeyPrinter = HaveApiKey.init(function (opts, { stamp }) {
const configuration = stamp.compose.configuration
console.log(configuration.apiKey) // It is perfectly safe to log secret API keys. Right?
})
HaveApiKey() // this will execute the initializer, and will print "abcd1234" to the consoleDescriptor merging algorithm
Other ways to add configuration
Last updated