zellige.js
Version:
A Moroccan utility library for working with CIN, phone numbers, currency, addresses, dates, and more.
67 lines (66 loc) • 2.84 kB
TypeScript
import type { BankDetails } from '../types/bank';
export declare enum BankValidationError {
INVALID_INPUT_TYPE = "BANK_001",
INVALID_IBAN_FORMAT = "BANK_002",
INVALID_BANK_CODE = "BANK_003",
INVALID_IBAN_CHECKSUM = "BANK_004",
INVALID_RIB_FORMAT = "BANK_005",
INVALID_RIB_LENGTH = "BANK_006",
INVALID_RIB_CHECKSUM = "BANK_007",
BANK_NOT_FOUND = "BANK_008",
INVALID_AMOUNT = "BANK_009",
BRANCH_NOT_FOUND = "BANK_010"
}
export declare class BankValidationException extends Error {
code: BankValidationError;
details?: any | undefined;
constructor(code: BankValidationError, message: string, details?: any | undefined);
}
/**
* Validates a given IBAN (International Bank Account Number) for Moroccan banks.
*
* @param iban - The IBAN string to validate.
* @returns `true` if the IBAN is valid, `false` otherwise.
* @throws {TypeError} If the provided IBAN is not a string.
*
* The function performs the following checks:
* 1. Ensures the IBAN is a string.
* 2. Removes any whitespace and converts the IBAN to uppercase.
* 3. Checks if the IBAN matches the Moroccan IBAN format (starts with 'MA' followed by 26 digits).
* 4. Extracts the bank code and verifies it against a list of active Moroccan banks.
* 5. Rearranges the IBAN and converts it to a numeric string for the MOD 97-10 check.
* 6. Performs the MOD 97-10 check to validate the IBAN.
*/
export declare function isValidIBAN(iban: string): boolean;
/**
* Validates a Moroccan RIB (Relevé d'Identité Bancaire).
*
* This function checks if the provided RIB is valid by performing the following steps:
* 1. Cleans the RIB by removing spaces and hyphens.
* 2. Extracts the bank code and verifies it against a list of active Moroccan banks.
* 3. Checks the length and format of the RIB against bank-specific rules.
* 4. Calculates the expected key using the MOD 97-10 algorithm and compares it with the actual key.
*
* @param rib - The RIB string to validate.
* @returns `true` if the RIB is valid, `false` otherwise.
*/
export declare function isValidRIB(rib: string): boolean;
export declare function getBankDetails(code: string): BankDetails | undefined;
/**
* Gets SWIFT/BIC code with branch support
*/
export declare function getSwiftCode(code: string, branch?: string): string | undefined;
/**
* Converts a given amount in Moroccan Dirhams (MAD) to its French words representation.
*
* @param amount - The amount in Moroccan Dirhams to be converted.
* @returns The French words representation of the given amount.
*
* @example
* ```typescript
* madToWords(1234); // "mille deux cent trente-quatre dirhams"
* madToWords(0); // "zéro dirhams"
* madToWords(-45.67); // "moins quarante-cinq dirhams et soixante-sept centimes"
* ```
*/
export declare function madToWords(amount: number): string;