mirror of
https://github.com/CorentinTh/it-tools.git
synced 2025-05-05 05:47:10 -04:00
25 lines
472 B
TypeScript
25 lines
472 B
TypeScript
![]() |
import { type MaybeRef, get } from '@vueuse/core';
|
||
|
|
||
|
import yaml from 'yaml';
|
||
|
|
||
|
export { formatYaml };
|
||
|
|
||
|
function formatYaml({
|
||
|
rawYaml,
|
||
|
sortKeys = false,
|
||
|
indentSize = 2,
|
||
|
}: {
|
||
|
rawYaml: MaybeRef<string>
|
||
|
sortKeys?: MaybeRef<boolean>
|
||
|
indentSize?: MaybeRef<number>
|
||
|
}) {
|
||
|
const parsedYaml = yaml.parse(get(rawYaml));
|
||
|
|
||
|
const formattedYAML = yaml.stringify(parsedYaml, {
|
||
|
sortMapEntries: get(sortKeys),
|
||
|
indent: get(indentSize),
|
||
|
});
|
||
|
|
||
|
return formattedYAML;
|
||
|
}
|