Registry / devops / yaml-fmt

yaml-fmt

JSON →
library0.0.8jsnpmunverified

A configurable YAML formatter for Node.js (CLI & API) that sorts object keys and array values in YAML files. Currently at v0.0.8, with infrequent releases. Key differentiators include support for wildcard targets, property-specific sort configurations, and JSON-based config files. Provides ESM and CJS support, ships TypeScript types, and can be used as a CLI tool via `yaml-fmt fmt` or programmatically. Alternatives like prettier or yq offer broader functionality but less YAML-specific sorting control.

npm install yaml-fmt
INSTALL
IMPORT
SIG · YAML-FMT
Y
yaml-fmt
devopsjavascriptv0.0.8
harness data pending
Install & Compatibility
Where this runs

No compatibility data collected yet for this library.

Code
Verified usage

Verified import paths — ran on the pinned version, not inferred.

format
import { format } from 'yaml-fmt'
const format = require('yaml-fmt')
ESM-only since v0.0.8; CommonJS require() not supported.
YamlFmtConfig
import type { YamlFmtConfig } from 'yaml-fmt'
TypeScript type only, use as import type.
yamlFmt (default)
import yamlFmt from 'yaml-fmt'
const yamlFmt = require('yaml-fmt').default
Default export is a function; do not use require with .default.
cli
import { cli } from 'yaml-fmt'
import cli from 'yaml-fmt'
cli is a named export, not default.

Demonstrates sorting all top-level keys alphabetically with indent 2.

import { format } from 'yaml-fmt'; import YAML from 'js-yaml'; const input = `name: Bob age: 30 `; const output = format(input, { indent: 2, all: true }); console.log(output); // age: 30 // name: Bob
Debug
Known issues
breakingv0.0.8 drops CommonJS support; only ESM imports work.
fix
Switch to import statements; use dynamic import if needed.
affects: >=0.0.8
gotchaArray sorting requires explicit configuration; not applied by `all: true`.
fix
Define array sort targets in config (e.g., "properties.enumValue.enum.[]": true).
affects: *
gotchaWildcard targets only match same-depth properties; nested paths not supported.
fix
Use explicit paths for deep nesting.
affects: *
deprecatedConfig file key 'root' is deprecated in favor of 'targets'.
fix
Move root sort config under 'targets' as 'root': true or array.
affects: >=0.0.6
Errors
Common errors & fixes
Cannot find module 'yaml-fmt'
Missing npm install or incompatible Node.js version.
fix
Run 'npm install yaml-fmt' and ensure Node.js >=12 (ESM support).
TypeError: format is not a function
Incorrect import (CommonJS require or wrong named import).
fix
Use import { format } from 'yaml-fmt' (ESM only).
yaml-fmt: error: unknown option `--all'
Using --all flag without value or in older version.
fix
Use -a (short flag) or ensure version >=0.0.6.
Upgrade
Version history
0.0.8latest on npm
Audit
Dependencies
js-yamlrequiredYAML parsing and serialization
yargsoptionalCLI argument parsing
Agent activity
12 hits · last 30 days
node
12
Resources
yaml-fmt — npm install yaml-fmt · libregistry