https://github.com/charukiewicz/hs-isbn
Haskell library for validating and working with ISBNs
https://github.com/charukiewicz/hs-isbn
books haskell isbn isbn-10 isbn-13
Last synced: 9 months ago
JSON representation
Haskell library for validating and working with ISBNs
- Host: GitHub
- URL: https://github.com/charukiewicz/hs-isbn
- Owner: charukiewicz
- License: apache-2.0
- Created: 2020-05-04T01:58:02.000Z (over 5 years ago)
- Default Branch: master
- Last Pushed: 2025-03-26T06:22:31.000Z (10 months ago)
- Last Synced: 2025-04-29T04:48:16.805Z (9 months ago)
- Topics: books, haskell, isbn, isbn-10, isbn-13
- Language: Haskell
- Homepage: https://hackage.haskell.org/package/isbn
- Size: 130 KB
- Stars: 6
- Watchers: 1
- Forks: 0
- Open Issues: 1
-
Metadata Files:
- Readme: README.md
- Changelog: CHANGELOG.md
- License: LICENSE
Awesome Lists containing this project
README
isbn: ISBN Validation and Manipulation
======================================
[](https://github.com/charukiewicz/hs-isbn/actions?query=workflow%3ACI)
[](https://hackage.haskell.org/package/isbn)
[](http://stackage.org/lts/package/isbn)
[](http://stackage.org/nightly/package/isbn)
[](https://www.apache.org/licenses/LICENSE-2.0.html)
All books published by major publishers since 1970 have an International Standard Book Number (ISBN) associated with them. Prior to 2007, all ISBNs issued were ten digit ISBN-10 format. Since 2007, new ISBNs have been issued in the thirteen digit ISBN-13 format. See the [ISBN Wikipedia article](https://en.wikipedia.org/wiki/International_Standard_Book_Number) for more information.
## Overview
This library provides data types and functions both validating and working with ISBNs. For general use, only importing the `Data.ISBN` module is required, as it reexports all functionality for validating and converting between ISBN-10 and ISBN-13 values. The specific implementations for validation are located in the `Data.ISBN.ISBN10` and `Data.ISBN.ISBN13` modules, respectively.
## Usage Example: Validating an ISBN and printing the error
```haskell
import Data.ISBN (ISBN, validateISBN, renderISBNValidationError)
validateUserSuppliedISBN :: Text -> Either Text ISBN
validateUserSuppliedISBN userIsbnInput =
either (Left . renderISBNValidationError) Right (validateISBN userIsbnInput)
someValidISBN10 =
validateUserSuppliedISBN "0345816021" -- Right (ISBN10 "0345816021")
someValidISBN13 =
validateUserSuppliedISBN "9780807014295" -- Right (ISBN13 "9780807014295")
tooShortISBN =
validateUserSuppliedISBN "0-345-816" -- Left "An ISBN must be 10 or 13 characters, not counting hyphens"
invalidISBN10 =
validateUserSuppliedISBN "0-345-81602-3" -- Left "The supplied ISBN-10 is not valid"
```
## Development
This library is developed using a [Nix](https://nixos.org/nix/) shell. The environment is specified in `shell.nix`. You can enter the environment with `nix` installed via `nix-shell`. The `nix-shell` will install sandboxed copies of `cabal-install`, `ghcid`, `entr`, and `gnumake`, which are the utilities necessary to build the project, run the tests, and create a local copy of the documentation.
#### Entering the development environment and runnning tests
```
$ cd
$ nix-shell # assumes `nix` is installed
(nix-shell) $ make help # show all of the make targets
(nix-shell) $ make tests-watch # build the library and run the tests in `ghcid`
(nix-shell) $ make docs # build a local copy of the haddock documentation
```