2023-04-10 17:34:58 +02:00
|
|
|
<script setup lang="ts">
|
2023-05-28 23:13:24 +02:00
|
|
|
import { stringify } from 'yaml';
|
|
|
|
import JSON5 from 'json5';
|
2023-04-10 17:34:58 +02:00
|
|
|
import type { UseValidationRule } from '@/composable/validation';
|
|
|
|
import { isNotThrowing } from '@/utils/boolean';
|
|
|
|
import { withDefaultOnError } from '@/utils/defaults';
|
|
|
|
|
|
|
|
const transformer = (value: string) => withDefaultOnError(() => stringify(JSON5.parse(value)), '');
|
|
|
|
|
|
|
|
const rules: UseValidationRule<string>[] = [
|
|
|
|
{
|
|
|
|
validator: (value: string) => value === '' || isNotThrowing(() => stringify(JSON5.parse(value))),
|
|
|
|
message: 'Provided JSON is not valid.',
|
|
|
|
},
|
|
|
|
];
|
|
|
|
</script>
|
|
|
|
|
2023-05-28 23:13:24 +02:00
|
|
|
<template>
|
|
|
|
<format-transformer
|
|
|
|
input-label="Your JSON"
|
|
|
|
input-placeholder="Paste your JSON here..."
|
|
|
|
output-label="YAML from your JSON"
|
|
|
|
output-language="yaml"
|
|
|
|
:input-validation-rules="rules"
|
|
|
|
:transformer="transformer"
|
|
|
|
/>
|
|
|
|
</template>
|