Socket
Socket
Sign inDemoInstall

nconf

Package Overview
Dependencies
Maintainers
1
Versions
38
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

nconf - npm Package Compare versions

Comparing version 0.5.0 to 0.5.1

18

lib/nconf/provider.js

@@ -44,3 +44,8 @@ /*

Provider.prototype[type] = function (options) {
return this.add('literal', options);
options = options || {};
if (!options.type) {
options.type = 'literal';
}
return this.add(type, options);
};

@@ -294,3 +299,5 @@ });

function getStores () {
return Object.keys(self.stores).map(function (name) {
var stores = Object.keys(self.stores);
stores.reverse();
return stores.map(function (name) {
return self.stores[name];

@@ -342,2 +349,5 @@ });

function loadSources () {
var sourceHierarchy = self.sources.splice(0);
sourceHierarchy.reverse();
//

@@ -349,7 +359,7 @@ // If we don't have a callback and the current

if (!callback) {
mergeSources(loadBatch(self.sources));
mergeSources(loadBatch(sourceHierarchy));
return loadBatch(getStores());
}
loadBatch(self.sources, function (err, data) {
loadBatch(sourceHierarchy, function (err, data) {
if (err) {

@@ -356,0 +366,0 @@ return callback(err);

@@ -72,2 +72,3 @@ /*

}
return this.store;
};

@@ -225,2 +226,3 @@

return fullpath;
};
};

@@ -202,2 +202,10 @@ /*

return true;
};
//
// ### function loadSync
// Returns the store managed by this instance
//
Memory.prototype.loadSync = function () {
return this.store || {};
};
{
"name": "nconf",
"description": "Hierarchical node.js configuration with files, environment variables, command-line arguments, and atomic object merging.",
"version": "0.5.0",
"version": "0.5.1",
"author": "Nodejitsu Inc. <info@nodejitsu.com>",

@@ -17,7 +17,7 @@ "contributors": [

"ini": "1.x.x",
"optimist": "0.2.x",
"optimist": "0.3.x",
"pkginfo": "0.2.x"
},
"devDependencies": {
"vows": "0.5.x >=0.5.11"
"vows": "0.6.x"
},

@@ -24,0 +24,0 @@ "main": "./lib/nconf",

{
"apples": true,
"bananas": true,
"foo": {
"bar": "boo"
},
"candy": {
"something": "file1",
"something1": true,

@@ -6,0 +10,0 @@ "something2": true

{
"candy": {
"something": "file2",
"something3": true,

@@ -4,0 +5,0 @@ "something4": true

@@ -31,2 +31,3 @@ /*

nconf.use('memory');
nconf.load();
assert.instanceOf(nconf.stores['memory'], nconf.Memory);

@@ -83,4 +84,4 @@ }

"without a callback": {
"should throw an exception": function () {
assert.throws(function () { nconf.load() });
"should respond with the merged store": function () {
assert.deepEqual(nconf.load(), { foo: { bar: {} } });
}

@@ -92,4 +93,5 @@ },

},
"should respond with an error": function (ign, err) {
assert.isNotNull(err);
"should respond with the merged store": function (ign, err, store) {
assert.isNull(err);
assert.deepEqual(store, { foo: { bar: {} } });
}

@@ -96,0 +98,0 @@ }

@@ -75,19 +75,43 @@ /*

helpers.assertMerged(null, provider.stores.file.store);
assert.equal(provider.stores.file.store.candy.something, 'file1');
}
},
"when sources are passed in": {
topic: new nconf.Provider({
sources: {
user: {
type: 'file',
file: files[0]
},
global: {
type: 'file',
file: files[1]
}
}
}
}).addBatch({
"When using nconf": {
"an instance of 'nconf.Provider'": {
"the load() method": {
"when sources are passed in": {
topic: new nconf.Provider({
sources: {
user: {
type: 'file',
file: files[0]
},
global: {
type: 'file',
file: files[1]
}
}
}),
"should respect the hierarchy ": function (provider) {
var merged = provider.load();
helpers.assertMerged(null, merged);
assert.equal(merged.candy.something, 'file1');
console.log(provider.sources);
}
}),
"should have the result merged in": function (provider) {
helpers.assertMerged(null, provider.load());
},
"when multiple stores are used": {
topic: new nconf.Provider().overrides({foo: {bar: 'baz'}})
.add('file1', {type: 'file', file: files[0]})
.add('file2', {type: 'file', file: files[1]}),
"should respect the hierarchy": function(provider) {
var merged = provider.load();
helpers.assertMerged(null, merged);
assert.equal(merged.foo.bar, 'baz');
assert.equal(merged.candy.something, 'file1');
}
}

@@ -94,0 +118,0 @@ }

@@ -68,3 +68,7 @@ /*

fs.readFile(tmpStore.file, function (err, d) {
return err ? that.callback(err) : that.callback(err, JSON.parse(d.toString()));
fs.unlinkSync(tmpStore.file);
return err
? that.callback(err)
: that.callback(err, JSON.parse(d.toString()));
});

@@ -81,2 +85,34 @@ });

"When using the nconf file store": {
topic: function () {
var tmpPath = path.join(__dirname, '..', 'fixtures', 'tmp.json'),
tmpStore = new nconf.File({ file: tmpPath });
return tmpStore;
},
"the saveSync() method": {
topic: function (tmpStore) {
var that = this;
Object.keys(data).forEach(function (key) {
tmpStore.set(key, data[key]);
});
var saved = tmpStore.saveSync();
fs.readFile(tmpStore.file, function (err, d) {
fs.unlinkSync(tmpStore.file);
return err
? that.callback(err)
: that.callback(err, JSON.parse(d.toString()), saved);
});
},
"should save the data correctly": function (err, read, saved) {
assert.isNull(err);
assert.deepEqual(read, data);
assert.deepEqual(read, saved);
}
}
}
}).addBatch({
"When using the nconf file store": {
"the set() method": {

@@ -140,2 +176,3 @@ "should respond with true": function () {

}
}).export(module);
}).export(module);
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