Git Product home page Git Product logo

isbn's Introduction

biblys/isbn

tests Latest Stable Version Total Downloads License Gitpod ready-to-code

biblys/isbn can be used to:

  • validate a string against the ISBN-10, ISBN-13 and EAN-13 formats
  • convert an ISBN to ISBN-10, ISBN-13, EAN-13 and GTIN-14 formats
  • parse an ISBN and extract registration agency, publisher code, publication code, checksum, etc.

CHANGELOG

Installation

Install with composer:

composer require biblys/isbn:^2.3.0

Usage

Formatting

Use case: converting an EAN (9782843449499) to an ISBN-13 (978-2-84344-949-9).

<?php

use Biblys\Isbn\Isbn;

try {
    $input = "9782843449499";
    $isbn13 = Isbn::convertToIsbn13($input);
    echo "ISBN-13: $isbn13"; // Prints ISBN-13: 978-2-84344-949-9
} catch(Exception $e) {
    echo "An error occured while attempting to format ISBN $input: ".$e->getMessage();
}

All formating methods:

  • Isbn::convertToIsbn10
  • Isbn::convertToIsbn13
  • Isbn::convertToEan13
  • Isbn::convertToGtin14

Validating

Use case: validating an incorrectly formed ISBN-13 (978-2-843-44949-9, should be 978-2-84344-949-9).

<?php

use Biblys\Isbn\Isbn;

try {
    $input = "978-2-843-44949-9";
    Isbn::validateAsIsbn13($input);
    echo "ISBN $input is valid!";
} catch(Exception $e) { // Will throw because third hyphen is misplaced
    echo "ISBN $input is invalid: ".$e->getMessage();
}

All validating methods:

  • Isbn::validateAsIsbn10
  • Isbn::validateAsIbsn13
  • Isbn::validateAsEan13
  • Isbn::isParsable

Learn more about validating ISBNs

Development

Using Gitpod

You can start a dev environnement by clicking Gitpod ready-to-code and start hacking in your browser right away!

Locally

If you'd rather setup a local dev environnement, you'll need:

  • PHP 7.x
  • Composer
  • (Optional) Docker to run tests and debug against different version of PHP

Clone this repository and run composer install to get started!

Tests

Run tests with PHPUnit:

composer install
composer test

Run tests in a docker container:

composer docker:test

Run tests in a docker container using a specific PHP version:

PHP_VERSION=7.1 composer docker:test

ISBN ranges update

New ISBN ranges may be added from time to time by the International ISBN Agency. Whenever it happens, this library must be updated. If a range update is necessary, please open an issue on Github. You can also open a pull request after updating the ranges your self with the following commands:

composer install
composer run update-ranges

Or using a docker container:

composer docker:update-ranges

Changelog

See Github releases

isbn's People

Contributors

clemlatz avatar kokoshneta avatar crishoj avatar dispositif avatar baschny avatar s1syphos avatar dependabot-preview[bot] avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.