/** * TIN (Afghan Tax Identification Number). * * The Afghan TIN is issued by the Afghanistan Revenue Department of the * Ministry of Finance to individuals, companies and organisations. It is a * 10 digit number. No check digit algorithm is published, so only the length * and digits are checked. * * Source * https://org-id.guide/list/AF-TIN * * PERSON/ENTITY */ import * as exceptions from '../exceptions'; import { strings } from '../util'; import { Validator, ValidateReturn } from '../types'; function clean(input: string): ReturnType { return strings.cleanUnicode(input, ' -./'); } const impl: Validator = { name: 'Afghan Tax Identification Number', localName: 'Tax Identification Number', abbreviation: 'TIN', examples: ['1234567890'], formats: ['nnnnnnnnnn'], 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 !== 10) { return { isValid: false, error: new exceptions.InvalidLength() }; } if (!strings.isdigits(value)) { return { isValid: false, error: new exceptions.InvalidFormat() }; } return { isValid: true, compact: value, isIndividual: true, isCompany: true, }; }, }; export const { name, localName, abbreviation, examples, formats, validate, format, compact, } = impl;