UNPKG

test-numbers-generator

Version:

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

150 lines (145 loc) 6.43 kB
// src/mobileNumberGenerators.ts // Generator functions for Dutch and European test phone numbers export type PhoneNumberType = 'mobile' | 'landline'; export type SupportedCountry = | 'Netherlands' | 'Germany' | 'Belgium' | 'France' | 'UnitedKingdom' | 'Spain' | 'Italy' | 'Austria' | 'Switzerland' | 'Sweden' | 'Norway' | 'Denmark' | 'Finland' | 'Portugal' | 'Ireland' | 'Turkey' | 'Morocco'; export const generateTestMobileNumber: Record<SupportedCountry, () => string> = { Netherlands: () => { // 0031 6 99xxxxxx (internationaal format met 00, 9 cijfers na 6) const random = Math.floor(100000000 + Math.random() * 900000000); return `0031 6 ${random.toString().substring(0, 8)}`; }, Germany: () => { // 0049 015 99xxxxxx (10-11 cijfers na landcode) const prefixes = ['015', '016', '017']; const prefix = prefixes[Math.floor(Math.random() * prefixes.length)]; const random = Math.floor(1000000 + Math.random() * 9000000); return `0049 ${prefix} ${random.toString().substring(0, 7)}`; }, Belgium: () => { // 0032 47 99xxxxx (47 + 7 cijfers = 9 cijfers totaal, zonder nationale 0) const prefixes = ['047', '048', '049']; const prefix = prefixes[Math.floor(Math.random() * prefixes.length)]; const random = Math.floor(10000000 + Math.random() * 90000000); return `0032 ${prefix.substring(1)} ${random.toString().substring(0, 7)}`; }, France: () => { // 0033 6/7 99xxxxxx (internationaal 0033 6/7 + 8 cijfers) const prefixes = ['6', '7']; const prefix = prefixes[Math.floor(Math.random() * prefixes.length)]; const random = Math.floor(10000000 + Math.random() * 90000000); return `0033 ${prefix} ${random.toString().substring(0, 8)}`; }, UnitedKingdom: () => { // 0044 7 99xxxxxxx (internationaal 0044 7 + 9 cijfers) const random = Math.floor(100000000 + Math.random() * 900000000); return `0044 7 ${random.toString().substring(0, 9)}`; }, Spain: () => { // 0034 6/7xxxxxxxx (9 cijfers totaal) const prefixes = ['6', '7']; const prefix = prefixes[Math.floor(Math.random() * prefixes.length)]; const random = Math.floor(100000000 + Math.random() * 900000000); return `0034 ${prefix}${random.toString().substring(0, 8)}`; }, Italy: () => { // 0039 3xx xxxxxxx (3xx prefix, 10 cijfers totaal) const prefix = Math.floor(320 + Math.random() * 80); // 320-399 const random = Math.floor(10000000 + Math.random() * 90000000); return `0039 ${prefix} ${random.toString().substring(0, 7)}`; }, Austria: () => { // 0043 664/676/699 xxxxxxx (664/676/699 prefix, 10-13 cijfers totaal, zonder nationale 0) const prefixes = ['664', '676', '699']; const prefix = prefixes[Math.floor(Math.random() * prefixes.length)]; const random = Math.floor(10000000 + Math.random() * 90000000); return `0043 ${prefix} ${random.toString().substring(0, 7)}`; }, Switzerland: () => { // 0041 75/76/77/78/79 xxxxxx (075/076/077/078/079 prefix, zonder nationale 0) const prefixes = ['75', '76', '77', '78', '79']; const prefix = prefixes[Math.floor(Math.random() * prefixes.length)]; const random = Math.floor(1000000 + Math.random() * 9000000); return `0041 ${prefix} ${random.toString().substring(0, 6)}`; }, Sweden: () => { // 0046 7 99xxxxxx (internationaal 0046 7 + 8 cijfers) const random = Math.floor(10000000 + Math.random() * 90000000); return `0046 7 ${random.toString().substring(0, 8)}`; }, Norway: () => { // 0047 4x/9x xxxxxx (altijd 8 cijfers) const prefixes = ['4', '9']; const prefix = prefixes[Math.floor(Math.random() * prefixes.length)]; const random = Math.floor(1000000 + Math.random() * 9000000); return `0047 ${prefix}${random.toString().substring(0, 7)}`; }, Denmark: () => { // 0045 2x/3x xxxxxx (mobiel beperkt tot 20-31, altijd 8 cijfers) const prefixes = ['20', '21', '22', '23', '24', '25', '26', '27', '28', '29', '30', '31']; const prefix = prefixes[Math.floor(Math.random() * prefixes.length)]; const random = Math.floor(100000 + Math.random() * 900000); return `0045 ${prefix}${random.toString().substring(0, 6)}`; }, Finland: () => { // 00358 40-50/457/59 xxxxxx (04x/050/0457/059 prefix, 9-10 cijfers totaal, zonder nationale 0) const prefixes = ['40', '41', '42', '43', '44', '45', '46', '47', '48', '49', '50', '457', '59']; const prefix = prefixes[Math.floor(Math.random() * prefixes.length)]; const random = Math.floor(1000000 + Math.random() * 9000000); return `00358 ${prefix} ${random.toString().substring(0, 6)}`; }, Portugal: () => { // 00351 91/92/93/96 xxxxxxx (9x prefix, 9 cijfers totaal) const prefixes = ['91', '92', '93', '96']; const prefix = prefixes[Math.floor(Math.random() * prefixes.length)]; const random = Math.floor(10000000 + Math.random() * 90000000); return `00351 ${prefix} ${random.toString().substring(0, 7)}`; }, Ireland: () => { // 00353 83/85/86/87/89 xxxxxx (083/085/086/087/089 prefix, zonder nationale 0) const prefixes = ['83', '85', '86', '87', '89']; const prefix = prefixes[Math.floor(Math.random() * prefixes.length)]; const random = Math.floor(1000000 + Math.random() * 9000000); return `00353 ${prefix} ${random.toString().substring(0, 6)}`; }, Turkey: () => { // 0090 5xx xxxxxxx (05xx prefix wordt 5xx zonder nationale 0, 10 cijfers totaal) const prefixes = ['531', '532', '533', '534', '535', '536', '537', '538', '539']; const prefix = prefixes[Math.floor(Math.random() * prefixes.length)]; const random = Math.floor(1000000 + Math.random() * 9000000); return `0090 ${prefix} ${random.toString().substring(0, 6)}`; }, Morocco: () => { // 00212 6/7 xxxxxxxx (6/7 prefix, 9 cijfers totaal, zonder nationale 0) const prefixes = ['6', '7']; const prefix = prefixes[Math.floor(Math.random() * prefixes.length)]; const random = Math.floor(10000000 + Math.random() * 90000000); return `00212 ${prefix} ${random.toString().substring(0, 8)}`; }, }; export const testNumbersGenerator = { generateTestMobileNumber, // Add all other generators for convenience // Import and add these if you want a single entry point for all // generateTestLandlineNumber, // generateTestBSN, // generateTestDutchIBAN, // generateTestDutchPostcode, // generateTestKvKNumber, };