Skip to content

Commit 77e6d97

Browse files
committed
internal refactor
1 parent 910afa2 commit 77e6d97

27 files changed

+261
-310
lines changed

CHANGELOG.md

+3
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,9 @@
1+
2+
13
## 8.2.0
24
- added VOIP support
35
- udpated metadata
6+
- Removed `MinMaxUtils` that was unused internally. While exported publically it was undocumented.
47

58
## 8.1.3
69
- deprectate `getFormattedNsn` in favor of `formatNsn`

lib/phone_numbers_parser.dart

+5-6
Original file line numberDiff line numberDiff line change
@@ -5,12 +5,11 @@ library phone_number_parser;
55

66
export 'src/phone_number.dart';
77

8-
export 'src/models/phone_number_type.dart';
9-
export 'src/models/phone_number_exceptions.dart';
10-
export 'src/models/iso_code.dart';
11-
export 'src/utils/utils.dart';
8+
export 'src/validation/phone_number_type.dart';
9+
export 'src/parsers/phone_number_exceptions.dart';
10+
export 'src/iso_codes/iso_code.dart';
1211

1312
// to remove next major:
14-
export 'src/models/phone_number_range.dart';
13+
export 'src/range/phone_number_range.dart';
1514
export 'src/parsers/phone_parser.dart';
16-
export 'src/formatters/phone_number_formatter.dart';
15+
export 'src/formatting/phone_number_formatter.dart';

lib/src/formatters/phone_number_formatter.dart lib/src/formatting/phone_number_formatter.dart

+1-1
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ import 'package:phone_numbers_parser/src/parsers/_national_number_parser.dart';
55
import 'package:phone_numbers_parser/src/regex/match_entirely_extension.dart';
66

77
import '../metadata/models/phone_metadata_formats.dart';
8-
import '../models/iso_code.dart';
8+
import '../iso_codes/iso_code.dart';
99

