UNPKG

degachejs

Version:

A Tunisian utility library for working with CIN, phone numbers, addresses, and more

210 lines (152 loc) โ€ข 5.14 kB
# ๐ŸŒด degache.js Tunisian Developer's Essential Utility Library ## Why degache.js? ๐Ÿค” Tired of rewriting validation code for Tunisian CIN, phone numbers, and tax IDs? `degache.js` is your go-to utility library for all things Tunisian! Named after the beautiful oasis city of Degache, this library brings the same refreshing relief to your development workflow. ## ๐Ÿš€ Features ### CIN (Carte d'Identitรฉ Nationale) ๐Ÿ†” ```typescript import { validateCIN } from 'degachejs'; // Simple validation const isValid = validateCIN('12345678'); // true ``` ### Phone Numbers ๐Ÿ“ฑ - โœ… Support for all Tunisian carriers (Ooredoo, Orange, Tunisie Telecom) - ๐Ÿ”„ International format conversion - ๐Ÿ“ž Smart formatting with country code - ๐Ÿข Carrier detection - ๐Ÿ”’ Strict mode validation ```typescript import { validatePhoneNumber, formatPhoneNumber, getCarrierInfo } from 'degachejs'; // Validate phone number const isValid = validatePhoneNumber('20123456'); // true // Validate with strict mode (no spaces or special characters allowed) const isStrictValid = validatePhoneNumber('20 123 456', { strict: true }); // false // Format phone number const formatted = formatPhoneNumber('20123456'); console.log(formatted); // +216 20 123 456 // Get carrier information const carrier = getCarrierInfo('20123456'); console.log(carrier); // { name: 'Ooredoo', prefixes: ['2'] } ``` ### Tax ID (Matricule Fiscal) ๐Ÿ’ผ ```typescript import { validateTaxID } from 'degachejs'; const isValid = validateTaxID('1234567A/P/M/000'); ``` ### Currency Formatting ๐Ÿ’ฐ ```typescript import { formatCurrency } from 'degachejs'; const amount = formatCurrency(1234.56); console.log(amount); // 1.234,560 ุฏูŠู†ุงุฑ ุชูˆู†ุณูŠ ``` ### Postal Codes ๐Ÿ“ฎ ```typescript import { validatePostalCode } from 'degachejs'; const isValid = validatePostalCode('1000'); // true for Tunis ``` ### Car Plates ๐Ÿš— ```typescript import { validateCarPlate, getCarPlateInfo } from 'degachejs'; // Validate car plate (Arabic format: XXX ุชูˆู†ุณ XXXX) const isValid = validateCarPlate('123 ุชูˆู†ุณ 4567'); // true // Validate special car plate (RS format) const isSpecialValid = validateCarPlate('RS 123 ุชูˆู†ุณ', { type: 'special' }); // true // Validate with strict mode const isStrictValid = validateCarPlate('123 ุชูˆู†ุณ 4567', { strict: true }); // false // Get car plate information const plateInfo = getCarPlateInfo('123 ุชูˆู†ุณ 4567'); console.log(plateInfo); // { // type: 'standard', // components: { // prefix: '123', // region: 'ุชูˆู†ุณ', // suffix: '4567' // } // } ``` ### Bank Account (RIB) Validation ๐Ÿฆ ```typescript import { validateRIB, getBankFromRIB } from 'degachejs'; // Validate RIB const isValid = validateRIB('12345678901234567890'); // Get bank information const bank = getBankFromRIB('12345678901234567890'); console.log(bank); // { name: 'Bank Name', code: '12' } ``` ### Date Formatting ๐Ÿ“… ```typescript import { formatDate } from 'degachejs'; const formatted = formatDate(new Date()); console.log(formatted); // Formatted date in Tunisian style ``` ### Constants ๐Ÿ“‹ ```typescript import { BANKS, CARRIERS, GOVERNORATES } from 'degachejs'; // Access list of Tunisian banks console.log(BANKS); // Access list of mobile carriers console.log(CARRIERS); // Access list of governorates console.log(GOVERNORATES); ``` ## ๐Ÿ“ฆ Installation ```bash npm install degachejs # or yarn add degachejs # or pnpm add degachejs ``` ## ๐Ÿ› ๏ธ Usage ```typescript import { validateCIN, formatPhoneNumber, validateTaxID, formatCurrency, validateRIB, getBankFromRIB, formatDate, validateCarPlate, getCarPlateInfo } from 'degachejs'; // Validate CIN const isCINValid = validateCIN('12345678'); // Format phone number const phoneNumber = formatPhoneNumber('20123456'); // Validate Tax ID const isTaxIDValid = validateTaxID('1234567A/P/M/000'); // Format currency const price = formatCurrency(1234.56, { symbol: true }); // Validate RIB const isRIBValid = validateRIB('12345678901234567890'); // Get bank information const bankInfo = getBankFromRIB('12345678901234567890'); // Format date const formattedDate = formatDate(new Date()); // Validate car plate const isCarPlateValid = validateCarPlate('123 ุชูˆู†ุณ 4567'); // Get car plate information const carPlateInfo = getCarPlateInfo('123 ุชูˆู†ุณ 4567'); ``` ## ๐Ÿค Contributing We welcome contributions from the Tunisian developer community! Whether it's: - ๐Ÿ› Bug fixes - โœจ New features - ๐Ÿ“š Documentation improvements - ๐Ÿงช Test cases - ๐Ÿ’ก Feature suggestions Check out our [Contributing Guide](CONTRIBUTING.md) to get started. ## ๐Ÿ”’ Security All validation and formatting functions are designed with security in mind, following best practices for handling sensitive data. ## ๐Ÿ“„ License degache.js is MIT licensed. See the [LICENSE](LICENSE) file for details. ## ๐Ÿ† Production Ready - โœ… Comprehensive input validation - โšก Optimized performance - ๐Ÿงช High test coverage - ๐Ÿ“š Detailed documentation - ๐Ÿ”’ Type-safe APIs --- Built with โค๏ธ for the Tunisian developer community ๐Ÿ‡น๐Ÿ‡ณ