node package manager
Don’t reinvent the wheel. Reuse code within your team. Create a free org »

mdconf-from

mdconf-from

parses a markdown file and returns a configuration object

KLP

NPM version Build Status Dependency Status

js-standard-style

Installation | API | Annotated source

Installation

npm install mdconf-from --save

API

This package assumes that:

  1. The markdown file is utf8 encoded.
  2. There is a single h1 section.
  3. There is a ## Configuration section.

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

License

MIT