Skip to content

apiaryio/drafter-npm

master
Switch branches/tags

Name already in use

A tag already exists with the provided branch name. Many Git commands accept both tag and branch names, so creating this branch may cause unexpected behavior. Are you sure you want to create this branch?
Code

Latest commit

 

Git stats

Files

Permalink
Failed to load latest commit information.
Type
Name
Latest commit message
Commit time
lib
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

logo

Drafter NPM Package Build Status

The Drafter NPM package is an API Blueprint parser for Node. This package is a wrapper around the underlying C++ parser Drafter. Drafter NPM optionally depends on the C++ binding to Drafter Protagonist. If for any reason Protagonist is not installable, this package will fallback to using the slower, pure JavaScript version of Drafter, drafter.js.

Installation

Drafter can be installed from NPM. If you want to use Drafter from a web browser, check out drafter.js.

$ npm install drafter

Usage

var drafter = require('drafter');

Once you've included drafter, you can parse an API Blueprint asynchronously:

var options = {
  generateSourceMap: true,
};

drafter.parse('# API Blueprint...', options, function(err, result) {
  if (err) {
    console.log(err);
  } else {
    console.log(result);
  }
});

Alternatively, you can use Drafter synchronously:

try {
  var result = drafter.parseSync('# API Blueprint...', options);
  console.log(result);
} catch (err) {
  console.log(err);
}

Parsing Options

Options can be passed to the parser as an optional second argument to both the asynchronous and synchronous interfaces:

var options = {
  generateSourceMap: true
}

drafter.parse('# My API', options, callback);

The available options are:

Name Description
requireBlueprintName Require parsed blueprints have a title (default: false)
generateSourceMap Enable sourcemap generation (default: false)

License

MIT License. See the LICENSE file.