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

config-cev-generator

Package Overview
Dependencies
Maintainers
1
Versions
5
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

config-cev-generator - npm Package Compare versions

Comparing version 0.1.5 to 0.1.6

8

cev-cli.js

@@ -35,2 +35,9 @@ #!/usr/bin/env node

},
'noprefix': {
key: 'n',
description: "Do not use a prefix; supercedes --prefix.",
args: 0,
mandatory: false,
default: cev.DEFAULT_NO_PREFIX
},
'casing': {

@@ -71,2 +78,3 @@ key: 'c',

var vars = cev.generate(require('config'), {
noPrefix: opts.noprefix,
prefix: opts.prefix,

@@ -73,0 +81,0 @@ separator: opts.separator,

27

lib/cev.js

@@ -6,2 +6,3 @@ 'use strict';

var DEFAULT_PREFIX = 'NODE_APP';
var DEFAULT_NO_PREFIX = false;
var PACKAGE_NAME_PREFIX_PLACEHOLDER = '@';

@@ -29,2 +30,3 @@ var DEFAULT_SEPARATOR = '_';

* <li><code>prefix</code>: prefix, default: NODE_APP (see exported DEFAULT_PREFIX); use '@' to use the name of your application</li>
* <li><code>noPrefix</code>: true|false, default: false (see exported DEFAULT_NO_PREFIX); overrides use of any prefix</li>
* <li><code>separator</code>: separator, default: _ (see exported DEFAULT_SEPARATOR)</li>

@@ -42,9 +44,13 @@ * <li><code>casing</code>: value indicating the casing policy to use:

*/
var generate = function generate(obj, opts) {
var generate = function generate (obj, opts) {
obj = obj || {};
opts = opts || {};
var prefix = opts.prefix || module.exports.DEFAULT_PREFIX;
if (prefix === PACKAGE_NAME_PREFIX_PLACEHOLDER) {
prefix = require(path.resolve('package.json')).name;
var prefix = '';
var noPrefix = opts.noPrefix;
if (!noPrefix) {
prefix = opts.prefix || module.exports.DEFAULT_PREFIX;
if (prefix === PACKAGE_NAME_PREFIX_PLACEHOLDER) {
prefix = require(path.resolve('package.json')).name;
}
}

@@ -63,6 +69,6 @@ var separator = opts.separator || module.exports.DEFAULT_SEPARATOR;

Object.keys(obj).forEach(function (key) {
if ((obj[key] instanceof Function)) return; // skip
else if (obj[key] instanceof Object) { // recurse
if ((obj[ key ] instanceof Function)) return; // skip
else if (obj[ key ] instanceof Object) { // recurse
var pre = applyCasing((prefix ? (prefix + separator) : '') + key, casing);
vars[key] = generate(obj[key], {
vars[ key ] = generate(obj[ key ], {
prefix: pre,

@@ -73,7 +79,7 @@ separator: separator,

});
if ((!Object.keys(vars[key]).length) && !empties) delete vars[key];
if ((!Object.keys(vars[ key ]).length) && !empties) delete vars[ key ];
}
else { // add
var v = applyCasing((prefix ? prefix + separator : '') + key, casing);
vars[key] = v;
vars[ key ] = v;
}

@@ -84,3 +90,3 @@ });

function applyCasing(value, casing) {
function applyCasing (value, casing) {
value = value.toString();

@@ -100,2 +106,3 @@ switch (casing) {

module.exports.DEFAULT_PREFIX = DEFAULT_PREFIX;
module.exports.DEFAULT_NO_PREFIX = DEFAULT_NO_PREFIX;
module.exports.DEFAULT_SEPARATOR = DEFAULT_SEPARATOR;

@@ -102,0 +109,0 @@ module.exports.DEFAULT_EMPTIES = DEFAULT_EMPTIES;

{
"name": "config-cev-generator",
"private": false,
"version": "0.1.5",
"keywords": ["config", "node-config", "custom-environment-variables", "generator"],
"version": "0.1.6",
"keywords": [
"config",
"node-config",
"custom-environment-variables",
"generator"
],
"main": "lib/cev",

@@ -26,3 +31,6 @@ "bin": {

"config": "^1.12.0"
},
"devDependencies": {
"mocha": "^2.5.3"
}
}

@@ -11,2 +11,25 @@ 'use strict';

});
it('should work with no prefix specified', function (done) {
var opts = {
noPrefix: true,
prefix: 'GOO'
};
var obj = {
foo: 1,
bar: {
sna: 1,
fu: 2
}
};
var expected = {
foo: 'FOO',
bar: {
sna: 'BAR_SNA',
fu: 'BAR_FU'
}
};
var actual = cev(obj, opts);
assert.deepEqual(actual, expected);
done();
});
it('should work with a flat object with defaults', function (done) {

@@ -13,0 +36,0 @@ var obj = {

Sorry, the diff of this file is not supported yet

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