Module:Format ISBN/doc

This module formats ISBNs. By convention, printed ISBNs use either hyphens or spaces to separate the elements within the number. The module accepts a string that represents an ISBN, and returns a formatted ISBN string. The input ISBN must be valid. That is:
 * it must be 10 or 13 characters long after removing any existing hyphen or space formatting; and
 * for 13 character ISBNs, all the characters must be digits, and it must start with 978 or 979;
 * for 10 character ISBNs, all the characters except the final one must be digits, and the final character must be either a digit or X;
 * and, the final character must be the correct check digit.

The module's only public function is format. The formatted ISBN uses hyphens or spaces, with hyphens as the default. The default prefix is ISBN, but the prefix is settable. ISBNs with 10 characters may optionally be converted to equivalent 13 character ISBNs. For invalid input ISBNs, the error return value is settable, and the default is ISBN error.

Usage
Invoke with:

Parameters:
 * isbn: The ISBN to format. Must be supplied. Should be a valid 10 character or 13 character ISBN.
 * prefix: ISBN format prefix. Optional. Default is ISBN. If not empty, it is separated from the ISBN by.
 * use_spaces: Indicate formatting with spaces instead of hyphens. Boolean. Optional. Default is false.
 * use_conversion: Convert 10 character ISBNs to 13 character ones before formatting. Boolean. Optional. Default is false. This parameter has no effect if the input ISBN is a 13 character one.
 * error: Return value to use in place of ISBN error. Optional.

Parameters may also be supplied by position, in the order shown above. If using positional parameters, a shorthand way to set prefix to the empty string is to follow the positional isbn with a single pipe character. For example, equivalent to.

Examples
Using results in:

Using results in:

Using results in:

Using results in:

Using results in:

Using results in:

Using results in:

Using results in:

Canonical uses
To format an ISBN in article text:
 * Replace wikitext ISBN 978-1843560289
 * with
 * to generate:


 * Alternatively, replace wikitext ISBN 978-1843560289
 * with ISBN
 * to generate: ISBN

To format an ISBN in a book citation (or other template with an parameter):
 * Replace wikitext
 * with }}
 * to generate:

In all cases, ISBN magic links, wiki article categorisation, and so on will continue to work correctly. MediaWiki recognises and treats both formatted and unformatted valid ISBNs equivalently, and it checks for and triggers ISBN magic links only after all template and other processing is finished.

Limitations
The module will format only ISBN numbers in the English language and US registration groups. That is, ISBNs with 10 characters and that begin with 0 or 1, and ISBNs with 13 characters that begin with 978-0, 978-1, or 979-8. In practice, this is likely to be all books referenced by the Bogleheads wiki. As of 2021, very few books use the 979-8 ISBN range.

The module will partially format ISBN numbers that are not in the English language and US registration groups. Formatting is restricted to separating only the first three digits of a 13 character ISBN, and the final (check) digit of all ISBNs. In particular, this means that invoking it on a correctly formatted non-English ISBN will create a less-correctly formatted one.