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

cnfg-ng

Package Overview
Dependencies
Maintainers
1
Versions
3
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

cnfg-ng - npm Package Compare versions

Comparing version 1.0.0 to 1.0.1

.editorconfig

48

cnfg.js

@@ -1,24 +0,22 @@

var
pathHelpers = require('path'),
resolve = pathHelpers.resolve,
_ = require('lodash'),
debug = require('debug')('cnfg'),
walkDirSync = require('./walkDirSync');
var pathHelpers = require('path');
var resolve = pathHelpers.resolve;
var _ = require('lodash');
var debug = require('debug')('cnfg');
var walkDirSync = require('./walkDirSync');
function sanitizeExtensions(configuredExtensions) {
if (!configuredExtensions) {
return ['.js'];
}
return Array.isArray(configuredExtensions)
? configuredExtensions
: [configuredExtensions];
if (!configuredExtensions) {
return ['.js'];
}
return Array.isArray(configuredExtensions)
? configuredExtensions
: [configuredExtensions];
}
module.exports = function(path, env, processEnv, configFileExtensions) {
var
length = path.length,
config = {},
depth, files, envs;
var length = path.length;
var config = {};
var depth, files, envs;
var extensions = sanitizeExtensions(configFileExtensions);
var extensions = sanitizeExtensions(configFileExtensions);

@@ -32,9 +30,9 @@ env = env || process.env.NODE_ENV || 'development';

var onlyFiles = function(filepath) {
const fileExt = pathHelpers.extname(filepath);
if (extensions.indexOf(fileExt) === -1) {
return false;
}
var baseName = pathHelpers.basename(filepath);
var baseNameWithoutExtension = baseName.substr(0, baseName.length - fileExt.length);
return baseNameWithoutExtension !== 'index';
const fileExt = pathHelpers.extname(filepath);
if (extensions.indexOf(fileExt) === -1) {
return false;
}
var baseName = pathHelpers.basename(filepath);
var baseNameWithoutExtension = baseName.substr(0, baseName.length - fileExt.length);
return baseNameWithoutExtension !== 'index';
}

@@ -62,3 +60,3 @@

var endsWith = function(string, suffix) {
var l = string.length - suffix.length;
var l = string.length - suffix.length;
return l >= 0 && string.indexOf(suffix, l) === l;

@@ -65,0 +63,0 @@ }

{
"name": "cnfg-ng",
"version": "1.0.0",
"description": "Hierarchical environment configuration for node.js applications, forked from cnfg",
"main": "cnfg.js",
"scripts": {
"prepublish": "run-s test",
"test": "run-s test-js test-ts",
"test-js": "mocha -R spec test --recursive",
"test-ts": "mocha -R spec test-ts/**/*.spec.ts --require ts-node/register --recursive",
"autotest-ts": "mocha -R mocha-yar test-ts/**/*.spec.ts --require ts-node/register --recursive --watch --watch-extensions ts",
"autotest-js": "mocha -R mocha-yar test --recursive --watch",
"autotest": "run-p autotest-js autotest-ts",
"postinstall": "typings install"
},
"repository": "https://github.com/fluffynuts/cnfg.git",
"author": "Davyd McColl <davydm@gmail.com>",
"license": "MIT",
"bugs": {
"url": "https://github.com/fluffynuts/cnfg/issues"
},
"homepage": "https://github.com/fluffynuts/cnfg",
"dependencies": {
"debug": "^2.2.0",
"lodash": "^4.6.1"
},
"keywords": [
"config",
"settings",
"conf",
"recursive",
"recursively",
"environment",
"env",
"hierarchy",
"hierarchical"
],
"devDependencies": {
"chai": "~1.8.1",
"mocha": "^3.0.1",
"mocha-yar": "^1.0.10",
"npm-run-all": "^2.3.0",
"ts-node": "^1.2.2",
"typescript": "^1.8.10",
"typings": "^1.3.2"
}
"name": "cnfg-ng",
"version": "1.0.1",
"description": "Hierarchical environment configuration for node.js applications, forked from cnfg",
"main": "cnfg.js",
"scripts": {
"prepublish": "run-s test",
"test": "run-s test-js test-ts",
"test-js": "mocha -R spec test --recursive",
"test-ts": "mocha -R spec test-ts/**/*.spec.ts --require ts-node/register --recursive",
"autotest-ts": "mocha -R mocha-yar test-ts/**/*.spec.ts --require ts-node/register --recursive --watch --watch-extensions ts",
"autotest-js": "mocha -R mocha-yar test --recursive --watch",
"autotest": "run-p autotest-js autotest-ts",
"postinstall": "typings install"
},
"repository": "https://github.com/boo1ean/cnfg.git",
"author": "Egor Gumenyuk <boo1ean0807@gmail.com>",
"license": "MIT",
"bugs": {
"url": "https://github.com/boo1ean/cnfg/issues"
},
"homepage": "https://github.com/boo1ean/cnfg",
"dependencies": {
"debug": "^2.2.0",
"lodash": "^4.6.1"
},
"keywords": [
"config",
"settings",
"conf",
"recursive",
"recursively",
"environment",
"env",
"hierarchy",
"hierarchical"
],
"devDependencies": {
"chai": "~1.8.1",
"mocha": "^3.0.1",
"mocha-yar": "^1.0.10",
"npm-run-all": "^2.3.0",
"ts-node": "^1.2.2",
"typescript": "^1.8.10",
"typings": "^1.3.2"
}
}

@@ -0,1 +1,5 @@

*This package as been deprecated as it was a temporary release whilst my pull
request for the `walkdir` dependency removal was being reviewd. Please use the
official [cnfg](http://npmjs.com/package/cnfg) package instead.*
cnfg-ng

@@ -2,0 +6,0 @@ ====

@@ -6,117 +6,117 @@ /// <reference path="../typings/index.d.ts" />

describe('cnfg under ts-node', () => {
function cnfg(path: string, env?: any, processEnv?: any) {
return actual_cnfg(path, env, processEnv, ['.js', '.ts'])
}
describe('Heirarchical environment config extraction', () => {
it('Should extract single-level config very well', () => {
// Arrange
const
path = __dirname + '/config-single-level',
expected = {
api: { key: '123' },
app: { transport: 'http' },
db: { name: 'johny' }
};
// Act
const result = cnfg(path, null, null);
// Assert
expect(result).to.be.deep.equal(expected);
})
it('Should extract two-level configuration like a boss', function () {
var path = __dirname + '/config-two-levels';
var expected = {
'api': { key: '123' },
'app': { transport: 'http' },
'db': { name: 'johny' }
};
function cnfg(path: string, env?: any, processEnv?: any) {
return actual_cnfg(path, env, processEnv, ['.js', '.ts'])
}
describe('Heirarchical environment config extraction', () => {
it('Should extract single-level config very well', () => {
// Arrange
const
path = __dirname + '/config-single-level',
expected = {
api: { key: '123' },
app: { transport: 'http' },
db: { name: 'johny' }
};
// Act
const result = cnfg(path, null, null);
// Assert
expect(result).to.be.deep.equal(expected);
})
it('Should extract two-level configuration like a boss', function () {
var path = __dirname + '/config-two-levels';
var expected = {
'api': { key: '123' },
'app': { transport: 'http' },
'db': { name: 'johny' }
};
expect(cnfg(path)).to.be.deep.equal(expected);
expect(cnfg(path)).to.be.deep.equal(expected);
var expected_prod = {
'api': { key: 'prod_123' },
'app': { transport: 'http' },
'db': { name: 'prod_johny', port: 5555 }
};
var expected_prod = {
'api': { key: 'prod_123' },
'app': { transport: 'http' },
'db': { name: 'prod_johny', port: 5555 }
};
expect(cnfg(path, 'prod')).to.be.deep.equal(expected_prod);
expect(cnfg(path, 'prod')).to.be.deep.equal(expected_prod);
var expected_test = {
'api': { key: '123', test_secret: 'wow such secret' },
'app': { transport: 'http' },
'db': { name: 'johny' }
};
var expected_test = {
'api': { key: '123', test_secret: 'wow such secret' },
'app': { transport: 'http' },
'db': { name: 'johny' }
};
expect(cnfg(path, 'test')).to.be.deep.equal(expected_test);
});
expect(cnfg(path, 'test')).to.be.deep.equal(expected_test);
});
it('Should extract configuration with index.ts in base dir', function () {
var expected = {
'api': { key: '123' },
'app': { transport: 'http' },
'db': { name: 'johny' }
};
it('Should extract configuration with index.ts in base dir', function () {
var expected = {
'api': { key: '123' },
'app': { transport: 'http' },
'db': { name: 'johny' }
};
expect(require('./config-with-index')).to.be.deep.equal(expected);
});
expect(require('./config-with-index')).to.be.deep.equal(expected);
});
it('Should extract two-level configuration with index', function () {
var path = './config-two-levels-with-index';
it('Should extract two-level configuration with index', function () {
var path = './config-two-levels-with-index';
var expected_prod = {
'api': { key: 'prod_123' },
'app': { transport: 'http' },
'db': { name: 'prod_johny', port: 5555 }
};
var expected_prod = {
'api': { key: 'prod_123' },
'app': { transport: 'http' },
'db': { name: 'prod_johny', port: 5555 }
};
expect(require(path)).to.be.deep.equal(expected_prod);
});
expect(require(path)).to.be.deep.equal(expected_prod);
});
it('Should apply overrides env correctly', function () {
var path = __dirname + '/config-with-env';
it('Should apply overrides env correctly', function () {
var path = __dirname + '/config-with-env';
var expected = {
'api': { key: 'prod_123', key2: 'env key', underscored_key: 456 },
'app': { transport: 'http' },
'db': { name: 'prod_johny', port: 5555 }
};
var expected = {
'api': { key: 'prod_123', key2: 'env key', underscored_key: 456 },
'app': { transport: 'http' },
'db': { name: 'prod_johny', port: 5555 }
};
expect(cnfg(path, 'prod', { CNFG_API__KEY2: 'env key', CNFG_API__UNDERSCORED_KEY: 456 })).to.be.deep.equal(expected);
})
});
describe('Configuration', function () {
it('Properties should not be changed', function () {
var path = __dirname + '/config-single-level';
var expected = {
'api': { key: '123' },
'app': { transport: 'http' },
'db': { name: 'johny' }
};
expect(cnfg(path, 'prod', { CNFG_API__KEY2: 'env key', CNFG_API__UNDERSCORED_KEY: 456 })).to.be.deep.equal(expected);
})
});
describe('Configuration', function () {
it('Properties should not be changed', function () {
var path = __dirname + '/config-single-level';
var expected = {
'api': { key: '123' },
'app': { transport: 'http' },
'db': { name: 'johny' }
};
var config = cnfg(path);
var config = cnfg(path);
expect(config).to.be.deep.equal(expected);
expect(config).to.be.deep.equal(expected);
expect(() => {
config.api = 1;
}).to.throw // running under ts-node, when attempting to assign, this will throw
expect(config).to.be.deep.equal(expected);
});
expect(() => {
config.api = 1;
}).to.throw // running under ts-node, when attempting to assign, this will throw
expect(config).to.be.deep.equal(expected);
});
it('May be extended with new properties', function () {
var path = __dirname + '/config-single-level';
var expected = {
'api': { key: '123' },
'app': { transport: 'http' },
'db': { name: 'johny' }
};
it('May be extended with new properties', function () {
var path = __dirname + '/config-single-level';
var expected = {
'api': { key: '123' },
'app': { transport: 'http' },
'db': { name: 'johny' }
};
var config = cnfg(path);
var config = cnfg(path);
expect(config).to.be.deep.equal(expected);
expect(config).to.be.deep.equal(expected);
config.newProp = 1;
config.newProp = 1;
expect(config).to.have.property('newProp');
});
});
});
expect(config).to.have.property('newProp');
});
});
});
/// <reference path="../../typings/index.d.ts" />
module.exports = {
key: '123'
key: '123'
}

