Skip to content

Commit

Permalink
internal refactor
Browse files Browse the repository at this point in the history
  • Loading branch information
cedvdb committed Feb 28, 2024
1 parent 910afa2 commit 77e6d97
Show file tree
Hide file tree
Showing 27 changed files with 261 additions and 310 deletions.
3 changes: 3 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@


## 8.2.0
- added VOIP support
- udpated metadata
- Removed `MinMaxUtils` that was unused internally. While exported publically it was undocumented.

## 8.1.3
- deprectate `getFormattedNsn` in favor of `formatNsn`
Expand Down
11 changes: 5 additions & 6 deletions lib/phone_numbers_parser.dart
Original file line number Diff line number Diff line change
Expand Up @@ -5,12 +5,11 @@ library phone_number_parser;

export 'src/phone_number.dart';

export 'src/models/phone_number_type.dart';
export 'src/models/phone_number_exceptions.dart';
export 'src/models/iso_code.dart';
export 'src/utils/utils.dart';
export 'src/validation/phone_number_type.dart';
export 'src/parsers/phone_number_exceptions.dart';
export 'src/iso_codes/iso_code.dart';

// to remove next major:
export 'src/models/phone_number_range.dart';
export 'src/range/phone_number_range.dart';
export 'src/parsers/phone_parser.dart';
export 'src/formatters/phone_number_formatter.dart';
export 'src/formatting/phone_number_formatter.dart';
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import 'package:phone_numbers_parser/src/parsers/_national_number_parser.dart';
import 'package:phone_numbers_parser/src/regex/match_entirely_extension.dart';

import '../metadata/models/phone_metadata_formats.dart';
import '../models/iso_code.dart';
import '../iso_codes/iso_code.dart';

