# yaml-cat

> Concatenate YAML front matter from several files into one object

Latest version **0.4.2** (published 2022-11-20) · GPL-3.0 license · 38 weekly downloads

## Install

```sh
npm install yaml-cat
pnpm add yaml-cat
yarn add yaml-cat
bun add yaml-cat
```

Provides the command `yaml-cat`.

## Health

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

Positive: no vulnerabilities.

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

Negative: abandoned; declining downloads.

## Facts

| | |
|---|---|
| Version | 0.4.2 |
| Published | 2022-11-20 |
| First published | 2015-03-11 |
| Weekly downloads | 38 |
| License | GPL-3.0 |
| TypeScript types | none |
| Module format | CommonJS |
| Dependencies | 5 |
| Unpacked size | 45.9 KB |
| Known vulnerabilities | 0 |
| Install scripts | no |
| GitHub stars | 7 |
| Author | Neil Freeman |
| Maintainers | fitnr |
| Keywords | concatenate, command line utility, data processing, yaml, yaml front matter, yfm |

## Links

- npm: https://www.npmjs.com/package/yaml-cat
- Repository: https://github.com/fitnr/yaml-cat
- Issues: https://github.com/fitnr/yaml-cat/issues
- npm.io page: https://npm.io/package/yaml-cat

## Dependencies (5)

- [merge](https://npm.io/package/merge.md) ^2.1.1
- [js-yaml](https://npm.io/package/js-yaml.md) ^3.13.1
- [commander](https://npm.io/package/commander.md) ^2.9.0
- [glob-concat](https://npm.io/package/glob-concat.md) ^1.0.1
- [front-matter](https://npm.io/package/front-matter.md) ^3.1.0

## 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
- [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
- [mmt-mcp](https://npm.io/package/mmt-mcp.md) — 0 weekly downloads

## Recent versions

- 0.4.2 (latest) — 2022-11-20
- 0.4.1 — 2021-05-15
- 0.4.0 — 2020-04-05
- 0.3.2 — 2015-12-31
- 0.3.1 — 2015-11-07
- 0.3.0 — 2015-11-07
- 0.2.0 — 2015-03-11

## README

# yaml-cat

Concatenate the YAML and YAML front matter of files.

## Usage

Given two files, `pets/cats.yaml` and `pets/dogs.yaml` that look like this:

````yaml
---
# pets/cats.yaml
sound: meow
lives: 9
````
````yaml
# pets/dogs.yaml
---
sound: bark
---
````

Do this on the command line:

````bash
yaml-cat 'pets/*.yaml'
````
````yaml
---
pets/cats.yaml:
    sound: meow
    lives: 9
pets/dogs.yaml
    sound: bark
---
````

Or, do this in node:

````javascript
> var yamlCat = require('yaml-cat');
> var result = yamlCat('pets/*.yaml');
{
    'pets/cats.yaml': {
        sound: 'meow',
        lives: 9
    },
    'pets/dogs.yaml': {
        sound: 'bark',
    }
}
````

## Usage

````bash
  Usage: yaml-cat [options] <file ...>

  Concatenate the YAML front matter of several files

    -V, --version             output the version number
    -o, --output <file>       Save result to file
    -f, --format <format>     Output format (YAML or JSON)
    -C, --cwd <path>          Output with keys relative to this path
    -i, --indent <indent>     Number of spaces to indent
    -m, --merge               Merge YFM into a single object
    -e, --extend <key>        Put result under a key with this name
    -n, --no-ext              Strip the file extension from keys
    -a, --array               Return an array (list) of objects
````

Example:
````
yaml-cat pets/cats.yaml pets/dogs.yaml -o result.yaml
$ cat result.yaml
````
````yaml
---
pets/cats.yaml:
    sound: meow
    lives: 9
pets/dogs.yaml:
    sound: bark
---
````

## Command line options

### cwd
`yaml-cat` uses the filepaths of input files as keys in the output. With `--cwd`, the key will be relative to the given directory.
````
yaml-cat --cwd pets pets/cats.yaml pets/dogs.yaml
````
````yaml
---
cats.yaml:
    sound: meow
    lives: 9
dogs.yaml:
    sound: bark
---
````

### no-ext

Strip the extension from files in the given key. Use with `--cwd` to get just the file name-part as the key.

````
yaml-cat --cwd pets --no-ext pets/cats.yaml pets/dogs.yaml
````
````yaml
---
cats:
    sound: meow
    lives: 9
dogs:
    sound: bark
````

### extend
Pass a string to `---extend` to place the entire result under that key.
````
yaml-cat --extent pets --cwd pets pets/cats.yaml pets/dogs.yaml
````
````yaml
---
pets:
    cats.yaml:
        sound: meow
        lives: 9
    dogs.yaml:
        sound: bark
````

### format
Choose output in JSON or YAML.
````
yaml-cat --format json pets/cats.yaml pets/dogs.yaml
````
````json
{
    "pets/cats.yaml": {...},
    "pets/dogs.yaml": {...}
}
````

(Note that JSON output is prettified here for readability. The actual function does not prettify.)

### merge
Merge all the yaml front matter into a single object. Overlapping keys will be given the value of the last given file, which could be unpredictible if globs are used.
````
yaml-cat --merge pets/cats.yaml pets/dogs.yaml
````
````yaml
---
sound: bark
lives: 9
````

Obviously that isn't that effective in this example, but maybe your data isn't as contrived as it is here.

The `--merge` and `--extend` options may seem similar, but they have a very different effect. Running them together will merge the entire result AND place it under a single key.
````
yaml-cat --extend pets --merge pets/cats.yaml pets/dogs.yaml
````
````yaml
---
pets:
    sound: bark
    lives: 9
````

### delims

The default delimiter is `---`, and by default `yaml-cat` only puts one at the start of YAML. If you want an ending delimeter, pass a comma-separated list of two delimters. Does nothing when `--format` equals `json`.
````
yaml-cat --delims +++,+++ foo/*.yaml foo/bar/*.yaml
````
````
+++
foo/foo.yaml:
    ...
foo/bar/bar.yaml:
    ...
+++
````

### array

Use this option to return an array of objects:
````
yaml-cat --array pets/cats.yaml pets/dogs.yaml
````
````yaml
-
    sound: meow
    lives: 9
-
    sound: bark
````

````
yaml-cat --format json --array pets/cats.yaml pets/dogs.yaml
````
````json
[
    {
        "sound": "meow",
        "lives": 9
    },
    {
        "sound": "bark"
    }
]
````

### API

yamlcat(pattern, options)

* pattern: A file, list of files, or [glob](https://www.npmjs.com/package/glob).
* options: A javascript object. The default looks like this:

````javascript

var opts = {
    // (String) The keys in the output are the input filenames. Interpret them relative to this
    // ignored if 'merge' is set
    cwd: '.',

    // The start and end delimiter for the output YAML
    delims: ['---', '---'],

    // (string) return format
    // if empty, function returns a Javascript object
    // valid formats: 'yaml', 'json'
    format: null,

    // (Integer) number of spaces to indent
    indent: 4,

    // Object to extend with the result
    extend: {},

    // (Boolean) whether to merge all the front matter into a single object
    merge: false,
}
````

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