it-tools/src/tools/yaml-viewer/yaml-models.ts
sharevb fd0a723f06 feat(Yaml Viewer): add parsing validation
Add parsing validations
Fix #540
2024-04-07 22:31:42 +02:00

25 lines
513 B
TypeScript

import { type MaybeRef, get } from '@vueuse/core';
import { yamlParse } from 'composeverter';
import yaml from 'yaml';
export { formatYaml };
function formatYaml({
rawYaml,
sortKeys = false,
indentSize = 2,
}: {
rawYaml: MaybeRef<string>
sortKeys?: MaybeRef<boolean>
indentSize?: MaybeRef<number>
}) {
const parsedYaml = yamlParse(get(rawYaml));
const formattedYAML = yaml.stringify(parsedYaml, {
sortMapEntries: get(sortKeys),
indent: get(indentSize),
});
return formattedYAML;
}