sl-nic-utils
Version:
Sri Lanka NIC Utilities - An adaptable npm package designed to validate NIC numbers, determine the NIC format, convert between OLD and NEW formats, and extract detailed information from Sri Lanka National Identity Card (NIC) numbers.
71 lines (70 loc) • 2.42 kB
TypeScript
import { NicGender, NicType } from './lib/types';
/**
* Represents a birthday with year, month, and date.
*/
declare class Birthday {
readonly year: number;
readonly month: number;
readonly date: number;
/**
* Creates a new instance of the Birthday class.
* @param year - The year of the birthday.
* @param month - The month of the birthday.
* @param date - The date of the birthday.
*/
constructor(year: number, month: number, date: number);
/**
* Returns a string representation of the birthday in the format "YYYY/MM/DD".
* @returns The string representation of the birthday.
*/
toString(): string;
/**
* Returns a Date object representing the birthday.
* @returns The Date object representing the birthday.
*/
toDate(): Date;
}
/**
* Represents a NIC (National Identity Card) number.
*/
export default class NIC {
private readonly nic;
/**
* Creates a new instance of the NIC class.
* @param nic - The NIC number as a string.
* @throws {TypeError} If the provided NIC is not a string.
*/
constructor(nic: string);
/**
* Checks if the NIC number is valid.
* @returns {boolean} True if the NIC number is valid, false otherwise.
*/
get isValid(): boolean;
/**
* Gets the type of the NIC number.
* @returns {NicType} The type of the NIC number.
* @throws {Error} If the NIC number is invalid.
*/
get type(): NicType;
/**
* Gets the gender associated with the NIC number.
* @returns {NicGender} The gender associated with the NIC number.
* @throws {Error} If the NIC number is invalid.
*/
get gender(): NicGender;
/**
* Gets the birthday associated with the NIC number.
* @returns {Birthday} The birthday associated with the NIC number.
* @throws {Error} If the NIC number is invalid.
*/
get birthday(): Birthday;
/**
* Formats the NIC number to the specified target type.
* @param targetType - The target type to format the NIC number to. Defaults to the current type.
* @returns {string} The formatted NIC number.
* @throws {TypeError} If the targetType is not a string or is not 'OLD' or 'NEW'.
* @throws {Error} If the targetType is 'OLD' and the NIC number is not valid for an old NIC.
*/
format(targetType?: NicType): string;
}
export {};