mdconf-from

0.2.2 • Public • Published

mdconf-from

parses a markdown file and returns a configuration object

Installation | API | Annotated source License

NPM version Build Status Dependency Status JavaScript Style Guide KLP

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, 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

License

MIT

Readme

Keywords

Package Sidebar

Install

npm i mdconf-from

Weekly Downloads

0

Version

0.2.2

License

MIT

Last publish

Collaborators

  • fibo