phone_parser 0.0.7
phone_parser: ^0.0.7 copied to clipboard
Dart library for parsing phone numbers with auto synced with Google libphonenumber. Inspired by Google's libphonenumber and PhoneNumberKit for ios.
π Phone Parser #
A Dart library for parsing, validating, and formatting phone numbers β always in sync with Googleβs libphonenumber.
Unlike traditional phone number libraries where you wait for maintainers to publish updates, phone_parser auto-syncs with Googleβs libphonenumber.
That means whenever Google ships a new release, your project gets the latest intelligence instantly β no delays, no stale metadata, no headaches.
β¨ Whether youβre building a shiny new Flutter app or running a Dart backend server, phone_parser is smart, reliable, and always up-to-date.
So you can focus on building while phone_parser takes care of keeping things current. π‘
π Why phone_parser? #
Googleβs libphonenumber is fantastic, but:
- β It isnβt natively available for all platforms.
- β You often need channels or bindings to use it.
- β Updates depend on maintainers.
β
phone_parser solves this:
- Works across all Dart platforms (Flutter, backend, CLI).
- Ships with auto-synced metadata from Googleβs libphonenumber.
- A fork of
phone_numbers_parserwith seamless updates built-in.
β¨ Features #
- β Validation β Check if a number is valid, by type (mobile, fixed line, VoIP, etc.)
- β Formatting β Format numbers region-specifically
- β Phone Ranges β Expand or compare ranges of numbers
- β Number Extraction β Find phone numbers in plain text
- β Eastern Arabic digits support
- β Best-in-class metadata β Always fresh from Googleβs libphonenumber
π Demo #
Try it out: Live Demo
π¦ Installation #
dependencies:
phone_parser: ^latest
π Usage #
Start with the PhoneNumber class:
import 'package:phone_parser/phone_parser.dart';
void main() async {
// Load metadata before parsing numbers
await MetadataFinder.readMetadataJson("./");
final frPhone0 = PhoneNumber.parse('+33 655 5705 76');
// Parsing in different contexts
final frPhone1 = PhoneNumber.parse('0 655 5705 76', callerCountry: "FR");
final frPhone2 = PhoneNumber.parse('011 33 655-5705-76', callerCountry: "US");
final frPhone3 = PhoneNumber.parse('011 33 655 5705 76', destinationCountry: "FR");
final isAllEqual = frPhone0 == frPhone1 && frPhone0 == frPhone2 && frPhone0 == frPhone3;
print(frPhone1);
print('All representations equal: $isAllEqual');
// β
Validation
print('valid: ${frPhone1.isValid()}');
print('valid mobile: ${frPhone1.isValid(type: PhoneNumberType.mobile)}');
print('valid fixed line: ${frPhone1.isValid(type: PhoneNumberType.fixedLine)}');
// β
Extract numbers from text
final text = 'hey my number is: +33 939 876 218, or call me on +33 939 876 999';
final found = PhoneNumber.findPotentialPhoneNumbers(text);
print('Found: $found');
}
β Validation #
final valid = phone.validate();
final validMobile = phone.validate(type: PhoneNumberType.mobile);
final validFixed = phone.validate(type: PhoneNumberType.fixedLine);
π¨ Formatting #
Region-specific formatting that respects local conventions:
final phoneNumber = PhoneNumber.parse('2025550119', destinationCountry: IsoCode.US);
print(phoneNumber.formatNsn()); // (202) 555-0119
π’ Ranges #
Work with phone numbers like numbers:
final first = PhoneNumber.parse('+33 655 5705 00');
final last = PhoneNumber.parse('+33 655 5705 03');
final range = PhoneNumber.getRange(first, last);
print('Count: ${range.count}');
print('Expanded: ${range.expandRange()}');
final one = PhoneNumber.parse('+33 655 5705 01');
final two = PhoneNumber.parse('+33 655 5705 02');
if (one.isAdjacentTo(two)) print('We are adjacent');
if (one.isSequentialTo(two)) print('$two comes after $one');
final three = two + 1;
print('Still a phone number: $three'); // +33 655 5705 03
π€ Contributing #
Contributions are welcome! π
If youβd like to improve phone_parser:
- Fork the repo
- Create a new branch:
git checkout -b feature/my-feature - Commit your changes:
git commit -m 'Add my feature' - Push to the branch:
git push origin feature/my-feature - Open a Pull Request π
π License #
This project is licensed under the MIT License.
π‘ Summary:
- π Works everywhere (Flutter, CLI, Server)
- β‘ Auto-syncs with Googleβs libphonenumber
- π Reliable, consistent, always up-to-date
