build codecov Current Version Scala Steward badge license

Scala-isbn is a library to work with ISBNs. An ISBN is an International Standard Book Number. ISBNs were 10 digits in length up to the end of December 2006, but since 1 January 2007 they now always consist of 13 digits. ISBNs are calculated using a specific mathematical formula and include a check digit to validate the number. This library can convert ISBN-10s to ISBN-13s and vice versa if possible. It can also give the hyphenated versions of the ISBN, following the ISBN Ranges. It can also split the ISBN into its parts ('prefix element', 'registration group element', 'registrant element', 'publication element' and 'check digit'.)

Only valid SBN, ISBN-10 and ISBN-13 strings, with leniency towards spaces and hyphens, can be lifted into an ISBN case class.


Scala-isbn is published for Scala 2.13. To start using it add the following to your build.sbt:

libraryDependencies += "nl.gn0s1s" %% "scala-isbn" % "1.0.1"

Example usage

import nl.gn0s1s.isbn._

val book = Isbn("9781617292774") // val book: Option[nl.gn0s1s.isbn.Isbn] = Some(Isbn(9781617292774))
val book = Isbn("abc") // val book: Option[nl.gn0s1s.isbn.Isbn] = None, 
val book = Isbn("161729277X") // val book: Option[nl.gn0s1s.isbn.Isbn] = Some(Isbn(9781617292774))

book.flatMap(_.toIsbn10) // val res1: Option[String] = Some(161729277X) // val res2: Option[String] = Some(9781617292774)
book.flatMap(_.toHyphenatedIsbn10) // val res3: Option[String] = Some(1-61729-277-X) // val res4: Option[String] = Some(978-1-61729-277-4) // val res5: Option[String] = Some(978-1617292774) // val res6: Option[String] = Some(978) // val res7: Option[String] = Some(1) // val res8: Option[String] = Some(61729) // val res9: Option[String] = Some(277) // val res10: Option[String] = Some(4)



The code is available under the Mozilla Public License, version 2.0.