| Safe Haskell | Safe |
|---|---|
| Language | Haskell2010 |
Data.ISBN.ISBN10
Synopsis
- data ISBN = ISBN10 Text
- validateISBN10 :: Text -> Either ISBN10ValidationError ISBN
- data ISBN10ValidationError
- renderISBN10ValidationError :: ISBN10ValidationError -> Text
- confirmISBN10CheckDigit :: Text -> Bool
- calculateISBN10CheckDigitValue :: Text -> Int
- isbn10CharToNumericValue :: Char -> Int
- numericValueToISBN10Char :: Int -> Char
- isValidISBN10CheckDigit :: Char -> Bool
- isNumericCharacter :: Char -> Bool
- isISBN10 :: ISBN -> Bool
- unsafeToISBN10 :: 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.
validateISBN10 :: Text -> Either ISBN10ValidationError ISBN Source #
Used to safely create ISBN10 values represented by the ISBN data type.
Assumes that the Text input is an ISBN-10 string, either with or
without hyphens.
Will return either a validated ISBN-10 or an ISBN10ValidationError, which can be
rendered as a descriptive string using renderISBN10ValidationError.
Examples:
validateISBN10 "0-345-81602-1" == Right (ISBN10 "0345816021") validateISBN10 "0345816021" == Right (ISBN10 "0345816021") validateISBN10 "0-807-01429-X" == Right (ISBN10 "080701429X") validateISBN10 "0-345-816" == Left ISBN10InvalidInputLength validateISBN10 "X-345-81602-1" == Left ISBN10IllegalCharactersInBody validateISBN10 "0-345-81602-B" == Left ISBN10IllegalCharacterAsCheckDigit validateISBN10 "0-345-81602-3" == Left ISBN10InvalidCheckDigit
Validation Errors
data ISBN10ValidationError Source #
Possible validation errors resulting from ISBN-10 validation.
Constructors
| ISBN10InvalidInputLength | The length of the input string is not 10 characters, not counting hyphens |
| ISBN10IllegalCharactersInBody | The first nine characters of the ISBN-10 input contain non-numeric characters |
| ISBN10IllegalCharacterAsCheckDigit | The check digit of the ISBN-10 is not a valid character ( |
| ISBN10InvalidCheckDigit | The check digit is not valid for the given ISBN-10 |
Instances
| Eq ISBN10ValidationError Source # | |
Defined in Data.ISBN.ISBN10 Methods (==) :: ISBN10ValidationError -> ISBN10ValidationError -> Bool # (/=) :: ISBN10ValidationError -> ISBN10ValidationError -> Bool # | |
| Show ISBN10ValidationError Source # | |
Defined in Data.ISBN.ISBN10 Methods showsPrec :: Int -> ISBN10ValidationError -> ShowS # show :: ISBN10ValidationError -> String # showList :: [ISBN10ValidationError] -> ShowS # | |
renderISBN10ValidationError :: ISBN10ValidationError -> Text Source #
Convert an ISBN10ValidationError into a human-friendly error message.
Helpers
confirmISBN10CheckDigit :: Text -> Bool Source #
Confirms that the check digit of an ISBN-10 is correct. Assumes that the
input consists of 9 numeric characters followed by a legal check digit
character (0-9 or X).
Examples:
confirmISBN10CheckDigit "0345816021" == True confirmISBN10CheckDigit "080701429X" == True
calculateISBN10CheckDigitValue :: Text -> Int Source #
Calculates an ISBN-10 check digit value using the standard check digit calculation formula. Assumes that the input is 9 numeric characters. The check digit value can be any number in the range 0 to 10, the last of which is represented by the symbol 'X' in an ISBN-10.
See: https://en.wikipedia.org/wiki/International_Standard_Book_Number#ISBN-10_check_digits
Examples:
calculateISBN10CheckDigitValue "034581602" == 1 calculateISBN10CheckDigitValue "080701429" == 10
isbn10CharToNumericValue :: Char -> Int Source #
Converts an ISBN-10 character to a numeric value. Valid input characters
include 0-9 as well as X.
numericValueToISBN10Char :: Int -> Char Source #
Converts a numeric value to an ISBN-10 character. Valid input values are the numbers from 0 to 10.
isValidISBN10CheckDigit :: Char -> Bool Source #
Validates a character as a valid ISBN-10 check digit character. ISBN-10
check digit characters include 0-9 as well as the symbol . The lowercase
letter 'x' is not considered valid.X
isNumericCharacter :: Char -> Bool Source #
Determines whether a character is numeric (e.g. in the range of 0-9).
isISBN10 :: ISBN -> Bool Source #
Determines whether an ISBN value is an ISBN-10.
Examples:
isISBN10 (unsafeToISBN10 "0060899220") == True isISBN10 (unsafeToISBN13 "9780060899226") == False