isbn
ISBN Validation and Manipulation
https://github.com/charukiewicz/hs-isbn
LTS Haskell 22.41: | 1.1.0.5 |
Stackage Nightly 2024-11-12: | 1.1.0.5 |
Latest on Hackage: | 1.1.0.5 |
isbn-1.1.0.5@sha256:25818b9dbd6ed378dadfccf045df92e6b78e703615f3c717eb7c2cc849e7d111,2106
Module documentation for 1.1.0.5
isbn: ISBN Validation and Manipulation
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 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
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 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 <path-to-repo>
$ 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
Changes
Revision history for isbn
1.1.0.5 - December 26, 2023
- Bump version of
text
dependency to include versions up to 2.2 (exclusive) - Add
flake.nix
file for Nix Flake-based development (vianix develop
) - Bump
nixpkgs.json
torelease-23.11
branch of Nixpkgs fornix-shell
based development
1.1.0.4 - September 6, 2022
- Bumped version bound of
text
dependency to includetext-2.0.x
.
1.1.0.3 - January 10, 2022
- Changed imports of
Data.Text
to be qualified to prevent ambiguous import issues caused by changed toPrelude
in GHC 9.x.
1.1.0.2 - November 13, 2020
- Built documentation using GHC 8.8.4
- Changed Nix shell development environment to use
fetchFromGitHub
instead offetchGit
for nixpkgs - Changed
hackage-build
Makefile target to splitsdist
anddocs
outputs into separate subdirectories ofbuild/
- Added
hackage-upload
andhackage-upload-publish
Makefile targets to upload new package builds to Hackage
1.1.0.1 - July 30, 2020
- Changed implementation of
validateISBN
to make a copy of the input text, preventing space leaks - Added some test cases for ISBN-13s with a ‘979’ prefix
1.1.0.0 - July 28, 2020
- Changed exports in
Data.ISBN
module to not export the constructors of theISBN
data type- If constructors are needed, the
Data.Types.ISBN
module can be imported instead
- If constructors are needed, the
- Added
isISBN10
andisISBN13
functions to allow for checking of the opaqueISBN
data type without the use of its value constructors
1.0.0.0 - May 17, 2020
- Initial release. Features:
- General ISBN validation based off of text input, as well as specific ISBN-10 or ISBN-13 validation
- Validation errors with human-friendly renderers, that can be used to display error messages to end users
- ISBN-10 to ISBN-13 conversion and vise versa