Front Matter Format Support
- front-matter:
front-mattersupports only YAML front matter, making it simple but limited in terms of format flexibility. - gray-matter:
gray-mattersupports multiple formats, including YAML, JSON, and TOML, providing much greater flexibility for different use cases. - remark-frontmatter:
remark-frontmatteris designed to work with any front matter format, but it is primarily used in conjunction withremarkfor Markdown, allowing for flexibility in format choice. - yaml-front-matter:
yaml-front-mattersupports only YAML front matter, similar tofront-matter, but is optimized for YAML parsing.
Content Parsing
- front-matter:
front-matterextracts front matter and content but does not provide advanced content parsing features. - gray-matter:
gray-matterprovides built-in support for extracting and parsing content separately from the front matter, making it more versatile. - remark-frontmatter:
remark-frontmatterfocuses on front matter parsing within Markdown files and works alongsideremarkfor content processing, but does not parse content itself. - yaml-front-matter:
yaml-front-matterextracts front matter and content but does not offer advanced content parsing capabilities.
Ease of Use
- front-matter:
front-matteris very easy to use with a simple API for parsing front matter from files. - gray-matter:
gray-matteris also user-friendly, with a clear API that supports more complex use cases due to its additional features. - remark-frontmatter:
remark-frontmatteris easy to use for those familiar with theremarkecosystem, but may have a learning curve for new users. - yaml-front-matter:
yaml-front-matteroffers a straightforward API for parsing YAML front matter, making it easy to integrate into projects.
Performance
- front-matter:
front-matteris lightweight and performs well for parsing front matter, with minimal overhead. - gray-matter:
gray-matteris slightly heavier due to its additional features, but still performs efficiently for most use cases. - remark-frontmatter:
remark-frontmatterperformance depends on theremarkprocessing pipeline, but it is generally efficient for handling front matter in Markdown. - yaml-front-matter:
yaml-front-matteris lightweight and performs well for parsing YAML front matter.
Code Example
- front-matter:
Example of using
front-matterconst frontMatter = require('front-matter'); const data = frontMatter('--- title: My Post --- Hello, world!'); console.log(data.attributes); // { title: 'My Post' } console.log(data.body); // 'Hello, world!' - gray-matter:
Example of using
gray-matterconst grayMatter = require('gray-matter'); const { data, content } = grayMatter('--- title: My Post --- Hello, world!'); console.log(data); // { title: 'My Post' } console.log(content); // 'Hello, world!' - remark-frontmatter:
Example of using
remark-frontmatterconst remark = require('remark'); const frontmatter = require('remark-frontmatter'); const file = remark() .use(frontmatter) .processSync('--- title: My Post --- Hello, world!'); console.log(file.contents); - yaml-front-matter:
Example of using
yaml-front-matterconst yamlFront = require('yaml-front-matter'); const data = yamlFront.load('--- title: My Post --- Hello, world!'); console.log(data); // { title: 'My Post' }