mirror of
https://github.com/CorentinTh/it-tools.git
synced 2025-05-05 13:57:10 -04:00
feat(new-tool): toml to yaml
This commit is contained in:
parent
c7d4f112c0
commit
746e5bdccc
4 changed files with 77 additions and 0 deletions
27
src/tools/toml-to-yaml/toml-to-yaml.vue
Normal file
27
src/tools/toml-to-yaml/toml-to-yaml.vue
Normal file
|
@ -0,0 +1,27 @@
|
|||
<script setup lang="ts">
|
||||
import { parse as parseToml } from 'iarna-toml-esm';
|
||||
import { stringify as stringifyToYaml } from 'yaml';
|
||||
import { withDefaultOnError } from '../../utils/defaults';
|
||||
import { isValidToml } from '../toml-to-json/toml.services';
|
||||
import type { UseValidationRule } from '@/composable/validation';
|
||||
|
||||
const transformer = (value: string) => value.trim() === '' ? '' : withDefaultOnError(() => stringifyToYaml(parseToml(value)), '');
|
||||
|
||||
const rules: UseValidationRule<string>[] = [
|
||||
{
|
||||
validator: isValidToml,
|
||||
message: 'Provided TOML is not valid.',
|
||||
},
|
||||
];
|
||||
</script>
|
||||
|
||||
<template>
|
||||
<format-transformer
|
||||
input-label="Your TOML"
|
||||
input-placeholder="Paste your TOML here..."
|
||||
output-label="YAML from your TOML"
|
||||
output-language="yaml"
|
||||
:input-validation-rules="rules"
|
||||
:transformer="transformer"
|
||||
/>
|
||||
</template>
|
Loading…
Add table
Add a link
Reference in a new issue