-
-
Notifications
You must be signed in to change notification settings - Fork 2.8k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(new tool): VAT Number Validator
- Loading branch information
Showing
6 changed files
with
89 additions
and
4 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
import { ReceiptTax } from '@vicons/tabler'; | ||
import { defineTool } from '../tool'; | ||
|
||
export const tool = defineTool({ | ||
name: 'VAT Numbers Validator', | ||
path: '/vat-validator', | ||
description: 'Validate VAT Numbers', | ||
keywords: ['vat', 'validator'], | ||
component: () => import('./vat-validator.vue'), | ||
icon: ReceiptTax, | ||
createdAt: new Date('2024-08-15'), | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,58 @@ | ||
<script setup lang="ts"> | ||
import { checkVAT, countries } from 'jsvat-next'; | ||
import type { CKeyValueListItems } from '@/ui/c-key-value-list/c-key-value-list.types'; | ||
const rawVATNumber = ref('BE0411905847'); | ||
const vatInfos = computed<{ isValid: boolean; infos: CKeyValueListItems }>(() => { | ||
const vat = checkVAT(rawVATNumber.value, countries); | ||
if (vat == null) { | ||
return { isValid: false, infos: [] }; | ||
} | ||
return { | ||
isValid: vat.isValid, | ||
infos: [ | ||
{ | ||
label: 'Is VAT Number valid ?', | ||
value: vat.isValid, | ||
}, | ||
{ | ||
label: 'Is VAT Number valid format ?', | ||
value: vat.isValidFormat, | ||
}, | ||
{ | ||
label: 'Cleaned VAT Number', | ||
value: vat.value, | ||
}, | ||
{ | ||
label: 'Country (name)', | ||
value: vat.country?.name || 'Unknown', | ||
}, | ||
{ | ||
label: 'Country (ISO2)', | ||
value: vat.country?.isoCode?.short || 'unk', | ||
}, | ||
{ | ||
label: 'Country (ISO3)', | ||
value: vat.country?.isoCode?.long || 'unk', | ||
}, | ||
{ | ||
label: 'Country (ISO Num)', | ||
value: vat.country?.isoCode?.numeric || 0, | ||
}, | ||
], | ||
}; | ||
}); | ||
</script> | ||
|
||
<template> | ||
<div> | ||
<c-input-text v-model:value="rawVATNumber" placeholder="Enter a VAT number to check for validity..." test-id="vat-input" mb-2 /> | ||
<n-alert v-if="!vatInfos.isValid" type="error" mb-2> | ||
Invalid VAT Number. | ||
</n-alert> | ||
|
||
<c-card v-if="vatInfos.infos.length > 0" title="VAT Number Infos"> | ||
<c-key-value-list :items="vatInfos.infos" data-test-id="vat-info" /> | ||
</c-card> | ||
</div> | ||
</template> |