Security News
Fluent Assertions Faces Backlash After Abandoning Open Source Licensing
Fluent Assertions is facing backlash after dropping the Apache license for a commercial model, leaving users blindsided and questioning contributor rights.
configurazione
Advanced tools
#Configurazione ##A simple configuration manager in Node.js
###Introduction Configurazione is a very simple tool to make the management of configuration options for modules and classes easier.
In this first version, it's (limited) capabilities include:
###Instalation
Install Configurazione through NPM
npm install configurazione --save
This will install Configurazione as a dependency and update your package.json automatically.
Next require Configurazione in your Node.js script, like this:
var configurazione = require('configurazione');
###Usage
Configurazione has a clean and simple API, currently consisting of 4 methods:
####Setting default options
Imagine that we have an Icecream class, and in the constructor of our class, we define some following default options. We can easily add them to the Configurazione manager by calling configurazione.defaults()
var defaultOptions = {
name: 'Super delicious icecream',
flavours: ['vanilla', 'strawberry', 'chocolate'],
price: 10,
discount: false
};
// add the default options to the Configurazione manager
configurazione.defaults(defaultOptions);
####Setting user options
Next imagine that we instantiate a new Icecream, passing our own custom options. Let's say we want to enable a discount.
new Icecream({discount: true});
In the constructor of our Icecream class we now add the user options to the Configurazione manager by calling config.options()
var defaultOptions = {
name: 'Super delicious icecream',
flavours: ['vanilla', 'strawberry', 'chocolate'],
price: 10,
discount: false
};
// add the default options to the Configurazione library
configurazione.defaults(defaultOptions);
// add the user options to the Configurazione library
configurazione.options(userOptions);
####Getting configuration options
Next, inside our Icecream class, when we want to use a configuration option, we simply ask Configurazione to retrieve the correct value for a specific option. Configurazione will figure out if it should return the default value, or the user submitted value. User submitted options haven precedence over the default values.
var name = configurazione.get('name');
console.log(name); // prints 'Super delicious icecream'
var discount = configurazione.get('discount');
console.log(discount); // prints 'true', since user options take precedence over default options
####Setting configuration options
Sometimes, we want to store a specific configuration value at runtime. It's possible to add a new option or overwrite the value of an existign one.
var price = configurazione.get('price');
console.log(price); // prints '10'
// apply the discount
if(configurazione.get('discount'))
{
configurazione.set('price', 8);
}
var price = configurazione.get('price');
console.log(price); // prints '8'
FAQs
A simple configuration manager in Node.js
The npm package configurazione receives a total of 3 weekly downloads. As such, configurazione popularity was classified as not popular.
We found that configurazione demonstrated a not healthy version release cadence and project activity because the last version was released a year ago. It has 1 open source maintainer collaborating on the project.
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Security News
Fluent Assertions is facing backlash after dropping the Apache license for a commercial model, leaving users blindsided and questioning contributor rights.
Research
Security News
Socket researchers uncover the risks of a malicious Python package targeting Discord developers.
Security News
The UK is proposing a bold ban on ransomware payments by public entities to disrupt cybercrime, protect critical services, and lead global cybersecurity efforts.