yaml-fmt
v0.0.8
Published
Configurable Yaml formatter.
Downloads
254
Readme
Yaml
Configurable Yaml formatter.
Install
npm i -g yaml-fmt
Usage
yaml-fmt fmt $gropPaths... [-c [configpath]] [-i [indent]] [-a (sort all object properties)]
Config File
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"]
}
}
Array Sort
{
"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.
Wild Card
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