minted_contact 1.0.2
minted_contact: ^1.0.2 copied to clipboard
Well-modelled Dart value types for contact details: Email and PhoneNumber, checked against the real standards rather than a regex. Part of the minted family.
example/minted_contact_example.dart
// This example prints to stdout so it runs standalone via `dart run`.
// ignore_for_file: avoid_print
import 'package:minted_contact/minted_contact.dart';
void main() {
// Parse, don't validate: an `Email` exists only if it is well-formed.
// #region email
final email = Email.tryParse('Jane.Doe@Example.COM')!;
print(email.value); // Jane.Doe@example.com (domain lower-cased)
print(email.domain); // example.com
print(email.mailtoUri); // mailto:Jane.Doe@example.com
print(Email.tryParse('not-an-email')); // null
// #endregion
// `PhoneNumber` normalises to E.164. National-format input needs a region
// `+`-international input does not.
// #region phone
final phone = PhoneNumber.tryParse('0 655 5705 76', region: 'FR')!;
print(phone.value); // +33655570576
print(phone.type); // PhoneNumberType.mobile
print(phone.telUri); // tel:+33655570576
// #endregion
}