New Case Study:See how Anthropic automated 95% of dependency reviews with Socket.Learn More
Socket
Sign inDemoInstall
Socket

cfg-manager

Package Overview
Dependencies
Maintainers
1
Versions
8
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

cfg-manager - npm Package Compare versions

Comparing version 0.0.1 to 0.0.2

17

index.js
'use strict';
var objectAssign = require('object-assign');
module.exports = {

@@ -25,11 +27,12 @@

*/
init: function(defaultConfig, options = {}) {
let prefix = options.prefix || this.prefix;
let config = Object.assign({}, defaultConfig || {});
let env = process.env;
init: function(defaultConfig, options) {
options = options || {};
var prefix = options.prefix || this.prefix;
var config = objectAssign({}, defaultConfig || {});
var env = process.env;
for (let key in env) {
let realKey = key.substr(prefix.length);
for (var key in env) {
var realKey = key.substr(prefix.length);
if (key.indexOf(prefix) === 0 && config[realKey] !== undefined) {
let value = env[key];
var value = env[key];
// Convert string into number if it's a number

@@ -36,0 +39,0 @@ config[realKey] = this._isNumeric(value) ? parseFloat(value) : value;

{
"name": "cfg-manager",
"version": "0.0.1",
"version": "0.0.2",
"author": "Ricky Chien <ricky060709@gmail.com>",

@@ -15,4 +15,6 @@ "description": "Managing config and environment variables",

"readme": "README.md",
"dependencies": {
"object-assign": "^3.0.0"
},
"devDependencies": {
"babel": "^5.6.23",
"mocha": "^2.2.5"

@@ -19,0 +21,0 @@ },

@@ -19,9 +19,13 @@ # Cfg-manager

The cfg-manager can treat user input parameters as ENVs and merge it with a given default configuration.
The cfg-manager can treat user input parameters as ENVs and merge it with a given default configuration. Easily access config from modules by parsing pre-stored environment variable.
### Example
You can simply initialize config from an entry module and access it from sub-modules without re-initializing again.
Initialize and generate merged config which is also stored in environment varialbe with the name CONFIG_MANAGER_ENVS.
In entry.js, simply use:
```javascript
var subModule = require('sub-modules');
var cfgManager = require('cfg-manager');

@@ -34,4 +38,6 @@

Get config once you already init / store your config as an environment variable
Simply access config with getConfig() once you already init() in your config from entry module.
In sub-modules.js:
```javascript

@@ -42,2 +48,24 @@ var cfgManager = require('cfg-manager');

### APIs
#### init(defaultConfig, [options])
Initialize config object by merging given confg object and given environment variables.
options: ```Object```
return: ```Object```
##### options.prefix
Environment variable prefix. Cfg-manager only parse environment variables if they begin with given prefix.
type: ```string```
default: ```'APP_'```
#### getConfig()
Return config object directly if config has been initialized and existed in environment variable CONFIG_MANAGER_ENVS.
## Development

@@ -44,0 +72,0 @@

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