function isValidIsbn(isbn) {
  const isbnDigits = isbn.toUpperCase();

  if (isbnDigits.length !== 10 && isbnDigits.length !== 13) {
    return false;
  }

  if (!isbnDigits.match(ISBN_PATTERN)) {
    return false;
  }

  if (isbnDigits.length === 10) {
    const checkSum = isbnDigits
      .split('')
      .map((d, i) => (10 - i) * (d === 'X' ? 10 : parseInt(d, 10)))
      .reduce((sum, parcel) => sum + parcel, 0);

    return checkSum % 11 === 0;
  }

  const checkSum = isbnDigits
    .split('')
    .map((d, i) => ((i + 1) % 2 === 0 ? 3 : 1) * parseInt(d, 10))
    .reduce((sum, parcel) => sum + parcel, 0);

  return checkSum % 10 === 0;
}
Validates a ISBN string by checking the verififier digit.
Both formats are supported (obsolete 10 digits and
current 13 digits one).

By design it supports only Brazilian ISBNs.

@param {string} isbn The ISBN to be validated
@returns true if the ISBN provided is valid