Configurable Yaml formatter.
npm i -g yaml-fmt
yaml-fmt fmt $gropPaths... [-c [configpath]] [-i [indent]] [-a (sort all object properties)]
The configuration file is json.
- targets: Record<string, Array | true>: set target properties you want to sort value, if specifying string array, the key is priotized.
- root: Array | true: If you set boolean flag to it, sort root properties, and if specifying string array, the key is priotized.
- indent: set indent number of output yaml
- all: sort all properties before applying sort by configuration.
- lineWidth: max line width of output yaml.
{
"targets": {
"properties": ["id"]
}
}
{
"targets": {
"properties.enumValue.enum.[]": true,
}
}
target file
properties:
id:
type: 'number'
enumValue:
type: object
enum: ['b', 'c', 'a'],
sorted
properties:
id:
type: 'number'
enumValue:
type: object
enum: ['a', 'b', 'c'],
Limitation: To sort values in array needs explicit configurations.
You can specify wild card in same depth property. You need
{
"targets": {
"*.target": true
}
}
target file
a:
target:
b: 1
a: 2
b:
target:
b: 1
a: 2
sorted
a:
target:
a: 2
b: 1
b:
target:
a: 2
b: 1