1010
class PhoneNumberFormatter {
1111
/// format national number for international use
File renamed without changes.

lib/src/metadata/generated/country_code_to_iso_code.dart

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import "../../models/iso_code.dart";
1+
import "../../iso_codes/iso_code.dart";
22

33
const countryCodeToIsoCode = {
44
'247': [IsoCode.AC],

lib/src/metadata/generated/metadata_by_iso_code.dart

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import "../../models/iso_code.dart";
1+
import "../../iso_codes/iso_code.dart";
22
import "../models/phone_metadata.dart";
33

44
const metadataByIsoCode = {

lib/src/metadata/generated/metadata_examples_by_iso_code.dart

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import "../../models/iso_code.dart";
1+
import "../../iso_codes/iso_code.dart";
22
import "../models/phone_metadata_examples.dart";
33

44
const metadataExamplesByIsoCode = {

lib/src/metadata/generated/metadata_formats_by_iso_code.dart

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import "../../models/iso_code.dart";
1+
import "../../iso_codes/iso_code.dart";
22
import "../models/phone_metadata_formats.dart";
33

44
const metadataFormatsByIsoCode = <IsoCode, PhoneMetadataFormats>{

lib/src/metadata/generated/metadata_lengths_by_iso_code.dart

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import "../../models/iso_code.dart";
1+
import "../../iso_codes/iso_code.dart";
22
import "../models/phone_metadata_lengths.dart";
33

44
const metadataLenghtsByIsoCode = {

lib/src/metadata/generated/metadata_patterns_by_iso_code.dart

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import "../../models/iso_code.dart";
1+
import "../../iso_codes/iso_code.dart";
22
import "../models/phone_metadata_patterns.dart";
33

44
const metadataPatternsByIsoCode = {

lib/src/metadata/metadata_finder.dart

+3-3
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import '../parsers/_validator.dart';
1+
import '../validation/validator.dart';
22
import 'generated/country_code_to_iso_code.dart';
33
import 'generated/metadata_by_iso_code.dart';
44
import 'generated/metadata_formats_by_iso_code.dart';
@@ -8,8 +8,8 @@ import 'models/phone_metadata.dart';
88
import 'models/phone_metadata_formats.dart';
99
import 'models/phone_metadata_lengths.dart';
1010
import 'models/phone_metadata_patterns.dart';
11-
import '../models/iso_code.dart';
12-
import '../models/phone_number_exceptions.dart';
11+
import '../iso_codes/iso_code.dart';
12+
import '../parsers/phone_number_exceptions.dart';
1313

1414
/// Helper to find metadata
1515
abstract class MetadataFinder {

lib/src/metadata/models/phone_metadata.dart

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import 'dart:convert';
22

3-
import '../../models/iso_code.dart';
3+
import '../../iso_codes/iso_code.dart';
44

55
/// phone metadata
66
///

lib/src/parsers/_country_code_parser.dart

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import 'dart:math';
22

3-
import 'package:phone_numbers_parser/src/constants/constants.dart';
4-
import 'package:phone_numbers_parser/src/models/phone_number_exceptions.dart';
3+
import 'package:phone_numbers_parser/src/regex/constants.dart';
4+
import 'package:phone_numbers_parser/src/parsers/phone_number_exceptions.dart';
55
import 'package:phone_numbers_parser/src/metadata/metadata_finder.dart';
66

77
abstract class CountryCodeParser {

lib/src/parsers/_iso_code_parser.dart

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import 'package:phone_numbers_parser/src/models/phone_number_exceptions.dart';
1+
import 'package:phone_numbers_parser/src/parsers/phone_number_exceptions.dart';
22

33
abstract class IsoCodeParser {
44
/// normalize an iso code to be what the lib expects, mainly uppercases it

lib/src/parsers/_text_parser.dart

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import '../constants/constants.dart';
1+
import '../regex/constants.dart';
22

33
/// responsible of normalizing and finding phone numbers in text
44
abstract class TextParser {
Original file line numberDiff line numberDiff line change
@@ -1,34 +1,34 @@
1-
class PhoneNumberException {
2-
final Code code;
3-
final String? description;
4-
5-
const PhoneNumberException({
6-
required this.code,
7-
this.description,
8-
});
9-
10-
@override
11-
String toString() =>
12-
'PhoneNumberException(code: $code, description: $description)';
13-
}
14-
15-
enum Code {
16-
/// A phone number was not found
17-
notFound,
18-
19-
/// Invalid phone number
20-
invalid,
21-
22-
/// invalid country code
23-
///
24-
/// Valid example: 33 for france
25-
invalidCountryCallingCode,
26-
27-
/// invalid alpha-2 code (example valid)
28-
///
29-
/// Valid example: FR for france
30-
invalidIsoCode,
31-
32-
/// Input has reached the maximum limit
33-
inputIsTooLong
34-
}
1+
class PhoneNumberException {
2+
final Code code;
3+
final String? description;
4+
5+
const PhoneNumberException({
6+
required this.code,
7+
this.description,
8+
});
9+
10+
@override
11+
String toString() =>
12+
'PhoneNumberException(code: $code, description: $description)';
13+
}
14+
15+
enum Code {
16+
/// A phone number was not found
17+
notFound,
18+
19+
/// Invalid phone number
20+
invalid,
21+
22+
/// invalid country code
23+
///
24+
/// Valid example: 33 for france
25+
invalidCountryCallingCode,
26+
27+
/// invalid alpha-2 code (example valid)
28+
///
29+
/// Valid example: FR for france
30+
invalidIsoCode,
31+
32+
/// Input has reached the maximum limit
33+
inputIsTooLong
34+
}

lib/src/parsers/phone_parser.dart

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import 'package:meta/meta.dart';
2-
import 'package:phone_numbers_parser/src/parsers/_validator.dart';
2+
import 'package:phone_numbers_parser/src/validation/validator.dart';
33

44
import '../../phone_numbers_parser.dart';
55
import '../metadata/metadata_finder.dart';

lib/src/phone_number.dart

+5-5
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,12 @@
1-
import 'package:phone_numbers_parser/src/formatters/phone_number_formatter.dart';
2-
import 'package:phone_numbers_parser/src/models/phone_number_range.dart';
3-
import 'package:phone_numbers_parser/src/models/phone_number_type.dart';
1+
import 'package:phone_numbers_parser/src/formatting/phone_number_formatter.dart';
2+
import 'package:phone_numbers_parser/src/range/phone_number_range.dart';
3+
import 'package:phone_numbers_parser/src/validation/phone_number_type.dart';
44
import 'package:phone_numbers_parser/src/parsers/_text_parser.dart';
5-
import 'package:phone_numbers_parser/src/parsers/_validator.dart';
5+
import 'package:phone_numbers_parser/src/validation/validator.dart';
66
import 'package:phone_numbers_parser/src/parsers/phone_parser.dart';
77
import 'package:phone_numbers_parser/src/metadata/metadata_finder.dart';
88

9-
import 'models/iso_code.dart';
9+
import 'iso_codes/iso_code.dart';
1010

1111
/// represents a phone number
1212
///
File renamed without changes.
Original file line numberDiff line numberDiff line change
@@ -1,73 +1,73 @@
1-
class Constants {
2-
/// The minimum and maximum length of the country calling code.
3-
static const int minLengthCountryCallingCode = 1;
4-
static const int maxLengthCountryCallingCode = 3;
5-
6-
/// The minimum and maximum length of the national significant number.
7-
/// lib phone number uses 2 but ITU says it's 3
8-
static const int minLengthNsn = 3;
9-
10-
/// The ITU says the maximum length should be 15, but we have found longer numbers in Germany.
11-
static const int maxLengthNsn = 17;
12-
13-
/// New Zealand can have 5 digits
14-
static const int minLengthCountryPlusNsn = 5;
15-
16-
/// accepted punctuation within a phone number
17-
static const String _punctuation = r' ()\[\]\-\.\/\\';
18-
static const String _plus = r'++';
19-
20-
/// Westhen and easthern arabic numerals
21-
static const String _digits = r'0-90-9٠-٩۰-۹';
22-
23-
/// Regex to find possible phone number candidates in a string.
24-
///
25-
/// This regex tries to match all phone numbers. It doesn't match special
26-
/// numbers like the 100.
27-
///
28-
/// The regex must start by either a + or a digit, then be followed by at least 6 digits.
29-
/// The digits are formed of westhern and easthern numerals.
30-
/// There can also be punctuation between the digts.
31-
static final String possiblePhoneNumber =
32-
'[$_plus$_digits](?:[$_punctuation]{0,3}[$_digits]){6,}';
33-
34-
/// Matches strings that look like dates using "/" as a separator. Examples: 3/10/2011, 31/10/96 or
35-
/// 08/31/95.
36-
static final Pattern slashSeparatedDates =
37-
r'(?:(?:[0-3]?\\d/[01]?\\d)|(?:[01]?\\d/[0-3]?\\d))/(?:[12]\\d)?\\d{2}';
38-
// Replace Easthern to Westhern arabic numbers https://en.wikipedia.org/wiki/Eastern_Arabic_numerals
39-
static Map<String, String> allNormalizationMappings = {
40-
'+': '+',
41-
'+': '+',
42-
'0': '0',
43-
'1': '1',
44-
'2': '2',
45-
'3': '3',
46-
'4': '4',
47-
'5': '5',
48-
'6': '6',
49-
'7': '7',
50-
'8': '8',
51-
'9': '9',
52-
'٠': '0',
53-
'١': '1',
54-
'٢': '2',
55-
'٣': '3',
56-
'٤': '4',
57-
'٥': '5',
58-
'٦': '6',
59-
'٧': '7',
60-
'٨': '8',
61-
'٩': '9',
62-
'۰': '0',
63-
'۱': '1',
64-
'۲': '2',
65-
'۳': '3',
66-
'۴': '4',
67-
'۵': '5',
68-
'۶': '6',
69-
'۷': '7',
70-
'۸': '8',
71-
'۹': '9',
72-
};
73-
}
1+
class Constants {
2+
/// The minimum and maximum length of the country calling code.
3+
static const int minLengthCountryCallingCode = 1;
4+
static const int maxLengthCountryCallingCode = 3;
5+
6+
/// The minimum and maximum length of the national significant number.
7+
/// lib phone number uses 2 but ITU says it's 3
8+
static const int minLengthNsn = 3;
9+
10+
/// The ITU says the maximum length should be 15, but we have found longer numbers in Germany.
11+
static const int maxLengthNsn = 17;
12+
13+
/// New Zealand can have 5 digits
14+
static const int minLengthCountryPlusNsn = 5;
15+
16+
/// accepted punctuation within a phone number
17+
static const String _punctuation = r' ()\[\]\-\.\/\\';
18+
static const String _plus = r'++';
19+
20+
/// Westhen and easthern arabic numerals
21+
static const String _digits = r'0-90-9٠-٩۰-۹';
22+
23+
/// Regex to find possible phone number candidates in a string.
24+
///
25+
/// This regex tries to match all phone numbers. It doesn't match special
26+
/// numbers like the 100.
27+
///
28+
/// The regex must start by either a + or a digit, then be followed by at least 6 digits.
29+
/// The digits are formed of westhern and easthern numerals.
30+
/// There can also be punctuation between the digts.
31+
static final String possiblePhoneNumber =
32+
'[$_plus$_digits](?:[$_punctuation]{0,3}[$_digits]){6,}';
33+
34+
/// Matches strings that look like dates using "/" as a separator. Examples: 3/10/2011, 31/10/96 or
35+
/// 08/31/95.
36+
static final Pattern slashSeparatedDates =
37+
r'(?:(?:[0-3]?\\d/[01]?\\d)|(?:[01]?\\d/[0-3]?\\d))/(?:[12]\\d)?\\d{2}';
38+
// Replace Easthern to Westhern arabic numbers https://en.wikipedia.org/wiki/Eastern_Arabic_numerals
39+
static Map<String, String> allNormalizationMappings = {
40+
'+': '+',
41+
'+': '+',
42+
'0': '0',
43+
'1': '1',
44+
'2': '2',
45+
'3': '3',
46+
'4': '4',
47+
'5': '5',
48+
'6': '6',
49+
'7': '7',
50+
'8': '8',
51+
'9': '9',
52+
'٠': '0',
53+
'١': '1',
54+
'٢': '2',
55+
'٣': '3',
56+
'٤': '4',
57+
'٥': '5',
58+
'٦': '6',
59+
'٧': '7',
60+
'٨': '8',
61+
'٩': '9',
62+
'۰': '0',
63+
'۱': '1',
64+
'۲': '2',
65+
'۳': '3',
66+
'۴': '4',
67+
'۵': '5',
68+
'۶': '6',
69+
'۷': '7',
70+
'۸': '8',
71+
'۹': '9',
72+
};
73+
}

0 commit comments

Comments
 (0)