UNPKG

test-numbers-generator

Version:

Generate and validate European test phone numbers (mobile and landline) in safe, non-existent ranges.

219 lines (159 loc) • 7.42 kB
# test-numbers-generator Generate and validate European test phone numbers (mobile and landline) in safe, non-existent ranges. ## Features - šŸ“± **Mobile Numbers**: Generate test mobile numbers for 17 European and North African countries - šŸ  **Landline Numbers**: Generate test landline numbers for all supported countries - šŸ†” **Dutch Identifiers**: Generate and validate Dutch BSN, IBAN, KvK numbers - šŸ“® **Postcodes**: Generate and validate postcodes for multiple countries - šŸŒ **Real Address Data**: Fetch real Dutch postcodes and address data using the PDOK Locatieserver API - šŸ” **Address Validation**: Check address details by postcode and house number - šŸ˜ļø **Place Names**: Fetch random valid Dutch place names ## Supported Countries šŸ‡³šŸ‡± Netherlands • šŸ‡©šŸ‡Ŗ Germany • šŸ‡§šŸ‡Ŗ Belgium • šŸ‡«šŸ‡· France • šŸ‡¬šŸ‡§ United Kingdom • šŸ‡ŖšŸ‡ø Spain • šŸ‡®šŸ‡¹ Italy • šŸ‡¦šŸ‡¹ Austria • šŸ‡ØšŸ‡­ Switzerland • šŸ‡øšŸ‡Ŗ Sweden • šŸ‡³šŸ‡“ Norway • šŸ‡©šŸ‡° Denmark • šŸ‡«šŸ‡® Finland • šŸ‡µšŸ‡¹ Portugal • šŸ‡®šŸ‡Ŗ Ireland • šŸ‡¹šŸ‡· Turkey • šŸ‡²šŸ‡¦ Morocco ## Installation ```bash npm install test-numbers-generator ``` ## Usage ### Mobile Phone Numbers ```ts import { generateTestMobileNumber, isTestMobileNumber } from 'test-numbers-generator'; // Generate a mobile number (uses international 00 prefix) const mobileNL = generateTestMobileNumber.Netherlands(); console.log(mobileNL); // "0031 6 12345678" const mobileDE = generateTestMobileNumber.Germany(); console.log(mobileDE); // "0049 015 1234567" (or 016/017) const mobileFR = generateTestMobileNumber.France(); console.log(mobileFR); // "0033 6 12345678" (or 7) // Validate mobile numbers console.log(isTestMobileNumber.Netherlands(mobileNL)); // true console.log(isTestMobileNumber.Germany("0049 018 1234567")); // false (invalid prefix) ``` ### Landline Phone Numbers ```ts import { generateTestLandlineNumber, isTestLandlineNumber } from 'test-numbers-generator'; const landlineNL = generateTestLandlineNumber.Netherlands(); console.log(landlineNL); // "010 991234567" const landlineDE = generateTestLandlineNumber.Germany(); console.log(landlineDE); // "030 9912345" // Validate landline numbers console.log(isTestLandlineNumber.Netherlands(landlineNL)); // true ``` ### Dutch BSN (Burgerservicenummer) ```ts import { generateTestBSN, isValidBSN } from 'test-numbers-generator'; const bsn = generateTestBSN(); console.log(bsn); // "999012345" (test range) console.log(isValidBSN(bsn)); // true console.log(isValidBSN("123456789")); // false (invalid checksum) ``` ### Dutch IBAN ```ts import { generateTestDutchIBAN, isValidDutchIBAN } from 'test-numbers-generator'; const iban = generateTestDutchIBAN(); console.log(iban); // "NL99INGB0123456789" console.log(isValidDutchIBAN(iban)); // true ``` ### KvK Numbers ```ts import { generateTestKvKNumber } from 'test-numbers-generator'; const kvk = generateTestKvKNumber(); console.log(kvk); // "12345678" ``` ### Postcodes ```ts import { generateTestPostcode, isValidDutchPostcode } from 'test-numbers-generator'; const postcodeNL = generateTestPostcode.Netherlands(); console.log(postcodeNL); // "9999 XX" console.log(isValidDutchPostcode(postcodeNL)); // true ``` ### Real Dutch Address Data (PDOK API) ```ts import { fetchRandomDutchPostcodeFromPDOK, checkAdresByPostcodeHuisnummer, fetchPostcodesMetHuisnummerToevoeging, getRandomPlaatsnaam } from 'test-numbers-generator'; // Fetch a real, existing Dutch postcode const realPostcode = await fetchRandomDutchPostcodeFromPDOK(); console.log(realPostcode); // "1011 AC" // Check address details by postcode and house number const address = await checkAdresByPostcodeHuisnummer('1011 AC', 1); console.log(address); // { straatnaam: 'Prins Hendrikkade', woonplaats: 'Amsterdam' } // Find postcodes with house number additions (like 12A, 12-B) const postcodesWithAdditions = await fetchPostcodesMetHuisnummerToevoeging('Amsterdam', 20); console.log(postcodesWithAdditions); // Set of postcodes // Get a random valid Dutch place name const placeName = await getRandomPlaatsnaam(); console.log(placeName); // "Amsterdam" ``` ## Mobile Number Format Details All mobile numbers are generated using the international `00` prefix format and follow official country specifications: - **šŸ‡³šŸ‡± Netherlands**: `0031 6 xxxxxxxx` (9 digits after 06) - **šŸ‡©šŸ‡Ŗ Germany**: `0049 015/016/017 xxxxxxx` (10-11 digits after country code) - **šŸ‡§šŸ‡Ŗ Belgium**: `0032 047/048/049 xxxxxxx` (9 digits total) - **šŸ‡«šŸ‡· France**: `0033 6/7 xxxxxxxx` (8 digits after prefix) - **šŸ‡¬šŸ‡§ United Kingdom**: `0044 7 xxxxxxxxx` (9 digits after 7) - **šŸ‡ŖšŸ‡ø Spain**: `0034 6/7xxxxxxxx` (9 digits total) - **ļæ½ļæ½šŸ‡¹ Italy**: `0039 3xx xxxxxxx` (10 digits total) - **šŸ‡¦šŸ‡¹ Austria**: `0043 06xx xxxxxxx` (10-13 digits total) - **šŸ‡ØšŸ‡­ Switzerland**: `0041 07x xxxxxx` (9 digits total) - **šŸ‡øšŸ‡Ŗ Sweden**: `0046 7 xxxxxxxx` (8 digits after 7) - **šŸ‡³šŸ‡“ Norway**: `0047 4x/9x xxxxxx` (8 digits total) - **šŸ‡©šŸ‡° Denmark**: `0045 xxxxxxxx` (8 digits, various prefixes) - **šŸ‡«šŸ‡® Finland**: `00358 04x/050 xxxxxx` (9-10 digits total) - **šŸ‡µšŸ‡¹ Portugal**: `00351 9x xxxxxxx` (9 digits total) - **šŸ‡®šŸ‡Ŗ Ireland**: `00353 08x xxxxxx` (9 digits total) - **šŸ‡¹šŸ‡· Turkey**: `0090 053x xxxxxx` (10 digits total) - **šŸ‡²šŸ‡¦ Morocco**: `00212 06/07 xxxxxxx` (9 digits total) ## API Reference ### Types ```ts type SupportedCountry = | 'Netherlands' | 'Germany' | 'Belgium' | 'France' | 'UnitedKingdom' | 'Spain' | 'Italy' | 'Austria' | 'Switzerland' | 'Sweden' | 'Norway' | 'Denmark' | 'Finland' | 'Portugal' | 'Ireland' | 'Turkey' | 'Morocco'; type PhoneNumberType = 'mobile' | 'landline'; ``` ### Functions ```ts // Phone number generators generateTestMobileNumber: Record<SupportedCountry, () => string> generateTestLandlineNumber: Record<SupportedCountry, () => string> // Phone number validators isTestMobileNumber: Record<SupportedCountry, (number: string) => boolean> isTestLandlineNumber: Record<SupportedCountry, (number: string) => boolean> isTestPhoneNumber(number: string): boolean // Dutch identifiers generateTestBSN(): string isValidBSN(bsn: string): boolean generateTestDutchIBAN(): string isValidDutchIBAN(iban: string): boolean generateTestKvKNumber(): string // Postcodes generateTestPostcode: Record<SupportedPostcodeCountry, () => string> isValidDutchPostcode(postcode: string): boolean // Real address data (async) fetchRandomDutchPostcodeFromPDOK(): Promise<string> checkAdresByPostcodeHuisnummer(postcode: string, huisnummer: number): Promise<AddressInfo> fetchPostcodesMetHuisnummerToevoeging(plaats: string, limit?: number): Promise<Set<string>> getRandomPlaatsnaam(): Promise<string> ``` ## Test Numbers Policy All generated numbers are designed to be **safe for testing**: - šŸ“± Mobile numbers use realistic formats but are in test ranges - šŸ  Landline numbers include "99" sequences to indicate test numbers - šŸ†” BSN numbers use the 999xxxxxx test range - šŸ¦ IBAN numbers use test bank codes - šŸ“® Postcodes use 9999 XX format for tests **āš ļø Important**: These numbers should only be used for testing purposes and are not real, active numbers. ## Contributing Contributions are welcome! Please ensure all tests pass: ```bash npm test npm run test:coverage ``` ## License MIT