mirror of
https://github.com/CorentinTh/it-tools.git
synced 2025-05-07 06:47:13 -04:00
feat(new-tool): yaml to toml
This commit is contained in:
parent
ea50a3fc65
commit
e29b258e90
5 changed files with 83 additions and 3 deletions
28
src/tools/yaml-to-toml/yaml-to-toml.vue
Normal file
28
src/tools/yaml-to-toml/yaml-to-toml.vue
Normal file
|
@ -0,0 +1,28 @@
|
|||
<script setup lang="ts">
|
||||
import { stringify as stringifyToml } from 'iarna-toml-esm';
|
||||
import { parse as parseYaml } from 'yaml';
|
||||
import { withDefaultOnError } from '../../utils/defaults';
|
||||
import type { UseValidationRule } from '@/composable/validation';
|
||||
|
||||
const convertYamlToToml = (value: string) => [stringifyToml(parseYaml(value))].flat().join('\n').trim();
|
||||
|
||||
const transformer = (value: string) => value.trim() === '' ? '' : withDefaultOnError(() => convertYamlToToml(value), '');
|
||||
|
||||
const rules: UseValidationRule<string>[] = [
|
||||
{
|
||||
validator: (v: string) => v === '' || parseYaml(v),
|
||||
message: 'Provided JSON is not valid.',
|
||||
},
|
||||
];
|
||||
</script>
|
||||
|
||||
<template>
|
||||
<format-transformer
|
||||
input-label="Your YAML"
|
||||
input-placeholder="Paste your YAML here..."
|
||||
output-label="TOML from your YAML"
|
||||
output-language="toml"
|
||||
:input-validation-rules="rules"
|
||||
:transformer="transformer"
|
||||
/>
|
||||
</template>
|
Loading…
Add table
Add a link
Reference in a new issue