Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/hokaccha/node-data-section
Read data from comment, like a perl's Data::Section::Simple.
https://github.com/hokaccha/node-data-section
Last synced: about 2 months ago
JSON representation
Read data from comment, like a perl's Data::Section::Simple.
- Host: GitHub
- URL: https://github.com/hokaccha/node-data-section
- Owner: hokaccha
- License: mit
- Created: 2011-07-08T09:22:01.000Z (over 13 years ago)
- Default Branch: master
- Last Pushed: 2012-05-31T00:14:42.000Z (over 12 years ago)
- Last Synced: 2024-10-14T15:08:49.913Z (2 months ago)
- Language: JavaScript
- Homepage:
- Size: 114 KB
- Stars: 5
- Watchers: 3
- Forks: 1
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# node-data-section
Read data from comment, like a perl's Data::Section::Simple.
## Install
$ npm install data-section
## Usage
### basic
``` js
var dataSection = require('data-section');// getAll
dataSection.get(function(err, data) {
console.log(data.data1); // foo
console.log(data.data2); // bar\nbaz
});// get
dataSection.get('data1', function(err, data) {
console.log(data); // foo
});// getAllSync
var data = dataSection.getSync();
console.log(data.data1); // foo
console.log(data.data2); // bar\nbaz// getSync
console.log( dataSection.getSync('data1') ); // foo
console.log( dataSection.getSync('data2') ); // bar\nbaz/* __DATA__
@@ data1
foo
@@ data2
bar
baz
__DATA__*/
```### set filename
``` js
// data1.js
/*__DATA__
@@ foo
bar
__DATA__*/
```Read from data1.js.
``` js
var dataSection = require('data-section');
var data1js = __dirname + '/data1.js';// getAll
dataSection.get({ filename: data1js }, function(err, data) {
console.log(data.foo); // bar
});// get
dataSection.get({ key: 'foo', filename: data1js }, function(err, data) {
console.log(data); // bar
});// getAllSync
var data = dataSection.getSync({ filename: data1js });
console.log(data.foo); // bar// getSync
var data = dataSection.getSync({ key: 'foo', filename: data1js });
console.log(data); // bar
```## test
Using nodeunit.
``` js
$ nodeunit test
```