mirror of
https://github.com/sharevb/it-tools.git
synced 2026-11-23 22:31:10 +03:00
Compare commits
1
Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
6896d03a3a |
No files matched your search
Vendored
+14
-5
@@ -89,6 +89,9 @@ declare module '@vue/runtime-core' {
|
||||
HtmlWysiwygEditor: typeof import('./src/tools/html-wysiwyg-editor/html-wysiwyg-editor.vue')['default']
|
||||
HttpStatusCodes: typeof import('./src/tools/http-status-codes/http-status-codes.vue')['default']
|
||||
IbanValidatorAndParser: typeof import('./src/tools/iban-validator-and-parser/iban-validator-and-parser.vue')['default']
|
||||
IcalGenerator: typeof import('./src/tools/ical-generator/ical-generator.vue')['default']
|
||||
IcalMerger: typeof import('./src/tools/ical-merger/ical-merger.vue')['default']
|
||||
IcalParser: typeof import('./src/tools/ical-parser/ical-parser.vue')['default']
|
||||
'IconMdi:brushVariant': typeof import('~icons/mdi/brush-variant')['default']
|
||||
'IconMdi:kettleSteamOutline': typeof import('~icons/mdi/kettle-steam-outline')['default']
|
||||
IconMdiChevronDown: typeof import('~icons/mdi/chevron-down')['default']
|
||||
@@ -109,7 +112,6 @@ declare module '@vue/runtime-core' {
|
||||
Ipv6UlaGenerator: typeof import('./src/tools/ipv6-ula-generator/ipv6-ula-generator.vue')['default']
|
||||
JsonDiff: typeof import('./src/tools/json-diff/json-diff.vue')['default']
|
||||
JsonMinify: typeof import('./src/tools/json-minify/json-minify.vue')['default']
|
||||
JsonSizeAnalyzer: typeof import('./src/tools/json-size-analyzer/json-size-analyzer.vue')['default']
|
||||
JsonToCsv: typeof import('./src/tools/json-to-csv/json-to-csv.vue')['default']
|
||||
JsonToToml: typeof import('./src/tools/json-to-toml/json-to-toml.vue')['default']
|
||||
JsonToXml: typeof import('./src/tools/json-to-xml/json-to-xml.vue')['default']
|
||||
@@ -131,23 +133,30 @@ declare module '@vue/runtime-core' {
|
||||
MetaTagGenerator: typeof import('./src/tools/meta-tag-generator/meta-tag-generator.vue')['default']
|
||||
MimeTypes: typeof import('./src/tools/mime-types/mime-types.vue')['default']
|
||||
NavbarButtons: typeof import('./src/components/NavbarButtons.vue')['default']
|
||||
NButton: typeof import('naive-ui')['NButton']
|
||||
NCheckbox: typeof import('naive-ui')['NCheckbox']
|
||||
NCode: typeof import('naive-ui')['NCode']
|
||||
NCollapseTransition: typeof import('naive-ui')['NCollapseTransition']
|
||||
NConfigProvider: typeof import('naive-ui')['NConfigProvider']
|
||||
NDatePicker: typeof import('naive-ui')['NDatePicker']
|
||||
NDivider: typeof import('naive-ui')['NDivider']
|
||||
NEllipsis: typeof import('naive-ui')['NEllipsis']
|
||||
NFormItem: typeof import('naive-ui')['NFormItem']
|
||||
NGi: typeof import('naive-ui')['NGi']
|
||||
NGrid: typeof import('naive-ui')['NGrid']
|
||||
NH1: typeof import('naive-ui')['NH1']
|
||||
NH3: typeof import('naive-ui')['NH3']
|
||||
NIcon: typeof import('naive-ui')['NIcon']
|
||||
NInput: typeof import('naive-ui')['NInput']
|
||||
NInputNumber: typeof import('naive-ui')['NInputNumber']
|
||||
NInputGroup: typeof import('naive-ui')['NInputGroup']
|
||||
NLayout: typeof import('naive-ui')['NLayout']
|
||||
NLayoutSider: typeof import('naive-ui')['NLayoutSider']
|
||||
NMenu: typeof import('naive-ui')['NMenu']
|
||||
NRadio: typeof import('naive-ui')['NRadio']
|
||||
NRadioGroup: typeof import('naive-ui')['NRadioGroup']
|
||||
NScrollbar: typeof import('naive-ui')['NScrollbar']
|
||||
NSlider: typeof import('naive-ui')['NSlider']
|
||||
NSwitch: typeof import('naive-ui')['NSwitch']
|
||||
NTree: typeof import('naive-ui')['NTree']
|
||||
NSpace: typeof import('naive-ui')['NSpace']
|
||||
NTable: typeof import('naive-ui')['NTable']
|
||||
NumeronymGenerator: typeof import('./src/tools/numeronym-generator/numeronym-generator.vue')['default']
|
||||
OtpCodeGeneratorAndValidator: typeof import('./src/tools/otp-code-generator-and-validator/otp-code-generator-and-validator.vue')['default']
|
||||
PasswordStrengthAnalyser: typeof import('./src/tools/password-strength-analyser/password-strength-analyser.vue')['default']
|
||||
|
||||
+2
-1
@@ -68,8 +68,9 @@
|
||||
"highlight.js": "^11.7.0",
|
||||
"iarna-toml-esm": "^3.0.5",
|
||||
"ibantools": "^4.3.3",
|
||||
"ical-generator": "^8.0.0",
|
||||
"ical.js": "^2.1.0",
|
||||
"js-base64": "^3.7.6",
|
||||
"json-analyzer": "^1.2.2",
|
||||
"json5": "^2.2.3",
|
||||
"jwt-decode": "^3.1.2",
|
||||
"libphonenumber-js": "^1.10.28",
|
||||
|
||||
Generated
+53
-52
@@ -101,12 +101,15 @@ dependencies:
|
||||
ibantools:
|
||||
specifier: ^4.3.3
|
||||
version: 4.3.3
|
||||
ical-generator:
|
||||
specifier: ^8.0.0
|
||||
version: 8.0.0(@types/node@18.15.11)
|
||||
ical.js:
|
||||
specifier: ^2.1.0
|
||||
version: 2.1.0
|
||||
js-base64:
|
||||
specifier: ^3.7.6
|
||||
version: 3.7.7
|
||||
json-analyzer:
|
||||
specifier: ^1.2.2
|
||||
version: 1.2.2
|
||||
json5:
|
||||
specifier: ^2.2.3
|
||||
version: 2.2.3
|
||||
@@ -3046,7 +3049,6 @@ packages:
|
||||
|
||||
/@types/node@18.15.11:
|
||||
resolution: {integrity: sha512-E5Kwq2n4SbMzQOn6wnmBjuK9ouqlURrcZDVfbo9ftDDTFt3nk7ZKK4GMOzoYgnpQJKcxwQw+lGaBvvlMo0qN/Q==}
|
||||
dev: true
|
||||
|
||||
/@types/node@18.18.8:
|
||||
resolution: {integrity: sha512-OLGBaaK5V3VRBS1bAkMVP2/W9B+H8meUfl866OrMNQqt7wDgdpWPp5o6gmIc9pB+lIQHSq4ZL8ypeH1vPxcPaQ==}
|
||||
@@ -4567,11 +4569,6 @@ packages:
|
||||
resolution: {integrity: sha512-IfEDxwoWIjkeXL1eXcDiow4UbKjhLdq6/EuSVR9GMN7KVH3r9gQ83e73hsz1Nd1T3ijd5xv1wcWRYO+D6kCI2w==}
|
||||
dev: true
|
||||
|
||||
/colors@1.4.0:
|
||||
resolution: {integrity: sha512-a+UqTh4kgZg/SlGvfbzDHpgRu7AAQOmmqRHJnxhRZICKFUT91brVhNNt58CMWU9PsBbv3PDCZUHbVxuDiH2mtA==}
|
||||
engines: {node: '>=0.1.90'}
|
||||
dev: false
|
||||
|
||||
/combined-stream@1.0.8:
|
||||
resolution: {integrity: sha512-FQN4MRfuJeHf7cBbBMJFXhKSDq+2kAArBlmRBvcvFE5BB1HZKXtSFASDhdlz9zOYwxh8lDdnvmMOe/+5cdoEdg==}
|
||||
engines: {node: '>= 0.8'}
|
||||
@@ -6153,6 +6150,47 @@ packages:
|
||||
resolution: {integrity: sha512-RUTlGuFj3cU/Qfu5YIrsIZjW34/VDgKOz5fDr64Mc4NWP9b2i48vQ39r5xCl1yyFQeyEG/lASstIQHAUX18rRA==}
|
||||
dev: false
|
||||
|
||||
/ical-generator@8.0.0(@types/node@18.15.11):
|
||||
resolution: {integrity: sha512-CvVKK3JJrKop6z7i7/NS69FjYdR6ux1LswIeiZ3yaicX7ocMFLQI475JhQabCT7koUkaCVFNVxLaYaxtdPgwww==}
|
||||
engines: {node: 18 || 20 || >=22.0.0}
|
||||
peerDependencies:
|
||||
'@touch4it/ical-timezones': '>=1.6.0'
|
||||
'@types/luxon': '>= 1.26.0'
|
||||
'@types/mocha': '>= 8.2.1'
|
||||
'@types/node': '*'
|
||||
dayjs: '>= 1.10.0'
|
||||
luxon: '>= 1.26.0'
|
||||
moment: '>= 2.29.0'
|
||||
moment-timezone: '>= 0.5.33'
|
||||
rrule: '>= 2.6.8'
|
||||
peerDependenciesMeta:
|
||||
'@touch4it/ical-timezones':
|
||||
optional: true
|
||||
'@types/luxon':
|
||||
optional: true
|
||||
'@types/mocha':
|
||||
optional: true
|
||||
'@types/node':
|
||||
optional: true
|
||||
dayjs:
|
||||
optional: true
|
||||
luxon:
|
||||
optional: true
|
||||
moment:
|
||||
optional: true
|
||||
moment-timezone:
|
||||
optional: true
|
||||
rrule:
|
||||
optional: true
|
||||
dependencies:
|
||||
'@types/node': 18.15.11
|
||||
uuid-random: 1.3.2
|
||||
dev: false
|
||||
|
||||
/ical.js@2.1.0:
|
||||
resolution: {integrity: sha512-BOVfrH55xQ6kpS3muGvIXIg2l7p+eoe12/oS7R5yrO3TL/j/bLsR0PR+tYQESFbyTbvGgPHn9zQ6tI4FWyuSaQ==}
|
||||
dev: false
|
||||
|
||||
/iconv-lite@0.6.3:
|
||||
resolution: {integrity: sha512-4fCk79wshMdzMp2rH06qWrJE4iolqLhCUH+OiuIgU++RB0+94NlDL81atO7GX55uUKueo0txHNtvEyI6D7WdMw==}
|
||||
engines: {node: '>=0.10.0'}
|
||||
@@ -6627,21 +6665,6 @@ packages:
|
||||
hasBin: true
|
||||
dev: true
|
||||
|
||||
/json-analyzer@1.2.2:
|
||||
resolution: {integrity: sha512-3xWTxyIggxOYIPT9NkucQPxlOBPJY14/ifely3eCtifE5pAxJXl/jUmSDwq+fLVhHIIj9MIJ6Bv7u3ItChG8vQ==}
|
||||
engines: {node: '>=8.0.0'}
|
||||
hasBin: true
|
||||
dependencies:
|
||||
commander: 2.20.3
|
||||
lodash.flowright: 3.5.0
|
||||
lodash.get: 4.4.2
|
||||
lodash.isobject: 3.0.2
|
||||
pako: 1.0.11
|
||||
pretty-bytes: 5.6.0
|
||||
prettyjson: 1.2.5
|
||||
utf8-length: 0.0.1
|
||||
dev: false
|
||||
|
||||
/json-parse-even-better-errors@2.3.1:
|
||||
resolution: {integrity: sha512-xyFwyhro/JEof6Ghe2iz2NcXoj2sloNsWr/XsERDK/oiPCfaNhl5ONfp+jQdAZRQQ0IJWNzH9zIZF7li91kh2w==}
|
||||
dev: true
|
||||
@@ -6781,18 +6804,6 @@ packages:
|
||||
resolution: {integrity: sha512-FT1yDzDYEoYWhnSGnpE/4Kj1fLZkDFyqRb7fNt6FdYOSxlUWAtp42Eh6Wb0rGIv/m9Bgo7x4GhQbm5Ys4SG5ow==}
|
||||
dev: true
|
||||
|
||||
/lodash.flowright@3.5.0:
|
||||
resolution: {integrity: sha512-YxTYuodkvyINbDInmFcGGvkQwoAuoGUYosqstRTr5eq63GQt7WQ2xFU0wG1UfdbKYPwevd3zWDd6ybEE2g6qvA==}
|
||||
dev: false
|
||||
|
||||
/lodash.get@4.4.2:
|
||||
resolution: {integrity: sha512-z+Uw/vLuy6gQe8cfaFWD7p0wVv8fJl3mbzXh33RS+0oW2wvUqiRXiQ69gLWSLpgB5/6sU+r6BlQR0MBILadqTQ==}
|
||||
dev: false
|
||||
|
||||
/lodash.isobject@3.0.2:
|
||||
resolution: {integrity: sha512-3/Qptq2vr7WeJbB4KHUSKlq8Pl7ASXi3UG6CMbBm8WRtXi8+GHm7mKaU3urfpSEzWe2wCIChs6/sdocUsTKJiA==}
|
||||
dev: false
|
||||
|
||||
/lodash.merge@4.6.2:
|
||||
resolution: {integrity: sha512-0KpjqXRVvrYyCsX1swR/XTK0va6VQkQM6MNo7PqW77ByjAhoARA8EfrP1N4+KlKj8YS0ZUCtRT/YUuhyYDujIQ==}
|
||||
dev: true
|
||||
@@ -7040,6 +7051,7 @@ packages:
|
||||
|
||||
/minimist@1.2.8:
|
||||
resolution: {integrity: sha512-2yyAR8qBkN3YuheJanUpWC5U3bb5osDywNB8RzDVlDwDHbocAJveqqj1u8+SVD7jkWT4yvsHCpWqqWqAxb0zCA==}
|
||||
dev: true
|
||||
|
||||
/mlly@1.4.0:
|
||||
resolution: {integrity: sha512-ua8PAThnTwpprIaU47EPeZ/bPUVp2QYBbWMphUQpVdBI3Lgqzm5KZQ45Agm3YJedHXaIHl6pBGabaLSUPPSptg==}
|
||||
@@ -7358,10 +7370,6 @@ packages:
|
||||
resolution: {integrity: sha512-R4nPAVTAU0B9D35/Gk3uJf/7XYbQcyohSKdvAxIRSNghFl4e71hVoGnBNQz9cWaXxO2I10KTC+3jMdvvoKw6dQ==}
|
||||
engines: {node: '>=6'}
|
||||
|
||||
/pako@1.0.11:
|
||||
resolution: {integrity: sha512-4hLB8Py4zZce5s4yd9XzopqwVv/yGNhV1Bl8NTmCq1763HeK2+EwVTv+leGeL13Dnh2wfbqowVPXCIO0z4taYw==}
|
||||
dev: false
|
||||
|
||||
/param-case@2.1.1:
|
||||
resolution: {integrity: sha512-eQE845L6ot89sk2N8liD8HAuH4ca6Vvr7VWAWwt7+kvvG5aBcPmmphQ68JsEG2qa9n1TykS2DLeMt363AAH8/w==}
|
||||
dependencies:
|
||||
@@ -7594,6 +7602,7 @@ packages:
|
||||
/pretty-bytes@5.6.0:
|
||||
resolution: {integrity: sha512-FFw039TmrBqFK8ma/7OL3sDz/VytdtJr044/QUJtH0wK9lb9jLq9tJyIxUwtQJHwar2BqtiA4iCWSwo9JLkzFg==}
|
||||
engines: {node: '>=6'}
|
||||
dev: true
|
||||
|
||||
/pretty-bytes@6.1.0:
|
||||
resolution: {integrity: sha512-Rk753HI8f4uivXi4ZCIYdhmG1V+WKzvRMg/X+M42a6t7D07RcmopXJMDNk6N++7Bl75URRGsb40ruvg7Hcp2wQ==}
|
||||
@@ -7609,14 +7618,6 @@ packages:
|
||||
react-is: 18.2.0
|
||||
dev: true
|
||||
|
||||
/prettyjson@1.2.5:
|
||||
resolution: {integrity: sha512-rksPWtoZb2ZpT5OVgtmy0KHVM+Dca3iVwWY9ifwhcexfjebtgjg3wmrUt9PvJ59XIYBcknQeYHD8IAnVlh9lAw==}
|
||||
hasBin: true
|
||||
dependencies:
|
||||
colors: 1.4.0
|
||||
minimist: 1.2.8
|
||||
dev: false
|
||||
|
||||
/prosemirror-changeset@2.2.1:
|
||||
resolution: {integrity: sha512-J7msc6wbxB4ekDFj+n9gTW/jav/p53kdlivvuppHsrZXCaQdVgRghoZbSS3kwrRyAstRVQ4/+u5k7YfLgkkQvQ==}
|
||||
dependencies:
|
||||
@@ -9073,14 +9074,14 @@ packages:
|
||||
requires-port: 1.0.0
|
||||
dev: true
|
||||
|
||||
/utf8-length@0.0.1:
|
||||
resolution: {integrity: sha512-j/XH2ftofBiobnyApxlN/J6j/ixwT89WEjDcjT66d2i0+GIn9RZfzt8lpEXXE4jUe4NsjBSUq70kS2euQ4nnMw==}
|
||||
dev: false
|
||||
|
||||
/util-deprecate@1.0.2:
|
||||
resolution: {integrity: sha512-EPD5q1uXyFxJpCrLnCc1nHnq3gOa6DZBocAIiI2TaSCA7VCJ1UJDMagCzIkXNsUYfD1daK//LTEQ8xiIbrHtcw==}
|
||||
dev: true
|
||||
|
||||
/uuid-random@1.3.2:
|
||||
resolution: {integrity: sha512-UOzej0Le/UgkbWEO8flm+0y+G+ljUon1QWTEZOq1rnMAsxo2+SckbiZdKzAHHlVh6gJqI1TjC/xwgR50MuCrBQ==}
|
||||
dev: false
|
||||
|
||||
/uuid@9.0.0:
|
||||
resolution: {integrity: sha512-MXcSTerfPa4uqyzStbRoTgt5XIe3x5+42+q1sDuy3R5MDk66URdLMOZe5aPX/SQd+kuYAh0FdP/pO28IkQyTeg==}
|
||||
dev: false
|
||||
|
||||
@@ -7,8 +7,15 @@ import sqlHljs from 'highlight.js/lib/languages/sql';
|
||||
import xmlHljs from 'highlight.js/lib/languages/xml';
|
||||
import yamlHljs from 'highlight.js/lib/languages/yaml';
|
||||
import iniHljs from 'highlight.js/lib/languages/ini';
|
||||
import bashHljs from 'highlight.js/lib/languages/bash';
|
||||
import markdownHljs from 'highlight.js/lib/languages/markdown';
|
||||
import jsHljs from 'highlight.js/lib/languages/javascript';
|
||||
import cssHljs from 'highlight.js/lib/languages/css';
|
||||
import goHljs from 'highlight.js/lib/languages/go';
|
||||
import csharpHljs from 'highlight.js/lib/languages/csharp';
|
||||
import { Base64 } from 'js-base64';
|
||||
import { useCopy } from '@/composable/copy';
|
||||
import { useDownloadFileFromBase64 } from '@/composable/downloadBase64';
|
||||
|
||||
const props = withDefaults(
|
||||
defineProps<{
|
||||
@@ -17,12 +24,17 @@ const props = withDefaults(
|
||||
language?: string
|
||||
copyPlacement?: 'top-right' | 'bottom-right' | 'outside' | 'none'
|
||||
copyMessage?: string
|
||||
wordWrap?: boolean
|
||||
downloadFileName?: string
|
||||
downloadButtonText?: string
|
||||
}>(),
|
||||
{
|
||||
followHeightOf: null,
|
||||
language: 'txt',
|
||||
copyPlacement: 'top-right',
|
||||
copyMessage: 'Copy to clipboard',
|
||||
downloadFileName: '',
|
||||
downloadButtonText: 'Download',
|
||||
},
|
||||
);
|
||||
hljs.registerLanguage('sql', sqlHljs);
|
||||
@@ -31,13 +43,25 @@ hljs.registerLanguage('html', xmlHljs);
|
||||
hljs.registerLanguage('xml', xmlHljs);
|
||||
hljs.registerLanguage('yaml', yamlHljs);
|
||||
hljs.registerLanguage('toml', iniHljs);
|
||||
hljs.registerLanguage('bash', bashHljs);
|
||||
hljs.registerLanguage('markdown', markdownHljs);
|
||||
hljs.registerLanguage('css', cssHljs);
|
||||
hljs.registerLanguage('javascript', jsHljs);
|
||||
hljs.registerLanguage('go', goHljs);
|
||||
hljs.registerLanguage('csharp', csharpHljs);
|
||||
|
||||
const { value, language, followHeightOf, copyPlacement, copyMessage } = toRefs(props);
|
||||
const { value, language, followHeightOf, copyPlacement, copyMessage, downloadFileName, downloadButtonText } = toRefs(props);
|
||||
const { height } = followHeightOf.value ? useElementSize(followHeightOf) : { height: ref(null) };
|
||||
|
||||
const { copy, isJustCopied } = useCopy({ source: value, createToast: false });
|
||||
const tooltipText = computed(() => isJustCopied.value ? 'Copied!' : copyMessage.value);
|
||||
|
||||
const valueBase64 = computed(() => Base64.encode(value.value));
|
||||
const { download } = useDownloadFileFromBase64(
|
||||
{
|
||||
source: valueBase64,
|
||||
filename: downloadFileName,
|
||||
});
|
||||
</script>
|
||||
|
||||
<template>
|
||||
@@ -49,11 +73,16 @@ const tooltipText = computed(() => isJustCopied.value ? 'Copied!' : copyMessage.
|
||||
:style="height ? `min-height: ${height - 40 /* card padding */ + 10 /* negative margin compensation */}px` : ''"
|
||||
>
|
||||
<n-config-provider :hljs="hljs">
|
||||
<n-code :code="value" :language="language" :trim="false" data-test-id="area-content" />
|
||||
<n-code :code="value" :language="language" :word-wrap="wordWrap" :trim="false" data-test-id="area-content" />
|
||||
</n-config-provider>
|
||||
</n-scrollbar>
|
||||
<div absolute right-10px top-10px>
|
||||
<c-tooltip v-if="value" :tooltip="tooltipText" position="left">
|
||||
<div
|
||||
v-if="value && copyPlacement !== 'none'"
|
||||
absolute right-10px
|
||||
:top-10px="copyPlacement === 'top-right' ? '' : 'no'"
|
||||
:bottom-10px="copyPlacement === 'bottom-right' ? '' : 'no'"
|
||||
>
|
||||
<c-tooltip v-if="value && copyPlacement !== 'outside'" :tooltip="tooltipText" position="left">
|
||||
<c-button circle important:h-10 important:w-10 @click="copy()">
|
||||
<n-icon size="22" :component="Copy" />
|
||||
</c-button>
|
||||
@@ -65,6 +94,11 @@ const tooltipText = computed(() => isJustCopied.value ? 'Copied!' : copyMessage.
|
||||
{{ tooltipText }}
|
||||
</c-button>
|
||||
</div>
|
||||
<div v-if="downloadFileName !== '' && value !== ''" mt-5 flex justify-center>
|
||||
<c-button secondary @click="download">
|
||||
{{ downloadButtonText }}
|
||||
</c-button>
|
||||
</div>
|
||||
</div>
|
||||
</template>
|
||||
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
import { extension as getExtensionFromMimeType, extension as getMimeTypeFromExtension } from 'mime-types';
|
||||
import type { Ref } from 'vue';
|
||||
import type { MaybeRef, Ref } from 'vue';
|
||||
import _ from 'lodash';
|
||||
import { get } from '@vueuse/core';
|
||||
|
||||
export {
|
||||
getMimeTypeFromBase64,
|
||||
@@ -75,21 +76,11 @@ function downloadFromBase64({ sourceValue, filename, extension, fileMimeType }:
|
||||
}
|
||||
|
||||
function useDownloadFileFromBase64(
|
||||
{ source, filename, extension, fileMimeType }:
|
||||
{ source: Ref<string>; filename?: string; extension?: string; fileMimeType?: string }) {
|
||||
return {
|
||||
download() {
|
||||
downloadFromBase64({ sourceValue: source.value, filename, extension, fileMimeType });
|
||||
},
|
||||
};
|
||||
}
|
||||
|
||||
function useDownloadFileFromBase64Refs(
|
||||
{ source, filename, extension }:
|
||||
{ source: Ref<string>; filename?: Ref<string>; extension?: Ref<string> }) {
|
||||
{ source: MaybeRef<string>; filename?: MaybeRef<string>; extension?: MaybeRef<string> }) {
|
||||
return {
|
||||
download() {
|
||||
downloadFromBase64({ sourceValue: source.value, filename: filename?.value, extension: extension?.value });
|
||||
downloadFromBase64({ sourceValue: get(source), filename: get(filename), extension: get(extension) });
|
||||
},
|
||||
};
|
||||
}
|
||||
@@ -116,3 +107,13 @@ function previewImageFromBase64(base64String: string): HTMLImageElement {
|
||||
|
||||
return img;
|
||||
}
|
||||
|
||||
function useDownloadFileFromBase64Refs(
|
||||
{ source, filename, extension }:
|
||||
{ source: Ref<string>; filename?: Ref<string>; extension?: Ref<string> }) {
|
||||
return {
|
||||
download() {
|
||||
downloadFromBase64({ sourceValue: source.value, filename: filename?.value, extension: extension?.value });
|
||||
},
|
||||
};
|
||||
}
|
||||
@@ -0,0 +1,127 @@
|
||||
<script setup lang="ts">
|
||||
import slugify from '@sindresorhus/slugify';
|
||||
import ical, { ICalCalendarMethod } from 'ical-generator';
|
||||
import { Base64 } from 'js-base64';
|
||||
import { useDownloadFileFromBase64 } from '@/composable/downloadBase64';
|
||||
|
||||
interface Event {
|
||||
startend: [number, number]
|
||||
summary?: string
|
||||
description?: string
|
||||
location?: string
|
||||
url?: string
|
||||
}
|
||||
|
||||
const events = ref<Array<Event>>([{
|
||||
startend: [Date.now(), Date.now()],
|
||||
summary: 'An event',
|
||||
}]);
|
||||
function deleteEvent(index: number) {
|
||||
if (events.value.length === 1) {
|
||||
return;
|
||||
}
|
||||
events.value.splice(index, 1);
|
||||
}
|
||||
function addEvent() {
|
||||
const now = Date.now();
|
||||
events.value.push({
|
||||
startend: [now, now + 3600 * 1000],
|
||||
summary: 'An event',
|
||||
});
|
||||
}
|
||||
|
||||
const output = computed(() => {
|
||||
try {
|
||||
const calendar = ical({ name: events.value[0]?.summary || 'unamed' });
|
||||
|
||||
// A method is required for outlook to display event as an invitation
|
||||
calendar.method(ICalCalendarMethod.REQUEST);
|
||||
|
||||
for (const event of events.value) {
|
||||
calendar.createEvent({
|
||||
start: new Date(event.startend[0]).toUTCString(),
|
||||
end: new Date(event.startend[0]).toUTCString(),
|
||||
summary: event.summary,
|
||||
description: event.description,
|
||||
location: event.location,
|
||||
url: event.url,
|
||||
});
|
||||
}
|
||||
|
||||
return { ical: calendar.toString() };
|
||||
}
|
||||
catch (e: any) {
|
||||
return { error: e.toString() };
|
||||
}
|
||||
});
|
||||
const outputBase64 = computed(() => Base64.encode(output.value?.ical || ''));
|
||||
const customOutputFileName = ref('');
|
||||
const outputFileName = computed(() => {
|
||||
if (customOutputFileName.value) {
|
||||
return customOutputFileName.value;
|
||||
}
|
||||
|
||||
return slugify(events.value[0]?.summary || 'unamed');
|
||||
});
|
||||
const { download } = useDownloadFileFromBase64(
|
||||
{
|
||||
source: outputBase64,
|
||||
filename: outputFileName,
|
||||
extension: 'ics',
|
||||
});
|
||||
</script>
|
||||
|
||||
<template>
|
||||
<div>
|
||||
<div mb-2 flex items-baseline gap-2>
|
||||
<c-input-text
|
||||
v-model:value="outputFileName"
|
||||
placeholder="Generated if empty"
|
||||
label="Output filename:"
|
||||
label-position="left"
|
||||
mb-2
|
||||
/>
|
||||
<c-button v-if="output.ical" @click="download">
|
||||
Download ICS
|
||||
</c-button>
|
||||
</div>
|
||||
|
||||
<c-alert v-if="output.error" mb-2>
|
||||
{{ output.error }}
|
||||
</c-alert>
|
||||
|
||||
<c-card v-for="(event, index) in events" :key="index" mb-2>
|
||||
<n-form-item label="Title:" label-placement="left">
|
||||
<n-input v-model:value="event.summary" :allow-input="(value:string) => !!value" />
|
||||
</n-form-item>
|
||||
<n-form-item label="Dates and hours:" label-placement="left">
|
||||
<n-date-picker v-model:value="event.startend" type="datetimerange" />
|
||||
</n-form-item>
|
||||
<c-input-text
|
||||
v-model:value="event.description"
|
||||
label="Description"
|
||||
placeholder="Put a description here"
|
||||
multiline
|
||||
rows="2"
|
||||
mb-2
|
||||
/>
|
||||
<c-input-text
|
||||
v-model:value="event.url"
|
||||
label="Url:"
|
||||
label-position="left"
|
||||
placeholder="Put an url here"
|
||||
mb-2
|
||||
/>
|
||||
<div flex justify-center>
|
||||
<c-button @click="deleteEvent(index)">
|
||||
Delete
|
||||
</c-button>
|
||||
</div>
|
||||
</c-card>
|
||||
<div mt-2 flex justify-center>
|
||||
<c-button @click="addEvent">
|
||||
Add Event
|
||||
</c-button>
|
||||
</div>
|
||||
</div>
|
||||
</template>
|
||||
@@ -0,0 +1,12 @@
|
||||
import { CalendarEvent } from '@vicons/tabler';
|
||||
import { defineTool } from '../tool';
|
||||
|
||||
export const tool = defineTool({
|
||||
name: 'ICAL Generator',
|
||||
path: '/ical-generator',
|
||||
description: 'Generate ICAL/ICS file from event infos',
|
||||
keywords: ['ical', 'calendar', 'event', 'generator'],
|
||||
component: () => import('./ical-generator.vue'),
|
||||
icon: CalendarEvent,
|
||||
createdAt: new Date('2024-08-15'),
|
||||
});
|
||||
@@ -0,0 +1,82 @@
|
||||
import { describe, expect, it } from 'vitest';
|
||||
import { mergeIcals } from './ical-merger.service';
|
||||
|
||||
describe('ical-merger', () => {
|
||||
describe('mergeIcals', () => {
|
||||
it('merge correctly', () => {
|
||||
expect(mergeIcals([
|
||||
`BEGIN:VCALENDAR
|
||||
PRODID:-//xyz Corp//NONSGML PDA Calendar Version 1.0//EN
|
||||
VERSION:2.0
|
||||
BEGIN:VEVENT
|
||||
DTSTAMP:19960704T120000Z
|
||||
UID:uid1@example.com
|
||||
ORGANIZER:mailto:jsmith@example.com
|
||||
DTSTART:19960918T143000Z
|
||||
DTEND:19960920T220000Z
|
||||
STATUS:CONFIRMED
|
||||
CATEGORIES:CONFERENCE
|
||||
SUMMARY:Networld+Interop Conference
|
||||
DESCRIPTION:Networld+Interop Conference
|
||||
and Exhibit\\nAtlanta World Congress Center\\n
|
||||
Atlanta\\, Georgia
|
||||
END:VEVENT
|
||||
END:VCALENDAR`,
|
||||
`BEGIN:VCALENDAR
|
||||
METHOD:xyz
|
||||
VERSION:2.0
|
||||
PRODID:-//ABC Corporation//NONSGML My Product//EN
|
||||
BEGIN:VEVENT
|
||||
DTSTAMP:19970324T120000Z
|
||||
SEQUENCE:0
|
||||
UID:uid3@example.com
|
||||
ORGANIZER:mailto:jdoe@example.com
|
||||
ATTENDEE;RSVP=TRUE:mailto:jsmith@example.com
|
||||
DTSTART:19970324T123000Z
|
||||
DTEND:19970324T210000Z
|
||||
CATEGORIES:MEETING,PROJECT
|
||||
CLASS:PUBLIC
|
||||
SUMMARY:Calendaring Interoperability Planning Meeting
|
||||
DESCRIPTION:Discuss how we can test c&s interoperability\\n
|
||||
using iCalendar and other IETF standards.
|
||||
LOCATION:LDB Lobby
|
||||
ATTACH;FMTTYPE=application/postscript:ftp://example.com/pub/
|
||||
conf/bkgrnd.ps
|
||||
END:VEVENT
|
||||
END:VCALENDAR`,
|
||||
])).to.eq(
|
||||
`BEGIN:VCALENDAR
|
||||
PRODID:it-tools-ical-merger
|
||||
VERSION:1.0
|
||||
BEGIN:VEVENT
|
||||
DTSTAMP:19960704T120000Z
|
||||
UID:uid1@example.com
|
||||
ORGANIZER:mailto:jsmith@example.com
|
||||
DTSTART:19960918T143000Z
|
||||
DTEND:19960920T220000Z
|
||||
STATUS:CONFIRMED
|
||||
CATEGORIES:CONFERENCE
|
||||
SUMMARY:Networld+Interop Conference
|
||||
DESCRIPTION:Networld+Interop Conference and Exhibit\\nAtlanta World Congress
|
||||
Center\\nAtlanta\\, Georgia
|
||||
END:VEVENT
|
||||
BEGIN:VEVENT
|
||||
DTSTAMP:19970324T120000Z
|
||||
SEQUENCE:0
|
||||
UID:uid3@example.com
|
||||
ORGANIZER:mailto:jdoe@example.com
|
||||
ATTENDEE;RSVP=TRUE:mailto:jsmith@example.com
|
||||
DTSTART:19970324T123000Z
|
||||
DTEND:19970324T210000Z
|
||||
CATEGORIES:MEETING,PROJECT
|
||||
CLASS:PUBLIC
|
||||
SUMMARY:Calendaring Interoperability Planning Meeting
|
||||
DESCRIPTION:Discuss how we can test c&s interoperability\\nusing iCalendar a
|
||||
nd other IETF standards.
|
||||
LOCATION:LDB Lobby
|
||||
ATTACH;FMTTYPE=application/postscript:ftp://example.com/pub/conf/bkgrnd.ps
|
||||
END:VEVENT
|
||||
END:VCALENDAR`.replace(/\n/g, '\r\n'));
|
||||
});
|
||||
});
|
||||
});
|
||||
@@ -0,0 +1,45 @@
|
||||
import ICAL from 'ical.js';
|
||||
|
||||
export function mergeIcals(inputs: Array<string>, options: {
|
||||
calname?: string
|
||||
timezone?: string
|
||||
caldesc?: string
|
||||
} = {}) {
|
||||
let calendar;
|
||||
for (const input of inputs) {
|
||||
try {
|
||||
const jcal = ICAL.parse(input);
|
||||
const cal = new ICAL.Component(jcal);
|
||||
|
||||
if (!calendar) {
|
||||
calendar = cal;
|
||||
calendar.updatePropertyWithValue('prodid', 'it-tools-ical-merger');
|
||||
calendar.updatePropertyWithValue('version', '1.0');
|
||||
|
||||
if (options.calname) {
|
||||
calendar.updatePropertyWithValue('x-wr-calname', options.calname);
|
||||
}
|
||||
if (options.timezone) {
|
||||
calendar.updatePropertyWithValue('x-wr-timezone', options.timezone);
|
||||
}
|
||||
if (options.caldesc) {
|
||||
calendar.updatePropertyWithValue('x-wr-caldesc', options.caldesc);
|
||||
}
|
||||
}
|
||||
else {
|
||||
for (const vevent of cal.getAllSubcomponents('vevent')) {
|
||||
calendar.addSubcomponent(vevent);
|
||||
}
|
||||
}
|
||||
}
|
||||
catch (e) {
|
||||
throw new Error(`Failed to merge: ${e}\n\nWith input: ${input}`);
|
||||
}
|
||||
}
|
||||
|
||||
if (!calendar) {
|
||||
throw new Error('No icals parsed successfully');
|
||||
}
|
||||
|
||||
return calendar.toString();
|
||||
}
|
||||
@@ -0,0 +1,96 @@
|
||||
<script setup lang="ts">
|
||||
import { mergeIcals } from './ical-merger.service';
|
||||
|
||||
const fileInputs = ref<Array<File>>([]);
|
||||
const mergedOutput = ref('');
|
||||
const calendarName = ref('');
|
||||
const calendarDescription = ref('');
|
||||
const errors = ref('');
|
||||
|
||||
function onUploads(files: Array<File>) {
|
||||
fileInputs.value = [...fileInputs.value, ...files];
|
||||
}
|
||||
function deleteFile(index: number) {
|
||||
fileInputs.value.splice(index, 1);
|
||||
}
|
||||
async function mergeFiles() {
|
||||
const fileBuffers: Array<string> = [];
|
||||
for (const file of fileInputs.value) {
|
||||
fileBuffers.push(await readFileAsString(file));
|
||||
}
|
||||
errors.value = '';
|
||||
mergedOutput.value = '';
|
||||
try {
|
||||
mergedOutput.value = mergeIcals(fileBuffers);
|
||||
}
|
||||
catch (e: any) {
|
||||
errors.value = e.toString();
|
||||
}
|
||||
}
|
||||
|
||||
function readFileAsString(file: File) {
|
||||
return new Promise<string>((resolve, reject) => {
|
||||
const fr = new FileReader();
|
||||
fr.onload = () => {
|
||||
resolve(fr.result as string || '');
|
||||
};
|
||||
fr.onerror = reject;
|
||||
fr.readAsText(file);
|
||||
});
|
||||
}
|
||||
</script>
|
||||
|
||||
<template>
|
||||
<div>
|
||||
<c-file-upload
|
||||
title="Drag and drop iCal file here, or click to select a file"
|
||||
multiple
|
||||
mb-2
|
||||
@files-upload="onUploads"
|
||||
/>
|
||||
|
||||
<n-form-item label="Title:" label-placement="left">
|
||||
<n-input v-model:value="calendarName" placeholder="Please input merge calendar title..." />
|
||||
</n-form-item>
|
||||
|
||||
<n-form-item label="Description:">
|
||||
<n-input v-model:value="calendarDescription" placeholder="Please input merged calendar description..." />
|
||||
</n-form-item>
|
||||
|
||||
<ul>
|
||||
<li v-for="(file, index) in fileInputs" :key="index" mb-1>
|
||||
<n-button mr-2 @click="deleteFile(index)">
|
||||
Delete
|
||||
</n-button>
|
||||
File to merge: {{ file.name }}
|
||||
</li>
|
||||
</ul>
|
||||
|
||||
<div flex justify-center>
|
||||
<n-button @click="mergeFiles">
|
||||
Merge iCal files
|
||||
</n-button>
|
||||
</div>
|
||||
|
||||
<n-divider />
|
||||
|
||||
<c-alert v-if="errors" mb-2>
|
||||
{{ errors }}
|
||||
</c-alert>
|
||||
|
||||
<textarea-copyable
|
||||
v-if="mergedOutput"
|
||||
v-model:value="mergedOutput"
|
||||
download-file-name="merge.ics"
|
||||
download-button-text="Download merged iCal"
|
||||
label="Merged ICAL"
|
||||
mb-2
|
||||
/>
|
||||
</div>
|
||||
</template>
|
||||
|
||||
<style lang="less" scoped>
|
||||
::v-deep(.n-upload-trigger) {
|
||||
width: 100%;
|
||||
}
|
||||
</style>
|
||||
@@ -0,0 +1,12 @@
|
||||
import { CalendarPlus } from '@vicons/tabler';
|
||||
import { defineTool } from '../tool';
|
||||
|
||||
export const tool = defineTool({
|
||||
name: 'iCal Merger',
|
||||
path: '/ical-merger',
|
||||
description: 'Merge many iCal file to a single',
|
||||
keywords: ['ical', 'ics', 'merger'],
|
||||
component: () => import('./ical-merger.vue'),
|
||||
icon: CalendarPlus,
|
||||
createdAt: new Date('2024-08-15'),
|
||||
});
|
||||
@@ -0,0 +1,96 @@
|
||||
<script setup lang="ts">
|
||||
import type { Ref } from 'vue';
|
||||
import ICAL from 'ical.js';
|
||||
|
||||
const inputType = ref<'file' | 'content'>('file');
|
||||
const icalContent = ref('');
|
||||
const fileInput = ref() as Ref<File | null>;
|
||||
const icalInfosRaw = computedAsync(async () => {
|
||||
const file = fileInput.value;
|
||||
const content = icalContent.value;
|
||||
try {
|
||||
if (inputType.value === 'file' && file) {
|
||||
const jcal = ICAL.parse(await readFileAsString(file));
|
||||
return new ICAL.Component(jcal);
|
||||
}
|
||||
else {
|
||||
const jcal = ICAL.parse(content);
|
||||
return new ICAL.Component(jcal);
|
||||
}
|
||||
}
|
||||
catch (e: any) {
|
||||
return {
|
||||
error: e.toString(),
|
||||
};
|
||||
}
|
||||
});
|
||||
|
||||
async function onUpload(file: File) {
|
||||
if (file) {
|
||||
fileInput.value = file;
|
||||
}
|
||||
}
|
||||
|
||||
watch(icalContent, (_, newValue) => {
|
||||
if (newValue !== '') {
|
||||
fileInput.value = null;
|
||||
}
|
||||
});
|
||||
|
||||
function readFileAsString(file: File) {
|
||||
return new Promise<string>((resolve, reject) => {
|
||||
const fr = new FileReader();
|
||||
fr.onload = () => {
|
||||
resolve(fr.result as string || '');
|
||||
};
|
||||
fr.onerror = reject;
|
||||
fr.readAsText(file);
|
||||
});
|
||||
}
|
||||
</script>
|
||||
|
||||
<template>
|
||||
<div>
|
||||
<n-radio-group v-model:value="inputType" name="radiogroup" mb-2 flex justify-center>
|
||||
<n-space>
|
||||
<n-radio
|
||||
value="file"
|
||||
label="File"
|
||||
/>
|
||||
<n-radio
|
||||
value="content"
|
||||
label="Content"
|
||||
/>
|
||||
</n-space>
|
||||
</n-radio-group>
|
||||
|
||||
<c-file-upload
|
||||
v-if="inputType === 'file'"
|
||||
title="Drag and drop iCal file here, or click to select a file"
|
||||
@file-upload="onUpload"
|
||||
/>
|
||||
|
||||
<c-input-text
|
||||
v-if="inputType === 'content'"
|
||||
v-model:value="icalContent"
|
||||
label="iCal Content"
|
||||
placeholder="Paste your iCal content here"
|
||||
multiline
|
||||
mb-2
|
||||
/>
|
||||
|
||||
<n-divider />
|
||||
|
||||
<textarea-copyable
|
||||
label="Parsed iCal"
|
||||
mb-2
|
||||
:value="JSON.stringify(icalInfosRaw, null, 2)"
|
||||
/>
|
||||
</div>
|
||||
</template>
|
||||
|
||||
<style lang="less" scoped>
|
||||
::v-deep(.n-upload-trigger) {
|
||||
width: 100%;
|
||||
}
|
||||
</style>
|
||||
@@ -0,0 +1,12 @@
|
||||
import { CalendarEvent } from '@vicons/tabler';
|
||||
import { defineTool } from '../tool';
|
||||
|
||||
export const tool = defineTool({
|
||||
name: 'ICAL File Parser',
|
||||
path: '/ical-parser',
|
||||
description: 'Parse ICAL/ICS file to event display',
|
||||
keywords: ['ical', 'ics', 'calendar', 'parser'],
|
||||
component: () => import('./ical-parser.vue'),
|
||||
icon: CalendarEvent,
|
||||
createdAt: new Date('2024-08-15'),
|
||||
});
|
||||
+6
-2
@@ -2,7 +2,7 @@ import { tool as base64FileConverter } from './base64-file-converter';
|
||||
import { tool as base64StringConverter } from './base64-string-converter';
|
||||
import { tool as basicAuthGenerator } from './basic-auth-generator';
|
||||
import { tool as emailNormalizer } from './email-normalizer';
|
||||
import { tool as jsonSizeAnalyzer } from './json-size-analyzer';
|
||||
import { tool as icalMerger } from './ical-merger';
|
||||
|
||||
import { tool as asciiTextDrawer } from './ascii-text-drawer';
|
||||
|
||||
@@ -13,6 +13,8 @@ import { tool as jsonToXml } from './json-to-xml';
|
||||
import { tool as regexTester } from './regex-tester';
|
||||
import { tool as regexMemo } from './regex-memo';
|
||||
import { tool as markdownToHtml } from './markdown-to-html';
|
||||
import { tool as icalParser } from './ical-parser';
|
||||
import { tool as icalGenerator } from './ical-generator';
|
||||
import { tool as pdfSignatureChecker } from './pdf-signature-checker';
|
||||
import { tool as numeronymGenerator } from './numeronym-generator';
|
||||
import { tool as macAddressGenerator } from './mac-address-generator';
|
||||
@@ -152,7 +154,6 @@ export const toolsByCategory: ToolCategory[] = [
|
||||
crontabGenerator,
|
||||
jsonViewer,
|
||||
jsonMinify,
|
||||
jsonSizeAnalyzer,
|
||||
jsonToCsv,
|
||||
sqlPrettify,
|
||||
chmodCalculator,
|
||||
@@ -186,6 +187,9 @@ export const toolsByCategory: ToolCategory[] = [
|
||||
textDiff,
|
||||
numeronymGenerator,
|
||||
asciiTextDrawer,
|
||||
icalGenerator,
|
||||
icalParser,
|
||||
icalMerger,
|
||||
],
|
||||
},
|
||||
{
|
||||
|
||||
@@ -1,12 +0,0 @@
|
||||
import { FileAnalytics } from '@vicons/tabler';
|
||||
import { defineTool } from '../tool';
|
||||
|
||||
export const tool = defineTool({
|
||||
name: 'Json Size Analyzer',
|
||||
path: '/json-size-analyzer',
|
||||
description: 'Measure JSON nodes relative weights',
|
||||
keywords: ['json', 'size', 'analyzer'],
|
||||
component: () => import('./json-size-analyzer.vue'),
|
||||
icon: FileAnalytics,
|
||||
createdAt: new Date('2024-07-14'),
|
||||
});
|
||||
-13
@@ -1,13 +0,0 @@
|
||||
declare module 'json-analyzer' {
|
||||
export default function analyze({
|
||||
json,
|
||||
verbose,
|
||||
maxDepth,
|
||||
target,
|
||||
}: {
|
||||
json: any,
|
||||
verbose: boolean,
|
||||
maxDepth: number,
|
||||
target: string,
|
||||
});
|
||||
}
|
||||
@@ -1,113 +0,0 @@
|
||||
import { describe, expect, it } from 'vitest';
|
||||
import { getJsonUsageTreeNodes } from './json-size-analyzer.service';
|
||||
|
||||
describe('json-size-analyzer', () => {
|
||||
describe('getJsonUsageTreeNodes', () => {
|
||||
it('return correct tree nodes structures', () => {
|
||||
expect(getJsonUsageTreeNodes([{ a: [1, 2, 3] }, { b: 'a' }])).to.deep.eq({
|
||||
children: [
|
||||
{
|
||||
children: [
|
||||
{
|
||||
children: [
|
||||
{
|
||||
children: [],
|
||||
key: '$.[0].a.[0]',
|
||||
label: '$.[0].a.[0]: 1 B(26 B gzip)',
|
||||
},
|
||||
{
|
||||
children: [],
|
||||
key: '$.[0].a.[1]',
|
||||
label: '$.[0].a.[1]: 1 B(24 B gzip)',
|
||||
},
|
||||
{
|
||||
children: [],
|
||||
key: '$.[0].a.[2]',
|
||||
label: '$.[0].a.[2]: 1 B(25 B gzip)',
|
||||
},
|
||||
],
|
||||
key: '$.[0].a',
|
||||
label: '$.[0].a: 7 B(35 B gzip) ; 28.000% of parent ; biggest child node: \'0\'',
|
||||
},
|
||||
],
|
||||
key: '$.[0]',
|
||||
label: '$.[0]: 13 B(43 B gzip) ; 52.000% of parent ; biggest child node: \'a\'',
|
||||
},
|
||||
{
|
||||
children: [
|
||||
{
|
||||
children: [],
|
||||
key: '$.[1].b',
|
||||
label: '$.[1].b: 1 B(25 B gzip)',
|
||||
},
|
||||
],
|
||||
key: '$.[1]',
|
||||
label: '$.[1]: 9 B(34 B gzip) ; 36.000% of parent ; biggest child node: \'b\'',
|
||||
},
|
||||
],
|
||||
key: '$',
|
||||
label: '$: 25 B(61 B gzip) ; 100.00% of parent ; biggest child node: \'0\'',
|
||||
});
|
||||
expect(getJsonUsageTreeNodes({ a: { b: [1, 2, 3], c: 12 } })).to.deep.eq({
|
||||
children: [
|
||||
{
|
||||
children: [
|
||||
{
|
||||
children: [
|
||||
{
|
||||
children: [],
|
||||
key: '$.a.b.[0]',
|
||||
label: '$.a.b.[0]: 1 B(26 B gzip)',
|
||||
},
|
||||
{
|
||||
children: [],
|
||||
key: '$.a.b.[1]',
|
||||
label: '$.a.b.[1]: 1 B(24 B gzip)',
|
||||
},
|
||||
{
|
||||
children: [],
|
||||
key: '$.a.b.[2]',
|
||||
label: '$.a.b.[2]: 1 B(25 B gzip)',
|
||||
},
|
||||
],
|
||||
key: '$.a.b',
|
||||
label: '$.a.b: 7 B(35 B gzip) ; 26.923% of parent ; biggest child node: \'0\'',
|
||||
},
|
||||
{
|
||||
children: [],
|
||||
key: '$.a.c',
|
||||
label: '$.a.c: 2 B(24 B gzip)',
|
||||
},
|
||||
],
|
||||
key: '$.a',
|
||||
label: '$.a: 20 B(50 B gzip) ; 76.923% of parent ; biggest child node: \'b\'',
|
||||
},
|
||||
],
|
||||
key: '$',
|
||||
label: '$: 26 B(63 B gzip) ; 100.00% of parent ; biggest child node: \'a\'',
|
||||
});
|
||||
expect(getJsonUsageTreeNodes({ a: { b: 'azerty', c: 'ueop' } })).to.deep.eq({
|
||||
children: [
|
||||
{
|
||||
children: [
|
||||
{
|
||||
children: [],
|
||||
key: '$.a.b',
|
||||
label: '$.a.b: 6 B(30 B gzip)',
|
||||
},
|
||||
{
|
||||
children: [],
|
||||
key: '$.a.c',
|
||||
label: '$.a.c: 4 B(29 B gzip)',
|
||||
},
|
||||
],
|
||||
key: '$.a',
|
||||
label: '$.a: 25 B(51 B gzip) ; 80.645% of parent ; biggest child node: \'b\'',
|
||||
},
|
||||
],
|
||||
key: '$',
|
||||
label: '$: 31 B(61 B gzip) ; 100.00% of parent ; biggest child node: \'a\'',
|
||||
});
|
||||
});
|
||||
});
|
||||
});
|
||||
@@ -1,51 +0,0 @@
|
||||
import jsonAnalyzer from 'json-analyzer';
|
||||
|
||||
export interface Meta {
|
||||
__meta__: {
|
||||
size?: {
|
||||
value: number
|
||||
raw: string
|
||||
gzip: string
|
||||
}
|
||||
number_of_childs?: number
|
||||
parent_relative_percentage?: string
|
||||
biggest_node_child: string
|
||||
}
|
||||
}
|
||||
export type AnalysisNode = {
|
||||
[key: string]: object & Meta
|
||||
} & Meta;
|
||||
|
||||
export type TreeNode = {
|
||||
key: string
|
||||
label: string
|
||||
children: Array<TreeNode>
|
||||
} & Record<string, unknown>;
|
||||
|
||||
function getTreeNodes(obj: AnalysisNode, parentName: string): TreeNode {
|
||||
const childNodes = Object.entries(obj)
|
||||
.filter(([key, v]) => key !== '__meta__' && typeof v === 'object')
|
||||
.map(([k, v]) => ({
|
||||
key: (Number.isNaN(Number.parseInt(k, 10)) ? `.${k}` : `.[${k}]`),
|
||||
value: v as AnalysisNode,
|
||||
}));
|
||||
const biggest_child_node = obj.__meta__.biggest_node_child ? ` ; biggest child node: '${obj.__meta__.biggest_node_child}'` : '';
|
||||
const parent_relative_percentage = obj.__meta__.parent_relative_percentage ? ` ; ${obj.__meta__.parent_relative_percentage} of parent` : '';
|
||||
return {
|
||||
key: parentName,
|
||||
label: obj.__meta__
|
||||
? `${parentName}: ${obj.__meta__.size?.raw}(${obj.__meta__.size?.gzip} gzip)${parent_relative_percentage}${biggest_child_node}`
|
||||
: parentName,
|
||||
children: childNodes.map(childNode => getTreeNodes(childNode.value, parentName + childNode.key)),
|
||||
};
|
||||
}
|
||||
|
||||
export function getJsonUsageTreeNodes(jsonObj: any, maxDepth: number = 100, targetNode: string = ''): TreeNode {
|
||||
const analysis = jsonAnalyzer({
|
||||
json: jsonObj,
|
||||
verbose: true,
|
||||
maxDepth,
|
||||
target: targetNode,
|
||||
});
|
||||
return getTreeNodes(analysis, '$');
|
||||
}
|
||||
@@ -1,68 +0,0 @@
|
||||
<script setup lang="ts">
|
||||
import JSON5 from 'json5';
|
||||
import { getJsonUsageTreeNodes } from './json-size-analyzer.service';
|
||||
import { useValidation } from '@/composable/validation';
|
||||
|
||||
const json = ref('{"a": 1, "b": [1,2,3]}');
|
||||
const maxDepth = ref(100);
|
||||
const target = ref('');
|
||||
|
||||
const jsonSizes = computed(() => {
|
||||
const jsonObj = JSON5.parse(json.value);
|
||||
if (!jsonObj) {
|
||||
return null;
|
||||
}
|
||||
return [getJsonUsageTreeNodes(jsonObj, maxDepth.value - 1, target.value)];
|
||||
});
|
||||
const searchInAnalysis = ref('');
|
||||
|
||||
const jsonValidation = useValidation({
|
||||
source: json,
|
||||
rules: [
|
||||
{
|
||||
validator: (v) => {
|
||||
return JSON5.parse(v);
|
||||
},
|
||||
message: 'Provided JSON is not valid.',
|
||||
},
|
||||
],
|
||||
});
|
||||
</script>
|
||||
|
||||
<template>
|
||||
<div style="max-width: 600px;">
|
||||
<c-card title="Input" mb-2>
|
||||
<c-input-text
|
||||
v-model:value="json"
|
||||
label="JSON"
|
||||
multiline
|
||||
placeholder="Put your JSON data here..."
|
||||
rows="5"
|
||||
:validation="jsonValidation"
|
||||
mb-2
|
||||
/>
|
||||
|
||||
<n-form-item label="Max Depth:" label-placement="left">
|
||||
<n-input-number v-model:value="maxDepth" :min="0" w-full />
|
||||
</n-form-item>
|
||||
|
||||
<c-input-text
|
||||
v-model:value="target"
|
||||
label="Target Node"
|
||||
placeholder="Where to start the analyze (ie, a[0].b.c)"
|
||||
mb-2
|
||||
/>
|
||||
</c-card>
|
||||
|
||||
<c-card v-if="jsonSizes" title="Analysis">
|
||||
<n-input v-model:value="searchInAnalysis" placeholder="Search in result" />
|
||||
<n-tree
|
||||
:show-irrelevant-nodes="false"
|
||||
:pattern="searchInAnalysis"
|
||||
:default-expand-all="true"
|
||||
:data="jsonSizes"
|
||||
block-line
|
||||
/>
|
||||
</c-card>
|
||||
</div>
|
||||
</template>
|
||||
Reference in new issue
Block a user