Skip to content

Commit

Permalink
Merge pull request #85 from koblas/fo_vn
Browse files Browse the repository at this point in the history
fix: added the Faroe Islands tax number
  • Loading branch information
koblas committed Jul 7, 2023
2 parents 00ecf5e + fd01b81 commit 5ce1987
Show file tree
Hide file tree
Showing 7 changed files with 116 additions and 4 deletions.
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -90,6 +90,7 @@ All country validators are in the "namespace" of the ISO country code.
| Finland | FI | ALV | Company | ALV nro (Arvonlisäveronumero, Finnish VAT number) |
| Finland | FI | HETU | Person | HETU (Henkilötunnus, Finnish personal identity code) |
| Finland | FI | YTUNNUS | Company | Y-tunnus (Finnish business identifier) |
| Faroe Islands | FO | VN | Company/Person | Vinnutal, Faroe Islands tax number |
| France | FR | NIF | Person | NIF (Numéro d'Immatriculation Fiscale, French tax identification number) |
| Great Britain | GB | NINO | Person | NINO (United Kingdom National Insurance Number) |
| Great Britain | GB | UTR | Person | UTR (United Kingdom Unique Taxpayer Reference) |
Expand Down
7 changes: 5 additions & 2 deletions bin/tmpl/tin.ts
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,9 @@ const impl: Validator = {
return { isValid: false, error: new exceptions.InvalidLength() };
}

if (!strings.isdigits(value)) {
return { isValid: false, error: new exceptions.InvalidFormat() };
}
// if (!validRe.test(value)) {
// return { isValid: false, error: new exceptions.InvalidFormat() };
// }
Expand All @@ -71,8 +74,8 @@ const impl: Validator = {
return {
isValid: true,
compact: value,
isIndividual: value[0] === 'P',
isCompany: value[0] !== 'P',
isIndividual: false,
isCompany: false,
};
},
};
Expand Down
4 changes: 2 additions & 2 deletions src/eg/tn.ts
Original file line number Diff line number Diff line change
Expand Up @@ -49,8 +49,8 @@ function clean(input: string): ReturnType<typeof strings.cleanUnicode> {
}

const impl: Validator = {
name: 'NAME',
localName: 'NAME',
name: 'Tax Registration Number',
localName: 'الرقم الضريبي',
abbreviation: 'TN',

compact(input: string): string {
Expand Down
1 change: 1 addition & 0 deletions src/fo/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
export * as vn from './vn';
34 changes: 34 additions & 0 deletions src/fo/vn.spec.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
import { validate, format } from './vn';
import { InvalidLength, InvalidFormat } from '../exceptions';

describe('fo/vn', () => {
it('format:623857', () => {
const result = format('623857');

expect(result).toEqual('623857');
});

it('fvalidate:623857', () => {
const result = validate('623857');

expect(result.isValid && result.compact).toEqual('623857');
});

test.each(['623857', '33 28 28', '563.609'])('validate:%s', value => {
const result = validate(value);

expect(result.isValid).toEqual(true);
});

it('validate:62385', () => {
const result = validate('62385');

expect(result.error).toBeInstanceOf(InvalidLength);
});

it('validate:62385A', () => {
const result = validate('62385A');

expect(result.error).toBeInstanceOf(InvalidFormat);
});
});
71 changes: 71 additions & 0 deletions src/fo/vn.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,71 @@
/**
* V-number (Vinnutal, Faroe Islands tax number).
*
* In the Faroe Islands the legal persons TIN equals the V number issued by the
* Faroese Tax Administration. It is a consecutive number.
*
* Source
* https://www.taks.fo/fo/borgari/bolkar/at-stovna-virki/
* https://www.oecd.org/tax/automatic-exchange/crs-implementation-and-assistance/tax-identification-numbers/Faroe-islands-TIN.pdf
*
* ENTITY/PERSON
*/

import * as exceptions from '../exceptions';
import { strings } from '../util';
import { Validator, ValidateReturn } from '../types';

function clean(input: string): ReturnType<typeof strings.cleanUnicode> {
return strings.cleanUnicode(input, ' -.');
}

// const validRe = /^[PCGQV]{1}00[A-Z0-9]{8}$/;

// const ALPHABET = '0123456789X';

const impl: Validator = {
name: 'Vinnutal',
localName: 'NAME',
abbreviation: 'VN',

compact(input: string): string {
const [value, err] = clean(input);

if (err) {
throw err;
}

return value;
},

format(input: string): string {
const [value] = clean(input);

return value;
},

validate(input: string): ValidateReturn {
const [value, error] = clean(input);

if (error) {
return { isValid: false, error };
}
if (value.length !== 6) {
return { isValid: false, error: new exceptions.InvalidLength() };
}

if (!strings.isdigits(value)) {
return { isValid: false, error: new exceptions.InvalidFormat() };
}

return {
isValid: true,
compact: value,
isIndividual: false,
isCompany: false,
};
},
};

export const { name, localName, abbreviation, validate, format, compact } =
impl;
2 changes: 2 additions & 0 deletions src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ import * as EE from './ee';
import * as EG from './eg';
import * as ES from './es';
import * as FI from './fi';
import * as FO from './fo';
import * as FR from './fr';
import * as GB from './gb';
import * as GH from './gh';
Expand Down Expand Up @@ -118,6 +119,7 @@ export const stdnum: Record<string, Record<string, Validator>> = {
EG,
ES,
FI,
FO,
FR,
GB,
GH,
Expand Down

0 comments on commit 5ce1987

Please sign in to comment.