# yaml-sort

> Sort YAML files alphabetically

Latest version **3.0.0** (published 2025-10-15) · MIT license · 0 weekly downloads

## Install

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

Provides the command `yaml-sort`.

## Health

**Score 55/100 (C)** — status: stable.

Positive: no vulnerabilities; has provenance; high maintenance score.

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

## Facts

| | |
|---|---|
| Version | 3.0.0 |
| Published | 2025-10-15 |
| First published | 2020-06-18 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | none |
| Module format | CommonJS |
| Node | >=20 |
| Dependencies | 2 |
| Unpacked size | 7.3 KB |
| Known vulnerabilities | 0 |
| Install scripts | no |
| Provenance | attested (GitHub Actions) |
| GitHub stars | 35 |
| Author | Damien Debin |
| Maintainers | ddebin |
| Keywords | cli, yaml, yml, sort, stream, shell |

## Links

- npm: https://www.npmjs.com/package/yaml-sort
- Repository: https://github.com/ddebin/yaml-sort
- Homepage: https://github.com/ddebin/yaml-sort#readme
- Issues: https://github.com/ddebin/yaml-sort/issues
- npm.io page: https://npm.io/package/yaml-sort

## Dependencies (2)

- [yargs](https://npm.io/package/yargs.md) ^18.0.0
- [js-yaml](https://npm.io/package/js-yaml.md) ^4.0.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
- [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

- 3.0.0 (latest) — 2025-10-15
- 2.1.0 — 2024-12-09
- 2.0.1 — 2024-11-21
- 2.0.0 — 2023-01-09
- 1.2.1 — 2022-03-14
- 1.2.0 — 2022-03-11
- 1.1.1 — 2022-03-09
- 1.1.0 — 2021-04-01
- 1.0.6 — 2021-04-01
- 1.0.4 — 2020-06-18
- 1.0.2 — 2020-06-18
- 1.0.1 — 2020-06-18
- 1.0.0 — 2020-06-18

## README

![Node.js CI](https://github.com/ddebin/yaml-sort/workflows/Node.js%20CI/badge.svg)
[![npm version](https://badge.fury.io/js/yaml-sort.svg)](https://www.npmjs.com/package/yaml-sort)

# About

`yaml-sort` sorts [YAML](https://yaml.org/) files alphabetically.

This tool is basically a tiny wrapper around [js-yaml](https://github.com/nodeca/js-yaml).

(Inspired by [yml-sorter](https://github.com/42BV/yml-sorter))

# Installation

`npm install -g yaml-sort`

# Usage

```
Usage: yaml-sort [options]

Options:
  -i, --input         The YAML file(s) which needs to be sorted  [array] [default: STDIN]
  -o, --output        The YAML file to output sorted content to  [string] [default: overwrite input file if specified or STDOUT]
  -s, --stdout        Output the proposed sort to STDOUT only  [boolean]
  -k, --check         Check if the given file(s) is already sorted  [boolean]
      --indent, --id  Indentation width (in spaces)  [number] [default: 2]
  -e, --encoding      Input encoding  [choices: "ascii", "utf8", "utf16le"] [default: "utf8"]
  -q, --quotingStyle  Strings will be quoted using this quoting style  [choices: "single", "double"] [default: "single"]
  -f, --forceQuotes   Force quotes around all strings  [boolean]
  -w, --lineWidth     Wrap line width (-1 for unlimited width)  [number] [default: 80]
  -h, --help          Show help  [boolean]
      --version       Show version number  [boolean]

Examples:
  yaml-sort --input config.yml                                 Sorts alphabetically and overwrites the file config.yml
  yaml-sort --input config.yml --lineWidth 100 --stdout        Sorts the file config.yml and output result to STDOUT wrapped to 100 columns
  yaml-sort --input config.yml --indent 4 --output sorted.yml  Indents with 4 spaces and outputs result to file sorted.yml
  cat config.yml | yaml-sort                                   Sorts alphabetically from STDIN
```

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