mdconf-from
parses a markdown file and returns a configuration object
Installation | API | Annotated source License
Installation
npm install mdconf-from --save
API
This package assumes that:
- The markdown file is utf8 encoded.
- There is a single h1 section.
- There is a
## Configuration
section, like this.
See also mdconf to learn how Markdown driven configuration works.
mdconfFrom(file)
- @param
{String}
file relative path - @returns
{Object}
config
// Suppose you are parsing this file itself.
var config = require('mdconf-from')('README.md')
console.log(config.foo) // bar
Configuration
This package does not use any configuration at all, this section is here only for test and documentation purpouse.
- foo: bar
Annotated source
Actually this package is a wrapper around mdconf.
var fs = require('fs')
var mdconf = require('mdconf')
function mdconfFrom (file) {
Parse the markdown in given file.
var content = fs.readFileSync(file, 'utf8')
var markdownObj = mdconf(content)
Extract the Configuration section.
var rootKey = Object.keys(markdownObj)[0]
var config = markdownObj[rootKey].configuration
return config
}
Export function
module.exports = mdconfFrom