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_parser
with 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