arabicfmt
Version:
Arabic-first formatting for numbers, currency, dates and bidirectional text across all 22 Arab League countries — with correct handling of the 2025–2026 Unicode currency-symbol transition (Saudi Riyal U+20C1, UAE Dirham U+20C3, Omani Rial U+20C4).
62 lines (59 loc) • 2.5 kB
TypeScript
/**
* IBAN validation and formatting (ISO 13616).
*
* Validity is the real ISO 7064 mod-97 checksum — not a regex guess — plus a
* country length check from the SWIFT IBAN registry. Length is only enforced
* for countries in {@link IBAN_LENGTHS}; others still get the checksum + the
* general 15–34 character bound, so unknown-country IBANs are never wrongly
* accepted on checksum alone.
*/
/**
* Total IBAN length per country (ISO 3166-1 alpha-2), from the SWIFT registry.
* Covers the Arab League countries that issue IBANs plus common partners.
*/
declare const IBAN_LENGTHS: Readonly<Record<string, number>>;
/** Strip spaces and upper-case — the canonical electronic IBAN form. */
declare function normalizeIBAN(iban: string): string;
/**
* Validate an IBAN: structure, registry length (when known), and the mod-97
* checksum.
*
* @example isValidIBAN("SA03 8000 0000 6080 1016 7519") // true
* @example isValidIBAN("SA03 8000 0000 6080 1016 7510") // false (bad checksum)
*/
declare function isValidIBAN(iban: string): boolean;
interface FormatIBANOptions {
/** Group separator. Default a single space (`"SA03 8000 …"`). */
separator?: string;
}
/**
* Format an IBAN into groups of four for display.
*
* @example formatIBAN("SA0380000000608010167519") // "SA03 8000 0000 6080 1016 7519"
*/
declare function formatIBAN(iban: string, options?: FormatIBANOptions): string;
/**
* Saudi national ID / Iqama validation.
*
* A Saudi ID is 10 digits whose leading digit encodes the holder type
* (1 = citizen / national ID, 2 = resident / Iqama) and whose final digit is a
* Luhn (ISO 7064 mod-10) check digit computed left-to-right over all ten digits.
*/
type SaudiIdType = "citizen" | "resident";
/**
* Validate a Saudi national ID or Iqama number (10 digits, leading 1 or 2,
* correct Luhn check digit).
*
* @example isValidSaudiId("1012345672") // true (citizen)
* @example isValidSaudiId("2100000005") // true (resident / Iqama)
* @example isValidSaudiId("1012345671") // false (bad check digit)
*/
declare function isValidSaudiId(id: string): boolean;
/**
* Holder type from the leading digit, or `null` when the ID is invalid.
*
* @example saudiIdType("1012345672") // "citizen"
* @example saudiIdType("2100000005") // "resident"
*/
declare function saudiIdType(id: string): SaudiIdType | null;
export { type FormatIBANOptions, IBAN_LENGTHS, type SaudiIdType, formatIBAN, isValidIBAN, isValidSaudiId, normalizeIBAN, saudiIdType };