-
Notifications
You must be signed in to change notification settings - Fork 26
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #85 from koblas/fo_vn
fix: added the Faroe Islands tax number
- Loading branch information
Showing
7 changed files
with
116 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
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 @@ | ||
export * as vn from './vn'; |
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,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); | ||
}); | ||
}); |
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,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; |
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