mirror of
https://github.com/sharevb/it-tools.git
synced 2026-11-24 14:50:17 +03:00
Compare commits
2
Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
8545fc6fa5 | ||
|
|
3aa887ce54 |
No files matched your search
Vendored
+7
-4
@@ -107,9 +107,9 @@ declare module '@vue/runtime-core' {
|
||||
Ipv4RangeExpander: typeof import('./src/tools/ipv4-range-expander/ipv4-range-expander.vue')['default']
|
||||
Ipv4SubnetCalculator: typeof import('./src/tools/ipv4-subnet-calculator/ipv4-subnet-calculator.vue')['default']
|
||||
Ipv6UlaGenerator: typeof import('./src/tools/ipv6-ula-generator/ipv6-ula-generator.vue')['default']
|
||||
Iso3166Searcher: typeof import('./src/tools/iso-3166-searcher/iso-3166-searcher.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']
|
||||
@@ -130,7 +130,6 @@ declare module '@vue/runtime-core' {
|
||||
MenuLayout: typeof import('./src/components/MenuLayout.vue')['default']
|
||||
MetaTagGenerator: typeof import('./src/tools/meta-tag-generator/meta-tag-generator.vue')['default']
|
||||
MimeTypes: typeof import('./src/tools/mime-types/mime-types.vue')['default']
|
||||
NA: typeof import('naive-ui')['NA']
|
||||
NavbarButtons: typeof import('./src/components/NavbarButtons.vue')['default']
|
||||
NCheckbox: typeof import('naive-ui')['NCheckbox']
|
||||
NCollapseTransition: typeof import('naive-ui')['NCollapseTransition']
|
||||
@@ -140,11 +139,15 @@ declare module '@vue/runtime-core' {
|
||||
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']
|
||||
NLayout: typeof import('naive-ui')['NLayout']
|
||||
NLayoutSider: typeof import('naive-ui')['NLayoutSider']
|
||||
NMenu: typeof import('naive-ui')['NMenu']
|
||||
NSpace: typeof import('naive-ui')['NSpace']
|
||||
NTable: typeof import('naive-ui')['NTable']
|
||||
NScrollbar: typeof import('naive-ui')['NScrollbar']
|
||||
NSlider: typeof import('naive-ui')['NSlider']
|
||||
NSwitch: typeof import('naive-ui')['NSwitch']
|
||||
NTree: typeof import('naive-ui')['NTree']
|
||||
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']
|
||||
|
||||
+1
-2
@@ -54,7 +54,6 @@
|
||||
"change-case": "^4.1.2",
|
||||
"colord": "^2.9.3",
|
||||
"composerize-ts": "^0.6.2",
|
||||
"countries-db": "^1.2.0",
|
||||
"country-code-lookup": "^0.1.0",
|
||||
"cron-validator": "^1.3.1",
|
||||
"cronstrue": "^2.26.0",
|
||||
@@ -69,8 +68,8 @@
|
||||
"highlight.js": "^11.7.0",
|
||||
"iarna-toml-esm": "^3.0.5",
|
||||
"ibantools": "^4.3.3",
|
||||
"iso-639-1": "^3.1.3",
|
||||
"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
+51
-17
@@ -59,9 +59,6 @@ dependencies:
|
||||
composerize-ts:
|
||||
specifier: ^0.6.2
|
||||
version: 0.6.2
|
||||
countries-db:
|
||||
specifier: ^1.2.0
|
||||
version: 1.2.0
|
||||
country-code-lookup:
|
||||
specifier: ^0.1.0
|
||||
version: 0.1.0
|
||||
@@ -104,12 +101,12 @@ dependencies:
|
||||
ibantools:
|
||||
specifier: ^4.3.3
|
||||
version: 4.3.3
|
||||
iso-639-1:
|
||||
specifier: ^3.1.3
|
||||
version: 3.1.3
|
||||
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
|
||||
@@ -4570,6 +4567,11 @@ 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'}
|
||||
@@ -4663,10 +4665,6 @@ packages:
|
||||
browserslist: 4.22.1
|
||||
dev: true
|
||||
|
||||
/countries-db@1.2.0:
|
||||
resolution: {integrity: sha512-eZQgxVsNSRQ4yv9xQbgyR1psJBHDBhnhhU4OMXXUdrfbWW9gaiglKgueTq3ZWGuvxoR78g2ljVFsJmEptfNPmw==}
|
||||
dev: false
|
||||
|
||||
/country-code-lookup@0.1.0:
|
||||
resolution: {integrity: sha512-IOI66HEG+8bXfWPy+sTzuN7161vmDZOHg1wgIPFf3WfD73FeLajnn6C+fnxOIa9RL1WRBDMXQQWW/FOaOYaQ3w==}
|
||||
dev: false
|
||||
@@ -6502,11 +6500,6 @@ packages:
|
||||
resolution: {integrity: sha512-RHxMLp9lnKHGHRng9QFhRCMbYAcVpn69smSGcq3f36xjgVVWThj4qqLbTLlq7Ssj8B+fIQ1EuCEGI2lKsyQeIw==}
|
||||
dev: true
|
||||
|
||||
/iso-639-1@3.1.3:
|
||||
resolution: {integrity: sha512-1jz0Wh9hyLMRwqEPchb/KZCiTqfFWtc9R3nm7GHPygBAKS8wdKJ3FH4lvLsri6UtAE5Kz5SnowtXZa//6bqMyw==}
|
||||
engines: {node: '>=6.0'}
|
||||
dev: false
|
||||
|
||||
/isobject@3.0.1:
|
||||
resolution: {integrity: sha512-WhB9zCku7EGTj/HQQRz5aUQEUeoQZH2bWcltRErOpymJ4boYE6wL9Tbr23krRPSZ+C5zqNSrSw+Cc7sZZ4b7vg==}
|
||||
engines: {node: '>=0.10.0'}
|
||||
@@ -6634,6 +6627,21 @@ 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
|
||||
@@ -6773,6 +6781,18 @@ 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
|
||||
@@ -7020,7 +7040,6 @@ packages:
|
||||
|
||||
/minimist@1.2.8:
|
||||
resolution: {integrity: sha512-2yyAR8qBkN3YuheJanUpWC5U3bb5osDywNB8RzDVlDwDHbocAJveqqj1u8+SVD7jkWT4yvsHCpWqqWqAxb0zCA==}
|
||||
dev: true
|
||||
|
||||
/mlly@1.4.0:
|
||||
resolution: {integrity: sha512-ua8PAThnTwpprIaU47EPeZ/bPUVp2QYBbWMphUQpVdBI3Lgqzm5KZQ45Agm3YJedHXaIHl6pBGabaLSUPPSptg==}
|
||||
@@ -7339,6 +7358,10 @@ 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:
|
||||
@@ -7571,7 +7594,6 @@ 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==}
|
||||
@@ -7587,6 +7609,14 @@ 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:
|
||||
@@ -9043,6 +9073,10 @@ 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
|
||||
|
||||
+2
-2
@@ -2,6 +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 asciiTextDrawer } from './ascii-text-drawer';
|
||||
|
||||
@@ -12,7 +13,6 @@ 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 iso3166Searcher } from './iso-3166-searcher';
|
||||
import { tool as pdfSignatureChecker } from './pdf-signature-checker';
|
||||
import { tool as numeronymGenerator } from './numeronym-generator';
|
||||
import { tool as macAddressGenerator } from './mac-address-generator';
|
||||
@@ -152,6 +152,7 @@ export const toolsByCategory: ToolCategory[] = [
|
||||
crontabGenerator,
|
||||
jsonViewer,
|
||||
jsonMinify,
|
||||
jsonSizeAnalyzer,
|
||||
jsonToCsv,
|
||||
sqlPrettify,
|
||||
chmodCalculator,
|
||||
@@ -185,7 +186,6 @@ export const toolsByCategory: ToolCategory[] = [
|
||||
textDiff,
|
||||
numeronymGenerator,
|
||||
asciiTextDrawer,
|
||||
iso3166Searcher,
|
||||
],
|
||||
},
|
||||
{
|
||||
|
||||
-35
@@ -1,35 +0,0 @@
|
||||
declare module 'countries-db'{
|
||||
export interface CountryInfo {
|
||||
id: string
|
||||
name: string
|
||||
officialName: string
|
||||
emoji: string
|
||||
emojiUnicode: string
|
||||
iso2: string
|
||||
iso3: string
|
||||
isoNumeric: string
|
||||
geonameId: number
|
||||
continentId: string
|
||||
population: number
|
||||
elevation: number
|
||||
areaSqKm: number
|
||||
coordinates: {
|
||||
latitude: number
|
||||
longitude: number
|
||||
},
|
||||
timezones: Array<string>
|
||||
domain: string
|
||||
currencyCode: string
|
||||
currencyName: string
|
||||
postalCodeFormat: string
|
||||
postalCodeRegex: string
|
||||
phoneCode: string
|
||||
neighborCountryIds: Array<string>
|
||||
languages: Array<string>
|
||||
locales: Array<string>
|
||||
}
|
||||
|
||||
export function getAllCountries(): {[id:string]: CountryInfo};
|
||||
export function getCountry(id: string, property: string): string | Array<string> | number;
|
||||
export function getCountry(id: string): CountryInfo;
|
||||
}
|
||||
@@ -1,12 +0,0 @@
|
||||
import { Flag } from '@vicons/tabler';
|
||||
import { defineTool } from '../tool';
|
||||
|
||||
export const tool = defineTool({
|
||||
name: 'ISO 3166 Country Codes Searcher',
|
||||
path: '/iso-3166-searcher',
|
||||
description: 'Allow searching for Country Code (ISO 3166) and info',
|
||||
keywords: ['iso', 'iso2', 'iso3', 'phone', 'currency', 'timezones', 'domain', 'lang', 'iso3166', 'country', 'ccltd', 'searcher'],
|
||||
component: () => import('./iso-3166-searcher.vue'),
|
||||
icon: Flag,
|
||||
createdAt: new Date('2024-04-20'),
|
||||
});
|
||||
@@ -1,104 +0,0 @@
|
||||
<script setup lang="ts">
|
||||
import CountriesDB from 'countries-db';
|
||||
import ISO6391 from 'iso-639-1';
|
||||
import { useFuzzySearch } from '@/composable/fuzzySearch';
|
||||
import useDebouncedRef from '@/composable/debouncedref';
|
||||
|
||||
const searchQuery = useDebouncedRef('', 500);
|
||||
const countriesSearchData = Object.entries(CountriesDB.getAllCountries()).map(([_, info]) => {
|
||||
return {
|
||||
iso2: info.iso2,
|
||||
iso3: info.iso3,
|
||||
domain: info.domain,
|
||||
name: `${info.name} ${info.officialName}`,
|
||||
info,
|
||||
};
|
||||
});
|
||||
const { searchResult } = useFuzzySearch({
|
||||
search: searchQuery,
|
||||
data: countriesSearchData,
|
||||
options: {
|
||||
keys: ['name', { name: 'iso3', weight: 3 }, { name: 'iso2', weight: 2 }, 'domain'],
|
||||
threshold: 0.3,
|
||||
isCaseSensitive: false,
|
||||
useExtendedSearch: true,
|
||||
},
|
||||
});
|
||||
|
||||
function langToName(code: string) {
|
||||
const name = ISO6391.getName(code);
|
||||
if (!name) {
|
||||
return code;
|
||||
}
|
||||
return `${code} (${name})`;
|
||||
}
|
||||
</script>
|
||||
|
||||
<template>
|
||||
<div mx-auto max-w-2400px important:flex-1>
|
||||
<div flex items-center gap-3>
|
||||
<c-input-text
|
||||
v-model:value="searchQuery"
|
||||
placeholder="Search Countries by name, iso2, iso3..."
|
||||
mx-auto max-w-600px
|
||||
>
|
||||
<template #prefix>
|
||||
<icon-mdi-search mr-6px color-black op-70 dark:color-white />
|
||||
</template>
|
||||
</c-input-text>
|
||||
</div>
|
||||
|
||||
<div v-if="searchQuery.trim().length > 0">
|
||||
<div
|
||||
v-if="searchResult.length === 0"
|
||||
mt-4
|
||||
text-20px
|
||||
font-bold
|
||||
>
|
||||
No results
|
||||
</div>
|
||||
|
||||
<div v-else>
|
||||
<div mt-4 text-20px font-bold>
|
||||
Search result
|
||||
</div>
|
||||
|
||||
<n-table>
|
||||
<thead>
|
||||
<th>Iso2/Iso3</th>
|
||||
<th>Name and Info</th>
|
||||
</thead>
|
||||
<tbody>
|
||||
<tr v-for="(result, ix) in searchResult" :key="ix">
|
||||
<td style="vertical-align: top">
|
||||
<input-copyable :value="result.iso2" />
|
||||
<input-copyable :value="result.iso3" />
|
||||
</td>
|
||||
<td>
|
||||
<input-copyable label-width="150px" label="Name" label-position="left" :value="result.name" mb-1 />
|
||||
<input-copyable label-width="150px" label="Official Name" label-position="left" :value="result.info.officialName" mb-1 />
|
||||
<input-copyable label-width="150px" label="Domain" label-position="left" :value="result.info.domain" mb-1 />
|
||||
<input-copyable label-width="150px" label="Emoji" label-position="left" :value="`${result.info.emoji} (${result.info.emojiUnicode})`" mb-1 />
|
||||
<input-copyable label-width="150px" label="ISO Num" label-position="left" :value="result.info.isoNumeric" mb-1 />
|
||||
<input-copyable label-width="150px" label="Continent" label-position="left" :value="result.info.continentId" mb-1 />
|
||||
<input-copyable label-width="150px" label="Elevation (m)" label-position="left" :value="result.info.elevation" mb-1 />
|
||||
<input-copyable label-width="150px" label="Population" label-position="left" :value="result.info.population" mb-1 />
|
||||
<input-copyable label-width="150px" label="Area (km²)" label-position="left" :value="result.info.areaSqKm" mb-1 />
|
||||
<input-copyable label-width="150px" label="Timezones" label-position="left" :value="result.info.timezones.join('\n')" mb-1 />
|
||||
<input-copyable label-width="150px" label="Currency" label-position="left" :value="`${result.info.currencyCode} / ${result.info.currencyName}`" mb-1 />
|
||||
<input-copyable label-width="150px" label="Postal Code" label-position="left" :value="`${result.info.postalCodeFormat} / ${result.info.postalCodeRegex}`" mb-1 />
|
||||
<input-copyable label-width="150px" label="Phone Code" label-position="left" :value="result.info.phoneCode" mb-1 />
|
||||
<input-copyable label-width="150px" label="Neighbor Countries" label-position="left" :value="result.info.neighborCountryIds.map(id => CountriesDB.getCountry(id, 'name')?.toString() || id).join(', ')" mb-1 />
|
||||
<input-copyable label-width="150px" label="Languages" label-position="left" :value="result.info.languages.map(langToName).join(', ')" mb-1 />
|
||||
<input-copyable label-width="150px" label="Locales" label-position="left" :value="result.info.locales.map(langToName).join(', ')" mb-1 />
|
||||
<!-- //NOSONAR --><n-a :href="`https://www.openstreetmap.org/#map=5/${result.info.coordinates.latitude}/${result.info.coordinates.longitude}`" target="_blank">
|
||||
> See on OpenStreetMap
|
||||
</n-a>
|
||||
</td>
|
||||
</tr>
|
||||
</tbody>
|
||||
</n-table>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</template>
|
||||
@@ -0,0 +1,12 @@
|
||||
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
@@ -0,0 +1,13 @@
|
||||
declare module 'json-analyzer' {
|
||||
export default function analyze({
|
||||
json,
|
||||
verbose,
|
||||
maxDepth,
|
||||
target,
|
||||
}: {
|
||||
json: any,
|
||||
verbose: boolean,
|
||||
maxDepth: number,
|
||||
target: string,
|
||||
});
|
||||
}
|
||||
@@ -0,0 +1,113 @@
|
||||
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\'',
|
||||
});
|
||||
});
|
||||
});
|
||||
});
|
||||
@@ -0,0 +1,51 @@
|
||||
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, '$');
|
||||
}
|
||||
@@ -0,0 +1,68 @@
|
||||
<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