front-matter vs gray-matter vs js-yaml vs yaml-front-matter vs yamljs
Markdown Front Matter Parsing Libraries
front-mattergray-matterjs-yamlyaml-front-matteryamljsSimilar Packages:

Markdown Front Matter Parsing Libraries

These libraries are designed to parse front matter from Markdown files, allowing developers to extract metadata and configuration settings from the top of Markdown documents. This is particularly useful in static site generators and content management systems where metadata is often used to control how content is displayed or processed. Each library offers unique features and syntax support, catering to different use cases and preferences in handling YAML and front matter formats.

Npm Package Weekly Downloads Trend

3 Years

Github Stars Ranking

Stat Detail

Package
Downloads
Stars
Size
Issues
Publish
License
front-matter0695-326 years agoMIT
gray-matter04,483-785 years agoMIT
js-yaml06,6191.45 MB711 days agoMIT
yaml-front-matter0194-216 years agoMIT
yamljs0886-539 years agoMIT

Feature Comparison: front-matter vs gray-matter vs js-yaml vs yaml-front-matter vs yamljs

Parsing Capabilities

  • front-matter:

    front-matter provides a simple API to extract front matter from Markdown files. It supports basic YAML syntax and is optimized for performance, making it ideal for projects that require minimal overhead.

  • gray-matter:

    gray-matter excels in parsing both YAML and JSON front matter, offering flexibility with custom delimiters. It also allows you to parse the content of the Markdown file alongside the front matter, which is useful for static site generators.

  • js-yaml:

    js-yaml is a powerful YAML parser that can handle complex YAML structures, including nested objects and arrays. It is not specifically designed for front matter but is excellent for general YAML parsing needs.

  • yaml-front-matter:

    yaml-front-matter combines YAML parsing with front matter extraction, allowing you to easily manage metadata in Markdown files. It provides a straightforward API for accessing front matter and the remaining content of the Markdown file.

  • yamljs:

    yamljs is a comprehensive library for parsing and stringifying YAML. It supports advanced YAML features and is suitable for applications that require extensive manipulation of YAML data.

Ease of Use

  • front-matter:

    front-matter is designed for simplicity, making it easy to integrate into projects without a steep learning curve. Its API is intuitive, allowing developers to quickly extract front matter with minimal configuration.

  • gray-matter:

    gray-matter offers a user-friendly API that is easy to understand, especially for those familiar with Markdown. Its ability to handle different front matter formats makes it versatile for various projects.

  • js-yaml:

    js-yaml has a slightly steeper learning curve due to its extensive features, but it is well-documented, making it manageable for developers who need advanced YAML capabilities.

  • yaml-front-matter:

    yaml-front-matter is straightforward to use, providing clear methods for extracting front matter and content. Its API is designed to be intuitive for developers working with Markdown.

  • yamljs:

    yamljs is powerful but may require more effort to learn due to its comprehensive feature set. However, it provides detailed documentation to assist developers in utilizing its capabilities.

Performance

  • front-matter:

    front-matter is lightweight and optimized for performance, making it suitable for high-frequency parsing scenarios, such as in static site generators where speed is crucial.

  • gray-matter:

    gray-matter balances performance with flexibility, allowing for efficient parsing of front matter while also supporting additional features without significant overhead.

  • js-yaml:

    js-yaml is robust but may not be as fast as lighter libraries for simple front matter parsing. It is best used when complex YAML structures are involved, where its performance trade-offs are justified.

  • yaml-front-matter:

    yaml-front-matter performs well for typical front matter extraction tasks, but its performance may vary based on the complexity of the YAML content being parsed.

  • yamljs:

    yamljs is designed for comprehensive YAML handling, which may introduce some performance overhead compared to simpler libraries. It is best used when advanced YAML features are needed.

Community and Support

  • front-matter:

    front-matter has a smaller community compared to some alternatives, but it is actively maintained and sufficient for basic needs.

  • gray-matter:

    gray-matter enjoys a larger user base and community support, making it easier to find examples and solutions to common issues.

  • js-yaml:

    js-yaml has a strong community and extensive documentation, making it a reliable choice for developers needing support for YAML parsing.

  • yaml-front-matter:

    yaml-front-matter has a decent level of community support, with documentation that covers most use cases, although it may not be as extensive as larger libraries.

  • yamljs:

    yamljs has a solid community and is well-documented, providing ample resources for developers seeking help with YAML parsing and manipulation.

