yamljs vs front-matter vs gray-matter vs js-yaml vs yaml-front-matter
Markdown Front Matter Parsing Libraries
yamljsfront-mattergray-matterjs-yamlyaml-front-matterSimilar 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
yamljs1,876,218887-539 years agoMIT
front-matter0694-326 years agoMIT
gray-matter04,415-705 years agoMIT
js-yaml06,561386 kB695 months agoMIT
yaml-front-matter0194-215 years agoMIT

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

Parsing Capabilities

  • 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.

  • 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.

Ease of Use

  • 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.

  • 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.

Performance

  • 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.

  • 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.

Community and Support

  • yamljs:

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

  • 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.

Extensibility

  • yamljs:

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

  • 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.

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

  • 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.

  • 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.

README for yamljs

yaml.js

Build status

Standalone JavaScript YAML 1.2 Parser & Encoder. Works under node.js and all major browsers. Also brings command line YAML/JSON conversion tools.

Mainly inspired from Symfony Yaml Component.

How to use

Import yaml.js in your html page:

<script type="text/javascript" src="yaml.js"></script>

Parse yaml string:

nativeObject = YAML.parse(yamlString);

Dump native object into yaml string:

yamlString = YAML.stringify(nativeObject[, inline /* @integer depth to start using inline notation at */[, spaces /* @integer number of spaces to use for indentation */] ]);

Load yaml file:

nativeObject = YAML.load('file.yml');

Load yaml file:

YAML.load('file.yml', function(result)
{
    nativeObject = result;
});

Use with node.js

Install module:

npm install yamljs

Use it:

YAML = require('yamljs');

// parse YAML string
nativeObject = YAML.parse(yamlString);

// Generate YAML
yamlString = YAML.stringify(nativeObject, 4);

// Load yaml file using YAML.load
nativeObject = YAML.load('myfile.yml');

Command line tools

You can enable the command line tools by installing yamljs as a global module:

npm install -g yamljs

Then, two cli commands should become available: yaml2json and json2yaml. They let you convert YAML to JSON and JSON to YAML very easily.

yaml2json

usage: yaml2json [-h] [-v] [-p] [-i INDENTATION] [-s] [-r] [-w] input

Positional arguments:
  input                 YAML file or directory containing YAML files.

Optional arguments:
  -h, --help            Show this help message and exit.
  -v, --version         Show program's version number and exit.
  -p, --pretty          Output pretty (indented) JSON.
  -i INDENTATION, --indentation INDENTATION
                        Number of space characters used to indent code (use 
                        with --pretty, default: 2).
  -s, --save            Save output inside JSON file(s) with the same name.
  -r, --recursive       If the input is a directory, also find YAML files in 
                        sub-directories recursively.
  -w, --watch           Watch for changes.

json2yaml

usage: json2yaml [-h] [-v] [-d DEPTH] [-i INDENTATION] [-s] [-r] [-w] input

Positional arguments:
  input                 JSON file or directory containing JSON files.

Optional arguments:
  -h, --help            Show this help message and exit.
  -v, --version         Show program's version number and exit.
  -d DEPTH, --depth DEPTH
                        Set minimum level of depth before generating inline 
                        YAML (default: 2).
  -i INDENTATION, --indentation INDENTATION
                        Number of space characters used to indent code 
                        (default: 2).
  -s, --save            Save output inside YML file(s) with the same name.
  -r, --recursive       If the input is a directory, also find JSON files in 
                        sub-directories recursively.
  -w, --watch           Watch for changes.

examples

# Convert YAML to JSON and output resulting JSON on the console
yaml2json myfile.yml

# Store output inside a JSON file
yaml2json myfile.yml > output.json

# Output "pretty" (indented) JSON
yaml2json myfile.yml --pretty

# Save the output inside a file called myfile.json
yaml2json myfile.yml --pretty --save

# Watch a full directory and convert any YAML file into its JSON equivalent
yaml2json mydirectory --pretty --save --recursive

# Convert JSON to YAML and store output inside a JSON file
json2yaml myfile.json > output.yml

# Output YAML that will be inlined only after 8 levels of indentation
json2yaml myfile.json --depth 8

# Save the output inside a file called myfile.json with 4 spaces for each indentation
json2yaml myfile.json --indentation 4

# Watch a full directory and convert any JSON file into its YAML equivalent
json2yaml mydirectory --pretty --save --recursive