it-tools/src/tools/yaml-viewer/yaml-models.ts
Isaiah fc06f01b34
feat(new-tool): yaml formater (#779)
* validating if yaml is correct and collecting format options

* Formatting yaml, sorting keys and changing indent size.

* Removed unused format options

* Fixed lint errors

* Installed types for js-yaml

* Removed legacy routing and added tool creation date

Co-authored-by: Corentin THOMASSET <corentin.thomasset74@gmail.com>

* Using existing yaml package instead of js-yaml

* Update src/tools/yaml-viewer/index.ts

---------

Co-authored-by: Isaiah <66272034+isaiah-j@users.noreply.github.com>
Co-authored-by: Corentin THOMASSET <corentin.thomasset74@gmail.com>
2024-01-31 09:58:53 +00:00

24 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;
}