mirror of
https://github.com/sharevb/it-tools.git
synced 2026-11-20 21:23:08 +03:00
Merge branch 'feat/json-to-csharp' into chore/all-my-stuffs
# Conflicts: # components.d.ts # package.json # pnpm-lock.yaml # src/tools/index.ts
This commit is contained in:
commit
4cdcbafbc1
6 files changed
+75
No files matched your search
@@ -131,6 +131,7 @@
|
||||
"js-base64": "^3.7.7",
|
||||
"json-editor-vue": "^0.16.0",
|
||||
"json-analyzer": "^1.2.2",
|
||||
"json2csharp": "^1.0.3",
|
||||
"json5": "^2.2.3",
|
||||
"jsonpath": "^1.1.1",
|
||||
"jsonar-mod": "^1.9.0",
|
||||
|
||||
Generated
+7
@@ -251,6 +251,9 @@ dependencies:
|
||||
json-editor-vue:
|
||||
specifier: ^0.16.0
|
||||
version: 0.16.0(@lezer/common@1.2.3)(vue@3.3.4)
|
||||
json2csharp:
|
||||
specifier: ^1.0.3
|
||||
version: 1.0.3
|
||||
json5:
|
||||
specifier: ^2.2.3
|
||||
version: 2.2.3
|
||||
@@ -8599,6 +8602,10 @@ packages:
|
||||
resolution: {integrity: sha512-Bdboy+l7tA3OGW6FjyFHWkP5LuByj1Tk33Ljyq0axyzdk9//JSi2u3fP1QSmd1KNwq6VOKYGlAu87CisVir6Pw==}
|
||||
dev: true
|
||||
|
||||
/json2csharp@1.0.3:
|
||||
resolution: {integrity: sha512-hbe5csNMtvYf4neEDvYRWkJf8fgxeheuMAfhG80f2HIpeUMunPvv+4F2fS1PLpXbdzBp6EMQjZiocRvKhtahgg==}
|
||||
dev: false
|
||||
|
||||
/json5@2.2.3:
|
||||
resolution: {integrity: sha512-XmOWe7eyHYH14cLdVPoyg+GOH3rYX++KpzrylJwSW98t3Nk+U8XOl8FWKOgwtzdb8lXGf6zYwDUzeHMWfxasyg==}
|
||||
engines: {node: '>=6'}
|
||||
|
||||
@@ -23,6 +23,7 @@ import { tool as jsUnobfuscator } from './js-unobfuscator';
|
||||
import { tool as jsonToPhpArray } from './json-to-php-array';
|
||||
import { tool as phpArrayToJson } from './php-array-to-json';
|
||||
import { tool as jsonSizeAnalyzer } from './json-size-analyzer';
|
||||
import { tool as jsonToCsharp } from './json-to-csharp';
|
||||
|
||||
import { tool as cssXpathConverter } from './css-xpath-converter';
|
||||
import { tool as cssSelectorsMemo } from './css-selectors-memo';
|
||||
@@ -181,6 +182,7 @@ export const toolsByCategory: ToolCategory[] = [
|
||||
markdownToHtml,
|
||||
currencyConverter,
|
||||
hddCalculator,
|
||||
jsonToCsharp,
|
||||
],
|
||||
},
|
||||
{
|
||||
|
||||
@@ -0,0 +1,12 @@
|
||||
import { CSharp } from '@vicons/tabler';
|
||||
import { defineTool } from '../tool';
|
||||
|
||||
export const tool = defineTool({
|
||||
name: 'JSON to C#',
|
||||
path: '/json-to-csharp',
|
||||
description: 'Convert JSON data to C# type definition',
|
||||
keywords: ['json', 'c#', 'csharp'],
|
||||
component: () => import('./json-to-csharp.vue'),
|
||||
icon: CSharp,
|
||||
createdAt: new Date('2024-05-11'),
|
||||
});
|
||||
@@ -0,0 +1,50 @@
|
||||
<script setup lang="ts">
|
||||
import JSON5 from 'json5';
|
||||
import json2csharp from 'json2csharp';
|
||||
import type { UseValidationRule } from '@/composable/validation';
|
||||
import TextareaCopyable from '@/components/TextareaCopyable.vue';
|
||||
import { withDefaultOnError } from '@/utils/defaults';
|
||||
|
||||
const defaultValue = `{
|
||||
a:"n",
|
||||
arr: [1, 2],
|
||||
nested: {
|
||||
a:1,
|
||||
b:"2"
|
||||
}
|
||||
}`;
|
||||
const jsonInput = ref(defaultValue);
|
||||
const useNewtonsoft = useStorage('json-to-csharp:newtonsoft', false);
|
||||
const csharpOutput = computed(() => withDefaultOnError(
|
||||
() => json2csharp(JSON.stringify(JSON5.parse(jsonInput.value)), useNewtonsoft.value), ''));
|
||||
const rules: UseValidationRule<string>[] = [
|
||||
{
|
||||
validator: (v: string) => v === '' || JSON5.parse(v),
|
||||
message: 'Provided JSON is not valid.',
|
||||
},
|
||||
];
|
||||
</script>
|
||||
|
||||
<template>
|
||||
<c-card title="JSON to C#">
|
||||
<c-input-text
|
||||
v-model:value="jsonInput"
|
||||
multiline
|
||||
placeholder="Put your json string here..."
|
||||
rows="20"
|
||||
label="JSON to C#"
|
||||
:validation-rules="rules"
|
||||
raw-text
|
||||
mb-5
|
||||
/>
|
||||
<n-checkbox v-model:checked="useNewtonsoft">
|
||||
<span title="Use Newtonsoft Annotations">Use Newtonsoft Annotations</span>
|
||||
</n-checkbox>
|
||||
</c-card>
|
||||
<c-card title="Your C# code">
|
||||
<TextareaCopyable
|
||||
:value="csharpOutput"
|
||||
language="csharp"
|
||||
/>
|
||||
</c-card>
|
||||
</template>
|
||||
+3
@@ -0,0 +1,3 @@
|
||||
declare module 'json2csharp'{
|
||||
export default function(json: string, useNewtonsoftAnnotations?: boolean): string;
|
||||
}
|
||||
Reference in new issue
Block a user