Socket
Socket
Sign inDemoInstall

front-matter

Package Overview
Dependencies
Maintainers
1
Versions
37
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

front-matter

Extract YAML front matter from a string


Version published
Weekly downloads
1.9M
decreased by-3.5%
Maintainers
1
Weekly downloads
 
Created

What is front-matter?

The front-matter npm package is used to parse YAML or JSON front matter from strings, typically used in markdown files. This is useful for extracting metadata from content files.

What are front-matter's main functionalities?

Parsing Front Matter

This feature allows you to parse a string containing front matter and extract the metadata and content separately.

const frontMatter = require('front-matter');
const content = '---\ntitle: Hello World\ndate: 2023-10-01\n---\nThis is the content of the file.';
const parsed = frontMatter(content);
console.log(parsed.attributes); // { title: 'Hello World', date: '2023-10-01' }
console.log(parsed.body); // 'This is the content of the file.'

Custom Delimiters

This feature allows you to specify custom delimiters for the front matter, which is useful if your front matter is not delimited by the default '---'.

const frontMatter = require('front-matter');
const content = '+++\ntitle: Hello World\ndate: 2023-10-01\n+++\nThis is the content of the file.';
const options = { delimiters: '+++' };
const parsed = frontMatter(content, options);
console.log(parsed.attributes); // { title: 'Hello World', date: '2023-10-01' }
console.log(parsed.body); // 'This is the content of the file.'

Other packages similar to front-matter

Keywords

FAQs

Package last updated on 05 Oct 2018

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc