mirror of
https://github.com/CorentinTh/it-tools.git
synced 2025-05-04 13:29:13 -04:00
feat(i18n): yaml to json
This commit is contained in:
parent
7a70dbbe0c
commit
9331434c14
4 changed files with 24 additions and 6 deletions
|
@ -6,7 +6,7 @@ type ValidatorReturnType = unknown;
|
||||||
|
|
||||||
export interface UseValidationRule<T> {
|
export interface UseValidationRule<T> {
|
||||||
validator: (value: T) => ValidatorReturnType
|
validator: (value: T) => ValidatorReturnType
|
||||||
message: string
|
message: any
|
||||||
}
|
}
|
||||||
|
|
||||||
export function isFalsyOrHasThrown(cb: () => ValidatorReturnType): boolean {
|
export function isFalsyOrHasThrown(cb: () => ValidatorReturnType): boolean {
|
||||||
|
@ -56,7 +56,6 @@ export function useValidation<T>({
|
||||||
watch(
|
watch(
|
||||||
[source, ...watchRefs],
|
[source, ...watchRefs],
|
||||||
() => {
|
() => {
|
||||||
state.message = '';
|
|
||||||
state.status = undefined;
|
state.status = undefined;
|
||||||
|
|
||||||
for (const rule of get(rules)) {
|
for (const rule of get(rules)) {
|
||||||
|
|
9
src/tools/yaml-to-json-converter/locales/en.yml
Normal file
9
src/tools/yaml-to-json-converter/locales/en.yml
Normal file
|
@ -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
src/tools/yaml-to-json-converter/locales/zh.yml
Normal file
9
src/tools/yaml-to-json-converter/locales/zh.yml
Normal file
|
@ -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...'
|
|
@ -4,6 +4,7 @@ import type { UseValidationRule } from '@/composable/validation';
|
||||||
import { isNotThrowing } from '@/utils/boolean';
|
import { isNotThrowing } from '@/utils/boolean';
|
||||||
import { withDefaultOnError } from '@/utils/defaults';
|
import { withDefaultOnError } from '@/utils/defaults';
|
||||||
|
|
||||||
|
const { t } = useI18n();
|
||||||
function transformer(value: string) {
|
function transformer(value: string) {
|
||||||
return withDefaultOnError(() => {
|
return withDefaultOnError(() => {
|
||||||
const obj = parseYaml(value);
|
const obj = parseYaml(value);
|
||||||
|
@ -14,16 +15,16 @@ function transformer(value: string) {
|
||||||
const rules: UseValidationRule<string>[] = [
|
const rules: UseValidationRule<string>[] = [
|
||||||
{
|
{
|
||||||
validator: (value: string) => isNotThrowing(() => parseYaml(value)),
|
validator: (value: string) => isNotThrowing(() => parseYaml(value)),
|
||||||
message: 'Provided YAML is not valid.',
|
message: computed(() => t('tools.yaml-to-json-converter.invalid')),
|
||||||
},
|
},
|
||||||
];
|
];
|
||||||
</script>
|
</script>
|
||||||
|
|
||||||
<template>
|
<template>
|
||||||
<format-transformer
|
<format-transformer
|
||||||
input-label="Your YAML"
|
:input-label="t('tools.yaml-to-json-converter.your-yaml')"
|
||||||
input-placeholder="Paste your yaml here..."
|
:input-placeholder="t('tools.yaml-to-json-converter.placeholder.your-yaml')"
|
||||||
output-label="JSON from your YAML"
|
:output-label="t('tools.yaml-to-json-converter.json-from-yaml')"
|
||||||
output-language="json"
|
output-language="json"
|
||||||
:input-validation-rules="rules"
|
:input-validation-rules="rules"
|
||||||
:transformer="transformer"
|
:transformer="transformer"
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue