# yamatter

> Transform YAML front-matter data from the command line

Latest version **0.6.0** (published 2024-08-15) · MIT license · 0 weekly downloads

## Install

```sh
npm install yamatter
pnpm add yamatter
yarn add yamatter
bun add yamatter
```

## Health

**Score 15/100 (F)** — status: abandoned.

Positive: no vulnerabilities.

Warnings: low downloads; no types; no esm support; pre 1.0.

Negative: abandoned; low maintenance score.

## Facts

| | |
|---|---|
| Version | 0.6.0 |
| Published | 2024-08-15 |
| First published | 2023-02-13 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | none |
| Module format | CommonJS |
| Dependencies | 0 |
| Known vulnerabilities | 0 |
| Install scripts | no |
| GitHub stars | 7 |
| Author | Dan Burzo |
| Maintainers | danburzo |
| Keywords | yaml, markdown, frontmatter |

## Links

- npm: https://www.npmjs.com/package/yamatter
- Repository: https://github.com/danburzo/yamatter
- Homepage: https://github.com/danburzo/yamatter#readme
- Issues: https://github.com/danburzo/yamatter/issues
- npm.io page: https://npm.io/package/yamatter

## Alternatives

- [monaco-yaml](https://npm.io/package/monaco-yaml.md) — 420.1K weekly downloads
- [@crewx/workflow](https://npm.io/package/@crewx/workflow.md) — 3.1K weekly downloads
- [yaml-cat](https://npm.io/package/yaml-cat.md) — 38 weekly downloads
- [nunjucks-in-yaml](https://npm.io/package/nunjucks-in-yaml.md) — 9 weekly downloads
- [shopify-symlinks](https://npm.io/package/shopify-symlinks.md) — 3 weekly downloads

## Recent versions

- 0.6.0 (latest) — 2024-08-15
- 0.5.0 — 2024-06-27
- 0.4.0 — 2023-02-14
- 0.3.0 — 2023-02-14
- 0.2.3 — 2023-02-13
- 0.2.2 — 2023-02-13
- 0.2.1 — 2023-02-13
- 0.2.0 — 2023-02-13
- 0.1.1 — 2023-02-13
- 0.1.0 — 2023-02-13
- 0.0.1 — 2023-02-13

## README

Yamatter is a command-line tool to inspect and transform YAML front-matter data  using [`js-yaml`](https://github.com/nodeca/js-yaml).

## Installation

Install `yamatter` globally with `npm`:

```bash
npm install -g yamatter
```

Run `yamatter` without installing it with `npx`:

```bash
npx yamatter
```

## Usage

```bash
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`](https://github.com/mrmlnc/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:

```bash
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.

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

__to-uppercase.js__:

```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`](https://github.com/mrmlnc/fast-glob) directly. These options are passed by default:

```json
{
	"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`](https://github.com/nodeca/js-yaml)’s `dump()` method. These options are passed by default:

```json
{
	"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

* [mikefarah/yq](https://github.com/mikefarah/yq)
* [dbohdan/structured-text-tools](https://github.com/dbohdan/structured-text-tools)

---
_Source: https://npm.io/package/yamatter · Machine-readable twin of the npm.io package page. Health data is recomputed on every publish._
