npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2026 – Pkg Stats / Ryan Hefner

yaml-fromat

v0.2.1

Published

Read and write YAML front matter

Readme

yaml-fromat

Read and write YAML front matter. JS library (and eventually CLI).

Installation

Install the library in your project using your package manager of choice:

  • npm i yaml-fromat
  • yarn add yaml-fromat
  • pnpm add yaml-fromat

Install the CLI globally (I recommend using Volta as your Node manager):

API

Reading

readFile(file)

  • file Path to the file for reading

Returns a Promise that resolves to a JSON object containing the front matter in the input file. This includes the non-front-matter contents (the rest of the file) in _contents.

The YAML front matter should be the first thing in the file, with no blank lines before it.

const yamlFM = require('yaml-fromat');

fs.writeFileSync('file.md',
`---
key: value
---

Some other contents`
);
yamlFM.readFile('some/file.md').then(console.log);

// result:
// {
//   key: 'value',
//   _contents: '\nSome other contents'
// }

readString(string)

  • string The string to read

Returns a Promise that resolves to a JSON object containing the front matter in the input string. This includes the non-front-matter contents (the rest of the string) in _contents.

The YAML front matter should be the first thing in the string, with no blank lines before it.

const yamlFM = require('yaml-fromat');

yamlFM.readString(
`---
key: value
---

Some other contents`
).then(console.log);

// result:
// {
//   key: 'value',
//   _contents: '\nSome other contents'
// }

Errors

Error parsing YAML in front matter if there was a parsing error

Top level should be a key/value map if the YAML is not a YAML Map at the top level

Non-terminated YAML front matter if the YAML front matter does not have a closing --- line

Writing

These attempt to:

  • Preserve blank lines and comments in the YAML
  • Maintain the order of existing data

Current limitations, to be addressed:

writeFile(file, inputYaml)

  • file Path to the file to read then write
  • inputYaml YAML to add to the file

Returns a Promise that resolves when the input YAML has been combined with the existing YAML in the input file. New data will be appended to the existing front matter. Changes to existing keys will be made in-place. If input file does not contain front matter, a new block of YAML front matter will be added.

The YAML front matter should be the first thing in the file, with no blank lines before it.

const yamlFM = require('yaml-fromat');

fs.writeFileSync('file.md',
`---
key: value
---

Some other contents`
);
yamlFM.writeFile('file.md', 'foo: bar').then(console.log);

// file.md now contains:
// ---
// key: value
// foo: bar
// ---
//
// Some other contents`

writeString(inputString, inputYaml)

  • inputString The input string, possibly containing YAML front matter
  • inputYaml YAML to add to the input string

Returns a Promise that resolves to a string where the input YAML has been combined with the existing front matter from the input string. New data will be appended to the existing front matter. Changes to existing keys will be made in-place. If input string does not contain front matter, a new block of YAML front matter will be added.

Examples

Adding new data

const yamlFM = require('yaml-fromat');

yamlFM.writeString(
`---
foo: bar
---

Some other things`,
'more: data'
).then(console.log);

// ---
// foo: bar
// more: data
// ---
//
// Some other things

Changing existing data

const yamlFM = require('yaml-fromat');

yamlFM.writeString(
`---
foo: bar
---

Other contents`,
'foo: baz'
).then(console.log);

// ---
// foo: baz
// ---
//
// Other contents

Errors

Non-terminated YAML front matter if the YAML front matter does not have a closing --- line

Error parsing YAML in front matter if there was a parsing error

Error parsing input YAML if the input YAML cannot be parsed for some reason

Cannot add non-map items at the top level if the input YAML is not a Map (so this can't add key/value items)

CLI

Not yet implemented

Development

Run the tests with yarn run test or yarn run test --watch

Check code coverage with yarn run coverage

Check lint errors with yarn run lint