Isbn extension type
An ISBN (International Standard Book Number): validated for length, prefix, and the ISO 2108 check digit, mod-11 over the ten-digit form and GS1 mod-10 over the thirteen-digit one. Standard: ISO 2108.
Normalisation on parse: spaces and hyphens are stripped, a trailing x is upper-cased, and the
ten-digit form is folded into its thirteen-digit equivalent, so value is always thirteen digits
and the two spellings of one book compare equal. isbn10 rebuilds the legacy form.
Not hyphenated: the group boundaries come from ISBN International's range table, not the digits.
final isbn = Isbn.tryParse('0-306-40615-2')!;
print(isbn.value); // 9780306406157
print(isbn.isbn10); // 0306406152 (null for a 979 ISBN, which never had one)
print(Isbn.tryParse('9790260000438')); // null (an ISMN: printed music, not a book)
- on
Properties
- body → Digits
-
The nine digits between the prefix and the check digit: registration group, registrant and
publication, run together. Splitting them needs a range table this package does not carry.
no setter
- checkDigit → Digit
-
The final digit, the GS1 mod-10 check over the other twelve.
no setter
- isbn10 → String?
-
The legacy ten-character form (mod-11 check digit,
Xfor ten), ornullfor a979ISBN, which never had one.no setter - prefix → Digits
-
The three-digit GS1 prefix,
978or979. Read Digits.asString for the plain text.no setter - value → String
-
final
Static Methods
-
fromComponents(
{required Digits prefix, required Digits body}) → ParseOutcome< IsbnFailure, Isbn> -
Builds an Isbn from its GS1
prefix(978or979) and nine-digitbody, computing the check digit, reporting the IsbnFailure when the parts don't form a valid ISBN. -
parse(
String input) → ParseOutcome< IsbnFailure, Isbn> -
Parses
inputas an ISBN, reporting the IsbnFailure that says which check failed. -
tryParse(
String input) → Isbn? -
Parses
inputas an ISBN, or returnsnullwhen it fails the length, character, prefix, or check-digit tests. Both generations are accepted; the result is always thirteen digits.