@@ -1,3 +0,3 @@

var cnfg = require('../'),
expect = require('chai').expect;
var cnfg = require('../');
var expect = require('chai').expect;

@@ -4,0 +4,0 @@ describe('Hierarchical environment config extraction', function() {

{
"name": "cnfg-ng",
"dependencies": {},
"globalDevDependencies": {
"chai": "registry:dt/chai#3.4.0+20160601211834",
"mocha": "registry:dt/mocha#2.2.5+20160720003353",
"node": "registry:dt/node#6.0.0+20160805072842"
}
"name": "cnfg-ng",
"dependencies": {},
"globalDevDependencies": {
"chai": "registry:dt/chai#3.4.0+20160601211834",
"mocha": "registry:dt/mocha#2.2.5+20160720003353",
"node": "registry:dt/node#6.0.0+20160805072842"
}
}

@@ -1,35 +0,34 @@

var
pathHelpers = require('path'),
debug = require('debug')('cnfg'),
fs = require('fs');
var pathHelpers = require('path');
var debug = require('debug')('cnfg');
var fs = require('fs');
function isDirectory(path) {
try {
var info = fs.lstatSync(path);
return info.isDirectory();
} catch (ignore) {
return false;
}
try {
var info = fs.lstatSync(path);
return info.isDirectory();
} catch (ignore) {
return false;
}
}
module.exports = function walkDirSync(path) {
try {
debug('read contents of dir: ', path);
var
contents = fs.readdirSync(path),
result = []
contents.forEach(function (item) {
var fullPath = pathHelpers.join(path, item);
if (isDirectory(fullPath)) {
var subContents = walkDirSync(fullPath);
result.push.apply(result, subContents);
} else {
result.push(fullPath);
}
})
debug('found ', result.length, ' items under ', path);
return result;
} catch (ignore) {
return []
}
try {
debug('read contents of dir: ', path);
var
contents = fs.readdirSync(path),
result = []
contents.forEach(function (item) {
var fullPath = pathHelpers.join(path, item);
if (isDirectory(fullPath)) {
var subContents = walkDirSync(fullPath);
result.push.apply(result, subContents);
} else {
result.push(fullPath);
}
})
debug('found ', result.length, ' items under ', path);
return result;
} catch (ignore) {
return []
}
}
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