postal-code-checker
Version:
A package for validating postal codes from various countries.
69 lines (66 loc) • 2.32 kB
TypeScript
// Generated by dts-bundle-generator v9.5.1
export type CountryPostalCode = {
regex: string;
example: string[];
isGenericRegex: boolean;
country: string;
};
export type PostalCodeData = {
[countryCode: string]: CountryPostalCode;
};
export declare const COUNTRIES: PostalCodeData;
export type CountryCode = Extract<keyof typeof COUNTRIES, string>;
export type Country = {
postalCodeRegex: string;
examplePostalCodes: string[];
isGenericRegex: boolean;
countryName: string;
countryCode: CountryCode;
};
export type CountryOption = {
countryName: string;
countryCode: string;
};
/**
* Retrieves all countries as an array of CountryOption objects.
*
* @returns {CountryOption[]} An array of CountryOption objects, each containing:
* - countryName: The name of the country
* - countryCode: The code of the country
*
* @example
* const countries = getAllCountries();
* // Returns: [
* // { countryName: "United States", countryCode: "US" },
* // { countryName: "Canada", countryCode: "CA" },
* // ...
* // ]
*/
export declare const getAllCountries: () => CountryOption[];
/**
* Retrieves country information based on the provided country code.
*
* @param {CountryCode} countryCode - The ISO 3166-1 alpha-2 country code.
* @returns {Country | null} An object containing country information if found, or null if not found.
*
* @example
* const countryInfo = getCountryByCode('US');
* if (countryInfo) {
* console.log(countryInfo.countryCode); // "US"
* console.log(countryInfo.countryName); // "United States"
* console.log(countryInfo.postalCodeRegex); // Regular expression for US postal codes
* console.log(countryInfo.examplePostalCodes);// Array of example US postal codes
* console.log(countryInfo.isGenericRegex); // Boolean indicating if the regex is generic
* }
*/
export declare const getCountryByCode: (countryCode: CountryCode) => Country | null;
/**
* A custom hook for validating postal codes based on country codes.
*
* @returns {Object} An object containing the validatePostalCode function.
* @property {function} validatePostalCode - A function to validate postal codes.
*/
export declare const usePostalCodeValidation: () => {
validatePostalCode: (countryCode: CountryCode, postalCode: string) => boolean;
};
export {};