Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

adds Japanese phone number support #73

Merged
merged 1 commit into from
Apr 17, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
44 changes: 44 additions & 0 deletions lib/src/phone_number.dart
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,48 @@ class PhoneNumber {
'0049 (0)### ######x##',
'0049 (0)### ######/##',
];
static const jaPhoneNumberPatterns = [
// // Standard non-geographic 10-digit phone number formats
'0#########',
'0#-####-####',
'(0#) ####-####',
'0##-###-####',
'(0##) ###-####',
'0###-##-####',
'(0###) ##-####',
// // Standard non-geographic 11-digit phone number formats
'0##########',
'0#-#####-####',
'(0#) #####-####',
'0##-####-####',
'(0##) ####-####',
'0###-###-####',
'(0###) ###-####',
// // Standard non-geographic 10-digit phone number formats with country code
'+810#########',
'+81-0#########',
'+81 0#########',
'+81-0#-####-####',
'+81 0#-####-####',
'+81 (0#) ####-####',
'+81-0##-###-####',
'+81 0##-###-####',
'+81 (0##) ###-####',
'+81-0###-##-####',
'+81 0###-##-####',
'+81 (0###) ##-####',
// // Standard non-geographic 11-digit phone number formats with country code
'+810##########',
'+81-0#-#####-####',
'+81 0#-#####-####',
'+81 (0#) #####-####',
'+81-0##-####-####',
'+81 0##-####-####',
'+81 (0##) ####-####',
'+81-0###-###-####',
'+81 0###-###-####',
'+81 (0###) ###-####',
];

const PhoneNumber(this.random);

Expand All @@ -87,4 +129,6 @@ class PhoneNumber {
String us() => random.fromPattern(usPhoneNumberPatterns);

String de() => random.fromPattern(dePhoneNumberPatterns);

String ja() => random.fromPattern(jaPhoneNumberPatterns);
}
52 changes: 52 additions & 0 deletions test/specs/phone_number.dart
Original file line number Diff line number Diff line change
Expand Up @@ -129,4 +129,56 @@ void main() {
}
});
});
group('ja', () {
test('should be able to generate ja phone number', () {
for (var i = 0; i < 20; i++) {
expect(
faker.phoneNumber.ja(),
anyOf(
[
// // Standard non-geographic 10-digit phone number formats
matches(r'0\d{9}'),
matches(r'0\d{1}-\d{4}-\d{4}'),
matches(r'\(0\d{1}\) \d{4}-\d{4}'),
matches(r'0\d{2}-\d{3}-\d{4}'),
matches(r'\(0\d{2}\) \d{3}-\d{4}'),
matches(r'0\d{3}-\d{2}-\d{4}'),
matches(r'\(0\d{3}\) \d{2}-\d{4}'),
// // Standard non-geographic 11-digit phone number formats
matches(r'0\d{10}'),
matches(r'0\d{1}-\d{5}-\d{4}'),
matches(r'\(0\d{1}\) \d{5}-\d{4}'),
matches(r'0\d{2}-\d{4}-\d{4}'),
matches(r'\(0\d{2}\) \d{4}-\d{4}'),
matches(r'0\d{3}-\d{3}-\d{4}'),
matches(r'\(0\d{3}\) \d{3}-\d{4}'),
// // Standard non-geographic 10-digit phone number formats with country code
matches(r'\+810\d{9}'),
matches(r'\+81-0\d{9}'),
matches(r'\+81 0\d{9}'),
matches(r'\+81-\(0\d{1}\)-\d{4}-\d{4}'),
matches(r'\+81 \(0\d{1}\) \d{4}-\d{4}'),
matches(r'\+81-0\d{2}-\d{3}-\d{4}'),
matches(r'\+81 0\d{2}-\d{3}-\d{4}'),
matches(r'\+81 \(0\d{2}\) \d{3}-\d{4}'),
matches(r'\+81-0\d{3}-\d{2}-\d{4}'),
matches(r'\+81 0\d{3}-\d{2}-\d{4}'),
matches(r'\+81 \(0\d{3}\) \d{2}-\d{4}'),
// // Standard non-geographic 11-digit phone number formats with country code
matches(r'\+810\d{10}'),
matches(r'\+81-0\d{1}-\d{5}-\d{4}'),
matches(r'\+81 0\d{1}-\d{5}-\d{4}'),
matches(r'\+81 \(0\d{1}\) \d{5}-\d{4}'),
matches(r'\+81-0\d{2}-\d{4}-\d{4}'),
matches(r'\+81 0\d{2}-\d{4}-\d{4}'),
matches(r'\+81 \(0\d{2}\) \d{4}-\d{4}'),
matches(r'\+81-0\d{3}-\d{3}-\d{4}'),
matches(r'\+81 0\d{3}-\d{3}-\d{4}'),
matches(r'\+81 \(0\d{3}\) \d{3}-\d{4}'),
],
),
);
}
});
});
}