node-data-section
Read data from comment, like a perl's Data::Section::Simple.
Install
$ npm install data-section
Usage
basic
var dataSection = require('data-section');
dataSection.get(function(err, data) {
console.log(data.data1);
console.log(data.data2);
});
dataSection.get('data1', function(err, data) {
console.log(data);
});
var data = dataSection.getSync();
console.log(data.data1);
console.log(data.data2);
console.log( dataSection.getSync('data1') );
console.log( dataSection.getSync('data2') );
set filename
Read from data1.js.
var dataSection = require('data-section');
var data1js = __dirname + '/data1.js';
dataSection.get({ filename: data1js }, function(err, data) {
console.log(data.foo);
});
dataSection.get({ key: 'foo', filename: data1js }, function(err, data) {
console.log(data);
});
var data = dataSection.getSync({ filename: data1js });
console.log(data.foo);
var data = dataSection.getSync({ key: 'foo', filename: data1js });
console.log(data);
test
Using nodeunit.
$ nodeunit test