-
-
Notifications
You must be signed in to change notification settings - Fork 3.7k
tool: yaml format #779
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
tool: yaml format #779
Changes from 9 commits
Commits
Show all changes
10 commits
Select commit
Hold shift + click to select a range
3a99642
validating if yaml is correct and collecting format options
lovesinatra 3a13b79
Formatting yaml, sorting keys and changing indent size.
lovesinatra 8493450
Removed unused format options
lovesinatra 4f69621
Fixed lint errors
lovesinatra 5f92d64
Installed types for js-yaml
lovesinatra 8ccbf21
Removed legacy routing and added tool creation date
lovesinatra 1e8dc93
Using existing yaml package instead of js-yaml
lovesinatra 8cd5e6d
Merge remote-tracking branch 'origin/yaml-viewer' into yaml-viewer
lovesinatra f77a83e
Merge branch 'main' into yaml-viewer
lovesinatra 47abf47
Update src/tools/yaml-viewer/index.ts
CorentinTh File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
import { AlignJustified } from '@vicons/tabler'; | ||
import { defineTool } from '../tool'; | ||
|
||
export const tool = defineTool({ | ||
name: 'YAML prettify and format', | ||
path: '/yaml-prettify', | ||
description: 'Prettify your YAML string to a human friendly readable format.', | ||
keywords: ['yaml', 'viewer', 'prettify', 'format'], | ||
component: () => import('./yaml-viewer.vue'), | ||
icon: AlignJustified, | ||
createdAt: new Date('2023-11-29'), | ||
}); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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; | ||
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,72 @@ | ||
<script setup lang="ts"> | ||
import yaml from 'yaml'; | ||
import { useStorage } from '@vueuse/core'; | ||
import { formatYaml } from './yaml-models'; | ||
import { withDefaultOnError } from '@/utils/defaults'; | ||
import { useValidation } from '@/composable/validation'; | ||
import TextareaCopyable from '@/components/TextareaCopyable.vue'; | ||
|
||
const inputElement = ref<HTMLElement>(); | ||
|
||
const rawYaml = useStorage('yaml-prettify:raw-yaml', ''); | ||
const indentSize = useStorage('yaml-prettify:indent-size', 2); | ||
const sortKeys = useStorage('yaml-prettify:sort-keys', false); | ||
|
||
const cleanYaml = computed(() => withDefaultOnError(() => formatYaml({ rawYaml, indentSize, sortKeys }), '')); | ||
|
||
const rawYamlValidation = useValidation({ | ||
source: rawYaml, | ||
rules: [ | ||
{ | ||
validator: v => v === '' || yaml.parse(v), | ||
message: 'Provided YAML is not valid.', | ||
}, | ||
], | ||
}); | ||
</script> | ||
|
||
<template> | ||
<div style="flex: 0 0 100%"> | ||
<div style="margin: 0 auto; max-width: 600px" flex justify-center gap-3> | ||
<n-form-item label="Sort keys :" label-placement="left" label-width="100"> | ||
<n-switch v-model:value="sortKeys" /> | ||
</n-form-item> | ||
<n-form-item label="Indent size :" label-placement="left" label-width="100" :show-feedback="false"> | ||
<n-input-number v-model:value="indentSize" min="1" max="10" style="width: 100px" /> | ||
</n-form-item> | ||
</div> | ||
</div> | ||
|
||
<n-form-item | ||
label="Your raw YAML" | ||
:feedback="rawYamlValidation.message" | ||
:validation-status="rawYamlValidation.status" | ||
> | ||
<c-input-text | ||
ref="inputElement" | ||
v-model:value="rawYaml" | ||
placeholder="Paste your raw YAML here..." | ||
rows="20" | ||
multiline | ||
autocomplete="off" | ||
autocorrect="off" | ||
autocapitalize="off" | ||
spellcheck="false" | ||
monospace | ||
/> | ||
</n-form-item> | ||
<n-form-item label="Prettified version of your YAML"> | ||
<TextareaCopyable :value="cleanYaml" language="yaml" :follow-height-of="inputElement" /> | ||
</n-form-item> | ||
</template> | ||
|
||
<style lang="less" scoped> | ||
.result-card { | ||
position: relative; | ||
.copy-button { | ||
position: absolute; | ||
top: 10px; | ||
right: 10px; | ||
} | ||
} | ||
</style> |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.