This commit is contained in:
Chris 2024-12-15 22:34:26 -08:00 committed by GitHub
commit e6ddaf08a7
No known key found for this signature in database
GPG key ID: B5690EEEBB952194

View file

@ -4,6 +4,8 @@ import { convertArrayToCsv } from './json-to-csv.service';
import type { UseValidationRule } from '@/composable/validation'; import type { UseValidationRule } from '@/composable/validation';
import { withDefaultOnError } from '@/utils/defaults'; import { withDefaultOnError } from '@/utils/defaults';
const defaultValue = '[\n {\n "Age": 18,\n "Country": "Germany",\n "Gender": "Male",\n "Purchased": "N",\n "Salary": 20000\n },\n {\n "Age": 19,\n "Country": "France",\n "Gender": "Female",\n "Purchased": "N",\n "Salary": 22000\n },\n {\n "Age": 20,\n "Country": "England",\n "Gender": "Female",\n "Purchased": "N",\n "Salary": 24000\n }\n]';
function transformer(value: string) { function transformer(value: string) {
return withDefaultOnError(() => { return withDefaultOnError(() => {
if (value === '') { if (value === '') {
@ -24,6 +26,7 @@ const rules: UseValidationRule<string>[] = [
<template> <template>
<format-transformer <format-transformer
input-label="Your raw JSON" input-label="Your raw JSON"
:input-default="defaultValue"
input-placeholder="Paste your raw JSON here..." input-placeholder="Paste your raw JSON here..."
output-label="CSV version of your JSON" output-label="CSV version of your JSON"
:input-validation-rules="rules" :input-validation-rules="rules"