Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

confabulous

Package Overview
Dependencies
Maintainers
1
Versions
27
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

confabulous - npm Package Compare versions

Comparing version 1.1.3 to 1.2.0

lib/processors/envToCamelCaseProp.js

4

CHANGELOG.md
# Change Log
## [1.2.0]
### Added
- envToCamelCaseProps processor
## [1.1.3]

@@ -4,0 +8,0 @@ ### Changed

var debug = require('debug')('confabulous:transformers:envToProp')
var unflatten = require('flat').unflatten
var merge = require('../merge')
module.exports = function() {
module.exports = function(_options) {
var options = merge({ prefix: '', filter: /.*/ }, _options)
return function(config, cb) {
debug('running')
var result = Object.keys(config).reduce(function(accumulator, key) {
accumulator[key.toLowerCase().replace(/_/g, '.')] = config[key]
if (!options.filter.test(key)) return accumulator
accumulator[toPropertyPath(stripPrefix(key, options.prefix))] = config[key]
return accumulator
}, {})
cb(null, unflatten(result))
function stripPrefix(key, prefix) {
return key.replace(new RegExp('^' + prefix), '')
}
function toPropertyPath(key) {
return key.toLowerCase().replace(/_/g, '.')
}
}
}
}

5

package.json
{
"name": "confabulous",
"version": "1.1.3",
"version": "1.2.0",
"description": "A pluggable, hierarchical, asynchronous config loader and post processor with support for environment variables, command line arguments, json, javascript, http, vault, etcd and postgres",

@@ -18,7 +18,8 @@ "main": "index.js",

"async": "^2.0.0-rc.5",
"camelize": "^1.0.0",
"debug": "^2.2.0",
"deep-freeze": "0.0.1",
"flat": "^2.0.0",
"lodash.has": "^4.2.0",
"lodash.set": "^4.2.0",
"lodash.has": "^4.2.0",
"merge": "^1.2.0",

@@ -25,0 +26,0 @@ "minimist": "^1.2.0",

@@ -37,3 +37,3 @@ # Confabulous

```js
new Confabulous().add((config) => {
new Confabulous().add(config => {
return loaders.args()

@@ -47,3 +47,3 @@ })

```js
new Confabulous().add((config) => {
new Confabulous().add(config => {
return loaders.env()

@@ -57,3 +57,3 @@ })

```js
new Confabulous().add((config) => {
new Confabulous().add(config => {
return loaders.require({ path: './conf/defaults.js' })

@@ -71,3 +71,3 @@ })

```js
new Confabulous().add((config) => {
new Confabulous().add(config => {
return loaders.file({ path: './conf/defaults.js' }, [

@@ -92,3 +92,3 @@ processors.json()

```js
new Confabulous().add((config) => {
new Confabulous().add(config => {
return loaders.require({ path: './extra.json' }), [

@@ -103,3 +103,3 @@ processors.mount({ key: 'move.to.here' })

```js
new Confabulous().add((config) => {
new Confabulous().add(config => {
return loaders.env(), [

@@ -112,5 +112,5 @@ processors.unflatten()

#### envToProp
Converts environment variables in the form ```NODE_ENV``` to nested properties in the form ```node.env```
Converts environment variables in the form ```NODE_ENV=test``` to nested properties in the form ```{ node: { env: "test" } }```
```js
new Confabulous().add((config) => {
new Confabulous().add(config => {
return loaders.env(), [

@@ -121,7 +121,49 @@ processors.envToProp()

```
If you want to prefix your environment variables with an application discriminator you can also strip the prefix.
```js
new Confabulous().add(config => {
return loaders.env(), [
processors.envToProp({ prefix: 'GS_' }) // GS_SERVER_PORT => server.port
])
})
```
You can also filter environment variables to include only those you want
```js
new Confabulous().add(config => {
return loaders.env(), [
processors.envToProp({ filter: /^GS_/ }) // Only include environment variables starting with GS_
])
})
```
#### envToCamelCaseProp
Converts environment variables in the form ```USER__FIRST_NAME=fred``` to nested properties in the form ```{ user: { firstName: "fred" } }```
```js
new Confabulous().add(config => {
return loaders.env(), [
processors.envToCamelCaseProp()
])
})
```
If you want to prefix your environment variables with an application discriminator you can also strip the prefix.
```js
new Confabulous().add(config => {
return loaders.env(), [
processors.envToCamelCaseProp({ prefix: 'GS_' }) // GS_SERVER_PORT => server.port
])
})
```
You can also filter environment variables to include only those you want
```js
new Confabulous().add(config => {
return loaders.env(), [
processors.envToCamelCaseProp({ filter: /^GS_/ }) // Only include environment variables starting with GS_
])
})
```
#### json
Parses text into JSON. Useful when you have more than one post processor
```js
new Confabulous().add((config) => {
new Confabulous().add(config => {
return loaders.file({ path: './config.json.encrypted' }, [

@@ -136,3 +178,3 @@ processors.json()

```js
new Confabulous().add((config) => {
new Confabulous().add(config => {
return loaders.file({ path: './config.json.encrypted' }, [

@@ -139,0 +181,0 @@ processors.decrypt({ algorithm: 'aes192', password: process.env.SECRET }),

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc