mirror of
https://github.com/CorentinTh/it-tools.git
synced 2025-05-05 13:57:10 -04:00
feat(new-tool): json to csv converter
This commit is contained in:
parent
4cbd7ac145
commit
69f0bd079f
7 changed files with 200 additions and 0 deletions
32
src/tools/json-to-csv/json-to-csv.vue
Normal file
32
src/tools/json-to-csv/json-to-csv.vue
Normal file
|
@ -0,0 +1,32 @@
|
|||
<script setup lang="ts">
|
||||
import JSON5 from 'json5';
|
||||
import { convertArrayToCsv } from './json-to-csv.service';
|
||||
import type { UseValidationRule } from '@/composable/validation';
|
||||
import { withDefaultOnError } from '@/utils/defaults';
|
||||
|
||||
function transformer(value: string) {
|
||||
return withDefaultOnError(() => {
|
||||
if (value === '') {
|
||||
return '';
|
||||
}
|
||||
return convertArrayToCsv({ array: JSON5.parse(value) });
|
||||
}, '');
|
||||
}
|
||||
|
||||
const rules: UseValidationRule<string>[] = [
|
||||
{
|
||||
validator: (v: string) => v === '' || JSON5.parse(v),
|
||||
message: 'Provided JSON is not valid.',
|
||||
},
|
||||
];
|
||||
</script>
|
||||
|
||||
<template>
|
||||
<format-transformer
|
||||
input-label="Your raw json"
|
||||
input-placeholder="Paste your raw json here..."
|
||||
output-label="CSV version of your JSON"
|
||||
:input-validation-rules="rules"
|
||||
:transformer="transformer"
|
||||
/>
|
||||
</template>
|
Loading…
Add table
Add a link
Reference in a new issue