import { createValidator } from 'idnumbers/core';
const validator = createValidator({
METADATA: {
iso3166Alpha2: 'XX',
minLength: 6,
maxLength: 6,
parsable: false,
checksum: false,
regexp: /^\d{6}$/,
aliasOf: null,
names: [],
links: [],
deprecated: false,
},
validate: (id: string) => /^\d{6}$/.test(id),
});
validator.validate('123456'); // true
validator.validate('12345A'); // false
Create a CountryValidator from a country module (a class with static methods, or a plain object bundling module-level functions).
Wraps methods in arrow functions to avoid
thisbinding issues that occur when static methods are detached from their class. The module's parse result type carries over to the validator (#123).A validator that this function or
createCompositeValidator()built is returned as-is instead of being wrapped again (#183).