matter-toml
TypeScript icon, indicating that this package has built-in type declarations

1.0.0 • Public • Published

matter-toml

Archetype: Node.js package

matter-toml is a TOML 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-toml

Usage

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);

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 YAML and JSON also

License

Apache-2.0 License. See LICENSE for details.

Package Sidebar

Install

npm i matter-toml

Weekly Downloads

5

Version

1.0.0

License

Apache-2.0

Unpacked Size

22 kB

Total Files

5

Last publish

Collaborators

  • alexstevovich