polish-validators
Version:
A set of validator functions that check common polish numbers.
46 lines (45 loc) • 2.42 kB
TypeScript
/**
* Validates a PESEL (Polish national identification number) string.
* This function validates the control number and ensures the birthdate is also valid.
*
* **Note:** This validator isn't perfect. Some invalid numbers might still return true.
* For example, people born before the year 1931 might accidentally swap their birthyear
* and birthday, and the function will still pass. 1st, 5th, and 9th or 2nd, 6th, and
* 10th numbers may also be swapped while still passing. There is nothing that can really
* be done about that, other than validating against a database of PESEL numbers.
*
* @param {string} pesel - The 11-digit PESEL number as a string.
* @returns {boolean} `true` if the PESEL is valid; `false` otherwise.
*/
export declare function isPeselValid(pesel: string): boolean;
/**
* Validates a PESEL (Polish national identification number) string.
* This function validates the control number and ensures the birthdate is also valid.
*
* **Note:** This validator isn't perfect. Some invalid numbers might still return true.
* For example, people born before the year 1931 might accidentally swap their birthyear
* and birthday, and the function will still pass. 1st, 5th, and 9th or 2nd, 6th, and
* 10th numbers may also be swapped while still passing. There is nothing that can really
* be done about that, other than validating against a database of PESEL numbers.
*
* @param {string} pesel - The 11-digit PESEL number as a string.
* @returns {boolean} `true` if the PESEL is invalid; `false` otherwise.
*/
export declare const isPeselInvalid: (pesel: string) => boolean;
/**
* Extracts the birthdate from a valid PESEL number.
* @param pesel - The 11-digit PESEL number as a string.
* @returns {Date | null} The birthdate as a Date object, or null if PESEL is invalid.
*/
export declare function getBirthdateFromPesel(pesel: string): Date | null;
export declare const PeselSex: {
readonly Male: "male";
readonly Female: "female";
};
export type PeselSex = (typeof PeselSex)[keyof typeof PeselSex];
/**
* Extracts the sex from a valid PESEL number.
* @param pesel - The 11-digit PESEL number as a string.
* @returns {PeselSex | null} 'male' if the PESEL belongs to a male, 'female' if it belongs to a female, null if PESEL is invalid.
*/
export declare function extractSexFromPesel(pesel: string): PeselSex | null;