You're Invited:Meet the Socket Team at BlackHat and DEF CON in Las Vegas, Aug 4-6.RSVP
Socket
Book a DemoInstallSign in
Socket

@github-docs/frontmatter

Package Overview
Dependencies
Maintainers
2
Versions
6
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@github-docs/frontmatter

Parse and validate YAML frontmatter

1.0.0
Source
npmnpm
Version published
Weekly downloads
790
7.34%
Maintainers
2
Weekly downloads
 
Created
Source

@github-docs/frontmatter

Parse and validate YAML frontmatter

This is a frontmatter parser built on gray-matter that supports optional frontmatter validation using a revalidator JSON schema.

Installation

This is a Node.js module available through the npm registry.

npm install @github-docs/frontmatter

Usage

const frontmatter = require('@github-docs/frontmatter')

const schema = {
  properties: {
    title: {
      type: 'string',
      required: true
    },
    meaning_of_life: {
      type: 'number',
      minimum: 40,
      maximum: 50
    }
  }
}

const markdown = `---
title: Hello, World
meaning_of_life: 42
---

I am content.
`

const { data, content, errors } = frontmatter(markdown)

API

This module exports a single function:

frontmatter(markdown, [options])

  • markdown String (required) - the contents of a markdown file that includes YAML frontmatter.
  • options Object (optional)
    • schema Object - A revalidator JSON schema.
    • filepath String - The name of the file being parsed. Useful for debugging when errors occur.
    • validateKeyNames Boolean - If true, checks that all keys are specified as schema properties. Defaults to false
    • validateKeyOrder Boolean - If true, checks that all keys are in the same order they appear in the schema. Defaults to false

License

MIT

FAQs

Package last updated on 10 Sep 2019

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