/** * TIN (Curaçao Tax Identification Number). * * The Curaçao TIN (persoonsnummer) is used for individuals and entities for * all taxes. It is a 9 digit number generated by the tax system, with no * published structure or check digit. * * Source * https://www.oecd.org/content/dam/oecd/en/topics/policy-issue-focus/aeoi/curacao-tin.pdf * * 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: 'Curaçao Tax Identification Number', localName: 'Persoonsnummer', abbreviation: 'TIN', examples: ['123456789'], formats: ['nnnnnnnnn'], 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 !== 9) { 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;