blob: 39c9297f2ba9652f79e06a5c1a76d3dc0d214a9f (
plain) (
blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
|
<script setup lang="ts">
import { parse as parseYaml } from 'yaml';
import type { UseValidationRule } from '@/composable/validation';
import { isNotThrowing } from '@/utils/boolean';
import { withDefaultOnError } from '@/utils/defaults';
function transformer(value: string) {
return withDefaultOnError(() => {
const obj = parseYaml(value);
return obj ? JSON.stringify(obj, null, 3) : '';
}, '');
}
const rules: UseValidationRule<string>[] = [
{
validator: (value: string) => isNotThrowing(() => parseYaml(value)),
message: 'Provided YAML is not valid.',
},
];
</script>
<template>
<format-transformer
input-label="Your YAML"
input-placeholder="Paste your yaml here..."
output-label="JSON from your YAML"
output-language="json"
:input-validation-rules="rules"
:transformer="transformer"
/>
</template>
|