isbn-1.0.0.0: ISBN Validation and Manipulation

Safe HaskellSafe
LanguageHaskell2010

Data.ISBN.ISBN13

Synopsis

Documentation

data ISBN Source #

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.

When importing this data type, it is recommended not expose the constructors, and instead use unsafeToISBN10 or unsafeToISBN13 to coerce Text values into ISBN values.

Constructors

ISBN13 Text

An ISBN-13 value. Consists of 12 digits followed by a base-10 check digit (0-9).

Instances
Eq ISBN Source # 
Instance details

Defined in Data.ISBN.Types

Methods

(==) :: ISBN -> ISBN -> Bool #

(/=) :: ISBN -> ISBN -> Bool #

Show ISBN Source # 
Instance details

Defined in Data.ISBN.Types

Methods

showsPrec :: Int -> ISBN -> ShowS #

show :: ISBN -> String #

showList :: [ISBN] -> ShowS #

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

renderISBN13ValidationError :: ISBN13ValidationError -> Text Source #

Convert an ISBN10ValidationError into a human-friendly error message.

data ISBN13ValidationError Source #

Possible validation errors resulting from ISBN-13 validation.

Constructors

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

numericValueToISBN13Char :: Int -> Char Source #

Converts a numeric value to an ISBN-13 character. Valid input values are the numbers from 0 to 10.

unsafeToISBN13 :: Text -> ISBN Source #

Will create an ISBN13 value without any validation.