Archetype: Node.js package
matter-toml is a TOML front-matter parser and combiner. Minimal and perfect.
- 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.
npm install matter-toml
import { parse, serialize, validate } from 'matter-toml';
const text = `+++
title = "Hello World"
tags = ["toml", "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);
Parses a document with front matter.
Parameter | Type | Description |
---|---|---|
text |
string | The document containing front matter and text. |
An object containing:
-
data
→ Parsed front matter. -
content
→ The remaining document content.
Converts an object into front matter format.
Parameter | Type | Description |
---|---|---|
data |
object | The structured front matter data. |
content |
string | The document content. |
A string formatted as front matter with the given content.
Checks if front matter is correctly formatted and parsable.
Parameter | Type | Description |
---|---|---|
text |
string | The document to validate. |
-
true
if valid. -
false
if invalid.
I provide matter parsers for YAML
and JSON
also
Apache-2.0 License. See LICENSE for details.