mirror of
https://github.com/CorentinTh/it-tools.git
synced 2025-05-05 13:57:10 -04:00
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>
This commit is contained in:
parent
c46207f1bb
commit
fc06f01b34
5 changed files with 111 additions and 3 deletions
24
src/tools/yaml-viewer/yaml-models.ts
Normal file
24
src/tools/yaml-viewer/yaml-models.ts
Normal file
|
@ -0,0 +1,24 @@
|
|||
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;
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue