mirror of
https://github.com/sharevb/it-tools.git
synced 2026-11-20 21:23:08 +03:00
Merge branch 'up/fix/json-to-object' into chore/all-my-stuffs
This commit is contained in:
commit
f7c2d896af
6 files changed
+83
-2
No files matched your search
+4
-1
@@ -411,4 +411,7 @@ tools:
|
||||
|
||||
text-to-binary:
|
||||
title: Text to ASCII binary
|
||||
description: Convert text to its ASCII binary representation and vice-versa.
|
||||
description: Convert text to its ASCII binary representation and vice-versa.
|
||||
json-to-object:
|
||||
title: JSON to object
|
||||
description: Parse and convert JSON to object.
|
||||
@@ -213,6 +213,7 @@
|
||||
"slashes": "^3.0.12",
|
||||
"spdx-satisfies": "^5.0.1",
|
||||
"sql-formatter": "^13.0.0",
|
||||
"stringify-object": "^5.0.0",
|
||||
"sshpk": "^1.18.0",
|
||||
"svg2png-wasm": "^1.4.1",
|
||||
"svgo": "^3.3.2",
|
||||
@@ -280,6 +281,7 @@
|
||||
"@types/potrace": "^2.1.5",
|
||||
"@types/punycode": "^2.1.4",
|
||||
"@types/qrcode": "^1.5.0",
|
||||
"@types/stringify-object": "^4.0.5",
|
||||
"@types/spdx-satisfies": "^0.1.2",
|
||||
"@types/sshpk": "^1.17.4",
|
||||
"@types/turndown": "^5.0.5",
|
||||
|
||||
Generated
+30
-1
@@ -539,6 +539,9 @@ dependencies:
|
||||
sshpk:
|
||||
specifier: ^1.18.0
|
||||
version: 1.18.0
|
||||
stringify-object:
|
||||
specifier: ^5.0.0
|
||||
version: 5.0.0
|
||||
svg2png-wasm:
|
||||
specifier: ^1.4.1
|
||||
version: 1.4.1
|
||||
@@ -739,6 +742,9 @@ devDependencies:
|
||||
'@types/sshpk':
|
||||
specifier: ^1.17.4
|
||||
version: 1.17.4
|
||||
'@types/stringify-object':
|
||||
specifier: ^4.0.5
|
||||
version: 4.0.5
|
||||
'@types/turndown':
|
||||
specifier: ^5.0.5
|
||||
version: 5.0.5
|
||||
@@ -5635,6 +5641,10 @@ packages:
|
||||
'@types/node': 18.18.8
|
||||
dev: true
|
||||
|
||||
/@types/stringify-object@4.0.5:
|
||||
resolution: {integrity: sha512-TzX5V+njkbJ8iJ0mrj+Vqveep/1JBH4SSA3J2wYrE1eUrOhdsjTBCb0kao4EquSQ8KgPpqY4zSVP2vCPWKBElg==}
|
||||
dev: true
|
||||
|
||||
/@types/tough-cookie@4.0.2:
|
||||
resolution: {integrity: sha512-Q5vtl1W5ue16D+nIaW8JWebSSraJVlK+EthKn7e7UcD4KWsaSJ8BqGPXNaPghgtcn/fhvrN17Tv8ksUsQpiplw==}
|
||||
dev: true
|
||||
@@ -6447,7 +6457,7 @@ packages:
|
||||
'@vue/compiler-dom': 3.3.4
|
||||
'@vue/reactivity': 3.3.4
|
||||
'@vue/shared': 3.3.4
|
||||
minimatch: 9.0.5
|
||||
minimatch: 9.0.1
|
||||
muggle-string: 0.3.1
|
||||
typescript: 5.2.2
|
||||
vue-template-compiler: 2.7.14
|
||||
@@ -9797,6 +9807,11 @@ packages:
|
||||
hasown: 2.0.0
|
||||
dev: true
|
||||
|
||||
/get-own-enumerable-keys@1.0.0:
|
||||
resolution: {integrity: sha512-PKsK2FSrQCyxcGHsGrLDcK0lx+0Ke+6e8KFFozA9/fIQLhQzPaRvJFdcz7+Axg3jUH/Mq+NI4xa5u/UT2tQskA==}
|
||||
engines: {node: '>=14.16'}
|
||||
dev: false
|
||||
|
||||
/get-own-enumerable-property-symbols@3.0.2:
|
||||
resolution: {integrity: sha512-I0UBV/XOz1XkIJHEUDMZAbzCThU/H8DxmSfmdGcKPnVhu2VfFqr34jr9777IyaTYvxjedWhqVIilEDsCdP5G6g==}
|
||||
dev: true
|
||||
@@ -10753,6 +10768,11 @@ packages:
|
||||
engines: {node: '>=0.10.0'}
|
||||
dev: true
|
||||
|
||||
/is-obj@3.0.0:
|
||||
resolution: {integrity: sha512-IlsXEHOjtKhpN8r/tRFj2nDyTmHvcfNeu/nrRIcXE17ROeatXchkojffa1SpdqW4cr/Fj6QkEf/Gn4zf6KKvEQ==}
|
||||
engines: {node: '>=12'}
|
||||
dev: false
|
||||
|
||||
/is-path-inside@3.0.3:
|
||||
resolution: {integrity: sha512-Fd4gABb+ycGAmKou8eMftCupSir5lRxqf4aD/vd0cD2qc4HL07OjCeuHMr8Ro4CoMaeCKDB0/ECBOVWjTwUvPQ==}
|
||||
engines: {node: '>=8'}
|
||||
@@ -14361,6 +14381,15 @@ packages:
|
||||
is-regexp: 1.0.0
|
||||
dev: true
|
||||
|
||||
/stringify-object@5.0.0:
|
||||
resolution: {integrity: sha512-zaJYxz2FtcMb4f+g60KsRNFOpVMUyuJgA51Zi5Z1DOTC3S59+OQiVOzE9GZt0x72uBGWKsQIuBKeF9iusmKFsg==}
|
||||
engines: {node: '>=14.16'}
|
||||
dependencies:
|
||||
get-own-enumerable-keys: 1.0.0
|
||||
is-obj: 3.0.0
|
||||
is-regexp: 3.1.0
|
||||
dev: false
|
||||
|
||||
/strip-ansi@6.0.1:
|
||||
resolution: {integrity: sha512-Y38VPSHcqkFrCpFnQ9vuSXmquuv5oXOKpGeT6aGrr3o3Gc9AlVa6JBfUSOCnbxGGZF+/0ooI7KrPuUSztUdU5A==}
|
||||
engines: {node: '>=8'}
|
||||
|
||||
@@ -233,6 +233,7 @@ import { tool as pdfUnlock } from './pdf-unlock';
|
||||
import { tool as ipCidrToRange } from './ip-cidr-to-range';
|
||||
import { tool as ipRangeToCidr } from './ip-range-to-cidr';
|
||||
import { tool as ipv6AddressConverter } from './ipv6-address-converter';
|
||||
import { tool as jsonToObject } from './json-to-object';
|
||||
|
||||
export const toolsByCategory: ToolCategory[] = [
|
||||
{
|
||||
@@ -385,6 +386,7 @@ export const toolsByCategory: ToolCategory[] = [
|
||||
jsonLinter,
|
||||
jsonToCsv,
|
||||
csvToJson,
|
||||
jsonToObject,
|
||||
sqlPrettify,
|
||||
chmodCalculator,
|
||||
dockerRunToDockerComposeConverter,
|
||||
|
||||
@@ -0,0 +1,13 @@
|
||||
import { Braces } from '@vicons/tabler';
|
||||
import { defineTool } from '../tool';
|
||||
import { translate } from '@/plugins/i18n.plugin';
|
||||
|
||||
export const tool = defineTool({
|
||||
name: translate('tools.json-to-object.title'),
|
||||
path: '/json-to-object',
|
||||
description: translate('tools.json-to-object.description'),
|
||||
keywords: ['json', 'parse', 'object', 'convert', 'transform'],
|
||||
component: () => import('./json-to-object.vue'),
|
||||
icon: Braces,
|
||||
createdAt: new Date('2024-08-16'),
|
||||
});
|
||||
@@ -0,0 +1,32 @@
|
||||
<script setup lang="ts">
|
||||
import JSON5 from 'json5';
|
||||
import stringifyObject from 'stringify-object';
|
||||
import type { UseValidationRule } from '@/composable/validation';
|
||||
import { isNotThrowing } from '@/utils/boolean';
|
||||
import { withDefaultOnError } from '@/utils/defaults';
|
||||
|
||||
function transformer(value: string) {
|
||||
return withDefaultOnError(() => stringifyObject(JSON5.parse(value), {
|
||||
indent: ' ',
|
||||
singleQuotes: false,
|
||||
}), '');
|
||||
}
|
||||
|
||||
const rules: UseValidationRule<string>[] = [
|
||||
{
|
||||
validator: (value: string) => value === '' || isNotThrowing(() => stringifyObject(JSON5.parse(value))),
|
||||
message: 'Provided JSON is not valid.',
|
||||
},
|
||||
];
|
||||
</script>
|
||||
|
||||
<template>
|
||||
<format-transformer
|
||||
input-label="Your JSON"
|
||||
input-placeholder="Paste your JSON here..."
|
||||
output-label="Object from your JSON"
|
||||
output-language="js"
|
||||
:input-validation-rules="rules"
|
||||
:transformer="transformer"
|
||||
/>
|
||||
</template>
|
||||
Reference in new issue
Block a user