/** * TIN (Anguilla Tax Identification Number). * * The Anguilla Tax Identification Number is issued to individuals and entities * for tax purposes. The number consists of 10 digits in the format XXXXX-XXXXX * where the first 5 digits represent the taxpayer's registration number and * the last 5 digits are a sequence number (including prefix and check digit). * * TINs are unique numbers automatically generated by the tax administration system * and consist of 10 digits, including prefix digit and check digit. * - Individual TINs start with prefix 1 * - Non-Individual (business) TINs start with prefix 2 * * Source * https://www.oecd.org/tax/automatic-exchange/crs-implementation-and-assistance/tax-identification-numbers/Anguilla-TIN.pdf * * PERSON/ENTITY */ import * as exceptions from '../exceptions'; import { strings } from '../util'; import { Validator, ValidateReturn } from '../types'; // import { weightedSum } from '../util/checksum'; function clean(input: string): ReturnType { return strings.cleanUnicode(input, ' -'); } const impl: Validator = { name: 'Anguilla Tax Identification Number', localName: 'Tax Identification Number', abbreviation: 'TIN', compact(input: string): string { const [value, err] = clean(input); if (err) { throw err; } return value; }, format(input: string): string { const [value] = clean(input); if (value.length !== 10) { return value; } return `${value.substring(0, 5)}-${value.substring(5)}`; }, validate(input: string): ValidateReturn { const [value, error] = clean(input); if (error) { return { isValid: false, error }; } if (value.length !== 10) { return { isValid: false, error: new exceptions.InvalidLength() }; } if (!strings.isdigits(value)) { return { isValid: false, error: new exceptions.InvalidFormat() }; } const prefix = value[0]; if (prefix !== '1' && prefix !== '2') { return { isValid: false, error: new exceptions.InvalidComponent() }; } // Validate checksum // const [front, check] = strings.splitAt(value, 8); // const sum = weightedSum(front, { // weights: [7, 3, 1, 7, 3, 1, 7, 3], // modulus: 10, // }); // if (String(sum) !== check) { // return { isValid: false, error: new exceptions.InvalidChecksum() }; // } return { isValid: true, compact: value, isIndividual: prefix === '1', isCompany: prefix === '2', }; }, }; export const { name, localName, abbreviation, validate, format, compact } = impl;