Skip to content

Commit 4c424fc

Browse files
committed
Merge branch 'feat/vat-validator' into chore/all-my-stuffs
# Conflicts: # package.json # pnpm-lock.yaml # src/tools/index.ts
2 parents 975a863 + d38f9a2 commit 4c424fc

File tree

5 files changed

+81
-0
lines changed

5 files changed

+81
-0
lines changed

package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -174,6 +174,7 @@
174174
"jsonpath": "^1.1.1",
175175
"jsonar-mod": "^1.9.0",
176176
"jsstack.js": "^2.0.0",
177+
"jsvat-next": "^3.0.4",
177178
"jwt-decode": "^3.1.2",
178179
"korean-unpacker": "^1.0.3",
179180
"libphonenumber-js": "^1.10.28",

pnpm-lock.yaml

Lines changed: 8 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src/tools/index.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,7 @@ import { tool as stacktracePrettier } from './stacktrace-prettier';
4949
import { tool as dataTransferRateConverter } from './data-transfer-rate-converter';
5050
import { tool as dataStorageUnitConverter } from './data-storage-unit-converter';
5151
import { tool as unicodeSearch } from './unicode-search';
52+
import { tool as vatValidator } from './vat-validator';
5253

5354
import { tool as cssXpathConverter } from './css-xpath-converter';
5455
import { tool as cssSelectorsMemo } from './css-selectors-memo';
@@ -436,6 +437,7 @@ export const toolsByCategory: ToolCategory[] = [
436437
phoneParserAndFormatter,
437438
ibanValidatorAndParser,
438439
luhnValidator,
440+
vatValidator,
439441
],
440442
},
441443
];

src/tools/vat-validator/index.ts

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
import { ReceiptTax } from '@vicons/tabler';
2+
import { defineTool } from '../tool';
3+
4+
export const tool = defineTool({
5+
name: 'VAT Numbers Validator',
6+
path: '/vat-validator',
7+
description: 'Validate VAT Numbers',
8+
keywords: ['vat', 'validator'],
9+
component: () => import('./vat-validator.vue'),
10+
icon: ReceiptTax,
11+
createdAt: new Date('2024-08-15'),
12+
});
Lines changed: 58 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,58 @@
1+
<script setup lang="ts">
2+
import { checkVAT, countries } from 'jsvat-next';
3+
import type { CKeyValueListItems } from '@/ui/c-key-value-list/c-key-value-list.types';
4+
5+
const rawVATNumber = ref('BE0411905847');
6+
const vatInfos = computed<{ isValid: boolean; infos: CKeyValueListItems }>(() => {
7+
const vat = checkVAT(rawVATNumber.value, countries);
8+
if (vat == null) {
9+
return { isValid: false, infos: [] };
10+
}
11+
return {
12+
isValid: vat.isValid,
13+
infos: [
14+
{
15+
label: 'Is VAT Number valid ?',
16+
value: vat.isValid,
17+
},
18+
{
19+
label: 'Is VAT Number valid format ?',
20+
value: vat.isValidFormat,
21+
},
22+
{
23+
label: 'Cleaned VAT Number',
24+
value: vat.value,
25+
},
26+
{
27+
label: 'Country (name)',
28+
value: vat.country?.name || 'Unknown',
29+
},
30+
{
31+
label: 'Country (ISO2)',
32+
value: vat.country?.isoCode?.short || 'unk',
33+
},
34+
{
35+
label: 'Country (ISO3)',
36+
value: vat.country?.isoCode?.long || 'unk',
37+
},
38+
{
39+
label: 'Country (ISO Num)',
40+
value: vat.country?.isoCode?.numeric || 0,
41+
},
42+
],
43+
};
44+
});
45+
</script>
46+
47+
<template>
48+
<div>
49+
<c-input-text v-model:value="rawVATNumber" placeholder="Enter a VAT number to check for validity..." test-id="vat-input" mb-2 />
50+
<n-alert v-if="!vatInfos.isValid" type="error" mb-2>
51+
Invalid VAT Number.
52+
</n-alert>
53+
54+
<c-card v-if="vatInfos.infos.length > 0" title="VAT Number Infos">
55+
<c-key-value-list :items="vatInfos.infos" data-test-id="vat-info" />
56+
</c-card>
57+
</div>
58+
</template>

0 commit comments

Comments
 (0)