1.0.0 • Published 5 months ago

remark-frontmatter-validator v1.0.0

Weekly downloads
37
License
MIT
Repository
github
Last release
5 months ago

remark-frontmatter-validator Test

A remark plugin to validate the values in your frontmatter.

Install

Install the plugin and remark-frontmatter:

npm install remark-frontmatter-validator remark-frontmatter --save-dev

Add the plugin to your .remarkrc and define the shape of your frontmatter:

{
  "plugins": [
    ["remark-frontmatter", ["yaml"]],
    [
      "remark-frontmatter-validator",
      [
        2,
        {
          "title": {
            "type": "string",
            "required": true
          },
          "image": {
            "type": "string",
            "required": true
          },
          "tags": {
            "type": "array"
          }
        }
      ]
    ]
  ]
}

Options

The plugin accepts an object that describes the fields in your frontmatter. Each key of the object should match a key in your frontmatter. The key's value is an object that describes the value.

In the example below, title is a required value and it must be a string:

"title": {
  "type": "string",
  "required": true
}

Field object

The key's value is an object that describes the value.

  • type - The value's type: string, object, number, boolean, array, or date.
  • maxLength - The value's maximum length.
  • oneOf - An array of options that the value must match.
  • match - A regular expression that the value must match.
  • required - Set the value as true if it is required.

In the example below, there can be up to 2 tags and it can match "writing", "code", or "notes":

"tags": {
  "type": "array",
  "maxLength": 2,
  "oneOf": ["writing", "code", "notes"]
}

In the example below, the image path must match the regex (where 2020-10-31-cat.png is valid and cat.gif is invalid) and it is required:

"image": {
  "match": "^\\d\\d\\d\\d-\\d\\d-\\d\\d-.*.(png|jpg)",
  "type": "string",
  "required": true
},
1.0.0

5 months ago

0.3.0

4 years ago

0.2.1

4 years ago

0.2.0

4 years ago

0.3.2

4 years ago

0.4.0

4 years ago

0.3.1

4 years ago

0.3.3

4 years ago

0.1.1

4 years ago

0.1.0

4 years ago