mirror of
https://github.com/CorentinTh/it-tools.git
synced 2025-05-04 21:37:11 -04:00

* 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>
24 lines
472 B
TypeScript
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;
|
|
}
|