@devdataphone/sdk
v1.0.1
Published
Generate valid E.164 phone numbers for QA testing, database seeding, and mock data. Zero server-side retention.
Maintainers
Readme
@devdataphone/sdk
Generate valid E.164 phone numbers for QA testing, database seeding, and mock data. Zero server-side retention.
🌐 Try it online: DevDataPhone.com - Free online phone number generator with no signup required.
Features
- ✅ Generate valid E.164 format phone numbers
- ✅ Support for 10+ countries (US, UK, CN, IN, AU, CA, DE, FR, JP, BR)
- ✅ Validate phone numbers with detailed results
- ✅ Format numbers to national, international, or E.164
- ✅ Zero dependencies for core functionality
- ✅ TypeScript support included
- ✅ Works in Node.js 14+
Installation
npm install @devdataphone/sdkQuick Start
const { generate, validate, format } = require('@devdataphone/sdk');
// Generate 10 US phone numbers
const numbers = generate({ region: 'US', count: 10 });
console.log(numbers[0].number); // +14155550123
// Validate a phone number
const result = validate('+8613912345678');
console.log(result.valid); // true
console.log(result.country); // China
console.log(result.countryCode); // CN
// Format a phone number
console.log(format('+14155550100', 'national')); // (415) 555-0100
console.log(format('+14155550100', 'international')); // +1 415 555 0100ESM Import
import { generate, validate, format } from '@devdataphone/sdk';API Reference
generate(options)
Generate random phone numbers.
| Option | Type | Default | Description |
|--------|------|---------|-------------|
| region | string | 'US' | Country code (US, UK, CN, IN, AU, CA, DE, FR, JP, BR) |
| count | number | 1 | Number of phone numbers (1-1000) |
| format | string | 'e164' | Output format: 'e164', 'national', 'international', 'digits' |
const numbers = generate({ region: 'UK', count: 5 });
// Returns: [{ number: '+447700900123', national: '07700 900123', ... }]generateOne(region, format)
Generate a single phone number string.
const number = generateOne('CN', 'national');
// Returns: '139 1234 5678'validate(input, options)
Validate a phone number with detailed results.
const result = validate('+14155550100');
// Returns: { valid: true, country: 'United States', countryCode: 'US', type: 'FIXED_LINE_OR_MOBILE', ... }isValid(input, defaultCountry)
Quick boolean validation check.
isValid('+14155550100'); // true
isValid('555-0100', 'US'); // true
isValid('invalid'); // falseisE164(input)
Check if input is valid E.164 format.
isE164('+14155550100'); // true
isE164('(415) 555-0100'); // falseformat(input, style, options)
Format a phone number to different styles.
| Style | Example |
|-------|---------|
| 'e164' | +14155550100 |
| 'national' | (415) 555-0100 |
| 'international' | +1 415 555 0100 |
| 'rfc3966' | tel:+1-415-555-0100 |
| 'digits' | 14155550100 |
Convenience Formatters
toE164('+1 (415) 555-0100'); // +14155550100
toNational('+14155550100'); // (415) 555-0100
toInternational('+14155550100'); // +1 415 555 0100Country Data
const { COUNTRIES, getCountry, getSupportedCountries, isSupported } = require('@devdataphone/sdk');
getSupportedCountries(); // ['US', 'UK', 'CN', 'IN', 'AU', 'CA', 'DE', 'FR', 'JP', 'BR']
isSupported('US'); // true
getCountry('US'); // { code: 'US', name: 'United States', dialCode: '+1', ... }Supported Countries
| Code | Country | Dial Code | |------|---------|-----------| | US | United States | +1 | | UK | United Kingdom | +44 | | CN | China | +86 | | IN | India | +91 | | AU | Australia | +61 | | CA | Canada | +1 | | DE | Germany | +49 | | FR | France | +33 | | JP | Japan | +81 | | BR | Brazil | +55 |
Use Cases
- QA Testing: Generate realistic phone numbers for automated tests
- Database Seeding: Populate development databases with valid phone data
- Mock Data: Create demo data for UI development
- Form Testing: Test phone input validation without using real numbers
💡 Need a visual interface? Visit DevDataPhone.com for an instant online generator.
TypeScript
Full TypeScript definitions are included:
import { generate, validate, format, GenerateOptions, ValidationResult } from '@devdataphone/sdk';
const options: GenerateOptions = { region: 'US', count: 5 };
const numbers = generate(options);
const result: ValidationResult = validate('+14155550100');Optional: Enhanced Validation with libphonenumber-js
For enhanced validation accuracy, optionally install libphonenumber-js:
npm install libphonenumber-jsThe SDK will automatically use it if available.
Related Resources
- 📖 Why Mock Data Matters for Development
- 📖 Stop Using Bad Regex for Phone Validation
- 🛠️ Online Phone Number Generator
License
MIT © DevDataPhone
DevDataPhone.com - Free Phone Number Generator for Developers
