Package Exports
- parser-front-matter
This package does not declare an exports field, so the exports above have been automatically detected and optimized by JSPM instead. If any package subpath is missing, it is recommended to post an issue to the original package (parser-front-matter) to support the "exports" field. If that is not possible, create a JSPM override to customize the exports field for this package.
Readme
parser-front-matter

Front matter parsing middleware based on gray-matter.
This is kind of like a consolidate.js engine, but for parsing. Works with Assemble, verb, express.js, parser-cache, or any application with similar conventions.
Install
Install with npm
$ npm i parser-front-matter --save
Usage
var parser = require('parser-front-matter');
file object
Returned file
objects have the following properties (no other properties are modified on the given file):
data
: data from parsed front mattercontent
: the content string, excluding front-matter (assemble compatibility)contents
: the content string as a buffer, excluding front-matterorig
: the original content string with front-matter included
API
.parse
Parse front matter from the given string or the contents
in the given file
and callback next(err, file)
.
If an object is passed, either file.contents
or file.content
may be used (for gulp and assemble compatibility).
Params
file
{String|Object}: The object or string to parse.options
{Object|Function}: ornext
callback function. Options are passed to gray-matter.next
{Function}: callback function.
Example
// pass a string
parser.parse('---\ntitle: foo\n---\nbar', function (err, file) {
//=> {content: 'bar', data: {title: 'foo'}}
});
// or an object
var file = {contents: new Buffer('---\ntitle: foo\nbar')};
parser.parse(file, function(err, res) {
//=> {content: 'bar', data: {title: 'foo'}}
});
.parseSync
Parse front matter from the given string or the contents
in the given file
. If an object is passed, either file.contents
or file.content
may be used (for gulp and assemble compatibility).
Params
file
{String|Object}: The object or string to parse.options
{Object}: passed to gray-matter.
Example
// pass a string
var res = parser.parseSync('---\ntitle: foo\n---\nbar');
// or an object
var file = {contents: new Buffer('---\ntitle: foo\nbar')};
var res = parser.parseSync(file);
//=> {content: 'bar', data: {title: 'foo'}}
Related
- gray-matter: Parse front-matter from a string or file. Fast, reliable and easy to use. Parses YAML… more | homepage
- parser-cache: Cache and load parsers, similiar to consolidate.js engines. | homepage
- parser-csv: CSV parser, compatible with [parser-cache]. | homepage
Tests
Install dev dependencies:
$ npm i -d && npm test
Author
Jon Schlinkert
License
Copyright © 2014-2015 Jon Schlinkert Released under the MIT license.
This file was generated by verb-cli on October 20, 2015.