Safe Haskell | Safe-Inferred |
---|---|
Language | Haskell2010 |
Synopsis
- data ISBN = ISBN13 Text
- validateISBN13 :: Text -> Either ISBN13ValidationError ISBN
- renderISBN13ValidationError :: ISBN13ValidationError -> Text
- data ISBN13ValidationError
- confirmISBN13CheckDigit :: Text -> Bool
- calculateISBN13CheckDigitValue :: Text -> Int
- numericValueToISBN13Char :: Int -> Char
- isISBN13 :: ISBN -> Bool
- unsafeToISBN13 :: Text -> ISBN
Documentation
Data type for representing ISBN values. Values of this type should be
created safely using validateISBN
, which will produce ISBN10
or ISBN13
values after validating the input.
The validateISBN10
and validateISBN13
functions can
also be used to only attempt to create ISBNs of a specific type.
To create ISBN
values without validation, use the unsafeToISBN10
and unsafeToISBN13
functions to coerce Text
values
into ISBN
values.
validateISBN13 :: Text -> Either ISBN13ValidationError ISBN Source #
Used to safely create ISBN13
values represented by the ISBN
data type.
Assumes that the Text
input is an ISBN-13 string, either with or
without hyphens.
Will return either a validated ISBN-13 or an ISBN13ValidationError
, which can be
rendered as a descriptive string using renderISBN13ValidationError
.
Examples:
validateISBN13 "9780345816023" == Right (ISBN13 "9780345816023") validateISBN13 "9780807014295" == Right (ISBN13 "9780807014295") validateISBN13 "9780306406157" == Right (ISBN13 "9780306406157") validateISBN13 "978-0-306-40615-7" == Right (ISBN13 "9780306406157") validateISBN13 "9780345816029" == Left ISBN13InvalidCheckDigit validateISBN13 "9780807014299" == Left ISBN13InvalidCheckDigit validateISBN13 "00000000000000" == Left ISBN13InvalidInputLength validateISBN13 "0X00000000000" == Left ISBN13IllegalCharactersInInput
Validation Errors
renderISBN13ValidationError :: ISBN13ValidationError -> Text Source #
Convert an ISBN13ValidationError
into a human-friendly error message.
data ISBN13ValidationError Source #
Possible validation errors resulting from ISBN-13 validation.
ISBN13InvalidInputLength | The length of the input string is not 13 characters, not counting hyphens |
ISBN13IllegalCharactersInInput | The ISBN-13 input contains non-numeric characters |
ISBN13InvalidCheckDigit | The check digit is not valid for the given ISBN-13 |
Instances
Eq ISBN13ValidationError Source # | |
Defined in Data.ISBN.ISBN13 (==) :: ISBN13ValidationError -> ISBN13ValidationError -> Bool # (/=) :: ISBN13ValidationError -> ISBN13ValidationError -> Bool # | |
Show ISBN13ValidationError Source # | |
Defined in Data.ISBN.ISBN13 showsPrec :: Int -> ISBN13ValidationError -> ShowS # show :: ISBN13ValidationError -> String # showList :: [ISBN13ValidationError] -> ShowS # |
Helpers
confirmISBN13CheckDigit :: Text -> Bool Source #
Confirms that the check digit of an ISBN-13 is correct. Assumes that the
input consists of 12 numeric characters followed by a legal check digit
character (0-9
).
Examples:
confirmISBN13CheckDigit "9780306406157" == True confirmISBN13CheckDigit "9780345816029" == False
calculateISBN13CheckDigitValue :: Text -> Int Source #
Calculates an ISBN-13 check digit value using the standard check digit calculation formula. Assumes that the input is 12 numeric characters. The check digit value will be a number from 0 to 9.
See: https://en.wikipedia.org/wiki/International_Standard_Book_Number#ISBN-13_check_digit_calculation
Examples:
calculateISBN13CheckDigitValue "978030640615" == 7 calculateISBN13CheckDigitValue "978151915024" == 0
numericValueToISBN13Char :: Int -> Char Source #
Converts a numeric value to an ISBN-13 character. Valid input values are the numbers from 0 to 10.
isISBN13 :: ISBN -> Bool Source #
Determines whether an ISBN
value is an ISBN-13.
Examples:
isISBN13 (unsafeToISBN10 "0060899220") == False isISBN13 (unsafeToISBN13 "9780060899226") == True
Since: 1.1.0.0