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

configuration

Package Overview
Dependencies
Maintainers
1
Versions
35
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

configuration - npm Package Compare versions

Comparing version 0.0.2 to 0.0.3

40

index.js

@@ -8,2 +8,3 @@ var util = require('util');

EventEmitter.call(this);
this.defaults = underscore.clone(defaults || {});
this.data = defaults || {};

@@ -15,9 +16,13 @@ };

"use strict";
var event;
var ret = this;
if (this.data[key]) {
this.data[key] = value;
this.emit('change', key, this.data[key]);
event = 'change';
} else {
this.data[key] = value;
this.emit('set', key, this.data[key]);
event = 'set';
}
this.data[key] = value;
this.emit(event, key, this.data[key]);
this.emit(event + ':' + key, this.data[key]);
return ret;
};

@@ -34,7 +39,31 @@

this.emit('remove', key, this.data[key]);
this.emit('remove:' + key, this.data[key]);
delete this.data[key];
this.data[key] = null;
}
return this;
};
Configuration.prototype.removeAll = function removeAll() {
"use strict";
this.emit('removeAll');
delete this.data;
this.data = {};
return this;
};
Configuration.prototype.isEmpty = function isEmpty() {
"use strict";
return underscore.isEmpty(this.data);
};
Configuration.prototype.reset = function reset() {
"use strict";
this.emit('reset');
delete this.data;
this.data = null;
this.data = this.defaults;
return this;
};
Configuration.prototype.has = function has(key) {

@@ -50,6 +79,7 @@ "use strict";

underscore.each(config, function (value, key) {
that.add(key, value);
that.set(key, value);
});
return this;
};
module.exports = Configuration;

6

package.json

@@ -5,3 +5,3 @@ {

"description":"Simple light-weight configuration and setting module extending EventEmitter",
"version":"0.0.2",
"version":"0.0.3",
"homepage":"https://github.com/thomasfr/node-configuration",

@@ -16,6 +16,6 @@ "scripts":{

"dependencies":{
"underscore":"latest"
"underscore":"~1.3"
},
"engines":{
"node":">= 0.6.0"
"node":"~0.6.0"
},

@@ -22,0 +22,0 @@ "devDependencies":{

var Configuration = require('../');
var should = require('should');
describe('configuration', function () {
"use strict";
describe('defaults', function () {
var configuration = new Configuration({
str:"bar",
bool:true,
num:42
str: "bar",
bool: true,
num: 42
});

@@ -17,3 +20,3 @@ it("should contain default string value", function (done) {

configuration.get('bool').should.equal(true);
done()
done();
});

@@ -42,6 +45,14 @@ it("should contain default numeric value", function (done) {

});
it('should return the right values', function (done) {
it('should return the correct values', function (done) {
configuration.get('key').should.equal('value');
done();
});
it('should return an instance of configuration', function (done) {
configuration.set('foo', 'bar').should.be.an.instanceOf(Configuration);
done();
});
it('should return the same instance', function (done) {
configuration.set('foo', 'bar').should.equal(configuration);
done();
});
it('should emit a "set" event with the right key and value', function (done) {

@@ -62,6 +73,5 @@ configuration.on('set', function (key, value) {

configuration.set('eventKey', 'new value');
})
});
});
describe('#remove()', function () {

@@ -91,3 +101,3 @@ var configuration = new Configuration();

var configuration = new Configuration({
foo:"bar"
foo: "bar"
});

@@ -106,5 +116,44 @@ it('should be possible to check for values without errors', function (done) {

});
});
describe('#removeAll()', function () {
var configuration;
beforeEach(function () {
configuration = new Configuration();
configuration.set('foo', 'bar');
});
it('should be empty after calling removeAll()', function (done) {
configuration.removeAll().isEmpty().should.be.true;
done();
});
it('should not return any previously set key', function (done) {
should.not.exist(configuration.removeAll().get('foo'));
done();
});
it('should return same configuration instance', function (done) {
configuration.removeAll().should.equal(configuration);
done();
});
});
describe('#reset()', function () {
var configuration;
beforeEach(function () {
configuration = new Configuration({key: "value"});
configuration.set('foo', 'bar');
});
it('should not be empty after reset', function (done) {
configuration.reset().isEmpty().should.be.false;
done();
});
it('should not contain set keys', function (done) {
should.not.exist(configuration.reset().get('foo'));
done();
});
it('should contain default values', function (done) {
configuration.reset().get('key').should.equal('value');
done();
});
})
});
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