Extensibility

  • front-matter:

    front-matter is minimalistic and does not offer extensibility features, focusing solely on front matter parsing without additional functionalities.

  • gray-matter:

    gray-matter allows for some extensibility through custom delimiters and the ability to parse different content types, making it adaptable for various use cases.

  • js-yaml:

    js-yaml is highly extensible, allowing developers to define custom YAML types and tags, making it suitable for complex applications that require tailored YAML handling.

  • yaml-front-matter:

    yaml-front-matter provides basic extensibility for front matter management but is primarily focused on simplicity and ease of use.

  • yamljs:

    yamljs is very extensible, supporting custom YAML types and advanced features, making it a great choice for projects that require extensive YAML manipulation.

How to Choose: front-matter vs gray-matter vs js-yaml vs yaml-front-matter vs yamljs

  • front-matter:

    Choose front-matter if you need a lightweight and straightforward library that focuses solely on parsing front matter from Markdown files without any additional dependencies or complexity.

  • gray-matter:

    Opt for gray-matter if you want a more versatile solution that can handle both YAML and JSON front matter, and provides additional features like custom delimiters and the ability to parse Markdown content along with the front matter.

  • js-yaml:

    Select js-yaml if your primary need is robust YAML parsing and stringifying, especially if you require advanced YAML features like support for complex data types or custom YAML tags, and you don't specifically need front matter parsing.

  • yaml-front-matter:

    Use yaml-front-matter if you prefer a library that combines YAML parsing with front matter extraction, and you want a simple API that allows you to easily manage front matter in your Markdown files.

  • yamljs:

    Choose yamljs if you need a comprehensive YAML parser and serializer that can handle complex YAML structures, and you want the flexibility to work with YAML data beyond just front matter.

README for front-matter

front-matter

build coverage npm github

Sauce Test Status

Extract meta data (front-matter) from documents.

This modules does not do any IO (file loading or reading), only extracting and parsing front matter from strings.

This concept that was originally introduced to me through the jekyll blogging system and is pretty useful where you want to be able to easily add meta-data to content without the need for a database. YAML is extracted from the the top of a file between matching separators of "---" or "= yaml =". It will also extract YAML between a separator and "...".

Install

With npm do:

npm install front-matter

Example

So you have a file example.md:

---
title: Just hack'n
description: Nothing to see here
---

This is some text about some stuff that happened sometime ago

NOTE: As of front-matter@2.0.0 valid front matter is considered to have the starting separator on the first line.

Then you can do this:

var fs = require('fs')
  , fm = require('front-matter')

fs.readFile('./example.md', 'utf8', function(err, data){
  if (err) throw err

  var content = fm(data)

  console.log(content)
})

And end up with an object like this:

{
    attributes: {
        title: 'Just hack\'n',
        description: 'Nothing to see here'
    },
    body: 'This is some text about some stuff that happened sometime ago',
    bodyBegin: 6,
    frontmatter: 'title: Just hack\'n\ndescription: Nothing to see here'
}

Methods

var fm = require('front-matter')

fm(string, { allowUnsafe: false })

Return a content object with two properties:

  • content.attributes contains the extracted yaml attributes in json form
  • content.body contains the string contents below the yaml separators
  • content.bodyBegin contains the line number the body contents begins at
  • content.frontmatter contains the original yaml string contents

NOTE: By default fm() uses ys-yaml's safeLoad unless you set allowUnsafe in the options object to true.

fm.test(string)

Check if a string contains a front matter header of "---" or "= yaml =". Primarily used internally but is useful outside of the module.

Returns true or false

    fm.test(string) #=> true || false

Contributing

front-matter is an OPEN Source Project so please help out by reporting bugs or forking and opening pull requests when possible.

standard

All code is linted/formatted using standard style, any non-conforming code can be automatically formatted using the the fmt make task: make fmt.

Maintainers

Contributors

This module is awesome because of all the folks who submitted pull requests:

CHANGELOG

3.0.0

  • CI only tests Node versions >= v6 (drops v4, and v5)

LICENSE (MIT)

Copyright (c) Jason Campbell ("Author")

Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.