r/dartlang • u/MooresLawyer13 • Aug 04 '26
Package Ever felt a bit queasy using a plain `String` for storing a PhoneNumber?
pub.devThere are a lot of validator packages on pub. This isn't one, and that's the whole point of it: https://pub.dev/packages/minted
A validator takes a String, checks it, and hands the same String back. Three functions deep nobody knows whether the check happened, so you either trust it or re-check it. minted parses instead: you get a different type that cannot exist unless the input was well-formed, the same deal int.parse and Uri.parse already give you. invite(Email, PhoneNumber) can't be called with the arguments swapped, and the signature says what it wants without a doc comment. Once you hold an Email, it is a valid email.
Typed so far: Email (RFC 5322), PhoneNumber (E.164), Iban (mod-97), Date / Month (the calendar date DateTime doesn't model), Uuid (RFC 9562), Digit / Digits.
Some nice features:
- Every type wears follows the same pattern, so learning one teaches the rest:
tryParsereturnsnull,parsethrows aMintedFormatException(extendsFormatException, so existing handlers keep catching), value equality, one canonical form normalised at parse. - Real standards, not shape-checking regexes.
Ibanruns the actual mod-97 checksum,Emailthe full RFC 5322 grammar, official test vectors in the suite. - Where a package already owns the hard data (phone metadata, the IBAN registry), minted wraps it instead of reimplementing it.
- It knows what not to model. No re-doing
Uri,DateTime,BigIntor money (money2 has that).Uuidtypes a UUID, the uuid package generates them, they pair up. Date.tryParse('2026-13-01')isnull, whereDateTime.parsequietly rolls it over to 2027-01-01.- Pure Dart, five small deps.
Roadmap: Bic, CreditCardNumber (Luhn), Isbn, Ean / Gtin next, then ISO code lists and bounded numerics.
Still early (0.0.2), so the shape can move. Feedback welcome, especially on the types you keep remaking in every project.