jonschlinkert / gray-matter

Smarter YAML front matter parser, used by metalsmith, Gatsby, Netlify, Assemble, mapbox-gl, phenomic, vuejs vitepress, TinaCMS, Shopify Polaris, Ant Design, Astro, hashicorp, garden, slidev, saber, sourcegraph, and many others. Simple to use, and battle tested. Parses YAML by default but can also parse JSON Front Matter, Coffee Front Matter, TOML Front Matter, and has support for custom parsers. Please follow gray-matter's author: https://github.com/jonschlinkert

Home Page:https://github.com/jonschlinkert

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Identical calls to `matter` should produce the same result

movermeyer opened this issue · comments

Identical, successive calls to matter return different results.

Example code:

const input = `---
foo: bar
---
Tada!`;

const parsed = matter(contents);
const parsed_again = matter(contents);
console.log(parsed.language) // => yaml
console.log(parsed_again.language) // => undefined

I understand from this comment that it's caching based on the input string, and I can cache bust by passing in an empty options hash as a workaround.

In this case, I'm fine with it caching (even though it was unexpected and IMO should at least be documented). However, the cache should cache the resulting object exactly, so that identical calls to matter always return the same result.