# gray-matter — card for AI agents

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

Category: Markdown, editors and content · npm package `gray-matter` · latest version 4.0.3 (checked 2026-11-01)
Install: `npm install gray-matter`
License: MIT (permissive)

In your own product (generator, app, hosted service): **yes**. Permissive license: ship it inside your own product, closed or open source, and keep its license and copyright notice.

## Rules for AI agents (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.

## What it is
- gray-matter is a Node.js library that parses front matter, the metadata block at the top of a Markdown or HTML file. The README says it parses "YAML front matter by default", and also supports JSON, TOML and Coffee front matter, with options to set custom delimiters. It is MIT licensed, and the GitHub repository was created in 2014.
- You pass it a string and it returns a `file` object. `file.data` holds the parsed metadata and `file.content` holds the rest of the input with the front matter stripped. Extra calls cover the other common jobs: `matter.read` loads a file from disk, `matter.stringify` writes data back as front matter, and `matter.test` checks whether a string has front matter at all.
- It suits projects that keep content as files with metadata at the top, such as blogs and static sites. The repository description lists static site generators and documentation tools among its users.

## Caveats
- Only YAML and JSON stringify out of the box: Writing TOML or other formats back requires an engine that supplies its own `stringify` method.
- Excerpt separator defaults to `---`: With `excerpt: true`, the excerpt ends at the next `---`. The excerpt also stays inside `content`. Set `excerpt_separator` if your body uses `---` for other things.
- `matter.read` is synchronous: The file helper blocks while it reads from disk. For async code, read the file yourself and pass the string to `matter()`.
- README mixes old and new option names: The README marks `delims`, `lang` and `parsers` as deprecated. Even so, its own delimiters example still passes `delims`. Use `delimiters`, `language` and `engines` instead.
- Breaking changes in v3.0: The README points to the changelog for breaking changes made in v3.0. Older code samples may not match the current API.

## Numbers (AgentGid data)
- Gid Score: 66.7 (#565 of all tools, 26 of 149 in its category)
- Used in 98 public projects set up for AI coding agents (1.6%)
- Downloads last week: 15,377,146 (as of 2026-11-24), +38.4% over 4 weeks
- GitHub stars: 4,498 (as of 2026-11-24)
- Last push: 2025-06-14

## Often used with
Next.js 56.1%, remark-gfm 40.8%, TypeScript 94.9%, React 65.3%, react-markdown 30.6%, clsx 48.0%

## Links
- AgentGid page: https://agentgid.com/tools/gray-matter/
- Homepage: https://github.com/jonschlinkert/gray-matter
- Repository: https://github.com/jonschlinkert/gray-matter
- Source: https://github.com/jonschlinkert/gray-matter#readme
- Source: https://github.com/jonschlinkert/gray-matter
- Source: https://www.npmjs.com/package/gray-matter

---
AgentGid's catalog is curated: every entry was checked against the maker's official pages (registry, repository, license and pricing pages) on the date shown; a license value shows the quote it stands on wherever AgentGid has one. Usage numbers come from AgentGid's own scan of public repositories set up for AI coding agents. Claims by makers are reported, not tested by AgentGid.
