aboutsummaryrefslogtreecommitdiff
path: root/src/tools/json-to-csv/json-to-csv.vue
diff options
context:
space:
mode:
authorGravatar Corentin Thomasset <corentin.thomasset74@gmail.com> 2023-06-18 17:57:18 +0200
committerGravatar Corentin Thomasset <corentin.thomasset74@gmail.com> 2023-06-18 18:10:06 +0200
commit69f0bd079fd824dc9e929ccbbaa6bcaab0c38a7c (patch)
tree27d2b1fde22872f3d21dedf7c9af99f42187945b /src/tools/json-to-csv/json-to-csv.vue
parent4cbd7ac14588e954510340186c6797b19caca593 (diff)
downloadit-tools-69f0bd079fd824dc9e929ccbbaa6bcaab0c38a7c.tar.gz
it-tools-69f0bd079fd824dc9e929ccbbaa6bcaab0c38a7c.tar.zst
it-tools-69f0bd079fd824dc9e929ccbbaa6bcaab0c38a7c.zip
feat(new-tool): json to csv converter
Diffstat (limited to 'src/tools/json-to-csv/json-to-csv.vue')
-rw-r--r--src/tools/json-to-csv/json-to-csv.vue32
1 files changed, 32 insertions, 0 deletions
diff --git a/src/tools/json-to-csv/json-to-csv.vue b/src/tools/json-to-csv/json-to-csv.vue
new file mode 100644
index 0000000..cf15400
--- /dev/null
+++ b/src/tools/json-to-csv/json-to-csv.vue
@@ -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>