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 🙏

© 2024 – Pkg Stats / Ryan Hefner

yamatter

v0.6.0

Published

Transform YAML front-matter data from the command line

Downloads

41

Readme

Yamatter is a command-line tool to inspect and transform YAML front-matter data using js-yaml.

Installation

Install yamatter globally with npm:

npm install -g yamatter

Run yamatter without installing it with npx:

npx yamatter

Usage

yamatter [OPTIONS] [PATTERN ...]

Operands

The yamatter command accepts one or more glob patterns to match the files from which to read front-matter data.

The patterns are expanded by fast-glob. In order for the glob patterns to be expanded with fast-glob and not the shell that runs the command (e.g. sh, bash, zsh), make sure pass them enclosed in quotes:

yamatter 'content/**/*.md' 'notes/*.md'

yamatter looks for lines beginning with three or more hyphens (---) as the delimiter for front-matter data. Any matching files without front-matter data delimiters are ignored.

By default, yamatter ignores files matched by patterns inside .gitignore, if it finds one in the current working directory. It does not look for other .gitignore files neither up, nor down, the file system hierarchy. You can disable the ignore behavior with the --no-ignore flag.

Symbolic links (symlinks) are not followed. This helps avoid accidentally processing files outside the current working directory.

Options

--no-ignore

Don’t ignore files based on patterns found in .gitignore.

--silent

Don’t output to the standard output.

--no-filename

Don’t output filenames to the standard output.

--json

When outputting to the standard output, serialize the data as JSON instead of YAML.

-t <file>, --transform=<file>

Point to a JavaScript module, relative to the current working directory, that performs a transformation on the front-matter data.

The module must export a function that receives these arguments:

  • data: a JSON object corresponding to the original front-matter data
  • filepath: the source file path, relative to the current working directory

You can alter data directly, or return a new object in its place.

yamatter '*.md' -t to-uppercase.js

to-uppercase.js:

module.exports = function(data, filepath) {
	data.title = data.title.toUpperCase();
};

-w, --write

Write the result of the transformation back to the file.

Pro tip: Since this has the potential to be destructive, it is recommended that you run any yamatter --write commands in a folder that’s managed by a source control system such as Git, with any pending changes committed. This makes it easy to revert the files back to their original content.

--glob.<option>=<value>

Pass options to fast-glob directly. These options are passed by default:

{
	"followSymbolicLinks": false
}

Boolean and numeric values are cast to their respective data types. Other values are passed as strings, which limits the amount of fast-glob customization available.

--yaml.<option>=<value>

Pass serialization options to js-yaml’s dump() method. These options are passed by default:

{
	"lineWidth": -1
}

Boolean and numeric values are cast to their respective data types. Other values are passed as strings, which limits the amount of js-yaml customization available.

See also