API Reference
Complete documentation for all functions and data structures in degache.js.
Validators
validateCIN
Validates a Tunisian CIN (Carte d'Identité Nationale).
/**
* Validates a Tunisian CIN (Carte d'Identité Nationale)
* @param cin - The CIN number to validate
* @returns boolean indicating if the CIN is valid
*/
function validateCIN(cin: string): boolean
Example
import { validateCIN } from 'degachejs';
// Simple validation
const isValid = validateCIN('12345678'); // true
validatePhoneNumber
Validates a Tunisian phone number.
/**
* Validates a Tunisian phone number
* @param phoneNumber - The phone number to validate
* @returns boolean indicating if the phone number is valid
*/
function validatePhoneNumber(phoneNumber: string): boolean
Example
import { validatePhoneNumber } from 'degachejs';
// Validate phone number
const isValid = validatePhoneNumber('20123456'); // true
getCarrierInfo
Gets carrier information from a phone number.
/**
* Gets carrier information from a phone number
* @param phoneNumber - The phone number to check
* @returns carrier information or null if invalid
*/
function getCarrierInfo(phoneNumber: string): Carrier | null
Example
import { getCarrierInfo } from 'degachejs';
// Get carrier information
const carrier = getCarrierInfo('20123456');
console.log(carrier); // { name: 'Ooredoo', prefixes: ['2'] }
validateTaxID
Validates a Tunisian Tax ID (Matricule Fiscal).
/**
* Validates a Tunisian Tax ID (Matricule Fiscal)
* @param taxID - The Tax ID to validate
* @returns boolean indicating if the Tax ID is valid
*/
function validateTaxID(taxID: string): boolean
Example
import { validateTaxID } from 'degachejs';
const isValid = validateTaxID('1234567A/P/M/000');
validateRIB
Validates a Tunisian RIB (Relevé d'Identité Bancaire).
/**
* Validates a Tunisian RIB
* @param rib - The RIB to validate
* @returns boolean indicating if the RIB is valid
*/
function validateRIB(rib: string): boolean
Example
import { validateRIB } from 'degachejs';
// Validate RIB
const isValid = validateRIB('12345678901234567890');
getBankFromRIB
Gets bank information from a RIB.
/**
* Gets bank information from a RIB
* @param rib - The RIB to check
* @returns bank information or null if invalid
*/
function getBankFromRIB(rib: string): Bank | null
Example
import { getBankFromRIB } from 'degachejs';
// Get bank information
const bank = getBankFromRIB('12345678901234567890');
console.log(bank); // { name: 'Bank Name', code: '12' }
Formatters
formatPhoneNumber
Formats a Tunisian phone number with proper spacing and country code.
/**
* Formats a Tunisian phone number
* @param phoneNumber - The phone number to format
* @returns formatted phone number with country code and proper spacing
*/
function formatPhoneNumber(phoneNumber: string): string
Example
import { formatPhoneNumber } from 'degachejs';
// Format phone number
const formatted = formatPhoneNumber('20123456');
console.log(formatted); // +216 20 123 456
formatCurrency
Formats a number as Tunisian currency.
/**
* Formats a number as Tunisian currency
* @param amount - The amount to format
* @param options - Formatting options
* @returns formatted currency string
*/
function formatCurrency(amount: number, options?: CurrencyFormatOptions): string
Example
import { formatCurrency } from 'degachejs';
const amount = formatCurrency(1234.56);
console.log(amount); // 1.234,560 دينار تونسي
formatDate
Formats a date in Tunisian style.
/**
* Formats a date in Tunisian style
* @param date - The date to format
* @param options - Formatting options
* @returns formatted date string
*/
function formatDate(date: Date, options?: Intl.DateTimeFormatOptions): string
Example
import { formatDate } from 'degachejs';
const formatted = formatDate(new Date());
console.log(formatted); // Formatted date in Tunisian style
Constants
BANKS
List of Tunisian banks with their codes and names.
/**
* List of Tunisian banks
*/
const BANKS: Record<string, Bank>
Example
import { BANKS } from 'degachejs';
// Access list of Tunisian banks
console.log(BANKS);
CARRIERS
List of Tunisian mobile carriers with their prefixes.
/**
* List of Tunisian mobile carriers
*/
const CARRIERS: Record<string, Carrier>
Example
import { CARRIERS } from 'degachejs';
// Access list of mobile carriers
console.log(CARRIERS);
GOVERNORATES
List of Tunisian governorates.
/**
* List of Tunisian governorates
*/
const GOVERNORATES: string[]
Example
import { GOVERNORATES } from 'degachejs';
// Access list of governorates
console.log(GOVERNORATES);
Types
CIN
Type for Tunisian CIN.
/**
* Type for Tunisian CIN
*/
type CIN = string
PhoneNumber
Type for Tunisian phone number.
/**
* Type for Tunisian phone number
*/
type PhoneNumber = string
Carrier
Type for mobile carrier information.
/**
* Type for mobile carrier information
*/
interface Carrier {
name: string;
prefixes: string[];
}
Bank
Type for bank information.
/**
* Type for bank information
*/
interface Bank {
name: string;
code: string;
}