Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 1 addition & 2 deletions src/composable/validation.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ type ValidatorReturnType = unknown;

export interface UseValidationRule<T> {
validator: (value: T) => ValidatorReturnType
message: string
message: any
}

export function isFalsyOrHasThrown(cb: () => ValidatorReturnType): boolean {
Expand Down Expand Up @@ -56,7 +56,6 @@ export function useValidation<T>({
watch(
[source, ...watchRefs],
() => {
state.message = '';
state.status = undefined;

for (const rule of get(rules)) {
Expand Down
9 changes: 9 additions & 0 deletions src/tools/yaml-to-json-converter/locales/en.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
tools:
yaml-to-json-converter:
title: 'YAML to JSON converter'
description: 'Simply convert YAML to JSON with this live online converter.'
invalid: 'Provided JSON is not valid.'
your-yaml: 'Your YAML'
json-from-yaml: 'JSON from your YAML'
placeholder:
your-yaml: 'Paste your YAML here...'
9 changes: 9 additions & 0 deletions src/tools/yaml-to-json-converter/locales/zh.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
tools:
yaml-to-json-converter:
title: 'YAML to JSON'
description: '使用这个在线转换工具,简单地将YAML转换为JSON'
invalid: '提供的YAML有问题'
your-yaml: '原始YAML'
json-from-yaml: '转换后的JSON'
placeholder:
your-yaml: '在这粘贴你的YAML...'
9 changes: 5 additions & 4 deletions src/tools/yaml-to-json-converter/yaml-to-json.vue
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import type { UseValidationRule } from '@/composable/validation';
import { isNotThrowing } from '@/utils/boolean';
import { withDefaultOnError } from '@/utils/defaults';

const { t } = useI18n();
function transformer(value: string) {
return withDefaultOnError(() => {
const obj = parseYaml(value);
Expand All @@ -14,16 +15,16 @@ function transformer(value: string) {
const rules: UseValidationRule<string>[] = [
{
validator: (value: string) => isNotThrowing(() => parseYaml(value)),
message: 'Provided YAML is not valid.',
message: computed(() => t('tools.yaml-to-json-converter.invalid')),
},
];
</script>

<template>
<format-transformer
input-label="Your YAML"
input-placeholder="Paste your yaml here..."
output-label="JSON from your YAML"
:input-label="t('tools.yaml-to-json-converter.your-yaml')"
:input-placeholder="t('tools.yaml-to-json-converter.placeholder.your-yaml')"
:output-label="t('tools.yaml-to-json-converter.json-from-yaml')"
output-language="json"
:input-validation-rules="rules"
:transformer="transformer"
Expand Down