Skip to content
Agents tracked: 506 Releases (7d): 634 Agent status: 3 with issuesSince last limit reset: Claude 15d · Codex 0d For AI agents: Markdown Updated Nov 26, 2026

gray-matter

Parser extracting YAML/JSON front matter from markdown and text files.

Markdown, editors and contentNPM

GitHubWebsite

1. License

License from npm.

github.com/jonschlinkert/gray-matter

From the package registry and GitHub, checked daily. Tap a verdict to see its source.How we checkedReport an error

What gray-matter does

gray-matter does one small job: it splits a file into a <code>data</code> object and a <code>content</code> string, without regex, and can write the data back out as front matter.

gray-matter popularity

67 / 100
Gid Score, #565 overall
15.4M
downloads a week, npm
4,498
GitHub stars
98
agent projects use it
gray-matter: downloads per weeknpm, gray-matter 15,377,146
gray-matter: GitHub starsjonschlinkert/gray-matter 4,498

Gid Score measures public popularity and activity, not quality. How the Gid Score is calculated

How gray-matter is used

  • gray-matter is a dependency in 98 of the 6,258 public GitHub projects set up for AI coding agents that we scanned (2.0% of the 4,867 JavaScript/TypeScript ones), #5 of 149 in markdown, editors and content.
  • Counting the projects our scan samples by dependency (Solana 3,067, Ethereum and EVM 1,774, 3D and games 3,130, agent frameworks and SDKs 13,750), it appears in 247; those are left out of every share on this page.
  • Projects that use it most often also use Next.js (56.1%), remark-gfm (40.8%), TypeScript (94.9%).

By coding agent

69 projects, 2.1%
43 projects, 1.8%
40 projects, 1.3%
13 projects, 2.7%
10 projects, 2.9%
10 projects, 2.1%
6 projects, 2.2%

Often used with

In 56.1% of its projects
In 40.8% of its projects
In 94.9% of its projects
In 65.3% of its projects
In 30.6% of its projects
In 48.0% of its projects
In 61.2% of its projects
In 48.0% of its projects

gray-matter in practice

Strengths

One call, two fields

The main function takes a string and returns an object. Most code only needs <code>data</code> and <code>content</code> from it.

Not fooled by example front matter in code blocks

The maintainers chose not to parse with regex. They list fenced code blocks that contain sample YAML front matter as a case that other parsers get wrong.

Writes front matter back out

<code>matter.stringify</code> turns an object back into a front matter block and puts it in front of the content. The README notes this is useful for linting and for updating properties.

Language picked from the opening fence

If you write <code>---toml</code> as the first delimiter, gray-matter uses the TOML engine for that file without any options being set.

Watch out for

Only YAML and JSON stringify out of the box

Writing TOML or other formats back requires an engine that supplies its own <code>stringify</code> method.

Excerpt separator defaults to <code>---</code>

With <code>excerpt: true</code>, the excerpt ends at the next <code>---</code>. The excerpt also stays inside <code>content</code>. Set <code>excerpt_separator</code> if your body uses <code>---</code> for other things.

<code>matter.read</code> is synchronous

The file helper blocks while it reads from disk. For async code, read the file yourself and pass the string to <code>matter()</code>.

Parse a string with front matter

const matter = require('gray-matter');
console.log(matter('---\ntitle: Home\n---\nOther stuff'));
//=> { data: { title: 'Home'}, content: 'Other stuff' }

More about gray-matter

Funding
  • GitHub Sponsors: https://github.com/jonschlinkert
  • 16 GitHub sponsors

See all

Packages around it
  • next: React framework
  • remark-gfm: GitHub Markdown for remark
  • typescript: Typed JavaScript
  • react: UI library
  • clsx: className helper
  • react-markdown: Markdown to React
More in Markdown, editors and content

Alternatives

gray-matter This page

MITGid 6715.4M/wk

Compare gray-matter with another tool

Get started

Install it.

npm install gray-matter

Rules for your agent

Paste into AGENTS.md or CLAUDE.md
## gray-matter
- Import with `const matter = require('gray-matter')`, or in TypeScript with `import * as matter from 'gray-matter'`.
- Read metadata from `file.data` and the body from `file.content`. `orig`, `language`, `matter` and `stringify` are non-enumerable debug properties.
- Use `delimiters`, `language` and `engines`. Do not use the deprecated `delims`, `lang` and `parsers`.
- To update metadata, call `matter.stringify(content, data)`. Only YAML and JSON stringify by default; other formats need an engine with a `stringify` method.
- `matter.read(filepath)` is synchronous. In async code, read the file yourself and pass the string to `matter()`.
- When using `excerpt: true`, set `excerpt_separator` if the body may contain `---`. The excerpt is not removed from `content`.
- Check `file.isEmpty` or call `matter.test(str)` before relying on `data` fields.