Generate valid E.164 phone numbers for QA testing, database seeding, and mock data. Zero server-side retention.
npm install @devdataphone/sdkbash
npm install @devdataphone/sdk
`
Quick Start
`javascript
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 0100
`
$3
`javascript
import { generate, validate, format } from '@devdataphone/sdk';
`
API Reference
$3
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' |
`javascript
const numbers = generate({ region: 'UK', count: 5 });
// Returns: [{ number: '+447700900123', national: '07700 900123', ... }]
`
$3
Generate a single phone number string.
`javascript
const number = generateOne('CN', 'national');
// Returns: '139 1234 5678'
`
$3
Validate a phone number with detailed results.
`javascript
const result = validate('+14155550100');
// Returns: { valid: true, country: 'United States', countryCode: 'US', type: 'FIXED_LINE_OR_MOBILE', ... }
`
$3
Quick boolean validation check.
`javascript
isValid('+14155550100'); // true
isValid('555-0100', 'US'); // true
isValid('invalid'); // false
`
$3
Check if input is valid E.164 format.
`javascript
isE164('+14155550100'); // true
isE164('(415) 555-0100'); // false
`
$3
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 |
$3
`javascript
toE164('+1 (415) 555-0100'); // +14155550100
toNational('+14155550100'); // (415) 555-0100
toInternational('+14155550100'); // +1 415 555 0100
`
$3
`javascript
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:
`typescript
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:
`bash
npm install libphonenumber-js
``