class PhoneNumberFormatter {
/// format national number for international use
Expand Down
File renamed without changes.
2 changes: 1 addition & 1 deletion lib/src/metadata/generated/country_code_to_iso_code.dart
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import "../../models/iso_code.dart";
import "../../iso_codes/iso_code.dart";

const countryCodeToIsoCode = {
'247': [IsoCode.AC],
Expand Down
2 changes: 1 addition & 1 deletion lib/src/metadata/generated/metadata_by_iso_code.dart
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import "../../models/iso_code.dart";
import "../../iso_codes/iso_code.dart";
import "../models/phone_metadata.dart";

const metadataByIsoCode = {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import "../../models/iso_code.dart";
import "../../iso_codes/iso_code.dart";
import "../models/phone_metadata_examples.dart";

const metadataExamplesByIsoCode = {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import "../../models/iso_code.dart";
import "../../iso_codes/iso_code.dart";
import "../models/phone_metadata_formats.dart";

const metadataFormatsByIsoCode = <IsoCode, PhoneMetadataFormats>{
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import "../../models/iso_code.dart";
import "../../iso_codes/iso_code.dart";
import "../models/phone_metadata_lengths.dart";

const metadataLenghtsByIsoCode = {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import "../../models/iso_code.dart";
import "../../iso_codes/iso_code.dart";
import "../models/phone_metadata_patterns.dart";

const metadataPatternsByIsoCode = {
Expand Down
6 changes: 3 additions & 3 deletions lib/src/metadata/metadata_finder.dart
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import '../parsers/_validator.dart';
import '../validation/validator.dart';
import 'generated/country_code_to_iso_code.dart';
import 'generated/metadata_by_iso_code.dart';
import 'generated/metadata_formats_by_iso_code.dart';
Expand All @@ -8,8 +8,8 @@ import 'models/phone_metadata.dart';
import 'models/phone_metadata_formats.dart';
import 'models/phone_metadata_lengths.dart';
import 'models/phone_metadata_patterns.dart';
import '../models/iso_code.dart';
import '../models/phone_number_exceptions.dart';
import '../iso_codes/iso_code.dart';
import '../parsers/phone_number_exceptions.dart';

/// Helper to find metadata
abstract class MetadataFinder {
Expand Down
2 changes: 1 addition & 1 deletion lib/src/metadata/models/phone_metadata.dart
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import 'dart:convert';

import '../../models/iso_code.dart';
import '../../iso_codes/iso_code.dart';

/// phone metadata
///
Expand Down
4 changes: 2 additions & 2 deletions lib/src/parsers/_country_code_parser.dart
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import 'dart:math';

import 'package:phone_numbers_parser/src/constants/constants.dart';
import 'package:phone_numbers_parser/src/models/phone_number_exceptions.dart';
import 'package:phone_numbers_parser/src/regex/constants.dart';
import 'package:phone_numbers_parser/src/parsers/phone_number_exceptions.dart';
import 'package:phone_numbers_parser/src/metadata/metadata_finder.dart';

abstract class CountryCodeParser {
Expand Down
2 changes: 1 addition & 1 deletion lib/src/parsers/_iso_code_parser.dart
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import 'package:phone_numbers_parser/src/models/phone_number_exceptions.dart';
import 'package:phone_numbers_parser/src/parsers/phone_number_exceptions.dart';

abstract class IsoCodeParser {
/// normalize an iso code to be what the lib expects, mainly uppercases it
Expand Down
2 changes: 1 addition & 1 deletion lib/src/parsers/_text_parser.dart
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import '../constants/constants.dart';
import '../regex/constants.dart';

/// responsible of normalizing and finding phone numbers in text
abstract class TextParser {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,34 +1,34 @@
class PhoneNumberException {
final Code code;
final String? description;

const PhoneNumberException({
required this.code,
this.description,
});

@override
String toString() =>
'PhoneNumberException(code: $code, description: $description)';
}

enum Code {
/// A phone number was not found
notFound,

/// Invalid phone number
invalid,

/// invalid country code
///
/// Valid example: 33 for france
invalidCountryCallingCode,

/// invalid alpha-2 code (example valid)
///
/// Valid example: FR for france
invalidIsoCode,

/// Input has reached the maximum limit
inputIsTooLong
}
class PhoneNumberException {
final Code code;
final String? description;

const PhoneNumberException({
required this.code,
this.description,
});

@override
String toString() =>
'PhoneNumberException(code: $code, description: $description)';
}

enum Code {
/// A phone number was not found
notFound,

/// Invalid phone number
invalid,

/// invalid country code
///
/// Valid example: 33 for france
invalidCountryCallingCode,

/// invalid alpha-2 code (example valid)
///
/// Valid example: FR for france
invalidIsoCode,

/// Input has reached the maximum limit
inputIsTooLong
}
2 changes: 1 addition & 1 deletion lib/src/parsers/phone_parser.dart
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import 'package:meta/meta.dart';
import 'package:phone_numbers_parser/src/parsers/_validator.dart';
import 'package:phone_numbers_parser/src/validation/validator.dart';

import '../../phone_numbers_parser.dart';
import '../metadata/metadata_finder.dart';
Expand Down
10 changes: 5 additions & 5 deletions lib/src/phone_number.dart
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
import 'package:phone_numbers_parser/src/formatters/phone_number_formatter.dart';
import 'package:phone_numbers_parser/src/models/phone_number_range.dart';
import 'package:phone_numbers_parser/src/models/phone_number_type.dart';
import 'package:phone_numbers_parser/src/formatting/phone_number_formatter.dart';
import 'package:phone_numbers_parser/src/range/phone_number_range.dart';
import 'package:phone_numbers_parser/src/validation/phone_number_type.dart';
import 'package:phone_numbers_parser/src/parsers/_text_parser.dart';
import 'package:phone_numbers_parser/src/parsers/_validator.dart';
import 'package:phone_numbers_parser/src/validation/validator.dart';
import 'package:phone_numbers_parser/src/parsers/phone_parser.dart';
import 'package:phone_numbers_parser/src/metadata/metadata_finder.dart';

import 'models/iso_code.dart';
import 'iso_codes/iso_code.dart';

/// represents a phone number
///
Expand Down
File renamed without changes.
146 changes: 73 additions & 73 deletions lib/src/constants/constants.dart → lib/src/regex/constants.dart
Original file line number Diff line number Diff line change
@@ -1,73 +1,73 @@
class Constants {
/// The minimum and maximum length of the country calling code.
static const int minLengthCountryCallingCode = 1;
static const int maxLengthCountryCallingCode = 3;

/// The minimum and maximum length of the national significant number.
/// lib phone number uses 2 but ITU says it's 3
static const int minLengthNsn = 3;

/// The ITU says the maximum length should be 15, but we have found longer numbers in Germany.
static const int maxLengthNsn = 17;

/// New Zealand can have 5 digits
static const int minLengthCountryPlusNsn = 5;

/// accepted punctuation within a phone number
static const String _punctuation = r' ()\[\]\-\.\/\\';
static const String _plus = r'++';

/// Westhen and easthern arabic numerals
static const String _digits = r'0-90-9٠-٩۰-۹';

/// Regex to find possible phone number candidates in a string.
///
/// This regex tries to match all phone numbers. It doesn't match special
/// numbers like the 100.
///
/// The regex must start by either a + or a digit, then be followed by at least 6 digits.
/// The digits are formed of westhern and easthern numerals.
/// There can also be punctuation between the digts.
static final String possiblePhoneNumber =
'[$_plus$_digits](?:[$_punctuation]{0,3}[$_digits]){6,}';

/// Matches strings that look like dates using "/" as a separator. Examples: 3/10/2011, 31/10/96 or
/// 08/31/95.
static final Pattern slashSeparatedDates =
r'(?:(?:[0-3]?\\d/[01]?\\d)|(?:[01]?\\d/[0-3]?\\d))/(?:[12]\\d)?\\d{2}';
// Replace Easthern to Westhern arabic numbers https://en.wikipedia.org/wiki/Eastern_Arabic_numerals
static Map<String, String> allNormalizationMappings = {
'+': '+',
'+': '+',
'0': '0',
'1': '1',
'2': '2',
'3': '3',
'4': '4',
'5': '5',
'6': '6',
'7': '7',
'8': '8',
'9': '9',
'٠': '0',
'١': '1',
'٢': '2',
'٣': '3',
'٤': '4',
'٥': '5',
'٦': '6',
'٧': '7',
'٨': '8',
'٩': '9',
'۰': '0',
'۱': '1',
'۲': '2',
'۳': '3',
'۴': '4',
'۵': '5',
'۶': '6',
'۷': '7',
'۸': '8',
'۹': '9',
};
}
class Constants {
/// The minimum and maximum length of the country calling code.
static const int minLengthCountryCallingCode = 1;
static const int maxLengthCountryCallingCode = 3;

/// The minimum and maximum length of the national significant number.
/// lib phone number uses 2 but ITU says it's 3
static const int minLengthNsn = 3;

/// The ITU says the maximum length should be 15, but we have found longer numbers in Germany.
static const int maxLengthNsn = 17;

/// New Zealand can have 5 digits
static const int minLengthCountryPlusNsn = 5;

/// accepted punctuation within a phone number
static const String _punctuation = r' ()\[\]\-\.\/\\';
static const String _plus = r'++';

/// Westhen and easthern arabic numerals
static const String _digits = r'0-90-9٠-٩۰-۹';

/// Regex to find possible phone number candidates in a string.
///
/// This regex tries to match all phone numbers. It doesn't match special
/// numbers like the 100.
///
/// The regex must start by either a + or a digit, then be followed by at least 6 digits.
/// The digits are formed of westhern and easthern numerals.
/// There can also be punctuation between the digts.
static final String possiblePhoneNumber =
'[$_plus$_digits](?:[$_punctuation]{0,3}[$_digits]){6,}';

/// Matches strings that look like dates using "/" as a separator. Examples: 3/10/2011, 31/10/96 or
/// 08/31/95.
static final Pattern slashSeparatedDates =
r'(?:(?:[0-3]?\\d/[01]?\\d)|(?:[01]?\\d/[0-3]?\\d))/(?:[12]\\d)?\\d{2}';
// Replace Easthern to Westhern arabic numbers https://en.wikipedia.org/wiki/Eastern_Arabic_numerals
static Map<String, String> allNormalizationMappings = {
'+': '+',
'+': '+',
'0': '0',
'1': '1',
'2': '2',
'3': '3',
'4': '4',
'5': '5',
'6': '6',
'7': '7',
'8': '8',
'9': '9',
'٠': '0',
'١': '1',
'٢': '2',
'٣': '3',
'٤': '4',
'٥': '5',
'٦': '6',
'٧': '7',
'٨': '8',
'٩': '9',
'۰': '0',
'۱': '1',
'۲': '2',
'۳': '3',
'۴': '4',
'۵': '5',
'۶': '6',
'۷': '7',
'۸': '8',
'۹': '9',
};
}
Loading

0 comments on commit 77e6d97

Please sign in to comment.