glisbn
A ISBN utility library.
Types
Functions
pub fn get_checkdigit(isbn: String) -> Result(String, IsbnError)
Takes an ISBN and returns its checkdigit.
Examples
get_prefix("9788535902778")
// -> Ok("8")
get_checkdigit("2-1234-5680-2")
// -> Ok("2")
get_checkdigit("1str")
// -> Error(InvalidIsbn)
get_checkdigit("887385107X")
// -> Ok("X")
pub fn get_prefix(isbn: String) -> Result(String, IsbnError)
Takes an ISBN and returns its prefix.
Examples
get_prefix("9788535902778")
// -> Ok("978-85")
get_prefix("2-1234-5680-2")
// -> Ok("978-2")
get_prefix("1str")
// -> Error(InvalidIsbn)
pub fn get_publication_element(
isbn: String,
) -> Result(String, IsbnError)
Takes an ISBN and returns its publication element.
Examples
get_publication_element("978-1-86197-876-9")
// -> Ok("876")
get_publication_element("9789529351787")
// -> Ok("5178")
get_publication_element("1str")
// -> Error(InvalidIsbn)
pub fn get_publisher_zone(
isbn: String,
) -> Result(String, IsbnError)
Takes an ISBN and returns its publisher zone.
Examples
get_publisher_zone("9788535902778")
// -> Ok("Brazil")
get_publisher_zone("2-1234-5680-2")
// -> Ok("French language")
get_publisher_zone("1str")
// -> Error(InvalidIsbn)
pub fn get_registrant_element(
isbn: String,
) -> Result(String, IsbnError)
Takes an ISBN and returns its registrant element.
Examples
get_registrant_element("9788535902778")
// -> Ok("359")
get_registrant_element("978-1-86197-876-9")
// -> Ok("86197")
get_registrant_element("1str")
// -> Error(InvalidIsbn)
pub fn hyphenate(isbn: String) -> Result(String, IsbnError)
Takes an ISBN (10 or 13) and hyphenates it.
Examples
hyphenate("9788535902778")
// -> Ok("978-85-359-0277-8")
hyphenate("0306406152")
// -> Ok("0-306-40615-2")
hyphenate("978-5-12345-678")
// -> Error(InvalidIsbn)
pub fn is_checkdigit_valid(isbn: String) -> Bool
Takes an ISBN (10 or 13) and checks its validity by its checkdigit.
Examples
is_checkdigit_valid("85-359-0277-5")
// -> True
is_checkdigit_valid("978-5-12345-678-1")
// -> True
is_checkdigit_valid("978-5-12345-678")
// -> False
pub fn is_hyphens_correct(isbn: String) -> Bool
Checks if an ISBN (10 or 13) code is correctly hyphenated. If ISBN incorrect, that count as no.
Examples
is_hyphens_correct("978-85-359-0277-8")
// -> True
is_hyphens_correct("0-306-40615-2")
// -> True
is_hyphens_correct("97-8853590277-8")
// -> False
is_hyphens_correct("03-064-06152")
// -> False
is_hyphens_correct("str")
// -> False
pub fn is_valid(isbn: String) -> Bool
Takes an ISBN (10 or 13) and checks its validity by checking the checkdigit, length and characters.
Examples
is_valid("978-5-12345-678-1")
// -> True
is_valid("85-359-0277-5")
// -> True
is_valid("85-359-0277")
// -> False
is_valid("str")
// -> False
pub fn isbn10_checkdigit(
isbn: String,
) -> Result(String, IsbnError)
Takes an ISBN 10 code as string, returns its check digit.
Examples
isbn10_checkdigit("85-359-0277")
// -> Ok("5")
isbn10_checkdigit("5-02-013850")
// -> Ok("9")
isbn10_checkdigit("0str")
// -> Error(InvalidIsbn)
/// ```gleam isbn10_checkdigit(“887385107”) // -> Ok(“X”)
pub fn isbn10_to_13(isbn: String) -> Result(String, IsbnError)
Takes an ISBN 10 and converts it to ISBN 13.
Examples
isbn10_to_13("85-359-0277-5")
// -> Ok("9788535902778")
isbn10_to_13("0306406152")
// -> Ok("9780306406157")
isbn10_to_13("1str")
// -> Error(InvalidIsbn)
pub fn isbn13_checkdigit(
isbn: String,
) -> Result(String, IsbnError)
Takes an ISBN 13 code as string, returns its check digit.
Examples
isbn13_checkdigit("978-5-12345-678"")
// -> Ok("1")
isbn13_checkdigit("978-0-306-40615")
// -> Ok("7")
isbn13_checkdigit("1str")
// -> Error(InvalidIsbn)
pub fn isbn13_to_10(isbn: String) -> Result(String, IsbnError)
Takes an ISBN 13 and converts it to ISBN 10.
Examples
isbn13_to_10("9788535902778")
// -> Ok("8535902775")
isbn13_to_10("9780306406157")
// -> Ok("0306406152")
isbn13_to_10("1str")
// -> Error(InvalidIsbn)