Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

parser-front-matter

Package Overview
Dependencies
Maintainers
2
Versions
26
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

parser-front-matter

Front matter parsing middleware based on gray-matter.

  • 1.6.4
  • latest
  • Source
  • npm
  • Socket score

Version published
Weekly downloads
29K
decreased by-4.54%
Maintainers
2
Weekly downloads
 
Created
Source

parser-front-matter NPM version NPM monthly downloads NPM total downloads Linux Build Status

Front matter parsing middleware based on gray-matter.

Install

Install with npm:

$ npm install --save parser-front-matter

This is similar to a consolidate.js engine, but for parsing. Works with assemble, verb, generate, update, express.js, parser-cache, or any application with similar conventions.

Usage

var parser = require('parser-front-matter');

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}: or next 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'}}

file object

Returned file objects have the following properties (no other properties are modified on the given file):

  • data: data from parsed front matter
  • content: the content string, excluding front-matter (assemble compatibility)
  • contents: the content string as a buffer, excluding front-matter
  • orig: the original content string with front-matter included

About

Contributing

Pull requests and stars are always welcome. For bugs and feature requests, please create an issue.

Contributors

CommitsContributor
69jonschlinkert
2doowb

Building docs

(This project's readme.md is generated by verb, please don't edit the readme directly. Any changes to the readme must be made in the .verb.md readme template.)

To generate the readme, run the following command:

$ npm install -g verbose/verb#dev verb-generate-readme && verb

Running tests

Running and reviewing unit tests is a great way to get familiarized with a library and its API. You can install dependencies and run tests with the following command:

$ npm install && npm test

Author

Jon Schlinkert

License

Copyright © 2017, Jon Schlinkert. Released under the MIT License.


This file was generated by verb-generate-readme, v0.6.0, on July 16, 2017.

Keywords

FAQs

Package last updated on 16 Jul 2017

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc