2023-11-27 16:14:31 -05:00
|
|
|
import { type MaybeRef, get } from '@vueuse/core';
|
2023-11-27 16:31:02 -05:00
|
|
|
import yaml from "js-yaml";
|
2023-11-27 16:14:31 -05:00
|
|
|
|
2023-11-27 16:31:02 -05:00
|
|
|
export { formatYaml };
|
2023-11-27 16:14:31 -05:00
|
|
|
|
|
|
|
function formatYaml({
|
|
|
|
rawYaml,
|
|
|
|
sortKeys = false,
|
2023-11-27 16:31:02 -05:00
|
|
|
indentSize = 2,
|
2023-11-27 16:14:31 -05:00
|
|
|
}: {
|
|
|
|
rawYaml: MaybeRef<string>
|
|
|
|
sortKeys?: MaybeRef<boolean>
|
|
|
|
stripComments?: MaybeRef<boolean>
|
|
|
|
indentSize?: MaybeRef<number>
|
|
|
|
}) {
|
2023-11-27 16:31:02 -05:00
|
|
|
const parsedYaml = yaml.load(get(rawYaml));
|
|
|
|
|
|
|
|
const formattedYAML = yaml.dump(parsedYaml, {
|
|
|
|
indent: get(indentSize),
|
|
|
|
sortKeys: get(sortKeys)
|
|
|
|
});
|
2023-11-27 16:14:31 -05:00
|
|
|
|
2023-11-27 16:31:02 -05:00
|
|
|
return formattedYAML
|
2023-11-27 16:14:31 -05:00
|
|
|
}
|