Bolgia
Bolgia, an helper module for the config hell.
It recursively clone, mix, update and improve
configuration objects/hashes with nested properties.
˝..non ragioniam di lor, ma guarda e passa..˝
Install
$ npm install bolgia [-g]
// clone repo
$ git clone git@github.com:rootslab/bolgia.git
require
var Bolgia = require( 'bolgia' );
require returns an helper hash/obj with some properties/methods.
See examples.
Run Tests
$ cd bolgia/
$ npm test
Properties
Bolgia#circles : Object
Methods
Arguments within [ ] are optional.
Bolgia#clone( Object obj ) : Object
Bolgia#mix( Object dest, Object src ) : Object
Bolgia#improve( Object dest, Object src ) : Object
Bolgia#update( Object dest, Object src ) : Object
Bolgia#toString( Object o [, Boolean custom ] ) : String
Bolgia#doString( Object o [, Boolean custom ] ) : String
Bolgia#toArray( Object obj [, Boolean recur [, Array result ] ] ) : Array
Bolgia#toArrayEnum( Object obj [, Boolean recur [, Array result ] ] ) : Array
Bolgia#toHash( Array array [, Boolean recur [, Object result [, Boolean convert ] ] ] ) : Object
Bolgia#reveal( Array array ) : Array
Bolgia#count( Object obj [, Boolean leaf ] ) : Number
Bolgia#qs( Object hash [, Object opt ] ) : String
Bolgia#flatten( Object hash ) : Object
Sample Usage
require libs:
var log = console.log,
, util = require( 'util' )
, Bolgia = require( 'bolgia' );
define a default configuration object/hash:
var cfg = {
letters : [ 'aaa', 'bbb', 'ccc','ddd' ]
, numbers : {
1 : false
, 2 : false
, 3 : false
, 4 : false
}
, hell : {
h1 : {
a : [ 'a1!', 'a2!', 'a3!' ]
, b : [ 'b1!', 'b2!', 'b3!' ]
}
, h3 : {
1 : 0
, 2 : 0
}
}
};
define a custom update object/hash:
var upd = {
letters : [ undefined, 'BBB', 'CCC', undefined, 'EEE' ]
, numbers : {
1 : true
, 3 : Infinity
, 4 : null
}
, hell : {
h1 : {
a : [ undefined, 'A2!' ]
, b : [ 'B1!', undefined, 'B3!' ]
, e : [ undefined, 'E2!', 'E3!' ]
}
, h2 : 'BLAH'
, h3 : {
2 : new Date( '1913' )
}
}
};
update cfg with upd, and output results to console:
Bolgia.update( cfg, upd );
log( util.inspect( cfg, !true, null, true ) );
{
letters: [ 'aaa', 'BBB', 'CCC', 'ddd', 'EEE' ]
, numbers : {
1 : true
, 2 : false
, 3 : Infinity
, 4 : null
}
, hell : {
h1 : { a: [ 'a1!', 'A2!', 'a3!' ]
, h2 : 'BLAH'
b : [ 'B1!', 'b2!', 'B3!' ]
, e : [ undefined, 'E2!', 'E3!' ] }
h3 : {
1 : 0
, 2 : Wed Jan 01 1913 01:00:00 GMT+0100 (CET)
}
}
}
See readme-example
MIT License
Copyright (c) 2013-present < Guglielmo Ferri : 44gatti@gmail.com >
Permission is hereby granted, free of charge, to any person obtaining
a copy of this software and associated documentation files (the
'Software'), to deal in the Software without restriction, including
without limitation the rights to use, copy, modify, merge, publish,
distribute, sublicense, and/or sell copies of the Software, and to
permit persons to whom the Software is furnished to do so, subject to
the following conditions:
The above copyright notice and this permission notice shall be
included in all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED 'AS IS', WITHOUT WARRANTY OF ANY KIND,
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.