1.1.0 • Published 4 months ago
matter-yaml v1.1.0
matter-yaml
Archetype: Node.js package
matter-yaml is a YAML front-matter parser and combiner. Minimal and perfect.
Details
- Extract front matter data and returns the meta and content separated.
- Validate front matter structure before parsing.
- Serialize front matter back into a structured document.
Install
npm install matter-yaml
Usage
import { parse, serialize, validate } from 'matter-yaml';
const text = `---
title: "Hello World"
tags:
- yaml
- front-matter
published: true
---
This is the document content.`;
const result = parse(text);
console.log(result);
console.log(validate(text)); // true
const output = serialize(
{ title: 'New Title', draft: false },
'Updated content.',
);
console.log(output);
📜 API Reference
parse(text: string): { data: object, content: string }
Parses a document with front matter.
Parameters:
Parameter | Type | Description |
---|---|---|
text | string | The document containing front matter and text. |
Returns:
An object containing:
data
→ Parsed front matter.content
→ The remaining document content.
serialize(data: object, content: string): string
Converts an object into front matter format.
Parameters:
Parameter | Type | Description |
---|---|---|
data | object | The structured front matter data. |
content | string | The document content. |
Returns:
A string formatted as front matter with the given content.
validate(text: string): boolean
Checks if front matter is correctly formatted and parsable.
Parameters:
Parameter | Type | Description |
---|---|---|
text | string | The document to validate. |
Returns:
true
if valid.false
if invalid.
Related Links
I provide matter parsers for JSON
and TOML
also
License
Apache-2.0 License. See LICENSE for details.