ISBN
International Standard Book Number: the 13-digit book number with prefix 978 or 979, ending in a modulus 10 check digit.
Validate
Validates an ISBN-13: prefix 978 or 979, 13 digits and the modulus 10 check digit.
- Check digit: the first 12 digits weighted 1 and 3 alternately. The check digit brings the sum to a multiple of 10. It is the same rule as a GTIN-13.
- The 10-digit ISBN is rejected: since 2007 only the 13-digit form exists.
979-0is rejected: it is the ISMN range (printed music), and the RangeMessage gives it no ISBN group. Prefix 977 and any other prefix are rejected.- Separators: whitespace,
.,-or/between two digits, alone or in a run (the mask characterscpf.isValidreads), and whitespace around the value. Any two digits may be a boundary, because the groups vary in length. A leading or trailing separator and any other character are rejected. - The
ISBNlabel a book prints in front of the number is not part of the value:ISBN 978-65-89999-01-0is invalid, as for any other validator. - It does not check whether the registration group and the registrant are assigned.
isbn.getInfodoes. - The example the Agência Brasileira do ISBN prints,
978-65-89999-01-3, has a wrong check digit. The valid number ends in 0:978-65-89999-01-0. - Only a string is read. Any other type returns
false.
| Parameter | Type | Required |
|---|---|---|
value | string | yes |
| returns | boolean |
Check if an ISBN-13 is valid: the 978 or 979 prefix and the modulus 10 check digit of the ISBN Users' Manual (the first 12 digits weighed alternately 1 and 3, the same rule as a GTIN-13).
- Separators between two digits (space,
.,-or/, alone or in a run, asisValidCpfreads its mask) and spaces around the value are accepted; anything else, a leading or trailing separator or theISBNlabel a book prints in front of the number included, makes the value invalid. - A
979-0number is an ISMN (printed music), not an ISBN: the RangeMessage gives that range no ISBN group, so it is rejected. - Whether the group and the registrant are assigned is not checked; see
getIsbnInfo. - The printed example of the Agência Brasileira do ISBN,
ISBN 978-65-89999-01-3, does not carry the check digit the rule gives (0), so it is rejected.
import { isValidIsbn } from '@brazilian-utils/brazilian-utils';
isValidIsbn('9788533302273'); // true
isValidIsbn('978-65-89999-01-0'); // true
isValidIsbn('978-85-333-0227-4'); // false (wrong check digit)
isValidIsbn('8533302276'); // false (the 10 digit form)Try it with JavaScript isValidIsbn
Shared test cases (38) and the result in each library isbn.isValid
Format
Formats an ISBN-13 the way it is printed: its five elements separated by hyphens (978-65-89999-01-0). The lengths of the group and of the registrant come from isbn.getInfo.
- Returns an empty string exactly when
isbn.getInforeturnsnull: a partial or invalid value, or a group or registrant not assigned yet. - The
ISBNlabel is not added, and it is not accepted in the input:isbn.getInforejects it, so a value with a label returns an empty string. - The input may use any run of separators (space,
.,-,/) between digits, as inisbn.isValid. - Unlike
cpf.format, it does not mask a partial value, because the element lengths depend on the whole number.
| Parameter | Type | Required |
|---|---|---|
value | string | yes |
| returns | string |
Hyphenate an ISBN-13 by its elements, as getIsbnInfo splits it. The element lengths vary, so a partial or invalid value, or one in a range not assigned yet, returns ''. The ISBN label is not added.
import { formatIsbn } from '@brazilian-utils/brazilian-utils';
formatIsbn('9788533302273'); // '978-85-333-0227-3'
formatIsbn('9780306406157'); // '978-0-306-40615-7'
formatIsbn('978853330227'); // ''Source: ISBN Users' Manual, 7th edition, ISBN Ranges (RangeMessage) of the International ISBN Agency, and the Agência Brasileira do ISBN.
Code: brazilian-utils/javascriptTry it with JavaScript formatIsbn
Shared test cases (12) and the result in each library isbn.format
Parse
Removes the hyphens and every other character that is not a digit from an ISBN-13, keeping at most 13 digits.
- It only removes non-digits and keeps the first 13. It does not remove the
ISBNlabel: inISBN-13: 978-85-333-0227-3the13stays among the digits, so the result is1397885333022. Give it the number without the label. - A partial value keeps the digits it has. The function does not check the ISBN.
- Only a string is read. Any other type returns an empty string.
| Parameter | Type | Required |
|---|---|---|
value | string | yes |
| returns | string |
Remove the hyphens and every other character that is not a digit, keeping at most 13 digits.
import { parseIsbn } from '@brazilian-utils/brazilian-utils';
parseIsbn('978-85-333-0227-3'); // '9788533302273'Try it with JavaScript parseIsbn
Shared test cases (10) and the result in each library isbn.parse
Decode
Splits a valid ISBN-13 into its elements: prefix, registration group, registrant, publication and check digit, with the agency of the group. Returns null when isbn.isValid is false, and also when the group or the registrant is in a range not assigned yet.
- The value follows the rules of
isbn.isValid: a run of separators is accepted and theISBNlabel is not, soISBN 978-65-89999-01-0returnsnull. - The group and the registrant have variable lengths. They come from the RangeMessage of the International ISBN Agency, which the library refreshes every week.
- A valid check digit is not enough: a group or registrant not assigned returns
null. This includes the gaps at the start of a group, as in 978-968 and 978-970. - Fields:
isbn(the 13 digits, without label or hyphens),prefix("978"or"979"),registrationGroup,registrantandpublication(strings, with their leading zeros),checkDigit(a number),agencyandisBrazilian.agencyis the name the RangeMessage gives to the group, for exampleBrazilorEnglish language. isBrazilianistruefor the groups 85 and 65 (Agência Brasileira do ISBN).- Returns a new object on every call.
| Parameter | Type | Required |
|---|---|---|
value | string | yes |
| returns | IsbnInfo | null |
Split a valid ISBN-13 into its elements, as an IsbnInfo, following the ranges the International ISBN Agency publishes (the RangeMessage), which give the variable lengths of the group and of the registrant.
- Returns
nullwhen the value is not valid underisValidIsbn, or when its group or registrant falls in a range not assigned yet. - The ranges are refreshed by the datasets workflow.
| Field | Description |
|---|---|
isbn | The 13 digits |
prefix | '978' or '979' |
registrationGroup | The country, region or language area, e.g. '85' or '65' for Brazil |
registrant | The publisher or imprint within the group |
publication | The edition within the registrant |
checkDigit | The check digit, the last digit |
agency | The agency the International ISBN Agency lists for the group, e.g. 'Brazil' or 'English language' |
isBrazilian | true for the groups of the Agência Brasileira do ISBN, 85 and 65 |
import { getIsbnInfo } from '@brazilian-utils/brazilian-utils';
getIsbnInfo('978-65-89999-01-0');
// { isbn: '9786589999010', prefix: '978', registrationGroup: '65', registrant: '89999',
// publication: '01', checkDigit: 0, agency: 'Brazil', isBrazilian: true }
getIsbnInfo('9780306406157')?.agency; // 'English language'Try it with JavaScript getIsbnInfo
Shared test cases (15) and the result in each library isbn.getInfo
Official sources
- isbn-international.org/content/isbn-users-manual/…/29
- cblservicos.org.br/isbn/estrutura
- isbn-international.org/export_rangemessage.xml
- isbn-international.org/range_file_generation
See also GTIN (EAN/UPC)
Last updated on
